In the following pseudo-code:
if (rdtscp supported by hardware) {
Invoke "rdtscp" instruction
} else {
Invoke "rdtsc" instruction
}
Let's say the CPU does not support the rdtscp
instruction and so we fallback to the else statement.
If CPU mispredicts the branch, is it possible for the instruction pipeline to try to execute rdtscp
and throw an Illgal Instruction
error?
It is explicitly documented for the #UD trap (Invalid Opcode Execution) in the Intel Processor Manuals, Volume 3A, chapter 6.15:
In Intel 64 and IA-32 processors that implement out-of-order execution microarchitectures, this exception is not generated until an attempt is made to retire the result of executing an invalid instruction; that is, decoding and speculatively attempting to execute an invalid opcode does not generate this exception. Likewise, in the Pentium processor and earlier IA-32 processors, this exception is not generated as the result of prefetching and preliminary decoding of an invalid instruction.