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