Optimization with inline assembly

Xi Ruoyao ryxi@stu.xidian.edu.cn
Tue Aug 15 06:44:00 GMT 2017


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@stu.xidian.edu.cn>
School of Aerospace Science and Technology, Xidian University



More information about the Gcc-help mailing list