This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PPC GCC Inline assembly help



Michael Meissner-6 wrote:
> 
> 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@linux.vnet.ibm.com
> 
> 

Basically, I am building a tool to test the registers, so I need to know
exactly what register I am accessing into. The first method are ok, but then
I need to write by hand all the registers one by one. By the mean of second
method, I've planned to set the register by using function arguments, so the
constraints immediate value is what the passed variables have. Do you have
the best solution in mind regarding this matters? and please explain or give
me the link, so I can go through it.

regards,



-- 
View this message in context: http://www.nabble.com/PPC-GCC-Inline-assembly-help-tp23403005p23479610.html
Sent from the gcc - Help mailing list archive at Nabble.com.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]