https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99434

--- Comment #6 from cqwrteur <unlvsur at live dot com> ---
(In reply to Jakub Jelinek from comment #5)
> Testcase without includes:
> template<typename _To, typename _From>
> constexpr _To
> bit_cast(const _From& __from) noexcept
> {
>   return __builtin_bit_cast(_To, __from);
> }
> 
> struct u64x2_t
> {
> #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
>   unsigned long long high,low;
> #else
>   unsigned long long low,high;
> #endif
> };
> u64x2_t umul5(unsigned long long a,unsigned long long b) noexcept
> {
>   return bit_cast<u64x2_t>(static_cast<__uint128_t>(a)*b);
> }
> 
> u64x2_t umul_builtin(unsigned long long a,unsigned long long b) noexcept
> {
>   return __builtin_bit_cast(u64x2_t,static_cast<__uint128_t>(a)*b);
> }

did you fix the >>64 bug here? should I start another bug to report that?

The bit_cast/memcpy trick is to deal with the issue of. Probably can be
recognized early on than std::bit_cast?

std::uint64_t umul128(std::uint64_t a,std::uint64_t b,std::uint64_t& high)
noexcept
{
    __uint128_t res{static_cast<__uint128_t>(a)*b};
    high=static_cast<std::uint64_t>(res>>64);
    return static_cast<std::uint64_t>(res);
}

Reply via email to