visual c++ - How do you use the pause assembly instruction in 64-bit C++ code? -


since inlined assembly not supported vc++ 2010 in 64-bit code, how pause x86-64 instruction code? there not appear intrinsic there many other common assembly instructions (e.g., __rdtsc(), __cpuid(), etc...).

on why side, want instruction busy wait use case, (hyperthreaded) cpu available other threads running on said cpu (see: performance insights @ intel.com). pause instruction helpful use case spin-lock implementations, can't understand why ms did not include intrinsic.

thanks

wow, hard problem track down, in case else needs x86-64 pause instruction:

the yieldprocessor() macro windows.h expands undocumented _mm_pause intrinsic, expands pause instruction in 32-bit , 64-bit code.

this undocumented, way, partial (and incorrect vc++ 2010 documentation) yieldprocessor() appearing in msdn.

here example of block of yieldprocessor() macros compiles into:

    19:     ::yieldprocessor(); 000000013fdb18a0 f3 90                pause       20:     ::yieldprocessor(); 000000013fdb18a2 f3 90                pause       21:     ::yieldprocessor(); 000000013fdb18a4 f3 90                pause       22:     ::yieldprocessor(); 000000013fdb18a6 f3 90                pause       23:     ::yieldprocessor(); 000000013fdb18a8 f3 90                pause   

by way, each pause instruction seems produce 9 cycle delay on nehalem architecture, on average (i.e., 3 ns on 3.3 ghz cpu).


Comments