PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

How much faster is fixed point versus floating point?

Hi

Just a general question on the %age speedup expected if a game is converted from floating point to fixed point on a PDA? Anyone tried comparing frame-rates?
A comparison of frame-rates is non-sensical given it will depend entirely how much FPU code there is in the main loop.

If you're concerned about performance, then it's simple to create two versions of the same routine - one FPU based and one fixed-point... then time the two over a lot or iterations.

At a *guess* (I haven't got time to do a real-world comparison right now), that due to the way the FPU is emulated, optimised fixed-point usage could be 20 times (or more) faster (per instruction).
That sounds like an accurate guess. Just take a look at VOBenchmark's floating point and fixed point tests to compare the two forms. Fixed point is obviously much faster. If you're coding for the PocketPC, use fixed point.
From my tests fixedpoint math is faster in the 5-20 times range mostly.
So it's really pointless to use floatingpoint in anything realtime.
I did some tests over a year ago and found that to multiply a 4 element vector times a 4x4 matrix, fixed point was slightly over 10 times as fast on an SA-1110 compared to floating point.

I'm pretty sure I mentioned these results here on this website 18 months or so ago, but I've searched the archives and couldn't find them.
masCh · 29 Jan 2003, 06:35 UTC — ..
n00bie here;

what does it mean when people say floating point vs fixed point? I've read a lot about floating vs fixed but I dont know how it is controlled on the programming side.

is it how you declare your variables or do calculations?

I mean, can someone provide me an example of what is a fixed point calculation and what is floating point?

A simple example is fine, because chances are I wont really understand much anyway.
lets say we want to multiply n by m to get a definite number.

Possible results of multiply in floating point:
1012.56300086
7.27
65536
123.4567

Possible results of multiplying in fixed point:
63.56
12.00
7.95
1012.30

As you can see, floating point numbers are a lot more accurate, because the POINT is not FIXED to a certain number of digits. However, this takes a long time to calculate complex numbers, such as pi and the like (disregard lookup tables). If we use fixed point then the operations are MUCH faster because we only have to get to the nth decimal point and go no further. We always know the number bits the output will be, however, so even if the number doesn't use any trailing digits, they'll still be there because the number of digits after the POINT is FIXED and cannot be changed. It's not as accurate, either, because we can't calculate to so fine a decimal, which can be hindering to some 3D rendering. But not necessarily, if you program with fixed point in mind.
Ahh excellent now I understand. Back to basics eh? Heheh.

So floating points could have trailing decimals to E^06 or whatever and the cpu would still be calculating.. my question now is, what if you set all numbers to fixed point say to 10^-100, would it still be faster than computing a floating point calculation?
masCh wrote:
So floating points could have trailing decimals to E^06 or whatever and the cpu would still be calculating.. my question now is, what if you set all numbers to fixed point say to 10^-100, would it still be faster than computing a floating point calculation?


Well, no. The key point to fixed point computations is that they can be implemented with the integer instructions of a processor. This is basically where the actual speedup comes from. And this is also what limits the precision you can typically use while still having fast computation.

In most cases the architecture has support for 32-bit integers so that's what you'll use. In this case, if you choose 10 bits for the fractional part you have 22 bits left to represent the integer part. If you need more precision you loose range.

Of course, it would be possible to use fixed point calculation with any desired precision. To get 10^-100 precision though, you'd need about 333 fractional bits. So each fixed point number would be more than 40 bytes large and the computations would be slow.

/Orpe
As you can see, floating point numbers are a lot more accurate,


That's a common misconception; it's not always true. If you know the range of numbers you're operating on then fixed-point numbers can be actually be more accurate than floats (at least over a range).

A (32-bit) float represents a "floating point" number like this:

Sign(1 bit)
Exponent(8 bits)
Fraction(23 bits)

This means that the maximum range of bits (accuracy) that a number can cover is 23 bits. However, the shift (exponent) does allow us to represent very large and very small values.

If you want to represent a range of "only" -1 to 0.99, for example, then a 32-bit fixed point system could "more accurate" than a 32-bit floating point system over parts of the range.

Floating point (worst case):

If you say the exponent makes a shift of 1, and the 23 bits are (filled to use the entire range to "disable" the exponent's utility a bit):
Code:
100 0000 0000 0000 0000 0001

Then your maximum precision is (I think - I'm not entirely awake yet this morning):

Code:
1/(2^22) = 0.0000002384185791015625


Of course, as the sign can be shifted around (the exponent changes and the point "floats", the accuracy range for the number goes from best case (close to 0) to worst case (23 bits of precision needed).

So, for floating point best case, we can have a maximum accuracy of something like:

Code:

fract expo
1/((2^22)*(2^127)) = 2^-149

= 1.4012984643248170709237295832899e-45



Fixed-point:

Sign (1 bit)
Fraction(31 bits)

If we then do the same thing, we can say that the maximum (and minimum, and average) precision is:

Code:
1/(2^30) = 0.000000000931322574615478515625


If you were really serious about the accuracy trade-offs then you could plot a graph of fixed-point accuracy vs floating-point accuracy over the range (using something like Maple rather than something with "dubious" precision itself like Excel).

As for working with numbers like 10^-100 (I know it was only an example), I think you'll find that the granularity (accuracy) of numbers at that range, even doubles, is going to give you lots of problems with underflow.

ARM have a <a href="http://www.arm.com/support/567GAM/$File/DAI0033A_fixedpoint.pdf">document</a> on using fixed and floating point in C.

HTH,

Ref.

(Who's about to go from interesting stuff about floating-point to a friggin' management meeting. bah).
Wow, thanks for the explanation guys!

This looks like the kinda forum I'm gonna be staying in.