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