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