mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-02-06 09:39:55 +00:00
u128: add multiplication support (for MSVC)
This commit is contained in:
parent
b704cc8375
commit
4d9a167f56
@ -204,6 +204,7 @@ extern "C"
|
||||
uchar _subborrow_u64(uchar, u64, u64, u64*);
|
||||
u64 __shiftleft128(u64, u64, uchar);
|
||||
u64 __shiftright128(u64, u64, uchar);
|
||||
u64 _umul128(u64, u64, u64*);
|
||||
}
|
||||
|
||||
// Unsigned 128-bit integer implementation (TODO)
|
||||
@ -251,6 +252,13 @@ struct alignas(16) u128
|
||||
return value;
|
||||
}
|
||||
|
||||
constexpr friend u128 operator*(const u128& l, const u128& r)
|
||||
{
|
||||
u128 value = l;
|
||||
value *= r;
|
||||
return value;
|
||||
}
|
||||
|
||||
constexpr u128 operator+() const
|
||||
{
|
||||
return *this;
|
||||
@ -365,6 +373,24 @@ struct alignas(16) u128
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr u128& operator*=(const u128& r)
|
||||
{
|
||||
const u64 _hi = r.hi * lo + r.lo * hi;
|
||||
|
||||
if (std::is_constant_evaluated())
|
||||
{
|
||||
hi = (lo >> 32) * (r.lo >> 32) + (((lo >> 32) * (r.lo & 0xffffffff)) >> 32) + (((r.lo >> 32) * (lo & 0xffffffff)) >> 32);
|
||||
lo = lo * r.lo;
|
||||
}
|
||||
else
|
||||
{
|
||||
lo = _umul128(lo, r.lo, &hi);
|
||||
}
|
||||
|
||||
hi += _hi;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr u128& operator<<=(const u128& r)
|
||||
{
|
||||
if (std::is_constant_evaluated())
|
||||
|
Loading…
x
Reference in New Issue
Block a user