summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/arm64/native_clock.cpp24
-rw-r--r--src/common/arm64/native_clock.h10
-rw-r--r--src/common/atomic_ops.h79
-rw-r--r--src/common/common_types.h1
-rw-r--r--src/common/fs/file.h2
-rw-r--r--src/common/memory_detect.h2
-rw-r--r--src/common/overflow.h18
-rw-r--r--src/common/page_table.cpp34
-rw-r--r--src/common/settings.h13
-rw-r--r--src/common/settings_common.cpp2
-rw-r--r--src/common/settings_common.h2
-rw-r--r--src/common/time_zone.cpp12
-rw-r--r--src/common/uuid.h12
-rw-r--r--src/common/wall_clock.cpp32
-rw-r--r--src/common/wall_clock.h9
-rw-r--r--src/common/x64/native_clock.cpp26
-rw-r--r--src/common/x64/native_clock.h9
17 files changed, 133 insertions, 154 deletions
diff --git a/src/common/arm64/native_clock.cpp b/src/common/arm64/native_clock.cpp
index f437d7187..76ffb74ba 100644
--- a/src/common/arm64/native_clock.cpp
+++ b/src/common/arm64/native_clock.cpp
@@ -30,27 +30,27 @@ NativeClock::NativeClock() {
}
std::chrono::nanoseconds NativeClock::GetTimeNS() const {
- return std::chrono::nanoseconds{MultiplyHigh(GetHostTicksElapsed(), ns_cntfrq_factor)};
+ return std::chrono::nanoseconds{MultiplyHigh(GetUptime(), ns_cntfrq_factor)};
}
std::chrono::microseconds NativeClock::GetTimeUS() const {
- return std::chrono::microseconds{MultiplyHigh(GetHostTicksElapsed(), us_cntfrq_factor)};
+ return std::chrono::microseconds{MultiplyHigh(GetUptime(), us_cntfrq_factor)};
}
std::chrono::milliseconds NativeClock::GetTimeMS() const {
- return std::chrono::milliseconds{MultiplyHigh(GetHostTicksElapsed(), ms_cntfrq_factor)};
+ return std::chrono::milliseconds{MultiplyHigh(GetUptime(), ms_cntfrq_factor)};
}
-u64 NativeClock::GetCNTPCT() const {
- return MultiplyHigh(GetHostTicksElapsed(), guest_cntfrq_factor);
+s64 NativeClock::GetCNTPCT() const {
+ return MultiplyHigh(GetUptime(), guest_cntfrq_factor);
}
-u64 NativeClock::GetGPUTick() const {
- return MultiplyHigh(GetHostTicksElapsed(), gputick_cntfrq_factor);
+s64 NativeClock::GetGPUTick() const {
+ return MultiplyHigh(GetUptime(), gputick_cntfrq_factor);
}
-u64 NativeClock::GetHostTicksNow() const {
- u64 cntvct_el0 = 0;
+s64 NativeClock::GetUptime() const {
+ s64 cntvct_el0 = 0;
asm volatile("dsb ish\n\t"
"mrs %[cntvct_el0], cntvct_el0\n\t"
"dsb ish\n\t"
@@ -58,15 +58,11 @@ u64 NativeClock::GetHostTicksNow() const {
return cntvct_el0;
}
-u64 NativeClock::GetHostTicksElapsed() const {
- return GetHostTicksNow();
-}
-
bool NativeClock::IsNative() const {
return true;
}
-u64 NativeClock::GetHostCNTFRQ() {
+s64 NativeClock::GetHostCNTFRQ() {
u64 cntfrq_el0 = 0;
std::string_view board{""};
#ifdef ANDROID
diff --git a/src/common/arm64/native_clock.h b/src/common/arm64/native_clock.h
index a28b419f2..94bc1882e 100644
--- a/src/common/arm64/native_clock.h
+++ b/src/common/arm64/native_clock.h
@@ -17,17 +17,15 @@ public:
std::chrono::milliseconds GetTimeMS() const override;
- u64 GetCNTPCT() const override;
+ s64 GetCNTPCT() const override;
- u64 GetGPUTick() const override;
+ s64 GetGPUTick() const override;
- u64 GetHostTicksNow() const override;
-
- u64 GetHostTicksElapsed() const override;
+ s64 GetUptime() const override;
bool IsNative() const override;
- static u64 GetHostCNTFRQ();
+ static s64 GetHostCNTFRQ();
public:
using FactorType = unsigned __int128;
diff --git a/src/common/atomic_ops.h b/src/common/atomic_ops.h
index c18bb33c4..9bf6f2f81 100644
--- a/src/common/atomic_ops.h
+++ b/src/common/atomic_ops.h
@@ -15,25 +15,34 @@ namespace Common {
#if _MSC_VER
-[[nodiscard]] inline bool AtomicCompareAndSwap(volatile u8* pointer, u8 value, u8 expected) {
+template <typename T>
+[[nodiscard]] inline bool AtomicCompareAndSwap(T* pointer, T value, T expected);
+template <typename T>
+[[nodiscard]] inline bool AtomicCompareAndSwap(T* pointer, T value, T expected, T& actual);
+
+template <>
+[[nodiscard]] inline bool AtomicCompareAndSwap<u8>(u8* pointer, u8 value, u8 expected) {
const u8 result =
_InterlockedCompareExchange8(reinterpret_cast<volatile char*>(pointer), value, expected);
return result == expected;
}
-[[nodiscard]] inline bool AtomicCompareAndSwap(volatile u16* pointer, u16 value, u16 expected) {
+template <>
+[[nodiscard]] inline bool AtomicCompareAndSwap<u16>(u16* pointer, u16 value, u16 expected) {
const u16 result =
_InterlockedCompareExchange16(reinterpret_cast<volatile short*>(pointer), value, expected);
return result == expected;
}
-[[nodiscard]] inline bool AtomicCompareAndSwap(volatile u32* pointer, u32 value, u32 expected) {
+template <>
+[[nodiscard]] inline bool AtomicCompareAndSwap<u32>(u32* pointer, u32 value, u32 expected) {
const u32 result =
_InterlockedCompareExchange(reinterpret_cast<volatile long*>(pointer), value, expected);
return result == expected;
}
-[[nodiscard]] inline bool AtomicCompareAndSwap(volatile u64* pointer, u64 value, u64 expected) {
+template <>
+[[nodiscard]] inline bool AtomicCompareAndSwap<u64>(u64* pointer, u64 value, u64 expected) {
const u64 result = _InterlockedCompareExchange64(reinterpret_cast<volatile __int64*>(pointer),
value, expected);
return result == expected;
@@ -45,29 +54,32 @@ namespace Common {
reinterpret_cast<__int64*>(expected.data())) != 0;
}
-[[nodiscard]] inline bool AtomicCompareAndSwap(volatile u8* pointer, u8 value, u8 expected,
- u8& actual) {
+template <>
+[[nodiscard]] inline bool AtomicCompareAndSwap<u8>(u8* pointer, u8 value, u8 expected, u8& actual) {
actual =
_InterlockedCompareExchange8(reinterpret_cast<volatile char*>(pointer), value, expected);
return actual == expected;
}
-[[nodiscard]] inline bool AtomicCompareAndSwap(volatile u16* pointer, u16 value, u16 expected,
- u16& actual) {
+template <>
+[[nodiscard]] inline bool AtomicCompareAndSwap<u16>(u16* pointer, u16 value, u16 expected,
+ u16& actual) {
actual =
_InterlockedCompareExchange16(reinterpret_cast<volatile short*>(pointer), value, expected);
return actual == expected;
}
-[[nodiscard]] inline bool AtomicCompareAndSwap(volatile u32* pointer, u32 value, u32 expected,
- u32& actual) {
+template <>
+[[nodiscard]] inline bool AtomicCompareAndSwap<u32>(u32* pointer, u32 value, u32 expected,
+ u32& actual) {
actual =
_InterlockedCompareExchange(reinterpret_cast<volatile long*>(pointer), value, expected);
return actual == expected;
}
-[[nodiscard]] inline bool AtomicCompareAndSwap(volatile u64* pointer, u64 value, u64 expected,
- u64& actual) {
+template <>
+[[nodiscard]] inline bool AtomicCompareAndSwap<u64>(u64* pointer, u64 value, u64 expected,
+ u64& actual) {
actual = _InterlockedCompareExchange64(reinterpret_cast<volatile __int64*>(pointer), value,
expected);
return actual == expected;
@@ -91,23 +103,12 @@ namespace Common {
#else
-[[nodiscard]] inline bool AtomicCompareAndSwap(volatile u8* pointer, u8 value, u8 expected) {
- return __sync_bool_compare_and_swap(pointer, expected, value);
-}
-
-[[nodiscard]] inline bool AtomicCompareAndSwap(volatile u16* pointer, u16 value, u16 expected) {
- return __sync_bool_compare_and_swap(pointer, expected, value);
-}
-
-[[nodiscard]] inline bool AtomicCompareAndSwap(volatile u32* pointer, u32 value, u32 expected) {
+template <typename T>
+[[nodiscard]] inline bool AtomicCompareAndSwap(T* pointer, T value, T expected) {
return __sync_bool_compare_and_swap(pointer, expected, value);
}
-[[nodiscard]] inline bool AtomicCompareAndSwap(volatile u64* pointer, u64 value, u64 expected) {
- return __sync_bool_compare_and_swap(pointer, expected, value);
-}
-
-[[nodiscard]] inline bool AtomicCompareAndSwap(volatile u64* pointer, u128 value, u128 expected) {
+[[nodiscard]] inline bool AtomicCompareAndSwap(u64* pointer, u128 value, u128 expected) {
unsigned __int128 value_a;
unsigned __int128 expected_a;
std::memcpy(&value_a, value.data(), sizeof(u128));
@@ -115,31 +116,13 @@ namespace Common {
return __sync_bool_compare_and_swap((unsigned __int128*)pointer, expected_a, value_a);
}
-[[nodiscard]] inline bool AtomicCompareAndSwap(volatile u8* pointer, u8 value, u8 expected,
- u8& actual) {
+template <typename T>
+[[nodiscard]] inline bool AtomicCompareAndSwap(T* pointer, T value, T expected, T& actual) {
actual = __sync_val_compare_and_swap(pointer, expected, value);
return actual == expected;
}
-[[nodiscard]] inline bool AtomicCompareAndSwap(volatile u16* pointer, u16 value, u16 expected,
- u16& actual) {
- actual = __sync_val_compare_and_swap(pointer, expected, value);
- return actual == expected;
-}
-
-[[nodiscard]] inline bool AtomicCompareAndSwap(volatile u32* pointer, u32 value, u32 expected,
- u32& actual) {
- actual = __sync_val_compare_and_swap(pointer, expected, value);
- return actual == expected;
-}
-
-[[nodiscard]] inline bool AtomicCompareAndSwap(volatile u64* pointer, u64 value, u64 expected,
- u64& actual) {
- actual = __sync_val_compare_and_swap(pointer, expected, value);
- return actual == expected;
-}
-
-[[nodiscard]] inline bool AtomicCompareAndSwap(volatile u64* pointer, u128 value, u128 expected,
+[[nodiscard]] inline bool AtomicCompareAndSwap(u64* pointer, u128 value, u128 expected,
u128& actual) {
unsigned __int128 value_a;
unsigned __int128 expected_a;
@@ -151,7 +134,7 @@ namespace Common {
return actual_a == expected_a;
}
-[[nodiscard]] inline u128 AtomicLoad128(volatile u64* pointer) {
+[[nodiscard]] inline u128 AtomicLoad128(u64* pointer) {
unsigned __int128 zeros_a = 0;
unsigned __int128 result_a =
__sync_val_compare_and_swap((unsigned __int128*)pointer, zeros_a, zeros_a);
diff --git a/src/common/common_types.h b/src/common/common_types.h
index 0fc225aff..ae04c4d60 100644
--- a/src/common/common_types.h
+++ b/src/common/common_types.h
@@ -45,6 +45,7 @@ using f32 = float; ///< 32-bit floating point
using f64 = double; ///< 64-bit floating point
using VAddr = u64; ///< Represents a pointer in the userspace virtual address space.
+using DAddr = u64; ///< Represents a pointer in the device specific virtual address space.
using PAddr = u64; ///< Represents a pointer in the ARM11 physical address space.
using GPUVAddr = u64; ///< Represents a pointer in the GPU virtual address space.
diff --git a/src/common/fs/file.h b/src/common/fs/file.h
index 167c4d826..2e2396075 100644
--- a/src/common/fs/file.h
+++ b/src/common/fs/file.h
@@ -37,7 +37,7 @@ void OpenFileStream(FileStream& file_stream, const std::filesystem::path& path,
template <typename FileStream, typename Path>
void OpenFileStream(FileStream& file_stream, const Path& path, std::ios_base::openmode open_mode) {
if constexpr (IsChar<typename Path::value_type>) {
- file_stream.open(ToU8String(path), open_mode);
+ file_stream.open(std::filesystem::path{ToU8String(path)}, open_mode);
} else {
file_stream.open(std::filesystem::path{path}, open_mode);
}
diff --git a/src/common/memory_detect.h b/src/common/memory_detect.h
index a345e6d28..c8f239aed 100644
--- a/src/common/memory_detect.h
+++ b/src/common/memory_detect.h
@@ -18,4 +18,4 @@ struct MemoryInfo {
*/
[[nodiscard]] const MemoryInfo& GetMemInfo();
-} // namespace Common \ No newline at end of file
+} // namespace Common
diff --git a/src/common/overflow.h b/src/common/overflow.h
index 44d8e7e73..e184ead95 100644
--- a/src/common/overflow.h
+++ b/src/common/overflow.h
@@ -3,6 +3,7 @@
#pragma once
+#include <algorithm>
#include <type_traits>
#include "bit_cast.h"
@@ -19,4 +20,21 @@ inline T WrappingAdd(T lhs, T rhs) {
return BitCast<T>(lhs_u + rhs_u);
}
+template <typename T>
+ requires(std::is_integral_v<T> && std::is_signed_v<T>)
+inline bool CanAddWithoutOverflow(T lhs, T rhs) {
+#ifdef _MSC_VER
+ if (lhs >= 0 && rhs >= 0) {
+ return WrappingAdd(lhs, rhs) >= std::max(lhs, rhs);
+ } else if (lhs < 0 && rhs < 0) {
+ return WrappingAdd(lhs, rhs) <= std::min(lhs, rhs);
+ } else {
+ return true;
+ }
+#else
+ T res;
+ return !__builtin_add_overflow(lhs, rhs, &res);
+#endif
+}
+
} // namespace Common
diff --git a/src/common/page_table.cpp b/src/common/page_table.cpp
index 166dc3dce..85dc18c11 100644
--- a/src/common/page_table.cpp
+++ b/src/common/page_table.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/page_table.h"
+#include "common/scope_exit.h"
namespace Common {
@@ -11,29 +12,10 @@ PageTable::~PageTable() noexcept = default;
bool PageTable::BeginTraversal(TraversalEntry* out_entry, TraversalContext* out_context,
Common::ProcessAddress address) const {
- // Setup invalid defaults.
- out_entry->phys_addr = 0;
- out_entry->block_size = page_size;
- out_context->next_page = 0;
-
- // Validate that we can read the actual entry.
- const auto page = address / page_size;
- if (page >= backing_addr.size()) {
- return false;
- }
-
- // Validate that the entry is mapped.
- const auto phys_addr = backing_addr[page];
- if (phys_addr == 0) {
- return false;
- }
+ out_context->next_offset = GetInteger(address);
+ out_context->next_page = address / page_size;
- // Populate the results.
- out_entry->phys_addr = phys_addr + GetInteger(address);
- out_context->next_page = page + 1;
- out_context->next_offset = GetInteger(address) + page_size;
-
- return true;
+ return this->ContinueTraversal(out_entry, out_context);
}
bool PageTable::ContinueTraversal(TraversalEntry* out_entry, TraversalContext* context) const {
@@ -41,6 +23,12 @@ bool PageTable::ContinueTraversal(TraversalEntry* out_entry, TraversalContext* c
out_entry->phys_addr = 0;
out_entry->block_size = page_size;
+ // Regardless of whether the page was mapped, advance on exit.
+ SCOPE_EXIT({
+ context->next_page += 1;
+ context->next_offset += page_size;
+ });
+
// Validate that we can read the actual entry.
const auto page = context->next_page;
if (page >= backing_addr.size()) {
@@ -55,8 +43,6 @@ bool PageTable::ContinueTraversal(TraversalEntry* out_entry, TraversalContext* c
// Populate the results.
out_entry->phys_addr = phys_addr + context->next_offset;
- context->next_page = page + 1;
- context->next_offset += page_size;
return true;
}
diff --git a/src/common/settings.h b/src/common/settings.h
index 07dba53ab..16749ab68 100644
--- a/src/common/settings.h
+++ b/src/common/settings.h
@@ -419,9 +419,16 @@ struct Values {
linkage, false, "custom_rtc_enabled", Category::System, Specialization::Paired, true, true};
SwitchableSetting<s64> custom_rtc{
linkage, 0, "custom_rtc", Category::System, Specialization::Time,
- true, true, &custom_rtc_enabled};
- // Set on game boot, reset on stop. Seconds difference between current time and `custom_rtc`
- s64 custom_rtc_differential;
+ false, true, &custom_rtc_enabled};
+ SwitchableSetting<s64, true> custom_rtc_offset{linkage,
+ 0,
+ std::numeric_limits<int>::min(),
+ std::numeric_limits<int>::max(),
+ "custom_rtc_offset",
+ Category::System,
+ Specialization::Countable,
+ true,
+ true};
SwitchableSetting<bool> rng_seed_enabled{
linkage, false, "rng_seed_enabled", Category::System, Specialization::Paired, true, true};
SwitchableSetting<u32> rng_seed{
diff --git a/src/common/settings_common.cpp b/src/common/settings_common.cpp
index 5960b78aa..b90e3509c 100644
--- a/src/common/settings_common.cpp
+++ b/src/common/settings_common.cpp
@@ -35,7 +35,7 @@ bool BasicSetting::Save() const {
return save;
}
-bool BasicSetting::RuntimeModfiable() const {
+bool BasicSetting::RuntimeModifiable() const {
return runtime_modifiable;
}
diff --git a/src/common/settings_common.h b/src/common/settings_common.h
index 1a290ad77..987489e8a 100644
--- a/src/common/settings_common.h
+++ b/src/common/settings_common.h
@@ -186,7 +186,7 @@ public:
/**
* @returns true if the current setting can be changed while the guest is running.
*/
- [[nodiscard]] bool RuntimeModfiable() const;
+ [[nodiscard]] bool RuntimeModifiable() const;
/**
* @returns A unique number corresponding to the setting.
diff --git a/src/common/time_zone.cpp b/src/common/time_zone.cpp
index 69e728a9d..f77df604f 100644
--- a/src/common/time_zone.cpp
+++ b/src/common/time_zone.cpp
@@ -88,7 +88,17 @@ std::string FindSystemTimeZone() {
LOG_ERROR(Common, "Time zone {} not handled, defaulting to hour offset.", tz_index);
}
}
- return fmt::format("Etc/GMT{:s}{:d}", hours > 0 ? "-" : "+", std::abs(hours));
+
+ // For some reason the Etc/GMT times are reversed. GMT+6 contains -21600 as its offset,
+ // -6 hours instead of +6 hours, so these signs are purposefully reversed to fix it.
+ std::string postfix{""};
+ if (hours > 0) {
+ postfix = fmt::format("-{:d}", std::abs(hours));
+ } else if (hours < 0) {
+ postfix = fmt::format("+{:d}", std::abs(hours));
+ }
+
+ return fmt::format("Etc/GMT{:s}", postfix);
}
} // namespace Common::TimeZone
diff --git a/src/common/uuid.h b/src/common/uuid.h
index 7172ca165..81bfefbbb 100644
--- a/src/common/uuid.h
+++ b/src/common/uuid.h
@@ -12,9 +12,8 @@
namespace Common {
struct UUID {
- std::array<u8, 0x10> uuid{};
+ std::array<u8, 0x10> uuid;
- /// Constructs an invalid UUID.
constexpr UUID() = default;
/// Constructs a UUID from a reference to a 128 bit array.
@@ -34,14 +33,6 @@ struct UUID {
*/
explicit UUID(std::string_view uuid_string);
- ~UUID() = default;
-
- constexpr UUID(const UUID&) noexcept = default;
- constexpr UUID(UUID&&) noexcept = default;
-
- constexpr UUID& operator=(const UUID&) noexcept = default;
- constexpr UUID& operator=(UUID&&) noexcept = default;
-
/**
* Returns whether the stored UUID is valid or not.
*
@@ -121,6 +112,7 @@ struct UUID {
friend constexpr bool operator==(const UUID& lhs, const UUID& rhs) = default;
};
static_assert(sizeof(UUID) == 0x10, "UUID has incorrect size.");
+static_assert(std::is_trivial_v<UUID>);
/// An invalid UUID. This UUID has all its bytes set to 0.
constexpr UUID InvalidUUID = {};
diff --git a/src/common/wall_clock.cpp b/src/common/wall_clock.cpp
index 012fdc1e0..e14bf3e65 100644
--- a/src/common/wall_clock.cpp
+++ b/src/common/wall_clock.cpp
@@ -18,42 +18,40 @@ namespace Common {
class StandardWallClock final : public WallClock {
public:
- explicit StandardWallClock() : start_time{SteadyClock::Now()} {}
+ explicit StandardWallClock() {}
std::chrono::nanoseconds GetTimeNS() const override {
- return SteadyClock::Now() - start_time;
+ return std::chrono::duration_cast<std::chrono::nanoseconds>(
+ std::chrono::system_clock::now().time_since_epoch());
}
std::chrono::microseconds GetTimeUS() const override {
- return static_cast<std::chrono::microseconds>(GetHostTicksElapsed() / NsToUsRatio::den);
+ return std::chrono::duration_cast<std::chrono::microseconds>(
+ std::chrono::system_clock::now().time_since_epoch());
}
std::chrono::milliseconds GetTimeMS() const override {
- return static_cast<std::chrono::milliseconds>(GetHostTicksElapsed() / NsToMsRatio::den);
+ return std::chrono::duration_cast<std::chrono::milliseconds>(
+ std::chrono::system_clock::now().time_since_epoch());
}
- u64 GetCNTPCT() const override {
- return GetHostTicksElapsed() * NsToCNTPCTRatio::num / NsToCNTPCTRatio::den;
+ s64 GetCNTPCT() const override {
+ return GetUptime() * NsToCNTPCTRatio::num / NsToCNTPCTRatio::den;
}
- u64 GetGPUTick() const override {
- return GetHostTicksElapsed() * NsToGPUTickRatio::num / NsToGPUTickRatio::den;
+ s64 GetGPUTick() const override {
+ return GetUptime() * NsToGPUTickRatio::num / NsToGPUTickRatio::den;
}
- u64 GetHostTicksNow() const override {
- return static_cast<u64>(SteadyClock::Now().time_since_epoch().count());
- }
-
- u64 GetHostTicksElapsed() const override {
- return static_cast<u64>(GetTimeNS().count());
+ s64 GetUptime() const override {
+ return std::chrono::duration_cast<std::chrono::nanoseconds>(
+ std::chrono::steady_clock::now().time_since_epoch())
+ .count();
}
bool IsNative() const override {
return false;
}
-
-private:
- SteadyClock::time_point start_time;
};
std::unique_ptr<WallClock> CreateOptimalClock() {
diff --git a/src/common/wall_clock.h b/src/common/wall_clock.h
index f45d3d8c5..3a0c43909 100644
--- a/src/common/wall_clock.h
+++ b/src/common/wall_clock.h
@@ -29,16 +29,13 @@ public:
virtual std::chrono::milliseconds GetTimeMS() const = 0;
/// @returns The guest CNTPCT ticks since the construction of this clock.
- virtual u64 GetCNTPCT() const = 0;
+ virtual s64 GetCNTPCT() const = 0;
/// @returns The guest GPU ticks since the construction of this clock.
- virtual u64 GetGPUTick() const = 0;
+ virtual s64 GetGPUTick() const = 0;
/// @returns The raw host timer ticks since an indeterminate epoch.
- virtual u64 GetHostTicksNow() const = 0;
-
- /// @returns The raw host timer ticks since the construction of this clock.
- virtual u64 GetHostTicksElapsed() const = 0;
+ virtual s64 GetUptime() const = 0;
/// @returns Whether the clock directly uses the host's hardware clock.
virtual bool IsNative() const = 0;
diff --git a/src/common/x64/native_clock.cpp b/src/common/x64/native_clock.cpp
index 7d2a26bd9..d2d27fafe 100644
--- a/src/common/x64/native_clock.cpp
+++ b/src/common/x64/native_clock.cpp
@@ -8,39 +8,35 @@
namespace Common::X64 {
NativeClock::NativeClock(u64 rdtsc_frequency_)
- : start_ticks{FencedRDTSC()}, rdtsc_frequency{rdtsc_frequency_},
- ns_rdtsc_factor{GetFixedPoint64Factor(NsRatio::den, rdtsc_frequency)},
+ : rdtsc_frequency{rdtsc_frequency_}, ns_rdtsc_factor{GetFixedPoint64Factor(NsRatio::den,
+ rdtsc_frequency)},
us_rdtsc_factor{GetFixedPoint64Factor(UsRatio::den, rdtsc_frequency)},
ms_rdtsc_factor{GetFixedPoint64Factor(MsRatio::den, rdtsc_frequency)},
cntpct_rdtsc_factor{GetFixedPoint64Factor(CNTFRQ, rdtsc_frequency)},
gputick_rdtsc_factor{GetFixedPoint64Factor(GPUTickFreq, rdtsc_frequency)} {}
std::chrono::nanoseconds NativeClock::GetTimeNS() const {
- return std::chrono::nanoseconds{MultiplyHigh(GetHostTicksElapsed(), ns_rdtsc_factor)};
+ return std::chrono::nanoseconds{MultiplyHigh(GetUptime(), ns_rdtsc_factor)};
}
std::chrono::microseconds NativeClock::GetTimeUS() const {
- return std::chrono::microseconds{MultiplyHigh(GetHostTicksElapsed(), us_rdtsc_factor)};
+ return std::chrono::microseconds{MultiplyHigh(GetUptime(), us_rdtsc_factor)};
}
std::chrono::milliseconds NativeClock::GetTimeMS() const {
- return std::chrono::milliseconds{MultiplyHigh(GetHostTicksElapsed(), ms_rdtsc_factor)};
+ return std::chrono::milliseconds{MultiplyHigh(GetUptime(), ms_rdtsc_factor)};
}
-u64 NativeClock::GetCNTPCT() const {
- return MultiplyHigh(GetHostTicksElapsed(), cntpct_rdtsc_factor);
+s64 NativeClock::GetCNTPCT() const {
+ return MultiplyHigh(GetUptime(), cntpct_rdtsc_factor);
}
-u64 NativeClock::GetGPUTick() const {
- return MultiplyHigh(GetHostTicksElapsed(), gputick_rdtsc_factor);
+s64 NativeClock::GetGPUTick() const {
+ return MultiplyHigh(GetUptime(), gputick_rdtsc_factor);
}
-u64 NativeClock::GetHostTicksNow() const {
- return FencedRDTSC();
-}
-
-u64 NativeClock::GetHostTicksElapsed() const {
- return FencedRDTSC() - start_ticks;
+s64 NativeClock::GetUptime() const {
+ return static_cast<s64>(FencedRDTSC());
}
bool NativeClock::IsNative() const {
diff --git a/src/common/x64/native_clock.h b/src/common/x64/native_clock.h
index 334415eff..b2629b031 100644
--- a/src/common/x64/native_clock.h
+++ b/src/common/x64/native_clock.h
@@ -17,18 +17,15 @@ public:
std::chrono::milliseconds GetTimeMS() const override;
- u64 GetCNTPCT() const override;
+ s64 GetCNTPCT() const override;
- u64 GetGPUTick() const override;
+ s64 GetGPUTick() const override;
- u64 GetHostTicksNow() const override;
-
- u64 GetHostTicksElapsed() const override;
+ s64 GetUptime() const override;
bool IsNative() const override;
private:
- u64 start_ticks;
u64 rdtsc_frequency;
u64 ns_rdtsc_factor;