Advantages of using fixed-point arithmetic in C ++ for devices without FPU

I would like to optimize my C ++ code for an ARM device that does not have a floating point block. Most of my functions use float, and I'm considering changing them to a fixed point.

Are there any real benefits with ARM devices, or are the compilers smart enough to do it themselves?

For example, whether it will be more efficient on an ARM device.

//unsigned char const* input
unsigned int a, b;
a= *input++ << 12; 
b= *input++ << 12; 
a*=1024;    //0.25 shifted 12 bits
b*=1024;    //0.25 shifted 12 bits
*output++ = (a+b) >> 24;

than

float a,b;
a= *input++;
b= *input++;
a=a/4;
b=a/4;
*output++ = a+b;
+3
source share
4 answers

, , , , . , NaN , .

, , , FPU, ( ). , .

+4

gp2x, ARM- 200 . 3D-, float .

, . "soft-fp", . ​​ , .

++ Fixed Point Libray, , float.

+5

ARM, . -1 , , (NaN, inf ..). , .

+3

A fixed point is usually more efficient in all cases where the floating point does not actually float, even on devices with FPUs. For example, if you use long integers to represent a space to the nearest millimeter. Savings are usually realized at computational speed, in a space where you need a double rather than a floating one to get the same millimeter range as you, get out of the long one and put it where you can avoid functions such as sprintf, etc. .

So yes, a fixed point makes sense in many contexts.

+2
source

All Articles