blob: 61820ea1218908c0041e2ec20654815eebd41961 [file] [log] [blame]
cristya0459972013-11-03 18:09:35 +00001# ===========================================================================
2# http://www.gnu.org/software/autoconf-archive/ax_gcc_archflag.html
3# ===========================================================================
4#
5# SYNOPSIS
6#
7# AX_GCC_ARCHFLAG([PORTABLE?], [ACTION-SUCCESS], [ACTION-FAILURE])
8#
9# DESCRIPTION
10#
11# This macro tries to guess the "native" arch corresponding to the target
12# architecture for use with gcc's -march=arch or -mtune=arch flags. If
13# found, the cache variable $ax_cv_gcc_archflag is set to this flag and
14# ACTION-SUCCESS is executed; otherwise $ax_cv_gcc_archflag is set to
15# "unknown" and ACTION-FAILURE is executed. The default ACTION-SUCCESS is
16# to add $ax_cv_gcc_archflag to the end of $CFLAGS.
17#
18# PORTABLE? should be either [yes] (default) or [no]. In the former case,
19# the flag is set to -mtune (or equivalent) so that the architecture is
20# only used for tuning, but the instruction set used is still portable. In
21# the latter case, the flag is set to -march (or equivalent) so that
22# architecture-specific instructions are enabled.
23#
24# The user can specify --with-gcc-arch=<arch> in order to override the
25# macro's choice of architecture, or --without-gcc-arch to disable this.
26#
27# When cross-compiling, or if $CC is not gcc, then ACTION-FAILURE is
28# called unless the user specified --with-gcc-arch manually.
29#
30# Requires macros: AX_CHECK_COMPILE_FLAG, AX_GCC_X86_CPUID
31#
32# (The main emphasis here is on recent CPUs, on the principle that doing
33# high-performance computing on old hardware is uncommon.)
34#
35# LICENSE
36#
37# Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
38# Copyright (c) 2008 Matteo Frigo
39# Copyright (c) 2012 Tsukasa Oi
40#
41# This program is free software: you can redistribute it and/or modify it
42# under the terms of the GNU General Public License as published by the
43# Free Software Foundation, either version 3 of the License, or (at your
44# option) any later version.
45#
46# This program is distributed in the hope that it will be useful, but
47# WITHOUT ANY WARRANTY; without even the implied warranty of
48# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
49# Public License for more details.
50#
51# You should have received a copy of the GNU General Public License along
52# with this program. If not, see <http://www.gnu.org/licenses/>.
53#
54# As a special exception, the respective Autoconf Macro's copyright owner
55# gives unlimited permission to copy, distribute and modify the configure
56# scripts that are the output of Autoconf when processing the Macro. You
57# need not follow the terms of the GNU General Public License when using
58# or distributing such scripts, even though portions of the text of the
59# Macro appear in them. The GNU General Public License (GPL) does govern
60# all other use of the material that constitutes the Autoconf Macro.
61#
62# This special exception to the GPL applies to versions of the Autoconf
63# Macro released by the Autoconf Archive. When you make and distribute a
64# modified version of the Autoconf Macro, you may extend this special
65# exception to the GPL to apply to your modified version as well.
66
cristy17491be2014-06-24 01:10:53 +000067#serial 14
cristya0459972013-11-03 18:09:35 +000068
69AC_DEFUN([AX_GCC_ARCHFLAG],
70[AC_REQUIRE([AC_PROG_CC])
71AC_REQUIRE([AC_CANONICAL_HOST])
cristy17491be2014-06-24 01:10:53 +000072AC_REQUIRE([AC_PROG_SED])
cristya0459972013-11-03 18:09:35 +000073
74AC_ARG_WITH(gcc-arch, [AS_HELP_STRING([--with-gcc-arch=<arch>], [use architecture <arch> for gcc -march/-mtune, instead of guessing])],
cristy17491be2014-06-24 01:10:53 +000075 ax_gcc_arch=$withval, ax_gcc_arch=yes)
cristya0459972013-11-03 18:09:35 +000076
77AC_MSG_CHECKING([for gcc architecture flag])
78AC_MSG_RESULT([])
79AC_CACHE_VAL(ax_cv_gcc_archflag,
80[
81ax_cv_gcc_archflag="unknown"
82
83if test "$GCC" = yes; then
84
85if test "x$ax_gcc_arch" = xyes; then
86ax_gcc_arch=""
87if test "$cross_compiling" = no; then
88case $host_cpu in
cristy17491be2014-06-24 01:10:53 +000089 i[[3456]]86*|x86_64*|amd64*) # use cpuid codes
cristya0459972013-11-03 18:09:35 +000090 AX_GCC_X86_CPUID(0)
91 AX_GCC_X86_CPUID(1)
92 case $ax_cv_gcc_x86_cpuid_0 in
93 *:756e6547:*:*) # Intel
94 case $ax_cv_gcc_x86_cpuid_1 in
95 *5[[48]]?:*:*:*) ax_gcc_arch="pentium-mmx pentium" ;;
96 *5??:*:*:*) ax_gcc_arch=pentium ;;
cristya0459972013-11-03 18:09:35 +000097 *1?6[[7d]]?:*:*:*) ax_gcc_arch="penryn core2 pentium-m pentium3 pentiumpro" ;;
98 *1?6[[aef]]?:*:*:*|*2?6[[5cef]]?:*:*:*) ax_gcc_arch="corei7 core2 pentium-m pentium3 pentiumpro" ;;
99 *1?6c?:*:*:*|*[[23]]?66?:*:*:*) ax_gcc_arch="atom core2 pentium-m pentium3 pentiumpro" ;;
100 *2?6[[ad]]?:*:*:*) ax_gcc_arch="corei7-avx corei7 core2 pentium-m pentium3 pentiumpro" ;;
cristy17491be2014-06-24 01:10:53 +0000101 *[[1-9a-f]]?6??:*:*:*) ax_gcc_arch="core2 pentiumpro" ;;
102 *6[[3456]]?:*:*:*) ax_gcc_arch="pentium2 pentiumpro" ;;
103 *6a?:*[[01]]:*:*) ax_gcc_arch="pentium2 pentiumpro" ;;
104 *6a?:*[[234]]:*:*) ax_gcc_arch="pentium3 pentiumpro" ;;
105 *6[[9de]]?:*:*:*) ax_gcc_arch="pentium-m pentium3 pentiumpro" ;;
106 *6[[78b]]?:*:*:*) ax_gcc_arch="pentium3 pentiumpro" ;;
107 *6f?:*:*:*) ax_gcc_arch="core2 pentium-m pentium3 pentiumpro" ;;
108 *6??:*:*:*) ax_gcc_arch=pentiumpro ;;
109 *f3[[347]]:*:*:*|*f4[1347]:*:*:*|*f6?:*:*:*)
cristya0459972013-11-03 18:09:35 +0000110 case $host_cpu in
111 x86_64*) ax_gcc_arch="nocona pentium4 pentiumpro" ;;
112 *) ax_gcc_arch="prescott pentium4 pentiumpro" ;;
113 esac ;;
cristy17491be2014-06-24 01:10:53 +0000114 *f??:*:*:*) ax_gcc_arch="pentium4 pentiumpro";;
cristya0459972013-11-03 18:09:35 +0000115 esac ;;
116 *:68747541:*:*) # AMD
117 case $ax_cv_gcc_x86_cpuid_1 in
118 *5[[67]]?:*:*:*) ax_gcc_arch=k6 ;;
119 *5[[8d]]?:*:*:*) ax_gcc_arch="k6-2 k6" ;;
120 *5[[9]]?:*:*:*) ax_gcc_arch="k6-3 k6" ;;
121 *60?:*:*:*) ax_gcc_arch=k7 ;;
122 *6[[12]]?:*:*:*) ax_gcc_arch="athlon k7" ;;
123 *6[[34]]?:*:*:*) ax_gcc_arch="athlon-tbird k7" ;;
124 *67?:*:*:*) ax_gcc_arch="athlon-4 athlon k7" ;;
125 *6[[68a]]?:*:*:*)
126 AX_GCC_X86_CPUID(0x80000006) # L2 cache size
127 case $ax_cv_gcc_x86_cpuid_0x80000006 in
128 *:*:*[[1-9a-f]]??????:*) # (L2 = ecx >> 16) >= 256
129 ax_gcc_arch="athlon-xp athlon-4 athlon k7" ;;
130 *) ax_gcc_arch="athlon-4 athlon k7" ;;
131 esac ;;
cristy17491be2014-06-24 01:10:53 +0000132 *5??f??:*:*:*) ax_gcc_arch="btver1 amdfam10 k8" ;;
133 *6??f??:*:*:*) ax_gcc_arch="bdver1 amdfam10 k8" ;;
134 *[[1-9a-f]]??f??:*:*:*) ax_gcc_arch="amdfam10 k8" ;;
135 *f[[4cef8b]]?:*:*:*) ax_gcc_arch="athlon64 k8" ;;
136 *f5?:*:*:*) ax_gcc_arch="opteron k8" ;;
137 *f7?:*:*:*) ax_gcc_arch="athlon-fx opteron k8" ;;
138 *f??:*:*:*) ax_gcc_arch="k8" ;;
cristya0459972013-11-03 18:09:35 +0000139 esac ;;
140 *:746e6543:*:*) # IDT
141 case $ax_cv_gcc_x86_cpuid_1 in
142 *54?:*:*:*) ax_gcc_arch=winchip-c6 ;;
143 *58?:*:*:*) ax_gcc_arch=winchip2 ;;
144 *6[[78]]?:*:*:*) ax_gcc_arch=c3 ;;
145 *69?:*:*:*) ax_gcc_arch="c3-2 c3" ;;
146 esac ;;
147 esac
148 if test x"$ax_gcc_arch" = x; then # fallback
149 case $host_cpu in
150 i586*) ax_gcc_arch=pentium ;;
151 i686*) ax_gcc_arch=pentiumpro ;;
152 esac
153 fi
154 ;;
155
156 sparc*)
157 AC_PATH_PROG([PRTDIAG], [prtdiag], [prtdiag], [$PATH:/usr/platform/`uname -i`/sbin/:/usr/platform/`uname -m`/sbin/])
158 cputype=`(((grep cpu /proc/cpuinfo | cut -d: -f2) ; ($PRTDIAG -v |grep -i sparc) ; grep -i cpu /var/run/dmesg.boot ) | head -n 1) 2> /dev/null`
cristy17491be2014-06-24 01:10:53 +0000159 cputype=`echo "$cputype" | tr -d ' -' | $SED 's/SPARCIIi/SPARCII/' |tr $as_cr_LETTERS $as_cr_letters`
cristya0459972013-11-03 18:09:35 +0000160 case $cputype in
161 *ultrasparciv*) ax_gcc_arch="ultrasparc4 ultrasparc3 ultrasparc v9" ;;
162 *ultrasparciii*) ax_gcc_arch="ultrasparc3 ultrasparc v9" ;;
163 *ultrasparc*) ax_gcc_arch="ultrasparc v9" ;;
164 *supersparc*|*tms390z5[[05]]*) ax_gcc_arch="supersparc v8" ;;
165 *hypersparc*|*rt62[[056]]*) ax_gcc_arch="hypersparc v8" ;;
166 *cypress*) ax_gcc_arch=cypress ;;
167 esac ;;
168
169 alphaev5) ax_gcc_arch=ev5 ;;
170 alphaev56) ax_gcc_arch=ev56 ;;
171 alphapca56) ax_gcc_arch="pca56 ev56" ;;
172 alphapca57) ax_gcc_arch="pca57 pca56 ev56" ;;
173 alphaev6) ax_gcc_arch=ev6 ;;
174 alphaev67) ax_gcc_arch=ev67 ;;
175 alphaev68) ax_gcc_arch="ev68 ev67" ;;
176 alphaev69) ax_gcc_arch="ev69 ev68 ev67" ;;
177 alphaev7) ax_gcc_arch="ev7 ev69 ev68 ev67" ;;
178 alphaev79) ax_gcc_arch="ev79 ev7 ev69 ev68 ev67" ;;
179
180 powerpc*)
cristy17491be2014-06-24 01:10:53 +0000181 cputype=`((grep cpu /proc/cpuinfo | head -n 1 | cut -d: -f2 | cut -d, -f1 | $SED 's/ //g') ; /usr/bin/machine ; /bin/machine; grep CPU /var/run/dmesg.boot | head -n 1 | cut -d" " -f2) 2> /dev/null`
182 cputype=`echo $cputype | $SED -e 's/ppc//g;s/ *//g'`
cristya0459972013-11-03 18:09:35 +0000183 case $cputype in
184 *750*) ax_gcc_arch="750 G3" ;;
185 *740[[0-9]]*) ax_gcc_arch="$cputype 7400 G4" ;;
186 *74[[4-5]][[0-9]]*) ax_gcc_arch="$cputype 7450 G4" ;;
187 *74[[0-9]][[0-9]]*) ax_gcc_arch="$cputype G4" ;;
188 *970*) ax_gcc_arch="970 G5 power4";;
189 *POWER4*|*power4*|*gq*) ax_gcc_arch="power4 970";;
190 *POWER5*|*power5*|*gr*|*gs*) ax_gcc_arch="power5 power4 970";;
191 603ev|8240) ax_gcc_arch="$cputype 603e 603";;
192 *) ax_gcc_arch=$cputype ;;
193 esac
194 ax_gcc_arch="$ax_gcc_arch powerpc"
195 ;;
196esac
197fi # not cross-compiling
198fi # guess arch
199
200if test "x$ax_gcc_arch" != x -a "x$ax_gcc_arch" != xno; then
201for arch in $ax_gcc_arch; do
202 if test "x[]m4_default([$1],yes)" = xyes; then # if we require portable code
203 flags="-mtune=$arch"
204 # -mcpu=$arch and m$arch generate nonportable code on every arch except
205 # x86. And some other arches (e.g. Alpha) don't accept -mtune. Grrr.
206 case $host_cpu in i*86|x86_64*) flags="$flags -mcpu=$arch -m$arch";; esac
207 else
208 flags="-march=$arch -mcpu=$arch -m$arch"
209 fi
210 for flag in $flags; do
211 AX_CHECK_COMPILE_FLAG($flag, [ax_cv_gcc_archflag=$flag; break])
212 done
213 test "x$ax_cv_gcc_archflag" = xunknown || break
214done
215fi
216
217fi # $GCC=yes
218])
219AC_MSG_CHECKING([for gcc architecture flag])
220AC_MSG_RESULT($ax_cv_gcc_archflag)
221if test "x$ax_cv_gcc_archflag" = xunknown; then
222 m4_default([$3],:)
223else
224 m4_default([$2], [CFLAGS="$CFLAGS $ax_cv_gcc_archflag"])
225fi
226])