summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/CMakeLists.txt20
-rw-r--r--src/core/core_timing.cpp53
-rw-r--r--src/core/core_timing.h53
-rw-r--r--src/core/core_timing_util.cpp63
-rw-r--r--src/core/core_timing_util.h64
-rw-r--r--src/core/hle/kernel/thread.cpp1
-rw-r--r--src/core/hle/kernel/timer.cpp1
-rw-r--r--src/core/hle/service/audio/audout_u.cpp1
-rw-r--r--src/core/hle/service/audio/audren_u.cpp1
-rw-r--r--src/core/hle/service/hid/hid.cpp1
-rw-r--r--src/core/hle/service/nvflinger/nvflinger.cpp1
-rw-r--r--src/core/hle/service/time/time.cpp1
12 files changed, 146 insertions, 114 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index b7d52babc..4f6c45085 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -10,6 +10,8 @@ add_library(core STATIC
10 core_cpu.h 10 core_cpu.h
11 core_timing.cpp 11 core_timing.cpp
12 core_timing.h 12 core_timing.h
13 core_timing_util.cpp
14 core_timing_util.h
13 file_sys/content_archive.cpp 15 file_sys/content_archive.cpp
14 file_sys/content_archive.h 16 file_sys/content_archive.h
15 file_sys/control_metadata.cpp 17 file_sys/control_metadata.cpp
@@ -114,26 +116,26 @@ add_library(core STATIC
114 hle/service/apm/apm.h 116 hle/service/apm/apm.h
115 hle/service/apm/interface.cpp 117 hle/service/apm/interface.cpp
116 hle/service/apm/interface.h 118 hle/service/apm/interface.h
117 hle/service/audio/audio.cpp
118 hle/service/audio/audio.h
119 hle/service/audio/audin_u.cpp 119 hle/service/audio/audin_u.cpp
120 hle/service/audio/audin_u.h 120 hle/service/audio/audin_u.h
121 hle/service/audio/audio.cpp
122 hle/service/audio/audio.h
121 hle/service/audio/audout_u.cpp 123 hle/service/audio/audout_u.cpp
122 hle/service/audio/audout_u.h 124 hle/service/audio/audout_u.h
123 hle/service/audio/audrec_u.cpp 125 hle/service/audio/audrec_u.cpp
124 hle/service/audio/audrec_u.h 126 hle/service/audio/audrec_u.h
125 hle/service/audio/audren_u.cpp 127 hle/service/audio/audren_u.cpp
126 hle/service/audio/audren_u.h
127 hle/service/audio/audren_u.cpp 128 hle/service/audio/audren_u.cpp
128 hle/service/audio/audren_u.h 129 hle/service/audio/audren_u.h
130 hle/service/audio/audren_u.h
129 hle/service/audio/codecctl.cpp 131 hle/service/audio/codecctl.cpp
130 hle/service/audio/codecctl.h 132 hle/service/audio/codecctl.h
131 hle/service/audio/hwopus.cpp 133 hle/service/audio/hwopus.cpp
132 hle/service/audio/hwopus.h 134 hle/service/audio/hwopus.h
133 hle/service/bcat/module.cpp
134 hle/service/bcat/module.h
135 hle/service/bcat/bcat.cpp 135 hle/service/bcat/bcat.cpp
136 hle/service/bcat/bcat.h 136 hle/service/bcat/bcat.h
137 hle/service/bcat/module.cpp
138 hle/service/bcat/module.h
137 hle/service/fatal/fatal.cpp 139 hle/service/fatal/fatal.cpp
138 hle/service/fatal/fatal.h 140 hle/service/fatal/fatal.h
139 hle/service/fatal/fatal_p.cpp 141 hle/service/fatal/fatal_p.cpp
@@ -154,6 +156,10 @@ add_library(core STATIC
154 hle/service/lm/lm.h 156 hle/service/lm/lm.h
155 hle/service/mm/mm_u.cpp 157 hle/service/mm/mm_u.cpp
156 hle/service/mm/mm_u.h 158 hle/service/mm/mm_u.h
159 hle/service/nfp/nfp.cpp
160 hle/service/nfp/nfp.h
161 hle/service/nfp/nfp_user.cpp
162 hle/service/nfp/nfp_user.h
157 hle/service/nifm/nifm.cpp 163 hle/service/nifm/nifm.cpp
158 hle/service/nifm/nifm.h 164 hle/service/nifm/nifm.h
159 hle/service/nifm/nifm_a.cpp 165 hle/service/nifm/nifm_a.cpp
@@ -162,10 +168,6 @@ add_library(core STATIC
162 hle/service/nifm/nifm_s.h 168 hle/service/nifm/nifm_s.h
163 hle/service/nifm/nifm_u.cpp 169 hle/service/nifm/nifm_u.cpp
164 hle/service/nifm/nifm_u.h 170 hle/service/nifm/nifm_u.h
165 hle/service/nfp/nfp.cpp
166 hle/service/nfp/nfp.h
167 hle/service/nfp/nfp_user.cpp
168 hle/service/nfp/nfp_user.h
169 hle/service/ns/ns.cpp 171 hle/service/ns/ns.cpp
170 hle/service/ns/ns.h 172 hle/service/ns/ns.h
171 hle/service/ns/pl_u.cpp 173 hle/service/ns/pl_u.cpp
diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp
index 50d1e3fc9..a1b6f96f1 100644
--- a/src/core/core_timing.cpp
+++ b/src/core/core_timing.cpp
@@ -5,17 +5,15 @@
5#include "core/core_timing.h" 5#include "core/core_timing.h"
6 6
7#include <algorithm> 7#include <algorithm>
8#include <cinttypes>
9#include <limits>
10#include <mutex> 8#include <mutex>
11#include <string> 9#include <string>
12#include <tuple> 10#include <tuple>
13#include <unordered_map> 11#include <unordered_map>
14#include <vector> 12#include <vector>
15#include "common/assert.h" 13#include "common/assert.h"
16#include "common/logging/log.h"
17#include "common/thread.h" 14#include "common/thread.h"
18#include "common/threadsafe_queue.h" 15#include "common/threadsafe_queue.h"
16#include "core/core_timing_util.h"
19 17
20namespace CoreTiming { 18namespace CoreTiming {
21 19
@@ -59,7 +57,6 @@ static u64 event_fifo_id;
59static Common::MPSCQueue<Event, false> ts_queue; 57static Common::MPSCQueue<Event, false> ts_queue;
60 58
61constexpr int MAX_SLICE_LENGTH = 20000; 59constexpr int MAX_SLICE_LENGTH = 20000;
62constexpr u64 MAX_VALUE_TO_MULTIPLY = std::numeric_limits<s64>::max() / BASE_CLOCK_RATE;
63 60
64static s64 idled_cycles; 61static s64 idled_cycles;
65 62
@@ -72,54 +69,6 @@ static EventType* ev_lost = nullptr;
72 69
73static void EmptyTimedCallback(u64 userdata, s64 cyclesLate) {} 70static void EmptyTimedCallback(u64 userdata, s64 cyclesLate) {}
74 71
75s64 usToCycles(s64 us) {
76 if (us / 1000000 > MAX_VALUE_TO_MULTIPLY) {
77 LOG_ERROR(Core_Timing, "Integer overflow, use max value");
78 return std::numeric_limits<s64>::max();
79 }
80 if (us > MAX_VALUE_TO_MULTIPLY) {
81 LOG_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 LOG_ERROR(Core_Timing, "Integer overflow, use max value");
90 return std::numeric_limits<s64>::max();
91 }
92 if (us > MAX_VALUE_TO_MULTIPLY) {
93 LOG_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 LOG_ERROR(Core_Timing, "Integer overflow, use max value");
102 return std::numeric_limits<s64>::max();
103 }
104 if (ns > MAX_VALUE_TO_MULTIPLY) {
105 LOG_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 LOG_ERROR(Core_Timing, "Integer overflow, use max value");
114 return std::numeric_limits<s64>::max();
115 }
116 if (ns > MAX_VALUE_TO_MULTIPLY) {
117 LOG_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
123EventType* RegisterEvent(const std::string& name, TimedCallback callback) { 72EventType* RegisterEvent(const std::string& name, TimedCallback callback) {
124 // check for existing type with same name. 73 // check for existing type with same name.
125 // we want event type names to remain unique so that we can use them for serialization. 74 // we want event type names to remain unique so that we can use them for serialization.
diff --git a/src/core/core_timing.h b/src/core/core_timing.h
index dc31124a8..7fe6380ad 100644
--- a/src/core/core_timing.h
+++ b/src/core/core_timing.h
@@ -23,59 +23,6 @@
23 23
24namespace CoreTiming { 24namespace CoreTiming {
25 25
26// The below clock rate is based on Switch's clockspeed being widely known as 1.020GHz
27// The exact value used is of course unverified.
28constexpr u64 BASE_CLOCK_RATE = 1019215872; // Switch clock speed is 1020MHz un/docked
29
30inline s64 msToCycles(int ms) {
31 // since ms is int there is no way to overflow
32 return BASE_CLOCK_RATE * static_cast<s64>(ms) / 1000;
33}
34
35inline s64 msToCycles(float ms) {
36 return static_cast<s64>(BASE_CLOCK_RATE * (0.001f) * ms);
37}
38
39inline s64 msToCycles(double ms) {
40 return static_cast<s64>(BASE_CLOCK_RATE * (0.001) * ms);
41}
42
43inline s64 usToCycles(float us) {
44 return static_cast<s64>(BASE_CLOCK_RATE * (0.000001f) * us);
45}
46
47inline s64 usToCycles(int us) {
48 return (BASE_CLOCK_RATE * static_cast<s64>(us) / 1000000);
49}
50
51s64 usToCycles(s64 us);
52
53s64 usToCycles(u64 us);
54
55inline s64 nsToCycles(float ns) {
56 return static_cast<s64>(BASE_CLOCK_RATE * (0.000000001f) * ns);
57}
58
59inline s64 nsToCycles(int ns) {
60 return BASE_CLOCK_RATE * static_cast<s64>(ns) / 1000000000;
61}
62
63s64 nsToCycles(s64 ns);
64
65s64 nsToCycles(u64 ns);
66
67inline u64 cyclesToNs(s64 cycles) {
68 return cycles * 1000000000 / BASE_CLOCK_RATE;
69}
70
71inline s64 cyclesToUs(s64 cycles) {
72 return cycles * 1000000 / BASE_CLOCK_RATE;
73}
74
75inline u64 cyclesToMs(s64 cycles) {
76 return cycles * 1000 / BASE_CLOCK_RATE;
77}
78
79/** 26/**
80 * CoreTiming begins at the boundary of timing slice -1. An initial call to Advance() is 27 * CoreTiming begins at the boundary of timing slice -1. An initial call to Advance() is
81 * required to end slice -1 and start slice 0 before the first cycle of code is executed. 28 * required to end slice -1 and start slice 0 before the first cycle of code is executed.
diff --git a/src/core/core_timing_util.cpp b/src/core/core_timing_util.cpp
new file mode 100644
index 000000000..73dea4edb
--- /dev/null
+++ b/src/core/core_timing_util.cpp
@@ -0,0 +1,63 @@
1// Copyright 2008 Dolphin Emulator Project / 2017 Citra Emulator Project
2// Licensed under GPLv2+
3// Refer to the license.txt file included.
4
5#include "core/core_timing_util.h"
6
7#include <cinttypes>
8#include <limits>
9#include "common/logging/log.h"
10
11namespace CoreTiming {
12
13constexpr u64 MAX_VALUE_TO_MULTIPLY = std::numeric_limits<s64>::max() / BASE_CLOCK_RATE;
14
15s64 usToCycles(s64 us) {
16 if (us / 1000000 > MAX_VALUE_TO_MULTIPLY) {
17 LOG_ERROR(Core_Timing, "Integer overflow, use max value");
18 return std::numeric_limits<s64>::max();
19 }
20 if (us > MAX_VALUE_TO_MULTIPLY) {
21 LOG_DEBUG(Core_Timing, "Time very big, do rounding");
22 return BASE_CLOCK_RATE * (us / 1000000);
23 }
24 return (BASE_CLOCK_RATE * us) / 1000000;
25}
26
27s64 usToCycles(u64 us) {
28 if (us / 1000000 > MAX_VALUE_TO_MULTIPLY) {
29 LOG_ERROR(Core_Timing, "Integer overflow, use max value");
30 return std::numeric_limits<s64>::max();
31 }
32 if (us > MAX_VALUE_TO_MULTIPLY) {
33 LOG_DEBUG(Core_Timing, "Time very big, do rounding");
34 return BASE_CLOCK_RATE * static_cast<s64>(us / 1000000);
35 }
36 return (BASE_CLOCK_RATE * static_cast<s64>(us)) / 1000000;
37}
38
39s64 nsToCycles(s64 ns) {
40 if (ns / 1000000000 > MAX_VALUE_TO_MULTIPLY) {
41 LOG_ERROR(Core_Timing, "Integer overflow, use max value");
42 return std::numeric_limits<s64>::max();
43 }
44 if (ns > MAX_VALUE_TO_MULTIPLY) {
45 LOG_DEBUG(Core_Timing, "Time very big, do rounding");
46 return BASE_CLOCK_RATE * (ns / 1000000000);
47 }
48 return (BASE_CLOCK_RATE * ns) / 1000000000;
49}
50
51s64 nsToCycles(u64 ns) {
52 if (ns / 1000000000 > MAX_VALUE_TO_MULTIPLY) {
53 LOG_ERROR(Core_Timing, "Integer overflow, use max value");
54 return std::numeric_limits<s64>::max();
55 }
56 if (ns > MAX_VALUE_TO_MULTIPLY) {
57 LOG_DEBUG(Core_Timing, "Time very big, do rounding");
58 return BASE_CLOCK_RATE * (static_cast<s64>(ns) / 1000000000);
59 }
60 return (BASE_CLOCK_RATE * static_cast<s64>(ns)) / 1000000000;
61}
62
63} // namespace CoreTiming
diff --git a/src/core/core_timing_util.h b/src/core/core_timing_util.h
new file mode 100644
index 000000000..5c3718782
--- /dev/null
+++ b/src/core/core_timing_util.h
@@ -0,0 +1,64 @@
1// Copyright 2008 Dolphin Emulator Project / 2017 Citra Emulator Project
2// Licensed under GPLv2+
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "common/common_types.h"
8
9namespace CoreTiming {
10
11// The below clock rate is based on Switch's clockspeed being widely known as 1.020GHz
12// The exact value used is of course unverified.
13constexpr u64 BASE_CLOCK_RATE = 1019215872; // Switch clock speed is 1020MHz un/docked
14
15inline s64 msToCycles(int ms) {
16 // since ms is int there is no way to overflow
17 return BASE_CLOCK_RATE * static_cast<s64>(ms) / 1000;
18}
19
20inline s64 msToCycles(float ms) {
21 return static_cast<s64>(BASE_CLOCK_RATE * (0.001f) * ms);
22}
23
24inline s64 msToCycles(double ms) {
25 return static_cast<s64>(BASE_CLOCK_RATE * (0.001) * ms);
26}
27
28inline s64 usToCycles(float us) {
29 return static_cast<s64>(BASE_CLOCK_RATE * (0.000001f) * us);
30}
31
32inline s64 usToCycles(int us) {
33 return (BASE_CLOCK_RATE * static_cast<s64>(us) / 1000000);
34}
35
36s64 usToCycles(s64 us);
37
38s64 usToCycles(u64 us);
39
40inline s64 nsToCycles(float ns) {
41 return static_cast<s64>(BASE_CLOCK_RATE * (0.000000001f) * ns);
42}
43
44inline s64 nsToCycles(int ns) {
45 return BASE_CLOCK_RATE * static_cast<s64>(ns) / 1000000000;
46}
47
48s64 nsToCycles(s64 ns);
49
50s64 nsToCycles(u64 ns);
51
52inline u64 cyclesToNs(s64 cycles) {
53 return cycles * 1000000000 / BASE_CLOCK_RATE;
54}
55
56inline s64 cyclesToUs(s64 cycles) {
57 return cycles * 1000000 / BASE_CLOCK_RATE;
58}
59
60inline u64 cyclesToMs(s64 cycles) {
61 return cycles * 1000 / BASE_CLOCK_RATE;
62}
63
64} // namespace CoreTiming
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index cd85c4b7c..94735c86e 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -14,6 +14,7 @@
14#include "core/arm/arm_interface.h" 14#include "core/arm/arm_interface.h"
15#include "core/core.h" 15#include "core/core.h"
16#include "core/core_timing.h" 16#include "core/core_timing.h"
17#include "core/core_timing_util.h"
17#include "core/hle/kernel/errors.h" 18#include "core/hle/kernel/errors.h"
18#include "core/hle/kernel/handle_table.h" 19#include "core/hle/kernel/handle_table.h"
19#include "core/hle/kernel/kernel.h" 20#include "core/hle/kernel/kernel.h"
diff --git a/src/core/hle/kernel/timer.cpp b/src/core/hle/kernel/timer.cpp
index 0141125e4..904a3d0a5 100644
--- a/src/core/hle/kernel/timer.cpp
+++ b/src/core/hle/kernel/timer.cpp
@@ -6,6 +6,7 @@
6#include "common/assert.h" 6#include "common/assert.h"
7#include "common/logging/log.h" 7#include "common/logging/log.h"
8#include "core/core_timing.h" 8#include "core/core_timing.h"
9#include "core/core_timing_util.h"
9#include "core/hle/kernel/handle_table.h" 10#include "core/hle/kernel/handle_table.h"
10#include "core/hle/kernel/kernel.h" 11#include "core/hle/kernel/kernel.h"
11#include "core/hle/kernel/thread.h" 12#include "core/hle/kernel/thread.h"
diff --git a/src/core/hle/service/audio/audout_u.cpp b/src/core/hle/service/audio/audout_u.cpp
index 154bc12da..1dcd84d98 100644
--- a/src/core/hle/service/audio/audout_u.cpp
+++ b/src/core/hle/service/audio/audout_u.cpp
@@ -6,6 +6,7 @@
6#include <vector> 6#include <vector>
7#include "common/logging/log.h" 7#include "common/logging/log.h"
8#include "core/core_timing.h" 8#include "core/core_timing.h"
9#include "core/core_timing_util.h"
9#include "core/hle/ipc_helpers.h" 10#include "core/hle/ipc_helpers.h"
10#include "core/hle/kernel/event.h" 11#include "core/hle/kernel/event.h"
11#include "core/hle/kernel/hle_ipc.h" 12#include "core/hle/kernel/hle_ipc.h"
diff --git a/src/core/hle/service/audio/audren_u.cpp b/src/core/hle/service/audio/audren_u.cpp
index e623f4f8e..6aed9e2fa 100644
--- a/src/core/hle/service/audio/audren_u.cpp
+++ b/src/core/hle/service/audio/audren_u.cpp
@@ -7,6 +7,7 @@
7#include "common/alignment.h" 7#include "common/alignment.h"
8#include "common/logging/log.h" 8#include "common/logging/log.h"
9#include "core/core_timing.h" 9#include "core/core_timing.h"
10#include "core/core_timing_util.h"
10#include "core/hle/ipc_helpers.h" 11#include "core/hle/ipc_helpers.h"
11#include "core/hle/kernel/event.h" 12#include "core/hle/kernel/event.h"
12#include "core/hle/kernel/hle_ipc.h" 13#include "core/hle/kernel/hle_ipc.h"
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp
index 475a0a5cf..9a02ba686 100644
--- a/src/core/hle/service/hid/hid.cpp
+++ b/src/core/hle/service/hid/hid.cpp
@@ -5,6 +5,7 @@
5#include <atomic> 5#include <atomic>
6#include "common/logging/log.h" 6#include "common/logging/log.h"
7#include "core/core_timing.h" 7#include "core/core_timing.h"
8#include "core/core_timing_util.h"
8#include "core/frontend/emu_window.h" 9#include "core/frontend/emu_window.h"
9#include "core/frontend/input.h" 10#include "core/frontend/input.h"
10#include "core/hle/ipc_helpers.h" 11#include "core/hle/ipc_helpers.h"
diff --git a/src/core/hle/service/nvflinger/nvflinger.cpp b/src/core/hle/service/nvflinger/nvflinger.cpp
index 1fca1743d..5344441e1 100644
--- a/src/core/hle/service/nvflinger/nvflinger.cpp
+++ b/src/core/hle/service/nvflinger/nvflinger.cpp
@@ -9,6 +9,7 @@
9#include "common/scope_exit.h" 9#include "common/scope_exit.h"
10#include "core/core.h" 10#include "core/core.h"
11#include "core/core_timing.h" 11#include "core/core_timing.h"
12#include "core/core_timing_util.h"
12#include "core/hle/service/nvdrv/devices/nvdisp_disp0.h" 13#include "core/hle/service/nvdrv/devices/nvdisp_disp0.h"
13#include "core/hle/service/nvdrv/nvdrv.h" 14#include "core/hle/service/nvdrv/nvdrv.h"
14#include "core/hle/service/nvflinger/buffer_queue.h" 15#include "core/hle/service/nvflinger/buffer_queue.h"
diff --git a/src/core/hle/service/time/time.cpp b/src/core/hle/service/time/time.cpp
index 507ae95f4..f60bf7b91 100644
--- a/src/core/hle/service/time/time.cpp
+++ b/src/core/hle/service/time/time.cpp
@@ -6,6 +6,7 @@
6#include <ctime> 6#include <ctime>
7#include "common/logging/log.h" 7#include "common/logging/log.h"
8#include "core/core_timing.h" 8#include "core/core_timing.h"
9#include "core/core_timing_util.h"
9#include "core/hle/ipc_helpers.h" 10#include "core/hle/ipc_helpers.h"
10#include "core/hle/kernel/client_port.h" 11#include "core/hle/kernel/client_port.h"
11#include "core/hle/kernel/client_session.h" 12#include "core/hle/kernel/client_session.h"