root/include/asm-mips/string.h

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. strcpy
  2. strncpy
  3. strcmp
  4. strncmp
  5. memset
  6. memcpy
  7. memmove
  8. memscan

   1 /*
   2  * include/asm-mips/string.h
   3  *
   4  * This file is subject to the terms and conditions of the GNU General Public
   5  * License.  See the file "COPYING" in the main directory of this archive
   6  * for more details.
   7  *
   8  * Copyright (c) 1994, 1995  Waldorf Electronics
   9  * written by Ralf Baechle
  10  */
  11 
  12 #ifndef __ASM_MIPS_STRING_H
  13 #define __ASM_MIPS_STRING_H
  14 
  15 #include <asm/mipsregs.h>
  16 
  17 extern __inline__ char * strcpy(char * dest, const char *src)
     /* [previous][next][first][last][top][bottom][index][help] */
  18 {
  19   char *xdest = dest;
  20 
  21   __asm__ __volatile__(
  22         ".set\tnoreorder\n\t"
  23         ".set\tnoat\n"
  24         "1:\tlbu\t$1,(%1)\n\t"
  25         "addiu\t%1,%1,1\n\t"
  26         "sb\t$1,(%0)\n\t"
  27         "bnez\t$1,1b\n\t"
  28         "addiu\t%0,%0,1\n\t"
  29         ".set\tat\n\t"
  30         ".set\treorder"
  31         : "=r" (dest), "=r" (src)
  32         : "0" (dest), "1" (src)
  33         : "$1","memory");
  34 
  35   return xdest;
  36 }
  37 
  38 extern __inline__ char * strncpy(char *dest, const char *src, size_t n)
     /* [previous][next][first][last][top][bottom][index][help] */
  39 {
  40   char *xdest = dest;
  41 
  42   if (n == 0)
  43     return xdest;
  44 
  45   __asm__ __volatile__(
  46         ".set\tnoreorder\n\t"
  47         ".set\tnoat\n"
  48         "1:\tlbu\t$1,(%1)\n\t"
  49         "subu\t%2,%2,1\n\t"
  50         "sb\t$1,(%0)\n\t"
  51         "beqz\t$1,2f\n\t"
  52         "addiu\t%0,%0,1\n\t"
  53         "bnez\t%2,1b\n\t"
  54         "addiu\t%1,%1,1\n"
  55         "2:\n\t"
  56         ".set\tat\n\t"
  57         ".set\treorder\n\t"
  58         : "=r" (dest), "=r" (src), "=r" (n)
  59         : "0" (dest), "1" (src), "2" (n)
  60         : "$1","memory");
  61 
  62   return dest;
  63 }
  64 
  65 extern __inline__ int strcmp(const char * cs, const char * ct)
     /* [previous][next][first][last][top][bottom][index][help] */
  66 {
  67   int __res;
  68 
  69   __asm__ __volatile__(
  70         ".set\tnoreorder\n\t"
  71         ".set\tnoat\n\t"
  72         "lbu\t%2,(%0)\n"
  73         "1:\tlbu\t$1,(%1)\n\t"
  74         "addiu\t%0,%0,1\n\t"
  75         "bne\t$1,%2,2f\n\t"
  76         "addiu\t%1,%1,1\n\t"
  77         "bnez\t%2,1b\n\t"
  78         "lbu\t%2,(%0)\n\t"
  79         STR(FILL_LDS) "\n\t"
  80         "move\t%2,$1\n"
  81         "2:\tsub\t%2,%2,$1\n"
  82         "3:\t.set\tat\n\t"
  83         ".set\treorder\n\t"
  84         : "=d" (cs), "=d" (ct), "=d" (__res)
  85         : "0" (cs), "1" (ct)
  86         : "$1");
  87 
  88   return __res;
  89 }
  90 
  91 extern __inline__ int strncmp(const char * cs, const char * ct, size_t count)
     /* [previous][next][first][last][top][bottom][index][help] */
  92 {
  93   char __res;
  94 
  95   __asm__ __volatile__(
  96         ".set\tnoreorder\n\t"
  97         ".set\tnoat\n"
  98         "1:\tlbu\t%3,(%0)\n\t"
  99         "beqz\t%2,2f\n\t"
 100         "lbu\t$1,(%1)\n\t"
 101         "addiu\t%2,%2,-1\n\t"
 102         "bne\t$1,%3,3f\n\t"
 103         "addiu\t%0,%0,1\n\t"
 104         "bnez\t%3,1b\n\t"
 105         "addiu\t%1,%1,1\n"
 106         "2:\tmove\t%3,$1\n"
 107         "3:\tsub\t%3,%3,$1\n\t"
 108         ".set\tat\n\t"
 109         ".set\treorder"
 110         : "=d" (cs), "=d" (ct), "=d" (count), "=d" (__res)
 111         : "0" (cs), "1" (ct), "2" (count)
 112         : "$1");
 113 
 114   return __res;
 115 }
 116 
 117 extern __inline__ void * memset(void * s, int c, size_t count)
     /* [previous][next][first][last][top][bottom][index][help] */
 118 {
 119   void *xs = s;
 120 
 121   if (!count)
 122     return xs;
 123   __asm__ __volatile__(
 124         ".set\tnoreorder\n"
 125         "1:\tsb\t%3,(%0)\n\t"
 126         "bne\t%0,%1,1b\n\t"
 127         "addiu\t%0,%0,1\n\t"
 128         ".set\treorder"
 129         : "=r" (s), "=r" (count)
 130         : "0" (s), "r" (c), "1" (s + count - 1)
 131         : "memory");
 132 
 133   return xs;
 134 }
 135 
 136 extern __inline__ void * memcpy(void * to, const void * from, size_t n)
     /* [previous][next][first][last][top][bottom][index][help] */
 137 {
 138   void *xto = to;
 139 
 140   if (!n)
 141     return xto;
 142   __asm__ __volatile__(
 143         ".set\tnoreorder\n\t"
 144         ".set\tnoat\n"
 145         "1:\tlbu\t$1,(%1)\n\t"
 146         "addiu\t%1,%1,1\n\t"
 147         "sb\t$1,(%0)\n\t"
 148         "subu\t%2,%2,1\n\t"
 149         "bnez\t%2,1b\n\t"
 150         "addiu\t%0,%0,1\n\t"
 151         ".set\tat\n\t"
 152         ".set\treorder"
 153         : "=r" (to), "=r" (from), "=r" (n)
 154         : "0" (to), "1" (from), "2" (n)
 155         : "$1","memory" );
 156   return xto;
 157 }
 158 
 159 extern __inline__ void * memmove(void * dest,const void * src, size_t n)
     /* [previous][next][first][last][top][bottom][index][help] */
 160 {
 161   void *xdest = dest;
 162 
 163   if (!n)
 164     return xdest;
 165 
 166   if (dest < src)
 167     __asm__ __volatile__(
 168         ".set\tnoreorder\n\t"
 169         ".set\tnoat\n"
 170         "1:\tlbu\t$1,(%1)\n\t"
 171         "addiu\t%1,%1,1\n\t"
 172         "sb\t$1,(%0)\n\t"
 173         "subu\t%2,%2,1\n\t"
 174         "bnez\t%2,1b\n\t"
 175         "addiu\t%0,%0,1\n\t"
 176         ".set\tat\n\t"
 177         ".set\treorder"
 178         : "=r" (dest), "=r" (src), "=r" (n)
 179         : "0" (dest), "1" (src), "2" (n)
 180         : "$1","memory" );
 181   else
 182     __asm__ __volatile__(
 183         ".set\tnoreorder\n\t"
 184         ".set\tnoat\n"
 185         "1:\tlbu\t$1,-1(%1)\n\t"
 186         "subu\t%1,%1,1\n\t"
 187         "sb\t$1,-1(%0)\n\t"
 188         "subu\t%2,%2,1\n\t"
 189         "bnez\t%2,1b\n\t"
 190         "subu\t%0,%0,1\n\t"
 191         ".set\tat\n\t"
 192         ".set\treorder"
 193         : "=r" (dest), "=r" (src), "=r" (n)
 194         : "0" (dest+n), "1" (src+n), "2" (n)
 195         : "$1","memory" );
 196   return xdest;
 197 }
 198 
 199 extern __inline__ void * memscan(void * addr, int c, size_t size)
     /* [previous][next][first][last][top][bottom][index][help] */
 200 {
 201         if (!size)
 202                 return addr;
 203         __asm__(".set\tnoreorder\n\t"
 204                 ".set\tnoat\n"
 205                 "1:\tbeq\t$0,%1,2f\n\t"
 206                 "lbu\t$1,(%0)\n\t"
 207                 "subu\t%1,%1,1\n\t"
 208                 "bnez\t%1,1b\n\t"
 209                 "addiu\t%0,%0,1\n\t"
 210                 ".set\tat\n\t"
 211                 ".set\treorder\n"
 212                 "2:"
 213                 : "=r" (addr), "=r" (size)
 214                 : "0" (addr), "1" (size), "r" (c)
 215                 : "$1");
 216 
 217         return addr;
 218 }
 219 
 220 #endif /* __ASM_MIPS_STRING_H */

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