LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Hollis Blanchard <hollis@penguinppc.org>
To: Chris Friesen <cfriesen@nortel.com>
Cc: Linux PPC Dev <linuxppc-dev@ozlabs.org>
Subject: Re: syntax for clobber list with inline assembly
Date: Tue, 7 Jun 2005 20:02:57 -0500	[thread overview]
Message-ID: <455acab93dd9ab20cbbc1cff400f84e3@penguinppc.org> (raw)
In-Reply-To: <4b474e026a1d6040f1ec24466d8ff6a8@kernel.crashing.org>

On Jun 7, 2005, at 10:00 AM, Segher Boessenkool wrote:

>> 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

  reply	other threads:[~2005-06-08  1:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-07 14:49 syntax for clobber list with inline assembly Chris Friesen
2005-06-07 15:00 ` Segher Boessenkool
2005-06-08  1:02   ` Hollis Blanchard [this message]
2005-06-08 21:39     ` Chris Friesen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=455acab93dd9ab20cbbc1cff400f84e3@penguinppc.org \
    --to=hollis@penguinppc.org \
    --cc=cfriesen@nortel.com \
    --cc=linuxppc-dev@ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox