1 # ===========================================================================
2 # http://autoconf-archive.cryp.to/ax_gcc_x86_cpuid.html
3 # ===========================================================================
11 # On Pentium and later x86 processors, with gcc or a compiler that has a
12 # compatible syntax for inline assembly instructions, run a small program
13 # that executes the cpuid instruction with input OP. This can be used to
14 # detect the CPU type.
16 # On output, the values of the eax, ebx, ecx, and edx registers are stored
17 # as hexadecimal strings as "eax:ebx:ecx:edx" in the cache variable
18 # ax_cv_gcc_x86_cpuid_OP.
20 # If the cpuid 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), ax_cv_gcc_x86_cpuid_OP
23 # is set to the string "unknown".
25 # This macro mainly exists to be used in AX_GCC_ARCHFLAG.
33 # Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
34 # Copyright (c) 2008 Matteo Frigo
36 # This program is free software: you can redistribute it and/or modify it
37 # under the terms of the GNU General Public License as published by the
38 # Free Software Foundation, either version 3 of the License, or (at your
39 # option) any later version.
41 # This program is distributed in the hope that it will be useful, but
42 # WITHOUT ANY WARRANTY; without even the implied warranty of
43 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
44 # Public License for more details.
46 # You should have received a copy of the GNU General Public License along
47 # with this program. If not, see <http://www.gnu.org/licenses/>.
49 # As a special exception, the respective Autoconf Macro's copyright owner
50 # gives unlimited permission to copy, distribute and modify the configure
51 # scripts that are the output of Autoconf when processing the Macro. You
52 # need not follow the terms of the GNU General Public License when using
53 # or distributing such scripts, even though portions of the text of the
54 # Macro appear in them. The GNU General Public License (GPL) does govern
55 # all other use of the material that constitutes the Autoconf Macro.
57 # This special exception to the GPL applies to versions of the Autoconf
58 # Macro released by the Autoconf Macro Archive. When you make and
59 # distribute a modified version of the Autoconf Macro, you may extend this
60 # special exception to the GPL to apply to your modified version as well.
62 AC_DEFUN([AX_GCC_X86_CPUID],
63 [AC_REQUIRE([AC_PROG_CC])
65 AC_CACHE_CHECK(for x86 cpuid $1 output, ax_cv_gcc_x86_cpuid_$1,
66 [AC_RUN_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>], [
67 int op = $1, eax, ebx, ecx, edx;
70 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
72 f = fopen("conftest_cpuid", "w"); if (!f) return 1;
73 fprintf(f, "%x:%x:%x:%x\n", eax, ebx, ecx, edx);
77 [ax_cv_gcc_x86_cpuid_$1=`cat conftest_cpuid`; rm -f conftest_cpuid],
78 [ax_cv_gcc_x86_cpuid_$1=unknown; rm -f conftest_cpuid],
79 [ax_cv_gcc_x86_cpuid_$1=unknown])])