root/include/asm-m68k/string.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. strcpy
  2. strncpy
  3. strcat
  4. strncat
  5. strchr
  6. strpbrk
  7. strspn
  8. strtok
  9. strlen
  10. strcmp
  11. strncmp
  12. memset
  13. memmove

   1 #ifndef _M68K_STRING_H_
   2 #define _M68K_STRING_H_
   3 
   4 #define __HAVE_ARCH_STRCPY
   5 extern inline char * strcpy(char * dest,const char *src)
     /* [previous][next][first][last][top][bottom][index][help] */
   6 {
   7   char *xdest = dest;
   8 
   9   __asm__ __volatile__
  10        ("1:\tmoveb %1@+,%0@+\n\t"
  11         "jne 1b"
  12         : "=a" (dest), "=a" (src)
  13         : "0" (dest), "1" (src) : "memory");
  14   return xdest;
  15 }
  16 
  17 #define __HAVE_ARCH_STRNCPY
  18 extern inline char * strncpy(char *dest, const char *src, size_t n)
     /* [previous][next][first][last][top][bottom][index][help] */
  19 {
  20   char *xdest = dest;
  21 
  22   if (n == 0)
  23     return xdest;
  24 
  25   __asm__ __volatile__
  26        ("1:\tmoveb %1@+,%0@+\n\t"
  27         "jeq 2f\n\t"
  28         "subql #1,%2\n\t"
  29         "jne 1b\n\t"
  30         "2:"
  31         : "=a" (dest), "=a" (src), "=d" (n)
  32         : "0" (dest), "1" (src), "2" (n)
  33         : "memory");
  34   return xdest;
  35 }
  36 
  37 #define __HAVE_ARCH_STRCAT
  38 extern inline char * strcat(char * dest, const char * src)
     /* [previous][next][first][last][top][bottom][index][help] */
  39 {
  40         char *tmp = dest;
  41 
  42         while (*dest)
  43                 dest++;
  44         while ((*dest++ = *src++))
  45                 ;
  46 
  47         return tmp;
  48 }
  49 
  50 #define __HAVE_ARCH_STRNCAT
  51 extern inline char * strncat(char *dest, const char *src, size_t count)
     /* [previous][next][first][last][top][bottom][index][help] */
  52 {
  53         char *tmp = dest;
  54 
  55         if (count) {
  56                 while (*dest)
  57                         dest++;
  58                 while ((*dest++ = *src++)) {
  59                         if (--count == 0) {
  60                                 *dest++='\0';
  61                                 break;
  62                         }
  63                 }
  64         }
  65 
  66         return tmp;
  67 }
  68 
  69 #define __HAVE_ARCH_STRCHR
  70 extern inline char * strchr(const char * s, int c)
     /* [previous][next][first][last][top][bottom][index][help] */
  71 {
  72   const char ch = c;
  73   
  74   for(; *s != ch; ++s)
  75     if (*s == '\0')
  76       return( NULL );
  77   return( (char *) s);
  78 }
  79 
  80 #define __HAVE_ARCH_STRPBRK
  81 extern inline char * strpbrk(const char * cs,const char * ct)
     /* [previous][next][first][last][top][bottom][index][help] */
  82 {
  83   const char *sc1,*sc2;
  84   
  85   for( sc1 = cs; *sc1 != '\0'; ++sc1)
  86     for( sc2 = ct; *sc2 != '\0'; ++sc2)
  87       if (*sc1 == *sc2)
  88         return((char *) sc1);
  89   return( NULL );
  90 }
  91 
  92 #define __HAVE_ARCH_STRSPN
  93 extern inline size_t strspn(const char *s, const char *accept)
     /* [previous][next][first][last][top][bottom][index][help] */
  94 {
  95   const char *p;
  96   const char *a;
  97   size_t count = 0;
  98 
  99   for (p = s; *p != '\0'; ++p)
 100     {
 101       for (a = accept; *a != '\0'; ++a)
 102         if (*p == *a)
 103           break;
 104       if (*a == '\0')
 105         return count;
 106       else
 107         ++count;
 108     }
 109 
 110   return count;
 111 }
 112 
 113 #define __HAVE_ARCH_STRTOK
 114 extern inline char * strtok(char * s,const char * ct)
     /* [previous][next][first][last][top][bottom][index][help] */
 115 {
 116   char *sbegin, *send;
 117   
 118   sbegin  = s ? s : ___strtok;
 119   if (!sbegin) {
 120           return NULL;
 121   }
 122   sbegin += strspn(sbegin,ct);
 123   if (*sbegin == '\0') {
 124     ___strtok = NULL;
 125     return( NULL );
 126   }
 127   send = strpbrk( sbegin, ct);
 128   if (send && *send != '\0')
 129     *send++ = '\0';
 130   ___strtok = send;
 131   return (sbegin);
 132 }
 133 
 134 /* strstr !! */
 135 
 136 #define __HAVE_ARCH_STRLEN
 137 extern inline size_t strlen(const char * s)
     /* [previous][next][first][last][top][bottom][index][help] */
 138 {
 139   const char *sc;
 140   for (sc = s; *sc != '\0'; ++sc) ;
 141   return(sc - s);
 142 }
 143 
 144 /* strnlen !! */
 145 
 146 #define __HAVE_ARCH_STRCMP
 147 extern inline int strcmp(const char * cs,const char * ct)
     /* [previous][next][first][last][top][bottom][index][help] */
 148 {
 149   char __res;
 150 
 151   __asm__
 152        ("1:\tmoveb %0@+,%2\n\t" /* get *cs */
 153         "cmpb %1@+,%2\n\t"      /* compare a byte */
 154         "jne  2f\n\t"           /* not equal, break out */
 155         "tstb %2\n\t"           /* at end of cs? */
 156         "jne  1b\n\t"           /* no, keep going */
 157         "jra  3f\n\t"           /* strings are equal */
 158         "2:\tsubb %1@-,%2\n\t"  /* *cs - *ct */
 159         "3:"
 160         : "=a" (cs), "=a" (ct), "=d" (__res)
 161         : "0" (cs), "1" (ct));
 162   return __res;
 163 }
 164 
 165 #define __HAVE_ARCH_STRNCMP
 166 extern inline int strncmp(const char * cs,const char * ct,size_t count)
     /* [previous][next][first][last][top][bottom][index][help] */
 167 {
 168   char __res;
 169 
 170   if (!count)
 171     return 0;
 172   __asm__
 173        ("1:\tmovb %0@+,%3\n\t"          /* get *cs */
 174         "cmpb   %1@+,%3\n\t"            /* compare a byte */
 175         "jne    3f\n\t"                 /* not equal, break out */
 176         "tstb   %3\n\t"                 /* at end of cs? */
 177         "jeq    4f\n\t"                 /* yes, all done */
 178         "subql  #1,%2\n\t"              /* no, adjust count */
 179         "jne    1b\n\t"                 /* more to do, keep going */
 180         "2:\tmoveq #0,%3\n\t"           /* strings are equal */
 181         "jra    4f\n\t"
 182         "3:\tsubb %1@-,%3\n\t"          /* *cs - *ct */
 183         "4:"
 184         : "=a" (cs), "=a" (ct), "=d" (count), "=d" (__res)
 185         : "0" (cs), "1" (ct), "2" (count));
 186   return __res;
 187 }
 188 
 189 #define __HAVE_ARCH_MEMSET
 190 extern inline void * memset(void * s,int c,size_t count)
     /* [previous][next][first][last][top][bottom][index][help] */
 191 {
 192   void *xs = s;
 193   size_t temp;
 194 
 195   if (!count)
 196     return xs;
 197   c &= 0xff;
 198   if ((long) s & 1)
 199     {
 200       char *cs = s;
 201       *cs++ = c;
 202       s = cs;
 203       count--;
 204     }
 205   c |= c << 8;
 206   if (count > 2 && (long) s & 2)
 207     {
 208       short *ss = s;
 209       *ss++ = c;
 210       s = ss;
 211       count -= 2;
 212     }
 213   temp = count >> 2;
 214   if (temp)
 215     {
 216       long *ls = s;
 217       c |= c << 16;
 218       temp--;
 219       do
 220         *ls++ = c;
 221       while (temp--);
 222       s = ls;
 223     }
 224   if (count & 2)
 225     {
 226       short *ss = s;
 227       *ss++ = c;
 228       s = ss;
 229     }
 230   if (count & 1)
 231     {
 232       char *cs = s;
 233       *cs = c;
 234     }
 235   return xs;
 236 }
 237 
 238 #define __HAVE_ARCH_MEMCPY
 239 #define memcpy(to, from, n) \
 240 (__builtin_constant_p(n) ? \
 241  __builtin_memcpy((to),(from),(n)) : \
 242  memcpy((to),(from),(n)))
 243 
 244 #define __HAVE_ARCH_MEMMOVE
 245 extern inline void * memmove(void * dest,const void * src, size_t n)
     /* [previous][next][first][last][top][bottom][index][help] */
 246 {
 247   void *xdest = dest;
 248   size_t temp;
 249 
 250   if (!n)
 251     return xdest;
 252 
 253   if (dest < src)
 254     {
 255       if ((long) dest & 1)
 256         {
 257           char *cdest = dest;
 258           const char *csrc = src;
 259           *cdest++ = *csrc++;
 260           dest = cdest;
 261           src = csrc;
 262           n--;
 263         }
 264       if (n > 2 && (long) dest & 2)
 265         {
 266           short *sdest = dest;
 267           const short *ssrc = src;
 268           *sdest++ = *ssrc++;
 269           dest = sdest;
 270           src = ssrc;
 271           n -= 2;
 272         }
 273       temp = n >> 2;
 274       if (temp)
 275         {
 276           long *ldest = dest;
 277           const long *lsrc = src;
 278           temp--;
 279           do
 280             *ldest++ = *lsrc++;
 281           while (temp--);
 282           dest = ldest;
 283           src = lsrc;
 284         }
 285       if (n & 2)
 286         {
 287           short *sdest = dest;
 288           const short *ssrc = src;
 289           *sdest++ = *ssrc++;
 290           dest = sdest;
 291           src = ssrc;
 292         }
 293       if (n & 1)
 294         {
 295           char *cdest = dest;
 296           const char *csrc = src;
 297           *cdest = *csrc;
 298         }
 299     }
 300   else
 301     {
 302       dest = (char *) dest + n;
 303       src = (const char *) src + n;
 304       if ((long) dest & 1)
 305         {
 306           char *cdest = dest;
 307           const char *csrc = src;
 308           *--cdest = *--csrc;
 309           dest = cdest;
 310           src = csrc;
 311           n--;
 312         }
 313       if (n > 2 && (long) dest & 2)
 314         {
 315           short *sdest = dest;
 316           const short *ssrc = src;
 317           *--sdest = *--ssrc;
 318           dest = sdest;
 319           src = ssrc;
 320           n -= 2;
 321         }
 322       temp = n >> 2;
 323       if (temp)
 324         {
 325           long *ldest = dest;
 326           const long *lsrc = src;
 327           temp--;
 328           do
 329             *--ldest = *--lsrc;
 330           while (temp--);
 331           dest = ldest;
 332           src = lsrc;
 333         }
 334       if (n & 2)
 335         {
 336           short *sdest = dest;
 337           const short *ssrc = src;
 338           *--sdest = *--ssrc;
 339           dest = sdest;
 340           src = ssrc;
 341         }
 342       if (n & 1)
 343         {
 344           char *cdest = dest;
 345           const char *csrc = src;
 346           *--cdest = *--csrc;
 347         }
 348     }
 349   return xdest;
 350 }
 351 
 352 #define __HAVE_ARCH_MEMCMP
 353 #define memcmp(cs, ct, n) \
 354 (__builtin_constant_p(n) ? \
 355  __builtin_memcmp((cs),(ct),(n)) : \
 356  memcmp((cs),(ct),(n)))
 357 
 358 #endif /* _M68K_STRING_H_ */

/* [previous][next][first][last][top][bottom][index][help] */