Home | History | Annotate | Download | only in m4
      1 # ===========================================================================
      2 #      http://www.gnu.org/software/autoconf-archive/ax_gcc_builtin.html
      3 # ===========================================================================
      4 #
      5 # SYNOPSIS
      6 #
      7 #   AX_GCC_BUILTIN(BUILTIN)
      8 #
      9 # DESCRIPTION
     10 #
     11 #   This macro checks if the compiler supports one of GCC's built-in
     12 #   functions; many other compilers also provide those same built-ins.
     13 #
     14 #   The BUILTIN parameter is the name of the built-in function.
     15 #
     16 #   If BUILTIN is supported define HAVE_<BUILTIN>. Keep in mind that since
     17 #   builtins usually start with two underscores they will be copied over
     18 #   into the HAVE_<BUILTIN> definition (e.g. HAVE___BUILTIN_EXPECT for
     19 #   __builtin_expect()).
     20 #
     21 #   The macro caches its result in the ax_cv_have_<BUILTIN> variable (e.g.
     22 #   ax_cv_have___builtin_expect).
     23 #
     24 #   The macro currently supports the following built-in functions:
     25 #
     26 #    __builtin_assume_aligned
     27 #    __builtin_bswap32
     28 #    __builtin_bswap64
     29 #    __builtin_choose_expr
     30 #    __builtin___clear_cache
     31 #    __builtin_clrsb
     32 #    __builtin_clrsbl
     33 #    __builtin_clrsbll
     34 #    __builtin_clz
     35 #    __builtin_clzl
     36 #    __builtin_clzll
     37 #    __builtin_complex
     38 #    __builtin_constant_p
     39 #    __builtin_ctz
     40 #    __builtin_ctzl
     41 #    __builtin_ctzll
     42 #    __builtin_expect
     43 #    __builtin_ffs
     44 #    __builtin_ffsl
     45 #    __builtin_ffsll
     46 #    __builtin_fpclassify
     47 #    __builtin_huge_val
     48 #    __builtin_huge_valf
     49 #    __builtin_huge_vall
     50 #    __builtin_inf
     51 #    __builtin_infd128
     52 #    __builtin_infd32
     53 #    __builtin_infd64
     54 #    __builtin_inff
     55 #    __builtin_infl
     56 #    __builtin_isinf_sign
     57 #    __builtin_nan
     58 #    __builtin_nand128
     59 #    __builtin_nand32
     60 #    __builtin_nand64
     61 #    __builtin_nanf
     62 #    __builtin_nanl
     63 #    __builtin_nans
     64 #    __builtin_nansf
     65 #    __builtin_nansl
     66 #    __builtin_object_size
     67 #    __builtin_parity
     68 #    __builtin_parityl
     69 #    __builtin_parityll
     70 #    __builtin_popcount
     71 #    __builtin_popcountl
     72 #    __builtin_popcountll
     73 #    __builtin_powi
     74 #    __builtin_powif
     75 #    __builtin_powil
     76 #    __builtin_prefetch
     77 #    __builtin_trap
     78 #    __builtin_types_compatible_p
     79 #    __builtin_unreachable
     80 #
     81 #   Unsuppored built-ins will be tested with an empty parameter set and the
     82 #   result of the check might be wrong or meaningless so use with care.
     83 #
     84 # LICENSE
     85 #
     86 #   Copyright (c) 2013 Gabriele Svelto <gabriele.svelto (a] gmail.com>
     87 #
     88 #   Copying and distribution of this file, with or without modification, are
     89 #   permitted in any medium without royalty provided the copyright notice
     90 #   and this notice are preserved.  This file is offered as-is, without any
     91 #   warranty.
     92 
     93 #serial 2
     94 
     95 AC_DEFUN([AX_GCC_BUILTIN], [
     96     AS_VAR_PUSHDEF([ac_var], [ax_cv_have_$1])
     97 
     98     AC_CACHE_CHECK([for $1], [ac_var], [
     99         AC_LINK_IFELSE([AC_LANG_PROGRAM([], [
    100             m4_case([$1],
    101                 [__builtin_assume_aligned], [$1("", 0)],
    102                 [__builtin_bswap32], [$1(0)],
    103                 [__builtin_bswap64], [$1(0)],
    104                 [__builtin_choose_expr], [$1(0, 0, 0)],
    105                 [__builtin___clear_cache], [$1("", "")],
    106                 [__builtin_clrsb], [$1(0)],
    107                 [__builtin_clrsbl], [$1(0)],
    108                 [__builtin_clrsbll], [$1(0)],
    109                 [__builtin_clz], [$1(0)],
    110                 [__builtin_clzl], [$1(0)],
    111                 [__builtin_clzll], [$1(0)],
    112                 [__builtin_complex], [$1(0.0, 0.0)],
    113                 [__builtin_constant_p], [$1(0)],
    114                 [__builtin_ctz], [$1(0)],
    115                 [__builtin_ctzl], [$1(0)],
    116                 [__builtin_ctzll], [$1(0)],
    117                 [__builtin_expect], [$1(0, 0)],
    118                 [__builtin_ffs], [$1(0)],
    119                 [__builtin_ffsl], [$1(0)],
    120                 [__builtin_ffsll], [$1(0)],
    121                 [__builtin_fpclassify], [$1(0, 1, 2, 3, 4, 0.0)],
    122                 [__builtin_huge_val], [$1()],
    123                 [__builtin_huge_valf], [$1()],
    124                 [__builtin_huge_vall], [$1()],
    125                 [__builtin_inf], [$1()],
    126                 [__builtin_infd128], [$1()],
    127                 [__builtin_infd32], [$1()],
    128                 [__builtin_infd64], [$1()],
    129                 [__builtin_inff], [$1()],
    130                 [__builtin_infl], [$1()],
    131                 [__builtin_isinf_sign], [$1(0.0)],
    132                 [__builtin_nan], [$1("")],
    133                 [__builtin_nand128], [$1("")],
    134                 [__builtin_nand32], [$1("")],
    135                 [__builtin_nand64], [$1("")],
    136                 [__builtin_nanf], [$1("")],
    137                 [__builtin_nanl], [$1("")],
    138                 [__builtin_nans], [$1("")],
    139                 [__builtin_nansf], [$1("")],
    140                 [__builtin_nansl], [$1("")],
    141                 [__builtin_object_size], [$1("", 0)],
    142                 [__builtin_parity], [$1(0)],
    143                 [__builtin_parityl], [$1(0)],
    144                 [__builtin_parityll], [$1(0)],
    145                 [__builtin_popcount], [$1(0)],
    146                 [__builtin_popcountl], [$1(0)],
    147                 [__builtin_popcountll], [$1(0)],
    148                 [__builtin_powi], [$1(0, 0)],
    149                 [__builtin_powif], [$1(0, 0)],
    150                 [__builtin_powil], [$1(0, 0)],
    151                 [__builtin_prefetch], [$1("")],
    152                 [__builtin_trap], [$1()],
    153                 [__builtin_types_compatible_p], [$1(int, int)],
    154                 [__builtin_unreachable], [$1()],
    155                 [m4_warn([syntax], [Unsupported built-in $1, the test may fail])
    156                  $1()]
    157             )
    158             ])],
    159             [AS_VAR_SET([ac_var], [yes])],
    160             [AS_VAR_SET([ac_var], [no])])
    161     ])
    162 
    163     AS_IF([test yes = AS_VAR_GET([ac_var])],
    164         [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_$1), 1,
    165             [Define to 1 if the system has the `$1' built-in function])], [])
    166 
    167     AS_VAR_POPDEF([ac_var])
    168 ])
    169