4

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 Answers1

2

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
  • 134,909
  • 25
  • 265
  • 421
  • 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 Feb 10 '10 at 09:59
  • @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 Feb 10 '10 at 17:06
  • 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. –  Feb 11 '10 at 02:39
  • @codist: mul and 64-to-32 conversion should both be 1 cycle. – Potatoswatter Feb 11 '10 at 03:12
  • Thanks, its hard to get a brain around how fast things like this are. –  Feb 11 '10 at 03:22
  • Just wondering if there's a difference between `fp = fp / double(1<<16);` and `fp = ldexpf(fp, -16);` -- I have tried the later in my code. – matthias Jul 21 '14 at 11:23