qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Added hardfloat conversion from float32 to float64


From: Richard Henderson
Subject: Re: [PATCH] Added hardfloat conversion from float32 to float64
Date: Wed, 16 Oct 2019 08:38:06 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0

On 10/16/19 12:32 AM, Matus Kysel wrote:
> +float64 float32_to_float64(float32 a, float_status *status)
> +{
> +    if (unlikely(!float32_is_normal(a))) {
> +        return soft_float32_to_float64(a, status);
> +    } else if (float32_is_zero(a)) {
> +        return float64_set_sign(float64_zero, float32_is_neg(a));
> +    } else {
> +        double r = *(float *)&a;
> +        return *(float64 *)&r;
> +    }
> +}

This is a good idea, since there are no issues with inexact or rounding when
converting in this direction.

Please use union_float{32,64} instead of casting.

Your special case for 0 won't fire, since it is already filtered by
!float32_is_normal.

So I think this could be written as

    if (likely(float32_is_normal(a))) {
        union_float32 uf;
        union_float64 ud;

        uf.s = a;
        ud.h = uf.h;
        return ud.s;
    } else if (float32_is_zero(a)) {
        return float64_set_sign(float64_zero, float32_is_neg(a));
    } else {
        return soft_float32_to_float64(a);
    }


r~



reply via email to

[Prev in Thread] Current Thread [Next in Thread]