Port-powerpc archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Use of r31 on the powerpc/booke:mpc85xx architecture

On 10 Sep, 2012, at 12:11 , Scislowicz, Adam wrote:
> Yes, I was still using -fno-omit-frame-pointer when I experienced the issue, 
> perhaps it is responsible. I will try to reproduce shortly with different 
> build flags. Thank you for the response, I need to read the PPC ABI as I 
> haven't yet which is why I was unsure of the register allocations and 
> googling got me the incorrect answer the first time. Also I am not yet 
> familiar with good practices regarding gcc flags for the P2020 or more 
> generally powerpc. Most of my time has been spent on x86 and ARM thus far.
> Understood wrt stmw/lwm, was misreading the inline assembly wrt counting 
> colons and PPC ASM wasn't fresh in my mind, context switch in progress ;)

Note, though, that it isn't perfectly clear what the PPC ABI is.

The original PPC ELF ABI supplement, e.g. here


allowed r31 to optionally be dedicated to holding "environmental
pointers", whatever that is.  I suspect the option you are using
makes gcc dedicate r31 to this, probably to make alloca() a bit
cheaper (likely at the expense of making everything which doesn't
use alloca() a bit more expensive).

This option was unique to that ABI spec.  The (older) PowerOpen ABI,
used by AIX, specified r31 as a normal, callee-saved register, as
did the PowerPC "Embedded ABI" here:


More recently there has been work to unify the "desktop" and
"embedded" ABIs into one, e.g. here


and that work also removes the option of using r31 as anything
other than a normal, non-volatile register.  And, finally, the
(related) 64 bit ELF ABI, here


has never special-cased r31 either.

So while the original PPC ELF ABI provided the option of using r31 for
a dedicated function this was probably a bad idea (as you've discovered
the PowerPC instruction set has several useful instructions which
are hardwired to use r31, so dedicating r31 to some function gets in the
way of using those instructions) and the option has been removed in newer
work.  If -fno-omit-frame-pointer is making gcc special-case r31 then
you probably shouldn't use that flag.  It causes gcc to generate code
that doesn't conform to the most recent version of the PPC ABI and
makes it harder to use certain features of the PPC instruction set.

Dennis Ferguson

Home | Main Index | Thread Index | Old Index