2 * Most of the string-functions are rather heavily hand-optimized,
3 * see especially strsep,strstr,str[c]spn. They should work, but are not
4 * very easy to understand. Everything is done entirely within the register
5 * set, making the functions fast and clean. String instructions have been
6 * used through-out, making for "slightly" unclear code :-)
8 * AK: On P4 and K7 using non string instruction implementations might be faster
9 * for large memory blocks. But most of them are unlikely to be used on large
13 #include <linux/string.h>
14 #include <linux/module.h>
16 #ifdef __HAVE_ARCH_STRCPY
17 char *strcpy(char *dest, const char *src)
20 asm volatile("1:\tlodsb\n\t"
24 : "=&S" (d0), "=&D" (d1), "=&a" (d2)
25 : "0" (src), "1" (dest) : "memory");
28 EXPORT_SYMBOL(strcpy);
31 #ifdef __HAVE_ARCH_STRNCPY
32 char *strncpy(char *dest, const char *src, size_t count)
35 asm volatile("1:\tdecl %2\n\t"
44 : "=&S" (d0), "=&D" (d1), "=&c" (d2), "=&a" (d3)
45 : "0" (src), "1" (dest), "2" (count) : "memory");
48 EXPORT_SYMBOL(strncpy);
51 #ifdef __HAVE_ARCH_STRCAT
52 char *strcat(char *dest, const char *src)
55 asm volatile("repne\n\t"
62 : "=&S" (d0), "=&D" (d1), "=&a" (d2), "=&c" (d3)
63 : "0" (src), "1" (dest), "2" (0), "3" (0xffffffffu) : "memory");
66 EXPORT_SYMBOL(strcat);
69 #ifdef __HAVE_ARCH_STRNCAT
70 char *strncat(char *dest, const char *src, size_t count)
73 asm volatile("repne\n\t"
85 : "=&S" (d0), "=&D" (d1), "=&a" (d2), "=&c" (d3)
86 : "0" (src), "1" (dest), "2" (0), "3" (0xffffffffu), "g" (count)
90 EXPORT_SYMBOL(strncat);
93 #ifdef __HAVE_ARCH_STRCMP
94 int strcmp(const char *cs, const char *ct)
98 asm volatile("1:\tlodsb\n\t"
101 "testb %%al,%%al\n\t"
103 "xorl %%eax,%%eax\n\t"
105 "2:\tsbbl %%eax,%%eax\n\t"
108 : "=a" (res), "=&S" (d0), "=&D" (d1)
113 EXPORT_SYMBOL(strcmp);
116 #ifdef __HAVE_ARCH_STRNCMP
117 int strncmp(const char *cs, const char *ct, size_t count)
121 asm volatile("1:\tdecl %3\n\t"
126 "testb %%al,%%al\n\t"
128 "2:\txorl %%eax,%%eax\n\t"
130 "3:\tsbbl %%eax,%%eax\n\t"
133 : "=a" (res), "=&S" (d0), "=&D" (d1), "=&c" (d2)
134 : "1" (cs), "2" (ct), "3" (count)
138 EXPORT_SYMBOL(strncmp);
141 #ifdef __HAVE_ARCH_STRCHR
142 char *strchr(const char *s, int c)
146 asm volatile("movb %%al,%%ah\n"
150 "testb %%al,%%al\n\t"
155 : "=a" (res), "=&S" (d0)
160 EXPORT_SYMBOL(strchr);
163 #ifdef __HAVE_ARCH_STRLEN
164 size_t strlen(const char *s)
168 asm volatile("repne\n\t"
170 : "=c" (res), "=&D" (d0)
171 : "1" (s), "a" (0), "0" (0xffffffffu)
175 EXPORT_SYMBOL(strlen);
178 #ifdef __HAVE_ARCH_MEMCHR
179 void *memchr(const void *cs, int c, size_t count)
185 asm volatile("repne\n\t"
190 : "=D" (res), "=&c" (d0)
191 : "a" (c), "0" (cs), "1" (count)
195 EXPORT_SYMBOL(memchr);
198 #ifdef __HAVE_ARCH_MEMSCAN
199 void *memscan(void *addr, int c, size_t size)
203 asm volatile("repnz; scasb\n\t"
207 : "=D" (addr), "=c" (size)
208 : "0" (addr), "1" (size), "a" (c)
212 EXPORT_SYMBOL(memscan);
215 #ifdef __HAVE_ARCH_STRNLEN
216 size_t strnlen(const char *s, size_t count)
220 asm volatile("movl %2,%0\n\t"
222 "1:\tcmpb $0,(%0)\n\t"
229 : "=a" (res), "=&d" (d0)
230 : "c" (s), "1" (count)
234 EXPORT_SYMBOL(strnlen);