syntax for clobber list with inline assembly

4 messages, 3 authors, 2005-06-08 · open the first message on its own page

syntax for clobber list with inline assembly

From: Chris Friesen <hidden>
Date: 2005-06-07 14:49:15

I'm writing some inline assembly for ppc.  To specify that r3 is used, I 
know I need to list it in the clobbered list.

When doing this, do I specify it as "3" or "r3", or are both valid?

Thanks,

Chris

Re: syntax for clobber list with inline assembly

From: Segher Boessenkool <hidden>
Date: 2005-06-07 15:00:45

I'm writing some inline assembly for ppc.  To specify that r3 is used, 
I know I need to list it in the clobbered list.

When doing this, do I specify it as "3" or "r3", or are both valid?
Both work.


Segher

Re: syntax for clobber list with inline assembly

From: Hollis Blanchard <hidden>
Date: 2005-06-08 01:03:01

On Jun 7, 2005, at 10:00 AM, Segher Boessenkool wrote:
quoted
I'm writing some inline assembly for ppc.  To specify that r3 is 
used, I know I need to list it in the clobbered list.

When doing this, do I specify it as "3" or "r3", or are both valid?
Both work.
But it should be said that much better style is to let the compiler 
choose registers for you, i.e. don't hardcode register numbers at all. 
For example (well, it's contrived, but I hope you get the idea):

	int out;
	asm("mfmsr r3\n"
		"ori %0, r3, 0x1\n"
		: "=r"(out)
		:
		: "r3");

would be better written as

	int out, tmp;
	asm("mfmsr %1\n"
		"ori %0, %1, 0x1\n"
		: "=r"(out),  "=r"(tmp)
		:
		: );

Be careful about using "r" constraints when dealing with instructions 
that treat r0 as a special case, such as addi or lwz (use "b" instead).

Also be careful about gcc arranging outputs and inputs in the same 
register; it looks different when you're writing "%0" and "%1" in your 
assembly, but it's not.

Inline assembly is very subtle. If you mess up your constraints now, 
you might never know until you rebuild with a different compiler 
version and things fall apart.

-Hollis

Re: syntax for clobber list with inline assembly

From: Chris Friesen <hidden>
Date: 2005-06-08 21:40:08

Hollis Blanchard wrote:
But it should be said that much better style is to let the compiler 
choose registers for you, i.e. don't hardcode register numbers at all. 
For example (well, it's contrived, but I hope you get the idea):
Certainly that would be the normal case.

In this particular case I'm writing some code to test whether my 
function to flush/clear the entire cache is properly working.

It uses self-modifying code, and I've got some instructions using r3 
hardcoded as hex.  Thus the specific use of r3.

Chris
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help