Path: utzoo!dptcdc!jarvis.csri.toronto.edu!mailrus!cornell!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: <8903222320.AA01458@bayes.arc.nasa.gov> Date: 18 Apr 89 20:19:04 GMT Sender: usenet@rice.edu Organization: Sun-Spots Lines: 57 Approved: Sun-Spots@rice.edu Original-Date: Wed, 22 Mar 89 15:20:34 PST X-Sun-Spots-Digest: Volume 7, Issue 230, message 7 of 16 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 > > 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 /* 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; } Availability of this inline math library will be announced soon on the info-gcc mailing list. Mail to info-gcc-request@prep.ai.mit.edu to subscribe. Matthew Self NASA Ames Research Center self@bayes.arc.nasa.gov