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