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
;
299 #ifdef CPU_M68040_OR_M68060_ONLY
301 if (((unsigned long) s
) & 0x0f)
302 __memset_g(s
, c
, count
);
304 unsigned long *sp
= s
;
310 __asm__
__volatile__("1:\t"
312 "move16 %2@+,%0@+\n\t"
317 : "=a" (sp
), "=d" (tmp
)
318 : "a" (s
), "0" (sp
), "1" ((count
- 16) / 16 - 1)
323 __asm__
__volatile__("1:\t"
333 : "=a" (s
), "=d" (tmp
)
334 : "d" (data
), "0" (s
), "1" (count
/ 32 - 1)
341 extern void *memset(void *,int,__kernel_size_t
);
343 #define __memset_const(s,c,count) \
344 ((count==PAGE_SIZE) ? \
345 __memset_page((s),(c),(count)) : \
346 __memset_g((s),(c),(count)))
348 #define memset(s, c, count) \
349 (__builtin_constant_p(count) ? \
350 __memset_const((s),(c),(count)) : \
351 __memset_g((s),(c),(count)))
353 #define __HAVE_ARCH_MEMCPY
354 extern void * memcpy(void *, const void *, size_t );
356 * __builtin_memcpy() does not handle page-sized memcpys very well,
357 * thus following the same assumptions as for page-sized memsets, this
358 * function copies page-sized areas using an unrolled loop, without
359 * considering alignment.
361 * For the 680[46]0 only kernels we use the move16 instruction instead
362 * as it writes through the data-cache, invalidating the cache-lines
363 * touched. In this way we do not use up the entire data-cache (well,
364 * half of it on the 68060) by copying a page. An unrolled loop of two
365 * move16 instructions seem to the fastest. The only caveat is that
366 * both source and destination must be 16-byte aligned, if not we fall
367 * back to the generic memcpy function. - Jes
369 static inline void * __memcpy_page(void * to
, const void * from
, size_t count
)
374 #ifdef CPU_M68040_OR_M68060_ONLY
376 if (((unsigned long) to
| (unsigned long) from
) & 0x0f)
377 return memcpy(to
, from
, count
);
379 __asm__
__volatile__("1:\t"
381 "move16 %1@+,%0@+\n\t"
382 "move16 %1@+,%0@+\n\t"
385 : "=a" (to
), "=a" (from
), "=d" (tmp
)
386 : "0" (to
), "1" (from
) , "2" (count
/ 32 - 1)
389 __asm__
__volatile__("1:\t"
390 "movel %1@+,%0@+\n\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"
399 : "=a" (to
), "=a" (from
), "=d" (tmp
)
400 : "0" (to
), "1" (from
) , "2" (count
/ 32 - 1)
406 #define __memcpy_const(to, from, n) \
408 __memcpy_page((to),(from),(n)) : \
409 __builtin_memcpy((to),(from),(n)))
411 #define memcpy(to, from, n) \
412 (__builtin_constant_p(n) ? \
413 __memcpy_const((to),(from),(n)) : \
414 memcpy((to),(from),(n)))
416 #define __HAVE_ARCH_MEMMOVE
417 static inline void * memmove(void * dest
,const void * src
, size_t n
)
430 const char *csrc
= src
;
436 if (n
> 2 && (long) dest
& 2)
439 const short *ssrc
= src
;
449 const long *lsrc
= src
;
460 const short *ssrc
= src
;
468 const char *csrc
= src
;
474 dest
= (char *) dest
+ n
;
475 src
= (const char *) src
+ n
;
479 const char *csrc
= src
;
485 if (n
> 2 && (long) dest
& 2)
488 const short *ssrc
= src
;
498 const long *lsrc
= src
;
509 const short *ssrc
= src
;
517 const char *csrc
= src
;
524 #define __HAVE_ARCH_MEMCMP
525 extern int memcmp(const void * ,const void * ,size_t );
526 #define memcmp(cs, ct, n) \
527 (__builtin_constant_p(n) ? \
528 __builtin_memcmp((cs),(ct),(n)) : \
529 memcmp((cs),(ct),(n)))
531 #define __HAVE_ARCH_MEMCHR
532 static inline void *memchr(const void *cs
, int c
, size_t count
)
534 /* Someone else can optimize this, I don't care - tonym@mac.linux-m68k.org */
535 unsigned char *ret
= (unsigned char *)cs
;
536 for(;count
>0;count
--,ret
++)
537 if(*ret
== c
) return ret
;
542 #endif /* _M68K_STRING_H_ */