]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/powerpc/powerpc32/strcmp.S
fa75eca3a1ea4c8a1a0c7eb304755f868c8d0971
[thirdparty/glibc.git] / sysdeps / powerpc / powerpc32 / strcmp.S
1 /* Optimized strcmp implementation for PowerPC.
2 Copyright (C) 1997, 1999, 2000, 2003 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
19
20 #include <sysdep.h>
21 #include <bp-sym.h>
22 #include <bp-asm.h>
23
24 /* See strlen.s for comments on how the end-of-string testing works. */
25
26 /* int [r3] strcmp (const char *s1 [r3], const char *s2 [r4]) */
27
28 EALIGN (BP_SYM (strcmp), 4, 0)
29
30 #define rTMP r0
31 #define rRTN r3
32 #define rSTR1 r3 /* first string arg */
33 #define rSTR2 r4 /* second string arg */
34 #if __BOUNDED_POINTERS__
35 # define rHIGH1 r11
36 # define rHIGH2 r12
37 #endif
38 #define rWORD1 r5 /* current word in s1 */
39 #define rWORD2 r6 /* current word in s2 */
40 #define rFEFE r7 /* constant 0xfefefeff (-0x01010101) */
41 #define r7F7F r8 /* constant 0x7f7f7f7f */
42 #define rNEG r9 /* ~(word in s1 | 0x7f7f7f7f) */
43 #define rBITDIF r10 /* bits that differ in s1 & s2 words */
44
45 CHECK_BOUNDS_LOW (rSTR1, rTMP, rHIGH1)
46 CHECK_BOUNDS_LOW (rSTR2, rTMP, rHIGH2)
47
48 or rTMP, rSTR2, rSTR1
49 clrlwi. rTMP, rTMP, 30
50 lis rFEFE, -0x101
51 bne L(unaligned)
52
53 lwz rWORD1, 0(rSTR1)
54 lwz rWORD2, 0(rSTR2)
55 lis r7F7F, 0x7f7f
56 addi rFEFE, rFEFE, -0x101
57 addi r7F7F, r7F7F, 0x7f7f
58 b L(g1)
59
60 L(g0): lwzu rWORD1, 4(rSTR1)
61 bne cr1, L(different)
62 lwzu rWORD2, 4(rSTR2)
63 L(g1): add rTMP, rFEFE, rWORD1
64 nor rNEG, r7F7F, rWORD1
65 and. rTMP, rTMP, rNEG
66 cmpw cr1, rWORD1, rWORD2
67 beq+ L(g0)
68 L(endstring):
69 /* OK. We've hit the end of the string. We need to be careful that
70 we don't compare two strings as different because of gunk beyond
71 the end of the strings... */
72 and rTMP, r7F7F, rWORD1
73 beq cr1, L(equal)
74 add rTMP, rTMP, r7F7F
75 xor. rBITDIF, rWORD1, rWORD2
76 andc rNEG, rNEG, rTMP
77 blt- L(highbit)
78 cntlzw rBITDIF, rBITDIF
79 cntlzw rNEG, rNEG
80 addi rNEG, rNEG, 7
81 cmpw cr1, rNEG, rBITDIF
82 sub rRTN, rWORD1, rWORD2
83 bgelr+ cr1
84 L(equal):
85 li rRTN, 0
86 /* GKM FIXME: check high bounds. */
87 blr
88
89 L(different):
90 lwz rWORD1, -4(rSTR1)
91 xor. rBITDIF, rWORD1, rWORD2
92 sub rRTN, rWORD1, rWORD2
93 bgelr+
94 L(highbit):
95 ori rRTN, rWORD2, 1
96 /* GKM FIXME: check high bounds. */
97 blr
98
99
100 /* Oh well. In this case, we just do a byte-by-byte comparison. */
101 .align 4
102 L(unaligned):
103 lbz rWORD1, 0(rSTR1)
104 lbz rWORD2, 0(rSTR2)
105 b L(u1)
106
107 L(u0): lbzu rWORD1, 1(rSTR1)
108 bne- L(u4)
109 lbzu rWORD2, 1(rSTR2)
110 L(u1): cmpwi cr1, rWORD1, 0
111 beq- cr1, L(u3)
112 cmpw rWORD1, rWORD2
113 bne- L(u3)
114 lbzu rWORD1, 1(rSTR1)
115 lbzu rWORD2, 1(rSTR2)
116 cmpwi cr1, rWORD1, 0
117 cmpw rWORD1, rWORD2
118 bne+ cr1, L(u0)
119 L(u3): sub rRTN, rWORD1, rWORD2
120 /* GKM FIXME: check high bounds. */
121 blr
122 L(u4): lbz rWORD1, -1(rSTR1)
123 sub rRTN, rWORD1, rWORD2
124 /* GKM FIXME: check high bounds. */
125 blr
126 END (BP_SYM (strcmp))
127 libc_hidden_builtin_def (strcmp)