kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* extended asm and register clobbers
       [not found] <51575344.6010305@yahoo.com>
@ 2013-03-31  3:25 ` ishare
  0 siblings, 0 replies; only message in thread
From: ishare @ 2013-03-31  3:25 UTC (permalink / raw)
  To: kernelnewbies

On Sat, Mar 30, 2013 at 02:04:04PM -0700, dw 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."
> 
> 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"
>       );
>     }
> 
     It is probably because the compile finds the input will modify some regs before 
     save its value , in case its value is important for others .      
    
     try to save original edi on stack ,then use it ,then pop it ,like recovering from an irq.
   
> 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).
> 
> 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?
> 
> dw

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2013-03-31  3:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <51575344.6010305@yahoo.com>
2013-03-31  3:25 ` extended asm and register clobbers ishare

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).