Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include <linux/string.h> |
Al Viro | 784d569 | 2016-01-11 11:04:34 -0500 | [diff] [blame] | 2 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | |
Paolo Ciarrocchi | f73920c | 2008-02-22 23:09:56 +0100 | [diff] [blame] | 4 | char *strstr(const char *cs, const char *ct) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | { |
| 6 | int d0, d1; |
Paolo Ciarrocchi | f73920c | 2008-02-22 23:09:56 +0100 | [diff] [blame] | 7 | register char *__res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | __asm__ __volatile__( |
| 9 | "movl %6,%%edi\n\t" |
| 10 | "repne\n\t" |
| 11 | "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\n\t" |
| 19 | "cmpsb\n\t" |
| 20 | "je 2f\n\t" /* also works for empty string, see above */ |
| 21 | "xchgl %%eax,%%esi\n\t" |
| 22 | "incl %%esi\n\t" |
| 23 | "cmpb $0,-1(%%eax)\n\t" |
| 24 | "jne 1b\n\t" |
| 25 | "xorl %%eax,%%eax\n\t" |
| 26 | "2:" |
Paolo Ciarrocchi | 209b580 | 2008-08-02 21:24:45 +0200 | [diff] [blame] | 27 | : "=a" (__res), "=&c" (d0), "=&S" (d1) |
| 28 | : "0" (0), "1" (0xffffffff), "2" (cs), "g" (ct) |
| 29 | : "dx", "di"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | return __res; |
| 31 | } |
Al Viro | 784d569 | 2016-01-11 11:04:34 -0500 | [diff] [blame] | 32 | EXPORT_SYMBOL(strstr); |