www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/23/13:35:52

From: Paul Shirley <Paul AT chocolat*foobar.co.uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: float & ints & triangle3d_f
Date: Tue, 20 May 1997 19:11:10 +0100
Organization: wot? me?
Distribution: world
Message-ID: <OsxmYGA+kegzEwW0@foobar.co.uk>
References: <Pine DOT GSO DOT 3 DOT 96 DOT 970517180056 DOT 23053B-100000 AT linknet DOT kitsap DOT lib DOT wa DOT us>
NNTP-Posting-Host: chocolat.foobar.co.uk
Mime-Version: 1.0
Lines: 46
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019