Debian Codegraph @

scripts/ax_gcc_x86_avx_xgetbv.m4

raw
1 # ===========================================================================
2 # http://www.gnu.org/software/autoconf-archive/ax_gcc_x86_avx_xgetbv.html
3 # ===========================================================================
4 #
5 # SYNOPSIS
6 #
7 # AX_GCC_X86_AVX_XGETBV
8 #
9 # DESCRIPTION
10 #
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.
15 #
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.
19 #
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".
24 #
25 # This macro mainly exists to be used in AX_EXT.
26 #
27 # LICENSE
28 #
29 # Copyright (c) 2013 Michael Petch <[email protected]>
30 #
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.
35 #
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.
40 #
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/>.
43 #
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.
51 #
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.
56
57 #serial 2
58
59 AC_DEFUN([AX_GCC_X86_AVX_XGETBV],
60 [AC_REQUIRE([AC_PROG_CC])
61 AC_LANG_PUSH([C])
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;
65 FILE *f;
66 /* Opcodes for xgetbv */
67 __asm__ __volatile__ (".byte 0x0f, 0x01, 0xd0"
68 : "=a" (eax), "=d" (edx)
69 : "c" (op));
70 f = fopen("conftest_xgetbv", "w"); if (!f) return 1;
71 fprintf(f, "%x:%x\n", eax, edx);
72 fclose(f);
73 return 0;
74 ])],
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])])
78 AC_LANG_POP([C])
79 ])