xref: /linux/arch/x86/lib/strstr_32.c (revision 25489a4f556414445d342951615178368ee45cde)
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/string.h>
3 #include <linux/export.h>
4 
5 char *strstr(const char *cs, const char *ct)
6 {
7 int	d0, d1;
8 register char *__res;
9 __asm__ __volatile__(
10 	"movl %6,%%edi\n\t"
11 	"repne scasb\n\t"
12 	"notl %%ecx\n\t"
13 	"decl %%ecx\n\t"	/* NOTE! This also sets Z if searchstring='' */
14 	"movl %%ecx,%%edx\n"
15 	"1:\tmovl %6,%%edi\n\t"
16 	"movl %%esi,%%eax\n\t"
17 	"movl %%edx,%%ecx\n\t"
18 	"repe cmpsb\n\t"
19 	"je 2f\n\t"		/* also works for empty string, see above */
20 	"xchgl %%eax,%%esi\n\t"
21 	"incl %%esi\n\t"
22 	"cmpb $0,-1(%%eax)\n\t"
23 	"jne 1b\n\t"
24 	"xorl %%eax,%%eax\n\t"
25 	"2:"
26 	: "=a" (__res), "=&c" (d0), "=&S" (d1)
27 	: "0" (0), "1" (0xffffffff), "2" (cs), "g" (ct)
28 	: "dx", "di");
29 return __res;
30 }
31 EXPORT_SYMBOL(strstr);
32