root/include/asm-sparc/string.h

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

INCLUDED FROM


DEFINITIONS

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

   1 /* string.h: External definitions for optimized assembly string
   2              routines for the Linux Kernel.
   3 
   4    Copyright (C) 1994 David S. Miller (davem@caip.rutgers.edu)
   5 */
   6 
   7 extern inline size_t strlen(const char * str)
     /* [previous][next][first][last][top][bottom][index][help] */
   8 {
   9   register size_t retval = 0;
  10   register char tmp = 0;
  11   register char * lstr;
  12 
  13   lstr = (char *) str;
  14 
  15   __asm__("ldub [%1], %2\n\t"
  16           "or %%g0, %%g0, %0\n\t"
  17           "orcc %2, %%g0, %%g0\n\t"
  18           "be 2f\n\t"
  19           "add %1, 0x1, %1\n\t"
  20           "1: ldub [%1], %2\n\t"
  21           "add %0, 0x1, %0\n\t"
  22           "orcc %2, %%g0, %%g0\n\t"
  23           "bne 1b\n\t"
  24           "add %1, 0x1, %1\n\t"
  25           "2:" :
  26           "=r" (retval), "=r" (lstr), "=r" (tmp) :
  27           "0" (retval), "1" (lstr), "2" (tmp));
  28 
  29   return retval;
  30 }
  31 
  32 extern __inline__ int strcmp(const char* str1, const char* str2)
     /* [previous][next][first][last][top][bottom][index][help] */
  33 {
  34   register unsigned int tmp1=0, tmp2=0;
  35   register int retval=0;
  36 
  37   __asm__("ldub [%1], %3\n\t"
  38           "ldub [%2], %4\n\t"
  39           "1: add %2, 0x1, %2\n\t"
  40           "cmp %3, %4\n\t"
  41           "bne,a 2f\n\t"
  42           "sub %2, 0x1, %2\n\t"
  43           "ldub [%1], %3\n\t"
  44           "add %1, 0x1, %1\n\t"
  45           "cmp %3, 0x0\n\t"
  46           "bne,a 1b\n\t"
  47           "ldub [%2], %4\n\t"
  48           "b 3f\n\t"
  49           "or %%g0, %%g0, %0\n\t"
  50           "2: ldub [%1], %3\n\t"
  51           "ldub [%2], %4\n\t"
  52           "sub %3, %4, %0\n\t"
  53           "3: \n\t" :
  54           "=r" (retval), "=r" (str1), "=r" (str2), "=r" (tmp1), "=r" (tmp2) :
  55           "0" (retval), "1" (str1), "2" (str2),
  56           "3" (tmp1), "4" (tmp2));
  57 
  58   return retval;
  59 }
  60 
  61 extern __inline__ int strncmp(const char* str1, const char* str2, size_t strlen)
     /* [previous][next][first][last][top][bottom][index][help] */
  62 {
  63   register int retval=0;
  64 
  65   __asm__("cmp %3, 0x0\n\t"
  66           "be 2f\n\t"
  67           "ldub [%2], %%g3\n\t"
  68           "1: ldub [%1], %%g2\n\t"
  69           "sub %%g2, %%g3, %0\n\t"
  70           "cmp %0, 0x0\n\t"
  71           "bne 2f\n\t"
  72           "add %2, 0x1, %2\n\t"
  73           "cmp %%g2, 0x0\n\t"
  74           "be 2f\n\t"
  75           "add %1, 0x1, %1\n\t"
  76           "addcc %3, -1, %3\n\t"
  77           "bne,a 1b\n\t"
  78           "ldub [%2], %%g3\n\t"
  79           "2: " :
  80           "=r" (retval), "=r" (str1), "=r" (str2), "=r" (strlen) :
  81           "0" (retval), "1" (str1), "2" (str2), "3" (strlen) :
  82           "%g2", "%g3");
  83 
  84   return retval;
  85 }
  86 
  87 
  88 extern __inline__ char *strcpy(char* dest, const char* source)
     /* [previous][next][first][last][top][bottom][index][help] */
  89 {
  90   register char tmp;
  91   register char *retval;
  92 
  93   __asm__("or %%g0, %2, %0\n\t"
  94           "ldub [%1], %3\n\t"
  95           "1: stb %3, [%2]\n\t"
  96           "cmp %3, 0x0\n\t"
  97           "bne,a 1b\n\t"
  98           "ldub [%1], %3\n\t" :
  99           "=r" (retval), "=r" (source), "=r" (dest), "=r" (tmp) :
 100           "0" (retval), "1" (source), "2" (dest), "3" (tmp));
 101 
 102   return retval;
 103 }
 104 
 105 extern __inline__ char *strncpy(char *dest, const char *source, size_t cpylen)
     /* [previous][next][first][last][top][bottom][index][help] */
 106 {
 107   register char tmp;
 108   register char *retval;
 109 
 110   __asm__("or %%g0, %1, %0\n\t"
 111           "1: cmp %4, 0x0\n\t"
 112           "be 2f\n\t"
 113           "ldub [%1], %3\n\t"
 114           "add %1, 0x1, %1\n\t"
 115           "stb %3, [%2]\n\t"
 116           "sub %4, 0x1, %4\n\t"
 117           "ba 1\n\t"
 118           "add %2, 0x1, %2\n\t" :
 119           "=r" (retval), "=r" (dest), "=r" (source), "=r"(tmp), "=r" (cpylen) :
 120           "0" (retval), "1" (dest), "2" (source), 
 121           "3" (tmp), "4" (cpylen));
 122 
 123   return retval;
 124 }
 125 
 126 extern __inline__ char *strcat(char *dest, const char *src)
     /* [previous][next][first][last][top][bottom][index][help] */
 127 {
 128   register char *retval;
 129   register char temp=0;
 130 
 131   __asm__("or %%g0, %1, %0\n\t"
 132           "1: ldub [%1], %3\n\t"
 133           "cmp %3, 0x0\n\t"
 134           "bne,a 1b\n\t"
 135           "add %1, 0x1, %1\n\t"
 136           "2: ldub [%2], %3\n\t"
 137           "stb %3, [%1]\n\t"
 138           "add %1, 0x1, %1\n\t"
 139           "cmp %3, 0x0\n\t"
 140           "bne 2b\n\t"
 141           "add %2, 0x1, %2\n\t" :
 142           "=r" (retval), "=r" (dest), "=r" (src), "=r" (temp) :
 143           "0" (retval), "1" (dest), "2" (src), "3" (temp));
 144 
 145   return retval;
 146 }
 147 
 148 extern __inline__ char *strncat(char *dest, const char *src, size_t len)
     /* [previous][next][first][last][top][bottom][index][help] */
 149 {
 150   register char *retval;
 151   register char temp=0;
 152 
 153   __asm__("or %%g0, %1, %0\n\t"
 154           "1: ldub [%1], %3\n\t"
 155           "cmp %3, 0x0\n\t"
 156           "bne,a 1b\n\t"
 157           "add %1, 0x1, %1\n\t"
 158           "2: ldub [%2], %3\n\t"
 159           "stb %3, [%1]\n\t"
 160           "add %1, 0x1, %1\n\t"
 161           "add %3, -1, %3\n\t"
 162           "cmp %3, 0x0\n\t"
 163           "bne 2b\n\t"
 164           "add %2, 0x1, %2\n\t" :
 165           "=r" (retval), "=r" (dest), "=r" (src), "=r" (len), "=r" (temp) :
 166           "0" (retval), "1" (dest), "2" (src), "3" (len), "4" (temp));
 167 
 168   return retval;
 169 }
 170 
 171 extern __inline__ char *strchr(const char *src, int c)
     /* [previous][next][first][last][top][bottom][index][help] */
 172 {
 173   register char temp=0;
 174   register char *trick=0;
 175 
 176   __asm__("1: ldub [%0], %2\n\t"
 177           "cmp %2, %1\n\t"
 178           "bne,a 1b\n\t"
 179           "add %0, 0x1, %0\n\t"
 180           "or %%g0, %0, %3\n\t" :
 181           "=r" (src), "=r" (c), "=r" (temp), "=r" (trick), "=r" (src) :
 182           "0" (src), "1" (c), "2" (temp), "3" (trick), "4" (src));
 183 
 184   return trick;
 185 }
 186 
 187 extern __inline__ char *strpbrk(const char *cs, const char *ct)
     /* [previous][next][first][last][top][bottom][index][help] */
 188 {
 189   register char temp1, temp2;
 190   register char *scratch;
 191   register char *trick;
 192 
 193   __asm__("or %%g0, %1, %4\n\t"
 194           "1: ldub [%0], %2\n\t"
 195           "2: ldub [%1], %3\n\t"
 196           "cmp %3, %2\n\t"
 197           "be 3f\n\t"
 198           "nop\n\t"
 199           "cmp %3, 0x0\n\t"
 200           "bne 2b\n\t"
 201           "add %1, 0x1, %1\n\t"
 202           "or %%g0, %4, %1\n\t"
 203           "b 1b\n\t"
 204           "add %0, 0x1, %0\n\t"
 205           "or %%g0, %0, %5\n\t" :
 206           "=r" (cs) :
 207           "r" (ct), "r" (temp1), "r" (temp2), "r" (scratch), "r" (trick=0),
 208           "0" (cs), "1" (ct));
 209 
 210   return trick;
 211 
 212 }
 213 
 214       
 215 extern __inline__ size_t strspn(const char *s, const char *accept)
     /* [previous][next][first][last][top][bottom][index][help] */
 216 {
 217   register char temp1, temp2;
 218   register char* scratch;
 219   register size_t trick;
 220 
 221   __asm__("or %%g0, %1, %4\n\t"
 222           "1: ldub [%0], %2\n\t"
 223           "2: ldub [%1], %3\n\t"
 224           "cmp %3, 0x0\n\t"
 225           "be 3f\n\t"
 226           "cmp %3, %2"
 227           "bne 2b\n\t"
 228           "add %1, 0x1, %1\n\t"
 229           "add %0, 0x1, %0\n\t"
 230           "b 1b\n\t"
 231           "add %5, 0x1, %5\n\t"
 232           "3: or %%g0, %0, %4\n\t" :
 233           "=r" (s) :
 234           "r" (accept), "r" (temp1), "r" (temp2), 
 235           "r" (scratch), "r" (trick=0), "0" (s));
 236 
 237   return trick;
 238 
 239 }
 240 
 241 extern __inline__ char *strtok(char *s, const char *ct)
     /* [previous][next][first][last][top][bottom][index][help] */
 242 {
 243   static char* old; /* frob this kludge for now */
 244   register char *tok;
 245 
 246   if (s == (char *) 0)
 247     {
 248       if (old == (char *) 0)
 249         {
 250           return (char *) 0;
 251         }
 252       else
 253         s = old;
 254     }
 255 
 256   s += strspn(s, ct);
 257   if(*s == '\0')
 258     {
 259       old = (char *) 0;
 260       return (char *) 0;
 261     }
 262 
 263   tok = s;
 264   s = strpbrk(tok, ct);
 265   if (s == (char *) 0)
 266     old = (char *) 0;
 267   else
 268     {
 269       *s = '\0';
 270       old = s + 1;
 271     }
 272   return tok;
 273 }
 274         
 275 
 276 extern __inline__ void *memset(void *src, int c, size_t count)
     /* [previous][next][first][last][top][bottom][index][help] */
 277 {
 278   register void *retval;
 279 
 280   __asm__("or %%g0, %1, %0\n\t"
 281           "1: add %1, 0x1, %1\n\t"
 282           "2: add %3, -1, %3\n\t"
 283           "cmp %3, -1\n\t"
 284           "bne,a 1b\n\t"
 285           "stb %2, [%1]\n\t" :
 286           "=r" (retval), "=r" (src), "=r" (c), "=r" (count) :
 287           "0" (retval), "1" (src), "2" (c), "3" (count));
 288 
 289   return retval;
 290 }
 291 
 292 extern __inline__ void *memcpy(void *dest, const void *src, size_t count)
     /* [previous][next][first][last][top][bottom][index][help] */
 293 {
 294   register void *retval;
 295   register char tmp;
 296 
 297   __asm__("or %%g0, %1, %0\n\t"
 298           "add %3, -1, %3\n\t"
 299           "cmp %3, -1\n\t"
 300           "be 2f\n\t"
 301           "1: ldub [%2], %4\n\t"
 302           "add %2, 0x1, %2\n\t"
 303           "add %3, -1, %3\n\t"
 304           "cmp %3, -1\n\t"
 305           "stb %4, [%1]\n\t"
 306           "bne 1b\n\t"
 307           "add %1, 0x1, %1\n\t"
 308           "2: " :
 309           "=r" (retval), "=r" (dest), "=r" (src), "=r" (count), "=r" (tmp) :
 310           "0" (retval), "1" (dest), "2" (src), "3" (count), "4" (tmp));
 311 
 312   return retval;
 313 }
 314 
 315 extern __inline__ void *memmove(void *dest, const void *src, size_t count)
     /* [previous][next][first][last][top][bottom][index][help] */
 316 {
 317   register void *retval;
 318   register char tmp;
 319 
 320   __asm__("or %%g0, %1, %1\n\t"
 321           "add %3, -1, %3\n\t"
 322           "cmp %3, -1\n\t"
 323           "be 2f\n\t"
 324           "1: ldub [%2], %4\n\t"
 325           "add %2, 0x1, %2\n\t"
 326           "add %3, -1, %3\n\t"
 327           "cmp %3, -1\n\t"
 328           "stb %4, [%1]\n\t"
 329           "bne 1b\n\t"
 330           "add %1, 0x1, %1\n\t"
 331           "2: " :
 332           "=r" (retval), "=r" (dest), "=r" (src), "=r" (count), "=r" (tmp) :
 333           "0" (retval), "1" (dest), "2" (src), "3" (count), "4" (tmp));
 334 
 335   return retval;
 336 }
 337 
 338 extern __inline__ int memcmp(const void *cs, const void *ct, size_t count)
     /* [previous][next][first][last][top][bottom][index][help] */
 339 {
 340   register int retval;
 341   register unsigned long tmp1, tmp2;
 342 
 343   __asm__("or %%g0, %1, %0\n\t"
 344           "cmp %3, 0x0\n\t"
 345           "ble,a 3f\n\t"
 346           "or %%g0, %%g0, %0\n\t"
 347           "1: ldub [%1], %4\n\t"
 348           "ldub [%2], %5\n\t"
 349           "cmp %4, %5\n\t"
 350           "be,a 2f\n\t"
 351           "add %1, 0x1, %1\n\t"
 352           "bgeu 3f\n\t"
 353           "or %%g0, 0x1, %0\n\t"
 354           "b 3f\n\t"
 355           "or %%g0, -1, %0\n\t"
 356           "2: add %3, -1, %3\n\t"
 357           "cmp %3, 0x0\n\t"
 358           "bg 1b\n\t"
 359           "add %2, 0x1, %2\n\t"
 360           "or %%g0, %%g0, %0\n\t"
 361           "3: " :
 362           "=r" (retval) :
 363           "r" (cs), "r" (ct), "r" (count), "r" (tmp1=0), "r" (tmp2=0));
 364 
 365   return retval;
 366 }
 367 

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