1# ===========================================================================
2#   http://www.gnu.org/software/autoconf-archive/ax_check_x86_features.html
3# ===========================================================================
4# EDITED by C. P
5#
6# SYNOPSIS
7#
8#   AX_CHECK_X86_FEATURES([ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
9#
10# DESCRIPTION
11#
12#   Checks if the host cpu supports various x86 instruction set, the
13#   instructions that will get tested are "mmx, popcnt, sse, sse2, sse3,
14#   sse4.1, sse4.2, sse4a, avx, avx2, avx512f, fma, fma4, bmi, bmi2". If the
15#   instruction set is supported by the host cpu, the C preprocessor macro
16#   HAVE_XXX_INSTRUCTIONS is set to 1. The XXX is up-cased instruction case
17#   with dot replaced by underscore. For example, the test for "sse4.2"
18#   would export HAVE_SSE4_2_INSTRUCTIONS=1. Also the compiler flag
19#   "-msse4.2" would be added to X86_FEATURE_CFLAGS variable, that can be
20#   obtained in Makefile.am using @X86_FEATURE_CFLAGS@.
21#
22#   If any of the test for the instruction set were succeeded, the configure
23#   script would run ACTION-IF-FOUND if it is specified, or append
24#   X86_FEATURE_CFLAGS to CFLAGS. If none of the instruction were found,
25#   ACTION-IF-NOT-FOUND hook is triggered.
26#
27#   This macro requires gcc extended builtin function "__builtin_cpu_init"
28#   and "__builtin_cpu_supports" to detect the cpu features. It will error
29#   out if the compiler doesn't has these builtins.
30#
31#   See also AX_GCC_X86_CPU_SUPPORTS, which is the actual macro that perform
32#   the checks for the instruction sets.
33#
34# LICENSE
35#
36#   Copyright (c) 2016 Felix Chern <idryman@gmail.com>
37#
38#   This program is free software; you can redistribute it and/or modify it
39#   under the terms of the GNU General Public License as published by the
40#   Free Software Foundation; either version 2 of the License, or (at your
41#   option) any later version.
42#
43#   This program is distributed in the hope that it will be useful, but
44#   WITHOUT ANY WARRANTY; without even the implied warranty of
45#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
46#   Public License for more details.
47#
48#   You should have received a copy of the GNU General Public License along
49#   with this program. If not, see <http://www.gnu.org/licenses/>.
50#
51#   As a special exception, the respective Autoconf Macro's copyright owner
52#   gives unlimited permission to copy, distribute and modify the configure
53#   scripts that are the output of Autoconf when processing the Macro. You
54#   need not follow the terms of the GNU General Public License when using
55#   or distributing such scripts, even though portions of the text of the
56#   Macro appear in them. The GNU General Public License (GPL) does govern
57#   all other use of the material that constitutes the Autoconf Macro.
58#
59#   This special exception to the GPL applies to versions of the Autoconf
60#   Macro released by the Autoconf Archive. When you make and distribute a
61#   modified version of the Autoconf Macro, you may extend this special
62#   exception to the GPL to apply to your modified version as well.
63
64#serial 1
65
66AC_DEFUN([AX_CHECK_X86_FEATURES],
67 [m4_foreach_w(
68   [ax_x86_feature],
69   [mmx popcnt sse sse2 sse3 sse4.1 sse4.2 sse4a avx avx2 avx512f fma fma4 bmi bmi2],
70   [AX_GCC_X86_CPU_SUPPORTS(ax_x86_feature,
71     [X86_FEATURE_CFLAGS="$X86_FEATURE_CFLAGS -m[]ax_x86_feature"],
72     [])
73  ])
74  AC_SUBST([X86_FEATURE_CFLAGS])
75  m4_ifval([$1],[$1],
76    [CXXFLAGS="$CXXFLAGS $X86_FEATURE_CFLAGS"])
77  $2
78])
79