Skip to content

<xatomic.h>: Consider adding _mm_pause on x86/x64 #680

@AlexGuteniev

Description

@AlexGuteniev

I'm referring to this part:

STL/stl/inc/xatomic.h

Lines 26 to 40 in 260cfaf

#if defined(_M_CEE_PURE) || defined(_M_IX86) || defined(_M_X64)
#define _INTRIN_RELAXED(x) x
#define _INTRIN_ACQUIRE(x) x
#define _INTRIN_RELEASE(x) x
#define _INTRIN_ACQ_REL(x) x
#define _YIELD_PROCESSOR()
#elif defined(_M_ARM) || defined(_M_ARM64)
#define _INTRIN_RELAXED(x) _CONCAT(x, _nf)
#define _INTRIN_ACQUIRE(x) _CONCAT(x, _acq)
#define _INTRIN_RELEASE(x) _CONCAT(x, _rel)
// We don't have interlocked intrinsics for acquire-release ordering, even on
// ARM32/ARM64, so fall back to sequentially consistent.
#define _INTRIN_ACQ_REL(x) x
#define _YIELD_PROCESSOR() __yield()

In particular, this line:

#define _YIELD_PROCESSOR()

In "winnt.h" it is defined as follows:
#define YieldProcessor _mm_pause

In documentation on YieldProcessor use of pause instruction is documented:

This macro can be called on all processor platforms where Windows is supported, but it has no effect on some platforms. The definition varies from platform to platform. The following are some definitions of this macro in Winnt.h:

#define YieldProcessor() __asm { rep nop }
#define YieldProcessor _mm_pause
#define YieldProcessor __yield

Other synchronization libraries also make use of pause instruction.

@BillyONeal explained in #613 (comment):

The answer I've heard from folks that supposedly know better is "never _mm_pause ever" -- that macro was defined long before my time but it was defined as empty for x86/x64 and I don't think we would want to change that without extremely strong profiling evidence that it was a good idea.

Though I understand that there are some folks that know something, it all highly suspicious that this STL is the only library I know that avoids pause.

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixedSomething works now, yay!performanceMust go faster

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions