]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/i386/memcmp.S
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / i386 / memcmp.S
CommitLineData
5929563f 1/* Compare two memory blocks for differences in the first COUNT bytes.
dff8da6b 2 Copyright (C) 1995-2024 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 15 You should have received a copy of the GNU Lesser General Public
59ba27a6 16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
8f5ca04b
RM
18
19#include <sysdep.h>
20#include "asm-syntax.h"
21
2366713d 22#define PARMS 4+4 /* space for 1 saved reg */
3f02f778 23#define BLK1 PARMS
2366713d
JM
24#define BLK2 BLK1+4
25#define LEN BLK2+4
8f5ca04b
RM
26
27 .text
2366713d 28ENTRY (memcmp)
3f02f778 29
8f5ca04b 30 pushl %esi /* Save callee-safe registers. */
1ad9da69 31 cfi_adjust_cfa_offset (4)
8f5ca04b
RM
32 movl %edi, %edx /* Note that %edx is not used and can
33 so be used to save %edi. It's faster. */
1ad9da69 34 cfi_register (edi, edx)
8f5ca04b 35
3f02f778 36 movl BLK1(%esp), %esi
1ad9da69 37 cfi_rel_offset (esi, 0)
3f02f778
GM
38 movl BLK2(%esp), %edi
39 movl LEN(%esp), %ecx
8f5ca04b
RM
40
41 cld /* Set direction of comparison. */
42
43 xorl %eax, %eax /* Default result. */
44
45 repe /* Compare at most %ecx bytes. */
46 cmpsb
5929563f 47 jz L(1) /* If even last byte was equal we return 0. */
8f5ca04b
RM
48
49 /* The memory blocks are not equal. So result of the last
50 subtraction is present in the carry flag. It is set when
51 the byte in block #2 is bigger. In this case we have to
52 return -1 (=0xffffffff), else 1. */
53 sbbl %eax, %eax /* This is tricky. %eax == 0 and carry is set
54 or not depending on last subtraction. */
55
56 /* At this point %eax == 0, if the byte of block #1 was bigger, and
49c091e5 57 0xffffffff if the last byte of block #2 was bigger. The latter
8f5ca04b
RM
58 case is already correct but the former needs a little adjustment.
59 Note that the following operation does not change 0xffffffff. */
60 orb $1, %al /* Change 0 to 1. */
61
92945b52 62L(1): popl %esi /* Restore registers. */
1ad9da69
UD
63 cfi_adjust_cfa_offset (-4)
64 cfi_restore (esi)
8f5ca04b 65 movl %edx, %edi
1ad9da69 66 cfi_restore (edi)
8f5ca04b
RM
67
68 ret
2366713d 69END (memcmp)
8f5ca04b
RM
70
71#undef bcmp
2366713d 72weak_alias (memcmp, bcmp)
44829b3d
NG
73#undef __memcmpeq
74strong_alias (memcmp, __memcmpeq)
2366713d 75libc_hidden_builtin_def (memcmp)
9894127d 76libc_hidden_def (__memcmpeq)