]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/powerpc/powerpc32/power4/strncmp.S
Remove powerpc32 strncmp comments about bounded pointers.
[thirdparty/glibc.git] / sysdeps / powerpc / powerpc32 / power4 / strncmp.S
1 /* Optimized strcmp implementation for PowerPC32.
2 Copyright (C) 2003-2013 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19 #include <sysdep.h>
20
21 /* See strlen.s for comments on how the end-of-string testing works. */
22
23 /* int [r3] strncmp (const char *s1 [r3], const char *s2 [r4], size_t size [r5]) */
24
25 EALIGN (strncmp, 4, 0)
26
27 #define rTMP r0
28 #define rRTN r3
29 #define rSTR1 r3 /* first string arg */
30 #define rSTR2 r4 /* second string arg */
31 #define rN r5 /* max string length */
32 #define rWORD1 r6 /* current word in s1 */
33 #define rWORD2 r7 /* current word in s2 */
34 #define rWORD3 r10
35 #define rWORD4 r11
36 #define rFEFE r8 /* constant 0xfefefeff (-0x01010101) */
37 #define r7F7F r9 /* constant 0x7f7f7f7f */
38 #define rNEG r10 /* ~(word in s1 | 0x7f7f7f7f) */
39 #define rBITDIF r11 /* bits that differ in s1 & s2 words */
40
41 dcbt 0,rSTR1
42 or rTMP, rSTR2, rSTR1
43 lis r7F7F, 0x7f7f
44 dcbt 0,rSTR2
45 clrlwi. rTMP, rTMP, 30
46 cmplwi cr1, rN, 0
47 lis rFEFE, -0x101
48 bne L(unaligned)
49 /* We are word aligned so set up for two loops. first a word
50 loop, then fall into the byte loop if any residual. */
51 srwi. rTMP, rN, 2
52 clrlwi rN, rN, 30
53 addi rFEFE, rFEFE, -0x101
54 addi r7F7F, r7F7F, 0x7f7f
55 cmplwi cr1, rN, 0
56 beq L(unaligned)
57
58 mtctr rTMP /* Power4 wants mtctr 1st in dispatch group. */
59 lwz rWORD1, 0(rSTR1)
60 lwz rWORD2, 0(rSTR2)
61 b L(g1)
62
63 L(g0):
64 lwzu rWORD1, 4(rSTR1)
65 bne- cr1, L(different)
66 lwzu rWORD2, 4(rSTR2)
67 L(g1): add rTMP, rFEFE, rWORD1
68 nor rNEG, r7F7F, rWORD1
69 bdz L(tail)
70 and. rTMP, rTMP, rNEG
71 cmpw cr1, rWORD1, rWORD2
72 beq+ L(g0)
73
74 /* OK. We've hit the end of the string. We need to be careful that
75 we don't compare two strings as different because of gunk beyond
76 the end of the strings... */
77
78 L(endstring):
79 and rTMP, r7F7F, rWORD1
80 beq cr1, L(equal)
81 add rTMP, rTMP, r7F7F
82 xor. rBITDIF, rWORD1, rWORD2
83
84 andc rNEG, rNEG, rTMP
85 blt- L(highbit)
86 cntlzw rBITDIF, rBITDIF
87 cntlzw rNEG, rNEG
88 addi rNEG, rNEG, 7
89 cmpw cr1, rNEG, rBITDIF
90 sub rRTN, rWORD1, rWORD2
91 blt- cr1, L(equal)
92 srawi rRTN, rRTN, 31
93 ori rRTN, rRTN, 1
94 blr
95 L(equal):
96 li rRTN, 0
97 blr
98
99 L(different):
100 lwzu rWORD1, -4(rSTR1)
101 xor. rBITDIF, rWORD1, rWORD2
102 sub rRTN, rWORD1, rWORD2
103 blt- L(highbit)
104 srawi rRTN, rRTN, 31
105 ori rRTN, rRTN, 1
106 blr
107 L(highbit):
108 srwi rWORD2, rWORD2, 24
109 srwi rWORD1, rWORD1, 24
110 sub rRTN, rWORD1, rWORD2
111 blr
112
113
114 /* Oh well. In this case, we just do a byte-by-byte comparison. */
115 .align 4
116 L(tail):
117 and. rTMP, rTMP, rNEG
118 cmpw cr1, rWORD1, rWORD2
119 bne- L(endstring)
120 addi rSTR1, rSTR1, 4
121 bne- cr1, L(different)
122 addi rSTR2, rSTR2, 4
123 cmplwi cr1, rN, 0
124 L(unaligned):
125 mtctr rN /* Power4 wants mtctr 1st in dispatch group */
126 ble cr1, L(ux)
127 L(uz):
128 lbz rWORD1, 0(rSTR1)
129 lbz rWORD2, 0(rSTR2)
130 .align 4
131 L(u1):
132 cmpwi cr1, rWORD1, 0
133 bdz L(u4)
134 cmpw rWORD1, rWORD2
135 beq- cr1, L(u4)
136 bne- L(u4)
137 lbzu rWORD3, 1(rSTR1)
138 lbzu rWORD4, 1(rSTR2)
139 cmpwi cr1, rWORD3, 0
140 bdz L(u3)
141 cmpw rWORD3, rWORD4
142 beq- cr1, L(u3)
143 bne- L(u3)
144 lbzu rWORD1, 1(rSTR1)
145 lbzu rWORD2, 1(rSTR2)
146 cmpwi cr1, rWORD1, 0
147 bdz L(u4)
148 cmpw rWORD1, rWORD2
149 beq- cr1, L(u4)
150 bne- L(u4)
151 lbzu rWORD3, 1(rSTR1)
152 lbzu rWORD4, 1(rSTR2)
153 cmpwi cr1, rWORD3, 0
154 bdz L(u3)
155 cmpw rWORD3, rWORD4
156 beq- cr1, L(u3)
157 bne- L(u3)
158 lbzu rWORD1, 1(rSTR1)
159 lbzu rWORD2, 1(rSTR2)
160 b L(u1)
161
162 L(u3): sub rRTN, rWORD3, rWORD4
163 blr
164 L(u4): sub rRTN, rWORD1, rWORD2
165 blr
166 L(ux):
167 li rRTN, 0
168 blr
169 END (strncmp)
170 libc_hidden_builtin_def (strncmp)