2.9
[glibc/nacl-glibc.git] / sysdeps / i386 / i686 / strcmp.S
blob8601c1ca0378af6860c524d770284ce36abd7a19
1 /* Highly optimized version for ix86, x>=6.
2    Copyright (C) 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1999.
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 #include <sysdep.h>
22 #include "asm-syntax.h"
23 #include "bp-sym.h"
24 #include "bp-asm.h"
26 #define PARMS   LINKAGE         /* no space for saved regs */
27 #define STR1    PARMS
28 #define STR2    STR1+PTR_SIZE
30         .text
31 ENTRY (BP_SYM (strcmp))
32         ENTER
34         movl    STR1(%esp), %ecx
35         movl    STR2(%esp), %edx
36         CHECK_BOUNDS_LOW (%ecx, STR1(%esp))
37         CHECK_BOUNDS_LOW (%edx, STR2(%esp))
39 L(oop): movb    (%ecx), %al
40         cmpb    (%edx), %al
41         jne     L(neq)
42         incl    %ecx
43         incl    %edx
44         testb   %al, %al
45         jnz     L(oop)
47         xorl    %eax, %eax
48         /* when strings are equal, pointers rest one beyond
49            the end of the NUL terminators.  */
50         CHECK_BOUNDS_HIGH (%ecx, STR1(%esp), jbe)
51         CHECK_BOUNDS_HIGH (%edx, STR2(%esp), jbe)
52         LEAVE
53         ret
55 #ifndef __BOUNDED_POINTERS__
56 L(neq): movl    $1, %eax
57         movl    $-1, %ecx
58         cmovbl  %ecx, %eax
59 #else
60 L(neq): movl    $1, %eax
61         ja      L(chk)
62         negl    %eax
63         /* When strings differ, pointers rest on
64            the unequal characters.  */
65 L(chk): CHECK_BOUNDS_HIGH (%ecx, STR1(%esp), jb)
66         CHECK_BOUNDS_HIGH (%edx, STR2(%esp), jb)
67 #endif
69         LEAVE
70         ret
71 END (BP_SYM (strcmp))
72 libc_hidden_builtin_def (strcmp)