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.
views:
342answers:
1
+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
2010-02-10 03:36:35
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
2010-02-10 09:59:38
@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
2010-02-10 17:06:07
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
2010-02-11 02:39:52
@codist: mul and 64-to-32 conversion should both be 1 cycle.
Potatoswatter
2010-02-11 03:12:15
Thanks, its hard to get a brain around how fast things like this are.
codist
2010-02-11 03:22:45