summaryrefslogtreecommitdiff
path: root/src/common/uint128.cpp
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2019-02-15 20:04:11 -0400
committerGravatar FernandoS272019-02-15 22:57:16 -0400
commitecccfe033777d6ae7d29bcf0cfc30412f7d3be24 (patch)
treef6504e5f766a6f8675764124f7d231843de40583 /src/common/uint128.cpp
parentImplement 128 bits Unsigned Integer Multiplication and Division. (diff)
downloadyuzu-ecccfe033777d6ae7d29bcf0cfc30412f7d3be24.tar.gz
yuzu-ecccfe033777d6ae7d29bcf0cfc30412f7d3be24.tar.xz
yuzu-ecccfe033777d6ae7d29bcf0cfc30412f7d3be24.zip
Use u128 on Clock Cycles calculation.
Diffstat (limited to 'src/common/uint128.cpp')
-rw-r--r--src/common/uint128.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/common/uint128.cpp b/src/common/uint128.cpp
index aea7f03e2..8548ba808 100644
--- a/src/common/uint128.cpp
+++ b/src/common/uint128.cpp
@@ -1,7 +1,25 @@
1#ifdef _MSC_VER
2#include <intrin.h>
3
4#pragma intrinsic(_umul128)
5#endif
6#include "common/uint128.h"
1 7
2namespace Common { 8namespace Common {
9u128 Multiply64Into128(u64 a, u64 b) {
10#ifdef _MSC_VER
11 u128 result;
12 result[0] = _umul128(a, b, &result[1]);
13#else
14 unsigned __int128 tmp = a;
15 tmp *= b;
16 u128 result;
17 std::memcpy(&result, &tmp, sizeof(u128));
18#endif
19 return result;
20}
3 21
4std::pair<u64, u64> udiv128(u128 dividend, u64 divisor) { 22std::pair<u64, u64> Divide128On64(u128 dividend, u64 divisor) {
5 u64 remainder = dividend[0] % divisor; 23 u64 remainder = dividend[0] % divisor;
6 u64 accum = dividend[0] / divisor; 24 u64 accum = dividend[0] / divisor;
7 if (dividend[1] == 0) 25 if (dividend[1] == 0)
@@ -12,6 +30,10 @@ std::pair<u64, u64> udiv128(u128 dividend, u64 divisor) {
12 u64 second_segment = (first_segment % divisor) << 32; 30 u64 second_segment = (first_segment % divisor) << 32;
13 accum += (second_segment / divisor); 31 accum += (second_segment / divisor);
14 remainder += second_segment % divisor; 32 remainder += second_segment % divisor;
33 if (remainder >= divisor) {
34 accum++;
35 remainder -= divisor;
36 }
15 return {accum, remainder}; 37 return {accum, remainder};
16} 38}
17 39