mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-06 12:00:17 +02:00
28 lines
982 B
C++
28 lines
982 B
C++
// SPDX-License-Identifier: MIT
|
|
#include <FEXCore/Utils/SpinWaitLock.h>
|
|
|
|
namespace FEXCore::Utils::SpinWaitLock {
|
|
#ifdef ARCHITECTURE_arm64
|
|
constexpr uint64_t NanosecondsInSecond = 1'000'000'000ULL;
|
|
|
|
static uint64_t GetCycleCounterFrequency() {
|
|
uint64_t Result {};
|
|
__asm("mrs %[Res], CNTFRQ_EL0" : [Res] "=r"(Result));
|
|
return Result;
|
|
}
|
|
|
|
static uint64_t CalculateCyclesPerNanosecond() {
|
|
// Snapdragon devices historically use a 19.2Mhz cycle counter frequency
|
|
// This means that the number of cycles per nanosecond ends up being 52.0833...
|
|
//
|
|
// ARMv8.6 and ARMv9.1 requires the cycle counter frequency to be 1Ghz.
|
|
// This means the number of cycles per nanosecond ends up being 1.
|
|
uint64_t CounterFrequency = GetCycleCounterFrequency();
|
|
return NanosecondsInSecond / CounterFrequency;
|
|
}
|
|
|
|
uint64_t CycleCounterFrequency = GetCycleCounterFrequency();
|
|
uint64_t CyclesPerNanosecond = CalculateCyclesPerNanosecond();
|
|
#endif
|
|
} // namespace FEXCore::Utils::SpinWaitLock
|