home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / KERNEL-S / V1.2 / LINUX-1.2 / LINUX-1 / linux / include / asm-m68k / string.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-07  |  3.5 KB  |  155 lines

  1. #ifndef _M68K_STRING_H_
  2. #define _M68K_STRING_H_
  3.  
  4. #define __USE_PORTABLE_STRINGS_H_
  5.  
  6. extern inline char * strcpy(char * dest,const char *src)
  7. {
  8.   char *xdest = dest;
  9.  
  10.   __asm__ __volatile__
  11.        ("1:\tmoveb %1@+,%0@+\n\t"
  12.         "bne 1b"
  13.     : "=a" (dest), "=a" (src)
  14.         : "0" (dest), "1" (src) : "memory");
  15.   return xdest;
  16. }
  17.  
  18. extern inline char * strncpy(char *dest, const char *src, size_t n)
  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.     "beq 2f\n\t"
  28.         "subql #1,%2\n\t"
  29.         "bne 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 __USE_PORTABLE_strcat
  38.  
  39. #define __USE_PORTABLE_strncat
  40.  
  41. extern inline int strcmp(const char * cs,const char * ct)
  42. {
  43.   char __res;
  44.  
  45.   __asm__
  46.        ("1:\tmoveb %0@+,%2\n\t" /* get *cs */
  47.         "cmpb %1@+,%2\n\t"      /* compare a byte */
  48.         "bne  2f\n\t"           /* not equal, break out */
  49.         "tstb %2\n\t"           /* at end of cs? */
  50.         "bne  1b\n\t"           /* no, keep going */
  51.         "bra  3f\n\t"        /* strings are equal */
  52.         "2:\tsubb %1@-,%2\n\t"  /* *cs - *ct */
  53.         "3:"
  54.         : "=a" (cs), "=a" (ct), "=d" (__res)
  55.         : "0" (cs), "1" (ct));
  56.   return __res;
  57. }
  58.  
  59. extern inline int strncmp(const char * cs,const char * ct,size_t count)
  60. {
  61.   char __res;
  62.  
  63.   if (!count)
  64.     return 0;
  65.   __asm__
  66.        ("1:\tmovb %0@+,%3\n\t"          /* get *cs */
  67.         "cmpb   %1@+,%3\n\t"            /* compare a byte */
  68.         "bne    3f\n\t"                 /* not equal, break out */
  69.         "tstb   %3\n\t"                 /* at end of cs? */
  70.         "beq    4f\n\t"                 /* yes, all done */
  71.         "subql  #1,%2\n\t"              /* no, adjust count */
  72.         "bne    1b\n\t"                 /* more to do, keep going */
  73.         "2:\tmoveq #0,%3\n\t"           /* strings are equal */
  74.         "bra    4f\n\t"
  75.         "3:\tsubb %1@-,%3\n\t"          /* *cs - *ct */
  76.         "4:"
  77.         : "=a" (cs), "=a" (ct), "=d" (count), "=d" (__res)
  78.         : "0" (cs), "1" (ct), "2" (count));
  79.   return __res;
  80. }
  81.  
  82. #define __USE_PORTABLE_strchr
  83.  
  84. #define __USE_PORTABLE_strlen
  85.  
  86. #define __USE_PORTABLE_strspn
  87.  
  88. #define __USE_PORTABLE_strpbrk
  89.  
  90. #define __USE_PORTABLE_strtok
  91.  
  92. extern inline void * memset(void * s,char c,size_t count)
  93. {
  94.   void *xs = s;
  95.  
  96.   if (!count)
  97.     return xs;
  98.   __asm__ __volatile__
  99.        ("1:\tmoveb %3,%0@+\n\t"
  100.     "subql #1,%1\n\t"
  101.         "bne 1b"
  102.     : "=a" (s), "=d" (count)
  103.         : "0" (s), "d" (c), "1" (count)
  104.     : "memory");
  105.   return xs;
  106. }
  107.  
  108. extern inline void * memcpy(void * to, const void * from, size_t n)
  109. {
  110.   void *xto = to;
  111.  
  112.   if (!n)
  113.     return xto;
  114.   __asm__ __volatile__
  115.        ("1:\tmoveb %1@+,%0@+\n\t"
  116.     "subql #1,%2\n\t"
  117.         "bne 1b"
  118.         : "=a" (to), "=a" (from), "=d" (n)
  119.         : "0" (to), "1" (from), "2" (n)
  120.         : "memory" );
  121.   return xto;
  122. }
  123.  
  124. extern inline void * memmove(void * dest,const void * src, size_t n)
  125. {
  126.   void *xdest = dest;
  127.  
  128.   if (!n)
  129.     return xdest;
  130.  
  131.   if (dest < src)
  132.     __asm__ __volatile__
  133.        ("1:\tmoveb %1@+,%0@+\n\t"
  134.     "subql #1,%2\n\t"
  135.         "bne 1b"
  136.         : "=a" (dest), "=a" (src), "=d" (n)
  137.         : "0" (dest), "1" (src), "2" (n)
  138.         : "memory" );
  139.   else
  140.     __asm__ __volatile__
  141.        ("1:\tmoveb %1@-,%0@-\n\t"
  142.     "subql #1,%2\n\t"
  143.         "bne 1b"
  144.         : "=a" (dest), "=a" (src), "=d" (n)
  145.         : "0" (dest+n), "1" (src+n), "2" (n)
  146.         : "memory" );
  147.   return xdest;
  148. }
  149.  
  150. #define __USE_PORTABLE_memcmp
  151.  
  152. #define __USE_PORTABLE_memscan
  153.  
  154. #endif /* _M68K_STRING_H_ */
  155.