Blame mpn/x86/k6/mmx/rshift.asm

Packit 5c3484
dnl  AMD K6 mpn_rshift -- mpn right shift.
Packit 5c3484
Packit 5c3484
dnl  Copyright 1999, 2000, 2002 Free Software Foundation, Inc.
Packit 5c3484
Packit 5c3484
dnl  This file is part of the GNU MP Library.
Packit 5c3484
dnl
Packit 5c3484
dnl  The GNU MP Library is free software; you can redistribute it and/or modify
Packit 5c3484
dnl  it under the terms of either:
Packit 5c3484
dnl
Packit 5c3484
dnl    * the GNU Lesser General Public License as published by the Free
Packit 5c3484
dnl      Software Foundation; either version 3 of the License, or (at your
Packit 5c3484
dnl      option) any later version.
Packit 5c3484
dnl
Packit 5c3484
dnl  or
Packit 5c3484
dnl
Packit 5c3484
dnl    * the GNU General Public License as published by the Free Software
Packit 5c3484
dnl      Foundation; either version 2 of the License, or (at your option) any
Packit 5c3484
dnl      later version.
Packit 5c3484
dnl
Packit 5c3484
dnl  or both in parallel, as here.
Packit 5c3484
dnl
Packit 5c3484
dnl  The GNU MP Library is distributed in the hope that it will be useful, but
Packit 5c3484
dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
Packit 5c3484
dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
Packit 5c3484
dnl  for more details.
Packit 5c3484
dnl
Packit 5c3484
dnl  You should have received copies of the GNU General Public License and the
Packit 5c3484
dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
Packit 5c3484
dnl  see https://www.gnu.org/licenses/.
Packit 5c3484
Packit 5c3484
include(`../config.m4')
Packit 5c3484
Packit 5c3484
Packit 5c3484
C K6: 3.0 cycles/limb
Packit 5c3484
Packit 5c3484
Packit 5c3484
C mp_limb_t mpn_rshift (mp_ptr dst, mp_srcptr src, mp_size_t size,
Packit 5c3484
C                       unsigned shift);
Packit 5c3484
C
Packit 5c3484
C The loop runs at 3 cycles/limb, limited by decoding and by having 3 mmx
Packit 5c3484
C instructions.  This is despite every second fetch being unaligned.
Packit 5c3484
Packit 5c3484
Packit 5c3484
defframe(PARAM_SHIFT,16)
Packit 5c3484
defframe(PARAM_SIZE, 12)
Packit 5c3484
defframe(PARAM_SRC,  8)
Packit 5c3484
defframe(PARAM_DST,  4)
Packit 5c3484
deflit(`FRAME',0)
Packit 5c3484
Packit 5c3484
	TEXT
Packit 5c3484
	ALIGN(32)
Packit 5c3484
Packit 5c3484
PROLOGUE(mpn_rshift)
Packit 5c3484
deflit(`FRAME',0)
Packit 5c3484
Packit 5c3484
	C The 1 limb case can be done without the push %ebx, but it's then
Packit 5c3484
	C still the same speed.  The push is left as a free helping hand for
Packit 5c3484
	C the two_or_more code.
Packit 5c3484
Packit 5c3484
	movl	PARAM_SIZE, %eax
Packit 5c3484
	pushl	%ebx			FRAME_pushl()
Packit 5c3484
Packit 5c3484
	movl	PARAM_SRC, %ebx
Packit 5c3484
	decl	%eax
Packit 5c3484
Packit 5c3484
	movl	PARAM_SHIFT, %ecx
Packit 5c3484
	jnz	L(two_or_more)
Packit 5c3484
Packit 5c3484
	movl	(%ebx), %edx		C src limb
Packit 5c3484
	movl	PARAM_DST, %ebx
Packit 5c3484
Packit 5c3484
	shrdl(	%cl, %edx, %eax)	C return value
Packit 5c3484
Packit 5c3484
	shrl	%cl, %edx
Packit 5c3484
Packit 5c3484
	movl	%edx, (%ebx)		C dst limb
Packit 5c3484
	popl	%ebx
Packit 5c3484
Packit 5c3484
	ret
Packit 5c3484
Packit 5c3484
Packit 5c3484
	ALIGN(16)	C avoid offset 0x1f
Packit 5c3484
L(two_or_more):
Packit 5c3484
	C eax	size-1
Packit 5c3484
	C ebx	src
Packit 5c3484
	C ecx	shift
Packit 5c3484
	C edx
Packit 5c3484
Packit 5c3484
	movl	(%ebx), %edx	C src low limb
Packit 5c3484
	negl	%ecx
Packit 5c3484
Packit 5c3484
	addl	$32, %ecx	C 32-shift
Packit 5c3484
	movd	PARAM_SHIFT, %mm6
Packit 5c3484
Packit 5c3484
	shll	%cl, %edx	C retval
Packit 5c3484
	movl	PARAM_DST, %ecx
Packit 5c3484
Packit 5c3484
	leal	(%ebx,%eax,4), %ebx
Packit 5c3484
Packit 5c3484
	leal	-4(%ecx,%eax,4), %ecx
Packit 5c3484
	negl	%eax
Packit 5c3484
Packit 5c3484
Packit 5c3484
L(simple):
Packit 5c3484
	C eax	counter (negative)
Packit 5c3484
	C ebx	&src[size-1]
Packit 5c3484
	C ecx	&dst[size-1]
Packit 5c3484
	C edx	retval
Packit 5c3484
	C
Packit 5c3484
	C mm0	scratch
Packit 5c3484
	C mm6	shift
Packit 5c3484
Packit 5c3484
Zdisp(	movq,	0,(%ebx,%eax,4), %mm0)
Packit 5c3484
	incl	%eax
Packit 5c3484
Packit 5c3484
	psrlq	%mm6, %mm0
Packit 5c3484
Packit 5c3484
Zdisp(	movd,	%mm0, 0,(%ecx,%eax,4))
Packit 5c3484
	jnz	L(simple)
Packit 5c3484
Packit 5c3484
Packit 5c3484
	movq	%mm0, (%ecx)
Packit 5c3484
	movl	%edx, %eax
Packit 5c3484
Packit 5c3484
	popl	%ebx
Packit 5c3484
Packit 5c3484
	emms
Packit 5c3484
	ret
Packit 5c3484
Packit 5c3484
EPILOGUE()