Re: Optimization with inline assembly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2017-08-15 14:24 +0800, Xi Ruoyao wrote:
> In your code:
> 
>     asm(
>             "addl $1,(%1)"
>             : "=r"(res)
>             : "rdi"(z)
>             : "memory"
>     );
> 
> "res" is an unused output variable.  So GCC just optimize it away. You
> should use "asm volatile".

And I think it's better to rewrite it:

    asm( "addl $1, (%0)" :: "rdi"(z) : memory );

It would eliminate the unused variable res.
-- 
Xi Ruoyao <ryxi@xxxxxxxxxxxxxxxxx>
School of Aerospace Science and Technology, Xidian University



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux