summaryrefslogtreecommitdiffstats
path: root/src/common/x64/rdtsc.h
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2023-06-22 06:12:46 +0200
committerGitHub <noreply@github.com>2023-06-22 06:12:46 +0200
commite3122c5b468fd59b7eded5a3a7300643d05616bc (patch)
tree3fe4c2c0bea83f3bb8849ef8839b9520873d41c2 /src/common/x64/rdtsc.h
parentMerge pull request #10777 from liamwhite/no-barrier (diff)
parentnvdisp: Fix SingleCore frametime reporting (diff)
downloadyuzu-e3122c5b468fd59b7eded5a3a7300643d05616bc.tar
yuzu-e3122c5b468fd59b7eded5a3a7300643d05616bc.tar.gz
yuzu-e3122c5b468fd59b7eded5a3a7300643d05616bc.tar.bz2
yuzu-e3122c5b468fd59b7eded5a3a7300643d05616bc.tar.lz
yuzu-e3122c5b468fd59b7eded5a3a7300643d05616bc.tar.xz
yuzu-e3122c5b468fd59b7eded5a3a7300643d05616bc.tar.zst
yuzu-e3122c5b468fd59b7eded5a3a7300643d05616bc.zip
Diffstat (limited to 'src/common/x64/rdtsc.h')
-rw-r--r--src/common/x64/rdtsc.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/common/x64/rdtsc.h b/src/common/x64/rdtsc.h
new file mode 100644
index 000000000..0ec4f52f9
--- /dev/null
+++ b/src/common/x64/rdtsc.h
@@ -0,0 +1,37 @@
+// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+
+#ifdef _MSC_VER
+#include <intrin.h>
+#endif
+
+#include "common/common_types.h"
+
+namespace Common::X64 {
+
+#ifdef _MSC_VER
+__forceinline static u64 FencedRDTSC() {
+ _mm_lfence();
+ _ReadWriteBarrier();
+ const u64 result = __rdtsc();
+ _mm_lfence();
+ _ReadWriteBarrier();
+ return result;
+}
+#else
+static inline u64 FencedRDTSC() {
+ u64 eax;
+ u64 edx;
+ asm volatile("lfence\n\t"
+ "rdtsc\n\t"
+ "lfence\n\t"
+ : "=a"(eax), "=d"(edx));
+ return (edx << 32) | eax;
+}
+#endif
+
+u64 EstimateRDTSCFrequency();
+
+} // namespace Common::X64