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

mercurial at gmplib.org mercurial at gmplib.org
Sun Oct 31 01:09:54 UTC 2021


details:   /var/hg/gmp/rev/2da64c6b693d
changeset: 18265:2da64c6b693d
user:      Torbjorn Granlund <tg at gmplib.org>
date:      Sun Oct 31 02:08:34 2021 +0100
description:
Streamline.

details:   /var/hg/gmp/rev/f5f4588c6ccf
changeset: 18266:f5f4588c6ccf
user:      Torbjorn Granlund <tg at gmplib.org>
date:      Sun Oct 31 02:09:33 2021 +0100
description:
New file.

details:   /var/hg/gmp/rev/d343c620e614
changeset: 18267:d343c620e614
user:      Torbjorn Granlund <tg at gmplib.org>
date:      Sun Oct 31 02:09:45 2021 +0100
description:
New file.

diffstat:

 mpn/riscv/64/sec_tabselect.asm |  77 ++++++++++++++++++++++++++++++++++++
 mpn/s390_64/sec_tabselect.asm  |  89 ++++++++++++++++++++++++++++++++++++++++++
 mpn/x86/sec_tabselect.asm      |  29 ++++--------
 3 files changed, 176 insertions(+), 19 deletions(-)

diffs (244 lines):

diff -r 8c2d3d4637b2 -r d343c620e614 mpn/riscv/64/sec_tabselect.asm
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mpn/riscv/64/sec_tabselect.asm	Sun Oct 31 02:09:45 2021 +0100
@@ -0,0 +1,77 @@
+dnl  RISC-V/64 mpn_sec_tabselect
+
+dnl  Copyright 2021 Free Software Foundation, 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')
+
+dnl This is compiler output, mildly edited.  We don't expect this to be faster
+dnl than the C fallback code, but providing this in assembly avoids problems
+dnl with compilers which generate side channel leaky code.
+
+define(`rp',	`a0')
+define(`tp',	`a1')
+define(`n',	`a2')
+define(`nents',	`a3')
+define(`which',	`a4')
+
+ASM_START()
+PROLOGUE(mpn_sec_tabselect)
+	slli	n, n, 3
+	add	t4, a0, n
+
+L(cpy):	ld	a7, 0(tp)
+	addi	tp, tp, 8
+	addi	rp, rp, 8
+	sd	a7, -8(rp)
+	bne	rp, t4, L(cpy)
+
+	li	t5, 1
+	ble	nents, t5, L(ret)
+
+L(outer):
+	xor	t3, which, t5
+	neg	t3, t3
+	srai	t3, t3, 63
+	sub	rp, rp, n
+
+L(top):	ld	a5, 0(rp)
+	ld	t1, 0(tp)
+	addi	rp, rp, 8
+	addi	tp, tp, 8
+	xor	a5, a5, t1
+	and	a5, a5, t3
+	xor	a5, a5, t1
+	sd	a5, -8(rp)
+	bne	t4, rp, L(top)
+
+	addi	t5, t5, 1
+	bne	nents, t5, L(outer)
+
+L(ret):	ret
+EPILOGUE()
diff -r 8c2d3d4637b2 -r d343c620e614 mpn/s390_64/sec_tabselect.asm
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mpn/s390_64/sec_tabselect.asm	Sun Oct 31 02:09:45 2021 +0100
@@ -0,0 +1,89 @@
+dnl  S/390-64 mpn_sec_tabselect
+
+dnl  Copyright 2021 Free Software Foundation, 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 z900		 ?
+C z990		 ?
+C z9		 ?
+C z10		 ?
+C z196		 ?
+C z13		 ?
+C z14		 ?
+C z15		 ?
+
+dnl void
+dnl mpn_sec_tabselect (volatile mp_limb_t *rp, volatile const mp_limb_t *tab,
+dnl                    mp_size_t n, mp_size_t nents, mp_size_t which)
+
+define(`rp',	`%r2')
+define(`tp',	`%r3')
+define(`n',	`%r4')
+define(`nents',	`%r5')
+define(`which',	`%r6')
+
+ASM_START()
+PROLOGUE(mpn_sec_tabselect)
+	stmg	%r7, %r8, 56(%r15)
+	lgr	%r8, n
+	sllg	n, n, 3
+
+L(cpy):	lg	%r0, 0(tp)
+	stg	%r0, 0(rp)
+	aghi	tp, 8
+	aghi	rp, 8
+	brctg	%r8, L(cpy)
+
+	aghi	nents, -1
+	jle	L(ret)
+	slfi	which, 1
+
+L(outer):
+	slfi	which, 1
+	slbgr	%r0, %r0
+	sgr	rp, n
+	srlg	%r8, n, 3
+
+L(top):	lg	%r1, 0(rp)
+	lg	%r7, 0(tp)
+	xgr	%r7, %r1
+	ngr	%r7, %r0
+	xgr	%r1, %r7
+	stg	%r1, 0(rp)
+	aghi	tp, 8
+	aghi	rp, 8
+	brctg	%r8, L(top)
+
+	brctg	nents, L(outer)
+
+L(ret):	lmg	%r7, %r8, 56(%r15)
+	br	%r14
+EPILOGUE()
diff -r 8c2d3d4637b2 -r d343c620e614 mpn/x86/sec_tabselect.asm
--- a/mpn/x86/sec_tabselect.asm	Fri Oct 29 23:54:41 2021 +0200
+++ b/mpn/x86/sec_tabselect.asm	Sun Oct 31 02:09:45 2021 +0100
@@ -1,6 +1,6 @@
 dnl  x86 mpn_sec_tabselect.
 
-dnl  Copyright 2011 Free Software Foundation, Inc.
+dnl  Copyright 2011, 2021 Free Software Foundation, Inc.
 
 dnl  This file is part of the GNU MP Library.
 dnl
@@ -56,12 +56,11 @@
 define(`rp',     `%edi')
 define(`tp',     `%esi')
 define(`n',      `%ebx')
-define(`nents',  `%ecx')
+define(`nents',  `32(%esp)')
 define(`which',  `36(%esp)')
 
 define(`i',      `%ebp')
-define(`maskp',  `20(%esp)')
-define(`maskn',  `32(%esp)')
+define(`mask',   `%ecx')
 
 ASM_START()
 	TEXT
@@ -74,36 +73,28 @@
 	mov	20(%esp), rp
 	mov	24(%esp), tp
 	mov	28(%esp), n
-	mov	32(%esp), nents
 
 	lea	(rp,n,4), rp
 	lea	(tp,n,4), tp
-	sub	nents, which
 L(outer):
-	mov	which, %eax
-	add	nents, %eax
-	neg	%eax			C set CF iff 'which' != k
-	sbb	%eax, %eax
-	mov	%eax, maskn
-	not	%eax
-	mov	%eax, maskp
+	sub	$1, which
+	sbb	mask, mask
 
 	mov	n, i
 	neg	i
 
 	ALIGN(16)
 L(top):	mov	(tp,i,4), %eax
-	and	maskp, %eax
 	mov	(rp,i,4), %edx
-	and	maskn, %edx
-	or	%edx, %eax
+	xor	%edx, %eax
+	and	mask, %eax
+	xor	%edx, %eax
 	mov	%eax, (rp,i,4)
 	inc	i
 	js	L(top)
 
-L(end):	mov	n, %eax
-	lea	(tp,%eax,4), tp
-	dec	nents
+L(end):	lea	(tp,n,4), tp
+	decl	nents
 	jne	L(outer)
 
 L(outer_end):


More information about the gmp-commit mailing list