]>
Commit | Line | Data |
---|---|---|
5929563f | 1 | /* Compare two memory blocks for differences in the first COUNT bytes. |
0ecb606c | 2 | Copyright (C) 1995,1996,1997,2000,2004,2005 Free Software Foundation, Inc. |
5929563f | 3 | This file is part of the GNU C Library. |
8f5ca04b | 4 | |
5929563f | 5 | The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
8f5ca04b | 9 | |
5929563f UD |
10 | The GNU C Library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
8f5ca04b | 14 | |
41bdb6e2 AJ |
15 | You should have received a copy of the GNU Lesser General Public |
16 | License along with the GNU C Library; if not, write to the Free | |
17 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |
18 | 02111-1307 USA. */ | |
8f5ca04b RM |
19 | |
20 | #include <sysdep.h> | |
21 | #include "asm-syntax.h" | |
2fc08826 | 22 | #include "bp-sym.h" |
3f02f778 | 23 | #include "bp-asm.h" |
8f5ca04b | 24 | |
3f02f778 GM |
25 | #define PARMS LINKAGE+4 /* space for 1 saved reg */ |
26 | #define BLK1 PARMS | |
27 | #define BLK2 BLK1+PTR_SIZE | |
28 | #define LEN BLK2+PTR_SIZE | |
8f5ca04b RM |
29 | |
30 | .text | |
2fc08826 | 31 | ENTRY (BP_SYM (memcmp)) |
3f02f778 GM |
32 | ENTER |
33 | ||
8f5ca04b | 34 | pushl %esi /* Save callee-safe registers. */ |
0ecb606c | 35 | cfi_adjust_cfa_offset (4) |
8f5ca04b RM |
36 | movl %edi, %edx /* Note that %edx is not used and can |
37 | so be used to save %edi. It's faster. */ | |
0ecb606c | 38 | cfi_register (edi, edx) |
8f5ca04b | 39 | |
3f02f778 | 40 | movl BLK1(%esp), %esi |
0ecb606c | 41 | cfi_rel_offset (esi, 0) |
3f02f778 GM |
42 | movl BLK2(%esp), %edi |
43 | movl LEN(%esp), %ecx | |
53c06508 GM |
44 | CHECK_BOUNDS_LOW (%esi, BLK1(%esp)) |
45 | CHECK_BOUNDS_LOW (%edi, BLK2(%esp)) | |
8f5ca04b RM |
46 | |
47 | cld /* Set direction of comparison. */ | |
48 | ||
49 | xorl %eax, %eax /* Default result. */ | |
50 | ||
51 | repe /* Compare at most %ecx bytes. */ | |
52 | cmpsb | |
5929563f | 53 | jz L(1) /* If even last byte was equal we return 0. */ |
8f5ca04b RM |
54 | |
55 | /* The memory blocks are not equal. So result of the last | |
56 | subtraction is present in the carry flag. It is set when | |
57 | the byte in block #2 is bigger. In this case we have to | |
58 | return -1 (=0xffffffff), else 1. */ | |
59 | sbbl %eax, %eax /* This is tricky. %eax == 0 and carry is set | |
60 | or not depending on last subtraction. */ | |
61 | ||
62 | /* At this point %eax == 0, if the byte of block #1 was bigger, and | |
49c091e5 | 63 | 0xffffffff if the last byte of block #2 was bigger. The latter |
8f5ca04b RM |
64 | case is already correct but the former needs a little adjustment. |
65 | Note that the following operation does not change 0xffffffff. */ | |
66 | orb $1, %al /* Change 0 to 1. */ | |
67 | ||
53c06508 GM |
68 | L(1): CHECK_BOUNDS_HIGH (%esi, BLK1(%esp), jbe) |
69 | CHECK_BOUNDS_HIGH (%edi, BLK2(%esp), jbe) | |
70 | popl %esi /* Restore registers. */ | |
0ecb606c JJ |
71 | cfi_adjust_cfa_offset (-4) |
72 | cfi_restore (esi) | |
8f5ca04b | 73 | movl %edx, %edi |
0ecb606c | 74 | cfi_restore (edi) |
8f5ca04b | 75 | |
3f02f778 | 76 | LEAVE |
8f5ca04b | 77 | ret |
2fc08826 | 78 | END (BP_SYM (memcmp)) |
8f5ca04b RM |
79 | |
80 | #undef bcmp | |
2fc08826 | 81 | weak_alias (BP_SYM (memcmp), BP_SYM (bcmp)) |
758b2153 | 82 | libc_hidden_builtin_def (BP_SYM (memcmp)) |