diff options
| author | 2019-02-16 16:52:24 -0400 | |
|---|---|---|
| committer | 2019-02-16 16:52:24 -0400 | |
| commit | a8d4927e29bb1acbf5f3267f368801847acd4222 (patch) | |
| tree | a5b08502c0fce93f8ef7a429ae873571eca1f852 /src/common/uint128.cpp | |
| parent | Use u128 on Clock Cycles calculation. (diff) | |
| download | yuzu-a8d4927e29bb1acbf5f3267f368801847acd4222.tar.gz yuzu-a8d4927e29bb1acbf5f3267f368801847acd4222.tar.xz yuzu-a8d4927e29bb1acbf5f3267f368801847acd4222.zip | |
Corrections, documenting and fixes.
Diffstat (limited to 'src/common/uint128.cpp')
| -rw-r--r-- | src/common/uint128.cpp | 11 |
1 files changed, 6 insertions, 5 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 | ||
| 8 | namespace Common { | 9 | namespace Common { |
| 10 | |||
| 9 | u128 Multiply64Into128(u64 a, u64 b) { | 11 | u128 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 | ||
| 22 | std::pair<u64, u64> Divide128On64(u128 dividend, u64 divisor) { | 23 | std::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) { |