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

--- Comment #4 from Gero <gero.peterhoff at gmx dot net> ---
This is what a branch-free implementation for `uint64_t -> Float` might look
like if no hardware implementation is available.

template <std::floating_point Float>
inline constexpr Float  u64_to_float(const uint64_t x)  noexcept
{
        using limits = std::numeric_limits<Float>;

        if constexpr (limits::digits > 64)
        {
                return Float(x);
        }
        else
        {
                using type = std::conditional_t<limits::digits < 64,
std::float64_t, Float>;

                constexpr type
                        factor = type(0x1p+32);
                const int64_t
                        hi = int64_t(x >> 32),
                        lo = int64_t(uint32_t(x));

                return Float(type(hi)*factor + type(lo));
        }
}

Depending on the `Float`, this is up to 2x to 4x faster and never slower.
I don't understand why GCC still uses algorithms that involve jumps.

Reply via email to