summaryrefslogtreecommitdiff
path: root/src/core/core_timing.cpp
diff options
context:
space:
mode:
authorGravatar Lioncash2018-05-03 07:53:05 -0400
committerGravatar Lioncash2018-05-03 08:00:15 -0400
commit9f3641755e9a49c5869582f4be4a45a93c4ab247 (patch)
tree04d1f976cecc96768215422e285c9069cc263302 /src/core/core_timing.cpp
parentMerge pull request #431 from lioncash/fmt (diff)
downloadyuzu-9f3641755e9a49c5869582f4be4a45a93c4ab247.tar.gz
yuzu-9f3641755e9a49c5869582f4be4a45a93c4ab247.tar.xz
yuzu-9f3641755e9a49c5869582f4be4a45a93c4ab247.zip
core_timing: Don't include the log header in core timing's header
Avoids propagating logging macros and facilities to files that may not need them. This also allows hiding an internal constant.
Diffstat (limited to 'src/core/core_timing.cpp')
-rw-r--r--src/core/core_timing.cpp52
1 files changed, 51 insertions, 1 deletions
diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp
index 91c93e01f..dc1d8668f 100644
--- a/src/core/core_timing.cpp
+++ b/src/core/core_timing.cpp
@@ -6,6 +6,7 @@
6 6
7#include <algorithm> 7#include <algorithm>
8#include <cinttypes> 8#include <cinttypes>
9#include <limits>
9#include <mutex> 10#include <mutex>
10#include <string> 11#include <string>
11#include <tuple> 12#include <tuple>
@@ -57,7 +58,8 @@ static u64 event_fifo_id;
57// to the event_queue by the emu thread 58// to the event_queue by the emu thread
58static Common::MPSCQueue<Event, false> ts_queue; 59static Common::MPSCQueue<Event, false> ts_queue;
59 60
60static constexpr int MAX_SLICE_LENGTH = 20000; 61constexpr int MAX_SLICE_LENGTH = 20000;
62constexpr u64 MAX_VALUE_TO_MULTIPLY = std::numeric_limits<s64>::max() / BASE_CLOCK_RATE;
61 63
62static s64 idled_cycles; 64static s64 idled_cycles;
63 65
@@ -70,6 +72,54 @@ static EventType* ev_lost = nullptr;
70 72
71static void EmptyTimedCallback(u64 userdata, s64 cyclesLate) {} 73static void EmptyTimedCallback(u64 userdata, s64 cyclesLate) {}
72 74
75s64 usToCycles(s64 us) {
76 if (us / 1000000 > MAX_VALUE_TO_MULTIPLY) {
77 NGLOG_ERROR(Core_Timing, "Integer overflow, use max value");
78 return std::numeric_limits<s64>::max();
79 }
80 if (us > MAX_VALUE_TO_MULTIPLY) {
81 NGLOG_DEBUG(Core_Timing, "Time very big, do rounding");
82 return BASE_CLOCK_RATE * (us / 1000000);
83 }
84 return (BASE_CLOCK_RATE * us) / 1000000;
85}
86
87s64 usToCycles(u64 us) {
88 if (us / 1000000 > MAX_VALUE_TO_MULTIPLY) {
89 NGLOG_ERROR(Core_Timing, "Integer overflow, use max value");
90 return std::numeric_limits<s64>::max();
91 }
92 if (us > MAX_VALUE_TO_MULTIPLY) {
93 NGLOG_DEBUG(Core_Timing, "Time very big, do rounding");
94 return BASE_CLOCK_RATE * static_cast<s64>(us / 1000000);
95 }
96 return (BASE_CLOCK_RATE * static_cast<s64>(us)) / 1000000;
97}
98
99s64 nsToCycles(s64 ns) {
100 if (ns / 1000000000 > MAX_VALUE_TO_MULTIPLY) {
101 NGLOG_ERROR(Core_Timing, "Integer overflow, use max value");
102 return std::numeric_limits<s64>::max();
103 }
104 if (ns > MAX_VALUE_TO_MULTIPLY) {
105 NGLOG_DEBUG(Core_Timing, "Time very big, do rounding");
106 return BASE_CLOCK_RATE * (ns / 1000000000);
107 }
108 return (BASE_CLOCK_RATE * ns) / 1000000000;
109}
110
111s64 nsToCycles(u64 ns) {
112 if (ns / 1000000000 > MAX_VALUE_TO_MULTIPLY) {
113 NGLOG_ERROR(Core_Timing, "Integer overflow, use max value");
114 return std::numeric_limits<s64>::max();
115 }
116 if (ns > MAX_VALUE_TO_MULTIPLY) {
117 NGLOG_DEBUG(Core_Timing, "Time very big, do rounding");
118 return BASE_CLOCK_RATE * (static_cast<s64>(ns) / 1000000000);
119 }
120 return (BASE_CLOCK_RATE * static_cast<s64>(ns)) / 1000000000;
121}
122
73EventType* RegisterEvent(const std::string& name, TimedCallback callback) { 123EventType* RegisterEvent(const std::string& name, TimedCallback callback) {
74 // check for existing type with same name. 124 // check for existing type with same name.
75 // we want event type names to remain unique so that we can use them for serialization. 125 // we want event type names to remain unique so that we can use them for serialization.