Advertisement

Optimization: Benefit for using floats vs doubles?

Started by August 10, 2000 01:22 AM
14 comments, last by Dark Druid 24 years, 4 months ago
Oops, the above was me
Btw, every game engine I know of uses floats everywhere. I wouldn''t be suprised if some were using doubles for some parts, but I don''t know of any yet.
Almost all is said here above...but I think we''re going into the wrong direction...

I think in practice it doesn''t matter much if you use floats in stead of doubles! Unless: do you use long distances in your simulator? (precision...)

Maybe it''s a good idea to concentrate on the functions C(++) uses for your math (math.h)!
These functions call extra procs, and who knows what they all do? I do know they are NOT fast!!!
For example: converting from float to int will use up something like 15 cycles, while it can be done in 3 (or sometimes even 2) instruction cycles!!!

The FPU has it''s own functions (FSQRT, FCOS, FISTP, ...)
Use these functions if you want to optimize bigtime!!!

Did you also check your formula''s for too much "div''s"?
For example:
    // slow (total 34 cycles)double a = x / z;    // ~17 cycles or moredouble b = y / z;    // ~17 cycles or more// faster (total 23 cycles)double d = 1.0 / z;  // ~17 cycles or moredouble a = x * d;    // 3 cyclesdouble b = y * d;    // 3 cycles    


Advertisement
quote:
Jansic, you're way off on the "smallest" cache holding 8000 doubles. A lot of CPUs only have 32k of L1


Ok, I was basing that on the 128k L2 cache in my ageing Celeron and that L2->L1 copys don't generate many L2 misses, forgetting that an L1->CPU requirement is _way_ more likely to generate a cache miss...

Anyway, a little research yields the Intel Optimisation Reference:-

http://developer.intel.com/design/PentiumII/manuals/242816.htm


Which says that you should use floats of a _suitable size_ for your required precision, and as long as they're aligned correctly and you're consistent with their use, you'll get negligible performance differences...
However, you can get minor speed increases when using 32 bit floats, since some FP instructions will pair with integer instructions; and you get more cache space...
So Ok, 32 bits floats may help performance a _little_, but not all compilers will exploit such instruction scheduling by default. MSVC does, but only if you target a Pentium class chip.


quote:
Also, all recent and current CPUs, memory chips, etc are optimized for sending 32-bit words, not double words, because this is the native word size for the CPU.


Erm? actually all Pentium class chips and memory modules use 64 bit data paths, the Read & Write units both work with 64 bit data, so you won't be wasting any _bus_ bandwidth. All FP data gets adjusted to internally to 80 bits before it gets processed anyway.

Of course, as 'baskuenen' says, we're probably looking in the wrong places. I'd say the best float performance comes from not having to process any floats at all, so algorithm optimisation will probably yield better results than changing to a 'faster' data type... but I digress...

Jans.

-----------------
Janucybermetaltvgothmogbunny

Edited by - jansic on August 13, 2000 3:23:41 PM

Anyone know the rough amount of cycles it takes to convert floats to doubles? I''m using doubles in my math functions, but they always end up being converted to floats. How much am I losing? Thanks.

-----------------------------

1. "Diplomacy is the art of saying 'Nice doggie!'... till you can find a rock."

2. "Always remember you're unique, just like everyone else."

3. "If we don't succeed, we run the risk of failure."
-Dan Quayle

4. If life gives you sour grapes, squash them and make wine!
-----------------------------1. "Diplomacy is the art of saying 'Nice doggie!'... till you can find a rock." 2. "Always remember you're unique, just like everyone else." 3. "If we don't succeed, we run the risk of failure."-Dan Quayle4. If life gives you sour grapes, squash them and make wine!
Conversion from float to double or back doesn''t take any extra cycles!!!
If the FPU loads a float or a double, it''s just as fast. Internally the FPU works with 80bit numbers.


That''s what I was thinking, but I didn''t like my warnings, so I #pragma''d them, and was just making sure.

-----------------------------

1. "Diplomacy is the art of saying 'Nice doggie!'... till you can find a rock."

2. "Always remember you're unique, just like everyone else."

3. "If we don't succeed, we run the risk of failure."
-Dan Quayle

4. If life gives you sour grapes, squash them and make wine!
-----------------------------1. "Diplomacy is the art of saying 'Nice doggie!'... till you can find a rock." 2. "Always remember you're unique, just like everyone else." 3. "If we don't succeed, we run the risk of failure."-Dan Quayle4. If life gives you sour grapes, squash them and make wine!

This topic is closed to new replies.

Advertisement