Re: PPC GCC Inline assembly help

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

 



On Wed, May 06, 2009 at 02:22:45AM -0700, eija_flight wrote:
> 
> Hello,
> 
> I'm using GCC inline assembly on PowerPc.
> 
> Below codes is works :
> 
> int reg_gpr()
> {
> int Rx = 0;
> 	__asm__ (
> 		"mr 31,%0\n"
> 		:
> 		:"i"(Rx)
> 		);
> }
> 
> But not with this one : 
> 
> reg_gpr(0);
> int reg_gpr(int Rx)
> {
> 	__asm__ (
> 		"mr 31,%0\n"
> 		:
> 		:"i"(Rx)
> 		);
> }
> 
> It will send error messages "impossible constraints in asm"
> Is there any other method to modify Rx value from outside functions? 

In general this will not work, because you are modifying a register (r31) that
the compiler is unaware of what you are doing.  Who knows what the compiler has
in r31 at the time of your move?  Even if you know right now for a given set of
switches, the next compiler revision may generate completely different code.

Also, you are not guaranteed that the compiler will inline reg_gpr (though
adding always_inline as an attribute will help).

To quote from the tag line of a USENET poster (Henry Spencer) from the past:
"If you lie to the compiler, the compiler will get its revenge".  Abusing GCC's
asms is certainly one way to hang yourself.

So, step back, and describe the problem you are trying to solve at a higher
level.  Why are you trying to get an arbitrary register?  If you are trying to
get a bunch of registers for printing a debugging dump, it might be better to
call an asm function that stores the preserved registers into a block.
Alternatively, using a "r" constraint in the asm, and letting the compiler pick
the register might be what you need, or binding a variable to a register.

-- 
Michael Meissner, IBM
4 Technology Place Drive, MS 2203A, Westford, MA, 01886, USA
meissner@xxxxxxxxxxxxxxxxxx

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux