This is the mail archive of the gcc@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]
Other format: [Raw text]

Re: Automatic architecture optimization


On Thu, Sep 04, 2003 at 11:32:48AM -0700, Matt Fago wrote:
> Hopefully not a FAQ: I'm curious about why gcc does not support the 
> "-march" optimization flag, without an architecture given, to 
> automatically set the appropriate optimization flags for the processor 
> type the compiler is running on. This would require methods to determine 
> the processor type on all platforms that gcc runs on -- perhaps a 
> non-trivial task.

Obviously this scheme would only work when using GCC as a native compiler and
not a cross compiler.

Well the -m<xxx> options are done by each port (ie, it is not standardized
across platforms).  Have you considered writing the code to do this and
contributing it?

On some platforms like the x86, GCC uses the machine it was configured on (ie,
i686, i585, etc.) as the default machine to optimize for (though it only
generates instructions by default that can run on any 32-bit x86).

A low tech approach is to use a shell script (maybe even calling it gcc and
putting it in your PATH ahead of the system gcc) that determines the machine
(possibly using uname -p) type and then invokes the real gcc with those
options.  Of the top of my head, something like:

	#! /bin/sh

	# Invoke gcc with the proper -march option.  If the user has specified
	# -mcpu= or -march= don't override them.

	case "$*:`uname -p`" in
		*-mcpu=* | *-march=*)
			exec /usr/bin/gcc ${1+"$@"};;

		*:i686*)
			exec /usr/bin/gcc -mcpu=i686 ${1+"$@"};;

		*:i586*)
			exec /usr/bin/gcc -mcpu=i586 ${1+"$@"};;

		*:i486*)
			exec /usr/bin/gcc -mcpu=i486 ${1+"$@"};;

		*)	# Don't know the model, call it a Pentium-II and hope
			# for the best
			exec /usr/bin/gcc -mcpu=i686 ${1+"$@"};;
	esac


-- 
Michael Meissner
email: gnu@the-meissners.org
http://www.the-meissners.org


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