Update copyright notices with scripts/update-copyrights.
[jlayton/glibc.git] / sysdeps / x86_64 / multiarch / memcmp-sse4.S
1 /* memcmp with SSE4.1, wmemcmp with SSE4.1
2    Copyright (C) 2010-2013 Free Software Foundation, Inc.
3    Contributed by Intel Corporation.
4    This file is part of the GNU C Library.
5
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.
10
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.
15
16    You should have received a copy of the GNU Lesser General Public
17    License along with the GNU C Library; if not, see
18    <http://www.gnu.org/licenses/>.  */
19
20 #ifndef NOT_IN_libc
21
22 # include <sysdep.h>
23
24 # ifndef MEMCMP
25 #  define MEMCMP        __memcmp_sse4_1
26 # endif
27
28 # ifndef ALIGN
29 #  define ALIGN(n)      .p2align n
30 # endif
31
32 # define JMPTBL(I, B)   (I - B)
33
34 # define BRANCH_TO_JMPTBL_ENTRY(TABLE, INDEX, SCALE)            \
35   lea           TABLE(%rip), %r11;                              \
36   movslq        (%r11, INDEX, SCALE), %rcx;                     \
37   add           %r11, %rcx;                                     \
38   jmp           *%rcx;                                          \
39   ud2
40
41 /* Warning!
42            wmemcmp has to use SIGNED comparison for elements.
43            memcmp has to use UNSIGNED comparison for elemnts.
44 */
45
46         .section .text.sse4.1,"ax",@progbits
47 ENTRY (MEMCMP)
48 # ifdef USE_AS_WMEMCMP
49         shl     $2, %rdx
50 # endif
51         pxor    %xmm0, %xmm0
52         cmp     $79, %rdx
53         ja      L(79bytesormore)
54 # ifndef USE_AS_WMEMCMP
55         cmp     $1, %rdx
56         je      L(firstbyte)
57 # endif
58         add     %rdx, %rsi
59         add     %rdx, %rdi
60         BRANCH_TO_JMPTBL_ENTRY(L(table_64bytes), %rdx, 4)
61
62 # ifndef USE_AS_WMEMCMP
63         ALIGN (4)
64 L(firstbyte):
65         movzbl  (%rdi), %eax
66         movzbl  (%rsi), %ecx
67         sub     %ecx, %eax
68         ret
69 # endif
70
71         ALIGN (4)
72 L(79bytesormore):
73         movdqu  (%rsi), %xmm1
74         movdqu  (%rdi), %xmm2
75         pxor    %xmm1, %xmm2
76         ptest   %xmm2, %xmm0
77         jnc     L(16bytesin256)
78         mov     %rsi, %rcx
79         and     $-16, %rsi
80         add     $16, %rsi
81         sub     %rsi, %rcx
82
83         sub     %rcx, %rdi
84         add     %rcx, %rdx
85         test    $0xf, %rdi
86         jz      L(2aligned)
87
88         cmp     $128, %rdx
89         ja      L(128bytesormore)
90 L(less128bytes):
91         sub     $64, %rdx
92
93         movdqu  (%rdi), %xmm2
94         pxor    (%rsi), %xmm2
95         ptest   %xmm2, %xmm0
96         jnc     L(16bytesin256)
97
98         movdqu  16(%rdi), %xmm2
99         pxor    16(%rsi), %xmm2
100         ptest   %xmm2, %xmm0
101         jnc     L(32bytesin256)
102
103         movdqu  32(%rdi), %xmm2
104         pxor    32(%rsi), %xmm2
105         ptest   %xmm2, %xmm0
106         jnc     L(48bytesin256)
107
108         movdqu  48(%rdi), %xmm2
109         pxor    48(%rsi), %xmm2
110         ptest   %xmm2, %xmm0
111         jnc     L(64bytesin256)
112         cmp     $32, %rdx
113         jb      L(less32bytesin64)
114
115         movdqu  64(%rdi), %xmm2
116         pxor    64(%rsi), %xmm2
117         ptest   %xmm2, %xmm0
118         jnc     L(80bytesin256)
119
120         movdqu  80(%rdi), %xmm2
121         pxor    80(%rsi), %xmm2
122         ptest   %xmm2, %xmm0
123         jnc     L(96bytesin256)
124         sub     $32, %rdx
125         add     $32, %rdi
126         add     $32, %rsi
127 L(less32bytesin64):
128         add     $64, %rdi
129         add     $64, %rsi
130         add     %rdx, %rsi
131         add     %rdx, %rdi
132         BRANCH_TO_JMPTBL_ENTRY(L(table_64bytes), %rdx, 4)
133
134 L(128bytesormore):
135         cmp     $512, %rdx
136         ja      L(512bytesormore)
137         cmp     $256, %rdx
138         ja      L(less512bytes)
139 L(less256bytes):
140         sub     $128, %rdx
141
142         movdqu  (%rdi), %xmm2
143         pxor    (%rsi), %xmm2
144         ptest   %xmm2, %xmm0
145         jnc     L(16bytesin256)
146
147         movdqu  16(%rdi), %xmm2
148         pxor    16(%rsi), %xmm2
149         ptest   %xmm2, %xmm0
150         jnc     L(32bytesin256)
151
152         movdqu  32(%rdi), %xmm2
153         pxor    32(%rsi), %xmm2
154         ptest   %xmm2, %xmm0
155         jnc     L(48bytesin256)
156
157         movdqu  48(%rdi), %xmm2
158         pxor    48(%rsi), %xmm2
159         ptest   %xmm2, %xmm0
160         jnc     L(64bytesin256)
161
162         movdqu  64(%rdi), %xmm2
163         pxor    64(%rsi), %xmm2
164         ptest   %xmm2, %xmm0
165         jnc     L(80bytesin256)
166
167         movdqu  80(%rdi), %xmm2
168         pxor    80(%rsi), %xmm2
169         ptest   %xmm2, %xmm0
170         jnc     L(96bytesin256)
171
172         movdqu  96(%rdi), %xmm2
173         pxor    96(%rsi), %xmm2
174         ptest   %xmm2, %xmm0
175         jnc     L(112bytesin256)
176
177         movdqu  112(%rdi), %xmm2
178         pxor    112(%rsi), %xmm2
179         ptest   %xmm2, %xmm0
180         jnc     L(128bytesin256)
181
182         add     $128, %rsi
183         add     $128, %rdi
184
185         cmp     $64, %rdx
186         jae     L(less128bytes)
187
188         cmp     $32, %rdx
189         jb      L(less32bytesin128)
190
191         movdqu  (%rdi), %xmm2
192         pxor    (%rsi), %xmm2
193         ptest   %xmm2, %xmm0
194         jnc     L(16bytesin256)
195
196         movdqu  16(%rdi), %xmm2
197         pxor    16(%rsi), %xmm2
198         ptest   %xmm2, %xmm0
199         jnc     L(32bytesin256)
200         sub     $32, %rdx
201         add     $32, %rdi
202         add     $32, %rsi
203 L(less32bytesin128):
204         add     %rdx, %rsi
205         add     %rdx, %rdi
206         BRANCH_TO_JMPTBL_ENTRY(L(table_64bytes), %rdx, 4)
207
208 L(less512bytes):
209         sub     $256, %rdx
210         movdqu  (%rdi), %xmm2
211         pxor    (%rsi), %xmm2
212         ptest   %xmm2, %xmm0
213         jnc     L(16bytesin256)
214
215         movdqu  16(%rdi), %xmm2
216         pxor    16(%rsi), %xmm2
217         ptest   %xmm2, %xmm0
218         jnc     L(32bytesin256)
219
220         movdqu  32(%rdi), %xmm2
221         pxor    32(%rsi), %xmm2
222         ptest   %xmm2, %xmm0
223         jnc     L(48bytesin256)
224
225         movdqu  48(%rdi), %xmm2
226         pxor    48(%rsi), %xmm2
227         ptest   %xmm2, %xmm0
228         jnc     L(64bytesin256)
229
230         movdqu  64(%rdi), %xmm2
231         pxor    64(%rsi), %xmm2
232         ptest   %xmm2, %xmm0
233         jnc     L(80bytesin256)
234
235         movdqu  80(%rdi), %xmm2
236         pxor    80(%rsi), %xmm2
237         ptest   %xmm2, %xmm0
238         jnc     L(96bytesin256)
239
240         movdqu  96(%rdi), %xmm2
241         pxor    96(%rsi), %xmm2
242         ptest   %xmm2, %xmm0
243         jnc     L(112bytesin256)
244
245         movdqu  112(%rdi), %xmm2
246         pxor    112(%rsi), %xmm2
247         ptest   %xmm2, %xmm0
248         jnc     L(128bytesin256)
249
250         movdqu  128(%rdi), %xmm2
251         pxor    128(%rsi), %xmm2
252         ptest   %xmm2, %xmm0
253         jnc     L(144bytesin256)
254
255         movdqu  144(%rdi), %xmm2
256         pxor    144(%rsi), %xmm2
257         ptest   %xmm2, %xmm0
258         jnc     L(160bytesin256)
259
260         movdqu  160(%rdi), %xmm2
261         pxor    160(%rsi), %xmm2
262         ptest   %xmm2, %xmm0
263         jnc     L(176bytesin256)
264
265         movdqu  176(%rdi), %xmm2
266         pxor    176(%rsi), %xmm2
267         ptest   %xmm2, %xmm0
268         jnc     L(192bytesin256)
269
270         movdqu  192(%rdi), %xmm2
271         pxor    192(%rsi), %xmm2
272         ptest   %xmm2, %xmm0
273         jnc     L(208bytesin256)
274
275         movdqu  208(%rdi), %xmm2
276         pxor    208(%rsi), %xmm2
277         ptest   %xmm2, %xmm0
278         jnc     L(224bytesin256)
279
280         movdqu  224(%rdi), %xmm2
281         pxor    224(%rsi), %xmm2
282         ptest   %xmm2, %xmm0
283         jnc     L(240bytesin256)
284
285         movdqu  240(%rdi), %xmm2
286         pxor    240(%rsi), %xmm2
287         ptest   %xmm2, %xmm0
288         jnc     L(256bytesin256)
289
290         add     $256, %rsi
291         add     $256, %rdi
292
293         cmp     $128, %rdx
294         jae     L(less256bytes)
295
296         cmp     $64, %rdx
297         jae     L(less128bytes)
298
299         cmp     $32, %rdx
300         jb      L(less32bytesin256)
301
302         movdqu  (%rdi), %xmm2
303         pxor    (%rsi), %xmm2
304         ptest   %xmm2, %xmm0
305         jnc     L(16bytesin256)
306
307         movdqu  16(%rdi), %xmm2
308         pxor    16(%rsi), %xmm2
309         ptest   %xmm2, %xmm0
310         jnc     L(32bytesin256)
311         sub     $32, %rdx
312         add     $32, %rdi
313         add     $32, %rsi
314 L(less32bytesin256):
315         add     %rdx, %rsi
316         add     %rdx, %rdi
317         BRANCH_TO_JMPTBL_ENTRY(L(table_64bytes), %rdx, 4)
318
319         ALIGN (4)
320 L(512bytesormore):
321 # ifdef DATA_CACHE_SIZE_HALF
322         mov     $DATA_CACHE_SIZE_HALF, %R8_LP
323 # else
324         mov     __x86_64_data_cache_size_half(%rip), %R8_LP
325 # endif
326         mov     %r8, %r9
327         shr     $1, %r8
328         add     %r9, %r8
329         cmp     %r8, %rdx
330         ja      L(L2_L3_cache_unaglined)
331         sub     $64, %rdx
332         ALIGN (4)
333 L(64bytesormore_loop):
334         movdqu  (%rdi), %xmm2
335         pxor    (%rsi), %xmm2
336         movdqa  %xmm2, %xmm1
337
338         movdqu  16(%rdi), %xmm3
339         pxor    16(%rsi), %xmm3
340         por     %xmm3, %xmm1
341
342         movdqu  32(%rdi), %xmm4
343         pxor    32(%rsi), %xmm4
344         por     %xmm4, %xmm1
345
346         movdqu  48(%rdi), %xmm5
347         pxor    48(%rsi), %xmm5
348         por     %xmm5, %xmm1
349
350         ptest   %xmm1, %xmm0
351         jnc     L(64bytesormore_loop_end)
352         add     $64, %rsi
353         add     $64, %rdi
354         sub     $64, %rdx
355         jae     L(64bytesormore_loop)
356
357         add     $64, %rdx
358         add     %rdx, %rsi
359         add     %rdx, %rdi
360         BRANCH_TO_JMPTBL_ENTRY(L(table_64bytes), %rdx, 4)
361
362 L(L2_L3_cache_unaglined):
363         sub     $64, %rdx
364         ALIGN (4)
365 L(L2_L3_unaligned_128bytes_loop):
366         prefetchnta 0x1c0(%rdi)
367         prefetchnta 0x1c0(%rsi)
368         movdqu  (%rdi), %xmm2
369         pxor    (%rsi), %xmm2
370         movdqa  %xmm2, %xmm1
371
372         movdqu  16(%rdi), %xmm3
373         pxor    16(%rsi), %xmm3
374         por     %xmm3, %xmm1
375
376         movdqu  32(%rdi), %xmm4
377         pxor    32(%rsi), %xmm4
378         por     %xmm4, %xmm1
379
380         movdqu  48(%rdi), %xmm5
381         pxor    48(%rsi), %xmm5
382         por     %xmm5, %xmm1
383
384         ptest   %xmm1, %xmm0
385         jnc     L(64bytesormore_loop_end)
386         add     $64, %rsi
387         add     $64, %rdi
388         sub     $64, %rdx
389         jae     L(L2_L3_unaligned_128bytes_loop)
390
391         add     $64, %rdx
392         add     %rdx, %rsi
393         add     %rdx, %rdi
394         BRANCH_TO_JMPTBL_ENTRY(L(table_64bytes), %rdx, 4)
395
396 /*
397  * This case is for machines which are sensitive for unaligned instructions.
398  */
399         ALIGN (4)
400 L(2aligned):
401         cmp     $128, %rdx
402         ja      L(128bytesormorein2aligned)
403 L(less128bytesin2aligned):
404         sub     $64, %rdx
405
406         movdqa  (%rdi), %xmm2
407         pxor    (%rsi), %xmm2
408         ptest   %xmm2, %xmm0
409         jnc     L(16bytesin256)
410
411         movdqa  16(%rdi), %xmm2
412         pxor    16(%rsi), %xmm2
413         ptest   %xmm2, %xmm0
414         jnc     L(32bytesin256)
415
416         movdqa  32(%rdi), %xmm2
417         pxor    32(%rsi), %xmm2
418         ptest   %xmm2, %xmm0
419         jnc     L(48bytesin256)
420
421         movdqa  48(%rdi), %xmm2
422         pxor    48(%rsi), %xmm2
423         ptest   %xmm2, %xmm0
424         jnc     L(64bytesin256)
425         cmp     $32, %rdx
426         jb      L(less32bytesin64in2alinged)
427
428         movdqa  64(%rdi), %xmm2
429         pxor    64(%rsi), %xmm2
430         ptest   %xmm2, %xmm0
431         jnc     L(80bytesin256)
432
433         movdqa  80(%rdi), %xmm2
434         pxor    80(%rsi), %xmm2
435         ptest   %xmm2, %xmm0
436         jnc     L(96bytesin256)
437         sub     $32, %rdx
438         add     $32, %rdi
439         add     $32, %rsi
440 L(less32bytesin64in2alinged):
441         add     $64, %rdi
442         add     $64, %rsi
443         add     %rdx, %rsi
444         add     %rdx, %rdi
445         BRANCH_TO_JMPTBL_ENTRY(L(table_64bytes), %rdx, 4)
446
447         ALIGN (4)
448 L(128bytesormorein2aligned):
449         cmp     $512, %rdx
450         ja      L(512bytesormorein2aligned)
451         cmp     $256, %rdx
452         ja      L(256bytesormorein2aligned)
453 L(less256bytesin2alinged):
454         sub     $128, %rdx
455
456         movdqa  (%rdi), %xmm2
457         pxor    (%rsi), %xmm2
458         ptest   %xmm2, %xmm0
459         jnc     L(16bytesin256)
460
461         movdqa  16(%rdi), %xmm2
462         pxor    16(%rsi), %xmm2
463         ptest   %xmm2, %xmm0
464         jnc     L(32bytesin256)
465
466         movdqa  32(%rdi), %xmm2
467         pxor    32(%rsi), %xmm2
468         ptest   %xmm2, %xmm0
469         jnc     L(48bytesin256)
470
471         movdqa  48(%rdi), %xmm2
472         pxor    48(%rsi), %xmm2
473         ptest   %xmm2, %xmm0
474         jnc     L(64bytesin256)
475
476         movdqa  64(%rdi), %xmm2
477         pxor    64(%rsi), %xmm2
478         ptest   %xmm2, %xmm0
479         jnc     L(80bytesin256)
480
481         movdqa  80(%rdi), %xmm2
482         pxor    80(%rsi), %xmm2
483         ptest   %xmm2, %xmm0
484         jnc     L(96bytesin256)
485
486         movdqa  96(%rdi), %xmm2
487         pxor    96(%rsi), %xmm2
488         ptest   %xmm2, %xmm0
489         jnc     L(112bytesin256)
490
491         movdqa  112(%rdi), %xmm2
492         pxor    112(%rsi), %xmm2
493         ptest   %xmm2, %xmm0
494         jnc     L(128bytesin256)
495
496         add     $128, %rsi
497         add     $128, %rdi
498
499         cmp     $64, %rdx
500         jae     L(less128bytesin2aligned)
501
502         cmp     $32, %rdx
503         jb      L(less32bytesin128in2aligned)
504
505         movdqu  (%rdi), %xmm2
506         pxor    (%rsi), %xmm2
507         ptest   %xmm2, %xmm0
508         jnc     L(16bytesin256)
509
510         movdqu  16(%rdi), %xmm2
511         pxor    16(%rsi), %xmm2
512         ptest   %xmm2, %xmm0
513         jnc     L(32bytesin256)
514         sub     $32, %rdx
515         add     $32, %rdi
516         add     $32, %rsi
517 L(less32bytesin128in2aligned):
518         add     %rdx, %rsi
519         add     %rdx, %rdi
520         BRANCH_TO_JMPTBL_ENTRY(L(table_64bytes), %rdx, 4)
521
522         ALIGN (4)
523 L(256bytesormorein2aligned):
524
525         sub     $256, %rdx
526         movdqa  (%rdi), %xmm2
527         pxor    (%rsi), %xmm2
528         ptest   %xmm2, %xmm0
529         jnc     L(16bytesin256)
530
531         movdqa  16(%rdi), %xmm2
532         pxor    16(%rsi), %xmm2
533         ptest   %xmm2, %xmm0
534         jnc     L(32bytesin256)
535
536         movdqa  32(%rdi), %xmm2
537         pxor    32(%rsi), %xmm2
538         ptest   %xmm2, %xmm0
539         jnc     L(48bytesin256)
540
541         movdqa  48(%rdi), %xmm2
542         pxor    48(%rsi), %xmm2
543         ptest   %xmm2, %xmm0
544         jnc     L(64bytesin256)
545
546         movdqa  64(%rdi), %xmm2
547         pxor    64(%rsi), %xmm2
548         ptest   %xmm2, %xmm0
549         jnc     L(80bytesin256)
550
551         movdqa  80(%rdi), %xmm2
552         pxor    80(%rsi), %xmm2
553         ptest   %xmm2, %xmm0
554         jnc     L(96bytesin256)
555
556         movdqa  96(%rdi), %xmm2
557         pxor    96(%rsi), %xmm2
558         ptest   %xmm2, %xmm0
559         jnc     L(112bytesin256)
560
561         movdqa  112(%rdi), %xmm2
562         pxor    112(%rsi), %xmm2
563         ptest   %xmm2, %xmm0
564         jnc     L(128bytesin256)
565
566         movdqa  128(%rdi), %xmm2
567         pxor    128(%rsi), %xmm2
568         ptest   %xmm2, %xmm0
569         jnc     L(144bytesin256)
570
571         movdqa  144(%rdi), %xmm2
572         pxor    144(%rsi), %xmm2
573         ptest   %xmm2, %xmm0
574         jnc     L(160bytesin256)
575
576         movdqa  160(%rdi), %xmm2
577         pxor    160(%rsi), %xmm2
578         ptest   %xmm2, %xmm0
579         jnc     L(176bytesin256)
580
581         movdqa  176(%rdi), %xmm2
582         pxor    176(%rsi), %xmm2
583         ptest   %xmm2, %xmm0
584         jnc     L(192bytesin256)
585
586         movdqa  192(%rdi), %xmm2
587         pxor    192(%rsi), %xmm2
588         ptest   %xmm2, %xmm0
589         jnc     L(208bytesin256)
590
591         movdqa  208(%rdi), %xmm2
592         pxor    208(%rsi), %xmm2
593         ptest   %xmm2, %xmm0
594         jnc     L(224bytesin256)
595
596         movdqa  224(%rdi), %xmm2
597         pxor    224(%rsi), %xmm2
598         ptest   %xmm2, %xmm0
599         jnc     L(240bytesin256)
600
601         movdqa  240(%rdi), %xmm2
602         pxor    240(%rsi), %xmm2
603         ptest   %xmm2, %xmm0
604         jnc     L(256bytesin256)
605
606         add     $256, %rsi
607         add     $256, %rdi
608
609         cmp     $128, %rdx
610         jae     L(less256bytesin2alinged)
611
612         cmp     $64, %rdx
613         jae     L(less128bytesin2aligned)
614
615         cmp     $32, %rdx
616         jb      L(less32bytesin256in2alinged)
617
618         movdqa  (%rdi), %xmm2
619         pxor    (%rsi), %xmm2
620         ptest   %xmm2, %xmm0
621         jnc     L(16bytesin256)
622
623         movdqa  16(%rdi), %xmm2
624         pxor    16(%rsi), %xmm2
625         ptest   %xmm2, %xmm0
626         jnc     L(32bytesin256)
627         sub     $32, %rdx
628         add     $32, %rdi
629         add     $32, %rsi
630 L(less32bytesin256in2alinged):
631         add     %rdx, %rsi
632         add     %rdx, %rdi
633         BRANCH_TO_JMPTBL_ENTRY(L(table_64bytes), %rdx, 4)
634
635         ALIGN (4)
636 L(512bytesormorein2aligned):
637 # ifdef DATA_CACHE_SIZE_HALF
638         mov     $DATA_CACHE_SIZE_HALF, %R8_LP
639 # else
640         mov     __x86_64_data_cache_size_half(%rip), %R8_LP
641 # endif
642         mov     %r8, %r9
643         shr     $1, %r8
644         add     %r9, %r8
645         cmp     %r8, %rdx
646         ja      L(L2_L3_cache_aglined)
647
648         sub     $64, %rdx
649         ALIGN (4)
650 L(64bytesormore_loopin2aligned):
651         movdqa  (%rdi), %xmm2
652         pxor    (%rsi), %xmm2
653         movdqa  %xmm2, %xmm1
654
655         movdqa  16(%rdi), %xmm3
656         pxor    16(%rsi), %xmm3
657         por     %xmm3, %xmm1
658
659         movdqa  32(%rdi), %xmm4
660         pxor    32(%rsi), %xmm4
661         por     %xmm4, %xmm1
662
663         movdqa  48(%rdi), %xmm5
664         pxor    48(%rsi), %xmm5
665         por     %xmm5, %xmm1
666
667         ptest   %xmm1, %xmm0
668         jnc     L(64bytesormore_loop_end)
669         add     $64, %rsi
670         add     $64, %rdi
671         sub     $64, %rdx
672         jae     L(64bytesormore_loopin2aligned)
673
674         add     $64, %rdx
675         add     %rdx, %rsi
676         add     %rdx, %rdi
677         BRANCH_TO_JMPTBL_ENTRY(L(table_64bytes), %rdx, 4)
678 L(L2_L3_cache_aglined):
679         sub     $64, %rdx
680
681         ALIGN (4)
682 L(L2_L3_aligned_128bytes_loop):
683         prefetchnta 0x1c0(%rdi)
684         prefetchnta 0x1c0(%rsi)
685         movdqa  (%rdi), %xmm2
686         pxor    (%rsi), %xmm2
687         movdqa  %xmm2, %xmm1
688
689         movdqa  16(%rdi), %xmm3
690         pxor    16(%rsi), %xmm3
691         por     %xmm3, %xmm1
692
693         movdqa  32(%rdi), %xmm4
694         pxor    32(%rsi), %xmm4
695         por     %xmm4, %xmm1
696
697         movdqa  48(%rdi), %xmm5
698         pxor    48(%rsi), %xmm5
699         por     %xmm5, %xmm1
700
701         ptest   %xmm1, %xmm0
702         jnc     L(64bytesormore_loop_end)
703         add     $64, %rsi
704         add     $64, %rdi
705         sub     $64, %rdx
706         jae     L(L2_L3_aligned_128bytes_loop)
707
708         add     $64, %rdx
709         add     %rdx, %rsi
710         add     %rdx, %rdi
711         BRANCH_TO_JMPTBL_ENTRY(L(table_64bytes), %rdx, 4)
712
713
714         ALIGN (4)
715 L(64bytesormore_loop_end):
716         add     $16, %rdi
717         add     $16, %rsi
718         ptest   %xmm2, %xmm0
719         jnc     L(16bytes)
720
721         add     $16, %rdi
722         add     $16, %rsi
723         ptest   %xmm3, %xmm0
724         jnc     L(16bytes)
725
726         add     $16, %rdi
727         add     $16, %rsi
728         ptest   %xmm4, %xmm0
729         jnc     L(16bytes)
730
731         add     $16, %rdi
732         add     $16, %rsi
733         jmp     L(16bytes)
734
735 L(256bytesin256):
736         add     $256, %rdi
737         add     $256, %rsi
738         jmp     L(16bytes)
739 L(240bytesin256):
740         add     $240, %rdi
741         add     $240, %rsi
742         jmp     L(16bytes)
743 L(224bytesin256):
744         add     $224, %rdi
745         add     $224, %rsi
746         jmp     L(16bytes)
747 L(208bytesin256):
748         add     $208, %rdi
749         add     $208, %rsi
750         jmp     L(16bytes)
751 L(192bytesin256):
752         add     $192, %rdi
753         add     $192, %rsi
754         jmp     L(16bytes)
755 L(176bytesin256):
756         add     $176, %rdi
757         add     $176, %rsi
758         jmp     L(16bytes)
759 L(160bytesin256):
760         add     $160, %rdi
761         add     $160, %rsi
762         jmp     L(16bytes)
763 L(144bytesin256):
764         add     $144, %rdi
765         add     $144, %rsi
766         jmp     L(16bytes)
767 L(128bytesin256):
768         add     $128, %rdi
769         add     $128, %rsi
770         jmp     L(16bytes)
771 L(112bytesin256):
772         add     $112, %rdi
773         add     $112, %rsi
774         jmp     L(16bytes)
775 L(96bytesin256):
776         add     $96, %rdi
777         add     $96, %rsi
778         jmp     L(16bytes)
779 L(80bytesin256):
780         add     $80, %rdi
781         add     $80, %rsi
782         jmp     L(16bytes)
783 L(64bytesin256):
784         add     $64, %rdi
785         add     $64, %rsi
786         jmp     L(16bytes)
787 L(48bytesin256):
788         add     $16, %rdi
789         add     $16, %rsi
790 L(32bytesin256):
791         add     $16, %rdi
792         add     $16, %rsi
793 L(16bytesin256):
794         add     $16, %rdi
795         add     $16, %rsi
796 L(16bytes):
797         mov     -16(%rdi), %rax
798         mov     -16(%rsi), %rcx
799         cmp     %rax, %rcx
800         jne     L(diffin8bytes)
801 L(8bytes):
802         mov     -8(%rdi), %rax
803         mov     -8(%rsi), %rcx
804         cmp     %rax, %rcx
805         jne     L(diffin8bytes)
806         xor     %eax, %eax
807         ret
808
809         ALIGN (4)
810 L(12bytes):
811         mov     -12(%rdi), %rax
812         mov     -12(%rsi), %rcx
813         cmp     %rax, %rcx
814         jne     L(diffin8bytes)
815 L(4bytes):
816         mov     -4(%rsi), %ecx
817 # ifndef USE_AS_WMEMCMP
818         mov     -4(%rdi), %eax
819         cmp     %eax, %ecx
820 # else
821         cmp     -4(%rdi), %ecx
822 # endif
823         jne     L(diffin4bytes)
824 L(0bytes):
825         xor     %eax, %eax
826         ret
827
828 # ifndef USE_AS_WMEMCMP
829 /* unreal case for wmemcmp */
830         ALIGN (4)
831 L(65bytes):
832         movdqu  -65(%rdi), %xmm1
833         movdqu  -65(%rsi), %xmm2
834         mov     $-65, %dl
835         pxor    %xmm1, %xmm2
836         ptest   %xmm2, %xmm0
837         jnc     L(less16bytes)
838 L(49bytes):
839         movdqu  -49(%rdi), %xmm1
840         movdqu  -49(%rsi), %xmm2
841         mov     $-49, %dl
842         pxor    %xmm1, %xmm2
843         ptest   %xmm2, %xmm0
844         jnc     L(less16bytes)
845 L(33bytes):
846         movdqu  -33(%rdi), %xmm1
847         movdqu  -33(%rsi), %xmm2
848         mov     $-33, %dl
849         pxor    %xmm1, %xmm2
850         ptest   %xmm2, %xmm0
851         jnc     L(less16bytes)
852 L(17bytes):
853         mov     -17(%rdi), %rax
854         mov     -17(%rsi), %rcx
855         cmp     %rax, %rcx
856         jne     L(diffin8bytes)
857 L(9bytes):
858         mov     -9(%rdi), %rax
859         mov     -9(%rsi), %rcx
860         cmp     %rax, %rcx
861         jne     L(diffin8bytes)
862         movzbl  -1(%rdi), %eax
863         movzbl  -1(%rsi), %edx
864         sub     %edx, %eax
865         ret
866
867         ALIGN (4)
868 L(13bytes):
869         mov     -13(%rdi), %rax
870         mov     -13(%rsi), %rcx
871         cmp     %rax, %rcx
872         jne     L(diffin8bytes)
873         mov     -8(%rdi), %rax
874         mov     -8(%rsi), %rcx
875         cmp     %rax, %rcx
876         jne     L(diffin8bytes)
877         xor     %eax, %eax
878         ret
879
880         ALIGN (4)
881 L(5bytes):
882         mov     -5(%rdi), %eax
883         mov     -5(%rsi), %ecx
884         cmp     %eax, %ecx
885         jne     L(diffin4bytes)
886         movzbl  -1(%rdi), %eax
887         movzbl  -1(%rsi), %edx
888         sub     %edx, %eax
889         ret
890
891         ALIGN (4)
892 L(66bytes):
893         movdqu  -66(%rdi), %xmm1
894         movdqu  -66(%rsi), %xmm2
895         mov     $-66, %dl
896         pxor    %xmm1, %xmm2
897         ptest   %xmm2, %xmm0
898         jnc     L(less16bytes)
899 L(50bytes):
900         movdqu  -50(%rdi), %xmm1
901         movdqu  -50(%rsi), %xmm2
902         mov     $-50, %dl
903         pxor    %xmm1, %xmm2
904         ptest   %xmm2, %xmm0
905         jnc     L(less16bytes)
906 L(34bytes):
907         movdqu  -34(%rdi), %xmm1
908         movdqu  -34(%rsi), %xmm2
909         mov     $-34, %dl
910         pxor    %xmm1, %xmm2
911         ptest   %xmm2, %xmm0
912         jnc     L(less16bytes)
913 L(18bytes):
914         mov     -18(%rdi), %rax
915         mov     -18(%rsi), %rcx
916         cmp     %rax, %rcx
917         jne     L(diffin8bytes)
918 L(10bytes):
919         mov     -10(%rdi), %rax
920         mov     -10(%rsi), %rcx
921         cmp     %rax, %rcx
922         jne     L(diffin8bytes)
923         movzwl  -2(%rdi), %eax
924         movzwl  -2(%rsi), %ecx
925         cmp     %cl, %al
926         jne     L(end)
927         and     $0xffff, %eax
928         and     $0xffff, %ecx
929         sub     %ecx, %eax
930         ret
931
932         ALIGN (4)
933 L(14bytes):
934         mov     -14(%rdi), %rax
935         mov     -14(%rsi), %rcx
936         cmp     %rax, %rcx
937         jne     L(diffin8bytes)
938         mov     -8(%rdi), %rax
939         mov     -8(%rsi), %rcx
940         cmp     %rax, %rcx
941         jne     L(diffin8bytes)
942         xor     %eax, %eax
943         ret
944
945         ALIGN (4)
946 L(6bytes):
947         mov     -6(%rdi), %eax
948         mov     -6(%rsi), %ecx
949         cmp     %eax, %ecx
950         jne     L(diffin4bytes)
951 L(2bytes):
952         movzwl  -2(%rsi), %ecx
953         movzwl  -2(%rdi), %eax
954         cmp     %cl, %al
955         jne     L(end)
956         and     $0xffff, %eax
957         and     $0xffff, %ecx
958         sub     %ecx, %eax
959         ret
960
961         ALIGN (4)
962 L(67bytes):
963         movdqu  -67(%rdi), %xmm2
964         movdqu  -67(%rsi), %xmm1
965         mov     $-67, %dl
966         pxor    %xmm1, %xmm2
967         ptest   %xmm2, %xmm0
968         jnc     L(less16bytes)
969 L(51bytes):
970         movdqu  -51(%rdi), %xmm2
971         movdqu  -51(%rsi), %xmm1
972         mov     $-51, %dl
973         pxor    %xmm1, %xmm2
974         ptest   %xmm2, %xmm0
975         jnc     L(less16bytes)
976 L(35bytes):
977         movdqu  -35(%rsi), %xmm1
978         movdqu  -35(%rdi), %xmm2
979         mov     $-35, %dl
980         pxor    %xmm1, %xmm2
981         ptest   %xmm2, %xmm0
982         jnc     L(less16bytes)
983 L(19bytes):
984         mov     -19(%rdi), %rax
985         mov     -19(%rsi), %rcx
986         cmp     %rax, %rcx
987         jne     L(diffin8bytes)
988 L(11bytes):
989         mov     -11(%rdi), %rax
990         mov     -11(%rsi), %rcx
991         cmp     %rax, %rcx
992         jne     L(diffin8bytes)
993         mov     -4(%rdi), %eax
994         mov     -4(%rsi), %ecx
995         cmp     %eax, %ecx
996         jne     L(diffin4bytes)
997         xor     %eax, %eax
998         ret
999
1000         ALIGN (4)
1001 L(15bytes):
1002         mov     -15(%rdi), %rax
1003         mov     -15(%rsi), %rcx
1004         cmp     %rax, %rcx
1005         jne     L(diffin8bytes)
1006         mov     -8(%rdi), %rax
1007         mov     -8(%rsi), %rcx
1008         cmp     %rax, %rcx
1009         jne     L(diffin8bytes)
1010         xor     %eax, %eax
1011         ret
1012
1013         ALIGN (4)
1014 L(7bytes):
1015         mov     -7(%rdi), %eax
1016         mov     -7(%rsi), %ecx
1017         cmp     %eax, %ecx
1018         jne     L(diffin4bytes)
1019         mov     -4(%rdi), %eax
1020         mov     -4(%rsi), %ecx
1021         cmp     %eax, %ecx
1022         jne     L(diffin4bytes)
1023         xor     %eax, %eax
1024         ret
1025
1026         ALIGN (4)
1027 L(3bytes):
1028         movzwl  -3(%rdi), %eax
1029         movzwl  -3(%rsi), %ecx
1030         cmp     %eax, %ecx
1031         jne     L(diffin2bytes)
1032 L(1bytes):
1033         movzbl  -1(%rdi), %eax
1034         movzbl  -1(%rsi), %ecx
1035         sub     %ecx, %eax
1036         ret
1037 # endif
1038
1039         ALIGN (4)
1040 L(68bytes):
1041         movdqu  -68(%rdi), %xmm2
1042         movdqu  -68(%rsi), %xmm1
1043         mov     $-68, %dl
1044         pxor    %xmm1, %xmm2
1045         ptest   %xmm2, %xmm0
1046         jnc     L(less16bytes)
1047 L(52bytes):
1048         movdqu  -52(%rdi), %xmm2
1049         movdqu  -52(%rsi), %xmm1
1050         mov     $-52, %dl
1051         pxor    %xmm1, %xmm2
1052         ptest   %xmm2, %xmm0
1053         jnc     L(less16bytes)
1054 L(36bytes):
1055         movdqu  -36(%rdi), %xmm2
1056         movdqu  -36(%rsi), %xmm1
1057         mov     $-36, %dl
1058         pxor    %xmm1, %xmm2
1059         ptest   %xmm2, %xmm0
1060         jnc     L(less16bytes)
1061 L(20bytes):
1062         movdqu  -20(%rdi), %xmm2
1063         movdqu  -20(%rsi), %xmm1
1064         mov     $-20, %dl
1065         pxor    %xmm1, %xmm2
1066         ptest   %xmm2, %xmm0
1067         jnc     L(less16bytes)
1068         mov     -4(%rsi), %ecx
1069
1070 # ifndef USE_AS_WMEMCMP
1071         mov     -4(%rdi), %eax
1072         cmp     %eax, %ecx
1073 # else
1074         cmp     -4(%rdi), %ecx
1075 # endif
1076         jne     L(diffin4bytes)
1077         xor     %eax, %eax
1078         ret
1079
1080 # ifndef USE_AS_WMEMCMP
1081 /* unreal cases for wmemcmp */
1082         ALIGN (4)
1083 L(69bytes):
1084         movdqu  -69(%rsi), %xmm1
1085         movdqu  -69(%rdi), %xmm2
1086         mov     $-69, %dl
1087         pxor    %xmm1, %xmm2
1088         ptest   %xmm2, %xmm0
1089         jnc     L(less16bytes)
1090 L(53bytes):
1091         movdqu  -53(%rsi), %xmm1
1092         movdqu  -53(%rdi), %xmm2
1093         mov     $-53, %dl
1094         pxor    %xmm1, %xmm2
1095         ptest   %xmm2, %xmm0
1096         jnc     L(less16bytes)
1097 L(37bytes):
1098         movdqu  -37(%rsi), %xmm1
1099         movdqu  -37(%rdi), %xmm2
1100         mov     $-37, %dl
1101         pxor    %xmm1, %xmm2
1102         ptest   %xmm2, %xmm0
1103         jnc     L(less16bytes)
1104 L(21bytes):
1105         movdqu  -21(%rsi), %xmm1
1106         movdqu  -21(%rdi), %xmm2
1107         mov     $-21, %dl
1108         pxor    %xmm1, %xmm2
1109         ptest   %xmm2, %xmm0
1110         jnc     L(less16bytes)
1111         mov     -8(%rdi), %rax
1112         mov     -8(%rsi), %rcx
1113         cmp     %rax, %rcx
1114         jne     L(diffin8bytes)
1115         xor     %eax, %eax
1116         ret
1117
1118         ALIGN (4)
1119 L(70bytes):
1120         movdqu  -70(%rsi), %xmm1
1121         movdqu  -70(%rdi), %xmm2
1122         mov     $-70, %dl
1123         pxor    %xmm1, %xmm2
1124         ptest   %xmm2, %xmm0
1125         jnc     L(less16bytes)
1126 L(54bytes):
1127         movdqu  -54(%rsi), %xmm1
1128         movdqu  -54(%rdi), %xmm2
1129         mov     $-54, %dl
1130         pxor    %xmm1, %xmm2
1131         ptest   %xmm2, %xmm0
1132         jnc     L(less16bytes)
1133 L(38bytes):
1134         movdqu  -38(%rsi), %xmm1
1135         movdqu  -38(%rdi), %xmm2
1136         mov     $-38, %dl
1137         pxor    %xmm1, %xmm2
1138         ptest   %xmm2, %xmm0
1139         jnc     L(less16bytes)
1140 L(22bytes):
1141         movdqu  -22(%rsi), %xmm1
1142         movdqu  -22(%rdi), %xmm2
1143         mov     $-22, %dl
1144         pxor    %xmm1, %xmm2
1145         ptest   %xmm2, %xmm0
1146         jnc     L(less16bytes)
1147         mov     -8(%rdi), %rax
1148         mov     -8(%rsi), %rcx
1149         cmp     %rax, %rcx
1150         jne     L(diffin8bytes)
1151         xor     %eax, %eax
1152         ret
1153
1154         ALIGN (4)
1155 L(71bytes):
1156         movdqu  -71(%rsi), %xmm1
1157         movdqu  -71(%rdi), %xmm2
1158         mov     $-71, %dl
1159         pxor    %xmm1, %xmm2
1160         ptest   %xmm2, %xmm0
1161         jnc     L(less16bytes)
1162 L(55bytes):
1163         movdqu  -55(%rdi), %xmm2
1164         movdqu  -55(%rsi), %xmm1
1165         mov     $-55, %dl
1166         pxor    %xmm1, %xmm2
1167         ptest   %xmm2, %xmm0
1168         jnc     L(less16bytes)
1169 L(39bytes):
1170         movdqu  -39(%rdi), %xmm2
1171         movdqu  -39(%rsi), %xmm1
1172         mov     $-39, %dl
1173         pxor    %xmm1, %xmm2
1174         ptest   %xmm2, %xmm0
1175         jnc     L(less16bytes)
1176 L(23bytes):
1177         movdqu  -23(%rdi), %xmm2
1178         movdqu  -23(%rsi), %xmm1
1179         mov     $-23, %dl
1180         pxor    %xmm1, %xmm2
1181         ptest   %xmm2, %xmm0
1182         jnc     L(less16bytes)
1183         mov     -8(%rdi), %rax
1184         mov     -8(%rsi), %rcx
1185         cmp     %rax, %rcx
1186         jne     L(diffin8bytes)
1187         xor     %eax, %eax
1188         ret
1189 # endif
1190
1191         ALIGN (4)
1192 L(72bytes):
1193         movdqu  -72(%rsi), %xmm1
1194         movdqu  -72(%rdi), %xmm2
1195         mov     $-72, %dl
1196         pxor    %xmm1, %xmm2
1197         ptest   %xmm2, %xmm0
1198         jnc     L(less16bytes)
1199 L(56bytes):
1200         movdqu  -56(%rdi), %xmm2
1201         movdqu  -56(%rsi), %xmm1
1202         mov     $-56, %dl
1203         pxor    %xmm1, %xmm2
1204         ptest   %xmm2, %xmm0
1205         jnc     L(less16bytes)
1206 L(40bytes):
1207         movdqu  -40(%rdi), %xmm2
1208         movdqu  -40(%rsi), %xmm1
1209         mov     $-40, %dl
1210         pxor    %xmm1, %xmm2
1211         ptest   %xmm2, %xmm0
1212         jnc     L(less16bytes)
1213 L(24bytes):
1214         movdqu  -24(%rdi), %xmm2
1215         movdqu  -24(%rsi), %xmm1
1216         mov     $-24, %dl
1217         pxor    %xmm1, %xmm2
1218         ptest   %xmm2, %xmm0
1219         jnc     L(less16bytes)
1220
1221         mov     -8(%rsi), %rcx
1222         mov     -8(%rdi), %rax
1223         cmp     %rax, %rcx
1224         jne     L(diffin8bytes)
1225         xor     %eax, %eax
1226         ret
1227
1228 # ifndef USE_AS_WMEMCMP
1229 /* unreal cases for wmemcmp */
1230         ALIGN (4)
1231 L(73bytes):
1232         movdqu  -73(%rsi), %xmm1
1233         movdqu  -73(%rdi), %xmm2
1234         mov     $-73, %dl
1235         pxor    %xmm1, %xmm2
1236         ptest   %xmm2, %xmm0
1237         jnc     L(less16bytes)
1238 L(57bytes):
1239         movdqu  -57(%rdi), %xmm2
1240         movdqu  -57(%rsi), %xmm1
1241         mov     $-57, %dl
1242         pxor    %xmm1, %xmm2
1243         ptest   %xmm2, %xmm0
1244         jnc     L(less16bytes)
1245 L(41bytes):
1246         movdqu  -41(%rdi), %xmm2
1247         movdqu  -41(%rsi), %xmm1
1248         mov     $-41, %dl
1249         pxor    %xmm1, %xmm2
1250         ptest   %xmm2, %xmm0
1251         jnc     L(less16bytes)
1252 L(25bytes):
1253         movdqu  -25(%rdi), %xmm2
1254         movdqu  -25(%rsi), %xmm1
1255         mov     $-25, %dl
1256         pxor    %xmm1, %xmm2
1257         ptest   %xmm2, %xmm0
1258         jnc     L(less16bytes)
1259         mov     -9(%rdi), %rax
1260         mov     -9(%rsi), %rcx
1261         cmp     %rax, %rcx
1262         jne     L(diffin8bytes)
1263         movzbl  -1(%rdi), %eax
1264         movzbl  -1(%rsi), %ecx
1265         sub     %ecx, %eax
1266         ret
1267
1268         ALIGN (4)
1269 L(74bytes):
1270         movdqu  -74(%rsi), %xmm1
1271         movdqu  -74(%rdi), %xmm2
1272         mov     $-74, %dl
1273         pxor    %xmm1, %xmm2
1274         ptest   %xmm2, %xmm0
1275         jnc     L(less16bytes)
1276 L(58bytes):
1277         movdqu  -58(%rdi), %xmm2
1278         movdqu  -58(%rsi), %xmm1
1279         mov     $-58, %dl
1280         pxor    %xmm1, %xmm2
1281         ptest   %xmm2, %xmm0
1282         jnc     L(less16bytes)
1283 L(42bytes):
1284         movdqu  -42(%rdi), %xmm2
1285         movdqu  -42(%rsi), %xmm1
1286         mov     $-42, %dl
1287         pxor    %xmm1, %xmm2
1288         ptest   %xmm2, %xmm0
1289         jnc     L(less16bytes)
1290 L(26bytes):
1291         movdqu  -26(%rdi), %xmm2
1292         movdqu  -26(%rsi), %xmm1
1293         mov     $-26, %dl
1294         pxor    %xmm1, %xmm2
1295         ptest   %xmm2, %xmm0
1296         jnc     L(less16bytes)
1297         mov     -10(%rdi), %rax
1298         mov     -10(%rsi), %rcx
1299         cmp     %rax, %rcx
1300         jne     L(diffin8bytes)
1301         movzwl  -2(%rdi), %eax
1302         movzwl  -2(%rsi), %ecx
1303         jmp     L(diffin2bytes)
1304
1305         ALIGN (4)
1306 L(75bytes):
1307         movdqu  -75(%rsi), %xmm1
1308         movdqu  -75(%rdi), %xmm2
1309         mov     $-75, %dl
1310         pxor    %xmm1, %xmm2
1311         ptest   %xmm2, %xmm0
1312         jnc     L(less16bytes)
1313 L(59bytes):
1314         movdqu  -59(%rdi), %xmm2
1315         movdqu  -59(%rsi), %xmm1
1316         mov     $-59, %dl
1317         pxor    %xmm1, %xmm2
1318         ptest   %xmm2, %xmm0
1319         jnc     L(less16bytes)
1320 L(43bytes):
1321         movdqu  -43(%rdi), %xmm2
1322         movdqu  -43(%rsi), %xmm1
1323         mov     $-43, %dl
1324         pxor    %xmm1, %xmm2
1325         ptest   %xmm2, %xmm0
1326         jnc     L(less16bytes)
1327 L(27bytes):
1328         movdqu  -27(%rdi), %xmm2
1329         movdqu  -27(%rsi), %xmm1
1330         mov     $-27, %dl
1331         pxor    %xmm1, %xmm2
1332         ptest   %xmm2, %xmm0
1333         jnc     L(less16bytes)
1334         mov     -11(%rdi), %rax
1335         mov     -11(%rsi), %rcx
1336         cmp     %rax, %rcx
1337         jne     L(diffin8bytes)
1338         mov     -4(%rdi), %eax
1339         mov     -4(%rsi), %ecx
1340         cmp     %eax, %ecx
1341         jne     L(diffin4bytes)
1342         xor     %eax, %eax
1343         ret
1344 # endif
1345         ALIGN (4)
1346 L(76bytes):
1347         movdqu  -76(%rsi), %xmm1
1348         movdqu  -76(%rdi), %xmm2
1349         mov     $-76, %dl
1350         pxor    %xmm1, %xmm2
1351         ptest   %xmm2, %xmm0
1352         jnc     L(less16bytes)
1353 L(60bytes):
1354         movdqu  -60(%rdi), %xmm2
1355         movdqu  -60(%rsi), %xmm1
1356         mov     $-60, %dl
1357         pxor    %xmm1, %xmm2
1358         ptest   %xmm2, %xmm0
1359         jnc     L(less16bytes)
1360 L(44bytes):
1361         movdqu  -44(%rdi), %xmm2
1362         movdqu  -44(%rsi), %xmm1
1363         mov     $-44, %dl
1364         pxor    %xmm1, %xmm2
1365         ptest   %xmm2, %xmm0
1366         jnc     L(less16bytes)
1367 L(28bytes):
1368         movdqu  -28(%rdi), %xmm2
1369         movdqu  -28(%rsi), %xmm1
1370         mov     $-28, %dl
1371         pxor    %xmm1, %xmm2
1372         ptest   %xmm2, %xmm0
1373         jnc     L(less16bytes)
1374         mov     -12(%rdi), %rax
1375         mov     -12(%rsi), %rcx
1376         cmp     %rax, %rcx
1377         jne     L(diffin8bytes)
1378         mov     -4(%rsi), %ecx
1379 # ifndef USE_AS_WMEMCMP
1380         mov     -4(%rdi), %eax
1381         cmp     %eax, %ecx
1382 # else
1383         cmp     -4(%rdi), %ecx
1384 # endif
1385         jne     L(diffin4bytes)
1386         xor     %eax, %eax
1387         ret
1388
1389 # ifndef USE_AS_WMEMCMP
1390 /* unreal cases for wmemcmp */
1391         ALIGN (4)
1392 L(77bytes):
1393         movdqu  -77(%rsi), %xmm1
1394         movdqu  -77(%rdi), %xmm2
1395         mov     $-77, %dl
1396         pxor    %xmm1, %xmm2
1397         ptest   %xmm2, %xmm0
1398         jnc     L(less16bytes)
1399 L(61bytes):
1400         movdqu  -61(%rdi), %xmm2
1401         movdqu  -61(%rsi), %xmm1
1402         mov     $-61, %dl
1403         pxor    %xmm1, %xmm2
1404         ptest   %xmm2, %xmm0
1405         jnc     L(less16bytes)
1406 L(45bytes):
1407         movdqu  -45(%rdi), %xmm2
1408         movdqu  -45(%rsi), %xmm1
1409         mov     $-45, %dl
1410         pxor    %xmm1, %xmm2
1411         ptest   %xmm2, %xmm0
1412         jnc     L(less16bytes)
1413 L(29bytes):
1414         movdqu  -29(%rdi), %xmm2
1415         movdqu  -29(%rsi), %xmm1
1416         mov     $-29, %dl
1417         pxor    %xmm1, %xmm2
1418         ptest   %xmm2, %xmm0
1419         jnc     L(less16bytes)
1420
1421         mov     -13(%rdi), %rax
1422         mov     -13(%rsi), %rcx
1423         cmp     %rax, %rcx
1424         jne     L(diffin8bytes)
1425
1426         mov     -8(%rdi), %rax
1427         mov     -8(%rsi), %rcx
1428         cmp     %rax, %rcx
1429         jne     L(diffin8bytes)
1430         xor     %eax, %eax
1431         ret
1432
1433         ALIGN (4)
1434 L(78bytes):
1435         movdqu  -78(%rsi), %xmm1
1436         movdqu  -78(%rdi), %xmm2
1437         mov     $-78, %dl
1438         pxor    %xmm1, %xmm2
1439         ptest   %xmm2, %xmm0
1440         jnc     L(less16bytes)
1441 L(62bytes):
1442         movdqu  -62(%rdi), %xmm2
1443         movdqu  -62(%rsi), %xmm1
1444         mov     $-62, %dl
1445         pxor    %xmm1, %xmm2
1446         ptest   %xmm2, %xmm0
1447         jnc     L(less16bytes)
1448 L(46bytes):
1449         movdqu  -46(%rdi), %xmm2
1450         movdqu  -46(%rsi), %xmm1
1451         mov     $-46, %dl
1452         pxor    %xmm1, %xmm2
1453         ptest   %xmm2, %xmm0
1454         jnc     L(less16bytes)
1455 L(30bytes):
1456         movdqu  -30(%rdi), %xmm2
1457         movdqu  -30(%rsi), %xmm1
1458         mov     $-30, %dl
1459         pxor    %xmm1, %xmm2
1460         ptest   %xmm2, %xmm0
1461         jnc     L(less16bytes)
1462         mov     -14(%rdi), %rax
1463         mov     -14(%rsi), %rcx
1464         cmp     %rax, %rcx
1465         jne     L(diffin8bytes)
1466         mov     -8(%rdi), %rax
1467         mov     -8(%rsi), %rcx
1468         cmp     %rax, %rcx
1469         jne     L(diffin8bytes)
1470         xor     %eax, %eax
1471         ret
1472
1473         ALIGN (4)
1474 L(79bytes):
1475         movdqu  -79(%rsi), %xmm1
1476         movdqu  -79(%rdi), %xmm2
1477         mov     $-79, %dl
1478         pxor    %xmm1, %xmm2
1479         ptest   %xmm2, %xmm0
1480         jnc     L(less16bytes)
1481 L(63bytes):
1482         movdqu  -63(%rdi), %xmm2
1483         movdqu  -63(%rsi), %xmm1
1484         mov     $-63, %dl
1485         pxor    %xmm1, %xmm2
1486         ptest   %xmm2, %xmm0
1487         jnc     L(less16bytes)
1488 L(47bytes):
1489         movdqu  -47(%rdi), %xmm2
1490         movdqu  -47(%rsi), %xmm1
1491         mov     $-47, %dl
1492         pxor    %xmm1, %xmm2
1493         ptest   %xmm2, %xmm0
1494         jnc     L(less16bytes)
1495 L(31bytes):
1496         movdqu  -31(%rdi), %xmm2
1497         movdqu  -31(%rsi), %xmm1
1498         mov     $-31, %dl
1499         pxor    %xmm1, %xmm2
1500         ptest   %xmm2, %xmm0
1501         jnc     L(less16bytes)
1502         mov     -15(%rdi), %rax
1503         mov     -15(%rsi), %rcx
1504         cmp     %rax, %rcx
1505         jne     L(diffin8bytes)
1506         mov     -8(%rdi), %rax
1507         mov     -8(%rsi), %rcx
1508         cmp     %rax, %rcx
1509         jne     L(diffin8bytes)
1510         xor     %eax, %eax
1511         ret
1512 # endif
1513         ALIGN (4)
1514 L(64bytes):
1515         movdqu  -64(%rdi), %xmm2
1516         movdqu  -64(%rsi), %xmm1
1517         mov     $-64, %dl
1518         pxor    %xmm1, %xmm2
1519         ptest   %xmm2, %xmm0
1520         jnc     L(less16bytes)
1521 L(48bytes):
1522         movdqu  -48(%rdi), %xmm2
1523         movdqu  -48(%rsi), %xmm1
1524         mov     $-48, %dl
1525         pxor    %xmm1, %xmm2
1526         ptest   %xmm2, %xmm0
1527         jnc     L(less16bytes)
1528 L(32bytes):
1529         movdqu  -32(%rdi), %xmm2
1530         movdqu  -32(%rsi), %xmm1
1531         mov     $-32, %dl
1532         pxor    %xmm1, %xmm2
1533         ptest   %xmm2, %xmm0
1534         jnc     L(less16bytes)
1535
1536         mov     -16(%rdi), %rax
1537         mov     -16(%rsi), %rcx
1538         cmp     %rax, %rcx
1539         jne     L(diffin8bytes)
1540
1541         mov     -8(%rdi), %rax
1542         mov     -8(%rsi), %rcx
1543         cmp     %rax, %rcx
1544         jne     L(diffin8bytes)
1545         xor     %eax, %eax
1546         ret
1547
1548 /*
1549  * Aligned 8 bytes to avoid 2 branch "taken" in one 16 alinged code block.
1550  */
1551         ALIGN (3)
1552 L(less16bytes):
1553         movsbq  %dl, %rdx
1554         mov     (%rsi, %rdx), %rcx
1555         mov     (%rdi, %rdx), %rax
1556         cmp     %rax, %rcx
1557         jne     L(diffin8bytes)
1558         mov     8(%rsi, %rdx), %rcx
1559         mov     8(%rdi, %rdx), %rax
1560 L(diffin8bytes):
1561         cmp     %eax, %ecx
1562         jne     L(diffin4bytes)
1563         shr     $32, %rcx
1564         shr     $32, %rax
1565
1566 # ifdef USE_AS_WMEMCMP
1567 /* for wmemcmp */
1568         cmp     %eax, %ecx
1569         jne     L(diffin4bytes)
1570         xor     %eax, %eax
1571         ret
1572 # endif
1573
1574 L(diffin4bytes):
1575 # ifndef USE_AS_WMEMCMP
1576         cmp     %cx, %ax
1577         jne     L(diffin2bytes)
1578         shr     $16, %ecx
1579         shr     $16, %eax
1580 L(diffin2bytes):
1581         cmp     %cl, %al
1582         jne     L(end)
1583         and     $0xffff, %eax
1584         and     $0xffff, %ecx
1585         sub     %ecx, %eax
1586         ret
1587
1588         ALIGN (4)
1589 L(end):
1590         and     $0xff, %eax
1591         and     $0xff, %ecx
1592         sub     %ecx, %eax
1593         ret
1594 # else
1595
1596 /* for wmemcmp */
1597         mov     $1, %eax
1598         jl      L(nequal_bigger)
1599         neg     %eax
1600         ret
1601
1602         ALIGN (4)
1603 L(nequal_bigger):
1604         ret
1605
1606 L(unreal_case):
1607         xor     %eax, %eax
1608         ret
1609 # endif
1610
1611 END (MEMCMP)
1612
1613         .section .rodata.sse4.1,"a",@progbits
1614         ALIGN (3)
1615 # ifndef USE_AS_WMEMCMP
1616 L(table_64bytes):
1617         .int    JMPTBL (L(0bytes), L(table_64bytes))
1618         .int    JMPTBL (L(1bytes), L(table_64bytes))
1619         .int    JMPTBL (L(2bytes), L(table_64bytes))
1620         .int    JMPTBL (L(3bytes), L(table_64bytes))
1621         .int    JMPTBL (L(4bytes), L(table_64bytes))
1622         .int    JMPTBL (L(5bytes), L(table_64bytes))
1623         .int    JMPTBL (L(6bytes), L(table_64bytes))
1624         .int    JMPTBL (L(7bytes), L(table_64bytes))
1625         .int    JMPTBL (L(8bytes), L(table_64bytes))
1626         .int    JMPTBL (L(9bytes), L(table_64bytes))
1627         .int    JMPTBL (L(10bytes), L(table_64bytes))
1628         .int    JMPTBL (L(11bytes), L(table_64bytes))
1629         .int    JMPTBL (L(12bytes), L(table_64bytes))
1630         .int    JMPTBL (L(13bytes), L(table_64bytes))
1631         .int    JMPTBL (L(14bytes), L(table_64bytes))
1632         .int    JMPTBL (L(15bytes), L(table_64bytes))
1633         .int    JMPTBL (L(16bytes), L(table_64bytes))
1634         .int    JMPTBL (L(17bytes), L(table_64bytes))
1635         .int    JMPTBL (L(18bytes), L(table_64bytes))
1636         .int    JMPTBL (L(19bytes), L(table_64bytes))
1637         .int    JMPTBL (L(20bytes), L(table_64bytes))
1638         .int    JMPTBL (L(21bytes), L(table_64bytes))
1639         .int    JMPTBL (L(22bytes), L(table_64bytes))
1640         .int    JMPTBL (L(23bytes), L(table_64bytes))
1641         .int    JMPTBL (L(24bytes), L(table_64bytes))
1642         .int    JMPTBL (L(25bytes), L(table_64bytes))
1643         .int    JMPTBL (L(26bytes), L(table_64bytes))
1644         .int    JMPTBL (L(27bytes), L(table_64bytes))
1645         .int    JMPTBL (L(28bytes), L(table_64bytes))
1646         .int    JMPTBL (L(29bytes), L(table_64bytes))
1647         .int    JMPTBL (L(30bytes), L(table_64bytes))
1648         .int    JMPTBL (L(31bytes), L(table_64bytes))
1649         .int    JMPTBL (L(32bytes), L(table_64bytes))
1650         .int    JMPTBL (L(33bytes), L(table_64bytes))
1651         .int    JMPTBL (L(34bytes), L(table_64bytes))
1652         .int    JMPTBL (L(35bytes), L(table_64bytes))
1653         .int    JMPTBL (L(36bytes), L(table_64bytes))
1654         .int    JMPTBL (L(37bytes), L(table_64bytes))
1655         .int    JMPTBL (L(38bytes), L(table_64bytes))
1656         .int    JMPTBL (L(39bytes), L(table_64bytes))
1657         .int    JMPTBL (L(40bytes), L(table_64bytes))
1658         .int    JMPTBL (L(41bytes), L(table_64bytes))
1659         .int    JMPTBL (L(42bytes), L(table_64bytes))
1660         .int    JMPTBL (L(43bytes), L(table_64bytes))
1661         .int    JMPTBL (L(44bytes), L(table_64bytes))
1662         .int    JMPTBL (L(45bytes), L(table_64bytes))
1663         .int    JMPTBL (L(46bytes), L(table_64bytes))
1664         .int    JMPTBL (L(47bytes), L(table_64bytes))
1665         .int    JMPTBL (L(48bytes), L(table_64bytes))
1666         .int    JMPTBL (L(49bytes), L(table_64bytes))
1667         .int    JMPTBL (L(50bytes), L(table_64bytes))
1668         .int    JMPTBL (L(51bytes), L(table_64bytes))
1669         .int    JMPTBL (L(52bytes), L(table_64bytes))
1670         .int    JMPTBL (L(53bytes), L(table_64bytes))
1671         .int    JMPTBL (L(54bytes), L(table_64bytes))
1672         .int    JMPTBL (L(55bytes), L(table_64bytes))
1673         .int    JMPTBL (L(56bytes), L(table_64bytes))
1674         .int    JMPTBL (L(57bytes), L(table_64bytes))
1675         .int    JMPTBL (L(58bytes), L(table_64bytes))
1676         .int    JMPTBL (L(59bytes), L(table_64bytes))
1677         .int    JMPTBL (L(60bytes), L(table_64bytes))
1678         .int    JMPTBL (L(61bytes), L(table_64bytes))
1679         .int    JMPTBL (L(62bytes), L(table_64bytes))
1680         .int    JMPTBL (L(63bytes), L(table_64bytes))
1681         .int    JMPTBL (L(64bytes), L(table_64bytes))
1682         .int    JMPTBL (L(65bytes), L(table_64bytes))
1683         .int    JMPTBL (L(66bytes), L(table_64bytes))
1684         .int    JMPTBL (L(67bytes), L(table_64bytes))
1685         .int    JMPTBL (L(68bytes), L(table_64bytes))
1686         .int    JMPTBL (L(69bytes), L(table_64bytes))
1687         .int    JMPTBL (L(70bytes), L(table_64bytes))
1688         .int    JMPTBL (L(71bytes), L(table_64bytes))
1689         .int    JMPTBL (L(72bytes), L(table_64bytes))
1690         .int    JMPTBL (L(73bytes), L(table_64bytes))
1691         .int    JMPTBL (L(74bytes), L(table_64bytes))
1692         .int    JMPTBL (L(75bytes), L(table_64bytes))
1693         .int    JMPTBL (L(76bytes), L(table_64bytes))
1694         .int    JMPTBL (L(77bytes), L(table_64bytes))
1695         .int    JMPTBL (L(78bytes), L(table_64bytes))
1696         .int    JMPTBL (L(79bytes), L(table_64bytes))
1697 # else
1698 L(table_64bytes):
1699         .int    JMPTBL (L(0bytes), L(table_64bytes))
1700         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1701         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1702         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1703         .int    JMPTBL (L(4bytes), L(table_64bytes))
1704         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1705         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1706         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1707         .int    JMPTBL (L(8bytes), L(table_64bytes))
1708         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1709         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1710         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1711         .int    JMPTBL (L(12bytes), L(table_64bytes))
1712         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1713         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1714         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1715         .int    JMPTBL (L(16bytes), L(table_64bytes))
1716         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1717         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1718         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1719         .int    JMPTBL (L(20bytes), L(table_64bytes))
1720         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1721         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1722         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1723         .int    JMPTBL (L(24bytes), L(table_64bytes))
1724         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1725         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1726         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1727         .int    JMPTBL (L(28bytes), L(table_64bytes))
1728         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1729         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1730         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1731         .int    JMPTBL (L(32bytes), L(table_64bytes))
1732         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1733         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1734         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1735         .int    JMPTBL (L(36bytes), L(table_64bytes))
1736         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1737         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1738         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1739         .int    JMPTBL (L(40bytes), L(table_64bytes))
1740         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1741         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1742         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1743         .int    JMPTBL (L(44bytes), L(table_64bytes))
1744         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1745         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1746         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1747         .int    JMPTBL (L(48bytes), L(table_64bytes))
1748         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1749         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1750         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1751         .int    JMPTBL (L(52bytes), L(table_64bytes))
1752         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1753         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1754         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1755         .int    JMPTBL (L(56bytes), L(table_64bytes))
1756         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1757         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1758         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1759         .int    JMPTBL (L(60bytes), L(table_64bytes))
1760         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1761         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1762         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1763         .int    JMPTBL (L(64bytes), L(table_64bytes))
1764         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1765         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1766         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1767         .int    JMPTBL (L(68bytes), L(table_64bytes))
1768         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1769         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1770         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1771         .int    JMPTBL (L(72bytes), L(table_64bytes))
1772         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1773         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1774         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1775         .int    JMPTBL (L(76bytes), L(table_64bytes))
1776         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1777         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1778         .int    JMPTBL (L(unreal_case), L(table_64bytes))
1779 # endif
1780 #endif