Article View: comp.sys.powerpc
Article #2753Re: Debate: PowerMac "trounces" Pentium....???
From: Robert Salasidis
Date: Sat, 13 Jan 1996 17:37
Date: Sat, 13 Jan 1996 17:37
57 lines
2559 bytes
2559 bytes
Bernd Bernie Meyer wrote:
>
> Robert Salasidis <salasidis@medcor.mcgill.ca> wrote:
> : All games that are worth anything use absolutely zero floating point in critical
> : areas. Floating point is too inefficient, and integers are used exclusively
> : (this is for all games that require real time action).
>
> Sure? You know that some compiler optimize code by using the FPU for integer
> calculations? How about the following code?
>
> ----------------
> #include <stdio.h>
>
> #define COUNT 101
>
> main()
> {
> double a=0;
> unsigned int i,j;
> double b[COUNT];
>
> for (i=0;i<COUNT;i++)
> b[i]=i;
>
> for (j=0;j<4000000;j++) {
> for (i=0;i<COUNT-1;i++)
> a+=b[i]*b[i+1];
> }
> printf("%d: %d\n",j,a);
> }
> --------------------------------
>
> On a Pentium, changing a and b to be "int" rather than "double" slows it
> down. And that is despite "int" being 32 bits while "double" is 64 bits.
> Change the "*" to "/", and using the FPU is _still_ faster.
>
> Bernie
I tried out your code on a Pentium 120 with a QNX version of Watcom's
9.5 C compiler. This is what I get
using double 40.98 sec
int 43.88
however changing the * to a + (b[i]+b[i+i])
double 40.98 sec
int 17.05
I tried it out and surprisingly you are right that using double in the
above example is more efficient (the compiler does not optimize by using
double instead of 32 bit int - double is simply faster). Using doubles
instead of ints would result in different results, as one allows numbers
up to 10^307 while the other overflows at 2^32.
Eliminating a multiplication altogether however results in much faster
integer performance. The moral of this story is in a critical loop,
avoid multiplications (int or float) at all costs.
Technical Details
Message-ID:
<30F7EDDE.C6A@medcor.mcgill.ca>Path:
arc1-ca.pugleaf.net!news.mcgill.ca!newsReferences:
<4cu3om$157i@seminole.gate.net> <30F35518.4209@medcor.mcgill.ca> <4d2id2$8po@nnrp1.news.primenet.com> <DL1EDn.z0@wombat.hanse.de>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.mcgill.ca!news From: Robert Salasidis <salasidis@medcor.mcgill.ca> Newsgroups: comp.sys.powerpc,comp.os.linux.advocacy,comp.sys.mac.advocacy,comp.os.os2.advocacy,comp.sys.amiga.advocacy,comp.sys.intel,alt.2600 Subject: Re: Debate: PowerMac "trounces" Pentium....??? Date: Sat, 13 Jan 1996 12:37:34 -0500 Organization: Salasoft Inc. Message-ID: <30F7EDDE.C6A@medcor.mcgill.ca> References: <4cu3om$157i@seminole.gate.net> <30F35518.4209@medcor.mcgill.ca> <4d2id2$8po@nnrp1.news.primenet.com> <DL1EDn.z0@wombat.hanse.de> NNTP-Posting-Host: f-02.das.mcgill.ca Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 2.0b4 (Win95; I)