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?

Posted on 2003-01-18 08:46:17 by kairon
The pause instruction ?
Posted on 2003-01-18 10:37:42 by Axial
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.
Posted on 2003-01-18 10:40:03 by kairon
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.
Posted on 2003-01-18 11:02:01 by f0dder
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.


Thanks :alright:
Posted on 2003-01-18 12:26:09 by kairon
"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

Posted on 2003-01-18 16:29:20 by lingo12
This, of course, is entirely different from Hiroshimator's PAWS instruction.
Posted on 2003-01-18 17:07:50 by iblis
Other names for spin-wait loop:

Spin lock
Busy wait
Wait loop
Posted on 2003-01-20 15:55:09 by tenkey
polled waiting. ick ;)
Posted on 2003-01-20 15:55:48 by f0dder