| 1 |
# =========================================================================== |
| 2 |
# https://www.gnu.org/software/autoconf-archive/ax_cc_maxopt.html |
| 3 |
# =========================================================================== |
| 4 |
# |
| 5 |
# SYNOPSIS |
| 6 |
# |
| 7 |
# AX_CC_MAXOPT |
| 8 |
# |
| 9 |
# DESCRIPTION |
| 10 |
# |
| 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.) |
| 14 |
# |
| 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. |
| 19 |
# |
| 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. |
| 23 |
# |
| 24 |
# Requires macros: AX_CHECK_COMPILE_FLAG, AX_COMPILER_VENDOR, |
| 25 |
# AX_GCC_ARCHFLAG, AX_GCC_X86_CPUID. |
| 26 |
# |
| 27 |
# LICENSE |
| 28 |
# |
| 29 |
# Copyright (c) 2008 Steven G. Johnson <[email protected]> |
| 30 |
# Copyright (c) 2008 Matteo Frigo |
| 31 |
# |
| 32 |
# This program is free software: you can redistribute it and/or modify it |
| 33 |
# under the terms of the GNU General Public License as published by the |
| 34 |
# Free Software Foundation, either version 3 of the License, or (at your |
| 35 |
# option) any later version. |
| 36 |
# |
| 37 |
# This program is distributed in the hope that it will be useful, but |
| 38 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 39 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
| 40 |
# Public License for more details. |
| 41 |
# |
| 42 |
# You should have received a copy of the GNU General Public License along |
| 43 |
# with this program. If not, see <https://www.gnu.org/licenses/>. |
| 44 |
# |
| 45 |
# As a special exception, the respective Autoconf Macro's copyright owner |
| 46 |
# gives unlimited permission to copy, distribute and modify the configure |
| 47 |
# scripts that are the output of Autoconf when processing the Macro. You |
| 48 |
# need not follow the terms of the GNU General Public License when using |
| 49 |
# or distributing such scripts, even though portions of the text of the |
| 50 |
# Macro appear in them. The GNU General Public License (GPL) does govern |
| 51 |
# all other use of the material that constitutes the Autoconf Macro. |
| 52 |
# |
| 53 |
# This special exception to the GPL applies to versions of the Autoconf |
| 54 |
# Macro released by the Autoconf Archive. When you make and distribute a |
| 55 |
# modified version of the Autoconf Macro, you may extend this special |
| 56 |
# exception to the GPL to apply to your modified version as well. |
| 57 |
|
| 58 |
#serial 22 |
| 59 |
|
| 60 |
AC_DEFUN([AX_CC_MAXOPT], |
| 61 |
[ |
| 62 |
AC_REQUIRE([AC_PROG_CC]) |
| 63 |
AC_REQUIRE([AX_COMPILER_VENDOR]) |
| 64 |
AC_REQUIRE([AC_CANONICAL_HOST]) |
| 65 |
|
| 66 |
AC_ARG_ENABLE(portable-binary, [AS_HELP_STRING([--enable-portable-binary], [disable compiler optimizations that would produce unportable binaries])], |
| 67 |
acx_maxopt_portable=$enableval, acx_maxopt_portable=no) |
| 68 |
|
| 69 |
# Try to determine "good" native compiler flags if none specified via CFLAGS |
| 70 |
if test "x$ac_test_CFLAGS" = "x"; then |
| 71 |
case $ax_cv_c_compiler_vendor in |
| 72 |
dec) CFLAGS="$CFLAGS -newc -w0 -O5 -ansi_alias -ansi_args -fp_reorder -tune host" |
| 73 |
if test "x$acx_maxopt_portable" = xno; then |
| 74 |
CFLAGS="$CFLAGS -arch host" |
| 75 |
fi;; |
| 76 |
|
| 77 |
sun) CFLAGS="$CFLAGS -native -fast -xO5 -dalign" |
| 78 |
if test "x$acx_maxopt_portable" = xyes; then |
| 79 |
CFLAGS="$CFLAGS -xarch=generic" |
| 80 |
fi;; |
| 81 |
|
| 82 |
hp) CFLAGS="$CFLAGS +Oall +Optrs_ansi +DSnative" |
| 83 |
if test "x$acx_maxopt_portable" = xyes; then |
| 84 |
CFLAGS="$CFLAGS +DAportable" |
| 85 |
fi;; |
| 86 |
|
| 87 |
ibm) if test "x$acx_maxopt_portable" = xno; then |
| 88 |
xlc_opt="-qarch=auto -qtune=auto" |
| 89 |
else |
| 90 |
xlc_opt="-qtune=auto" |
| 91 |
fi |
| 92 |
AX_CHECK_COMPILE_FLAG($xlc_opt, |
| 93 |
CFLAGS="$CFLAGS -O3 -qansialias -w $xlc_opt", |
| 94 |
[CFLAGS="$CFLAGS -O3 -qansialias -w" |
| 95 |
echo "******************************************************" |
| 96 |
echo "* You seem to have the IBM C compiler. It is *" |
| 97 |
echo "* recommended for best performance that you use: *" |
| 98 |
echo "* *" |
| 99 |
echo "* CFLAGS=-O3 -qarch=xxx -qtune=xxx -qansialias -w *" |
| 100 |
echo "* ^^^ ^^^ *" |
| 101 |
echo "* where xxx is pwr2, pwr3, 604, or whatever kind of *" |
| 102 |
echo "* CPU you have. (Set the CFLAGS environment var. *" |
| 103 |
echo "* and re-run configure.) For more info, man cc. *" |
| 104 |
echo "******************************************************"]) |
| 105 |
;; |
| 106 |
|
| 107 |
intel) CFLAGS="$CFLAGS -O3 -ansi_alias" |
| 108 |
if test "x$acx_maxopt_portable" = xno; then |
| 109 |
icc_archflag=unknown |
| 110 |
icc_flags="" |
| 111 |
case $host_cpu in |
| 112 |
i686*|x86_64*) |
| 113 |
# icc accepts gcc assembly syntax, so these should work: |
| 114 |
AX_GCC_X86_CPUID(0) |
| 115 |
AX_GCC_X86_CPUID(1) |
| 116 |
case $ax_cv_gcc_x86_cpuid_0 in # see AX_GCC_ARCHFLAG |
| 117 |
*:756e6547:6c65746e:49656e69) # Intel |
| 118 |
case $ax_cv_gcc_x86_cpuid_1 in |
| 119 |
*0?6[[78ab]]?:*:*:*|?6[[78ab]]?:*:*:*|6[[78ab]]?:*:*:*) icc_flags="-xK" ;; |
| 120 |
*0?6[[9d]]?:*:*:*|?6[[9d]]?:*:*:*|6[[9d]]?:*:*:*|*1?65?:*:*:*) icc_flags="-xSSE2 -xB -xK" ;; |
| 121 |
*0?6e?:*:*:*|?6e?:*:*:*|6e?:*:*:*) icc_flags="-xSSE3 -xP -xO -xB -xK" ;; |
| 122 |
*0?6f?:*:*:*|?6f?:*:*:*|6f?:*:*:*|*1?66?:*:*:*) icc_flags="-xSSSE3 -xT -xB -xK" ;; |
| 123 |
*1?6[[7d]]?:*:*:*) icc_flags="-xSSE4.1 -xS -xT -xB -xK" ;; |
| 124 |
*1?6[[aef]]?:*:*:*|*2?6[[5cef]]?:*:*:*) icc_flags="-xSSE4.2 -xS -xT -xB -xK" ;; |
| 125 |
*2?6[[ad]]?:*:*:*) icc_flags="-xAVX -SSE4.2 -xS -xT -xB -xK" ;; |
| 126 |
*3?6[[ae]]?:*:*:*) icc_flags="-xCORE-AVX-I -xAVX -SSE4.2 -xS -xT -xB -xK" ;; |
| 127 |
*3?6[[cf]]?:*:*:*|*4?6[[56]]?:*:*:*) icc_flags="-xCORE-AVX2 -xCORE-AVX-I -xAVX -SSE4.2 -xS -xT -xB -xK" ;; |
| 128 |
*000?f[[346]]?:*:*:*|?f[[346]]?:*:*:*|f[[346]]?:*:*:*) icc_flags="-xSSE3 -xP -xO -xN -xW -xK" ;; |
| 129 |
*00??f??:*:*:*|??f??:*:*:*|?f??:*:*:*|f??:*:*:*) icc_flags="-xSSE2 -xN -xW -xK" ;; |
| 130 |
esac ;; |
| 131 |
esac ;; |
| 132 |
esac |
| 133 |
if test "x$icc_flags" != x; then |
| 134 |
for flag in $icc_flags; do |
| 135 |
AX_CHECK_COMPILE_FLAG($flag, [icc_archflag=$flag; break]) |
| 136 |
done |
| 137 |
fi |
| 138 |
AC_MSG_CHECKING([for icc architecture flag]) |
| 139 |
AC_MSG_RESULT($icc_archflag) |
| 140 |
if test "x$icc_archflag" != xunknown; then |
| 141 |
CFLAGS="$CFLAGS $icc_archflag" |
| 142 |
fi |
| 143 |
fi |
| 144 |
;; |
| 145 |
|
| 146 |
nvhpc) |
| 147 |
# default optimization flags for nvhpc |
| 148 |
CFLAGS="$CFLAGS -O3" |
| 149 |
;; |
| 150 |
|
| 151 |
gnu) |
| 152 |
# default optimization flags for gcc on all systems |
| 153 |
CFLAGS="$CFLAGS -O3 -fomit-frame-pointer" |
| 154 |
|
| 155 |
# -malign-double for x86 systems |
| 156 |
# LIBFFI_LOCAL: don't do this. |
| 157 |
# The testsuite doesn't use these flags and we'll get test failures. |
| 158 |
# AX_CHECK_COMPILE_FLAG(-malign-double, CFLAGS="$CFLAGS -malign-double") |
| 159 |
|
| 160 |
# -fstrict-aliasing for gcc-2.95+ |
| 161 |
AX_CHECK_COMPILE_FLAG(-fstrict-aliasing, |
| 162 |
CFLAGS="$CFLAGS -fstrict-aliasing") |
| 163 |
|
| 164 |
# note that we enable "unsafe" fp optimization with other compilers, too |
| 165 |
AX_CHECK_COMPILE_FLAG(-ffast-math, CFLAGS="$CFLAGS -ffast-math") |
| 166 |
|
| 167 |
AX_GCC_ARCHFLAG($acx_maxopt_portable) |
| 168 |
;; |
| 169 |
|
| 170 |
microsoft) |
| 171 |
# default optimization flags for MSVC opt builds |
| 172 |
CFLAGS="$CFLAGS -O2" |
| 173 |
;; |
| 174 |
esac |
| 175 |
|
| 176 |
if test -z "$CFLAGS"; then |
| 177 |
echo "" |
| 178 |
echo "********************************************************" |
| 179 |
echo "* WARNING: Don't know the best CFLAGS for this system *" |
| 180 |
echo "* Use ./configure CFLAGS=... to specify your own flags *" |
| 181 |
echo "* (otherwise, a default of CFLAGS=-O3 will be used) *" |
| 182 |
echo "********************************************************" |
| 183 |
echo "" |
| 184 |
CFLAGS="$CFLAGS -O3" |
| 185 |
fi |
| 186 |
|
| 187 |
AX_CHECK_COMPILE_FLAG($CFLAGS, [], [ |
| 188 |
echo "" |
| 189 |
echo "********************************************************" |
| 190 |
echo "* WARNING: The guessed CFLAGS don't seem to work with *" |
| 191 |
echo "* your compiler. *" |
| 192 |
echo "* Use ./configure CFLAGS=... to specify your own flags *" |
| 193 |
echo "********************************************************" |
| 194 |
echo "" |
| 195 |
]) |
| 196 |
|
| 197 |
fi |
| 198 |
]) |