Import 2.3.12pre3
[davej-history.git] / include / asm-mips / string.h
blobcc4e79a17a8930e58bdeb0937c3a05cf461d256d
1 /* $Id: string.h,v 1.6 1998/07/20 17:52:21 ralf Exp $
3 * This file is subject to the terms and conditions of the GNU General Public
4 * License. See the file "COPYING" in the main directory of this archive
5 * for more details.
7 * Copyright (c) 1994, 1995, 1996, 1997, 1998 by Ralf Baechle
8 */
9 #ifndef __ASM_MIPS_STRING_H
10 #define __ASM_MIPS_STRING_H
12 #define __HAVE_ARCH_STRCPY
13 extern __inline__ char *strcpy(char *__dest, __const__ char *__src)
15 char *__xdest = __dest;
17 __asm__ __volatile__(
18 ".set\tnoreorder\n\t"
19 ".set\tnoat\n"
20 "1:\tlbu\t$1,(%1)\n\t"
21 "addiu\t%1,1\n\t"
22 "sb\t$1,(%0)\n\t"
23 "bnez\t$1,1b\n\t"
24 "addiu\t%0,1\n\t"
25 ".set\tat\n\t"
26 ".set\treorder"
27 : "=r" (__dest), "=r" (__src)
28 : "0" (__dest), "1" (__src)
29 : "$1","memory");
31 return __xdest;
34 #define __HAVE_ARCH_STRNCPY
35 extern __inline__ char *strncpy(char *__dest, __const__ char *__src, size_t __n)
37 char *__xdest = __dest;
39 if (__n == 0)
40 return __xdest;
42 __asm__ __volatile__(
43 ".set\tnoreorder\n\t"
44 ".set\tnoat\n"
45 "1:\tlbu\t$1,(%1)\n\t"
46 "subu\t%2,1\n\t"
47 "sb\t$1,(%0)\n\t"
48 "beqz\t$1,2f\n\t"
49 "addiu\t%0,1\n\t"
50 "bnez\t%2,1b\n\t"
51 "addiu\t%1,1\n"
52 "2:\n\t"
53 ".set\tat\n\t"
54 ".set\treorder"
55 : "=r" (__dest), "=r" (__src), "=r" (__n)
56 : "0" (__dest), "1" (__src), "2" (__n)
57 : "$1","memory");
59 return __dest;
62 #define __HAVE_ARCH_STRCMP
63 extern __inline__ int strcmp(__const__ char *__cs, __const__ char *__ct)
65 int __res;
67 __asm__ __volatile__(
68 ".set\tnoreorder\n\t"
69 ".set\tnoat\n\t"
70 "lbu\t%2,(%0)\n"
71 "1:\tlbu\t$1,(%1)\n\t"
72 "addiu\t%0,1\n\t"
73 "bne\t$1,%2,2f\n\t"
74 "addiu\t%1,1\n\t"
75 "bnez\t%2,1b\n\t"
76 "lbu\t%2,(%0)\n\t"
77 #if _MIPS_ISA == _MIPS_ISA_MIPS1
78 "nop\n\t"
79 #endif
80 "move\t%2,$1\n"
81 "2:\tsubu\t%2,$1\n"
82 "3:\t.set\tat\n\t"
83 ".set\treorder"
84 : "=r" (__cs), "=r" (__ct), "=r" (__res)
85 : "0" (__cs), "1" (__ct)
86 : "$1");
88 return __res;
91 #define __HAVE_ARCH_STRNCMP
92 extern __inline__ int strncmp(__const__ char *__cs, __const__ char *__ct, size_t __count)
94 int __res;
96 __asm__ __volatile__(
97 ".set\tnoreorder\n\t"
98 ".set\tnoat\n"
99 "1:\tlbu\t%3,(%1)\n\t"
100 "beqz\t%2,2f\n\t"
101 "lbu\t$1,(%0)\n\t"
102 "addiu\t%1,1\n\t"
103 "subu\t%3,$1,%3\n\t"
104 "bnez\t%3,2f\n\t"
105 "addiu\t%0,1\n\t"
106 "bnez\t%1,1b\n"
107 "addiu\t%2,-1\n"
108 "2:\n\t"
109 ".set\tat\n\t"
110 ".set\treorder"
111 : "=r" (__cs), "=r" (__ct), "=r" (__count), "=r" (__res)
112 : "0" (__cs), "1" (__ct), "2" (__count)
113 : "$1");
115 return __res;
118 #define __HAVE_ARCH_MEMSET
119 extern void *memset(void *__s, int __c, size_t __count);
121 #define __HAVE_ARCH_MEMCPY
122 extern void *memcpy(void *__to, __const__ void *__from, size_t __n);
124 #define __HAVE_ARCH_MEMMOVE
125 extern void *memmove(void *__dest, __const__ void *__src, size_t __n);
127 /* Don't build bcopy at all ... */
128 #define __HAVE_ARCH_BCOPY
130 #define __HAVE_ARCH_MEMSCAN
131 extern __inline__ void *memscan(void *__addr, int __c, size_t __size)
133 char *__end = (char *)__addr + __size;
135 __asm__(".set\tpush\n\t"
136 ".set\tnoat\n\t"
137 ".set\treorder\n\t"
138 "1:\tbeq\t%0,%1,2f\n\t"
139 "addiu\t%0,1\n\t"
140 "lb\t$1,-1(%0)\n\t"
141 "bne\t$1,%4,1b\n"
142 "2:\t.set\tpop"
143 : "=r" (__addr), "=r" (__end)
144 : "0" (__addr), "1" (__end), "r" (__c)
145 : "$1");
147 return __addr;
150 #endif /* __ASM_MIPS_STRING_H */