This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: extended asm and register clobbers
- From: Ian Lance Taylor <iant at google dot com>
- To: dw <limegreensocks at yahoo dot com>
- Cc: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Sat, 30 Mar 2013 20:22:32 -0700
- Subject: Re: extended asm and register clobbers
- References: <51575344 dot 6010305 at yahoo dot com>
On Sat, Mar 30, 2013 at 2:04 PM, dw <limegreensocks@yahoo.com> wrote:
> I read this line from the docs:
>
> "If you refer to a particular hardware register from the assembler code, you
> probably have to list the register after the third colon to tell the
> compiler the register's value is modified."
Yes, but that is not necessary if the register is one of the outputs
of the asm.
> My own observation shows that this is true. However, attempting to add the
> register in question to the clobber list is returning a compile error.
>
> The asm (essentially memset):
>
> __CRT_INLINE VOID __stosb(PBYTE Dest, BYTE Data, SIZE_T Count)
> {
> __asm__
> (
> "cld; rep; stosb"
> :
> : "D" (Dest), "a" (Data), "c" (Count)
> : "edi", "memory", "cc"
> );
> }
>
> The error:
>
> error: can't find a register in class 'DIREG' while reloading 'asm'
> error: 'asm' operand has impossible constraints
>
> Without the edi clobber, this c++ code:
>
> __stosb((PBYTE)&c, 0, sizeof(c));
> __stosb((PBYTE)&c, 0, sizeof(c));
>
> generates this asm:
>
> 402cd3: cld
> 402cd4: rep stos BYTE PTR es:[rdi],al
> 402cd6: cld
> 402cd7: rep stos BYTE PTR es:[rdi],al
>
> Since rdi is not clobbered, gcc doesn't reload it between calls (likewise
> with rcx).
You need to tell GCC that the register is changed. But you can't do
it with a clobber, because then you can't use it as an input. So make
it an output.
> While I might be able to fake the compiler out by specifying outputs
> (probably need the volatile qualifier too), I don't really want to change
> Dest, I just want to use it as an input.
>
> What's the right way to go here?
Make it an output. You don't have to do anything with the value. You
just have to tell GCC that the value is changing.
Ian