libm for 68881 and Sun fpa is incredibly slow

Matthew Self self at bayes.arc.nasa.gov
Fri Apr 21 23:58:18 AEST 1989


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 at bayes.arc.nasa.gov



More information about the Comp.sys.sun mailing list