Blame sysdeps/i386/memcmp.S

Packit 6c4009
/* Compare two memory blocks for differences in the first COUNT bytes.
Packit 6c4009
   Copyright (C) 1995-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <sysdep.h>
Packit 6c4009
#include "asm-syntax.h"
Packit 6c4009
Packit 6c4009
#define PARMS	4+4	/* space for 1 saved reg */
Packit 6c4009
#define BLK1	PARMS
Packit 6c4009
#define BLK2	BLK1+4
Packit 6c4009
#define LEN	BLK2+4
Packit 6c4009
Packit 6c4009
	.text
Packit 6c4009
ENTRY (memcmp)
Packit 6c4009
Packit 6c4009
	pushl %esi		/* Save callee-safe registers.  */
Packit 6c4009
	cfi_adjust_cfa_offset (4)
Packit 6c4009
	movl %edi, %edx		/* Note that %edx is not used and can
Packit 6c4009
				   so be used to save %edi.  It's faster.  */
Packit 6c4009
	cfi_register (edi, edx)
Packit 6c4009
Packit 6c4009
	movl BLK1(%esp), %esi
Packit 6c4009
	cfi_rel_offset (esi, 0)
Packit 6c4009
	movl BLK2(%esp), %edi
Packit 6c4009
	movl LEN(%esp), %ecx
Packit 6c4009
Packit 6c4009
	cld			/* Set direction of comparison.  */
Packit 6c4009
Packit 6c4009
	xorl %eax, %eax		/* Default result.  */
Packit 6c4009
Packit 6c4009
	repe			/* Compare at most %ecx bytes.  */
Packit 6c4009
	cmpsb
Packit 6c4009
	jz L(1)			/* If even last byte was equal we return 0.  */
Packit 6c4009
Packit 6c4009
	/* The memory blocks are not equal.  So result of the last
Packit 6c4009
	   subtraction is present in the carry flag.  It is set when
Packit 6c4009
	   the byte in block #2 is bigger.  In this case we have to
Packit 6c4009
	   return -1 (=0xffffffff), else 1.  */
Packit 6c4009
	sbbl %eax, %eax		/* This is tricky.  %eax == 0 and carry is set
Packit 6c4009
				   or not depending on last subtraction.  */
Packit 6c4009
Packit 6c4009
	/* At this point %eax == 0, if the byte of block #1 was bigger, and
Packit 6c4009
	   0xffffffff if the last byte of block #2 was bigger.  The latter
Packit 6c4009
	   case is already correct but the former needs a little adjustment.
Packit 6c4009
	   Note that the following operation does not change 0xffffffff.  */
Packit 6c4009
	orb $1, %al		/* Change 0 to 1.  */
Packit 6c4009
Packit 6c4009
L(1):	popl %esi		/* Restore registers.  */
Packit 6c4009
	cfi_adjust_cfa_offset (-4)
Packit 6c4009
	cfi_restore (esi)
Packit 6c4009
	movl %edx, %edi
Packit 6c4009
	cfi_restore (edi)
Packit 6c4009
Packit 6c4009
	ret
Packit 6c4009
END (memcmp)
Packit 6c4009
Packit 6c4009
#undef bcmp
Packit 6c4009
weak_alias (memcmp, bcmp)
Packit 6c4009
libc_hidden_builtin_def (memcmp)