Undo accidental checkin.
[glibc.git] / sysdeps / i386 / i686 / multiarch / strcmp-sse4.S
blob0de0a113c041103cb61d5d39a17389ccb92187b8
1 /* strcmp with SSE4.2
2    Copyright (C) 2010 Free Software Foundation, Inc.
3    Contributed by Intel Corporation.
4    This file is part of the GNU C Library.
6    The GNU C Library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
11    The GNU C Library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
16    You should have received a copy of the GNU Lesser General Public
17    License along with the GNU C Library; if not, write to the Free
18    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19    02111-1307 USA.  */
21 #ifndef NOT_IN_libc
23 #include <sysdep.h>
24 #include "asm-syntax.h"
26 #define CFI_PUSH(REG)                                           \
27   cfi_adjust_cfa_offset (4);                                    \
28   cfi_rel_offset (REG, 0)
30 #define CFI_POP(REG)                                            \
31   cfi_adjust_cfa_offset (-4);                                   \
32   cfi_restore (REG)
34 #define PUSH(REG)       pushl REG; CFI_PUSH (REG)
35 #define POP(REG)        popl REG; CFI_POP (REG)
37 #ifndef USE_AS_STRNCMP
38 # ifndef STRCMP
39 #  define STRCMP        __strcmp_sse4_2
40 # endif
41 # define STR1           4
42 # define STR2           STR1+4
43 # define RETURN         ret; .p2align 4
44 #else
45 # ifndef STRCMP
46 #  define STRCMP        __strncmp_sse4_2
47 # endif
48 # define STR1           8
49 # define STR2           STR1+4
50 # define CNT            STR2+4
51 # define RETURN         POP (%ebp); ret; .p2align 4; CFI_PUSH (%ebp)
52 #endif
54         .section .text.sse4.2,"ax",@progbits
55 ENTRY (STRCMP)
56 #ifdef USE_AS_STRNCMP
57         PUSH    (%ebp)
58 #endif
59         mov     STR1(%esp), %edx
60         mov     STR2(%esp), %eax
61 #ifdef USE_AS_STRNCMP
62         movl    CNT(%esp), %ebp
63         test    %ebp, %ebp
64         je      L(eq)
65 #endif
66         mov     %dx, %cx
67         and     $0xfff, %cx
68         cmp     $0xff0, %cx
69         ja      L(first4bytes)
70         movdqu  (%edx), %xmm2
71         mov     %eax, %ecx
72         and     $0xfff, %ecx
73         cmp     $0xff0, %ecx
74         ja      L(first4bytes)
75         movd    %xmm2, %ecx
76         cmp     (%eax), %ecx
77         jne     L(less4bytes)
78         movdqu  (%eax), %xmm1
79         pxor    %xmm2, %xmm1
80         pxor    %xmm0, %xmm0
81         ptest   %xmm1, %xmm0
82         jnc     L(less16bytes)
83         pcmpeqb %xmm0, %xmm2
84         ptest   %xmm2, %xmm0
85         jnc     L(less16bytes)
87 #ifdef USE_AS_STRNCMP
88         sub     $16, %ebp
89         jbe     L(eq)
90 #endif
91         add     $16, %edx
92         add     $16, %eax
93 L(first4bytes):
94         movzbl  (%eax), %ecx
95         cmpb    %cl, (%edx)
96         jne     L(neq)
97         cmpl    $0, %ecx
98         je      L(eq)
100 #ifdef USE_AS_STRNCMP
101         cmp     $1, %ebp
102         je      L(eq)
103 #endif
105         movzbl  1(%eax), %ecx
106         cmpb    %cl, 1(%edx)
107         jne     L(neq)
108         cmpl    $0, %ecx
109         je      L(eq)
111 #ifdef USE_AS_STRNCMP
112         cmp     $2, %ebp
113         je      L(eq)
114 #endif
115         movzbl  2(%eax), %ecx
116         cmpb    %cl, 2(%edx)
117         jne     L(neq)
118         cmpl    $0, %ecx
119         je      L(eq)
121 #ifdef USE_AS_STRNCMP
122         cmp     $3, %ebp
123         je      L(eq)
124 #endif
125         movzbl  3(%eax), %ecx
126         cmpb    %cl, 3(%edx)
127         jne     L(neq)
128         cmpl    $0, %ecx
129         je      L(eq)
131 #ifdef USE_AS_STRNCMP
132         cmp     $4, %ebp
133         je      L(eq)
134 #endif
135         movzbl  4(%eax), %ecx
136         cmpb    %cl, 4(%edx)
137         jne     L(neq)
138         cmpl    $0, %ecx
139         je      L(eq)
141 #ifdef USE_AS_STRNCMP
142         cmp     $5, %ebp
143         je      L(eq)
144 #endif
145         movzbl  5(%eax), %ecx
146         cmpb    %cl, 5(%edx)
147         jne     L(neq)
148         cmpl    $0, %ecx
149         je      L(eq)
151 #ifdef USE_AS_STRNCMP
152         cmp     $6, %ebp
153         je      L(eq)
154 #endif
155         movzbl  6(%eax), %ecx
156         cmpb    %cl, 6(%edx)
157         jne     L(neq)
158         cmpl    $0, %ecx
159         je      L(eq)
161 #ifdef USE_AS_STRNCMP
162         cmp     $7, %ebp
163         je      L(eq)
164 #endif
165         movzbl  7(%eax), %ecx
166         cmpb    %cl, 7(%edx)
167         jne     L(neq)
168         cmpl    $0, %ecx
169         je      L(eq)
171 #ifdef USE_AS_STRNCMP
172         sub     $8, %ebp
173         je      L(eq)
174 #endif
175         add     $8, %eax
176         add     $8, %edx
178         PUSH    (%ebx)
179         PUSH    (%edi)
180         PUSH    (%esi)
181 #ifdef USE_AS_STRNCMP
182         cfi_remember_state
183 #endif
184         mov     %edx, %edi
185         mov     %eax, %esi
186         xorl    %eax, %eax
187 L(check_offset):
188         movl    %edi, %ebx
189         movl    %esi, %ecx
190         andl    $0xfff, %ebx
191         andl    $0xfff, %ecx
192         cmpl    %ebx, %ecx
193         cmovl   %ebx, %ecx
194         lea     -0xff0(%ecx), %edx
195         sub     %edx, %edi
196         sub     %edx, %esi
197         testl   %edx, %edx
198         jg      L(crosspage)
199 L(loop):
200         movdqu  (%esi,%edx), %xmm2
201         movdqu  (%edi,%edx), %xmm1
202         pcmpistri       $0x1a, %xmm2, %xmm1
203         jbe     L(end)
205 #ifdef USE_AS_STRNCMP
206         sub     $16, %ebp
207         jbe     L(more16byteseq)
208 #endif
210         add     $16, %edx
211         jle     L(loop)
212 L(crosspage):
213         movzbl  (%edi,%edx), %eax
214         movzbl  (%esi,%edx), %ebx
215         subl    %ebx, %eax
216         jne     L(ret)
217         testl   %ebx, %ebx
218         je      L(ret)
219 #ifdef USE_AS_STRNCMP
220         sub     $1, %ebp
221         jbe     L(more16byteseq)
222 #endif
223         inc     %edx
224         cmp     $15, %edx
225         jle     L(crosspage)
226         add     %edx, %edi
227         add     %edx, %esi
228         jmp     L(check_offset)
230         .p2align 4
231 L(end):
232         jnc     L(ret)
233 #ifdef USE_AS_STRNCMP
234         sub     %ecx, %ebp
235         jbe     L(more16byteseq)
236 #endif
237         lea     (%ecx,%edx), %ebx
238         movzbl  (%edi,%ebx), %eax
239         movzbl  (%esi,%ebx), %ecx
240         subl    %ecx, %eax
241 L(ret):
242         POP     (%esi)
243         POP     (%edi)
244         POP     (%ebx)
245 #ifdef USE_AS_STRNCMP
246         POP     (%ebp)
247 #endif
248         ret
250         .p2align 4
251 #ifdef USE_AS_STRNCMP
252         cfi_restore_state
253 L(more16byteseq):
254         POP     (%esi)
255         POP     (%edi)
256         POP     (%ebx)
257 #endif
258 L(eq):
259         xorl    %eax, %eax
260         RETURN
262 L(neq):
263         mov     $1, %eax
264         ja      L(neq_bigger)
265         neg     %eax
266 L(neq_bigger):
267         RETURN
269 L(less16bytes):
270         add     $0xfefefeff, %ecx
271         jnc     L(less4bytes)
272         xor     (%edx), %ecx
273         or      $0xfefefeff, %ecx
274         add     $1, %ecx
275         jnz     L(less4bytes)
277 #ifdef USE_AS_STRNCMP
278         cmp     $4, %ebp
279         jbe     L(eq)
280 #endif
281         mov     4(%edx), %ecx
282         cmp     4(%eax), %ecx
283         jne     L(more4bytes)
284         add     $0xfefefeff, %ecx
285         jnc     L(more4bytes)
286         xor     4(%edx), %ecx
287         or      $0xfefefeff, %ecx
288         add     $1, %ecx
289         jnz     L(more4bytes)
291 #ifdef USE_AS_STRNCMP
292         sub     $8, %ebp
293         jbe     L(eq)
294 #endif
296         add     $8, %edx
297         add     $8, %eax
298 L(less4bytes):
300         movzbl  (%eax), %ecx
301         cmpb    %cl, (%edx)
302         jne     L(neq)
303         cmpl    $0, %ecx
304         je      L(eq)
306 #ifdef USE_AS_STRNCMP
307         cmp     $1, %ebp
308         je      L(eq)
309 #endif
310         movzbl  1(%eax), %ecx
311         cmpb    %cl, 1(%edx)
312         jne     L(neq)
313         cmpl    $0, %ecx
314         je      L(eq)
316 #ifdef USE_AS_STRNCMP
317         cmp     $2, %ebp
318         je      L(eq)
319 #endif
321         movzbl  2(%eax), %ecx
322         cmpb    %cl, 2(%edx)
323         jne     L(neq)
324         cmpl    $0, %ecx
325         je      L(eq)
327 #ifdef USE_AS_STRNCMP
328         cmp     $3, %ebp
329         je      L(eq)
330 #endif
331         movzbl  3(%eax), %ecx
332         cmpb    %cl, 3(%edx)
333         jne     L(neq)
334         cmpl    $0, %ecx
335         je      L(eq)
337 L(more4bytes):
338 #ifdef USE_AS_STRNCMP
339         cmp     $4, %ebp
340         je      L(eq)
341 #endif
342         movzbl  4(%eax), %ecx
343         cmpb    %cl, 4(%edx)
344         jne     L(neq)
345         cmpl    $0, %ecx
346         je      L(eq)
349 #ifdef USE_AS_STRNCMP
350         cmp     $5, %ebp
351         je      L(eq)
352 #endif
353         movzbl  5(%eax), %ecx
354         cmpb    %cl, 5(%edx)
355         jne     L(neq)
356         cmpl    $0, %ecx
357         je      L(eq)
359 #ifdef USE_AS_STRNCMP
360         cmp     $6, %ebp
361         je      L(eq)
362 #endif
363         movzbl  6(%eax), %ecx
364         cmpb    %cl, 6(%edx)
365         jne     L(neq)
366         cmpl    $0, %ecx
367         je      L(eq)
369 #ifdef USE_AS_STRNCMP
370         cmp     $7, %ebp
371         je      L(eq)
372 #endif
373         movzbl  7(%eax), %ecx
374         cmpb    %cl, 7(%edx)
375         jne     L(neq)
376         jmp     L(eq)
378 END (STRCMP)
380 #endif