PATCH: Add --with-arch=cpu (Re: Should gcc configurted for CPU to generate code for CPU by default?)

H. J. Lu hjl@lucon.org
Fri Jul 19 10:45:00 GMT 2002


On Fri, Jul 19, 2002 at 09:02:07AM -0700, H. J. Lu wrote:
> On Fri, Jul 19, 2002 at 04:25:00PM +0100, Richard Earnshaw wrote:
> > > When I configure gcc for i686 with
> > > 
> > > .../configure --target=i686-xxxxx
> > > 
> > > I'd like to be able to make gcc generate code for i686 by default. It
> > > is also useful for MIPS. I am thinking adding
> > > 
> > > --with-default-ARCH=cpu
> > > 
> > > or
> > > 
> > > --with-default-CPU=cpu
> > > 
> > > or
> > > 
> > > --with-default-ISA=cpu
> > > 
> > > Any comments?
> > > 
> > 
> > What's wrong with the existing --with-cpu=... already supported by 
> > configure?
> > 
> 
> Correct me if I am wrong. At least for x86, --with-cpu=i686 is no
> different from --target=i686-xxxxx, as far as the default code
> generation is concerned. For x86, there are -mcpu=xxx and -march=xxx.
> -with-cpu=xxx sets the default -mcpu=xxx. I want something to set
> the default -march=xxx. Looking at install.texi. --with-cpu should
> be used to set -march=xxx for x86. But for x86, TARGET_CPU_DEFAULT
> is for -mcpu=... I am looking for TARGET_ARCH_DEFAULT. --with-arch=...
> will work for me.
> 
> 

Here is a patch to add --with-arch=cpu.


H.J.
-------------- next part --------------
2002-07-19  H.J. Lu <hjl@gnu.org>

	* Makefile.in (target_arch_default): New.
	(cs-config.h): Add TARGET_ARCH_DEFAULT="$(target_arch_default)".
	(cs-hconfig.h): Likewise.
	(cs-tconfig.h): Add TARGET_ARCH_DEFAULT="".
	(cs-tm_p.h): Likewise.

	* config.gcc (target_arch_default): New.
	Support --with-arch=cpu for i[34567]86-*-* and x86_64-*-*.

	* config/i386/i386.c (override_options): Set ix86_arch_string
	to cpu_names [TARGET_ARCH_DEFAULT].

	* configure.in: Substitute target_arch_default.
	* configure: Regenerated.

	* doc/install.texi: Document --with-arch=cpu.

--- gcc/Makefile.in.arch	Fri Jul 19 08:39:57 2002
+++ gcc/Makefile.in	Fri Jul 19 09:20:49 2002
@@ -277,6 +277,7 @@ lang_specs_files=@lang_specs_files@
 lang_options_files=@lang_options_files@
 lang_tree_files=@lang_tree_files@
 target_cpu_default=@target_cpu_default@
+target_arch_default=@target_arch_default@
 GCC_THREAD_FILE=@thread_file@
 OBJC_BOEHM_GC=@objc_boehm_gc@
 GTHREAD_FLAGS=@gthread_flags@
@@ -856,23 +857,28 @@ cs-config.h: Makefile
 	TM_DEFINES="$(tm_defines)" \
 	HEADERS="$(host_xm_file)" XM_DEFINES="$(host_xm_defines)" \
 	TARGET_CPU_DEFAULT="$(target_cpu_default)" \
+	TARGET_ARCH_DEFAULT="$(target_arch_default)" \
 	$(SHELL) $(srcdir)/mkconfig.sh config.h
 
 cs-hconfig.h: Makefile
 	TM_DEFINES="$(tm_defines)" \
 	HEADERS="$(build_xm_file)" XM_DEFINES="$(build_xm_defines)" \
 	TARGET_CPU_DEFAULT="$(target_cpu_default)" \
+	TARGET_ARCH_DEFAULT="$(target_arch_default)" \
 	$(SHELL) $(srcdir)/mkconfig.sh hconfig.h
 
 cs-tconfig.h: Makefile
 	TM_DEFINES="$(tm_defines)" \
 	HEADERS="$(xm_file)" XM_DEFINES="$(xm_defines)" \
 	TARGET_CPU_DEFAULT="" \
+	TARGET_ARCH_DEFAULT="" \
 	$(SHELL) $(srcdir)/mkconfig.sh tconfig.h
 
 cs-tm_p.h: Makefile
 	TM_DEFINES="" \
-	HEADERS="$(tm_p_file)" XM_DEFINES="" TARGET_CPU_DEFAULT="" \
+	HEADERS="$(tm_p_file)" XM_DEFINES="" \
+	TARGET_CPU_DEFAULT="" \
+	TARGET_ARCH_DEFAULT="" \
 	$(SHELL) $(srcdir)/mkconfig.sh tm_p.h
 
 # Don't automatically run autoconf, since configure.in might be accidentally
--- gcc/config.gcc.arch	Fri Jul 19 08:39:59 2002
+++ gcc/config.gcc	Fri Jul 19 10:15:37 2002
@@ -133,6 +133,8 @@
 #
 #  target_cpu_default	Set to override the default target model.
 #
+#  target_arch_default	Set to override the default arch model.
+#
 #  build_install_headers_dir
 #			Target to use when installing header files.
 #
@@ -197,6 +199,8 @@ float_format=
 use_collect2=
 # Set this to override the default target model.
 target_cpu_default=
+# Set this to override the default arch model.
+target_arch_default=
 # Set this to control how the header file directory is installed.
 install_headers_dir=install-headers-tar
 # Set this if directory names should be truncated to 14 characters.
@@ -252,13 +256,40 @@ arm*-*-*)
 xscale-*-*)
 	cpu_type=arm
 	;;
-i[34567]86-*-*)
-	cpu_type=i386
-	extra_headers="mmintrin.h xmmintrin.h"
-	;;
-x86_64-*-*)
+i[34567]86-*-* | x86_64-*-*)
 	cpu_type=i386
 	extra_headers="mmintrin.h xmmintrin.h"
+	case $machine in
+	x86_64-*-*)
+		target_arch_default=TARGET_CPU_DEFAULT_athlon_sse
+		;;
+	*)
+		target_arch_default=TARGET_CPU_DEFAULT_i386
+		;;
+	esac
+	case x"$with_arch" in
+	x)
+		;;
+	xi586)
+		target_arch_default="TARGET_CPU_DEFAULT_pentium"
+		;;
+	xi686 | xi786)
+		target_arch_default="TARGET_CPU_DEFAULT_pentiumpro"
+		;;
+	xi386 | xi486 | xpentium | xpentium-mmx | xpentiumpro \
+	| xpentium2 | xpentium3 | xpentium4 | xk6 | xk6-2 | xk6-3 \
+	| xathlon | xathlon-4)
+		target_arch_default="TARGET_CPU_DEFAULT_$with_arch"
+		;;
+	xyes | xno)
+		echo "--with-arch must be passed a value" 1>&2
+		exit 1
+		;;
+	*)
+		echo "Unknown arch used with --with-arch=$with_arch" 1>&2
+		exit 1
+		;;
+	esac
 	;;
 ia64-*-*)
 	extra_headers=ia64intrin.h
--- gcc/config/i386/i386.c.arch	Thu Jul 18 12:54:03 2002
+++ gcc/config/i386/i386.c	Fri Jul 19 09:20:55 2002
@@ -944,7 +944,7 @@ override_options ()
   if (!ix86_cpu_string)
     ix86_cpu_string = cpu_names [TARGET_CPU_DEFAULT];
   if (!ix86_arch_string)
-    ix86_arch_string = TARGET_64BIT ? "athlon-4" : "i386";
+    ix86_arch_string = cpu_names [TARGET_ARCH_DEFAULT];
 
   if (ix86_cmodel_string != 0)
     {
--- gcc/configure.in.arch	Fri Jul 19 08:39:59 2002
+++ gcc/configure.in	Fri Jul 19 09:22:23 2002
@@ -2691,6 +2691,7 @@ AC_SUBST(target_alias)
 AC_SUBST(c_target_objs)
 AC_SUBST(cxx_target_objs)
 AC_SUBST(target_cpu_default)
+AC_SUBST(target_arch_default)
 
 AC_SUBST_FILE(target_overrides)
 AC_SUBST_FILE(host_overrides)
--- gcc/doc/install.texi.arch	Sun Jun 30 23:23:28 2002
+++ gcc/doc/install.texi	Fri Jul 19 10:34:34 2002
@@ -677,6 +677,14 @@ SPARC@.  If configure does not recognize
 603e, or ultrasparc) you provide, please check the configure script
 for a complete list of supported models.
 
+@item --with-arch=@var{cpu}
+Also specify which cpu variant the compiler should generate code for
+by default.  For some processors, like the i386 family,
+@option{--with-cpu-@var{cpu}} will only schedule things appropriately
+for @var{cpu}. the compiler will not generate any code that
+does not run on the i386 without @option{--with-arch-@var{cpu}}.
+This is currently only supported on the i386 family of processors.
+
 @item --enable-altivec
 Specify that the target supports AltiVec vector enhancements.  This
 option will adjust the ABI for AltiVec enhancements, as well as generate
--- gcc/mkconfig.sh.arch	Sun Jun 23 08:33:42 2002
+++ gcc/mkconfig.sh	Fri Jul 19 09:21:50 2002
@@ -19,6 +19,12 @@ if [ "$TARGET_CPU_DEFAULT" != "" ]; then
     echo "#define TARGET_CPU_DEFAULT ($TARGET_CPU_DEFAULT)" >> ${output}T
 fi
 
+# Define TARGET_ARCH_DEFAULT if the system wants one.
+# This substitutes for lots of *.h files.
+if [ "$TARGET_ARCH_DEFAULT" != "" ]; then
+    echo "#define TARGET_ARCH_DEFAULT ($TARGET_ARCH_DEFAULT)" >> ${output}T
+fi
+
 # Provide defines for other target machine macros to be used everywhere.
 for def in $TM_DEFINES; do
     echo "#ifndef $def" | sed 's/=.*//' >> ${output}T


More information about the Gcc-patches mailing list