Hello, I have a few questions about the pause instruction, it tells the processor the following code is a spin loop for performance reasons (makes things faster), but what is a spin loop?Is it the same as a loop?
Also, would the pause instruction be best used at the beginning of a "spin" loop or before a JMP to the spin loop?
Thanks.
Also, would the pause instruction be best used at the beginning of a "spin" loop or before a JMP to the spin loop?
Thanks.
The pause instruction ?
B.206 PAUSE: Spin Loop Hint
PAUSE ; F3 90
PAUSE provides a hint to the processor that the following code is a spin loop. This improves processor performance by bypassing possible memory order violations. On older processors, this instruction operates as a NOP.
Taken from http://alien.dowling.edu/~rohit/nasmdocb.html#section-B.206 and works in FASM as well.
PAUSE ; F3 90
PAUSE provides a hint to the processor that the following code is a spin loop. This improves processor performance by bypassing possible memory order violations. On older processors, this instruction operates as a NOP.
Taken from http://alien.dowling.edu/~rohit/nasmdocb.html#section-B.206 and works in FASM as well.
hm, "spin loop". if you're doing normal win32 coding and don't have specific reasons, Sleep()ing is probably the smartest thing to do. Dunno about the instruction though. "the following code". First guess would be putting it as the first instruction in the loop.
Ok, I found some good documentation on this from Intel, seems to go well with Hyper-Threading, for anyone who's interested on what it said, here:
Use the PAUSE Instruction to Optimize Code
Intel recommends that software writers always use the PAUSE instruction in spin-wait loops.
Starting with the Intel? Pentium? 4 processor, this recommendation was made for the benefit of power savings. Executing a PAUSE in a spin-wait loop forces the spin-wait to finish one iteration of the loop before starting the next iteration. Halting the spin-wait loop reduces consumption of non-productive resources - and thus power.
With a Hyper-Threading Technology processor, using the PAUSE instruction optimizes processing of two threads. Pausing the spin-wait loop frees more resources for the other processor, allowing faster completion of its thread.
http://cedar.intel.com/media/training/hyper_threading_intro/tutorial/index.htm
Thanks :alright:
Use the PAUSE Instruction to Optimize Code
Intel recommends that software writers always use the PAUSE instruction in spin-wait loops.
Starting with the Intel? Pentium? 4 processor, this recommendation was made for the benefit of power savings. Executing a PAUSE in a spin-wait loop forces the spin-wait to finish one iteration of the loop before starting the next iteration. Halting the spin-wait loop reduces consumption of non-productive resources - and thus power.
With a Hyper-Threading Technology processor, using the PAUSE instruction optimizes processing of two threads. Pausing the spin-wait loop frees more resources for the other processor, allowing faster completion of its thread.
http://cedar.intel.com/media/training/hyper_threading_intro/tutorial/index.htm
Thanks :alright:
"Tuning Suggestion 1.
Rarely, a performance problem may be noted due to executing data on a
code page as instructions.
The only condition where this is very likely to happen is following an
indirect branch that is not resident in the trace cache. Only if a performance problem is clearly
due to this problem, try moving the data elsewhere, or inserting an illegal opcode or a pause
instruction immediately following the indirect branch. The latter two alternatives may degrade
performance in some circumstances."
from Intel Pentium 4 and Intel Xeon? Processor Optimization - Reference Manual
Regards,
Lingo
Rarely, a performance problem may be noted due to executing data on a
code page as instructions.
The only condition where this is very likely to happen is following an
indirect branch that is not resident in the trace cache. Only if a performance problem is clearly
due to this problem, try moving the data elsewhere, or inserting an illegal opcode or a pause
instruction immediately following the indirect branch. The latter two alternatives may degrade
performance in some circumstances."
from Intel Pentium 4 and Intel Xeon? Processor Optimization - Reference Manual
Regards,
Lingo
This, of course, is entirely different from Hiroshimator's PAWS instruction.
Other names for spin-wait loop:
Spin lock
Busy wait
Wait loop
Spin lock
Busy wait
Wait loop
polled waiting. ick ;)