mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-01-15 11:25:13 +00:00
411449cd51
Some checks are pending
Reuse / reuse (push) Waiting to run
Clang Format / clang-format (push) Waiting to run
Linux-Qt / build (push) Waiting to run
Linux / build (push) Waiting to run
macOS-Qt / build (push) Waiting to run
macOS / build (push) Waiting to run
Windows-Qt / build (push) Waiting to run
Windows / build (push) Waiting to run
55 lines
1.1 KiB
C++
55 lines
1.1 KiB
C++
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#pragma once
|
|
|
|
#include "common/arch.h"
|
|
|
|
#ifdef _MSC_VER
|
|
#include <intrin.h>
|
|
#endif
|
|
|
|
#include "common/types.h"
|
|
|
|
namespace Common {
|
|
|
|
#ifdef _MSC_VER
|
|
__forceinline static u64 FencedRDTSC() {
|
|
#ifdef ARCH_X86_64
|
|
_mm_lfence();
|
|
_ReadWriteBarrier();
|
|
const u64 result = __rdtsc();
|
|
_mm_lfence();
|
|
_ReadWriteBarrier();
|
|
return result;
|
|
#else
|
|
#error "Missing FencedRDTSC() implementation for target CPU architecture."
|
|
#endif
|
|
}
|
|
#else
|
|
static inline u64 FencedRDTSC() {
|
|
#ifdef ARCH_X86_64
|
|
u64 eax;
|
|
u64 edx;
|
|
asm volatile("lfence\n\t"
|
|
"rdtsc\n\t"
|
|
"lfence\n\t"
|
|
: "=a"(eax), "=d"(edx));
|
|
return (edx << 32) | eax;
|
|
#elif defined(ARCH_ARM64)
|
|
u64 ret;
|
|
asm volatile("isb\n\t"
|
|
"mrs %0, cntvct_el0\n\t"
|
|
"isb\n\t"
|
|
: "=r"(ret)::"memory");
|
|
return ret;
|
|
#else
|
|
#error "Missing FencedRDTSC() implementation for target CPU architecture."
|
|
#endif
|
|
}
|
|
#endif
|
|
|
|
u64 EstimateRDTSCFrequency();
|
|
|
|
} // namespace Common
|