diff options
| author | 2021-02-15 14:46:04 -0800 | |
|---|---|---|
| committer | 2021-02-15 14:46:04 -0800 | |
| commit | 0a91599aec5a0c4d4c87d3e23fea07dbb6ced0f7 (patch) | |
| tree | 1319cde17514c49d01045379d3a7ce2b4ccace0a /src/common/x64 | |
| parent | Merge pull request #5939 from Morph1984/web_types (diff) | |
| download | yuzu-0a91599aec5a0c4d4c87d3e23fea07dbb6ced0f7.tar.gz yuzu-0a91599aec5a0c4d4c87d3e23fea07dbb6ced0f7.tar.xz yuzu-0a91599aec5a0c4d4c87d3e23fea07dbb6ced0f7.zip | |
common: Merge uint128 to a single header file with inlines.
Diffstat (limited to 'src/common/x64')
| -rw-r--r-- | src/common/x64/native_clock.cpp | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/src/common/x64/native_clock.cpp b/src/common/x64/native_clock.cpp index a65f6b832..87de40624 100644 --- a/src/common/x64/native_clock.cpp +++ b/src/common/x64/native_clock.cpp | |||
| @@ -8,68 +8,10 @@ | |||
| 8 | #include <mutex> | 8 | #include <mutex> |
| 9 | #include <thread> | 9 | #include <thread> |
| 10 | 10 | ||
| 11 | #ifdef _MSC_VER | ||
| 12 | #include <intrin.h> | ||
| 13 | |||
| 14 | #pragma intrinsic(__umulh) | ||
| 15 | #pragma intrinsic(_udiv128) | ||
| 16 | #else | ||
| 17 | #include <x86intrin.h> | ||
| 18 | #endif | ||
| 19 | |||
| 20 | #include "common/atomic_ops.h" | 11 | #include "common/atomic_ops.h" |
| 21 | #include "common/uint128.h" | 12 | #include "common/uint128.h" |
| 22 | #include "common/x64/native_clock.h" | 13 | #include "common/x64/native_clock.h" |
| 23 | 14 | ||
| 24 | namespace { | ||
| 25 | |||
| 26 | [[nodiscard]] u64 GetFixedPoint64Factor(u64 numerator, u64 divisor) { | ||
| 27 | #ifdef __SIZEOF_INT128__ | ||
| 28 | const auto base = static_cast<unsigned __int128>(numerator) << 64ULL; | ||
| 29 | return static_cast<u64>(base / divisor); | ||
| 30 | #elif defined(_M_X64) || defined(_M_ARM64) | ||
| 31 | std::array<u64, 2> r = {0, numerator}; | ||
| 32 | u64 remainder; | ||
| 33 | #if _MSC_VER < 1923 | ||
| 34 | return udiv128(r[1], r[0], divisor, &remainder); | ||
| 35 | #else | ||
| 36 | return _udiv128(r[1], r[0], divisor, &remainder); | ||
| 37 | #endif | ||
| 38 | #else | ||
| 39 | // This one is bit more inaccurate. | ||
| 40 | return MultiplyAndDivide64(std::numeric_limits<u64>::max(), numerator, divisor); | ||
| 41 | #endif | ||
| 42 | } | ||
| 43 | |||
| 44 | [[nodiscard]] u64 MultiplyHigh(u64 a, u64 b) { | ||
| 45 | #ifdef __SIZEOF_INT128__ | ||
| 46 | return (static_cast<unsigned __int128>(a) * static_cast<unsigned __int128>(b)) >> 64; | ||
| 47 | #elif defined(_M_X64) || defined(_M_ARM64) | ||
| 48 | return __umulh(a, b); // MSVC | ||
| 49 | #else | ||
| 50 | // Generic fallback | ||
| 51 | const u64 a_lo = u32(a); | ||
| 52 | const u64 a_hi = a >> 32; | ||
| 53 | const u64 b_lo = u32(b); | ||
| 54 | const u64 b_hi = b >> 32; | ||
| 55 | |||
| 56 | const u64 a_x_b_hi = a_hi * b_hi; | ||
| 57 | const u64 a_x_b_mid = a_hi * b_lo; | ||
| 58 | const u64 b_x_a_mid = b_hi * a_lo; | ||
| 59 | const u64 a_x_b_lo = a_lo * b_lo; | ||
| 60 | |||
| 61 | const u64 carry_bit = (static_cast<u64>(static_cast<u32>(a_x_b_mid)) + | ||
| 62 | static_cast<u64>(static_cast<u32>(b_x_a_mid)) + (a_x_b_lo >> 32)) >> | ||
| 63 | 32; | ||
| 64 | |||
| 65 | const u64 multhi = a_x_b_hi + (a_x_b_mid >> 32) + (b_x_a_mid >> 32) + carry_bit; | ||
| 66 | |||
| 67 | return multhi; | ||
| 68 | #endif | ||
| 69 | } | ||
| 70 | |||
| 71 | } // namespace | ||
| 72 | |||
| 73 | namespace Common { | 15 | namespace Common { |
| 74 | 16 | ||
| 75 | u64 EstimateRDTSCFrequency() { | 17 | u64 EstimateRDTSCFrequency() { |