1 # ===========================================================================
2 # http://autoconf-archive.cryp.to/ax_cc_maxopt.html
3 # ===========================================================================
11 # Try to turn on "good" C optimization flags for various compilers and
12 # architectures, for some definition of "good". (In our case, good for
13 # FFTW and hopefully for other scientific codes. Modify as needed.)
15 # The user can override the flags by setting the CFLAGS environment
16 # variable. The user can also specify --enable-portable-binary in order to
17 # disable any optimization flags that might result in a binary that only
18 # runs on the host architecture.
20 # Note also that the flags assume that ANSI C aliasing rules are followed
21 # by the code (e.g. for gcc's -fstrict-aliasing), and that floating-point
22 # computations can be re-ordered as needed.
24 # Requires macros: AX_CHECK_COMPILER_FLAGS, AX_COMPILER_VENDOR,
25 # AX_GCC_ARCHFLAG, AX_GCC_X86_CPUID.
33 # Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
34 # Copyright (c) 2008 Matteo Frigo
36 # This program is free software: you can redistribute it and/or modify it
37 # under the terms of the GNU General Public License as published by the
38 # Free Software Foundation, either version 3 of the License, or (at your
39 # option) any later version.
41 # This program is distributed in the hope that it will be useful, but
42 # WITHOUT ANY WARRANTY; without even the implied warranty of
43 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
44 # Public License for more details.
46 # You should have received a copy of the GNU General Public License along
47 # with this program. If not, see <http://www.gnu.org/licenses/>.
49 # As a special exception, the respective Autoconf Macro's copyright owner
50 # gives unlimited permission to copy, distribute and modify the configure
51 # scripts that are the output of Autoconf when processing the Macro. You
52 # need not follow the terms of the GNU General Public License when using
53 # or distributing such scripts, even though portions of the text of the
54 # Macro appear in them. The GNU General Public License (GPL) does govern
55 # all other use of the material that constitutes the Autoconf Macro.
57 # This special exception to the GPL applies to versions of the Autoconf
58 # Macro released by the Autoconf Macro Archive. When you make and
59 # distribute a modified version of the Autoconf Macro, you may extend this
60 # special exception to the GPL to apply to your modified version as well.
62 AC_DEFUN([AX_CC_MAXOPT],
64 AC_REQUIRE([AC_PROG_CC])
65 AC_REQUIRE([AX_COMPILER_VENDOR])
66 AC_REQUIRE([AC_CANONICAL_HOST])
68 AC_ARG_ENABLE(portable-binary, [AC_HELP_STRING([--enable-portable-binary], [disable compiler optimizations that would produce unportable binaries])],
69 acx_maxopt_portable=$withval, acx_maxopt_portable=no)
71 # Try to determine "good" native compiler flags if none specified via CFLAGS
72 if test "$ac_test_CFLAGS" != "set"; then
74 case $ax_cv_c_compiler_vendor in
75 dec) CFLAGS="-newc -w0 -O5 -ansi_alias -ansi_args -fp_reorder -tune host"
76 if test "x$acx_maxopt_portable" = xno; then
77 CFLAGS="$CFLAGS -arch host"
80 sun) CFLAGS="-native -fast -xO5 -dalign"
81 if test "x$acx_maxopt_portable" = xyes; then
82 CFLAGS="$CFLAGS -xarch=generic"
85 hp) CFLAGS="+Oall +Optrs_ansi +DSnative"
86 if test "x$acx_maxopt_portable" = xyes; then
87 CFLAGS="$CFLAGS +DAportable"
90 ibm) if test "x$acx_maxopt_portable" = xno; then
91 xlc_opt="-qarch=auto -qtune=auto"
95 AX_CHECK_COMPILER_FLAGS($xlc_opt,
96 CFLAGS="-O3 -qansialias -w $xlc_opt",
97 [CFLAGS="-O3 -qansialias -w"
98 echo "******************************************************"
99 echo "* You seem to have the IBM C compiler. It is *"
100 echo "* recommended for best performance that you use: *"
102 echo "* CFLAGS=-O3 -qarch=xxx -qtune=xxx -qansialias -w *"
104 echo "* where xxx is pwr2, pwr3, 604, or whatever kind of *"
105 echo "* CPU you have. (Set the CFLAGS environment var. *"
106 echo "* and re-run configure.) For more info, man cc. *"
107 echo "******************************************************"])
110 intel) CFLAGS="-O3 -ansi_alias"
111 if test "x$acx_maxopt_portable" = xno; then
116 # icc accepts gcc assembly syntax, so these should work:
119 case $ax_cv_gcc_x86_cpuid_0 in # see AX_GCC_ARCHFLAG
120 *:756e6547:*:*) # Intel
121 case $ax_cv_gcc_x86_cpuid_1 in
122 *6a?:*[[234]]:*:*|*6[[789b]]?:*:*:*) icc_flags="-xK";;
123 *f3[[347]]:*:*:*|*f4[1347]:*:*:*) icc_flags="-xP -xN -xW -xK";;
124 *f??:*:*:*) icc_flags="-xN -xW -xK";;
128 if test "x$icc_flags" != x; then
129 for flag in $icc_flags; do
130 AX_CHECK_COMPILER_FLAGS($flag, [icc_archflag=$flag; break])
133 AC_MSG_CHECKING([for icc architecture flag])
134 AC_MSG_RESULT($icc_archflag)
135 if test "x$icc_archflag" != xunknown; then
136 CFLAGS="$CFLAGS $icc_archflag"
142 # default optimization flags for gcc on all systems
143 CFLAGS="-O3 -fomit-frame-pointer"
145 # -malign-double for x86 systems
146 AX_CHECK_COMPILER_FLAGS(-malign-double, CFLAGS="$CFLAGS -malign-double")
148 # -fstrict-aliasing for gcc-2.95+
149 AX_CHECK_COMPILER_FLAGS(-fstrict-aliasing,
150 CFLAGS="$CFLAGS -fstrict-aliasing")
152 # note that we enable "unsafe" fp optimization with other compilers, too
153 AX_CHECK_COMPILER_FLAGS(-ffast-math, CFLAGS="$CFLAGS -ffast-math")
155 AX_GCC_ARCHFLAG($acx_maxopt_portable)
159 if test -z "$CFLAGS"; then
161 echo "********************************************************"
162 echo "* WARNING: Don't know the best CFLAGS for this system *"
163 echo "* Use ./configure CFLAGS=... to specify your own flags *"
164 echo "* (otherwise, a default of CFLAGS=-O3 will be used) *"
165 echo "********************************************************"
170 AX_CHECK_COMPILER_FLAGS($CFLAGS, [], [
172 echo "********************************************************"
173 echo "* WARNING: The guessed CFLAGS don't seem to work with *"
174 echo "* your compiler. *"
175 echo "* Use ./configure CFLAGS=... to specify your own flags *"
176 echo "********************************************************"