This source file includes following definitions.
- strcpy
- strncpy
- strcmp
- strncmp
- memset
- memcpy
- memmove
1
2
3
4
5
6
7
8
9
10
11 #ifndef _ASM_MIPS_STRING_H_
12 #define _ASM_MIPS_STRING_H_
13
14 #define __USE_PORTABLE_STRINGS_H_
15
16 extern inline char * strcpy(char * dest,const char *src)
17 {
18 char *xdest = dest;
19
20 __asm__ __volatile__(
21 ".set\tnoreorder\n\t"
22 ".set\tnoat\n"
23 "1:\tlbu\t$1,(%1)\n\t"
24 "addiu\t%1,%1,1\n\t"
25 "sb\t$1,(%0)\n\t"
26 "bne\t$0,$1,1b\n\t"
27 "addiu\t%0,%0,1\n\t"
28 ".set\tat\n\t"
29 ".set\treorder"
30 : "=d" (dest), "=d" (src)
31 : "0" (dest), "1" (src)
32 : "$1","memory");
33
34 return xdest;
35 }
36
37 extern inline char * strncpy(char *dest, const char *src, size_t n)
38 {
39 char *xdest = dest;
40
41 if (n == 0)
42 return xdest;
43
44 __asm__ __volatile__(
45 ".set\tnoreorder\n\t"
46 ".set\tnoat\n"
47 "1:\tlbu\t$1,(%1)\n\t"
48 "addiu\t%2,%2,-1\n\t"
49 "sb\t$1,(%0)\n\t"
50 "beq\t$0,$1,2f\n\t"
51 "addiu\t%0,%0,1\n\t"
52 "bne\t$0,%2,1b\n\t"
53 "addiu\t%1,%1,1\n"
54 "2:\n\t"
55 ".set\tat\n\t"
56 ".set\treorder\n\t"
57 : "=d" (dest), "=d" (src), "=d" (n)
58 : "0" (dest), "1" (src), "2" (n)
59 : "$1","memory");
60
61 return dest;
62 }
63
64 #define __USE_PORTABLE_strcat
65 #define __USE_PORTABLE_strncat
66
67 extern inline int strcmp(const char * cs,const char * ct)
68 {
69 int __res;
70
71 __asm__ __volatile__(
72 ".set\tnoreorder\n\t"
73 ".set\tnoat\n\t"
74 "lbu\t%2,(%0)\n"
75 "1:\tlbu\t$1,(%1)\n\t"
76 "addiu\t%0,%0,1\n\t"
77 "bne\t$1,%2,2f\n\t"
78 "addiu\t%1,%1,1\n\t"
79 "bne\t$0,%2,1b\n\t"
80 "lbu\t%2,(%0)\n"
81 "move\t%2,$1\n"
82 "2:\tsub\t%2,%2,$1\n"
83 "3:\t.set\tat\n\t"
84 ".set\treorder\n\t"
85 : "=d" (cs), "=d" (ct), "=d" (__res)
86 : "0" (cs), "1" (ct)
87 : "$1");
88
89 return __res;
90 }
91
92 extern inline int strncmp(const char * cs,const char * ct,size_t count)
93 {
94 char __res;
95
96 __asm__ __volatile__(
97 ".set\tnoreorder\n\t"
98 ".set\tnoat\n"
99 "1:\tlbu\t%3,(%0)\n\t"
100 "beq\t$0,%2,2f\n\t"
101 "lbu\t$1,(%1)\n\t"
102 "addiu\t%2,%2,-1\n\t"
103 "bne\t$1,%3,3f\n\t"
104 "addiu\t%0,%0,1\n\t"
105 "bne\t$0,%3,1b\n\t"
106 "addiu\t%1,%1,1\n"
107 "2:\tmove\t%3,$1\n"
108 "3:\tsub\t%3,%3,$1\n\t"
109 ".set\tat\n\t"
110 ".set\treorder"
111 : "=d" (cs), "=d" (ct), "=d" (count), "=d" (__res)
112 : "0" (cs), "1" (ct), "2" (count)
113 : "$1");
114
115 return __res;
116 }
117
118 #define __USE_PORTABLE_strchr
119 #define __USE_PORTABLE_strlen
120 #define __USE_PORTABLE_strspn
121 #define __USE_PORTABLE_strpbrk
122 #define __USE_PORTABLE_strtok
123
124 extern inline void * memset(void * s,char c,size_t count)
125 {
126 void *xs = s;
127
128 if (!count)
129 return xs;
130 __asm__ __volatile__(
131 ".set\tnoreorder\n"
132 "1:\tsb\t%3,(%0)\n\t"
133 "addiu\t%1,%1,-1\n\t"
134 "bne\t$0,%1,1b\n\t"
135 "addiu\t%3,%3,1\n\t"
136 ".set\treorder"
137 : "=d" (s), "=d" (count)
138 : "0" (s), "d" (c), "1" (count)
139 : "memory");
140
141 return xs;
142 }
143
144 extern inline void * memcpy(void * to, const void * from, size_t n)
145 {
146 void *xto = to;
147
148 if (!n)
149 return xto;
150 __asm__ __volatile__(
151 ".set\tnoreorder\n\t"
152 ".set\tnoat\n"
153 "1:\tlbu\t$1,(%1)\n\t"
154 "addiu\t%1,%1,1\n\t"
155 "sb\t$1,(%0)\n\t"
156 "addiu\t%2,%2,-1\n\t"
157 "bne\t$0,%2,1b\n\t"
158 "addiu\t%0,%0,1\n\t"
159 ".set\tat\n\t"
160 ".set\treorder"
161 : "=d" (to), "=d" (from), "=d" (n)
162 : "0" (to), "1" (from), "2" (n)
163 : "$1","memory" );
164 return xto;
165 }
166
167 extern inline void * memmove(void * dest,const void * src, size_t n)
168 {
169 void *xdest = dest;
170
171 if (!n)
172 return xdest;
173
174 if (dest < src)
175 __asm__ __volatile__(
176 ".set\tnoreorder\n\t"
177 ".set\tnoat\n"
178 "1:\tlbu\t$1,(%1)\n\t"
179 "addiu\t%1,%1,1\n\t"
180 "sb\t$1,(%0)\n\t"
181 "addiu\t%2,%2,-1\n\t"
182 "bne\t$0,%2,1b\n\t"
183 "addiu\t%0,%0,1\n\t"
184 ".set\tat\n\t"
185 ".set\treorder"
186 : "=d" (dest), "=d" (src), "=d" (n)
187 : "0" (dest), "1" (src), "2" (n)
188 : "$1","memory" );
189 else
190 __asm__ __volatile__(
191 ".set\tnoreorder\n\t"
192 ".set\tnoat\n"
193 "1:\tlbu\t$1,-1(%1)\n\t"
194 "addiu\t%1,%1,-1\n\t"
195 "sb\t$1,-1(%0)\n\t"
196 "addiu\t%2,%2,-1\n\t"
197 "bne\t$0,%2,1b\n\t"
198 "addiu\t%0,%0,-1\n\t"
199 ".set\tat\n\t"
200 ".set\treorder"
201 : "=d" (dest), "=d" (src), "=d" (n)
202 : "0" (dest+n), "1" (src+n), "2" (n)
203 : "$1","memory" );
204 return xdest;
205 }
206
207 #define __USE_PORTABLE_memcmp
208
209 #endif