diff options
author | Fernando Sahmkow <fsahmkow27@gmail.com> | 2020-02-10 16:20:40 +0100 |
---|---|---|
committer | Fernando Sahmkow <fsahmkow27@gmail.com> | 2020-06-18 22:29:18 +0200 |
commit | e3524d114246a9221c766bdf1992777b208cbd67 (patch) | |
tree | 1454fe38bdafd94ada74ae5f1209a7466bbf4e78 /src/common/uint128.cpp | |
parent | Common: Implement WallClock Interface and implement a native clock for x64 (diff) | |
download | yuzu-e3524d114246a9221c766bdf1992777b208cbd67.tar yuzu-e3524d114246a9221c766bdf1992777b208cbd67.tar.gz yuzu-e3524d114246a9221c766bdf1992777b208cbd67.tar.bz2 yuzu-e3524d114246a9221c766bdf1992777b208cbd67.tar.lz yuzu-e3524d114246a9221c766bdf1992777b208cbd67.tar.xz yuzu-e3524d114246a9221c766bdf1992777b208cbd67.tar.zst yuzu-e3524d114246a9221c766bdf1992777b208cbd67.zip |
Diffstat (limited to '')
-rw-r--r-- | src/common/uint128.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/common/uint128.cpp b/src/common/uint128.cpp index 32bf56730..7e77588db 100644 --- a/src/common/uint128.cpp +++ b/src/common/uint128.cpp @@ -6,12 +6,34 @@ #include <intrin.h> #pragma intrinsic(_umul128) +#pragma intrinsic(_udiv128) #endif #include <cstring> #include "common/uint128.h" namespace Common { +#ifdef _MSC_VER + +u64 MultiplyAndDivide64(u64 a, u64 b, u64 d) { + u128 r{}; + r[0] = _umul128(a, b, &r[1]); + u64 remainder; + return _udiv128(r[1], r[0], d, &remainder); +} + +#else + +u64 MultiplyAndDivide64(u64 a, u64 b, u64 d) { + const u64 diva = a / d; + const u64 moda = a % d; + const u64 divb = b / d; + const u64 modb = b % d; + return diva * b + moda * divb + moda * modb / d; +} + +#endif + u128 Multiply64Into128(u64 a, u64 b) { u128 result; #ifdef _MSC_VER |