[Gmp-commit] /var/hg/gmp: 2 new changesets

mercurial at gmplib.org mercurial at gmplib.org
Sun Nov 18 00:27:54 UTC 2018


details:   /var/hg/gmp/rev/176728661568
changeset: 17708:176728661568
user:      Torbjorn Granlund <tg at gmplib.org>
date:      Sun Nov 18 01:27:02 2018 +0100
description:
Optimise.

details:   /var/hg/gmp/rev/2c7b911c6329
changeset: 17709:2c7b911c6329
user:      Torbjorn Granlund <tg at gmplib.org>
date:      Sun Nov 18 01:27:27 2018 +0100
description:
New file.

diffstat:

 mpn/powerpc64/mode64/p9/addmul_1.asm     |   74 ++--
 mpn/powerpc64/mode64/p9/mul_basecase.asm |  416 +++++++++++++++++++++++++++++++
 2 files changed, 450 insertions(+), 40 deletions(-)

diffs (truncated from 557 to 300 lines):

diff -r 52bae415aab0 -r 2c7b911c6329 mpn/powerpc64/mode64/p9/addmul_1.asm
--- a/mpn/powerpc64/mode64/p9/addmul_1.asm	Fri Nov 16 07:47:53 2018 +0100
+++ b/mpn/powerpc64/mode64/p9/addmul_1.asm	Sun Nov 18 01:27:27 2018 +0100
@@ -1,4 +1,4 @@
-dnl  POWER9 mpn_addmul_1.
+dnl  Power9 mpn_addmul_1.
 
 dnl  Copyright 2017, 2018 Free Software Foundation, Inc.
 
@@ -40,8 +40,9 @@
 C POWER9		 2.5
 
 C TODO
-C  * Schedule for POWER9 pipeline.
-C  * Unroll to at least 4x if that proves beneficial.
+C  * Schedule for Power9 pipeline.
+C  * Unroll 4x if that proves beneficial.
+C  * This is marginally faster (but much smaller) than ../aorsmul_1.asm.
 
 C INPUT PARAMETERS
 define(`rp', `r3')
@@ -51,41 +52,37 @@
 
 ASM_START()
 PROLOGUE(mpn_addmul_1)
-	std	r31, -8(r1)
-
 	cmpdi	cr6, n, 2
-
 	addi	r0, n, -1	C FIXME: postpone
 	srdi	r0, r0, 1	C FIXME: postpone
 	mtctr	r0		C FIXME: postpone
-
 	rldicl.	r0, n, 0,63	C r0 = n & 3, set cr0
 	bne	cr0, L(b1)
 
 L(b0):	ld	r10, 0(rp)
 	ld	r12, 0(up)
 	ld	r11, 8(rp)
-	ld	r31, 8(up)
-	maddld(	r0, r12, v0, r10)
+	ld	r0, 8(up)
+	maddld(	r9, r12, v0, r10)
 	maddhdu(r7, r12, v0, r10)
 	ble	cr6, L(2)
 	ld	r10, 16(rp)
 	ld	r12, 16(up)
-	maddld(	r8, r31, v0, r11)
-	maddhdu(r5, r31, v0, r11)
+	maddld(	r8, r0, v0, r11)
+	maddhdu(r5, r0, v0, r11)
 	addic	up, up, 16
 	addi	rp, rp, -8
 	b	L(mid)
 
 L(b1):	ld	r11, 0(rp)
-	ld	r31, 0(up)
+	ld	r0, 0(up)
 	ble	cr6, L(1)
 	ld	r10, 8(rp)
 	ld	r12, 8(up)
-	maddld(	r0, r31, v0, r11)
-	maddhdu(r5, r31, v0, r11)
+	maddld(	r8, r0, v0, r11)
+	maddhdu(r5, r0, v0, r11)
 	ld	r11, 16(rp)
-	ld	r31, 16(up)
+	ld	r0, 16(up)
 	maddld(	r9, r12, v0, r10)
 	maddhdu(r7, r12, v0, r10)
 	addic	up, up, 24
@@ -94,43 +91,40 @@
 	ALIGN(16)
 L(top):	ld	r10, 24(rp)
 	ld	r12, 0(up)
-	std	r0, 0(rp)
-	adde	r0, r5, r9
-	maddld(	r8, r31, v0, r11)	C W:0,2,4
-	maddhdu(r5, r31, v0, r11)	C W:1,3,5
+	std	r8, 0(rp)
+	adde	r9, r5, r9
+	maddld(	r8, r0, v0, r11)	C W:0,2,4
+	maddhdu(r5, r0, v0, r11)	C W:1,3,5
 L(mid):	ld	r11, 32(rp)
-	ld	r31, 8(up)
-	std	r0, 8(rp)
-	adde	r0, r7, r8
+	ld	r0, 8(up)
+	std	r9, 8(rp)
+	adde	r8, r7, r8
 	maddld(	r9, r12, v0, r10)	C W:1,3,5
 	maddhdu(r7, r12, v0, r10)	C W:2,4,6
 	addi	rp, rp, 16
 	addi	up, up, 16
 	bdnz	L(top)
 
-L(end):	std	r0, 0(rp)
-	adde	r0, r5, r9
-	maddld(	r8, r31, v0, r11)
-	maddhdu(r5, r31, v0, r11)
-	std	r0, 8(rp)
-	adde	r0, r7, r8
-	std	r0, 16(rp)
+L(end):	std	r8, 0(rp)
+	maddld(	r8, r0, v0, r11)
+	adde	r9, r5, r9
+	maddhdu(r5, r0, v0, r11)
+	std	r9, 8(rp)
+	adde	r8, r7, r8
+	std	r8, 16(rp)
 	addze	r3, r5
-	ld	r31, -8(r1)
 	blr
 
-L(2):	maddld(	r8, r31, v0, r11)
-	maddhdu(r5, r31, v0, r11)
-	std	r0, 0(rp)
-	addc	r0, r7, r8
-	std	r0, 8(rp)
+L(2):	maddld(	r8, r0, v0, r11)
+	maddhdu(r5, r0, v0, r11)
+	std	r9, 0(rp)
+	addc	r8, r7, r8
+	std	r8, 8(rp)
 	addze	r3, r5
-	ld	r31, -8(r1)
 	blr
 
-L(1):	maddld(	r0,  r31, v0, r11)
-	std	r0, 0(rp)
-	maddhdu(r3, r31, v0, r11)
-	ld	r31, -8(r1)
+L(1):	maddld(	r8,  r0, v0, r11)
+	std	r8, 0(rp)
+	maddhdu(r3, r0, v0, r11)
 	blr
 EPILOGUE()
diff -r 52bae415aab0 -r 2c7b911c6329 mpn/powerpc64/mode64/p9/mul_basecase.asm
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mpn/powerpc64/mode64/p9/mul_basecase.asm	Sun Nov 18 01:27:27 2018 +0100
@@ -0,0 +1,416 @@
+dnl  Power9 mpn_mul_basecase.
+
+dnl  Copyright 1999-2001, 2003-2006, 2008, 2017-2018 Free Software Foundation,
+dnl  Inc.
+
+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 modify
+dnl  it under the terms of either:
+dnl
+dnl    * the GNU Lesser General Public License as published by the Free
+dnl      Software Foundation; either version 3 of the License, or (at your
+dnl      option) any later version.
+dnl
+dnl  or
+dnl
+dnl    * the GNU General Public License as published by the Free Software
+dnl      Foundation; either version 2 of the License, or (at your option) any
+dnl      later version.
+dnl
+dnl  or both in parallel, as here.
+dnl
+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 General Public License
+dnl  for more details.
+dnl
+dnl  You should have received copies of the GNU General Public License and the
+dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
+dnl  see https://www.gnu.org/licenses/.
+
+include(`../config.m4')
+
+C                  cycles/limb
+C POWER3/PPC630          -
+C POWER4/PPC970          -
+C POWER5                 -
+C POWER6                 -
+C POWER7                 -
+C POWER8                 -
+C POWER9                 1.62
+
+C TODO
+C  * Check if (inner) loop alignment affects performance.
+C  * Could we schedule loads less in addmul_2/mul_2? That would save some regs
+C    and make the tail code more manageable.
+C  * Postpone some register saves to main loop.
+C  * Perhaps write more small operands (3x1, 3x2, 3x3) code.
+C  * Consider restoring rp,up after loop using arithmetic, eliminating r20,r21.
+C    On the other hand, the current rp,up restore register are useful for OSP.
+C  * Do OSP. This should save a lot with the current deep addmul_2 pipeline.
+
+C INPUT PARAMETERS
+define(`rp', `r3')
+define(`up', `r4')
+define(`un', `r5')
+define(`vp', `r6')
+define(`vn', `r7')
+
+define(`v0', `r0')
+define(`v1', `r7')
+define(`rp2', `r24')
+define(`up2', `r25')
+
+ASM_START()
+PROLOGUE(mpn_mul_basecase)
+	cmpdi	cr0, un, 2
+	bgt	cr0, L(un_gt2)
+	cmpdi	cr6, vn, 1
+	ld	r7, 0(vp)
+	ld	r5, 0(up)
+	mulld	r8, r5, r7	C weight 0
+	mulhdu	r9, r5, r7	C weight 1
+	std	r8, 0(rp)
+	beq	cr0, L(2x)
+	std	r9, 8(rp)
+	blr
+	ALIGN(16)
+L(2x):	ld	r0, 8(up)
+	mulld	r8, r0, r7	C weight 1
+	mulhdu	r10, r0, r7	C weight 2
+	addc	r9, r9, r8
+	addze	r10, r10
+	bne	cr6, L(2x2)
+	std	r9, 8(rp)
+	std	r10, 16(rp)
+	blr
+	ALIGN(16)
+L(2x2):	ld	r6, 8(vp)
+	mulld	r8, r5, r6	C weight 1
+	mulhdu	r11, r5, r6	C weight 2
+	addc	r9, r9, r8
+	std	r9, 8(rp)
+	adde	r11, r11, r10
+	mulld	r12, r0, r6	C weight 2
+	mulhdu	r0, r0, r6	C weight 3
+	addze	r0, r0
+	addc	r11, r11, r12
+	addze	r0, r0
+	std	r11, 16(rp)
+	std	r0, 24(rp)
+	blr
+
+L(un_gt2):
+	std	r22, -80(r1)
+	std	r23, -72(r1)
+	std	r24, -64(r1)
+	std	r25, -56(r1)
+	std	r26, -48(r1)
+	std	r27, -40(r1)
+	std	r28, -32(r1)
+	std	r29, -24(r1)
+	std	r30, -16(r1)
+	std	r31, -8(r1)
+	mr	rp2, r3			C rp
+	mr	up2, r4			C up
+	srdi	r22, r5, 2		C un
+	subfic	r23, r7, 0		C -vn, clear CA
+	subfo	r0, r0, r0		C clear OV (and r0)
+
+	cmpdi	cr6, un, 3
+	rldicl	r0, un, 0, 63		C r0 = un & 1
+	cmpdi	cr7, r0, 0
+	rldicl	r0, un, 63, 63		C FIXME: unused for vn = 1
+	cmpdi	cr5, r0, 0		C FIXME: unused for vn = 1
+
+	ld	v0, 0(vp)
+	rldicl.	r9, vn, 0, 63
+	beq	cr0, L(vn_evn)
+
+L(vn_odd):
+	addi	r10, un, -2
+	ld	r5, 0(up)
+	srdi	r10, r10, 1
+	mtctr	r10
+	bne	cr7, L(m1_b1)
+
+L(m1_b0):
+	ld	r10, 8(up)
+	mulld	r9, r5, v0
+	mulhdu	r11, r5, v0
+	ld	r12, 16(up)
+	mulld	r8, r10, v0
+	mulhdu	r5, r10, v0
+	addi	rp, rp, -8
+	b	L(m1_mid)
+
+L(m1_b1):
+	ld	r12, 8(up)
+	mulld	r8, r5, v0
+	mulhdu	r5, r5, v0
+	ld	r10, 16(up)
+	mulld	r9, r12, v0
+	mulhdu	r11, r12, v0
+	addi	up, up, 8
+	beq	cr6, L(m1_end)		C jump taken means un = 3, vn = {1,3}
+
+	ALIGN(16)
+L(m1_top):


More information about the gmp-commit mailing list