diff options
| author | Morph <39850852+Morph1984@users.noreply.github.com> | 2023-06-28 01:35:16 -0400 |
|---|---|---|
| committer | Morph <39850852+Morph1984@users.noreply.github.com> | 2023-06-28 01:39:15 -0400 |
| commit | 037e683b94cfec4533118c9e05f98f6499dc973a (patch) | |
| tree | b80f91f05df4d70861d8b216e59a9f1ea5c707cd /src/common/x64/cpu_wait.cpp | |
| parent | 88efcaf44e19fa6de3a00c569d521b43b4422f8a (diff) | |
x64: cpu_wait: Implement MWAITX for non-MSVC compilers
Diffstat (limited to 'src/common/x64/cpu_wait.cpp')
| -rw-r--r-- | src/common/x64/cpu_wait.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/common/x64/cpu_wait.cpp b/src/common/x64/cpu_wait.cpp index ea16c84900..41d385f598 100644 --- a/src/common/x64/cpu_wait.cpp +++ b/src/common/x64/cpu_wait.cpp @@ -47,6 +47,16 @@ static void TPAUSE() { const auto edx = static_cast<u32>(tsc >> 32); asm volatile("tpause %0" : : "r"(RequestC02State), "d"(edx), "a"(eax)); } + +static void MWAITX() { + static constexpr auto EnableWaitTimeFlag = 1U << 1; + static constexpr auto RequestC1State = 0U; + + // monitor_var should be aligned to a cache line. + alignas(64) u64 monitor_var{}; + asm volatile("monitorx" : : "a"(&monitor_var), "c"(0), "d"(0)); + asm volatile("mwaitx" : : "a"(RequestC1State), "b"(PauseCycles), "c"(EnableWaitTimeFlag)); +} #endif void MicroSleep() { |
