]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/i386/memcmp.S
update from main archvie 961022
[thirdparty/glibc.git] / sysdeps / i386 / memcmp.S
CommitLineData
8f5ca04b
RM
1/* memcmp -- compare two memory blocks for differences in the first COUNT
2 bytes.
92777700 3Copyright (C) 1995, 1996 Free Software Foundation, Inc.
8f5ca04b
RM
4This file is part of the GNU C Library.
5
6The GNU C Library is free software; you can redistribute it and/or
7modify it under the terms of the GNU Library General Public License as
8published by the Free Software Foundation; either version 2 of the
9License, or (at your option) any later version.
10
11The GNU C Library is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14Library General Public License for more details.
15
16You should have received a copy of the GNU Library General Public
17License along with the GNU C Library; see the file COPYING.LIB. If
18not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
20
21#include <sysdep.h>
22#include "asm-syntax.h"
23
24/*
25 INPUT PARAMETERS:
26 block1 (sp + 4)
27 block2 (sp + 8)
28 len (sp + 12)
29*/
30
31 .text
32ENTRY (memcmp)
33 pushl %esi /* Save callee-safe registers. */
34 movl %edi, %edx /* Note that %edx is not used and can
35 so be used to save %edi. It's faster. */
36
92777700
RM
37 movl 8(%esp), %esi /* Load address of block #1. */
38 movl 12(%esp), %edi /* Load address of block #2. */
39 movl 16(%esp), %ecx /* Load maximal length of compare area. */
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
47 jz L1 /* If even last byte was equal we return 0. */
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
57 0xffffffff if the last byte of block #2 was bigger. The later
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
62L1: popl %esi /* Restore registers. */
63 movl %edx, %edi
64
65 ret
6ed0492f 66END (memcmp)
8f5ca04b
RM
67
68#undef bcmp
69weak_alias (memcmp, bcmp)