summaryrefslogtreecommitdiff
path: root/src/core/core_timing.h
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.h
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.h')
-rw-r--r--src/core/core_timing.h51
1 files changed, 4 insertions, 47 deletions
diff --git a/src/core/core_timing.h b/src/core/core_timing.h
index 9d3c1d05c..dc31124a8 100644
--- a/src/core/core_timing.h
+++ b/src/core/core_timing.h
@@ -18,17 +18,14 @@
18 */ 18 */
19 19
20#include <functional> 20#include <functional>
21#include <limits>
22#include <string> 21#include <string>
23#include "common/common_types.h" 22#include "common/common_types.h"
24#include "common/logging/log.h"
25 23
26namespace CoreTiming { 24namespace CoreTiming {
27 25
28// The below clock rate is based on Switch's clockspeed being widely known as 1.020GHz 26// The below clock rate is based on Switch's clockspeed being widely known as 1.020GHz
29// The exact value used is of course unverified. 27// The exact value used is of course unverified.
30constexpr u64 BASE_CLOCK_RATE = 1019215872; // Switch clock speed is 1020MHz un/docked 28constexpr u64 BASE_CLOCK_RATE = 1019215872; // Switch clock speed is 1020MHz un/docked
31constexpr u64 MAX_VALUE_TO_MULTIPLY = std::numeric_limits<s64>::max() / BASE_CLOCK_RATE;
32 29
33inline s64 msToCycles(int ms) { 30inline s64 msToCycles(int ms) {
34 // since ms is int there is no way to overflow 31 // since ms is int there is no way to overflow
@@ -51,29 +48,9 @@ inline s64 usToCycles(int us) {
51 return (BASE_CLOCK_RATE * static_cast<s64>(us) / 1000000); 48 return (BASE_CLOCK_RATE * static_cast<s64>(us) / 1000000);
52} 49}
53 50
54inline s64 usToCycles(s64 us) { 51s64 usToCycles(s64 us);
55 if (us / 1000000 > MAX_VALUE_TO_MULTIPLY) {
56 NGLOG_ERROR(Core_Timing, "Integer overflow, use max value");
57 return std::numeric_limits<s64>::max();
58 }
59 if (us > MAX_VALUE_TO_MULTIPLY) {
60 NGLOG_DEBUG(Core_Timing, "Time very big, do rounding");
61 return BASE_CLOCK_RATE * (us / 1000000);
62 }
63 return (BASE_CLOCK_RATE * us) / 1000000;
64}
65 52
66inline s64 usToCycles(u64 us) { 53s64 usToCycles(u64 us);
67 if (us / 1000000 > MAX_VALUE_TO_MULTIPLY) {
68 NGLOG_ERROR(Core_Timing, "Integer overflow, use max value");
69 return std::numeric_limits<s64>::max();
70 }
71 if (us > MAX_VALUE_TO_MULTIPLY) {
72 NGLOG_DEBUG(Core_Timing, "Time very big, do rounding");
73 return BASE_CLOCK_RATE * static_cast<s64>(us / 1000000);
74 }
75 return (BASE_CLOCK_RATE * static_cast<s64>(us)) / 1000000;
76}
77 54
78inline s64 nsToCycles(float ns) { 55inline s64 nsToCycles(float ns) {
79 return static_cast<s64>(BASE_CLOCK_RATE * (0.000000001f) * ns); 56 return static_cast<s64>(BASE_CLOCK_RATE * (0.000000001f) * ns);
@@ -83,29 +60,9 @@ inline s64 nsToCycles(int ns) {
83 return BASE_CLOCK_RATE * static_cast<s64>(ns) / 1000000000; 60 return BASE_CLOCK_RATE * static_cast<s64>(ns) / 1000000000;
84} 61}
85 62
86inline s64 nsToCycles(s64 ns) { 63s64 nsToCycles(s64 ns);
87 if (ns / 1000000000 > MAX_VALUE_TO_MULTIPLY) {
88 NGLOG_ERROR(Core_Timing, "Integer overflow, use max value");
89 return std::numeric_limits<s64>::max();
90 }
91 if (ns > MAX_VALUE_TO_MULTIPLY) {
92 NGLOG_DEBUG(Core_Timing, "Time very big, do rounding");
93 return BASE_CLOCK_RATE * (ns / 1000000000);
94 }
95 return (BASE_CLOCK_RATE * ns) / 1000000000;
96}
97 64
98inline s64 nsToCycles(u64 ns) { 65s64 nsToCycles(u64 ns);
99 if (ns / 1000000000 > MAX_VALUE_TO_MULTIPLY) {
100 NGLOG_ERROR(Core_Timing, "Integer overflow, use max value");
101 return std::numeric_limits<s64>::max();
102 }
103 if (ns > MAX_VALUE_TO_MULTIPLY) {
104 NGLOG_DEBUG(Core_Timing, "Time very big, do rounding");
105 return BASE_CLOCK_RATE * (static_cast<s64>(ns) / 1000000000);
106 }
107 return (BASE_CLOCK_RATE * static_cast<s64>(ns)) / 1000000000;
108}
109 66
110inline u64 cyclesToNs(s64 cycles) { 67inline u64 cyclesToNs(s64 cycles) {
111 return cycles * 1000000000 / BASE_CLOCK_RATE; 68 return cycles * 1000000000 / BASE_CLOCK_RATE;