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