[Gmp-commit] /home/hgfiles/gmp: Tune.

mercurial at gmplib.org mercurial at gmplib.org
Wed Jun 30 23:06:00 CEST 2010


details:   /home/hgfiles/gmp/rev/5d980cdf49eb
changeset: 13660:5d980cdf49eb
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Wed Jun 30 23:05:53 2010 +0200
description:
Tune.

diffstat:

 ChangeLog               |    4 +
 mpn/x86_64/divrem_2.asm |  222 ++++++++++++++---------------------------------
 2 files changed, 73 insertions(+), 153 deletions(-)

diffs (truncated from 311 to 300 lines):

diff -r 40b15fdbf204 -r 5d980cdf49eb ChangeLog
--- a/ChangeLog	Sat Jun 19 16:16:52 2010 +0200
+++ b/ChangeLog	Wed Jun 30 23:05:53 2010 +0200
@@ -1,3 +1,7 @@
+2010-06-30  Torbjorn Granlund  <tege at gmplib.org>
+
+	* mpn/x86_64/divrem_2.asm: Tune.
+
 2010-06-19  Niels Möller  <nisse at lysator.liu.se>
 
 	* tune/speed.h (SPEED_ROUTINE_MPN_MOD_1_1): Pass normalized
diff -r 40b15fdbf204 -r 5d980cdf49eb mpn/x86_64/divrem_2.asm
--- a/mpn/x86_64/divrem_2.asm	Sat Jun 19 16:16:52 2010 +0200
+++ b/mpn/x86_64/divrem_2.asm	Wed Jun 30 23:05:53 2010 +0200
@@ -1,6 +1,6 @@
 dnl  x86-64 mpn_divrem_2 -- Divide an mpn number by a normalized 2-limb number.
 
-dnl  Copyright 2007, 2008 Free Software Foundation, Inc.
+dnl  Copyright 2007, 2008, 2010 Free Software Foundation, Inc.
 
 dnl  This file is part of the GNU MP Library.
 
@@ -20,22 +20,15 @@
 include(`../config.m4')
 
 
-C				NEW
-C		norm	frac	norm
-C AMD K8,K9	21	21	19
-C AMD K10	21	21	19
-C Intel P4	73	73	70
-C Intel core2	37.5	37.5	36
-C Intel corei	33	33	32
-C Intel atom	 ?	 ?	 ?
-C VIA nano	37	 ?	37
+C		c/l
+C AMD K8,K9	18
+C AMD K10	18
+C Intel P4	68
+C Intel core2	34
+C Intel corei	30.5
+C Intel atom	 ?
+C VIA nano	33
 
-C TODO
-C  * The loop has not been carefully tuned, nor analysed for critical path
-C    length.  It seems that 19 c/l is a bit long, compared to the 13 c/l for
-C    mpn_divrem_1.
-C  * Clean up.  This code is really crude.
-C  * Add testing to tests/devel/try.c before enabling NEW code.
 
 C INPUT PARAMETERS
 define(`qp',		`%rdi')
@@ -44,43 +37,40 @@
 define(`un_param',	`%rcx')
 define(`dp',		`%r8')
 
-define(`dinv',		`%r9')
-
-
-C rax rbx rcx rdx rsi rdi rbp r8  r9  r10 r11 r12 r13 r14 r15
-C         cnt         qp      d  dinv
 
 ASM_START()
 	TEXT
 	ALIGN(16)
 PROLOGUE(mpn_divrem_2)
-
 	push	%r15
-	lea	(%rdx,%rcx,8), %rax
 	push	%r14
 	push	%r13
+	push	%r12
+	lea	-24(%rdx,%rcx,8), %r12	C r12 = &up[un-1]
 	mov	%rsi, %r13
-	push	%r12
-	lea	-24(%rax), %r12
 	push	%rbp
 	mov	%rdi, %rbp
 	push	%rbx
-	mov	8(%r8), %r11
-	mov	-8(%rax), %r9
-	mov	(%r8), %r8
-	mov	-16(%rax), %r10
+	mov	8(%r8), %r11		C d1
+	mov	16(%r12), %rbx
+	mov	(%r8), %r8		C d0
+	mov	8(%r12), %r10
+
 	xor	R32(%r15), R32(%r15)
-	cmp	%r9, %r11
+	cmp	%rbx, %r11
 	ja	L(2)
 	setb	%dl
 	cmp	%r10, %r8
 	setbe	%al
 	orb	%al, %dl		C "orb" form to placate Sun tools
-	jne	L(23)
+	je	L(2)
+	inc	R32(%r15)
+	sub	%r8, %r10
+	sbb	%r11, %rbx
 L(2):
-	lea	-3(%rcx,%r13), %rbx	C un + fn - 3
-	test	%rbx, %rbx
-	js	L(6)
+	lea	-3(%rcx,%r13), %r14	C un + fn - 3
+	test	%r14, %r14
+	js	L(end)
 
 	push	%r8
 	push	%r10
@@ -94,124 +84,65 @@
 	mov	%r11, %rdx
 	mov	%rax, %rdi
 	imul	%rax, %rdx
-	mov	%rdx, %r14
+	mov	%rdx, %r9
 	mul	%r8
-	mov	%rdx, %rcx
-	mov	$-1, %rdx
-	add	%r8, %r14
-	adc	$0, %rdx
-	add	%rcx, %r14
-	adc	$0, %rdx
-	js	L(8)
-L(18):
-	dec	%rdi
-	sub	%r11, %r14
-	sbb	$0, %rdx
-	jns	L(18)
-L(8):
+	xor	R32(%rcx), R32(%rcx)
+	add	%r8, %r9
+	adc	$-1, %rcx
+	add	%rdx, %r9
+	adc	$0, %rcx
+	js	2f
+1:	dec	%rdi
+	sub	%r11, %r9
+	sbb	$0, %rcx
+	jns	1b
+2:
 
-C rax rbx rcx rdx rsi rdi rbp r8 r9 r10 r11 r12 r13 r14 r15
-C n2      un      n1 dinv qp  d0        d1  up  fn      msl
-C     n2  un     -d1      n1    dinv XX              XX
-
-ifdef(`NEW',`
-	lea	(%rbp,%rbx,8), %rbp
-	mov	%rbx, %rcx		C un
-	mov	%r9, %rbx
-	mov	%rdi, %r9		C di
-	mov	%r10, %r14
+	lea	(%rbp,%r14,8), %rbp
 	mov	%r11, %rsi
 	neg	%rsi			C -d1
+
+C rax rbx rcx rdx rsi rdi  rbp r8 r9 r10 r11 r12 r13 r14 r15
+C     n2  un      -d1 dinv qp  d0 q0     d1  up  fn      msl
+
 	ALIGN(16)
-L(loop):
-	mov	%r9, %rax		C di		ncp
+L(top):	mov	%rdi, %rax		C di		ncp
 	mul	%rbx			C		0, 17
-	add	%r14, %rax		C		4
-	mov	%rax, %r10		C q0		5
+	mov	%r10, %rcx		C
+	add	%rax, %rcx		C		4
 	adc	%rbx, %rdx		C		5
-	mov	%rdx, %rdi		C q		6
+	mov	%rdx, %r9		C q		6
 	imul	%rsi, %rdx		C		6
 	mov	%r8, %rax		C		ncp
-	lea	(%rdx, %r14), %rbx	C n1 -= ...	7
-	xor	R32(%r14), R32(%r14)	C
-	mul	%rdi			C		7
-	cmp	%rcx, %r13		C
+	lea	(%rdx, %r10), %rbx	C n1 -= ...	10
+	xor	R32(%r10), R32(%r10)	C
+	mul	%r9			C		7
+	cmp	%r14, %r13		C
 	jg	L(19)			C
-	mov	(%r12), %r14		C
+	mov	(%r12), %r10		C
 	sub	$8, %r12		C
-L(19):	sub	%r8, %r14		C		ncp
-	sbb	%r11, %rbx		C		9
-	sub	%rax, %r14		C		11
+L(19):	sub	%r8, %r10		C		ncp
+	sbb	%r11, %rbx		C		11
+	sub	%rax, %r10		C		11
 	sbb	%rdx, %rbx		C		12
-	inc	%rdi			C		7
+	xor	R32(%rax), R32(%rax)	C
 	xor	R32(%rdx), R32(%rdx)	C
-	cmp	%r10, %rbx		C		13
-	mov	%r8, %rax		C d0		ncp
-	adc	$-1, %rdx		C mask		14
-	add	%rdx, %rdi		C q--		15
-	and	%rdx, %rax		C d0 or 0	15
-	and	%r11, %rdx		C d1 or 0	15
-	add	%rax, %r14		C		16
+	cmp	%rcx, %rbx		C		13
+	cmovnc	%r8, %rax		C		14
+	cmovnc	%r11, %rdx		C		14
+	adc	$0, %r9			C adjust q	14
+	nop
+	add	%rax, %r10		C		15
 	adc	%rdx, %rbx		C		16
-	cmp	%r11, %rbx		C		17
+	cmp	%r11, %rbx		C
 	jae	L(fix)			C
-L(bck):	mov	%rdi, (%rbp)		C
+L(bck):	mov	%r9, (%rbp)		C
 	sub	$8, %rbp		C
-	dec	%rcx
-	jns	L(loop)
+	dec	%r14
+	jns	L(top)
 
-	mov	%r14, %r10
-	mov	%rbx, %r9
-',`
-	lea	(%rbp,%rbx,8), %rbp
-	mov	%rbx, %rcx
-	mov	%r9, %rax
-	mov	%r10, %rsi
-	ALIGN(16)
-L(loop):
-	mov	%rax, %r14		C		0, 19
-	mul	%rdi			C		0
-	mov	%r11, %r9		C		1
-	add	%rsi, %rax		C		4
-	mov	%rax, %rbx		C q0		5
-	adc	%r14, %rdx		C q		5
-	lea	1(%rdx), %r10		C		6
-	mov	%rdx, %rax		C		6
-	imul	%rdx, %r9		C		6
-	sub	%r9, %rsi		C		10
-	xor	R32(%r9), R32(%r9)	C
-	mul	%r8			C		7
-	cmp	%rcx, %r13		C
-	jg	L(13)			C
-	mov	(%r12), %r9		C
-	sub	$8, %r12		C
-L(13):	sub	%r8, %r9		C		ncp
-	sbb	%r11, %rsi		C		11
-	sub	%rax, %r9		C		11
-	sbb	%rdx, %rsi		C		12
-	cmp	%rbx, %rsi		C		13
-	sbb	%rax, %rax		C		14
-	not	%rax			C		15
-	add	%rax, %r10		C		16
-	mov	%r8, %rbx		C		ncp
-	and	%rax, %rbx		C		16
-	and	%r11, %rax		C		16
-	add	%rbx, %r9		C		17
-	adc	%rsi, %rax		C		18
-	cmp	%rax, %r11		C		19
-	jbe	L(fix)			C
-L(bck):	mov	%r10, (%rbp)		C
-	sub	$8, %rbp		C
-	mov	%r9, %rsi		C		18
-	dec	%rcx
-	jns	L(loop)
-
-	mov	%rsi, %r10
-	mov	%rax, %r9
-')
-L(6):
-	mov	%r10, 8(%r12)
-	mov	%r9, 16(%r12)
+L(end):	mov	%r10, 8(%r12)
+	mov	%rbx, 16(%r12)
 	pop	%rbx
 	pop	%rbp
 	pop	%r12
@@ -221,28 +152,13 @@
 	pop	%r15
 	ret
 
-L(23):	inc	R32(%r15)
-	sub	%r8, %r10
-	sbb	%r11, %r9
-	jmp	L(2)
-
-ifdef(`NEW',`
 L(fix):	seta	%dl
-	cmp	%r8, %r14
+	cmp	%r8, %r10
 	setae	%al
 	orb	%dl, %al		C "orb" form to placate Sun tools
 	je	L(bck)
-	inc	%rdi
-	sub	%r8, %r14
+	inc	%r9
+	sub	%r8, %r10
 	sbb	%r11, %rbx


More information about the gmp-commit mailing list