On 9 September 2012 02:29, Max Filippov <jcmvb...@gmail.com> wrote:
> +uint32_t HELPER(ftoui)(float32 v, uint32_t rounding_mode, uint32_t scale)
> +{
> +    float_status fp_status = {0};
> +    float32 zero = {0};

This probably won't compile if you turn on USE_SOFTFLOAT_STRUCT_TYPES
in softfloat.h. (That's a define intended to assist in avoiding
accidental mixing of the softfloat types with native int/float types.)

In any case softfloat.h provides a float32_zero which is probably what
you want to use here.

> +    float32 res;
> +
> +    set_float_rounding_mode(rounding_mode, &fp_status);
> +
> +    res = float32_mul(v, uint32_to_float32(scale, &fp_status), &fp_status);

Can you use the softflota scalbn function here instead?

> +
> +    if (float32_compare_quiet(v, zero, &fp_status) == float_relation_less) {
> +        return float32_to_int32(res, &fp_status);
> +    } else {
> +        return float32_to_uint32(res, &fp_status);
> +    }

This looks rather odd...are you sure it's correct?

> +}
> +
> +float32 HELPER(itof)(CPUXtensaState *env, uint32_t v, uint32_t scale)
> +{
> +    return float32_div(
> +                int32_to_float32(v, &env->fp_status),
> +                uint32_to_float32(scale, &env->fp_status),
> +                &env->fp_status);
> +}
> +
> +float32 HELPER(uitof)(CPUXtensaState *env, uint32_t v, uint32_t scale)
> +{
> +    return float32_div(
> +                uint32_to_float32(v, &env->fp_status),
> +                uint32_to_float32(scale, &env->fp_status),
> +                &env->fp_status);

Again, scalbn should let you avoid this division. (check how the
ARM float-to-int and int-to-float are done, I think the semantics
are similar.)

-- PMM

Reply via email to