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