Message-ID: <32CE3B92.2328@pobox.oleane.com> Date: Sat, 04 Jan 1997 12:14:26 +0100 From: Francois Charton Organization: CCMSA MIME-Version: 1.0 To: murray AT southeast DOT net CC: djgpp AT delorie DOT com Subject: Re: Fixed Point (Optimization) References: <32cd6b2c DOT 4726585 AT nntp DOT southeast DOT net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Murray Stokely wrote: > > Is Fixed-Point math still a neccesity for today's computers with > all their built it FPU's, etc? How much faster can it be? Anyway, > this is the same code procedure from our long thread on optimization; > I've recently come back to it, because I still see room for > improvement. What can be done to it. Fixed point? Lookup tables? > Over a year ago, I changed a part of the code in POVRAY2.2 (a raytracer) to replace floating point calculations by fixed point calculations. On my 486DX (which has a built in FPU) the result was a speed increase between 10 and 20%. However, I'm afraid the gain would be much less on a Pentium... Fixed point numbers behave like floating point numbers with fixed exponent. IMO, they can have two advantages over floats: 1/ for a given exponent, they are more precise : a 4 byte float has a 24 bit mantissa, a 4 byte fixed has a 32 bit mantissa (that is three more significant digits). This is sometime not useful, but for values in known bounds (like the values of sin() and cos()), it might be handy 2/ they are computed through integer calculations. Now, on older machines, this was a big advantage, because all floating point operations were very slow. On modern machines 486/Pentia, you have to check the performance, when working on povray, I noticed that : additions and substractions were usually faster in fixed point, but multiplications were slower in fixed point (except for multiplications by integers). As regards division, I think they were a bit faster. This was on a 486, but on the Pentium FPU, these basic operations are very fast, so I am less and less confident about the interest of fixed point on these machines. To sum up, I think fixed point are a must on no-FPU machines, and still bring some advantage on older machines like 386 or 486. For Pentium, I'm afraid they are at best equivalent to their floating point counterpart. Hence, they might be useful in games and popular applications, because they help compensate for the slower processors (and hence help your program to run on slower machines). Lookup-tables are useful whenever you often call a function several times with the same arguments. Then, you can precalculate these values. In your example, this could be done with the square root function, if you are sure it will never take arguments over (say) 1000, then you can have a table where all possible values are precalculated. With 4 bytes per number, this is a 4k table, quite usable... Francois