[PATCH v2] dix: add utility functions for double to/fro FP1616/FP3232 conversion

Michel Dänzer michel at daenzer.net
Wed Oct 5 01:53:24 PDT 2011


On Mit, 2011-10-05 at 17:01 +1000, Peter Hutterer wrote: 
> Co-authored by Jeremy Huddleston <jeremyhu at apple.com>
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

[...]

> +FP3232
> +double_to_fp3232(double in)
> +{
> +    FP3232 ret;
> +    int32_t integral;
> +    double tmp;
> +    uint32_t frac_d;
> +
> +    tmp = floor(in);
> +    integral = (int32_t)tmp;
> +    tmp = ldexp(in - (int)in, 32);

This needs to be

    ldexp(in - integral, 32)

or it's incorrect for -x.y with y > 5.

Though I'm not sure what using ldexp() instead of (1ULL << 32) or (1 <<
16) buys in exchange for generating larger and probably less efficient
code. If you insist in using ldexp though, consider converting the above
to

    (in - integral) * ldexp(1, 32)

which gcc seems clever enough to turn into the same code as

    (in - integral) * (1ULL << 32)

In general, I find the conversion code so verbose as to be borderline
confusing, but I guess the top priority right now is to make it
correct...

I assume there will be followup patches to make the relevant code use
these and fix make check.


-- 
Earthling Michel Dänzer           |                   http://www.amd.com
Libre software enthusiast         |          Debian, X and DRI developer


More information about the xorg-devel mailing list