Chris@10: dnl @synopsis AX_CC_MAXOPT Chris@10: dnl @summary turn on optimization flags for the C compiler Chris@10: dnl @category C Chris@10: dnl Chris@10: dnl Try to turn on "good" C optimization flags for various compilers Chris@10: dnl and architectures, for some definition of "good". (In our case, Chris@10: dnl good for FFTW and hopefully for other scientific codes. Modify Chris@10: dnl as needed.) Chris@10: dnl Chris@10: dnl The user can override the flags by setting the CFLAGS environment Chris@10: dnl variable. Chris@10: dnl Chris@10: dnl Note also that the flags assume that ANSI C aliasing rules are Chris@10: dnl followed by the code (e.g. for gcc's -fstrict-aliasing), and that Chris@10: dnl floating-point computations can be re-ordered as needed. Chris@10: dnl Chris@10: dnl Requires macros: AX_CHECK_COMPILER_FLAGS, AX_COMPILER_VENDOR, Chris@10: dnl Chris@10: dnl @version 2011-06-22 Chris@10: dnl @license GPLWithACException Chris@10: dnl @author Steven G. Johnson and Matteo Frigo. Chris@10: AC_DEFUN([AX_CC_MAXOPT], Chris@10: [ Chris@10: AC_REQUIRE([AC_PROG_CC]) Chris@10: AC_REQUIRE([AX_COMPILER_VENDOR]) Chris@10: AC_REQUIRE([AC_CANONICAL_HOST]) Chris@10: Chris@10: # Try to determine "good" native compiler flags if none specified via CFLAGS Chris@10: if test "$ac_test_CFLAGS" != "set"; then Chris@10: CFLAGS="" Chris@10: case $ax_cv_c_compiler_vendor in Chris@10: dec) CFLAGS="-newc -w0 -O5 -ansi_alias -ansi_args -fp_reorder -tune host" Chris@10: ;; Chris@10: Chris@10: sun) CFLAGS="-native -fast -xO5 -dalign" Chris@10: ;; Chris@10: Chris@10: hp) CFLAGS="+Oall +Optrs_ansi +DSnative" Chris@10: ;; Chris@10: Chris@10: ibm) xlc_opt="-qtune=auto" Chris@10: AX_CHECK_COMPILER_FLAGS($xlc_opt, Chris@10: CFLAGS="-O3 -qansialias -w $xlc_opt", Chris@10: [CFLAGS="-O3 -qansialias -w" Chris@10: echo "******************************************************" Chris@10: echo "* You seem to have the IBM C compiler. It is *" Chris@10: echo "* recommended for best performance that you use: *" Chris@10: echo "* *" Chris@10: echo "* CFLAGS=-O3 -qarch=xxx -qtune=xxx -qansialias -w *" Chris@10: echo "* ^^^ ^^^ *" Chris@10: echo "* where xxx is pwr2, pwr3, 604, or whatever kind of *" Chris@10: echo "* CPU you have. (Set the CFLAGS environment var. *" Chris@10: echo "* and re-run configure.) For more info, man cc. *" Chris@10: echo "******************************************************"]) Chris@10: ;; Chris@10: Chris@10: intel) CFLAGS="-O3" Chris@10: # Intel seems to have changed the spelling of this flag recently Chris@10: icc_ansi_alias="unknown" Chris@10: for flag in -ansi-alias -ansi_alias; do Chris@10: AX_CHECK_COMPILER_FLAGS($flag, [icc_ansi_alias=$flag; break]) Chris@10: done Chris@10: if test "x$icc_ansi_alias" != xunknown; then Chris@10: CFLAGS="$CFLAGS $icc_ansi_alias" Chris@10: fi Chris@10: AX_CHECK_COMPILER_FLAGS(-malign-double, CFLAGS="$CFLAGS -malign-double") Chris@10: # We used to check for architecture flags here, e.g. -xHost etc., Chris@10: # but these flags are problematic. On icc-12.0.0, "-mavx -xHost" Chris@10: # overrides -mavx with -xHost, generating SSE2 code instead of AVX Chris@10: # code. ICC does not seem to support -mtune=host or equivalent Chris@10: # non-ABI changing flag. Chris@10: ;; Chris@10: Chris@10: gnu) Chris@10: # Default optimization flags for gcc on all systems. Chris@10: # Somehow -O3 does not imply -fomit-frame-pointer on ia32 Chris@10: CFLAGS="-O3 -fomit-frame-pointer" Chris@10: Chris@10: # tune for the host by default Chris@10: AX_CHECK_COMPILER_FLAGS(-mtune=native, CFLAGS="$CFLAGS -mtune=native") Chris@10: Chris@10: # -malign-double for x86 systems Chris@10: AX_CHECK_COMPILER_FLAGS(-malign-double, CFLAGS="$CFLAGS -malign-double") Chris@10: Chris@10: # -fstrict-aliasing for gcc-2.95+ Chris@10: AX_CHECK_COMPILER_FLAGS(-fstrict-aliasing, Chris@10: CFLAGS="$CFLAGS -fstrict-aliasing") Chris@10: Chris@10: # -fno-schedule-insns is pretty much required on all risc Chris@10: # processors. Chris@10: # Chris@10: # gcc performs one pass of instruction scheduling, then a pass of Chris@10: # register allocation, then another pass of instruction Chris@10: # scheduling. The first pass reorders instructions in a way that Chris@10: # is pretty much the worst possible for the purposes of register Chris@10: # allocation. We disable the first pass. Chris@10: AX_CHECK_COMPILER_FLAGS(-fno-schedule-insns, CFLAGS="$CFLAGS -fno-schedule-insns") Chris@10: Chris@10: # note that we enable "unsafe" fp optimization with other compilers, too Chris@10: AX_CHECK_COMPILER_FLAGS(-ffast-math, CFLAGS="$CFLAGS -ffast-math") Chris@10: Chris@10: ;; Chris@10: esac Chris@10: Chris@10: if test -z "$CFLAGS"; then Chris@10: echo "" Chris@10: echo "********************************************************" Chris@10: echo "* WARNING: Don't know the best CFLAGS for this system *" Chris@10: echo "* Use ./configure CFLAGS=... to specify your own flags *" Chris@10: echo "* (otherwise, a default of CFLAGS=-O3 will be used) *" Chris@10: echo "********************************************************" Chris@10: echo "" Chris@10: CFLAGS="-O3" Chris@10: fi Chris@10: Chris@10: AX_CHECK_COMPILER_FLAGS($CFLAGS, [], [ Chris@10: echo "" Chris@10: echo "********************************************************" Chris@10: echo "* WARNING: The guessed CFLAGS don't seem to work with *" Chris@10: echo "* your compiler. *" Chris@10: echo "* Use ./configure CFLAGS=... to specify your own flags *" Chris@10: echo "********************************************************" Chris@10: echo "" Chris@10: CFLAGS="" Chris@10: ]) Chris@10: Chris@10: fi Chris@10: ])