[PATCH] Add LEA64 macro for sparc64.

David Miller davem at redhat.com
Tue Apr 16 02:49:11 CEST 2013


Ok, since we ran into so many problems last time around, why don't we
simply be less ambitious.  Perhaps trying to solve so many things all
at once in such a delicate area was a huge mistake. :-)

To that end, let's start with just a LEA64 macro and convert
mpn/sparc64 over to it.

It uses rdpc, therefore it doesn't have to be mindful of PIC thunks
nor having to cater to leaf functions in a special way.

It also doesn't try to use gotdata relocations.

I have my fingers crossed, hoping that this approach has much less
fallout.  But, we'll see. :-)

2013-04-15  David S. Miller  <davem at davemloft.net>

	* mpn/sparc32/sparc-defs.m4 (LEA64): New macro.
	* mpn/sparc64/gcd_1.asm: Use it.
	* mpn/sparc64/ultrasparct3/dive_1.asm: Likewise.
	* mpn/sparc64/ultrasparct3/invert_limb.asm: Likewise.
	* mpn/sparc64/ultrasparct3/mode1o.asm: Likewise.

diff -r 5ea92466ab67 mpn/sparc32/sparc-defs.m4
--- a/mpn/sparc32/sparc-defs.m4	Mon Apr 15 23:00:14 2013 +0200
+++ b/mpn/sparc32/sparc-defs.m4	Mon Apr 15 17:42:20 2013 -0700
@@ -46,4 +46,23 @@
   define(`lzcnt',	``lzd'	$1, $2')
 ')
 
+dnl  Usage: LEA64(symbol,reg,pic_reg)
+dnl
+dnl  Use whatever 64-bit code sequence is appropriate to load "symbol" into
+dnl  register "reg", potentially using register "pic_reg" to perform the
+dnl  calculations.
+
+define(LEA64,
+m4_assert_numargs(3)
+m4_assert_defined(`HAVE_GOTDATA')
+`ifdef(`PIC',`
+	rd	%pc, %`$2'
+	sethi	%hi(_GLOBAL_OFFSET_TABLE_+4), %`$3'
+	add	%`$3', %lo(_GLOBAL_OFFSET_TABLE_+8), %`$3'
+	add	%`$2', %`$3', %`$3'
+	sethi	%hi(`$1'), %`$2'
+	or	%`$2', %lo(`$1'), %`$2'
+	ldx	[%`$3' + %`$2'], %`$2'',`
+	setx	`$1', %`$3', %`$2'')')
+
 divert
diff -r 5ea92466ab67 mpn/sparc64/gcd_1.asm
--- a/mpn/sparc64/gcd_1.asm	Mon Apr 15 23:00:14 2013 +0200
+++ b/mpn/sparc64/gcd_1.asm	Mon Apr 15 17:42:20 2013 -0700
@@ -94,22 +95,7 @@
 
 L(noreduce):
 
-ifdef(`PIC',`
-	rd	%pc, %g3
-	sethi	%hi(_GLOBAL_OFFSET_TABLE_+4), %g4
-	add	%g4, %lo(_GLOBAL_OFFSET_TABLE_+8), %g4
-	add	%g3, %g4, %g4
-	sethi	%hi(ctz_table), %g1
-	or	%g1, %lo(ctz_table), %g1
-	ldx	[%g4+%g1], %i5
-',`
-	sethi	%hh(ctz_table), %l7
-	or	%l7, %hm(ctz_table), %l7
-	sllx	%l7, 32, %l7
-	sethi	%lm(ctz_table), %g1
-	add	%l7, %g1, %l7
-	or	%l7, %lo(ctz_table), %i5
-')
+	LEA64(ctz_table, i5, g4)
 
 	cmp	%o0, 0
 	bnz	%xcc, L(mid)
diff -r 5ea92466ab67 mpn/sparc64/ultrasparct3/dive_1.asm
--- a/mpn/sparc64/ultrasparct3/dive_1.asm	Mon Apr 15 23:00:14 2013 +0200
+++ b/mpn/sparc64/ultrasparct3/dive_1.asm	Mon Apr 15 17:42:20 2013 -0700
@@ -54,22 +54,7 @@
 	srlx	d, 1, %g1
 	and	%g1, 127, %g1
 
-ifdef(`PIC',`
-	rd	%pc, %g3
-	sethi	%hi(_GLOBAL_OFFSET_TABLE_+4), %g4
-	add	%g4, %lo(_GLOBAL_OFFSET_TABLE_+8), %g4
-	add	%g3, %g4, %g4
-	sethi	%hi(binvert_limb_table), %g2
-	or	%g2, %lo(binvert_limb_table), %g2
-	ldx	[%g4+%g2], %g2
-',`
-	sethi	%hh(binvert_limb_table), %g3
-	or	%g3, %hm(binvert_limb_table), %g3
-	sllx	%g3, 32, %g3
-	sethi	%lm(binvert_limb_table), %g2
-	add	%g3, %g2, %g3
-	or	%g3, %lo(binvert_limb_table), %g2
-')
+	LEA64(binvert_limb_table, g2, g4)
 	ldub	[%g2+%g1], %g1
 	add	%g1, %g1, %g2
 	mulx	%g1, %g1, %g1
diff -r 5ea92466ab67 mpn/sparc64/ultrasparct3/invert_limb.asm
--- a/mpn/sparc64/ultrasparct3/invert_limb.asm	Mon Apr 15 23:00:14 2013 +0200
+++ b/mpn/sparc64/ultrasparct3/invert_limb.asm	Mon Apr 15 17:42:20 2013 -0700
@@ -35,25 +35,10 @@
 	srlx	d, 55, %g1
 	add	%g1, %g1, %g1
 
-ifdef(`PIC',`
-	rd	%pc, %g3
-	sethi	%hi(_GLOBAL_OFFSET_TABLE_+4), %g4
-	add	%g4, %lo(_GLOBAL_OFFSET_TABLE_+8), %g4
-	add	%g3, %g4, %g4
-	sethi	%hi(approx_tab), %g2
-	or	%g2, %lo(approx_tab), %g2
-	ldx	[%g4+%g2], %g2
-	add	%g1, -512, %g1
-',`
-	sethi	%hh(approx_tab-512), %g3
-	or	%g3, %hm(approx_tab-512), %g3
-	sllx	%g3, 32, %g3
-	sethi	%lm(approx_tab-512), %g2
-	add	%g3, %g2, %g3
-	or	%g3, %lo(approx_tab-512), %g2
-')
+	LEA64(approx_tab, g2, g3)
+	sub	%g2, 512, %g2
+	srlx	d, 24, %g4
 	lduh	[%g2+%g1], %g3
-	srlx	d, 24, %g4
 	add	%g4, 1, %g4
 	sllx	%g3, 11, %g2
 	add	%g2, -1, %g2
diff -r 5ea92466ab67 mpn/sparc64/ultrasparct3/mode1o.asm
--- a/mpn/sparc64/ultrasparct3/mode1o.asm	Mon Apr 15 23:00:14 2013 +0200
+++ b/mpn/sparc64/ultrasparct3/mode1o.asm	Mon Apr 15 17:42:20 2013 -0700
@@ -41,22 +41,7 @@
 	srlx	d, 1, %g1
 	and	%g1, 127, %g1
 
-ifdef(`PIC',`
-	rd	%pc, %g3
-	sethi	%hi(_GLOBAL_OFFSET_TABLE_+4), %g4
-	add	%g4, %lo(_GLOBAL_OFFSET_TABLE_+8), %g4
-	add	%g3, %g4, %g4
-	sethi	%hi(binvert_limb_table), %g2
-	or	%g2, %lo(binvert_limb_table), %g2
-	ldx	[%g4+%g2], %g2
-',`
-	sethi	%hh(binvert_limb_table), %g3
-	or	%g3, %hm(binvert_limb_table), %g3
-	sllx	%g3, 32, %g3
-	sethi	%lm(binvert_limb_table), %g2
-	add	%g3, %g2, %g3
-	or	%g3, %lo(binvert_limb_table), %g2
-')
+	LEA64(binvert_limb_table, g2, g4)
 	ldub	[%g2+%g1], %g1
 	add	%g1, %g1, %g2
 	mulx	%g1, %g1, %g1


More information about the gmp-devel mailing list