summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service/time/clock_types.h
diff options
context:
space:
mode:
authorMorph <39850852+Morph1984@users.noreply.github.com>2023-04-23 06:09:49 +0200
committerMorph <39850852+Morph1984@users.noreply.github.com>2023-06-08 03:44:42 +0200
commit9dcc7bde8bb05dbc62fa196bcbe1484762e66917 (patch)
tree0fe9233f208999ec2ac64b38afb96a3ae21661b3 /src/core/hle/service/time/clock_types.h
parentcore_timing: Use CNTPCT as the guest CPU tick (diff)
downloadyuzu-9dcc7bde8bb05dbc62fa196bcbe1484762e66917.tar
yuzu-9dcc7bde8bb05dbc62fa196bcbe1484762e66917.tar.gz
yuzu-9dcc7bde8bb05dbc62fa196bcbe1484762e66917.tar.bz2
yuzu-9dcc7bde8bb05dbc62fa196bcbe1484762e66917.tar.lz
yuzu-9dcc7bde8bb05dbc62fa196bcbe1484762e66917.tar.xz
yuzu-9dcc7bde8bb05dbc62fa196bcbe1484762e66917.tar.zst
yuzu-9dcc7bde8bb05dbc62fa196bcbe1484762e66917.zip
Diffstat (limited to '')
-rw-r--r--src/core/hle/service/time/clock_types.h13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/core/hle/service/time/clock_types.h b/src/core/hle/service/time/clock_types.h
index e6293ffb9..9fc01ea90 100644
--- a/src/core/hle/service/time/clock_types.h
+++ b/src/core/hle/service/time/clock_types.h
@@ -3,6 +3,8 @@
#pragma once
+#include <ratio>
+
#include "common/common_funcs.h"
#include "common/common_types.h"
#include "common/uuid.h"
@@ -74,18 +76,19 @@ static_assert(std::is_trivially_copyable_v<ContinuousAdjustmentTimePoint>,
/// https://switchbrew.org/wiki/Glue_services#TimeSpanType
struct TimeSpanType {
s64 nanoseconds{};
- static constexpr s64 ns_per_second{1000000000ULL};
s64 ToSeconds() const {
- return nanoseconds / ns_per_second;
+ return nanoseconds / std::nano::den;
}
static TimeSpanType FromSeconds(s64 seconds) {
- return {seconds * ns_per_second};
+ return {seconds * std::nano::den};
}
- static TimeSpanType FromTicks(u64 ticks, u64 frequency) {
- return FromSeconds(static_cast<s64>(ticks) / static_cast<s64>(frequency));
+ template <u64 Frequency>
+ static TimeSpanType FromTicks(u64 ticks) {
+ using TicksToNSRatio = std::ratio<std::nano::den, Frequency>;
+ return {static_cast<s64>(ticks * TicksToNSRatio::num / TicksToNSRatio::den)};
}
};
static_assert(sizeof(TimeSpanType) == 8, "TimeSpanType is incorrect size");