views:

342

answers:

1

Most people seem to want to go the other way. I'm wondering if there is a fast way to convert fixed point to floating point, ideally using SSE2. Either straight C or C++ or even asm would be fine.

+1  A: 

It's easy as long as you have a double-precision FPU: there are 53 bits of significant figures. SSE2 has double-precision.

float conv_fx( int32_t fx ) {
    double fp = fx;
    fp = fp / double(1<<16); // multiplication by a constant
    return fp;
}
Potatoswatter
This code shows how simple it really is. The major performance constraint here will be memory, not CPU. Things would be different of course if you have to convert an _array_ of fixed-points to floats.
MSalters
@MSalters: Vector unpack+pack operations to convert pairs of `int32_t`s to `double`s at a time would still be the way to go to convert an array with SSE.
Potatoswatter
I thought it might be something like that but it seemed slow given its a conversion a div (or mul) and another conversion. I guess I will have to try it in various ways.
codist
@codist: mul and 64-to-32 conversion should both be 1 cycle.
Potatoswatter
Thanks, its hard to get a brain around how fast things like this are.
codist