xref: /linux/arch/x86/lib/strstr_32.c (revision 498495dba268b20e8eadd7fe93c140c68b6cc9d2)
1*b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
244f0257fSThomas Gleixner #include <linux/string.h>
3784d5699SAl Viro #include <linux/export.h>
444f0257fSThomas Gleixner 
strstr(const char * cs,const char * ct)544f0257fSThomas Gleixner char *strstr(const char *cs, const char *ct)
644f0257fSThomas Gleixner {
744f0257fSThomas Gleixner int	d0, d1;
844f0257fSThomas Gleixner register char *__res;
944f0257fSThomas Gleixner __asm__ __volatile__(
1044f0257fSThomas Gleixner 	"movl %6,%%edi\n\t"
1144f0257fSThomas Gleixner 	"repne\n\t"
1244f0257fSThomas Gleixner 	"scasb\n\t"
1344f0257fSThomas Gleixner 	"notl %%ecx\n\t"
1444f0257fSThomas Gleixner 	"decl %%ecx\n\t"	/* NOTE! This also sets Z if searchstring='' */
1544f0257fSThomas Gleixner 	"movl %%ecx,%%edx\n"
1644f0257fSThomas Gleixner 	"1:\tmovl %6,%%edi\n\t"
1744f0257fSThomas Gleixner 	"movl %%esi,%%eax\n\t"
1844f0257fSThomas Gleixner 	"movl %%edx,%%ecx\n\t"
1944f0257fSThomas Gleixner 	"repe\n\t"
2044f0257fSThomas Gleixner 	"cmpsb\n\t"
2144f0257fSThomas Gleixner 	"je 2f\n\t"		/* also works for empty string, see above */
2244f0257fSThomas Gleixner 	"xchgl %%eax,%%esi\n\t"
2344f0257fSThomas Gleixner 	"incl %%esi\n\t"
2444f0257fSThomas Gleixner 	"cmpb $0,-1(%%eax)\n\t"
2544f0257fSThomas Gleixner 	"jne 1b\n\t"
2644f0257fSThomas Gleixner 	"xorl %%eax,%%eax\n\t"
2744f0257fSThomas Gleixner 	"2:"
2844f0257fSThomas Gleixner 	: "=a" (__res), "=&c" (d0), "=&S" (d1)
2944f0257fSThomas Gleixner 	: "0" (0), "1" (0xffffffff), "2" (cs), "g" (ct)
3044f0257fSThomas Gleixner 	: "dx", "di");
3144f0257fSThomas Gleixner return __res;
3244f0257fSThomas Gleixner }
33784d5699SAl Viro EXPORT_SYMBOL(strstr);
34