This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Optimisation Oddities in gcc 2.95.3



First, it is almost certainly not the released version of gcc 2.95.3. 
According to the rpm I built and installed on Red Hat Linux 6.2 it's 
gcc-2.95.3-0.20000517.

I have a program based on one extracted from the Unix Review article at 
http://www.unixreview.com/articles/1997/9710/9710expbi/expbi.htm

However, I decided to use it to test a little of gcc-s optimisation, 
and perhaps to compare it with C compilers on other software platforms.

The times reported by the "time" command of bash were not what one 
would expect. Here is a sorted table showing relevant optimisation 
options and the CPU time used in running the test:
summer@possum compilerbenchmark]$ ./buildit | sort -k3
Optimisations=-O3 -march=i486      cputime=46.84s
Optimisations=-O3 -march=k6        cputime=47.55s
Optimisations=-O3 -march=i686      cputime=47.74s
Optimisations=-O3 -march=i586      cputime=47.82s
Optimisations=-O3 -march=i386      cputime=48.04s
Optimisations=-O0 -march=i586      cputime=48.35s
Optimisations=-O0 -march=i386      cputime=48.50s
Optimisations=-O0 -march=i686      cputime=48.97s
Optimisations=-O0 -march=k6        cputime=49.45s
Optimisations=-O0 -march=i486      cputime=49.77s
Optimisations=-Os -march=i386      cputime=65.73s
Optimisations=-Os -march=i686      cputime=66.31s
Optimisations=-O2 -march=i586      cputime=66.45s
Optimisations=-O1 -march=k6        cputime=66.53s
Optimisations=-O2 -march=i686      cputime=66.85s
Optimisations=-Os -march=i586      cputime=66.99s
Optimisations=-O1 -march=i686      cputime=67.00s
Optimisations=-O1 -march=i586      cputime=67.65s
Optimisations=-O2 -march=k6        cputime=67.76s
Optimisations=-O2 -march=i386      cputime=67.95s
Optimisations=-Os -march=k6        cputime=68.11s
Optimisations=-O1 -march=i486      cputime=68.37s
Optimisations=-Os -march=i486      cputime=68.46s
Optimisations=-O1 -march=i386      cputime=68.55s
Optimisations=-O2 -march=i486      cputime=70.49s
[summer@possum compilerbenchmark]$

The test is run on a Pentium II, 233 Mhz. It seems odd to me that code 
compiled for the i486 is faster than for any other processor. It's fair 
to say I find the whole set weird.

The code and script I use to run the program combine so that the 
program can easily report relevant compiler options.

They are attached for you to peruse and evaluate.


#include <stdlib.h>
#include <stdio.h>
#include <time.h>
 
typedef long int DType;
//#define DType int
DType a[20000];

void swapfunc(int i,int j)
{
	DType t = a[i];
	a[i]=a[j];
	a[j]=t;
}

void sift0(int n)
{
	if (n <= 0 || a[n-1] <= a[n]) return; 
	swapfunc(n-1, n); 
	sift0(n-1);
}


void is0(int n)
{
	int i;
	for (i=1;i<n;i++)
		sift0(i);
}

int main()
{
	int xx;
   time_t stime;
	time_t etime;
   double scputime,ecputime, ccputime; 

#ifdef OPT
	OPT
	printf("Optimisations=%-20s",opt);
#endif // OPT
	srandom(4);
	for (xx=0; xx < 20000; xx++)
	{
		a[xx]=random();
	}
   stime=time(&stime);
   scputime=(double)clock();
	is0(20000);
   time(&etime);
   ecputime=(double)clock();
   ccputime=(ecputime-scputime)/CLOCKS_PER_SEC;
   printf(" cputime=%5.2fs\n",
         ccputime);	
//	for (xx=0;xx < 10;xx++)
//		printf("%d\n",a[xx]);
	return 0;
}

#!/bin/bash
#set -x
function runseries()
{
for o in 0 1 2 3 s
	do 
		if [ ${o} = '?' ] ; then
			OPT=" -march=${arch} -mcpu=${arch}"
		else
			OPT="-O${o} -march=${arch}"
		fi
		gcc ${OPT} sort1.c -o sort1 \
			-D"OPT=char opt[]=\"${OPT}\";"\
			|| exit
		./sort1
	done
}
for arch in i386 i486 i586 i686 k6
	do
		runseries
	done
Cheers
John Summerfield
http://www2.ami.com.au/ for OS/2 & linux information.
Configuration, networking, combined IBM ftpsites index.

Microsoft's most solid OS: http://www.geocities.com/rcwoolley/

Note: mail delivered to me is deemed to be intended for me, for my 
disposition.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]