]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/powerpc/powerpc64/strcmp.S
Update copyright notices with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / powerpc / powerpc64 / strcmp.S
CommitLineData
cfc91acd 1/* Optimized strcmp implementation for PowerPC64.
d4697bc9 2 Copyright (C) 1997-2014 Free Software Foundation, Inc.
cfc91acd
RM
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
59ba27a6
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
cfc91acd
RM
18
19#include <sysdep.h>
cfc91acd
RM
20
21/* See strlen.s for comments on how the end-of-string testing works. */
22
23/* int [r3] strcmp (const char *s1 [r3], const char *s2 [r4]) */
24
2d67d91a 25EALIGN (strcmp, 4, 0)
d7d06f79 26 CALL_MCOUNT 2
cfc91acd 27
8a7413f9 28#define rTMP2 r0
cfc91acd
RM
29#define rRTN r3
30#define rSTR1 r3 /* first string arg */
31#define rSTR2 r4 /* second string arg */
cfc91acd
RM
32#define rWORD1 r5 /* current word in s1 */
33#define rWORD2 r6 /* current word in s2 */
482eb33c
UD
34#define rFEFE r7 /* constant 0xfefefefefefefeff (-0x0101010101010101) */
35#define r7F7F r8 /* constant 0x7f7f7f7f7f7f7f7f */
36#define rNEG r9 /* ~(word in s1 | 0x7f7f7f7f7f7f7f7f) */
cfc91acd 37#define rBITDIF r10 /* bits that differ in s1 & s2 words */
8a7413f9 38#define rTMP r11
cfc91acd 39
482eb33c 40 dcbt 0,rSTR1
cfc91acd 41 or rTMP, rSTR2, rSTR1
482eb33c
UD
42 dcbt 0,rSTR2
43 clrldi. rTMP, rTMP, 61
cfc91acd
RM
44 lis rFEFE, -0x101
45 bne L(unaligned)
46
482eb33c
UD
47 ld rWORD1, 0(rSTR1)
48 ld rWORD2, 0(rSTR2)
cfc91acd
RM
49 lis r7F7F, 0x7f7f
50 addi rFEFE, rFEFE, -0x101
cfc91acd 51 addi r7F7F, r7F7F, 0x7f7f
482eb33c
UD
52 sldi rTMP, rFEFE, 32
53 insrdi r7F7F, r7F7F, 32, 0
54 add rFEFE, rFEFE, rTMP
cfc91acd
RM
55 b L(g1)
56
482eb33c 57L(g0): ldu rWORD1, 8(rSTR1)
cfc91acd 58 bne cr1, L(different)
482eb33c 59 ldu rWORD2, 8(rSTR2)
cfc91acd
RM
60L(g1): add rTMP, rFEFE, rWORD1
61 nor rNEG, r7F7F, rWORD1
cfc91acd 62 and. rTMP, rTMP, rNEG
482eb33c 63 cmpd cr1, rWORD1, rWORD2
cfc91acd 64 beq+ L(g0)
8a7413f9 65
cfc91acd
RM
66/* OK. We've hit the end of the string. We need to be careful that
67 we don't compare two strings as different because of gunk beyond
68 the end of the strings... */
8a7413f9
AM
69#ifdef __LITTLE_ENDIAN__
70L(endstring):
71 addi rTMP2, rTMP, -1
72 beq cr1, L(equal)
73 andc rTMP2, rTMP2, rTMP
74 rldimi rTMP2, rTMP2, 1, 0
75 and rWORD2, rWORD2, rTMP2 /* Mask off gunk. */
76 and rWORD1, rWORD1, rTMP2
77 cmpd cr1, rWORD1, rWORD2
78 beq cr1, L(equal)
79 xor rBITDIF, rWORD1, rWORD2 /* rBITDIF has bits that differ. */
80 neg rNEG, rBITDIF
81 and rNEG, rNEG, rBITDIF /* rNEG has LS bit that differs. */
82 cntlzd rNEG, rNEG /* bitcount of the bit. */
83 andi. rNEG, rNEG, 56 /* bitcount to LS byte that differs. */
84 sld rWORD1, rWORD1, rNEG /* shift left to clear MS bytes. */
85 sld rWORD2, rWORD2, rNEG
86 xor. rBITDIF, rWORD1, rWORD2
87 sub rRTN, rWORD1, rWORD2
88 blt- L(highbit)
89 sradi rRTN, rRTN, 63 /* must return an int. */
90 ori rRTN, rRTN, 1
91 blr
92L(equal):
93 li rRTN, 0
94 blr
95
96L(different):
97 ld rWORD1, -8(rSTR1)
98 xor rBITDIF, rWORD1, rWORD2 /* rBITDIF has bits that differ. */
99 neg rNEG, rBITDIF
100 and rNEG, rNEG, rBITDIF /* rNEG has LS bit that differs. */
101 cntlzd rNEG, rNEG /* bitcount of the bit. */
102 andi. rNEG, rNEG, 56 /* bitcount to LS byte that differs. */
103 sld rWORD1, rWORD1, rNEG /* shift left to clear MS bytes. */
104 sld rWORD2, rWORD2, rNEG
105 xor. rBITDIF, rWORD1, rWORD2
106 sub rRTN, rWORD1, rWORD2
107 blt- L(highbit)
108 sradi rRTN, rRTN, 63
109 ori rRTN, rRTN, 1
110 blr
111L(highbit):
112 sradi rRTN, rWORD2, 63
113 ori rRTN, rRTN, 1
114 blr
115
116#else
117L(endstring):
cfc91acd
RM
118 and rTMP, r7F7F, rWORD1
119 beq cr1, L(equal)
120 add rTMP, rTMP, r7F7F
121 xor. rBITDIF, rWORD1, rWORD2
cfc91acd
RM
122 andc rNEG, rNEG, rTMP
123 blt- L(highbit)
482eb33c
UD
124 cntlzd rBITDIF, rBITDIF
125 cntlzd rNEG, rNEG
cfc91acd 126 addi rNEG, rNEG, 7
482eb33c 127 cmpd cr1, rNEG, rBITDIF
cfc91acd 128 sub rRTN, rWORD1, rWORD2
482eb33c 129 blt- cr1, L(equal)
8a7413f9 130 sradi rRTN, rRTN, 63 /* must return an int. */
482eb33c
UD
131 ori rRTN, rRTN, 1
132 blr
cfc91acd
RM
133L(equal):
134 li rRTN, 0
cfc91acd
RM
135 blr
136
137L(different):
482eb33c 138 ld rWORD1, -8(rSTR1)
cfc91acd 139 xor. rBITDIF, rWORD1, rWORD2
cfc91acd 140 sub rRTN, rWORD1, rWORD2
482eb33c
UD
141 blt- L(highbit)
142 sradi rRTN, rRTN, 63
143 ori rRTN, rRTN, 1
144 blr
cfc91acd 145L(highbit):
8a7413f9
AM
146 sradi rRTN, rWORD2, 63
147 ori rRTN, rRTN, 1
cfc91acd 148 blr
8a7413f9 149#endif
cfc91acd
RM
150
151/* Oh well. In this case, we just do a byte-by-byte comparison. */
152 .align 4
153L(unaligned):
154 lbz rWORD1, 0(rSTR1)
155 lbz rWORD2, 0(rSTR2)
156 b L(u1)
157
158L(u0): lbzu rWORD1, 1(rSTR1)
159 bne- L(u4)
160 lbzu rWORD2, 1(rSTR2)
161L(u1): cmpwi cr1, rWORD1, 0
162 beq- cr1, L(u3)
482eb33c 163 cmpd rWORD1, rWORD2
cfc91acd
RM
164 bne- L(u3)
165 lbzu rWORD1, 1(rSTR1)
166 lbzu rWORD2, 1(rSTR2)
482eb33c
UD
167 cmpdi cr1, rWORD1, 0
168 cmpd rWORD1, rWORD2
cfc91acd
RM
169 bne+ cr1, L(u0)
170L(u3): sub rRTN, rWORD1, rWORD2
cfc91acd
RM
171 blr
172L(u4): lbz rWORD1, -1(rSTR1)
173 sub rRTN, rWORD1, rWORD2
cfc91acd 174 blr
2d67d91a 175END (strcmp)
85dd1003 176libc_hidden_builtin_def (strcmp)