diff options
author | bunnei <bunneidev@gmail.com> | 2021-02-15 23:51:43 +0100 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2021-02-15 23:51:43 +0100 |
commit | 592a64991873273679fb9315775581c4a2fe5815 (patch) | |
tree | 0fc0ae121ffb09569951d6d7563ddac727f90b50 | |
parent | common: Merge uint128 to a single header file with inlines. (diff) | |
download | yuzu-592a64991873273679fb9315775581c4a2fe5815.tar yuzu-592a64991873273679fb9315775581c4a2fe5815.tar.gz yuzu-592a64991873273679fb9315775581c4a2fe5815.tar.bz2 yuzu-592a64991873273679fb9315775581c4a2fe5815.tar.lz yuzu-592a64991873273679fb9315775581c4a2fe5815.tar.xz yuzu-592a64991873273679fb9315775581c4a2fe5815.tar.zst yuzu-592a64991873273679fb9315775581c4a2fe5815.zip |
-rw-r--r-- | src/common/wall_clock.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/common/wall_clock.cpp b/src/common/wall_clock.cpp index a8c143f85..1545993bd 100644 --- a/src/common/wall_clock.cpp +++ b/src/common/wall_clock.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include <cstdint> + #include "common/uint128.h" #include "common/wall_clock.h" @@ -18,7 +20,9 @@ using base_time_point = std::chrono::time_point<base_timer>; class StandardWallClock final : public WallClock { public: explicit StandardWallClock(u64 emulated_cpu_frequency_, u64 emulated_clock_frequency_) - : WallClock(emulated_cpu_frequency_, emulated_clock_frequency_, false) { + : WallClock(emulated_cpu_frequency_, emulated_clock_frequency_, false), + emulated_clock_factor{GetFixedPoint64Factor(emulated_clock_frequency, 1000000000)}, + emulated_cpu_factor{GetFixedPoint64Factor(emulated_cpu_frequency, 1000000000)} { start_time = base_timer::now(); } @@ -41,16 +45,11 @@ public: } u64 GetClockCycles() override { - std::chrono::nanoseconds time_now = GetTimeNS(); - const u128 temporary = - Common::Multiply64Into128(time_now.count(), emulated_clock_frequency); - return Common::Divide128On32(temporary, 1000000000).first; + return MultiplyHigh(GetTimeNS().count(), emulated_clock_factor); } u64 GetCPUCycles() override { - std::chrono::nanoseconds time_now = GetTimeNS(); - const u128 temporary = Common::Multiply64Into128(time_now.count(), emulated_cpu_frequency); - return Common::Divide128On32(temporary, 1000000000).first; + return MultiplyHigh(GetTimeNS().count(), emulated_cpu_factor); } void Pause([[maybe_unused]] bool is_paused) override { @@ -59,6 +58,8 @@ public: private: base_time_point start_time; + const u64 emulated_clock_factor; + const u64 emulated_cpu_factor; }; #ifdef ARCHITECTURE_x86_64 |