Optimization practice xor OR mov

There are two snippets of codes after optimized by the compiler with levels 1 and 3:

(This code is responsible for "return 0" in the body of the main function!)

case 1:

movl	$0, %eax

case 2:

xorl	%eax, %eax

Case 2 is optimized by GCC with level 3, which is definitely more efficient than case 1.

WHY?

This is because the more work of decoding the immediate number 0 in case 1 makes it inefficient [1].


  1. https://qa.1r1g.com/sf/ask/4066329221/ ↩︎

posted @ 2023-01-12 20:32  44636346  阅读(16)  评论(0)    收藏  举报