Blame mpn/x86/pentium/logops_n.asm

Packit 5c3484
dnl  Intel Pentium mpn_and_n,...,mpn_xnor_n -- bitwise logical operations.
Packit 5c3484
Packit 5c3484
dnl  Copyright 2001, 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 P5: 3.0 c/l  and, ior, xor
Packit 5c3484
C     3.5 c/l  andn, iorn, nand, nior, xnor
Packit 5c3484
Packit 5c3484
Packit 5c3484
define(M4_choose_op,
Packit 5c3484
`ifdef(`OPERATION_$1',`
Packit 5c3484
define(`M4_function', `mpn_$1')
Packit 5c3484
define(`M4_want_pre', `$4')
Packit 5c3484
define(`M4op',        `$3')
Packit 5c3484
define(`M4_want_post',`$2')
Packit 5c3484
')')
Packit 5c3484
define(M4pre, `ifelse(M4_want_pre, yes,`$1')')
Packit 5c3484
define(M4post,`ifelse(M4_want_post,yes,`$1')')
Packit 5c3484
Packit 5c3484
M4_choose_op( and_n,     , andl,    )
Packit 5c3484
M4_choose_op( andn_n,    , andl, yes)
Packit 5c3484
M4_choose_op( nand_n, yes, andl,    )
Packit 5c3484
M4_choose_op( ior_n,     ,  orl,    )
Packit 5c3484
M4_choose_op( iorn_n,    ,  orl, yes)
Packit 5c3484
M4_choose_op( nior_n, yes,  orl,    )
Packit 5c3484
M4_choose_op( xor_n,     , xorl,    )
Packit 5c3484
M4_choose_op( xnor_n, yes, xorl,    )
Packit 5c3484
Packit 5c3484
ifdef(`M4_function',,
Packit 5c3484
`m4_error(`Unrecognised or undefined OPERATION symbol
Packit 5c3484
')')
Packit 5c3484
Packit 5c3484
MULFUNC_PROLOGUE(mpn_and_n mpn_andn_n mpn_nand_n mpn_ior_n mpn_iorn_n mpn_nior_n mpn_xor_n mpn_xnor_n)
Packit 5c3484
Packit 5c3484
NAILS_SUPPORT(0-31)
Packit 5c3484
Packit 5c3484
Packit 5c3484
C void M4_function (mp_ptr wp, mp_srcptr xp, mp_srcptr yp, mp_size_t size);
Packit 5c3484
C
Packit 5c3484
C Nothing complicated here, just some care to avoid data cache bank clashes
Packit 5c3484
C and AGIs.
Packit 5c3484
C
Packit 5c3484
C We're one register short of being able to do a simple 4 loads, 2 ops, 2
Packit 5c3484
C stores.  Instead %ebp is juggled a bit and nops are introduced to keep the
Packit 5c3484
C pairings as intended.  An in-place operation would free up a register, for
Packit 5c3484
C an 0.5 c/l speedup, if that's worth bothering with.
Packit 5c3484
C
Packit 5c3484
C This code seems best for P55 too.  Data alignment is a big problem for MMX
Packit 5c3484
C and the pairing restrictions on movq and integer instructions make life
Packit 5c3484
C difficult.
Packit 5c3484
Packit 5c3484
defframe(PARAM_SIZE,16)
Packit 5c3484
defframe(PARAM_YP,  12)
Packit 5c3484
defframe(PARAM_XP,   8)
Packit 5c3484
defframe(PARAM_WP,   4)
Packit 5c3484
Packit 5c3484
	TEXT
Packit 5c3484
	ALIGN(8)
Packit 5c3484
Packit 5c3484
PROLOGUE(M4_function)
Packit 5c3484
deflit(`FRAME',0)
Packit 5c3484
Packit 5c3484
	pushl	%ebx	FRAME_pushl()
Packit 5c3484
	pushl	%esi	FRAME_pushl()
Packit 5c3484
Packit 5c3484
	pushl	%edi	FRAME_pushl()
Packit 5c3484
	pushl	%ebp	FRAME_pushl()
Packit 5c3484
Packit 5c3484
	movl	PARAM_SIZE, %ecx
Packit 5c3484
	movl	PARAM_XP, %ebx
Packit 5c3484
Packit 5c3484
	movl	PARAM_YP, %esi
Packit 5c3484
	movl	PARAM_WP, %edi
Packit 5c3484
Packit 5c3484
	shrl	%ecx
Packit 5c3484
	jnc	L(entry)
Packit 5c3484
Packit 5c3484
	movl	(%ebx,%ecx,8), %eax	C risk of data cache bank clash here
Packit 5c3484
	movl	(%esi,%ecx,8), %edx
Packit 5c3484
Packit 5c3484
M4pre(`	notl_or_xorl_GMP_NUMB_MASK(%edx)')
Packit 5c3484
Packit 5c3484
	M4op	%edx, %eax
Packit 5c3484
Packit 5c3484
M4post(`xorl	$GMP_NUMB_MASK, %eax')
Packit 5c3484
	orl	%ecx, %ecx
Packit 5c3484
Packit 5c3484
	movl	%eax, (%edi,%ecx,8)
Packit 5c3484
	jz	L(done)
Packit 5c3484
Packit 5c3484
	jmp	L(entry)
Packit 5c3484
Packit 5c3484
Packit 5c3484
L(top):
Packit 5c3484
	C eax
Packit 5c3484
	C ebx	xp
Packit 5c3484
	C ecx	counter, limb pairs, decrementing
Packit 5c3484
	C edx
Packit 5c3484
	C esi	yp
Packit 5c3484
	C edi	wp
Packit 5c3484
	C ebp
Packit 5c3484
Packit 5c3484
	M4op	%ebp, %edx
Packit 5c3484
	nop
Packit 5c3484
Packit 5c3484
M4post(`xorl	$GMP_NUMB_MASK, %eax')
Packit 5c3484
M4post(`xorl	$GMP_NUMB_MASK, %edx')
Packit 5c3484
Packit 5c3484
	movl	%eax, 4(%edi,%ecx,8)
Packit 5c3484
	movl	%edx, (%edi,%ecx,8)
Packit 5c3484
Packit 5c3484
L(entry):
Packit 5c3484
	movl	-4(%ebx,%ecx,8), %ebp
Packit 5c3484
	nop
Packit 5c3484
Packit 5c3484
	movl	-4(%esi,%ecx,8), %eax
Packit 5c3484
	movl	-8(%esi,%ecx,8), %edx
Packit 5c3484
Packit 5c3484
M4pre(`	xorl	$GMP_NUMB_MASK, %eax')
Packit 5c3484
M4pre(`	xorl	$GMP_NUMB_MASK, %edx')
Packit 5c3484
Packit 5c3484
	M4op	%ebp, %eax
Packit 5c3484
	movl	-8(%ebx,%ecx,8), %ebp
Packit 5c3484
Packit 5c3484
	decl	%ecx
Packit 5c3484
	jnz	L(top)
Packit 5c3484
Packit 5c3484
Packit 5c3484
	M4op	%ebp, %edx
Packit 5c3484
	nop
Packit 5c3484
Packit 5c3484
M4post(`xorl	$GMP_NUMB_MASK, %eax')
Packit 5c3484
M4post(`xorl	$GMP_NUMB_MASK, %edx')
Packit 5c3484
Packit 5c3484
	movl	%eax, 4(%edi,%ecx,8)
Packit 5c3484
	movl	%edx, (%edi,%ecx,8)
Packit 5c3484
Packit 5c3484
Packit 5c3484
L(done):
Packit 5c3484
	popl	%ebp
Packit 5c3484
	popl	%edi
Packit 5c3484
Packit 5c3484
	popl	%esi
Packit 5c3484
	popl	%ebx
Packit 5c3484
Packit 5c3484
	ret
Packit 5c3484
Packit 5c3484
EPILOGUE()