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