Chris@42
|
1 dnl @synopsis AX_CC_MAXOPT
|
Chris@42
|
2 dnl @summary turn on optimization flags for the C compiler
|
Chris@42
|
3 dnl @category C
|
Chris@42
|
4 dnl
|
Chris@42
|
5 dnl Try to turn on "good" C optimization flags for various compilers
|
Chris@42
|
6 dnl and architectures, for some definition of "good". (In our case,
|
Chris@42
|
7 dnl good for FFTW and hopefully for other scientific codes. Modify
|
Chris@42
|
8 dnl as needed.)
|
Chris@42
|
9 dnl
|
Chris@42
|
10 dnl The user can override the flags by setting the CFLAGS environment
|
Chris@42
|
11 dnl variable.
|
Chris@42
|
12 dnl
|
Chris@42
|
13 dnl Note also that the flags assume that ANSI C aliasing rules are
|
Chris@42
|
14 dnl followed by the code (e.g. for gcc's -fstrict-aliasing), and that
|
Chris@42
|
15 dnl floating-point computations can be re-ordered as needed.
|
Chris@42
|
16 dnl
|
Chris@42
|
17 dnl Requires macros: AX_CHECK_COMPILER_FLAGS, AX_COMPILER_VENDOR,
|
Chris@42
|
18 dnl
|
Chris@42
|
19 dnl @version 2011-06-22
|
Chris@42
|
20 dnl @license GPLWithACException
|
Chris@42
|
21 dnl @author Steven G. Johnson <stevenj@alum.mit.edu> and Matteo Frigo.
|
Chris@42
|
22 AC_DEFUN([AX_CC_MAXOPT],
|
Chris@42
|
23 [
|
Chris@42
|
24 AC_REQUIRE([AC_PROG_CC])
|
Chris@42
|
25 AC_REQUIRE([AX_COMPILER_VENDOR])
|
Chris@42
|
26 AC_REQUIRE([AC_CANONICAL_HOST])
|
Chris@42
|
27
|
Chris@42
|
28 # Try to determine "good" native compiler flags if none specified via CFLAGS
|
Chris@42
|
29 if test "$ac_test_CFLAGS" != "set"; then
|
Chris@42
|
30 CFLAGS=""
|
Chris@42
|
31 case $ax_cv_c_compiler_vendor in
|
Chris@42
|
32 dec) CFLAGS="-newc -w0 -O5 -ansi_alias -ansi_args -fp_reorder -tune host"
|
Chris@42
|
33 ;;
|
Chris@42
|
34
|
Chris@42
|
35 sun) CFLAGS="-native -fast -xO5 -dalign"
|
Chris@42
|
36 ;;
|
Chris@42
|
37
|
Chris@42
|
38 hp) CFLAGS="+Oall +Optrs_ansi +DSnative"
|
Chris@42
|
39 ;;
|
Chris@42
|
40
|
Chris@42
|
41 ibm) xlc_opt="-qarch=auto -qtune=auto"
|
Chris@42
|
42 AX_CHECK_COMPILER_FLAGS($xlc_opt,
|
Chris@42
|
43 CFLAGS="-O3 -qalias=ansi -w $xlc_opt",
|
Chris@42
|
44 [CFLAGS="-O3 -qalias=ansi -w"])
|
Chris@42
|
45 ;;
|
Chris@42
|
46
|
Chris@42
|
47 intel) CFLAGS="-O3"
|
Chris@42
|
48 # Intel seems to have changed the spelling of this flag recently
|
Chris@42
|
49 icc_ansi_alias="unknown"
|
Chris@42
|
50 for flag in -ansi-alias -ansi_alias; do
|
Chris@42
|
51 AX_CHECK_COMPILER_FLAGS($flag, [icc_ansi_alias=$flag; break])
|
Chris@42
|
52 done
|
Chris@42
|
53 if test "x$icc_ansi_alias" != xunknown; then
|
Chris@42
|
54 CFLAGS="$CFLAGS $icc_ansi_alias"
|
Chris@42
|
55 fi
|
Chris@42
|
56 AX_CHECK_COMPILER_FLAGS(-malign-double, CFLAGS="$CFLAGS -malign-double")
|
Chris@42
|
57 # We used to check for architecture flags here, e.g. -xHost etc.,
|
Chris@42
|
58 # but these flags are problematic. On icc-12.0.0, "-mavx -xHost"
|
Chris@42
|
59 # overrides -mavx with -xHost, generating SSE2 code instead of AVX
|
Chris@42
|
60 # code. ICC does not seem to support -mtune=host or equivalent
|
Chris@42
|
61 # non-ABI changing flag.
|
Chris@42
|
62 ;;
|
Chris@42
|
63
|
Chris@42
|
64 clang)
|
Chris@42
|
65 CFLAGS="-O3 -fomit-frame-pointer"
|
Chris@42
|
66 AX_CHECK_COMPILER_FLAGS(-mtune=native, CFLAGS="$CFLAGS -mtune=native")
|
Chris@42
|
67 AX_CHECK_COMPILER_FLAGS(-fstrict-aliasing,CFLAGS="$CFLAGS -fstrict-aliasing")
|
Chris@42
|
68 AX_CHECK_COMPILER_FLAGS(-ffast-math, CFLAGS="$CFLAGS -ffast-math")
|
Chris@42
|
69 ;;
|
Chris@42
|
70
|
Chris@42
|
71 gnu)
|
Chris@42
|
72 # Default optimization flags for gcc on all systems.
|
Chris@42
|
73 # Somehow -O3 does not imply -fomit-frame-pointer on ia32
|
Chris@42
|
74 CFLAGS="-O3 -fomit-frame-pointer"
|
Chris@42
|
75
|
Chris@42
|
76 # tune for the host by default
|
Chris@42
|
77 AX_CHECK_COMPILER_FLAGS(-mtune=native, CFLAGS="$CFLAGS -mtune=native")
|
Chris@42
|
78
|
Chris@42
|
79 # -malign-double for x86 systems
|
Chris@42
|
80 AX_CHECK_COMPILER_FLAGS(-malign-double, CFLAGS="$CFLAGS -malign-double")
|
Chris@42
|
81
|
Chris@42
|
82 # -fstrict-aliasing for gcc-2.95+
|
Chris@42
|
83 AX_CHECK_COMPILER_FLAGS(-fstrict-aliasing,
|
Chris@42
|
84 CFLAGS="$CFLAGS -fstrict-aliasing")
|
Chris@42
|
85
|
Chris@42
|
86 # -fno-schedule-insns is pretty much required on all risc
|
Chris@42
|
87 # processors.
|
Chris@42
|
88 #
|
Chris@42
|
89 # gcc performs one pass of instruction scheduling, then a pass of
|
Chris@42
|
90 # register allocation, then another pass of instruction
|
Chris@42
|
91 # scheduling. The first pass reorders instructions in a way that
|
Chris@42
|
92 # is pretty much the worst possible for the purposes of register
|
Chris@42
|
93 # allocation. We disable the first pass.
|
Chris@42
|
94 AX_CHECK_COMPILER_FLAGS(-fno-schedule-insns, CFLAGS="$CFLAGS -fno-schedule-insns")
|
Chris@42
|
95
|
Chris@42
|
96 # note that we enable "unsafe" fp optimization with other compilers, too
|
Chris@42
|
97 AX_CHECK_COMPILER_FLAGS(-ffast-math, CFLAGS="$CFLAGS -ffast-math")
|
Chris@42
|
98
|
Chris@42
|
99 # flags to enable power ISA 2.07 instructions with gcc (always true with vsx)
|
Chris@42
|
100 if test "$have_vsx" = "yes"; then
|
Chris@42
|
101 AX_CHECK_COMPILER_FLAGS(-mcpu=power8, CFLAGS="$CFLAGS -mcpu=power8")
|
Chris@42
|
102 AX_CHECK_COMPILER_FLAGS(-mpower8-fusion, CFLAGS="$CFLAGS -mpower8-fusion")
|
Chris@42
|
103 AX_CHECK_COMPILER_FLAGS(-mpower8-vector, CFLAGS="$CFLAGS -mpower8-vector")
|
Chris@42
|
104 AX_CHECK_COMPILER_FLAGS(-mdirect-move, CFLAGS="$CFLAGS -mdirect-move")
|
Chris@42
|
105 fi
|
Chris@42
|
106 ;;
|
Chris@42
|
107 esac
|
Chris@42
|
108
|
Chris@42
|
109 if test -z "$CFLAGS"; then
|
Chris@42
|
110 echo ""
|
Chris@42
|
111 echo "********************************************************"
|
Chris@42
|
112 echo "* WARNING: Don't know the best CFLAGS for this system *"
|
Chris@42
|
113 echo "* Use ./configure CFLAGS=... to specify your own flags *"
|
Chris@42
|
114 echo "* (otherwise, a default of CFLAGS=-O3 will be used) *"
|
Chris@42
|
115 echo "********************************************************"
|
Chris@42
|
116 echo ""
|
Chris@42
|
117 CFLAGS="-O3"
|
Chris@42
|
118 fi
|
Chris@42
|
119
|
Chris@42
|
120 AX_CHECK_COMPILER_FLAGS($CFLAGS, [], [
|
Chris@42
|
121 echo ""
|
Chris@42
|
122 echo "********************************************************"
|
Chris@42
|
123 echo "* WARNING: The guessed CFLAGS don't seem to work with *"
|
Chris@42
|
124 echo "* your compiler. *"
|
Chris@42
|
125 echo "* Use ./configure CFLAGS=... to specify your own flags *"
|
Chris@42
|
126 echo "********************************************************"
|
Chris@42
|
127 echo ""
|
Chris@42
|
128 CFLAGS=""
|
Chris@42
|
129 ])
|
Chris@42
|
130
|
Chris@42
|
131 fi
|
Chris@42
|
132 ])
|