diff options
Diffstat (limited to 'src/common/uint128.cpp')
| -rw-r--r-- | src/common/uint128.cpp | 71 |
1 files changed, 0 insertions, 71 deletions
diff --git a/src/common/uint128.cpp b/src/common/uint128.cpp deleted file mode 100644 index 16bf7c828..000000000 --- a/src/common/uint128.cpp +++ /dev/null | |||
| @@ -1,71 +0,0 @@ | |||
| 1 | // Copyright 2019 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #ifdef _MSC_VER | ||
| 6 | #include <intrin.h> | ||
| 7 | |||
| 8 | #pragma intrinsic(_umul128) | ||
| 9 | #pragma intrinsic(_udiv128) | ||
| 10 | #endif | ||
| 11 | #include <cstring> | ||
| 12 | #include "common/uint128.h" | ||
| 13 | |||
| 14 | namespace Common { | ||
| 15 | |||
| 16 | #ifdef _MSC_VER | ||
| 17 | |||
| 18 | u64 MultiplyAndDivide64(u64 a, u64 b, u64 d) { | ||
| 19 | u128 r{}; | ||
| 20 | r[0] = _umul128(a, b, &r[1]); | ||
| 21 | u64 remainder; | ||
| 22 | #if _MSC_VER < 1923 | ||
| 23 | return udiv128(r[1], r[0], d, &remainder); | ||
| 24 | #else | ||
| 25 | return _udiv128(r[1], r[0], d, &remainder); | ||
| 26 | #endif | ||
| 27 | } | ||
| 28 | |||
| 29 | #else | ||
| 30 | |||
| 31 | u64 MultiplyAndDivide64(u64 a, u64 b, u64 d) { | ||
| 32 | const u64 diva = a / d; | ||
| 33 | const u64 moda = a % d; | ||
| 34 | const u64 divb = b / d; | ||
| 35 | const u64 modb = b % d; | ||
| 36 | return diva * b + moda * divb + moda * modb / d; | ||
| 37 | } | ||
| 38 | |||
| 39 | #endif | ||
| 40 | |||
| 41 | u128 Multiply64Into128(u64 a, u64 b) { | ||
| 42 | u128 result; | ||
| 43 | #ifdef _MSC_VER | ||
| 44 | result[0] = _umul128(a, b, &result[1]); | ||
| 45 | #else | ||
| 46 | unsigned __int128 tmp = a; | ||
| 47 | tmp *= b; | ||
| 48 | std::memcpy(&result, &tmp, sizeof(u128)); | ||
| 49 | #endif | ||
| 50 | return result; | ||
| 51 | } | ||
| 52 | |||
| 53 | std::pair<u64, u64> Divide128On32(u128 dividend, u32 divisor) { | ||
| 54 | u64 remainder = dividend[0] % divisor; | ||
| 55 | u64 accum = dividend[0] / divisor; | ||
| 56 | if (dividend[1] == 0) | ||
| 57 | return {accum, remainder}; | ||
| 58 | // We ignore dividend[1] / divisor as that overflows | ||
| 59 | const u64 first_segment = (dividend[1] % divisor) << 32; | ||
| 60 | accum += (first_segment / divisor) << 32; | ||
| 61 | const u64 second_segment = (first_segment % divisor) << 32; | ||
| 62 | accum += (second_segment / divisor); | ||
| 63 | remainder += second_segment % divisor; | ||
| 64 | if (remainder >= divisor) { | ||
| 65 | accum++; | ||
| 66 | remainder -= divisor; | ||
| 67 | } | ||
| 68 | return {accum, remainder}; | ||
| 69 | } | ||
| 70 | |||
| 71 | } // namespace Common | ||