Article View: comp.sys.sun
Article #12059Re: libm for 68881 and Sun fpa is incredibly slow
From: Matthew Self
Date: Fri, 21 Apr 1989 13:58
Date: Fri, 21 Apr 1989 13:58
57 lines
2828 bytes
2828 bytes
John Schultz compiled the following timings for Sun's math libraries using
GCC and CC with various options:
> My results, running on Sun 3/60, Sun OS 3.5, GNU CC 1.32 built using
> default switches were
>
> gcc -lm === 4.6 real 4.2 user 0.0 sys
> gcc -m68881 -lm === 4.4 real 4.2 user 0.0 sys
> gcc -O -m68881 -lm === 4.4 real 4.1 user 0.0 sys
> gcc -O -g -m68881 -lm === 5.4 real 4.2 user 0.1 sys
> cc -lm === 159.4 real 146.7 user 0.6 sys
> cc -O -lm === 155.4 real 146.2 user 0.4 sys
> cc -f68881 -lm === 6.6 real 4.6 user 0.1 sys
> cc /usr/lib/f68881.il === 9.9 real 6.7 user 0.1 sys
> cc -O /usr/lib/f68881.il === 6.5 real 6.4 user 0.0 sys
> **********************************************************************/
> #include <math.h>
>
> main()
> {
> register int i;
> register double x, y;
> for(i = 0, x = 0; i < 100000; i++, x += 2*M_PI/100000.0)
> y = cos(x);
> }
I have written an inline math library for GCC which is more than twice as
fast as any of these options for this test program. In fact, it permits
GCC to determine that the program does nothing at all, so it optimizes it
away entirely! I modified the test program slightly to make the return
value depend on the computations in the loop so this won't happen. Even
with the extra addition I introduced, the program now executes in only
2.5s, more than twice as fast as before. Here is the new test program:
#include <math.h> /* my inline ANSI math library */
#define M_PI 3.1415792 /* this isn't defined in ANSI C's math.h */
main()
{
int i; /* GCC doesn't need register declarations */
double x, y = 0;
for(i = 0, x = 0; i < 100000; i++, x += 2*M_PI/100000.0)
y += cos(x);
if (y == 0)
return 0;
else
return 1;
}
This inline math library was recently posted to the info-gcc mailing list
(gnu.gcc newsgroup). If you can't obtain a copy there, let me know and I
will send you a copy.
Matthew Self
NASA Ames Research Center
self@bayes.arc.nasa.gov
Technical Details
Message-ID:
<8903262300.AA04423@bayes.arc.nasa.gov>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!mit-eddie!uw-beaver!rice!sun-spots-requestShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!mit-eddie!uw-beaver!rice!sun-spots-request From: self@bayes.arc.nasa.gov (Matthew Self) Newsgroups: comp.sys.sun Subject: Re: libm for 68881 and Sun fpa is incredibly slow Keywords: Software Message-ID: <8903262300.AA04423@bayes.arc.nasa.gov> Date: 21 Apr 89 13:58:18 GMT Sender: usenet@rice.edu Organization: Sun-Spots Lines: 57 Approved: Sun-Spots@rice.edu Original-Date: Sun, 26 Mar 89 15:00:40 PST X-Sun-Spots-Digest: Volume 7, Issue 235, message 2 of 15