]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - lib/libc/amd64/string/memcmp.S
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / lib / libc / amd64 / string / memcmp.S
1 /*
2  * Written by J.T. Conklin <jtc@NetBSD.org>.
3  * Public domain.
4  * Adapted for NetBSD/x86_64 by Frank van der Linden <fvdl@wasabisystems.com>
5  */
6
7 #include <machine/asm.h>
8 __FBSDID("$FreeBSD$");
9
10 #if 0
11         RCSID("$NetBSD: memcmp.S,v 1.2 2003/07/26 19:24:39 salo Exp $")
12 #endif
13
14 ENTRY(memcmp)
15         cld                             /* set compare direction forward */
16         movq    %rdx,%rcx               /* compare by longs */
17         shrq    $3,%rcx
18         repe
19         cmpsq
20         jne     L5                      /* do we match so far? */
21
22         movq    %rdx,%rcx               /* compare remainder by bytes */
23         andq    $7,%rcx
24         repe
25         cmpsb
26         jne     L6                      /* do we match? */
27
28         xorl    %eax,%eax               /* we match, return zero        */
29         ret
30
31 L5:     movl    $8,%ecx                 /* We know that one of the next */
32         subq    %rcx,%rdi               /* eight pairs of bytes do not  */
33         subq    %rcx,%rsi               /* match.                       */
34         repe
35         cmpsb
36 L6:     xorl    %eax,%eax               /* Perform unsigned comparison  */
37         movb    -1(%rdi),%al
38         xorl    %edx,%edx
39         movb    -1(%rsi),%dl
40         subl    %edx,%eax
41         ret
42 END(memcmp)
43
44         .section .note.GNU-stack,"",%progbits