🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #2071

The power of inline functions (cc, gcc, g++).

#2071
From: Gordon Joly
Date: Mon, 05 Jun 1989 13:14
60 lines
2813 bytes
There are some rather alarming differences between the code
generated by gcc, g++ and /bin/cc; are we missing something?
We now believe that gcc uses /usr/include/math.h.

Tim Day, user.
Gordon Joly, installer.

Configurations:-
config.gcc sun3-os4,  config.g++ sun3-os4.
gcc 1.35, g++ 1.35.1-, libg++-1.35.0.
SUN OS 4.0.1, gas 1.33.
gcc/g++ on karl, SUN-3/160.
a.out run on phoebe, SUN-3/60.

------- Forwarded Message

Received: from cs.ucl.ac.uk by Stats.Ucl.AC.UK   via Satnet with SMTP
           id aa04194; 26 May 89 14:24 GMT
To: otto@uk.ac.ucl.cs, gordon@uk.ac.ucl.cs
cc: tday@uk.ac.ucl.cs, sam@uk.ac.ucl.cs, gillian@uk.ac.ucl.cs
Subject: The power of inline functions (cc, gcc, g++)
Date: Fri, 26 May 89 15:24:07 +0100
> From: Tim Day <T.Day@uk.ac.ucl.cs>
Source-Info:  phoebe.ps.ucl.ac.uk
Source-Info:  karl.stats.ucl.ac.uk

I was recently shocked and amazed by the effect of inline functions on
the following trivial prog (2*10^5 fp add, 10^5 sqrt):
#include <stdio.h>
#include <math.h>
main()
{	int i;double f,t;
	for (i=1,f=0.0,t=0.0;i<=100000;i++,f+=0.125,t+=sqrt(f));
	fprintf(stderr,"%f\n",t);
	exit((int)log(t));
}
All CPU times on phoebe.  Gnu stuff compiled 1.35 on karl.                 Time
cc -O4 -f68881 ctest.c -lm                                                 38.8
cc -O4 -f68881 ctest.c /usr/lib/f68881/libm.il -lm                          2.6
gcc -m68020 -m68881 -O -finline-functions -fomit-frame-pointer ctest.c -lm 51.4
g++ -m68020 -m68881 -O -finline-functions -fomit-frame-pointer ctest.c      1.2

(Note: these are _execution_ times.  I am quite prepared to pay extra at
compile time for this kind of acceleration !)

The difference between gcc and g++ is worrying... which math.h does gcc use ?
gcc-include/ doesn't actually contain a math.h, whereas g++-include/math.h
includes g++-include/math-68881.h, which is full of floppy __inline __asm stuff.

The slow progs both use jbsr _sqrt; the fast ones use fsqrtd sp@,fp0 (cc), or
fsqrtx fp1,fp0 (g++; none of this messing around doing double <-> extended
transfers on the stack !).

This might also explain why gcc compiled evileye was about 1/2 the speed
of the cc compiled version.  Is there anything which can be done to gcc
to get it to do similar things to g++, or should I try and force c through
g++ ?


------- End of Forwarded Message
Technical Details
Message-ID: <8906051459.AA18572@AENEAS.MIT.EDU>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watmath!uunet!tut.cis.ohio-state.edu!NSFNET-RELAY.AC.UK!gordon%stats.ucl.ac.uk

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watmath!uunet!tut.cis.ohio-state.edu!NSFNET-RELAY.AC.UK!gordon%stats.ucl.ac.uk
From: gordon%stats.ucl.ac.uk@NSFNET-RELAY.AC.UK (Gordon Joly)
Newsgroups: gnu.g++.bug
Subject: The power of inline functions (cc, gcc, g++).
Message-ID: <8906051459.AA18572@AENEAS.MIT.EDU>
Date: 5 Jun 89 13:14:56 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 60