2.9
[glibc/nacl-glibc.git] / sysdeps / sparc / sparc32 / strcmp.S
blobcf369dd839638710a9580c3f06c7f8d96cbf71b3
1 /* Compare two strings for differences.
2    For SPARC v7.
3    Copyright (C) 1996, 97, 99, 2003 Free Software Foundation, Inc.
4    This file is part of the GNU C Library.
5    Contributed by Jakub Jelinek <jj@ultra.linux.cz>.
7    The GNU C Library is free software; you can redistribute it and/or
8    modify it under the terms of the GNU Lesser General Public
9    License as published by the Free Software Foundation; either
10    version 2.1 of the License, or (at your option) any later version.
12    The GNU C Library is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    Lesser General Public License for more details.
17    You should have received a copy of the GNU Lesser General Public
18    License along with the GNU C Library; if not, write to the Free
19    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20    02111-1307 USA.  */
22 #include <sysdep.h>
24         /* Normally, this uses ((xword - 0x01010101) & 0x80808080) test
25            to find out if any byte in xword could be zero. This is fast, but
26            also gives false alarm for any byte in range 0x81-0xff. It does
27            not matter for correctness, as if this test tells us there could
28            be some zero byte, we check it byte by byte, but if bytes with
29            high bits set are common in the strings, then this will give poor
30            performance. You can #define EIGHTBIT_NOT_RARE and the algorithm
31            will use one tick slower, but more precise test
32            ((xword - 0x01010101) & (~xword) & 0x80808080),
33            which does not give any false alarms (but if some bits are set,
34            one cannot assume from it which bytes are zero and which are not).
35            It is yet to be measured, what is the correct default for glibc
36            in these days for an average user.
37          */
39         .text
40         .align          4
42 ENTRY(strcmp)
43         andcc           %o0, 3, %g0
44         be              13f
45          sethi          %hi(0x80808080), %g1
47         ldub            [%o0], %o4
48         add             %o0, 1, %o0
49         ldub            [%o1], %o5
50         cmp             %o4, 0
51         add             %o1, 1, %o1
52         be              2f
53          subcc          %o4, %o5, %o4
54         bne             2f
55          andcc          %o0, 3, %g0
56         be              4f
57          or             %g1, %lo(0x80808080), %o3
58         ldub            [%o0], %o4
59         add             %o0, 1, %o0
60         ldub            [%o1], %o5
61         cmp             %o4, 0
62         add             %o1, 1, %o1
63         be              2f
64          subcc          %o4, %o5, %o4
65         bne             2f
66          andcc          %o0, 3, %g0
67         be              5f
68          sethi          %hi(0x01010101), %g1
69         ldub            [%o0], %o4
70         add             %o0, 1, %o0
71         ldub            [%o1], %o5
72         cmp             %o4, 0
73         add             %o1, 1, %o1
74         be              2f
75          subcc          %o4, %o5, %o4
76         bne             2f
77          andcc          %o1, 3, %g2
78         bne             12f
79          or             %g1, %lo(0x01010101), %o2
80         b               1f
81          ld             [%o0], %o4
82 2:      retl
83          mov            %o4, %o0
85 13:     or              %g1, %lo(0x80808080), %o3
86 4:      sethi           %hi(0x01010101), %g1
87 5:      andcc           %o1, 3, %g2
88         bne             12f
89          or             %g1, %lo(0x01010101), %o2
91 0:      ld              [%o0], %o4
92 1:      ld              [%o1], %o5
93         sub             %o4, %o2, %g1
94         add             %o0, 4, %o0
95         cmp             %o4, %o5
96 #ifdef EIGHTBIT_NOT_RARE
97         andn            %g1, %o4, %g1
98 #endif
99         bne             11f
100          andcc          %g1, %o3, %g0
101         be              0b
102          add            %o1, 4, %o1
104         srl             %o4, 24, %g4
105         andcc           %g4, 0xff, %g0
106         be              2f
107          srl            %o4, 16, %g4
108         andcc           %g4, 0xff, %g0
109         be              2f
110          srl            %o4, 8, %g4
111         andcc           %g4, 0xff, %g0
112         be              2f
113          andcc          %o4, 0xff, %g0
114         bne,a           1b
115          ld             [%o0], %o4
116 2:      retl
117          clr            %o0
119 11:     srl             %o4, 24, %g4
120         srl             %o5, 24, %g5
121         andcc           %g4, 0xff, %g0
122         be              3f
123          subcc          %g4, %g5, %g4
124         bne             3f
125          srl            %o5, 16, %g5
126         srl             %o4, 16, %g4
127         andcc           %g4, 0xff, %g0
128         be              3f
129          subcc          %g4, %g5, %g4
130         bne             3f
131          srl            %o5, 8, %g5
132         srl             %o4, 8, %g4
133         andcc           %g4, 0xff, %g0
134         be              3f
135          subcc          %g4, %g5, %g4
136         bne             3f
137          subcc          %o4, %o5, %o4
138         retl
139          mov            %o4, %o0
140 3:      retl
141          mov            %g4, %o0
143 12:     save            %sp, -64, %sp
144         ld              [%i0], %i4
145         sll             %g2, 3, %g3
146         andn            %i1, 3, %i1
147         mov             32, %l1
148         ld              [%i1], %l2
149         mov             -1, %g6
150         add             %i1, 4, %i1
151         sub             %l1, %g3, %l1
152         sll             %g6, %g3, %g6
154 1:      sll             %l2, %g3, %g5
155         and             %i4, %g6, %l3
156         sub             %i4, %i2, %g1
157 #ifdef EIGHTBIT_NOT_RARE
158         andn            %g1, %i4, %g1
159 #endif
160         andcc           %g1, %i3, %g1
161         bne             3f
162          cmp            %g5, %l3
163         bne             2f
164          add            %i0, 4, %i0
165         ld              [%i1], %l2
166         add             %i1, 4, %i1
167         srl             %l2, %l1, %l4
168         or              %l4, %g5, %l4
169         cmp             %l4, %i4
170         be,a            1b
171          ld             [%i0], %i4
172         restore         %l4, %g0, %o3
173         retl
174          sub            %o4, %o3, %o0
176 2:      sll             %l2, %g3, %i2
177         srl             %i4, %g3, %i3
178         srl             %i2, %g3, %i2
179         restore
180         retl
181          sub            %o3, %o2, %o0
183 3:      srl             %i4, 24, %g4
184         srl             %g5, 24, %l6
185         andcc           %g4, 0xff, %g0
186         be              4f
187          subcc          %g4, %l6, %g4
188         bne             4f
189          cmp            %g2, 3
190         be              6f
191          srl            %i4, 16, %g4
192         srl             %g5, 16, %l6
193         andcc           %g4, 0xff, %g0
194         be              4f
195          subcc          %g4, %l6, %g4
196         bne             4f
197          cmp            %g2, 2
198         be              5f
199          srl            %i4, 8, %g4
200         srl             %g5, 8, %l6
201         andcc           %g4, 0xff, %g0
202         be              4f
203          subcc          %g4, %l6, %g4
204         bne             4f
205          add            %i0, 4, %i0
206         ld              [%i1], %l2
207         add             %i1, 4, %i1
208         srl             %l2, 24, %g5
209         andcc           %i4, 0xff, %g4
210         be              4f
211          subcc          %g4, %g5, %g4
212         be,a            1b
213          ld             [%i0], %i4
214 4:      jmpl            %i7 + 8, %g0
215          restore        %g4, %g0, %o0
217 5:      ld              [%i1], %l2
218         add             %i1, 4, %i1
219         add             %i0, 4, %i0
220         srl             %l2, 24, %l6
221         andcc           %g4, 0xff, %g4
222         be              4b
223          subcc          %g4, %l6, %g4
224         bne             4b
225          srl            %l2, 16, %l6
226         andcc           %i4, 0xff, %g4
227         and             %l6, 0xff, %l6
228         be              4b
229          subcc          %g4, %l6, %g4
230         be,a            1b
231          ld             [%i0], %i4
232         jmpl            %i7 + 8, %g0
233          restore        %g4, %g0, %o0
235 6:      ld              [%i1], %l2
236         add             %i1, 4, %i1
237         add             %i0, 4, %i0
238         srl             %l2, 24, %l6
239         andcc           %g4, 0xff, %g4
240         be              4b
241          subcc          %g4, %l6, %g4
242         bne             4b
243          srl            %l2, 16, %l6
244         srl             %i4, 8, %g4
245         and             %l6, 0xff, %l6
246         andcc           %g4, 0xff, %g4
247         be              4b
248          subcc          %g4, %l6, %g4
249         bne             4b
250          srl            %l2, 8, %l6
251         andcc           %i4, 0xff, %g4
252         and             %l6, 0xff, %l6
253         be              4b
254          subcc          %g4, %l6, %g4
255         be,a            1b
256          ld             [%i0], %i4
257         jmpl            %i7 + 8, %g0
258          restore        %g4, %g0, %o0
259 END(strcmp)
260 libc_hidden_builtin_def (strcmp)