1 #ifndef _M68K_STRING_H_
2 #define _M68K_STRING_H_
7 #define __HAVE_ARCH_STRCPY
8 static inline char * strcpy(char * dest,const char *src)
13 ("1:\tmoveb %1@+,%0@+\n\t"
15 : "=a" (dest), "=a" (src)
16 : "0" (dest), "1" (src) : "memory");
20 #define __HAVE_ARCH_STRNCPY
21 static inline char * strncpy(char *dest, const char *src, size_t n)
29 ("1:\tmoveb %1@+,%0@+\n\t"
34 : "=a" (dest), "=a" (src), "=d" (n)
35 : "0" (dest), "1" (src), "2" (n)
40 #define __HAVE_ARCH_STRCAT
41 static inline char * strcat(char * dest, const char * src)
47 while ((*dest++ = *src++))
53 #define __HAVE_ARCH_STRNCAT
54 static inline char * strncat(char *dest, const char *src, size_t count)
61 while ((*dest++ = *src++)) {
72 #define __HAVE_ARCH_STRCHR
73 static inline char * strchr(const char * s, int c)
84 #define __HAVE_ARCH_STRPBRK
85 static inline char *strpbrk(const char *cs,const char *ct)
89 for( sc1 = cs; *sc1 != '\0'; ++sc1)
90 for( sc2 = ct; *sc2 != '\0'; ++sc2)
98 #define __HAVE_ARCH_STRSPN
99 static inline size_t strspn(const char *s, const char *accept)
105 for (p = s; *p != '\0'; ++p)
107 for (a = accept; *a != '\0'; ++a)
122 #define __HAVE_ARCH_STRLEN
123 static inline size_t strlen(const char * s)
126 for (sc = s; *sc != '\0'; ++sc) ;
132 #define __HAVE_ARCH_STRCMP
133 static inline int strcmp(const char * cs,const char * ct)
138 ("1:\tmoveb %0@+,%2\n\t" /* get *cs */
139 "cmpb %1@+,%2\n\t" /* compare a byte */
140 "jne 2f\n\t" /* not equal, break out */
141 "tstb %2\n\t" /* at end of cs? */
142 "jne 1b\n\t" /* no, keep going */
143 "jra 3f\n\t" /* strings are equal */
144 "2:\tsubb %1@-,%2\n\t" /* *cs - *ct */
146 : "=a" (cs), "=a" (ct), "=d" (__res)
147 : "0" (cs), "1" (ct));
151 #define __HAVE_ARCH_STRNCMP
152 static inline int strncmp(const char * cs,const char * ct,size_t count)
159 ("1:\tmovb %0@+,%3\n\t" /* get *cs */
160 "cmpb %1@+,%3\n\t" /* compare a byte */
161 "jne 3f\n\t" /* not equal, break out */
162 "tstb %3\n\t" /* at end of cs? */
163 "jeq 4f\n\t" /* yes, all done */
164 "subql #1,%2\n\t" /* no, adjust count */
165 "jne 1b\n\t" /* more to do, keep going */
166 "2:\tmoveq #0,%3\n\t" /* strings are equal */
168 "3:\tsubb %1@-,%3\n\t" /* *cs - *ct */
170 : "=a" (cs), "=a" (ct), "=d" (count), "=d" (__res)
171 : "0" (cs), "1" (ct), "2" (count));
175 #define __HAVE_ARCH_MEMSET
177 * This is really ugly, but its highly optimizatiable by the
178 * compiler and is meant as compensation for gcc's missing
179 * __builtin_memset(). For the 680[23]0 it might be worth considering
180 * the optimal number of misaligned writes compared to the number of
181 * tests'n'branches needed to align the destination address. The
182 * 680[46]0 doesn't really care due to their copy-back caches.
183 * 10/09/96 - Jes Sorensen
185 static inline void * __memset_g(void * s, int c, size_t count)
201 case 32: case 33: case 34: case 35:
203 case 28: case 29: case 30: case 31:
205 case 24: case 25: case 26: case 27:
207 case 20: case 21: case 22: case 23:
209 case 16: case 17: case 18: case 19:
211 case 12: case 13: case 14: case 15:
213 case 8: case 9: case 10: case 11:
215 case 4: case 5: case 6: case 7:
242 if (count > 2 && (long) s & 2)
274 * __memset_page assumes that data is longword aligned. Most, if not
275 * all, of these page sized memsets are performed on page aligned
276 * areas, thus we do not need to check if the destination is longword
277 * aligned. Of course we suffer a serious performance loss if this is
278 * not the case but I think the risk of this ever happening is
279 * extremely small. We spend a lot of time clearing pages in
280 * get_empty_page() so I think it is worth it anyway. Besides, the
281 * 680[46]0 do not really care about misaligned writes due to their
284 * The optimized case for the 680[46]0 is implemented using the move16
285 * instruction. My tests showed that this implementation is 35-45%
286 * faster than the original implementation using movel, the only
287 * caveat is that the destination address must be 16-byte aligned.
288 * 01/09/96 - Jes Sorensen
290 static inline void * __memset_page(void * s,int c,size_t count)
292 unsigned long data, tmp;
301 #ifdef CPU_M68040_OR_M68060_ONLY
303 if (((unsigned long) s) & 0x0f)
304 __memset_g(s, c, count);
306 *((unsigned long *)(s))++ = data;
307 *((unsigned long *)(s))++ = data;
308 *((unsigned long *)(s))++ = data;
309 *((unsigned long *)(s))++ = data;
311 __asm__ __volatile__("1:\t"
313 "move16 %2@+,%0@+\n\t"
318 : "=a" (s), "=d" (tmp)
319 : "a" (sp), "0" (s), "1" ((count - 16) / 16 - 1)
324 __asm__ __volatile__("1:\t"
334 : "=a" (s), "=d" (tmp)
335 : "d" (data), "0" (s), "1" (count / 32 - 1)
342 extern void *memset(void *,int,__kernel_size_t);
344 #define __memset_const(s,c,count) \
345 ((count==PAGE_SIZE) ? \
346 __memset_page((s),(c),(count)) : \
347 __memset_g((s),(c),(count)))
349 #define memset(s, c, count) \
350 (__builtin_constant_p(count) ? \
351 __memset_const((s),(c),(count)) : \
352 __memset_g((s),(c),(count)))
354 #define __HAVE_ARCH_MEMCPY
355 extern void * memcpy(void *, const void *, size_t );
357 * __builtin_memcpy() does not handle page-sized memcpys very well,
358 * thus following the same assumptions as for page-sized memsets, this
359 * function copies page-sized areas using an unrolled loop, without
360 * considering alignment.
362 * For the 680[46]0 only kernels we use the move16 instruction instead
363 * as it writes through the data-cache, invalidating the cache-lines
364 * touched. In this way we do not use up the entire data-cache (well,
365 * half of it on the 68060) by copying a page. An unrolled loop of two
366 * move16 instructions seem to the fastest. The only caveat is that
367 * both source and destination must be 16-byte aligned, if not we fall
368 * back to the generic memcpy function. - Jes
370 static inline void * __memcpy_page(void * to, const void * from, size_t count)
375 #ifdef CPU_M68040_OR_M68060_ONLY
377 if (((unsigned long) to | (unsigned long) from) & 0x0f)
378 return memcpy(to, from, count);
380 __asm__ __volatile__("1:\t"
382 "move16 %1@+,%0@+\n\t"
383 "move16 %1@+,%0@+\n\t"
386 : "=a" (to), "=a" (from), "=d" (tmp)
387 : "0" (to), "1" (from) , "2" (count / 32 - 1)
390 __asm__ __volatile__("1:\t"
391 "movel %1@+,%0@+\n\t"
392 "movel %1@+,%0@+\n\t"
393 "movel %1@+,%0@+\n\t"
394 "movel %1@+,%0@+\n\t"
395 "movel %1@+,%0@+\n\t"
396 "movel %1@+,%0@+\n\t"
397 "movel %1@+,%0@+\n\t"
398 "movel %1@+,%0@+\n\t"
400 : "=a" (to), "=a" (from), "=d" (tmp)
401 : "0" (to), "1" (from) , "2" (count / 32 - 1)
407 #define __memcpy_const(to, from, n) \
409 __memcpy_page((to),(from),(n)) : \
410 __builtin_memcpy((to),(from),(n)))
412 #define memcpy(to, from, n) \
413 (__builtin_constant_p(n) ? \
414 __memcpy_const((to),(from),(n)) : \
415 memcpy((to),(from),(n)))
417 #define __HAVE_ARCH_MEMMOVE
418 static inline void * memmove(void * dest,const void * src, size_t n)
431 const char *csrc = src;
437 if (n > 2 && (long) dest & 2)
440 const short *ssrc = src;
450 const long *lsrc = src;
461 const short *ssrc = src;
469 const char *csrc = src;
475 dest = (char *) dest + n;
476 src = (const char *) src + n;
480 const char *csrc = src;
486 if (n > 2 && (long) dest & 2)
489 const short *ssrc = src;
499 const long *lsrc = src;
510 const short *ssrc = src;
518 const char *csrc = src;
525 #define __HAVE_ARCH_MEMCMP
526 extern int memcmp(const void * ,const void * ,size_t );
527 #define memcmp(cs, ct, n) \
528 (__builtin_constant_p(n) ? \
529 __builtin_memcmp((cs),(ct),(n)) : \
530 memcmp((cs),(ct),(n)))
532 #define __HAVE_ARCH_MEMCHR
533 static inline void *memchr(const void *cs, int c, size_t count)
535 /* Someone else can optimize this, I don't care - tonym@mac.linux-m68k.org */
536 unsigned char *ret = (unsigned char *)cs;
537 for(;count>0;count--,ret++)
538 if(*ret == c) return ret;
543 #endif /* _M68K_STRING_H_ */