summaryrefslogtreecommitdiffstats
path: root/src/core/core_timing.cpp
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2018-05-03 13:53:05 +0200
committerLioncash <mathew1800@gmail.com>2018-05-03 14:00:15 +0200
commit9f3641755e9a49c5869582f4be4a45a93c4ab247 (patch)
tree04d1f976cecc96768215422e285c9069cc263302 /src/core/core_timing.cpp
parentMerge pull request #431 from lioncash/fmt (diff)
downloadyuzu-9f3641755e9a49c5869582f4be4a45a93c4ab247.tar
yuzu-9f3641755e9a49c5869582f4be4a45a93c4ab247.tar.gz
yuzu-9f3641755e9a49c5869582f4be4a45a93c4ab247.tar.bz2
yuzu-9f3641755e9a49c5869582f4be4a45a93c4ab247.tar.lz
yuzu-9f3641755e9a49c5869582f4be4a45a93c4ab247.tar.xz
yuzu-9f3641755e9a49c5869582f4be4a45a93c4ab247.tar.zst
yuzu-9f3641755e9a49c5869582f4be4a45a93c4ab247.zip
Diffstat (limited to '')
-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 @@
#include <algorithm>
#include <cinttypes>
+#include <limits>
#include <mutex>
#include <string>
#include <tuple>
@@ -57,7 +58,8 @@ static u64 event_fifo_id;
// to the event_queue by the emu thread
static Common::MPSCQueue<Event, false> ts_queue;
-static constexpr int MAX_SLICE_LENGTH = 20000;
+constexpr int MAX_SLICE_LENGTH = 20000;
+constexpr u64 MAX_VALUE_TO_MULTIPLY = std::numeric_limits<s64>::max() / BASE_CLOCK_RATE;
static s64 idled_cycles;
@@ -70,6 +72,54 @@ static EventType* ev_lost = nullptr;
static void EmptyTimedCallback(u64 userdata, s64 cyclesLate) {}
+s64 usToCycles(s64 us) {
+ if (us / 1000000 > MAX_VALUE_TO_MULTIPLY) {
+ NGLOG_ERROR(Core_Timing, "Integer overflow, use max value");
+ return std::numeric_limits<s64>::max();
+ }
+ if (us > MAX_VALUE_TO_MULTIPLY) {
+ NGLOG_DEBUG(Core_Timing, "Time very big, do rounding");
+ return BASE_CLOCK_RATE * (us / 1000000);
+ }
+ return (BASE_CLOCK_RATE * us) / 1000000;
+}
+
+s64 usToCycles(u64 us) {
+ if (us / 1000000 > MAX_VALUE_TO_MULTIPLY) {
+ NGLOG_ERROR(Core_Timing, "Integer overflow, use max value");
+ return std::numeric_limits<s64>::max();
+ }
+ if (us > MAX_VALUE_TO_MULTIPLY) {
+ NGLOG_DEBUG(Core_Timing, "Time very big, do rounding");
+ return BASE_CLOCK_RATE * static_cast<s64>(us / 1000000);
+ }
+ return (BASE_CLOCK_RATE * static_cast<s64>(us)) / 1000000;
+}
+
+s64 nsToCycles(s64 ns) {
+ if (ns / 1000000000 > MAX_VALUE_TO_MULTIPLY) {
+ NGLOG_ERROR(Core_Timing, "Integer overflow, use max value");
+ return std::numeric_limits<s64>::max();
+ }
+ if (ns > MAX_VALUE_TO_MULTIPLY) {
+ NGLOG_DEBUG(Core_Timing, "Time very big, do rounding");
+ return BASE_CLOCK_RATE * (ns / 1000000000);
+ }
+ return (BASE_CLOCK_RATE * ns) / 1000000000;
+}
+
+s64 nsToCycles(u64 ns) {
+ if (ns / 1000000000 > MAX_VALUE_TO_MULTIPLY) {
+ NGLOG_ERROR(Core_Timing, "Integer overflow, use max value");
+ return std::numeric_limits<s64>::max();
+ }
+ if (ns > MAX_VALUE_TO_MULTIPLY) {
+ NGLOG_DEBUG(Core_Timing, "Time very big, do rounding");
+ return BASE_CLOCK_RATE * (static_cast<s64>(ns) / 1000000000);
+ }
+ return (BASE_CLOCK_RATE * static_cast<s64>(ns)) / 1000000000;
+}
+
EventType* RegisterEvent(const std::string& name, TimedCallback callback) {
// check for existing type with same name.
// we want event type names to remain unique so that we can use them for serialization.