Floating point vs. Fixed point

Started by
14 comments, last by ragonastick 22 years, 8 months ago
>the extra range for calculations is handy, but still, there could be a loss of accuracy using floating points if values are getting quite high

I think this is purely theoretical. I don''t think that in practice, anyone ever run into this problem while designing a game. It could be a problematic for some very specialized applications though.

But when it comes to performance: floating point operations such as multiplication and division are a lot faster than integer ones, at least on modern CPU''s / FPU''s (fmul is faster than imul, fdiv is *alot* faster then idiv, fadd is as fast as add, but it can be better pipelined on very well designed FPU''s such as AMD''s)

On the other hand, compares are alot faster on fixed point values: a simple cmp is enough, a floating point value needs an fcomp plus a costly flagword transfer operation.
Advertisement
Even just having taken a class in the stuff, I can tell you that it DOES in fact matter:

difference of .001 in ONE coord in a particular vector calculation amounts to a several-orders-of-magnitude error (not always that bad of course, but it crops up in very common solution methods, including inversion).

ld
No Excuses
* Floating point operations does pair. Pairing make a great difference (!).
* However, FP operations overlap - but this is only true for a very limited set of instructions.
* fmul is (unless my information is very outdated - this is from the Pentium time I reckon) is so very much slower than mul/imul. If I remember correctly fmul would take 49-50 cycles or so where as mul takes what, 4 or 8?
* You can use SIMD instructions to optimize fixed point math too (MMX).
* Uploading data into the FPU is slower than loading data into the CPU (Still, I don''t know how this is on modern P-IIII etc. processors).

"This album was written, recorded and edited at Gröndal, Stockholm in the year of 2000. At this point in time money still ruled the world. Capitalistic thoughts were wide spread. From the sky filled with the fumes of a billionarie''s cigar to the deepest abyss drenched in nuclear waste. A rich kid was a happy kid, oh..dirty, filthy times. Let this be a reminder."
- Fireside, taken from back of the Elite album
> * Floating point operations does pair. Pairing make a great difference (!).

That''s correct. They even pair better than integer instructions.

> * However, FP operations overlap - but this is only true for a very limited set of instructions.

Almost all RISC FPU instructions overlap on modern FPU''s.

> * fmul is (unless my information is very outdated - this is from the Pentium time I reckon) is so very much slower than mul/imul. If I remember correctly fmul would take 49-50 cycles or so where as mul takes what, 4 or 8?

Whaaa, your information is _very_ outdated
fmul takes between 0.5 and 3 cycles on a modern FPU, depends on pairing and overlapping. imul between 4 to 6. Both can vary due to cache misses. imul can have AGI''s stalls, fmul not.

> * You can use SIMD instructions to optimize fixed point math too (MMX).

Forget MMX. FPU and 3DNow or SSE(2) are far better and faster. And: MMX and FPU are mutually exclusive due to the same register set. This does not apply to 3DNow / SSE.

> * Uploading data into the FPU is slower than loading data into the CPU (Still, I don''t know how this is on modern P-IIII etc. processors).

It''s the same, it even uses the same cache area. This only applies to fld type instructions, fild is slower, since the fpu has to convert types.

conclusion: floating point is almost always faster. Except for compares, where fixed point takes the lead.


The only general (i.e. most always exists) is that fixed->integer is way faster than float->integer. As for precision, there''s SSE which lets you use HUGE floating point numbers. (Up to 128 bits, I think)

If you don''t need to convert to int and back often there''s few reasons not to use floating point.

Also, I''m not sure but can someone verify/disprove that on the mac there''s pretty much no speed difference between floats and ints? I''m no mac guy so I''m curious.
> Also, I''m not sure but can someone verify/disprove that on the
> mac there''s pretty much no speed difference between floats and
> ints? I''m no mac guy so I''m curious.

On the Mac floating point is faster, sometimes much faster, than integer maths, even without taking account of AltiVec vector units. Key calculations are particularly efficient: single precision FP multiply is almost as quick as addition, and multiply-add is as fast as multiply. Also the large FP register set (32 registers, no overlap with SSE or similar) makes a lot of difference to speed for complex calculations.

I think this is to some extent true of all RISC processors with FP capabilities, though a lot depends on implementation details.
John BlackburneProgrammer, The Pitbull Syndicate

This topic is closed to new replies.

Advertisement