summaryrefslogtreecommitdiff
path: root/src/common/wall_clock.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/wall_clock.cpp')
-rw-r--r--src/common/wall_clock.cpp17
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 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <cstdint>
6
5#include "common/uint128.h" 7#include "common/uint128.h"
6#include "common/wall_clock.h" 8#include "common/wall_clock.h"
7 9
@@ -18,7 +20,9 @@ using base_time_point = std::chrono::time_point<base_timer>;
18class StandardWallClock final : public WallClock { 20class StandardWallClock final : public WallClock {
19public: 21public:
20 explicit StandardWallClock(u64 emulated_cpu_frequency_, u64 emulated_clock_frequency_) 22 explicit StandardWallClock(u64 emulated_cpu_frequency_, u64 emulated_clock_frequency_)
21 : WallClock(emulated_cpu_frequency_, emulated_clock_frequency_, false) { 23 : WallClock(emulated_cpu_frequency_, emulated_clock_frequency_, false),
24 emulated_clock_factor{GetFixedPoint64Factor(emulated_clock_frequency, 1000000000)},
25 emulated_cpu_factor{GetFixedPoint64Factor(emulated_cpu_frequency, 1000000000)} {
22 start_time = base_timer::now(); 26 start_time = base_timer::now();
23 } 27 }
24 28
@@ -41,16 +45,11 @@ public:
41 } 45 }
42 46
43 u64 GetClockCycles() override { 47 u64 GetClockCycles() override {
44 std::chrono::nanoseconds time_now = GetTimeNS(); 48 return MultiplyHigh(GetTimeNS().count(), emulated_clock_factor);
45 const u128 temporary =
46 Common::Multiply64Into128(time_now.count(), emulated_clock_frequency);
47 return Common::Divide128On32(temporary, 1000000000).first;
48 } 49 }
49 50
50 u64 GetCPUCycles() override { 51 u64 GetCPUCycles() override {
51 std::chrono::nanoseconds time_now = GetTimeNS(); 52 return MultiplyHigh(GetTimeNS().count(), emulated_cpu_factor);
52 const u128 temporary = Common::Multiply64Into128(time_now.count(), emulated_cpu_frequency);
53 return Common::Divide128On32(temporary, 1000000000).first;
54 } 53 }
55 54
56 void Pause([[maybe_unused]] bool is_paused) override { 55 void Pause([[maybe_unused]] bool is_paused) override {
@@ -59,6 +58,8 @@ public:
59 58
60private: 59private:
61 base_time_point start_time; 60 base_time_point start_time;
61 const u64 emulated_clock_factor;
62 const u64 emulated_cpu_factor;
62}; 63};
63 64
64#ifdef ARCHITECTURE_x86_64 65#ifdef ARCHITECTURE_x86_64