[Gmp-commit] /var/hg/gmp: New code for Atom/32.

mercurial at gmplib.org mercurial at gmplib.org
Sun Feb 20 11:15:07 CET 2011


details:   /var/hg/gmp/rev/153ddf846890
changeset: 13864:153ddf846890
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Feb 20 10:59:12 2011 +0100
description:
New code for Atom/32.

diffstat:

 ChangeLog               |    5 +
 mpn/x86/atom/aors_n.asm |  137 +++++++++++++++++++++++++++++++++++++++++++----
 mpn/x86/atom/rshift.asm |  105 +++++++++++++++++++++++++++++++++++-
 3 files changed, 230 insertions(+), 17 deletions(-)

diffs (281 lines):

diff -r cb84fd36e8f2 -r 153ddf846890 ChangeLog
--- a/ChangeLog	Sat Feb 19 16:34:29 2011 +0100
+++ b/ChangeLog	Sun Feb 20 10:59:12 2011 +0100
@@ -1,3 +1,8 @@
+2011-02-20 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* mpn/x86/atom/aors_n.asm: New code.
+	* mpn/x86/atom/rshift.asm: Atom64 code adapted to 32-bit.
+
 2011-02-19  Torbjorn Granlund  <tege at gmplib.org>
 
 	* mpn/x86_64/atom/rsh1aors_n.asm: New file.
diff -r cb84fd36e8f2 -r 153ddf846890 mpn/x86/atom/aors_n.asm
--- a/mpn/x86/atom/aors_n.asm	Sat Feb 19 16:34:29 2011 +0100
+++ b/mpn/x86/atom/aors_n.asm	Sun Feb 20 10:59:12 2011 +0100
@@ -1,23 +1,132 @@
-dnl  Intel Atom mpn_add_n/mpn_sub_n -- mpn add or subtract.
+dnl  Intel Atom mpn_add_n/mpn_sub_n -- rp[] = up[] +- vp[].
 
 dnl  Copyright 2011 Free Software Foundation, Inc.
-dnl
+
+dnl  Contributed to the GNU project by Marco Bodrato.
+
 dnl  This file is part of the GNU MP Library.
-dnl
-dnl  The GNU MP Library is free software; you can redistribute it and/or
-dnl  modify it under the terms of the GNU Lesser General Public License as
-dnl  published by the Free Software Foundation; either version 3 of the
-dnl  License, or (at your option) any later version.
-dnl
-dnl  The GNU MP Library is distributed in the hope that it will be useful,
-dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
-dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-dnl  Lesser General Public License for more details.
-dnl
+
+dnl  The GNU MP Library is free software; you can redistribute it and/or modify
+dnl  it under the terms of the GNU Lesser General Public License as published
+dnl  by the Free Software Foundation; either version 3 of the License, or (at
+dnl  your option) any later version.
+
+dnl  The GNU MP Library is distributed in the hope that it will be useful, but
+dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+dnl  License for more details.
+
 dnl  You should have received a copy of the GNU Lesser General Public License
 dnl  along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.
 
 include(`../config.m4')
 
+ifdef(`OPERATION_add_n', `
+	define(M4_inst,        adcl)
+	define(M4_function_n,  mpn_add_n)
+	define(M4_function_nc, mpn_add_nc)
+	define(M4_description, add)
+',`ifdef(`OPERATION_sub_n', `
+	define(M4_inst,        sbbl)
+	define(M4_function_n,  mpn_sub_n)
+	define(M4_function_nc, mpn_sub_nc)
+	define(M4_description, subtract)
+',`m4_error(`Need OPERATION_add_n or OPERATION_sub_n
+')')')
+
 MULFUNC_PROLOGUE(mpn_add_n mpn_add_nc mpn_sub_n mpn_sub_nc)
-include_mpn(`x86/k7/aors_n.asm')
+
+C mp_limb_t M4_function_n (mp_ptr dst, mp_srcptr src1, mp_srcptr src2,
+C                         mp_size_t size);
+C mp_limb_t M4_function_nc (mp_ptr dst, mp_srcptr src1, mp_srcptr src2,
+C	                   mp_size_t size, mp_limb_t carry);
+C
+C Calculate src1,size M4_description src2,size, and store the result in
+C dst,size.  The return value is the carry bit from the top of the result (1
+C or 0).
+C
+C The _nc version accepts 1 or 0 for an initial carry into the low limb of
+C the calculation.  Note values other than 1 or 0 here will lead to garbage
+C results.
+
+defframe(PARAM_CARRY,20)
+defframe(PARAM_SIZE, 16)
+defframe(PARAM_SRC2, 12)
+defframe(PARAM_SRC1, 8)
+defframe(PARAM_DST,  4)
+
+dnl  re-use parameter space
+define(SAVE_RP,`PARAM_SIZE')
+define(SAVE_VP,`PARAM_SRC1')
+define(SAVE_UP,`PARAM_DST')
+
+define(`rp',  `%edi')
+define(`up',  `%esi')
+define(`vp',  `%ebp')
+define(`cy',  `%ecx')
+define(`r1',  `%ecx')
+define(`r2',  `%edx')
+
+ASM_START()
+	TEXT
+	ALIGN(8)
+deflit(`FRAME',0)
+
+PROLOGUE(M4_function_nc)
+	movl	PARAM_CARRY, cy		C carry
+	jmp	L(start)
+EPILOGUE()
+
+PROLOGUE(M4_function_n)
+	xorl	cy, cy			C carry
+L(start):
+	movl	PARAM_SIZE, %eax	C size
+	movl	rp, SAVE_RP
+	movl	PARAM_DST, rp
+	movl	up, SAVE_UP
+	shr	%eax			C size >> 1
+	movl	PARAM_SRC1, up
+	movl	vp, SAVE_VP
+	movl	PARAM_SRC2, vp
+	jz	L(one)			C size == 1
+	jc	L(three)		C size % 2 == 1
+
+	shr	cy
+	mov	(up), r2
+	lea	4(up), up
+	lea	4(vp), vp
+	lea	-4(rp), rp
+	jmp	L(entry)
+L(one):
+	shr	cy
+	mov	(up), r1
+	jmp	L(end)
+L(three):
+	shr	cy
+	mov	(up), r1
+
+	ALIGN(8)
+L(oop):
+	M4_inst	(vp), r1
+	lea	8(up), up
+	mov	-4(up), r2
+	lea	8(vp), vp
+	mov	r1, (rp)
+L(entry):
+	M4_inst	-4(vp), r2
+	decl	%eax
+	lea	8(rp), rp
+	mov	(up), r1
+	mov	r2, -4(rp)
+	jnz	L(oop)
+
+L(end):				C %eax is zero here
+	movl	SAVE_UP, up
+	M4_inst	(vp), r1
+	movl	SAVE_VP, vp
+	mov	r1, (rp)
+	adc	%eax, %eax
+	movl	SAVE_RP, rp
+	ret
+EPILOGUE()
+ASM_END()
diff -r cb84fd36e8f2 -r 153ddf846890 mpn/x86/atom/rshift.asm
--- a/mpn/x86/atom/rshift.asm	Sat Feb 19 16:34:29 2011 +0100
+++ b/mpn/x86/atom/rshift.asm	Sun Feb 20 10:59:12 2011 +0100
@@ -1,7 +1,9 @@
 dnl  Intel Atom mpn_rshift -- mpn right shift.
 
 dnl  Copyright 2011 Free Software Foundation, Inc.
-dnl
+
+dnl  Converted from AMD64 by Marco Bodrato.
+
 dnl  This file is part of the GNU MP Library.
 dnl
 dnl  The GNU MP Library is free software; you can redistribute it and/or
@@ -19,5 +21,102 @@
 
 include(`../config.m4')
 
-MULFUNC_PROLOGUE(mpn_rshift)
-include_mpn(`x86/pentium/rshift.asm')
+defframe(PARAM_CNT, 16)
+defframe(PARAM_SIZE,12)
+defframe(PARAM_SRC,  8)
+defframe(PARAM_DST,  4)
+
+dnl  re-use parameter space
+define(SAVE_UP,`PARAM_CNT')
+define(VAR_COUNT,`PARAM_SIZE')
+define(SAVE_EBX,`PARAM_SRC')
+define(SAVE_EBP,`PARAM_DST')
+
+define(`rp',  `%edi')
+define(`up',  `%esi')
+define(`cnt',  `%ecx')
+
+ASM_START()
+	TEXT
+	ALIGN(8)
+deflit(`FRAME',0)
+PROLOGUE(mpn_rshift)
+	movl	PARAM_CNT, cnt
+	movl	PARAM_SIZE, %edx
+	movl	up, SAVE_UP
+	movl	PARAM_SRC, up
+	push	rp			FRAME_pushl()
+	movl	PARAM_DST, rp
+	movl	%ebx, SAVE_EBX
+
+	shr	%edx
+	mov	(up), %eax
+	movl	%edx, VAR_COUNT
+	jnc	L(evn)
+
+	mov	%eax, %ebx
+	shr	%cl, %ebx
+	neg	cnt
+	shl	%cl, %eax
+	test	%edx, %edx
+	jnz	L(gt1)
+	mov	%ebx, (rp)
+	jmp	L(quit)
+
+L(gt1):	movl	%ebp, SAVE_EBP
+	push	%eax
+	mov	4(up), %eax
+	mov	%eax, %ebp
+	shl	%cl, %eax
+	jmp	L(lo1)
+
+L(evn):	movl	%ebp, SAVE_EBP
+	neg	cnt
+	mov	%eax, %ebp
+	mov	4(up), %edx
+	shl	%cl, %eax
+	mov	%edx, %ebx
+	shl	%cl, %edx
+	neg	cnt
+	decl	VAR_COUNT
+	lea	-4(rp), rp
+	lea	4(up), up
+	jz	L(end)
+	push	%eax			FRAME_pushl()
+
+	ALIGN(16)
+L(top):	shr	%cl, %ebp
+	or	%ebp, %edx
+	shr	%cl, %ebx
+	neg	cnt
+	mov	4(up), %eax
+	mov	%eax, %ebp
+	mov	%edx, 4(rp)
+	shl	%cl, %eax
+	lea	8(rp), rp
+L(lo1):	mov	8(up), %edx
+	or	%ebx, %eax
+	mov	%edx, %ebx
+	shl	%cl, %edx
+	lea	8(up), up
+	neg	cnt
+	mov	%eax, (rp)
+	decl	VAR_COUNT
+	jg	L(top)
+
+	pop	%eax			FRAME_popl()
+L(end):
+	shr	%cl, %ebp
+	shr	%cl, %ebx
+	or	%ebp, %edx
+	movl	SAVE_EBP, %ebp
+	mov	%edx, 4(rp)
+	mov	%ebx, 8(rp)
+
+L(quit):
+	movl	SAVE_UP, up
+	movl	SAVE_EBX, %ebx
+	pop	rp			FRAME_popl()
+	ret
+EPILOGUE()
+ASM_END()


More information about the gmp-commit mailing list