Blame sysdeps/i386/i586/memcpy.S

Packit 6c4009
/* Highly optimized version for i586.
Packit 6c4009
   Copyright (C) 1997-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
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+8	/* space for 2 saved regs */
Packit 6c4009
#define RTN	PARMS
Packit 6c4009
#define DEST	RTN
Packit 6c4009
#define SRC	DEST+4
Packit 6c4009
#define LEN	SRC+4
Packit 6c4009
Packit 6c4009
        .text
Packit 6c4009
#if defined PIC && IS_IN (libc)
Packit 6c4009
ENTRY (__memcpy_chk)
Packit 6c4009
	movl	12(%esp), %eax
Packit 6c4009
	cmpl	%eax, 16(%esp)
Packit 6c4009
	jb	HIDDEN_JUMPTARGET (__chk_fail)
Packit 6c4009
END (__memcpy_chk)
Packit 6c4009
#endif
Packit 6c4009
ENTRY (memcpy)
Packit 6c4009
Packit 6c4009
	pushl	%edi
Packit 6c4009
	cfi_adjust_cfa_offset (4)
Packit 6c4009
	pushl	%esi
Packit 6c4009
	cfi_adjust_cfa_offset (4)
Packit 6c4009
Packit 6c4009
	movl	DEST(%esp), %edi
Packit 6c4009
	cfi_rel_offset (edi, 4)
Packit 6c4009
	movl	SRC(%esp), %esi
Packit 6c4009
	cfi_rel_offset (esi, 0)
Packit 6c4009
	movl	LEN(%esp), %ecx
Packit 6c4009
	movl	%edi, %eax
Packit 6c4009
Packit 6c4009
	/* We need this in any case.  */
Packit 6c4009
	cld
Packit 6c4009
Packit 6c4009
	/* Cutoff for the big loop is a size of 32 bytes since otherwise
Packit 6c4009
	   the loop will never be entered.  */
Packit 6c4009
	cmpl	$32, %ecx
Packit 6c4009
	jbe	L(1)
Packit 6c4009
Packit 6c4009
	negl	%eax
Packit 6c4009
	andl	$3, %eax
Packit 6c4009
	subl	%eax, %ecx
Packit 6c4009
	xchgl	%eax, %ecx
Packit 6c4009
Packit 6c4009
	rep; movsb
Packit 6c4009
Packit 6c4009
	movl	%eax, %ecx
Packit 6c4009
	subl	$32, %ecx
Packit 6c4009
	js	L(2)
Packit 6c4009
Packit 6c4009
	/* Read ahead to make sure we write in the cache since the stupid
Packit 6c4009
	   i586 designers haven't implemented read-on-write-miss.  */
Packit 6c4009
	movl	(%edi), %eax
Packit 6c4009
L(3):	movl	28(%edi), %edx
Packit 6c4009
Packit 6c4009
	/* Now correct the loop counter.  Please note that in the following
Packit 6c4009
	   code the flags are not changed anymore.  */
Packit 6c4009
	subl	$32, %ecx
Packit 6c4009
Packit 6c4009
	movl	(%esi), %eax
Packit 6c4009
	movl	4(%esi), %edx
Packit 6c4009
	movl	%eax, (%edi)
Packit 6c4009
	movl	%edx, 4(%edi)
Packit 6c4009
	movl	8(%esi), %eax
Packit 6c4009
	movl	12(%esi), %edx
Packit 6c4009
	movl	%eax, 8(%edi)
Packit 6c4009
	movl	%edx, 12(%edi)
Packit 6c4009
	movl	16(%esi), %eax
Packit 6c4009
	movl	20(%esi), %edx
Packit 6c4009
	movl	%eax, 16(%edi)
Packit 6c4009
	movl	%edx, 20(%edi)
Packit 6c4009
	movl	24(%esi), %eax
Packit 6c4009
	movl	28(%esi), %edx
Packit 6c4009
	movl	%eax, 24(%edi)
Packit 6c4009
	movl	%edx, 28(%edi)
Packit 6c4009
Packit 6c4009
	leal	32(%esi), %esi
Packit 6c4009
	leal	32(%edi), %edi
Packit 6c4009
Packit 6c4009
	jns	L(3)
Packit 6c4009
Packit 6c4009
	/* Correct extra loop counter modification.  */
Packit 6c4009
L(2):	addl	$32, %ecx
Packit 6c4009
#ifndef USE_AS_MEMPCPY
Packit 6c4009
	movl	DEST(%esp), %eax
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
L(1):	rep; movsb
Packit 6c4009
Packit 6c4009
#ifdef USE_AS_MEMPCPY
Packit 6c4009
	movl	%edi, %eax
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
	popl	%esi
Packit 6c4009
	cfi_adjust_cfa_offset (-4)
Packit 6c4009
	cfi_restore (esi)
Packit 6c4009
	popl	%edi
Packit 6c4009
	cfi_adjust_cfa_offset (-4)
Packit 6c4009
	cfi_restore (edi)
Packit 6c4009
Packit 6c4009
	ret
Packit 6c4009
END (memcpy)
Packit 6c4009
#ifndef USE_AS_MEMPCPY
Packit 6c4009
libc_hidden_builtin_def (memcpy)
Packit 6c4009
#endif