Rewrite mulh64/umulh64

Use __int128_t/__uint128_t idioms on GCC/Clang.
May result in better codegen by avoiding inline asm.
This commit is contained in:
Nekotekina 2019-03-13 00:06:12 +03:00
parent 688aabc6c9
commit eae5b9e049

View File

@ -157,18 +157,18 @@ namespace utils
#endif
}
inline u64 umulh64(u64 a, u64 b)
constexpr u64 umulh64(u64 a, u64 b)
{
u64 result;
__asm__("mulq %[b]" : "=d"(result) : [a] "a"(a), [b] "rm"(b));
return result;
const __uint128_t x = a;
const __uint128_t y = b;
return (x * y) >> 64;
}
inline s64 mulh64(s64 a, s64 b)
constexpr s64 mulh64(s64 a, s64 b)
{
s64 result;
__asm__("imulq %[b]" : "=d"(result) : [a] "a"(a), [b] "rm"(b));
return result;
const __int128_t x = a;
const __int128_t y = b;
return (x * y) >> 64;
}
#elif defined(_MSC_VER)