Path: utzoo!telly!ddsw1!lll-winken!killer!tness7!texbell!bigtex!natinst!cs.utexas.edu!sm.unisys.com!ucla-cs!arman From: arman@oahu.cs.ucla.edu Newsgroups: gnu.gcc Subject: GCC performance (+ sample code) Message-ID: <16219@shemp.CS.UCLA.EDU> Date: 27 Sep 88 06:15:59 GMT Sender: news@CS.UCLA.EDU Reply-To: arman@CS.UCLA.EDU (Arman Bostani) Organization: UCLA Computer Science Department Lines: 179 Machine = Sun 3/60 System = SunOS 3.5 CC/GCC Options = -O This is a follow up to the message I posted about a week ago about the quality of code produced by GCC. Since then, I have compiled many more programs and benchmarks. It seems that GCC performs consistently better than the Sun C compiler on programs with relatively simple flow structures such as the Drhystone benchmarks, especially in the absence of register declarations. Unfortunately, with programs that have complicated flow structures, Sun cc seems to perform much better. The simplest example I have found is Duff's device which was posted to the net some time ago. The Sun compiler seems to produce code which on the average is 13% faster than the code produced by GCC. In fact, when Duff's device is GCC'd without the -O option, it runs faster! Which leads us to believe that there is possibly a bug in GCC's optimizer. I have included the source for Duff's device and the optimized assembly code produced by GCC. Cheers, arman. (windsor 203) cc -O duff.c -o duff.cc (windsor 204) gcc -O -v duff.c -o duff.gcc gcc version 1.28 /usr/local/lib/gcc-cpp -v -undef -D__GNU__ -D__GNUC__ -Dmc68000 -Dsun -Dunix -D__OPTIMIZE__ -D__HAVE_FPU__-Dmc68020 duff.c /tmp/cca07939.cpp GNU CPP version 1.28 /usr/local/lib/gcc-cc1 /tmp/cca07939.cpp -quiet -dumpbase duff.c -O -version -o /tmp/cca07939.s GNU C version 1.28 (68k, MIT syntax) compiled by GNU C version 1.28. as -mc68020 /tmp/cca07939.s -o duff.o ld -o duff.gcc /lib/crt0.o /lib/Mcrt1.o duff.o /usr/local/lib/gcc-gnulib -lc (windsor 205) gcc -v duff.c -o duff.nop gcc version 1.28 /usr/local/lib/gcc-cpp -v -undef -D__GNU__ -D__GNUC__ -Dmc68000 -Dsun -Dunix -D__HAVE_FPU__-Dmc68020 duff.c /tmp/cca07949.cpp GNU CPP version 1.28 /usr/local/lib/gcc-cc1 /tmp/cca07949.cpp -quiet -dumpbase duff.c -version -o /tmp/cca07949.s GNU C version 1.28 (68k, MIT syntax) compiled by GNU C version 1.28. as -mc68020 /tmp/cca07949.s -o duff.o ld -o duff.nop /lib/crt0.o /lib/Mcrt1.o duff.o /usr/local/lib/gcc-gnulib -lc (windsor 206) time duff.cc 10000 5.4u 0.0s 0:05 92% 0+8k 2+0io 0pf+0w (windsor 207) time duff.gcc 10000 6.1u 0.1s 0:06 96% 0+8k 2+0io 0pf+0w (windsor 208) time duff.nop 10000 5.8u 0.1s 0:06 92% 0+8k 2+0io 0pf+0w (windsor 209) ---------------------------------- duff.c ---------------------------------- #define BLK 1024 int a[BLK], b[BLK]; main(c,v) char **v; { int i, n = atoi(v[1]); for(i=0; i0); } } ---------------------------------- duff.s ---------------------------------- #NO_APP .text .even .globl _main _main: link a6,#0 moveml #0x3000,sp@- movel a6@(12),a0 movel a0@(4),sp@- jbsr _atoi movel d0,d3 clrl d2 addqw #4,sp cmpl d2,d3 jle L6 L5: pea 1024:w pea _b pea _a jbsr _send addw #12,sp addql #1,d2 cmpl d2,d3 jgt L5 L6: moveml a6@(-8),#0xc unlk a6 rts .even .globl _send _send: link a6,#0 moveml #0x3000,sp@- movel a6@(8),a1 movel a6@(12),a0 movel a6@(16),d2 movel d2,d1 addql #7,d1 jpl L8 addql #7,d1 L8: asrl #3,d1 movel d2,d0 jge L23 addql #7,d0 L23: moveq #-8,d3 andl d3,d0 subl d2,d0 negl d0 moveq #7,d3 cmpl d3,d0 jhi L9 LI21: movew pc@(L21-LI21-2:b,d0:l:2),d3 jmp pc@(2,d3:w) L21: .word L10-L21 .word L20-L21 .word L19-L21 .word L18-L21 .word L17-L21 .word L16-L21 .word L15-L21 .word L14-L21 L10: L11: movew a0@+,a1@ L14: movew a0@+,a1@ L15: movew a0@+,a1@ L16: movew a0@+,a1@ L17: movew a0@+,a1@ L18: movew a0@+,a1@ L19: movew a0@+,a1@ L20: movew a0@+,a1@ subql #1,d1 andb #0xc,cc jgt L11 L9: moveml a6@(-8),#0xc unlk a6 rts .comm _b,4096 .comm _a,4096 -- Arman Bostani // UCLA Computer Science Department // +1 213-825-3194 3417 Boelter Hall // Los Angeles, California 90024-1596 // USA arman@CS.UCLA.EDU ...!(ucbvax,rutgers)!ucla-cs!arman