4 ms·
Nit, but specifically on this: > call 1f > > 1: <next instruction> It's worth noting that "call $+5" degrades performance if used improperly. Consider:
by hun3 3y ago
Nit, but specifically on this:
> call 1f
>
> 1: <next instruction>
It's worth noting that "call $+5" degrades performance if used improperly. Consider:
call 1f
1:
pop %eax
See the problem? (Hint: it's branch prediction)
That's right! The CPU has its own idea of an approximate "call stack" (a.k.a. return stack buffer), which it uses to predict branch target for RETs.
Note that the POP doesn't count as a "return," so it usually does not pop from the return stack buffer at all. In this case, the CPU confidently mispredicts the branch when the next matching RET gets queued into the pipeline, sometimes severly degrading performance.
- russdill 3y agoA lot of the x86 code I look at is rather old.