blob: 97023a0555a593ffba8d7710922738dcca9b7a5d [file] [log] [blame]
wdenk40c85552000-07-19 14:09:16 +00001/*
2 * String handling functions for PowerPC.
3 *
4 * Copyright (C) 1996 Paul Mackerras.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11#include <ppc_asm.tmpl>
12#include <asm/errno.h>
13
14 .globl strcpy
15strcpy:
16 addi r5,r3,-1
17 addi r4,r4,-1
181: lbzu r0,1(r4)
19 cmpwi 0,r0,0
20 stbu r0,1(r5)
21 bne 1b
22 blr
23
24 .globl strncpy
25strncpy:
26 cmpwi 0,r5,0
27 beqlr
28 mtctr r5
29 addi r6,r3,-1
30 addi r4,r4,-1
311: lbzu r0,1(r4)
32 cmpwi 0,r0,0
33 stbu r0,1(r6)
34 bdnzf 2,1b /* dec ctr, branch if ctr != 0 && !cr0.eq */
35 blr
36
37 .globl strcat
38strcat:
39 addi r5,r3,-1
40 addi r4,r4,-1
411: lbzu r0,1(r5)
42 cmpwi 0,r0,0
43 bne 1b
44 addi r5,r5,-1
451: lbzu r0,1(r4)
46 cmpwi 0,r0,0
47 stbu r0,1(r5)
48 bne 1b
49 blr
50
51 .globl strcmp
52strcmp:
53 addi r5,r3,-1
54 addi r4,r4,-1
551: lbzu r3,1(r5)
56 cmpwi 1,r3,0
57 lbzu r0,1(r4)
58 subf. r3,r0,r3
59 beqlr 1
60 beq 1b
61 blr
62
63 .globl strlen
64strlen:
65 addi r4,r3,-1
661: lbzu r0,1(r4)
67 cmpwi 0,r0,0
68 bne 1b
69 subf r3,r3,r4
70 blr
71
72 .globl memset
73memset:
74 rlwimi r4,r4,8,16,23
75 rlwimi r4,r4,16,0,15
76 addi r6,r3,-4
77 cmplwi 0,r5,4
78 blt 7f
79 stwu r4,4(r6)
80 beqlr
81 andi. r0,r6,3
82 add r5,r0,r5
83 subf r6,r0,r6
84 rlwinm r0,r5,32-2,2,31
85 mtctr r0
86 bdz 6f
871: stwu r4,4(r6)
88 bdnz 1b
896: andi. r5,r5,3
907: cmpwi 0,r5,0
91 beqlr
92 mtctr r5
93 addi r6,r6,3
948: stbu r4,1(r6)
95 bdnz 8b
96 blr
97
98 .globl bcopy
99bcopy:
100 mr r6,r3
101 mr r3,r4
102 mr r4,r6
103 b memcpy
104
105 .globl memmove
106memmove:
107 cmplw 0,r3,r4
108 bgt backwards_memcpy
109 /* fall through */
110
111 .globl memcpy
112memcpy:
113 rlwinm. r7,r5,32-3,3,31 /* r0 = r5 >> 3 */
114 addi r6,r3,-4
115 addi r4,r4,-4
116 beq 2f /* if less than 8 bytes to do */
117 andi. r0,r6,3 /* get dest word aligned */
118 mtctr r7
119 bne 5f
1201: lwz r7,4(r4)
121 lwzu r8,8(r4)
122 stw r7,4(r6)
123 stwu r8,8(r6)
124 bdnz 1b
125 andi. r5,r5,7
1262: cmplwi 0,r5,4
127 blt 3f
128 lwzu r0,4(r4)
129 addi r5,r5,-4
130 stwu r0,4(r6)
1313: cmpwi 0,r5,0
132 beqlr
133 mtctr r5
134 addi r4,r4,3
135 addi r6,r6,3
1364: lbzu r0,1(r4)
137 stbu r0,1(r6)
138 bdnz 4b
139 blr
1405: subfic r0,r0,4
141 mtctr r0
1426: lbz r7,4(r4)
143 addi r4,r4,1
144 stb r7,4(r6)
145 addi r6,r6,1
146 bdnz 6b
147 subf r5,r0,r5
148 rlwinm. r7,r5,32-3,3,31
149 beq 2b
150 mtctr r7
151 b 1b
152
153 .globl backwards_memcpy
154backwards_memcpy:
155 rlwinm. r7,r5,32-3,3,31 /* r0 = r5 >> 3 */
156 add r6,r3,r5
157 add r4,r4,r5
158 beq 2f
159 andi. r0,r6,3
160 mtctr r7
161 bne 5f
1621: lwz r7,-4(r4)
163 lwzu r8,-8(r4)
164 stw r7,-4(r6)
165 stwu r8,-8(r6)
166 bdnz 1b
167 andi. r5,r5,7
1682: cmplwi 0,r5,4
169 blt 3f
170 lwzu r0,-4(r4)
171 subi r5,r5,4
172 stwu r0,-4(r6)
1733: cmpwi 0,r5,0
174 beqlr
175 mtctr r5
1764: lbzu r0,-1(r4)
177 stbu r0,-1(r6)
178 bdnz 4b
179 blr
1805: mtctr r0
1816: lbzu r7,-1(r4)
182 stbu r7,-1(r6)
183 bdnz 6b
184 subf r5,r0,r5
185 rlwinm. r7,r5,32-3,3,31
186 beq 2b
187 mtctr r7
188 b 1b
189
190 .globl memcmp
191memcmp:
192 cmpwi 0,r5,0
193 ble- 2f
194 mtctr r5
195 addi r6,r3,-1
196 addi r4,r4,-1
1971: lbzu r3,1(r6)
198 lbzu r0,1(r4)
199 subf. r3,r0,r3
200 bdnzt 2,1b
201 blr
2022: li r3,0
203 blr
204
205 .global memchr
206memchr:
207 cmpwi 0,r5,0
208 ble- 2f
209 mtctr r5
210 addi r3,r3,-1
2111: lbzu r0,1(r3)
212 cmpw 0,r0,r4
213 bdnzf 2,1b
214 beqlr
2152: li r3,0
216 blr