Blame sysdeps/i386/i586/lshift.S

Packit 6c4009
/* Pentium optimized __mpn_lshift --
Packit 6c4009
   Copyright (C) 1992-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+16		/* space for 4 saved regs */
Packit 6c4009
#define RES	PARMS
Packit 6c4009
#define S	RES+4
Packit 6c4009
#define SIZE	S+4
Packit 6c4009
#define CNT	SIZE+4
Packit 6c4009
Packit 6c4009
	.text
Packit 6c4009
ENTRY (__mpn_lshift)
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
	pushl	%ebp
Packit 6c4009
	cfi_adjust_cfa_offset (4)
Packit 6c4009
	cfi_rel_offset (ebp, 0)
Packit 6c4009
	pushl	%ebx
Packit 6c4009
	cfi_adjust_cfa_offset (4)
Packit 6c4009
Packit 6c4009
	movl	RES(%esp),%edi
Packit 6c4009
	cfi_rel_offset (edi, 12)
Packit 6c4009
	movl	S(%esp),%esi
Packit 6c4009
	cfi_rel_offset (esi, 8)
Packit 6c4009
	movl	SIZE(%esp),%ebx
Packit 6c4009
	cfi_rel_offset (ebx, 0)
Packit 6c4009
	movl	CNT(%esp),%ecx
Packit 6c4009
Packit 6c4009
/* We can use faster code for shift-by-1 under certain conditions.  */
Packit 6c4009
	cmp	$1,%ecx
Packit 6c4009
	jne	L(normal)
Packit 6c4009
	leal	4(%esi),%eax
Packit 6c4009
	cmpl	%edi,%eax
Packit 6c4009
	jnc	L(special)		/* jump if s_ptr + 1 >= res_ptr */
Packit 6c4009
	leal	(%esi,%ebx,4),%eax
Packit 6c4009
	cmpl	%eax,%edi
Packit 6c4009
	jnc	L(special)		/* jump if res_ptr >= s_ptr + size */
Packit 6c4009
Packit 6c4009
L(normal):
Packit 6c4009
	leal	-4(%edi,%ebx,4),%edi
Packit 6c4009
	leal	-4(%esi,%ebx,4),%esi
Packit 6c4009
Packit 6c4009
	movl	(%esi),%edx
Packit 6c4009
	subl	$4,%esi
Packit 6c4009
	xorl	%eax,%eax
Packit 6c4009
	shldl	%cl,%edx,%eax		/* compute carry limb */
Packit 6c4009
	pushl	%eax			/* push carry limb onto stack */
Packit 6c4009
	cfi_adjust_cfa_offset (4)
Packit 6c4009
Packit 6c4009
	decl	%ebx
Packit 6c4009
	pushl	%ebx
Packit 6c4009
	cfi_adjust_cfa_offset (4)
Packit 6c4009
	shrl	$3,%ebx
Packit 6c4009
	jz	L(end)
Packit 6c4009
Packit 6c4009
	movl	(%edi),%eax		/* fetch destination cache line */
Packit 6c4009
Packit 6c4009
	ALIGN	(2)
Packit 6c4009
L(oop):	movl	-28(%edi),%eax		/* fetch destination cache line */
Packit 6c4009
	movl	%edx,%ebp
Packit 6c4009
Packit 6c4009
	movl	(%esi),%eax
Packit 6c4009
	movl	-4(%esi),%edx
Packit 6c4009
	shldl	%cl,%eax,%ebp
Packit 6c4009
	shldl	%cl,%edx,%eax
Packit 6c4009
	movl	%ebp,(%edi)
Packit 6c4009
	movl	%eax,-4(%edi)
Packit 6c4009
Packit 6c4009
	movl	-8(%esi),%ebp
Packit 6c4009
	movl	-12(%esi),%eax
Packit 6c4009
	shldl	%cl,%ebp,%edx
Packit 6c4009
	shldl	%cl,%eax,%ebp
Packit 6c4009
	movl	%edx,-8(%edi)
Packit 6c4009
	movl	%ebp,-12(%edi)
Packit 6c4009
Packit 6c4009
	movl	-16(%esi),%edx
Packit 6c4009
	movl	-20(%esi),%ebp
Packit 6c4009
	shldl	%cl,%edx,%eax
Packit 6c4009
	shldl	%cl,%ebp,%edx
Packit 6c4009
	movl	%eax,-16(%edi)
Packit 6c4009
	movl	%edx,-20(%edi)
Packit 6c4009
Packit 6c4009
	movl	-24(%esi),%eax
Packit 6c4009
	movl	-28(%esi),%edx
Packit 6c4009
	shldl	%cl,%eax,%ebp
Packit 6c4009
	shldl	%cl,%edx,%eax
Packit 6c4009
	movl	%ebp,-24(%edi)
Packit 6c4009
	movl	%eax,-28(%edi)
Packit 6c4009
Packit 6c4009
	subl	$32,%esi
Packit 6c4009
	subl	$32,%edi
Packit 6c4009
	decl	%ebx
Packit 6c4009
	jnz	L(oop)
Packit 6c4009
Packit 6c4009
L(end):	popl	%ebx
Packit 6c4009
	cfi_adjust_cfa_offset (-4)
Packit 6c4009
	andl	$7,%ebx
Packit 6c4009
	jz	L(end2)
Packit 6c4009
L(oop2):
Packit 6c4009
	movl	(%esi),%eax
Packit 6c4009
	shldl	%cl,%eax,%edx
Packit 6c4009
	movl	%edx,(%edi)
Packit 6c4009
	movl	%eax,%edx
Packit 6c4009
	subl	$4,%esi
Packit 6c4009
	subl	$4,%edi
Packit 6c4009
	decl	%ebx
Packit 6c4009
	jnz	L(oop2)
Packit 6c4009
Packit 6c4009
L(end2):
Packit 6c4009
	shll	%cl,%edx		/* compute least significant limb */
Packit 6c4009
	movl	%edx,(%edi)		/* store it */
Packit 6c4009
Packit 6c4009
	popl	%eax			/* pop carry limb */
Packit 6c4009
	cfi_adjust_cfa_offset (-4)
Packit 6c4009
Packit 6c4009
	popl	%ebx
Packit 6c4009
	cfi_adjust_cfa_offset (-4)
Packit 6c4009
	cfi_restore (ebx)
Packit 6c4009
	popl	%ebp
Packit 6c4009
	cfi_adjust_cfa_offset (-4)
Packit 6c4009
	cfi_restore (ebp)
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
Packit 6c4009
/* We loop from least significant end of the arrays, which is only
Packit 6c4009
   permissible if the source and destination don't overlap, since the
Packit 6c4009
   function is documented to work for overlapping source and destination.
Packit 6c4009
*/
Packit 6c4009
Packit 6c4009
	cfi_adjust_cfa_offset (16)
Packit 6c4009
	cfi_rel_offset (edi, 12)
Packit 6c4009
	cfi_rel_offset (esi, 8)
Packit 6c4009
	cfi_rel_offset (ebp, 4)
Packit 6c4009
	cfi_rel_offset (ebx, 0)
Packit 6c4009
L(special):
Packit 6c4009
	movl	(%esi),%edx
Packit 6c4009
	addl	$4,%esi
Packit 6c4009
Packit 6c4009
	decl	%ebx
Packit 6c4009
	pushl	%ebx
Packit 6c4009
	cfi_adjust_cfa_offset (4)
Packit 6c4009
	shrl	$3,%ebx
Packit 6c4009
Packit 6c4009
	addl	%edx,%edx
Packit 6c4009
	incl	%ebx
Packit 6c4009
	decl	%ebx
Packit 6c4009
	jz	L(Lend)
Packit 6c4009
Packit 6c4009
	movl	(%edi),%eax		/* fetch destination cache line */
Packit 6c4009
Packit 6c4009
	ALIGN	(2)
Packit 6c4009
L(Loop):
Packit 6c4009
	movl	28(%edi),%eax		/* fetch destination cache line */
Packit 6c4009
	movl	%edx,%ebp
Packit 6c4009
Packit 6c4009
	movl	(%esi),%eax
Packit 6c4009
	movl	4(%esi),%edx
Packit 6c4009
	adcl	%eax,%eax
Packit 6c4009
	movl	%ebp,(%edi)
Packit 6c4009
	adcl	%edx,%edx
Packit 6c4009
	movl	%eax,4(%edi)
Packit 6c4009
Packit 6c4009
	movl	8(%esi),%ebp
Packit 6c4009
	movl	12(%esi),%eax
Packit 6c4009
	adcl	%ebp,%ebp
Packit 6c4009
	movl	%edx,8(%edi)
Packit 6c4009
	adcl	%eax,%eax
Packit 6c4009
	movl	%ebp,12(%edi)
Packit 6c4009
Packit 6c4009
	movl	16(%esi),%edx
Packit 6c4009
	movl	20(%esi),%ebp
Packit 6c4009
	adcl	%edx,%edx
Packit 6c4009
	movl	%eax,16(%edi)
Packit 6c4009
	adcl	%ebp,%ebp
Packit 6c4009
	movl	%edx,20(%edi)
Packit 6c4009
Packit 6c4009
	movl	24(%esi),%eax
Packit 6c4009
	movl	28(%esi),%edx
Packit 6c4009
	adcl	%eax,%eax
Packit 6c4009
	movl	%ebp,24(%edi)
Packit 6c4009
	adcl	%edx,%edx
Packit 6c4009
	movl	%eax,28(%edi)
Packit 6c4009
Packit 6c4009
	leal	32(%esi),%esi		/* use leal not to clobber carry */
Packit 6c4009
	leal	32(%edi),%edi
Packit 6c4009
	decl	%ebx
Packit 6c4009
	jnz	L(Loop)
Packit 6c4009
Packit 6c4009
L(Lend):
Packit 6c4009
	popl	%ebx
Packit 6c4009
	cfi_adjust_cfa_offset (-4)
Packit 6c4009
	sbbl	%eax,%eax		/* save carry in %eax */
Packit 6c4009
	andl	$7,%ebx
Packit 6c4009
	jz	L(Lend2)
Packit 6c4009
	addl	%eax,%eax		/* restore carry from eax */
Packit 6c4009
L(Loop2):
Packit 6c4009
	movl	%edx,%ebp
Packit 6c4009
	movl	(%esi),%edx
Packit 6c4009
	adcl	%edx,%edx
Packit 6c4009
	movl	%ebp,(%edi)
Packit 6c4009
Packit 6c4009
	leal	4(%esi),%esi		/* use leal not to clobber carry */
Packit 6c4009
	leal	4(%edi),%edi
Packit 6c4009
	decl	%ebx
Packit 6c4009
	jnz	L(Loop2)
Packit 6c4009
Packit 6c4009
	jmp	L(L1)
Packit 6c4009
L(Lend2):
Packit 6c4009
	addl	%eax,%eax		/* restore carry from eax */
Packit 6c4009
L(L1):	movl	%edx,(%edi)		/* store last limb */
Packit 6c4009
Packit 6c4009
	sbbl	%eax,%eax
Packit 6c4009
	negl	%eax
Packit 6c4009
Packit 6c4009
	popl	%ebx
Packit 6c4009
	cfi_adjust_cfa_offset (-4)
Packit 6c4009
	cfi_restore (ebx)
Packit 6c4009
	popl	%ebp
Packit 6c4009
	cfi_adjust_cfa_offset (-4)
Packit 6c4009
	cfi_restore (ebp)
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 (__mpn_lshift)