What is the best practice to write a cross platform implementation of the x86 pause instruction? I am planning to use it in a busy spinning loop in a C++ 11 project.
Does this intrinsic do the right thing even when the native processor does not support the x86 pause instruction?
Yes, the pause instruction is encoded as F3 90. A pre Pentium 4 processor which does not know about this instruction will decode it as:
REP NOP
That is just a ordinary NOP
with a useless prefix-byte. The processor will wait a cycle or two and then continue without altering the processor state in any way. You will not get the performance and power benefits from using PAUSE
but the program will still work as expected.
Fun fact: REP NOP
was even legal on the 8086 released roughly 35 years ago. That's what I call backward compatibility.