summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/uint128.cpp11
-rw-r--r--src/common/uint128.h9
-rw-r--r--src/core/arm/dynarmic/arm_dynarmic.cpp2
-rw-r--r--src/core/core_timing_util.cpp5
4 files changed, 14 insertions, 13 deletions
diff --git a/src/common/uint128.cpp b/src/common/uint128.cpp
index 8548ba808..2238a52c5 100644
--- a/src/common/uint128.cpp
+++ b/src/common/uint128.cpp
@@ -3,31 +3,32 @@
3 3
4#pragma intrinsic(_umul128) 4#pragma intrinsic(_umul128)
5#endif 5#endif
6#include <cstring>
6#include "common/uint128.h" 7#include "common/uint128.h"
7 8
8namespace Common { 9namespace Common {
10
9u128 Multiply64Into128(u64 a, u64 b) { 11u128 Multiply64Into128(u64 a, u64 b) {
10#ifdef _MSC_VER
11 u128 result; 12 u128 result;
13#ifdef _MSC_VER
12 result[0] = _umul128(a, b, &result[1]); 14 result[0] = _umul128(a, b, &result[1]);
13#else 15#else
14 unsigned __int128 tmp = a; 16 unsigned __int128 tmp = a;
15 tmp *= b; 17 tmp *= b;
16 u128 result;
17 std::memcpy(&result, &tmp, sizeof(u128)); 18 std::memcpy(&result, &tmp, sizeof(u128));
18#endif 19#endif
19 return result; 20 return result;
20} 21}
21 22
22std::pair<u64, u64> Divide128On64(u128 dividend, u64 divisor) { 23std::pair<u64, u64> Divide128On32(u128 dividend, u32 divisor) {
23 u64 remainder = dividend[0] % divisor; 24 u64 remainder = dividend[0] % divisor;
24 u64 accum = dividend[0] / divisor; 25 u64 accum = dividend[0] / divisor;
25 if (dividend[1] == 0) 26 if (dividend[1] == 0)
26 return {accum, remainder}; 27 return {accum, remainder};
27 // We ignore dividend[1] / divisor as that overflows 28 // We ignore dividend[1] / divisor as that overflows
28 u64 first_segment = (dividend[1] % divisor) << 32; 29 const u64 first_segment = (dividend[1] % divisor) << 32;
29 accum += (first_segment / divisor) << 32; 30 accum += (first_segment / divisor) << 32;
30 u64 second_segment = (first_segment % divisor) << 32; 31 const u64 second_segment = (first_segment % divisor) << 32;
31 accum += (second_segment / divisor); 32 accum += (second_segment / divisor);
32 remainder += second_segment % divisor; 33 remainder += second_segment % divisor;
33 if (remainder >= divisor) { 34 if (remainder >= divisor) {
diff --git a/src/common/uint128.h b/src/common/uint128.h
index 45e384c33..52e6b46eb 100644
--- a/src/common/uint128.h
+++ b/src/common/uint128.h
@@ -1,13 +1,14 @@
1#include <array> 1
2#include <cstdint>
3#include <cstring>
4#include <utility> 2#include <utility>
5#include "common/common_types.h" 3#include "common/common_types.h"
6 4
7namespace Common { 5namespace Common {
8 6
7// This function multiplies 2 u64 values and produces a u128 value;
9u128 Multiply64Into128(u64 a, u64 b); 8u128 Multiply64Into128(u64 a, u64 b);
10 9
11std::pair<u64, u64> Divide128On64(u128 dividend, u64 divisor); 10// This function divides a u128 by a u32 value and produces two u64 values:
11// the result of division and the remainder
12std::pair<u64, u64> Divide128On32(u128 dividend, u32 divisor);
12 13
13} // namespace Common 14} // namespace Common
diff --git a/src/core/arm/dynarmic/arm_dynarmic.cpp b/src/core/arm/dynarmic/arm_dynarmic.cpp
index 25f76259b..4fdc12f11 100644
--- a/src/core/arm/dynarmic/arm_dynarmic.cpp
+++ b/src/core/arm/dynarmic/arm_dynarmic.cpp
@@ -152,7 +152,7 @@ std::unique_ptr<Dynarmic::A64::Jit> ARM_Dynarmic::MakeJit() const {
152 config.tpidr_el0 = &cb->tpidr_el0; 152 config.tpidr_el0 = &cb->tpidr_el0;
153 config.dczid_el0 = 4; 153 config.dczid_el0 = 4;
154 config.ctr_el0 = 0x8444c004; 154 config.ctr_el0 = 0x8444c004;
155 config.cntfrq_el0 = Timing::CNTFREQ; // Value from fusee. 155 config.cntfrq_el0 = Timing::CNTFREQ;
156 156
157 // Unpredictable instructions 157 // Unpredictable instructions
158 config.define_unpredictable_behaviour = true; 158 config.define_unpredictable_behaviour = true;
diff --git a/src/core/core_timing_util.cpp b/src/core/core_timing_util.cpp
index aab4aa697..7942f30d6 100644
--- a/src/core/core_timing_util.cpp
+++ b/src/core/core_timing_util.cpp
@@ -62,9 +62,8 @@ s64 nsToCycles(u64 ns) {
62} 62}
63 63
64u64 CpuCyclesToClockCycles(u64 ticks) { 64u64 CpuCyclesToClockCycles(u64 ticks) {
65 u128 temporal = Common::Multiply64Into128(ticks, CNTFREQ); 65 const u128 temporal = Common::Multiply64Into128(ticks, CNTFREQ);
66 std::pair<u64, u64> result = Common::Divide128On64(temporal, BASE_CLOCK_RATE); 66 return Common::Divide128On32(temporal, static_cast<u32>(BASE_CLOCK_RATE)).first;
67 return result.first;
68} 67}
69 68
70} // namespace Core::Timing 69} // namespace Core::Timing