Beware, Intel increased the stall for 'rep nop' in some recent cpu to IIRC about 200 cycles.
They even document that this might have a detrimental effect. It is basically far too long for the sort of thing it makes sense to busy-wait for.
Thanks for the info:) I will be beware of that when playing with 'rep nop' in newer x86 cpu.
See 8.4.7 Pause Latency in Skylake Microarchitecture in IntelĀ® 64 and IA-32 Architectures Optimization Reference Manual
The latency of PAUSE instruction in prior generation microarchitecture is about 10 cycles, whereas on Skylake microarchitecture it has been extended to as many as 140 cycles.
An earlier section does explain why you need pause though. One of its effects is to stop the cpu speculatively executing multiple iterations of the wait look - each with its own pending read of the memory location that is being looked at. Unwinding that isn't free - and was particularly expensive on P4 Netburst - what a surprise, they ran everything except benchmark looks very slowly.
David
- Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)