diff options
| author | 2019-02-15 19:26:41 -0400 | |
|---|---|---|
| committer | 2019-02-15 22:55:31 -0400 | |
| commit | 3ea48e8ebe25686f2342cd79b32409fcd1bccb28 (patch) | |
| tree | c9e5c3da2dec7ad2ef371a0d6fcd8c9cc11dc729 /src/common/uint128.cpp | |
| parent | Correct CNTPCT to use Clock Cycles instead of Cpu Cycles. (diff) | |
| download | yuzu-3ea48e8ebe25686f2342cd79b32409fcd1bccb28.tar.gz yuzu-3ea48e8ebe25686f2342cd79b32409fcd1bccb28.tar.xz yuzu-3ea48e8ebe25686f2342cd79b32409fcd1bccb28.zip | |
Implement 128 bits Unsigned Integer Multiplication and Division.
Diffstat (limited to 'src/common/uint128.cpp')
| -rw-r--r-- | src/common/uint128.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/common/uint128.cpp b/src/common/uint128.cpp new file mode 100644 index 000000000..aea7f03e2 --- /dev/null +++ b/src/common/uint128.cpp | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | |||
| 2 | namespace Common { | ||
| 3 | |||
| 4 | std::pair<u64, u64> udiv128(u128 dividend, u64 divisor) { | ||
| 5 | u64 remainder = dividend[0] % divisor; | ||
| 6 | u64 accum = dividend[0] / divisor; | ||
| 7 | if (dividend[1] == 0) | ||
| 8 | return {accum, remainder}; | ||
| 9 | // We ignore dividend[1] / divisor as that overflows | ||
| 10 | u64 first_segment = (dividend[1] % divisor) << 32; | ||
| 11 | accum += (first_segment / divisor) << 32; | ||
| 12 | u64 second_segment = (first_segment % divisor) << 32; | ||
| 13 | accum += (second_segment / divisor); | ||
| 14 | remainder += second_segment % divisor; | ||
| 15 | return {accum, remainder}; | ||
| 16 | } | ||
| 17 | |||
| 18 | } // namespace Common | ||