Mail Archives: djgpp/1997/05/23/13:35:52
In article <Pine DOT GSO DOT 3 DOT 96 DOT 970517180056 DOT 23053B-100000 AT linknet DOT kitsap DOT lib.
wa.us>, KaRNaGE <dlydiard AT linknet DOT kitsap DOT lib DOT wa DOT us> writes
>i searched the back mail, and from what i read, floats are faster then
>ints, on a pentuim?....before i convert all my code to floating point,
>i was wondering a few things:
>
>Are floats still faster then ints on a pentuim pro?
I believe the P6 has *better* float performance.
>Is comparing floats slower then comparing ints? i.e. if (a < b)
Never compare floats if you can avoid it. If you really do have to do
it, compute the difference in fp, store it as a float then check bit31
(the sign bit).
>>>
// Test the sign of a float
// return <>0 if -ve
static inline unsigned int
SignofFLOAT32(FLOAT32 v)
{
int t;
*((FLOAT32*)&t) = v;
return t & 0x80000000;
}
<<<
>will type casting floats to ints slow my code down?..
Yes. This is almost the slowest thing you can do. Theres code to do it
faster floating around (can't find my copy ;( but avoid where possible.
FPU multiply is *much* faster then INT multiplies. FPU divides are
slightly faster and can be pipelined (if you know how to force the
compiler to do it ;) Simple addition/subtraction is much faster in INT.
Basically, use floats for things like 3d matrix operations - the number
of multiplies will dominate everything. Use fixed point for integrating
loops (polygon edge stepping for example).
Most important: don't blindly change from int->float code - you will be
dissapointed since only some code will actually benefit. Most of the
people you will hear claim that fpu code is slower have done just that.
---
Paul Shirley: that star in my email address should be a period!
- Raw text -