Relative performance of x86 inc vs. add instruction

前端 未结 4 1635
无人共我
无人共我 2020-12-01 17:05

Quick question, assuming beforehand

mov eax, 0

which is more efficient?

inc eax
inc eax

or

add         


        
4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-01 17:39

    If you ever wanna know raw performance stats of x86 instructions, see Dr Agner Fogs listings (volume 4 to be exact). As for the part about compilers, thats dependent on the compiler's code generator, and not something you should rely on too much.

    on a side note: I find it funny/ironic that in a question about performance, you used MOV EAX,0 to zero a register instead of XOR EAX,EAX :P (and if MOV EAX,0 was done beforehand, the fastest variant would be to remove the inc's and add's and just MOV EAX,2).

提交回复
热议问题