Home | History | Annotate | Download | only in m4
      1 # ===========================================================================
      2 #       http://www.gnu.org/software/autoconf-archive/ax_cc_maxopt.html
      3 # ===========================================================================
      4 #
      5 # SYNOPSIS
      6 #
      7 #   AX_CC_MAXOPT
      8 #
      9 # DESCRIPTION
     10 #
     11 #   Try to turn on "good" C optimization flags for various compilers and
     12 #   architectures, for some definition of "good". (In our case, good for
     13 #   FFTW and hopefully for other scientific codes. Modify as needed.)
     14 #
     15 #   The user can override the flags by setting the CFLAGS environment
     16 #   variable. The user can also specify --enable-portable-binary in order to
     17 #   disable any optimization flags that might result in a binary that only
     18 #   runs on the host architecture.
     19 #
     20 #   Note also that the flags assume that ANSI C aliasing rules are followed
     21 #   by the code (e.g. for gcc's -fstrict-aliasing), and that floating-point
     22 #   computations can be re-ordered as needed.
     23 #
     24 #   Requires macros: AX_CHECK_COMPILE_FLAG, AX_COMPILER_VENDOR,
     25 #   AX_GCC_ARCHFLAG, AX_GCC_X86_CPUID.
     26 #
     27 # LICENSE
     28 #
     29 #   Copyright (c) 2008 Steven G. Johnson <stevenj (a] alum.mit.edu>
     30 #   Copyright (c) 2008 Matteo Frigo
     31 #
     32 #   This program is free software: you can redistribute it and/or modify it
     33 #   under the terms of the GNU General Public License as published by the
     34 #   Free Software Foundation, either version 3 of the License, or (at your
     35 #   option) any later version.
     36 #
     37 #   This program is distributed in the hope that it will be useful, but
     38 #   WITHOUT ANY WARRANTY; without even the implied warranty of
     39 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
     40 #   Public License for more details.
     41 #
     42 #   You should have received a copy of the GNU General Public License along
     43 #   with this program. If not, see <http://www.gnu.org/licenses/>.
     44 #
     45 #   As a special exception, the respective Autoconf Macro's copyright owner
     46 #   gives unlimited permission to copy, distribute and modify the configure
     47 #   scripts that are the output of Autoconf when processing the Macro. You
     48 #   need not follow the terms of the GNU General Public License when using
     49 #   or distributing such scripts, even though portions of the text of the
     50 #   Macro appear in them. The GNU General Public License (GPL) does govern
     51 #   all other use of the material that constitutes the Autoconf Macro.
     52 #
     53 #   This special exception to the GPL applies to versions of the Autoconf
     54 #   Macro released by the Autoconf Archive. When you make and distribute a
     55 #   modified version of the Autoconf Macro, you may extend this special
     56 #   exception to the GPL to apply to your modified version as well.
     57 
     58 #serial 13
     59 
     60 AC_DEFUN([AX_CC_MAXOPT],
     61 [
     62 AC_REQUIRE([AC_PROG_CC])
     63 AC_REQUIRE([AX_COMPILER_VENDOR])
     64 AC_REQUIRE([AC_CANONICAL_HOST])
     65 
     66 AC_ARG_ENABLE(portable-binary, [AS_HELP_STRING([--enable-portable-binary], [disable compiler optimizations that would produce unportable binaries])],
     67 	acx_maxopt_portable=$enableval, acx_maxopt_portable=no)
     68 
     69 # Try to determine "good" native compiler flags if none specified via CFLAGS
     70 if test "$ac_test_CFLAGS" != "set"; then
     71   CFLAGS=""
     72   case $ax_cv_c_compiler_vendor in
     73     dec) CFLAGS="-newc -w0 -O5 -ansi_alias -ansi_args -fp_reorder -tune host"
     74 	 if test "x$acx_maxopt_portable" = xno; then
     75            CFLAGS="$CFLAGS -arch host"
     76          fi;;
     77 
     78     sun) CFLAGS="-native -fast -xO5 -dalign"
     79 	 if test "x$acx_maxopt_portable" = xyes; then
     80 	   CFLAGS="$CFLAGS -xarch=generic"
     81          fi;;
     82 
     83     hp)  CFLAGS="+Oall +Optrs_ansi +DSnative"
     84 	 if test "x$acx_maxopt_portable" = xyes; then
     85 	   CFLAGS="$CFLAGS +DAportable"
     86 	 fi;;
     87 
     88     ibm) if test "x$acx_maxopt_portable" = xno; then
     89            xlc_opt="-qarch=auto -qtune=auto"
     90 	 else
     91            xlc_opt="-qtune=auto"
     92 	 fi
     93          AX_CHECK_COMPILE_FLAG($xlc_opt,
     94 		CFLAGS="-O3 -qansialias -w $xlc_opt",
     95                [CFLAGS="-O3 -qansialias -w"
     96                 echo "******************************************************"
     97                 echo "*  You seem to have the IBM  C compiler.  It is      *"
     98                 echo "*  recommended for best performance that you use:    *"
     99                 echo "*                                                    *"
    100                 echo "*    CFLAGS=-O3 -qarch=xxx -qtune=xxx -qansialias -w *"
    101                 echo "*                      ^^^        ^^^                *"
    102                 echo "*  where xxx is pwr2, pwr3, 604, or whatever kind of *"
    103                 echo "*  CPU you have.  (Set the CFLAGS environment var.   *"
    104                 echo "*  and re-run configure.)  For more info, man cc.    *"
    105                 echo "******************************************************"])
    106          ;;
    107 
    108     intel) CFLAGS="-O3 -ansi_alias"
    109 	if test "x$acx_maxopt_portable" = xno; then
    110 	  icc_archflag=unknown
    111 	  icc_flags=""
    112 	  case $host_cpu in
    113 	    i686*|x86_64*)
    114               # icc accepts gcc assembly syntax, so these should work:
    115 	      AX_GCC_X86_CPUID(0)
    116               AX_GCC_X86_CPUID(1)
    117 	      case $ax_cv_gcc_x86_cpuid_0 in # see AX_GCC_ARCHFLAG
    118                 *:756e6547:*:*) # Intel
    119                   case $ax_cv_gcc_x86_cpuid_1 in
    120                     *6a?:*[[234]]:*:*|*6[[789b]]?:*:*:*) icc_flags="-xK";;
    121                     *f3[[347]]:*:*:*|*f4[1347]:*:*:*) icc_flags="-xP -xN -xW -xK";;
    122                     *f??:*:*:*) icc_flags="-xN -xW -xK";;
    123                   esac ;;
    124               esac ;;
    125           esac
    126           if test "x$icc_flags" != x; then
    127             for flag in $icc_flags; do
    128               AX_CHECK_COMPILE_FLAG($flag, [icc_archflag=$flag; break])
    129             done
    130           fi
    131           AC_MSG_CHECKING([for icc architecture flag])
    132 	  AC_MSG_RESULT($icc_archflag)
    133           if test "x$icc_archflag" != xunknown; then
    134             CFLAGS="$CFLAGS $icc_archflag"
    135           fi
    136         fi
    137 	;;
    138 
    139     gnu)
    140      # default optimization flags for gcc on all systems
    141      CFLAGS="-O3 -fomit-frame-pointer"
    142 
    143      # -malign-double for x86 systems
    144      # LIBFFI -- DON'T DO THIS - CHANGES ABI
    145      # AX_CHECK_COMPILE_FLAG(-malign-double, CFLAGS="$CFLAGS -malign-double")
    146 
    147      #  -fstrict-aliasing for gcc-2.95+
    148      AX_CHECK_COMPILE_FLAG(-fstrict-aliasing,
    149 	CFLAGS="$CFLAGS -fstrict-aliasing")
    150 
    151      # note that we enable "unsafe" fp optimization with other compilers, too
    152      AX_CHECK_COMPILE_FLAG(-ffast-math, CFLAGS="$CFLAGS -ffast-math")
    153 
    154      AX_GCC_ARCHFLAG($acx_maxopt_portable)
    155      ;;
    156   esac
    157 
    158   if test -z "$CFLAGS"; then
    159 	echo ""
    160 	echo "********************************************************"
    161         echo "* WARNING: Don't know the best CFLAGS for this system  *"
    162         echo "* Use ./configure CFLAGS=... to specify your own flags *"
    163 	echo "* (otherwise, a default of CFLAGS=-O3 will be used)    *"
    164 	echo "********************************************************"
    165 	echo ""
    166         CFLAGS="-O3"
    167   fi
    168 
    169   AX_CHECK_COMPILE_FLAG($CFLAGS, [], [
    170 	echo ""
    171         echo "********************************************************"
    172         echo "* WARNING: The guessed CFLAGS don't seem to work with  *"
    173         echo "* your compiler.                                       *"
    174         echo "* Use ./configure CFLAGS=... to specify your own flags *"
    175         echo "********************************************************"
    176         echo ""
    177         CFLAGS=""
    178   ])
    179 
    180 fi
    181 ])
    182