This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: What registers are protected by "cc" in a clobberlist when using inline assembly?
- From: Jeffrey Walton <noloader at gmail dot com>
- To: Ian Lance Taylor <iant at google dot com>
- Cc: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Tue, 4 Feb 2014 18:03:45 -0500
- Subject: Re: What registers are protected by "cc" in a clobberlist when using inline assembly?
- Authentication-results: sourceware.org; auth=none
- References: <CAH8yC8m7oA2H5o5rrcV7anZUkjrid+XFKWx7gYDo=e8Z=dpw2A at mail dot gmail dot com> <CAKOQZ8yK4x7WXm1=jfEM5yFjsjW60RaHb0ubVsSo3uPbPdw6Zg at mail dot gmail dot com>
- Reply-to: noloader at gmail dot com
On Tue, Feb 4, 2014 at 4:55 PM, Ian Lance Taylor <iant@google.com> wrote:
> On Tue, Feb 4, 2014 at 1:16 PM, Jeffrey Walton <noloader@gmail.com> wrote:
>>
>> I'm having trouble locating information on the register(s) protected
>> by adding "cc" to a clobber list.
>>
>> Can anyone confirm (1) FLAGS/EFLAGS on x86/c64, and (2) CPSR on ARM?
>>
>> The reason I ask is I came across some code that sets the Carry Flag
>> (CF) on success, but "cc" was not specified in a clobber list:
>>
>> char rc;
>> unsigned int val;
>>
>> __asm__ volatile(
>> "rdrand %0 ; setc %1"
>> : "=r" (val), "=qm" (rc)
>> );
>>
>> // 1 = success, 0 = underflow
>> if(rc) {
>> // use val
>> ...
>> }
>>
>> So I'm trying to understand why "cc" was not specified.
>
> I'm not sure that explicitly clobbering "cc" has any effect on x86.
> For x86 GCC assumes that all asm statements clobber the flags
> register. See ix86_md_asm_clobbers in gcc/config/i386/i386.c.
>
> For ARM "cc" represents the internal representation of the condition
> code flags. It doesn't mean a specific register, but clobbering it
> will mean that GCC drops any information it is carrying about
> condition flags. Internally this is represented as a pseudo-register,
> CC_REGNUM.
Thanks Ian.
That's basically what others have told me without the reference to
ix86_md_asm_clobber.
Perhaps that would be a good topic to add to
http://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html.
Jeff