1 #ifndef _I386_STRING_H_
2 #define _I386_STRING_H_
6 /* Let gcc decide wether to inline or use the out of line functions */
8 #define __HAVE_ARCH_STRCPY
9 extern char *strcpy(char *dest, const char *src);
11 #define __HAVE_ARCH_STRNCPY
12 extern char *strncpy(char *dest, const char *src, size_t count);
14 #define __HAVE_ARCH_STRCAT
15 extern char *strcat(char *dest, const char *src);
17 #define __HAVE_ARCH_STRNCAT
18 extern char *strncat(char *dest, const char *src, size_t count);
20 #define __HAVE_ARCH_STRCMP
21 extern int strcmp(const char *cs, const char *ct);
23 #define __HAVE_ARCH_STRNCMP
24 extern int strncmp(const char *cs, const char *ct, size_t count);
26 #define __HAVE_ARCH_STRCHR
27 extern char *strchr(const char *s, int c);
29 #define __HAVE_ARCH_STRRCHR
30 extern char *strrchr(const char *s, int c);
32 #define __HAVE_ARCH_STRLEN
33 extern size_t strlen(const char *s);
35 static __always_inline void * __memcpy(void * to, const void * from, size_t n)
45 : "=&c" (d0), "=&D" (d1), "=&S" (d2)
46 : "0" (n/4), "g" (n), "1" ((long) to), "2" ((long) from)
52 * This looks ugly, but the compiler can optimize it totally,
53 * as the count is constant.
55 static __always_inline void * __constant_memcpy(void * to, const void * from, size_t n)
59 #if 1 /* want to do small copies with non-string ops? */
61 case 1: *(char*)to = *(char*)from; return to;
62 case 2: *(short*)to = *(short*)from; return to;
63 case 4: *(int*)to = *(int*)from; return to;
64 #if 1 /* including those doable with two moves? */
65 case 3: *(short*)to = *(short*)from;
66 *((char*)to+2) = *((char*)from+2); return to;
67 case 5: *(int*)to = *(int*)from;
68 *((char*)to+4) = *((char*)from+4); return to;
69 case 6: *(int*)to = *(int*)from;
70 *((short*)to+2) = *((short*)from+2); return to;
71 case 8: *(int*)to = *(int*)from;
72 *((int*)to+1) = *((int*)from+1); return to;
79 /* large block: use rep prefix */
83 : "=&c" (ecx), "=&D" (edi), "=&S" (esi)
84 : "0" (n/4), "1" (edi),"2" (esi)
88 /* small block: don't clobber ecx + smaller code */
89 if (n >= 4*4) __asm__ __volatile__("movsl"
90 :"=&D"(edi),"=&S"(esi):"0"(edi),"1"(esi):"memory");
91 if (n >= 3*4) __asm__ __volatile__("movsl"
92 :"=&D"(edi),"=&S"(esi):"0"(edi),"1"(esi):"memory");
93 if (n >= 2*4) __asm__ __volatile__("movsl"
94 :"=&D"(edi),"=&S"(esi):"0"(edi),"1"(esi):"memory");
95 if (n >= 1*4) __asm__ __volatile__("movsl"
96 :"=&D"(edi),"=&S"(esi):"0"(edi),"1"(esi):"memory");
101 case 1: __asm__ __volatile__("movsb"
102 :"=&D"(edi),"=&S"(esi):"0"(edi),"1"(esi):"memory");
104 case 2: __asm__ __volatile__("movsw"
105 :"=&D"(edi),"=&S"(esi):"0"(edi),"1"(esi):"memory");
107 default: __asm__ __volatile__("movsw\n\tmovsb"
108 :"=&D"(edi),"=&S"(esi):"0"(edi),"1"(esi):"memory");
113 #define __HAVE_ARCH_MEMCPY
115 #ifdef CONFIG_X86_USE_3DNOW
120 * This CPU favours 3DNow strongly (eg AMD Athlon)
123 static inline void * __constant_memcpy3d(void * to, const void * from, size_t len)
126 return __constant_memcpy(to, from, len);
127 return _mmx_memcpy(to, from, len);
130 static __inline__ void *__memcpy3d(void *to, const void *from, size_t len)
133 return __memcpy(to, from, len);
134 return _mmx_memcpy(to, from, len);
137 #define memcpy(t, f, n) \
138 (__builtin_constant_p(n) ? \
139 __constant_memcpy3d((t),(f),(n)) : \
140 __memcpy3d((t),(f),(n)))
148 #define memcpy(t, f, n) \
149 (__builtin_constant_p(n) ? \
150 __constant_memcpy((t),(f),(n)) : \
151 __memcpy((t),(f),(n)))
155 #define __HAVE_ARCH_MEMMOVE
156 void *memmove(void * dest,const void * src, size_t n);
158 #define memcmp __builtin_memcmp
160 #define __HAVE_ARCH_MEMCHR
161 extern void *memchr(const void * cs,int c,size_t count);
163 static inline void * __memset_generic(void * s, char c,size_t count)
166 __asm__ __volatile__(
169 : "=&c" (d0), "=&D" (d1)
170 :"a" (c),"1" (s),"0" (count)
175 /* we might want to write optimized versions of these later */
176 #define __constant_count_memset(s,c,count) __memset_generic((s),(c),(count))
179 * memset(x,0,y) is a reasonably common thing to do, so we want to fill
180 * things 32 bits at a time even when we don't know the size of the
181 * area at compile-time..
183 static __always_inline void * __constant_c_memset(void * s, unsigned long c, size_t count)
186 __asm__ __volatile__(
191 "1:\ttestb $1,%b3\n\t"
195 :"=&c" (d0), "=&D" (d1)
196 :"a" (c), "q" (count), "0" (count/4), "1" ((long) s)
201 /* Added by Gertjan van Wingerde to make minix and sysv module work */
202 #define __HAVE_ARCH_STRNLEN
203 extern size_t strnlen(const char * s, size_t count);
204 /* end of additional stuff */
206 #define __HAVE_ARCH_STRSTR
207 extern char *strstr(const char *cs, const char *ct);
210 * This looks horribly ugly, but the compiler can optimize it totally,
211 * as we by now know that both pattern and count is constant..
213 static __always_inline void * __constant_c_and_count_memset(void * s, unsigned long pattern, size_t count)
219 *(unsigned char *)s = pattern;
222 *(unsigned short *)s = pattern;
225 *(unsigned short *)s = pattern;
226 *(2+(unsigned char *)s) = pattern;
229 *(unsigned long *)s = pattern;
233 __asm__ __volatile__( \
236 : "=&c" (d0), "=&D" (d1) \
237 : "a" (pattern),"0" (count/4),"1" ((long) s) \
242 case 0: COMMON(""); return s;
243 case 1: COMMON("\n\tstosb"); return s;
244 case 2: COMMON("\n\tstosw"); return s;
245 default: COMMON("\n\tstosw\n\tstosb"); return s;
252 #define __constant_c_x_memset(s, c, count) \
253 (__builtin_constant_p(count) ? \
254 __constant_c_and_count_memset((s),(c),(count)) : \
255 __constant_c_memset((s),(c),(count)))
257 #define __memset(s, c, count) \
258 (__builtin_constant_p(count) ? \
259 __constant_count_memset((s),(c),(count)) : \
260 __memset_generic((s),(c),(count)))
262 #define __HAVE_ARCH_MEMSET
263 #define memset(s, c, count) \
264 (__builtin_constant_p(c) ? \
265 __constant_c_x_memset((s),(0x01010101UL*(unsigned char)(c)),(count)) : \
266 __memset((s),(c),(count)))
269 * find the first occurrence of byte 'c', or 1 past the area if none
271 #define __HAVE_ARCH_MEMSCAN
272 extern void *memscan(void * addr, int c, size_t size);
274 #endif /* __KERNEL__ */