[PATCH v2] Support powerpc64le-linux platform

Ulrich Weigand uweigand at de.ibm.com
Mon Dec 9 16:16:40 UTC 2013


Torbjorn Granlund wrote:
> Ulrich Weigand <Ulrich.Weigand at de.ibm.com> writes:
>   > Is the setting of of a TOC pointer unconditionally really needed
>   > (presumably for a call from another shlib including the main program)
>   > even for leaf functions which also don't use the TOC?
>   
>   If a function does not use the TOC (either explicitly or implicitly
>   e.g. because it performs a function call), then we do not need to
>   set it up in the prolog.  However, since there was just a single
>   PROLOGUE macro, it seemed the safe course to set it always.
>   
>   Now, if we know for sure that none of the functions needs a TOC,
>   we can omit it completely.  Or else, we could introduce two versions
>   of the PROLOGUE macro, and let each function choose the right one.
>   
> We have for other machines allowed an optional 2nd argument for
> PROLOGUE.
> 
>   I'm not sure if this is really worth the effort though: it makes
>   a difference only if the function is called externally (from another
>   shared library or via function pointer).  Aren't those routines
>   mostly called locally anyway?  Local calls will bypass the TOC
>   setup automatically anyway.
>   
> It will help time-critical end-user programs which call documented mpn
> functions directly.
> 
> Some asm files do use the TOC (typically mode1o.asm, invert_limb.asm,
> mod_1_[1234].asm, gcd_1.asm).
> 
> I'd suggest using PROLOGUE(fn,toc) for the latter functions, and
> PROLOGUE(fn) for other functions.
> 
> For the v1 ABI, I assume we cannot be clever about this.

No, for the v1 ABI it is the caller's responsibility to set up r2,
and the caller doesn't know whether the callee actually requires it.
This is one of the areas where the v2 ABI allows for an optimization
that was not possible with the v1 ABI.

I've now implemented your suggestion to add an optional 'toc' parameter,
modeled after the alpha 'gp' parameter.  I think I got all places where
this needs to be added; in general, I've not found any direct use of r2
in assembler code, except for those that come in via use of the LEA(L)
or CALL macros.

When building for the v1 ABI, the 'toc' parameter is simply ignored.
I've had to likewise change PROLOGUE_cpu for darwin and aix to accept
and ignore the 'toc' parameter.

Re-tested on powerpc64le-linux, powerpc64-linux, and powerpc64-ibm-aix
with no regressions.  I don't have a Darwin system to test on,
unfortunately, but since the change is identical to the AIX change,
it seems unlikely to be broken ...

Does this look OK?

>   > Is there a way we could test powerpc64le-linux or the new abi?  We try
>   > to have (automated) tests for every ABI which we claim to be supporting.
>   
>   Right now there is no base OS for powerpc64le-linux that you could
>   install readily, and there's also no easy way to get a machine to
>   run this on.  I'm sure once we're a bit farther along, we'll try
>   to make a powerpc64le-linux test machine available, e.g. in the
>   GCC compile farm.
>   
> I usually simulate GMP test systems.

OK, in that case the base OS question remains.  Right now, it seems
the easiest choice is to use the openSUSE experimental build; they
already have a (small) install image ready to run.  See "Run It":
https://en.opensuse.org/openSUSE:PowerLE


Bye,
Ulrich


ChangeLog:

2013-12-09  Ulrich Weigand  <Ulrich.Weigand at de.ibm.com>

	* configure.ac: Check for ELFv2 ABI on PowerPC.
	* mpn/powerpc64/elf.m4: Set assembler ABI version for ELFv2
	and use appropriate PROLOGUE_cpu/EPILOGUE_cpu sequences.
	Support optional 'toc' parameter to PROLOGUE_cpu.
	* mpn/powerpc64/aix.m4: Allow (and ignore) optional
	'toc' parameter to PROLOGUE_cpu.
	* mpn/powerpc64/darwin.m4: Likewise.

	* mpn/powerpc64/mode64/dive_1.asm (mpn_divexact_1): Add 'toc'
	parameter to PROLOGUE.
	* mpn/powerpc64/mode64/divrem_1.asm (mpn_divrem_1): Likewise.
	* mpn/powerpc64/mode64/divrem_2.asm (mpn_divrem_2): Likewise.
	* mpn/powerpc64/mode64/gcd_1.asm (mpn_gcd_1): Likewise.
	* mpn/powerpc64/mode64/invert_limb.asm (mpn_invert_limb): Likewise.
	* mpn/powerpc64/mode64/mod_1_1.asm (mpn_mod_1_1p_cps): Likewise.
	* mpn/powerpc64/mode64/mod_1_4.asm (mpn_mod_1s_4p_cps): Likewise.
	* mpn/powerpc64/mode64/mode1o.asm (mpn_modexact_1c_odd): Likewise.
	* mpn/powerpc64/mode64/p7/gcd_1.asm (mpn_gcd_1): Likewise.
	* mpn/powerpc64/p6/lshift.asm (mpn_lshift): Likewise.
	* mpn/powerpc64/p6/lshiftc.asm (mpn_lshiftc): Likewise.
	* mpn/powerpc64/p6/rshift.asm (mpn_rshift): Likewise.
	* mpn/powerpc64/vmx/popcount.asm (mpn_popcount): Likewise.


diff -r 52ba2a0e7ff8 configure.ac
--- a/configure.ac	Sat Dec 07 12:56:14 2013 +0100
+++ b/configure.ac	Mon Dec 09 15:58:17 2013 +0100
@@ -3504,6 +3504,14 @@
       GMP_ASM_POWERPC_PIC_ALWAYS
       GMP_ASM_POWERPC_R_REGISTERS
       GMP_INCLUDE_MPN(powerpc32/powerpc-defs.m4)
+
+      # Check for Linux ELFv2 ABI
+      AC_EGREP_CPP(yes,
+[#if _CALL_ELF == 2
+yes
+#endif],
+      [GMP_DEFINE_RAW(["define(<ELFv2_ABI>)"])])
+
       case $host in
         *-*-aix*)
 	  case $ABI in
diff -r 52ba2a0e7ff8 mpn/powerpc64/elf.m4
--- a/mpn/powerpc64/elf.m4	Sat Dec 07 12:56:14 2013 +0100
+++ b/mpn/powerpc64/elf.m4	Mon Dec 09 15:58:17 2013 +0100
@@ -18,15 +18,33 @@
 dnl  You should have received a copy of the GNU Lesser General Public License
 dnl  along with the GNU MP Library.  If not, see https://www.gnu.org/licenses/.
 
-define(`ASM_START',`')
+define(`ASM_START',
+`ifdef(`ELFv2_ABI',
+`
+	.abiversion 2
+')')
 
-dnl  Called: PROLOGUE_cpu(GSYM_PREFIX`'foo)
+dnl  Called: PROLOGUE_cpu(GSYM_PREFIX`'foo[,toc])
 dnl          EPILOGUE_cpu(GSYM_PREFIX`'foo)
 dnl
 
 define(`PROLOGUE_cpu',
-m4_assert_numargs(1)
-	`
+m4_assert_numargs_range(1,2)
+`ifelse(`$2',toc,,
+`ifelse(`$2',,,`m4_error(`Unrecognised PROLOGUE parameter')')')dnl
+ifdef(`ELFv2_ABI',
+`
+	.globl	$1
+	.type	$1, @function
+	.section	".text"
+	.align	5
+$1:
+ifelse(`$2',toc,`
+0:	addis	2, 12, (.TOC.-0b)@ha
+	addi	2, 2, (.TOC.-0b)@l
+	.localentry $1, .-$1
+',)
+',`
 	.globl	$1
 	.globl	.$1
 	.section	".opd","aw"
@@ -37,11 +55,16 @@
 	.type	.$1, @function
 	.section	".text"
 	.align	5
-.$1:')
+.$1:
+')')
 
 define(`EPILOGUE_cpu',
 m4_assert_numargs(1)
-`	.size	.$1, .-.$1')
+`ifdef(`ELFv2_ABI',`
+	.size	$1, .-$1
+',`
+	.size	.$1, .-.$1
+')')
 
 define(`TOC_ENTRY', `')
 
diff -r 52ba2a0e7ff8 mpn/powerpc64/aix.m4
--- a/mpn/powerpc64/aix.m4	Sat Dec 07 12:56:14 2013 +0100
+++ b/mpn/powerpc64/aix.m4	Mon Dec 09 15:58:17 2013 +0100
@@ -22,14 +22,15 @@
 	`.machine	"any"
 	.toc')
 
-dnl  Called: PROLOGUE_cpu(GSYM_PREFIX`'foo)
+dnl  Called: PROLOGUE_cpu(GSYM_PREFIX`'foo[,toc])
 dnl          EPILOGUE_cpu(GSYM_PREFIX`'foo)
 dnl
 dnl  Don't want ELF style .size in the epilogue.
 
 define(`PROLOGUE_cpu',
-m4_assert_numargs(1)
-	`
+m4_assert_numargs_range(1,2)
+`ifelse(`$2',toc,,
+`ifelse(`$2',,,`m4_error(`Unrecognised PROLOGUE parameter')')')dnl
 	.globl	$1
 	.globl	.$1
 	.csect	[DS], 3
diff -r 52ba2a0e7ff8 mpn/powerpc64/darwin.m4
--- a/mpn/powerpc64/darwin.m4	Sat Dec 07 12:56:14 2013 +0100
+++ b/mpn/powerpc64/darwin.m4	Mon Dec 09 15:58:17 2013 +0100
@@ -20,15 +20,17 @@
 
 define(`ASM_START',`')
 
-dnl  Called: PROLOGUE_cpu(GSYM_PREFIX`'foo)
+dnl  Called: PROLOGUE_cpu(GSYM_PREFIX`'foo[,toc])
 dnl          EPILOGUE_cpu(GSYM_PREFIX`'foo)
 dnl
 
 define(`DARWIN')
 
 define(`PROLOGUE_cpu',
-m4_assert_numargs(1)
-`	.text
+m4_assert_numargs_range(1,2)
+`ifelse(`$2',toc,,
+`ifelse(`$2',,,`m4_error(`Unrecognised PROLOGUE parameter')')')dnl
+	.text
 	.globl	$1
 	.align	5
 $1:')
diff -r 52ba2a0e7ff8 mpn/powerpc64/mode64/dive_1.asm
--- a/mpn/powerpc64/mode64/dive_1.asm	Sat Dec 07 12:56:14 2013 +0100
+++ b/mpn/powerpc64/mode64/dive_1.asm	Mon Dec 09 15:58:17 2013 +0100
@@ -42,7 +42,7 @@
 
 EXTERN(binvert_limb_table)
 
-PROLOGUE(mpn_divexact_1)
+PROLOGUE(mpn_divexact_1,toc)
 	addic.	n, n, -1
 	ld	r12, 0(up)
 	bne	cr0, L(2)
diff -r 52ba2a0e7ff8 mpn/powerpc64/mode64/divrem_1.asm
--- a/mpn/powerpc64/mode64/divrem_1.asm	Sat Dec 07 12:56:14 2013 +0100
+++ b/mpn/powerpc64/mode64/divrem_1.asm	Mon Dec 09 15:58:17 2013 +0100
@@ -45,7 +45,7 @@
 
 EXTERN_FUNC(mpn_invert_limb)
 
-PROLOGUE(mpn_divrem_1)
+PROLOGUE(mpn_divrem_1,toc)
 
 	mfcr	r12
 	add.	r10, r6, r4
diff -r 52ba2a0e7ff8 mpn/powerpc64/mode64/divrem_2.asm
--- a/mpn/powerpc64/mode64/divrem_2.asm	Sat Dec 07 12:56:14 2013 +0100
+++ b/mpn/powerpc64/mode64/divrem_2.asm	Mon Dec 09 15:58:17 2013 +0100
@@ -42,7 +42,7 @@
 
 EXTERN_FUNC(mpn_invert_limb)
 
-PROLOGUE(mpn_divrem_2)
+PROLOGUE(mpn_divrem_2,toc)
 	mflr	r0
 	std	r23, -72(r1)
 	std	r24, -64(r1)
diff -r 52ba2a0e7ff8 mpn/powerpc64/mode64/gcd_1.asm
--- a/mpn/powerpc64/mode64/gcd_1.asm	Sat Dec 07 12:56:14 2013 +0100
+++ b/mpn/powerpc64/mode64/gcd_1.asm	Mon Dec 09 15:58:17 2013 +0100
@@ -36,7 +36,7 @@
 EXTERN_FUNC(mpn_modexact_1c_odd)
 
 ASM_START()
-PROLOGUE(mpn_gcd_1)
+PROLOGUE(mpn_gcd_1,toc)
 	mflr	r0
 	std	r30, -16(r1)
 	std	r31, -8(r1)
diff -r 52ba2a0e7ff8 mpn/powerpc64/mode64/invert_limb.asm
--- a/mpn/powerpc64/mode64/invert_limb.asm	Sat Dec 07 12:56:14 2013 +0100
+++ b/mpn/powerpc64/mode64/invert_limb.asm	Mon Dec 09 15:58:17 2013 +0100
@@ -27,7 +27,7 @@
 C POWER7                66
 
 ASM_START()
-PROLOGUE(mpn_invert_limb)
+PROLOGUE(mpn_invert_limb,toc)
 	LEAL(	r12, approx_tab)
 	srdi	r9, r3, 32
 	rlwinm	r9, r9, 10, 23, 30	C (d >> 55) & 0x1fe
diff -r 52ba2a0e7ff8 mpn/powerpc64/mode64/mod_1_1.asm
--- a/mpn/powerpc64/mode64/mod_1_1.asm	Sat Dec 07 12:56:14 2013 +0100
+++ b/mpn/powerpc64/mode64/mod_1_1.asm	Mon Dec 09 15:58:17 2013 +0100
@@ -106,7 +106,7 @@
 	blr
 EPILOGUE()
 
-PROLOGUE(mpn_mod_1_1p_cps)
+PROLOGUE(mpn_mod_1_1p_cps,toc)
 	mflr	r0
 	std	r29, -24(r1)
 	std	r30, -16(r1)
diff -r 52ba2a0e7ff8 mpn/powerpc64/mode64/mod_1_4.asm
--- a/mpn/powerpc64/mode64/mod_1_4.asm	Sat Dec 07 12:56:14 2013 +0100
+++ b/mpn/powerpc64/mode64/mod_1_4.asm	Mon Dec 09 15:58:17 2013 +0100
@@ -186,7 +186,7 @@
 	b	L(10)
 EPILOGUE()
 
-PROLOGUE(mpn_mod_1s_4p_cps)
+PROLOGUE(mpn_mod_1s_4p_cps,toc)
 	mflr	r0
 	std	r29, -24(r1)
 	std	r30, -16(r1)
diff -r 52ba2a0e7ff8 mpn/powerpc64/mode64/mode1o.asm
--- a/mpn/powerpc64/mode64/mode1o.asm	Sat Dec 07 12:56:14 2013 +0100
+++ b/mpn/powerpc64/mode64/mode1o.asm	Mon Dec 09 15:58:17 2013 +0100
@@ -41,7 +41,7 @@
 
 EXTERN(binvert_limb_table)
 
-PROLOGUE(mpn_modexact_1c_odd)
+PROLOGUE(mpn_modexact_1c_odd,toc)
 	addic.	n, n, -1		C set carry as side effect
 	ld	r8, 0(up)
 	bne	cr0, L(2)
diff -r 52ba2a0e7ff8 mpn/powerpc64/mode64/p7/gcd_1.asm
--- a/mpn/powerpc64/mode64/p7/gcd_1.asm	Sat Dec 07 12:56:14 2013 +0100
+++ b/mpn/powerpc64/mode64/p7/gcd_1.asm	Mon Dec 09 15:58:17 2013 +0100
@@ -36,7 +36,7 @@
 EXTERN_FUNC(mpn_modexact_1c_odd)
 
 ASM_START()
-PROLOGUE(mpn_gcd_1)
+PROLOGUE(mpn_gcd_1,toc)
 	mflr	r0
 	std	r30, -16(r1)
 	std	r31, -8(r1)
diff -r 52ba2a0e7ff8 mpn/powerpc64/p6/lshift.asm
--- a/mpn/powerpc64/p6/lshift.asm	Sat Dec 07 12:56:14 2013 +0100
+++ b/mpn/powerpc64/p6/lshift.asm	Mon Dec 09 15:58:17 2013 +0100
@@ -41,7 +41,7 @@
 define(`rp',  `r7')
 
 ASM_START()
-PROLOGUE(mpn_lshift)
+PROLOGUE(mpn_lshift,toc)
 
 ifdef(`HAVE_ABI_mode32',`
 	rldicl	n, n, 0,32		C FIXME: avoid this zero extend
diff -r 52ba2a0e7ff8 mpn/powerpc64/p6/lshiftc.asm
--- a/mpn/powerpc64/p6/lshiftc.asm	Sat Dec 07 12:56:14 2013 +0100
+++ b/mpn/powerpc64/p6/lshiftc.asm	Mon Dec 09 15:58:17 2013 +0100
@@ -41,7 +41,7 @@
 define(`rp',  `r7')
 
 ASM_START()
-PROLOGUE(mpn_lshiftc)
+PROLOGUE(mpn_lshiftc,toc)
 
 ifdef(`HAVE_ABI_mode32',`
 	rldicl	n, n, 0,32		C FIXME: avoid this zero extend
diff -r 52ba2a0e7ff8 mpn/powerpc64/p6/rshift.asm
--- a/mpn/powerpc64/p6/rshift.asm	Sat Dec 07 12:56:14 2013 +0100
+++ b/mpn/powerpc64/p6/rshift.asm	Mon Dec 09 15:58:17 2013 +0100
@@ -41,7 +41,7 @@
 define(`rp',  `r7')
 
 ASM_START()
-PROLOGUE(mpn_rshift)
+PROLOGUE(mpn_rshift,toc)
 
 ifdef(`HAVE_ABI_mode32',`
 	rldicl	n, n, 0,32		C FIXME: avoid this zero extend
diff -r 52ba2a0e7ff8 mpn/powerpc64/vmx/popcount.asm
--- a/mpn/powerpc64/vmx/popcount.asm	Sat Dec 07 12:56:14 2013 +0100
+++ b/mpn/powerpc64/vmx/popcount.asm	Mon Dec 09 15:58:17 2013 +0100
@@ -55,7 +55,7 @@
 define(`LIMBS_CHUNK_THRES', 0x1001)
 
 ASM_START()
-PROLOGUE(mpn_popcount)
+PROLOGUE(mpn_popcount,toc)
 	mfspr	r10, 256
 	oris	r0, r10, 0xfffc		C Set VRSAVE bit 0-13
 	mtspr	256, r0



-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  Ulrich.Weigand at de.ibm.com



More information about the gmp-devel mailing list