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"
172 :"=c" (res
), "=&D" (d0
)
173 :"1" (s
),"a" (0), "0" (0xffffffffu
)
177 EXPORT_SYMBOL(strlen
);
180 #ifdef __HAVE_ARCH_MEMCHR
181 void *memchr(const void *cs
,int c
,size_t count
)
187 asm volatile( "repne\n\t"
192 :"=D" (res
), "=&c" (d0
)
193 :"a" (c
),"0" (cs
),"1" (count
)
197 EXPORT_SYMBOL(memchr
);
200 #ifdef __HAVE_ARCH_MEMSCAN
201 void *memscan(void * addr
, int c
, size_t size
)
205 asm volatile("repnz; scasb\n\t"
209 : "=D" (addr
), "=c" (size
)
210 : "0" (addr
), "1" (size
), "a" (c
)
214 EXPORT_SYMBOL(memscan
);
217 #ifdef __HAVE_ARCH_STRNLEN
218 size_t strnlen(const char *s
, size_t count
)
222 asm volatile( "movl %2,%0\n\t"
224 "1:\tcmpb $0,(%0)\n\t"
231 :"=a" (res
), "=&d" (d0
)
236 EXPORT_SYMBOL(strnlen
);