4#include "native/isa_import.h"
8#include "native/targets.h"
30 concept waiter =
requires (
volatile void * p, std::uint32_t t) {
45 template <waiter W> hint_flatten
47 noexcept(
noexcept(!f(p)) &&
noexcept(W::monitor(p)) &&
noexcept(W::mwait(0))) hint_blocking {
48 [[assume(W::supported)]];
58 using timer_t = std::uint64_t;
61 [[gnu::target(
"mwaitx")]]
static void monitor(
volatile void * p)
noexcept;
64 [[gnu::target(
"mwaitx")]]
static void mwait(std::uint32_t timer = 0)
noexcept hint_blocking;
66 static const bool supported;
72 using timer_t = std::uint64_t;
75 [[gnu::target(
"waitpkg")]]
static void monitor(
volatile void * p)
noexcept;
78 [[gnu::target(
"waitpkg")]]
static std::uint8_t
mwait(std::uint64_t timer = 0)
noexcept hint_blocking;
80 static const bool supported;
87 template<isa<x86> Arch = NATIVE_BA
SELINE,
unsigned Control = 1>
88 requires(Arch.has(x86_feature::waitpkg) && Control < 2)
89 hint_inline hint_artificial hint_target(
"waitpkg")
90 std::uint8_t
tpause(
std::uint64_t deadline) noexcept hint_blocking {
91 return __builtin_ia32_tpause(Control, std::uint32_t(deadline >> 32),
92 std::uint32_t(deadline));
97 using timer_t = std::uint64_t;
99 hint_inline hint_artificial
static void monitor(
volatile void *)
noexcept {}
101 hint_inline hint_artificial
static void mwait(std::uint32_t = 0) noexcept hint_blocking { _mm_pause(); }
103 inline static constinit bool supported =
true;
115 noexcept(
noexcept(k.template operator()<
mwaitx>()) &&
116 noexcept(k.template
operator()<
umwait>()) &&
noexcept(k.template
operator()<
spin>())) {
117 if (mwaitx::supported)
return k.template operator()<
mwaitx>();
118 else if (umwait::supported)
return k.template operator()<
umwait>();
119 else return k.template operator()<
spin>();
129 _mm_monitorx(
const_cast<void *
>(p), 0, 0);
131 [[gnu::target(
"mwaitx")]]
void mwaitx::mwait(std::uint32_t timer)
noexcept hint_blocking {
132 _mm_mwaitx(0, 0, timer);
135 _umonitor(
const_cast<void *
>(p));
137 [[gnu::target(
"waitpkg")]] std::uint8_t
umwait::mwait(std::uint64_t timer)
noexcept hint_blocking {
138 return _umwait(1, timer);
146 const bool mwaitx::supported = classify_isa(wait_capabilities, x86_feature::mwaitx).admitted();
147 const bool umwait::supported = classify_isa(wait_capabilities, x86_feature::waitpkg).admitted();
154 using ::native::waiter;
156 using ::native::mwaitx;
157 using ::native::umwait;
159 using ::native::spin;
some way to wait for a value to change
std::uint8_t tpause(std::uint64_t deadline) noexcept hint_blocking
auto with_waiter(auto k) noexcept(noexcept(k.template operator()<mwaitx >()) &&noexcept(k.template operator()<umwait >()) &&noexcept(k.template operator()<spin >()))
finds an appropriate waiter for the current CPU Prefer MWAITX, then WAITPKG, otherwise PAUSE....
void wait_until(volatile auto *p, auto f) noexcept(noexcept(!f(p)) &&noexcept(W::monitor(p)) &&noexcept(W::mwait(0))) hint_blocking
Wait until a predicate holds about a given memory location.
static void monitor(volatile void *p) noexcept
static void mwait(std::uint32_t timer=0) noexcept hint_blocking
static void monitor(volatile void *p) noexcept
static std::uint8_t mwait(std::uint64_t timer=0) noexcept hint_blocking
Architecture-tagged vectors, register packs and supporting value types. Native arithmetic follows its...
x86_capabilities observe_x86_capabilities() noexcept
Capture CPUID and, only with XSAVE and OSXSAVE, XCR0. No ISA profile required.
Standard-library adaptations documented here for SIMD value types.
waiter using the MONITORX/MWAITX instruction feature
A universally supported x86 spin waiter using PAUSE; monitor is a no-op.
static void monitor(volatile void *) noexcept
Ignore the address; PAUSE waiting does not arm a hardware monitor.
static void mwait(std::uint32_t=0) noexcept hint_blocking
Issue one PAUSE, ignoring the timer; no sleep duration or memory ordering is promised.
waiter using the WAITPKG instruction feature