On the x86, can someone confirm, whether or not a zero displacement jump (i.e. a jump that doesn't alter the values in CS or IP) clears the Instruction Prefetch Queue?
A jump to the next statement that would have been executed anyways does clear the instruction prefetch queue on any Intel x86 CPU that has one. It was a common to do so in self-modifying code in order to ensure that modified code was actually executed. Intel has gone so far as to document using a jump as means to ensure that self-modified code gets executed correctly even on modern CPUs.
From Intel 64 and IA-32 Architectures Software Developer’s Manual Volume 3: System Programming Guide:
8.1.3 Handling Self- and Cross-Modifying Code
...
As processor microarchitectures become more complex and start to speculatively execute code ahead of the retirement point (as in P6 and more recent processor families), the rules regarding which code should execute, pre- or post-modification, become blurred. To write self-modifying code and ensure that it is compliant with current and future versions of the IA-32 architectures, use one of the following coding options:
(* OPTION 1 *) Store modified code (as data) into code segment; Jump to new code or an intermediate location; Execute new code;
(Option 2 is to use a serializing instruction instead of a jump, but these don't exist on early x86 CPUs.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With