1 # ===========================================================================
2 # http://www.gnu.org/software/autoconf-archive/ax_gcc_x86_avx_xgetbv.html
3 # ===========================================================================
7 # AX_GCC_X86_AVX_XGETBV
11 # On later x86 processors with AVX SIMD support, with gcc or a compiler
12 # that has a compatible syntax for inline assembly instructions, run a
13 # small program that executes the xgetbv instruction with input OP. This
14 # can be used to detect if the OS supports AVX instruction usage.
16 # On output, the values of the eax and edx registers are stored as
17 # hexadecimal strings as "eax:edx" in the cache variable
18 # ax_cv_gcc_x86_avx_xgetbv.
20 # If the xgetbv instruction fails (because you are running a
21 # cross-compiler, or because you are not using gcc, or because you are on
22 # a processor that doesn't have this instruction),
23 # ax_cv_gcc_x86_avx_xgetbv_OP is set to the string "unknown".
25 # This macro mainly exists to be used in AX_EXT.
29 # Copyright (c) 2013 Michael Petch <mpetch@capp-sysware.com>
31 # This program is free software: you can redistribute it and/or modify it
32 # under the terms of the GNU General Public License as published by the
33 # Free Software Foundation, either version 3 of the License, or (at your
34 # option) any later version.
36 # This program is distributed in the hope that it will be useful, but
37 # WITHOUT ANY WARRANTY; without even the implied warranty of
38 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
39 # Public License for more details.
41 # You should have received a copy of the GNU General Public License along
42 # with this program. If not, see <http://www.gnu.org/licenses/>.
44 # As a special exception, the respective Autoconf Macro's copyright owner
45 # gives unlimited permission to copy, distribute and modify the configure
46 # scripts that are the output of Autoconf when processing the Macro. You
47 # need not follow the terms of the GNU General Public License when using
48 # or distributing such scripts, even though portions of the text of the
49 # Macro appear in them. The GNU General Public License (GPL) does govern
50 # all other use of the material that constitutes the Autoconf Macro.
52 # This special exception to the GPL applies to versions of the Autoconf
53 # Macro released by the Autoconf Archive. When you make and distribute a
54 # modified version of the Autoconf Macro, you may extend this special
55 # exception to the GPL to apply to your modified version as well.
59 AC_DEFUN([AX_GCC_X86_AVX_XGETBV],
60 [AC_REQUIRE([AC_PROG_CC])
62 AC_CACHE_CHECK(for x86-AVX xgetbv $1 output, ax_cv_gcc_x86_avx_xgetbv_$1,
63 [AC_RUN_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>], [
64 int op = $1, eax, edx;
66 /* Opcodes for xgetbv */
67 __asm__ __volatile__ (".byte 0x0f, 0x01, 0xd0"
68 : "=a" (eax), "=d" (edx)
70 f = fopen("conftest_xgetbv", "w"); if (!f) return 1;
71 fprintf(f, "%x:%x\n", eax, edx);
75 [ax_cv_gcc_x86_avx_xgetbv_$1=`cat conftest_xgetbv`; rm -f conftest_xgetbv],
76 [ax_cv_gcc_x86_avx_xgetbv_$1=unknown; rm -f conftest_xgetbv],
77 [ax_cv_gcc_x86_avx_xgetbv_$1=unknown])])