blob: 8152ac9b0f888cbe2df916da02552483849ace7a [file] [log] [blame]
wdenkc7de8292002-11-19 11:04:11 +00001/*
2 * String handling functions for PowerPC.
3 *
4 * Copyright (C) 1996 Paul Mackerras.
5 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
wdenkc7de8292002-11-19 11:04:11 +00007 */
8#include <ppc_asm.tmpl>
9#include <asm/errno.h>
10
11 .globl strcpy
12strcpy:
13 addi r5,r3,-1
14 addi r4,r4,-1
151: lbzu r0,1(r4)
16 cmpwi 0,r0,0
17 stbu r0,1(r5)
18 bne 1b
19 blr
20
21 .globl strncpy
22strncpy:
23 cmpwi 0,r5,0
24 beqlr
25 mtctr r5
26 addi r6,r3,-1
27 addi r4,r4,-1
281: lbzu r0,1(r4)
29 cmpwi 0,r0,0
30 stbu r0,1(r6)
31 bdnzf 2,1b /* dec ctr, branch if ctr != 0 && !cr0.eq */
32 blr
33
34 .globl strcat
35strcat:
36 addi r5,r3,-1
37 addi r4,r4,-1
381: lbzu r0,1(r5)
39 cmpwi 0,r0,0
40 bne 1b
41 addi r5,r5,-1
421: lbzu r0,1(r4)
43 cmpwi 0,r0,0
44 stbu r0,1(r5)
45 bne 1b
46 blr
47
48 .globl strcmp
49strcmp:
50 addi r5,r3,-1
51 addi r4,r4,-1
521: lbzu r3,1(r5)
53 cmpwi 1,r3,0
54 lbzu r0,1(r4)
55 subf. r3,r0,r3
56 beqlr 1
57 beq 1b
58 blr
59
60 .globl strlen
61strlen:
62 addi r4,r3,-1
631: lbzu r0,1(r4)
64 cmpwi 0,r0,0
65 bne 1b
66 subf r3,r3,r4
67 blr
68
69 .globl memset
70memset:
71 rlwimi r4,r4,8,16,23
72 rlwimi r4,r4,16,0,15
73 addi r6,r3,-4
74 cmplwi 0,r5,4
75 blt 7f
76 stwu r4,4(r6)
77 beqlr
78 andi. r0,r6,3
79 add r5,r0,r5
80 subf r6,r0,r6
81 rlwinm r0,r5,32-2,2,31
82 mtctr r0
83 bdz 6f
841: stwu r4,4(r6)
85 bdnz 1b
866: andi. r5,r5,3
877: cmpwi 0,r5,0
88 beqlr
89 mtctr r5
90 addi r6,r6,3
918: stbu r4,1(r6)
92 bdnz 8b
93 blr
94
95 .globl bcopy
96bcopy:
97 mr r6,r3
98 mr r3,r4
99 mr r4,r6
100 b memcpy
101
102 .globl memmove
103memmove:
104 cmplw 0,r3,r4
105 bgt backwards_memcpy
106 /* fall through */
107
108 .globl memcpy
109memcpy:
110 rlwinm. r7,r5,32-3,3,31 /* r0 = r5 >> 3 */
111 addi r6,r3,-4
112 addi r4,r4,-4
113 beq 2f /* if less than 8 bytes to do */
114 andi. r0,r6,3 /* get dest word aligned */
115 mtctr r7
116 bne 5f
1171: lwz r7,4(r4)
118 lwzu r8,8(r4)
119 stw r7,4(r6)
120 stwu r8,8(r6)
121 bdnz 1b
122 andi. r5,r5,7
1232: cmplwi 0,r5,4
124 blt 3f
125 lwzu r0,4(r4)
126 addi r5,r5,-4
127 stwu r0,4(r6)
1283: cmpwi 0,r5,0
129 beqlr
130 mtctr r5
131 addi r4,r4,3
132 addi r6,r6,3
1334: lbzu r0,1(r4)
134 stbu r0,1(r6)
135 bdnz 4b
136 blr
1375: subfic r0,r0,4
138 mtctr r0
1396: lbz r7,4(r4)
140 addi r4,r4,1
141 stb r7,4(r6)
142 addi r6,r6,1
143 bdnz 6b
144 subf r5,r0,r5
145 rlwinm. r7,r5,32-3,3,31
146 beq 2b
147 mtctr r7
148 b 1b
149
150 .globl backwards_memcpy
151backwards_memcpy:
152 rlwinm. r7,r5,32-3,3,31 /* r0 = r5 >> 3 */
153 add r6,r3,r5
154 add r4,r4,r5
155 beq 2f
156 andi. r0,r6,3
157 mtctr r7
158 bne 5f
1591: lwz r7,-4(r4)
160 lwzu r8,-8(r4)
161 stw r7,-4(r6)
162 stwu r8,-8(r6)
163 bdnz 1b
164 andi. r5,r5,7
1652: cmplwi 0,r5,4
166 blt 3f
167 lwzu r0,-4(r4)
168 subi r5,r5,4
169 stwu r0,-4(r6)
1703: cmpwi 0,r5,0
171 beqlr
172 mtctr r5
1734: lbzu r0,-1(r4)
174 stbu r0,-1(r6)
175 bdnz 4b
176 blr
1775: mtctr r0
1786: lbzu r7,-1(r4)
179 stbu r7,-1(r6)
180 bdnz 6b
181 subf r5,r0,r5
182 rlwinm. r7,r5,32-3,3,31
183 beq 2b
184 mtctr r7
185 b 1b
186
187 .globl memcmp
188memcmp:
189 cmpwi 0,r5,0
190 ble- 2f
191 mtctr r5
192 addi r6,r3,-1
193 addi r4,r4,-1
1941: lbzu r3,1(r6)
195 lbzu r0,1(r4)
196 subf. r3,r0,r3
197 bdnzt 2,1b
198 blr
1992: li r3,0
200 blr
201
202 .global memchr
203memchr:
204 cmpwi 0,r5,0
205 ble- 2f
206 mtctr r5
207 addi r3,r3,-1
2081: lbzu r0,1(r3)
209 cmpw 0,r0,r4
210 bdnzf 2,1b
211 beqlr
2122: li r3,0
213 blr