1 dnl @synopsis AX_GCC_X86_CPUID(OP)
2 dnl @summary run x86 cpuid instruction OP using gcc inline assembler
5 dnl On Pentium and later x86 processors, with gcc or a compiler that
6 dnl has a compatible syntax for inline assembly instructions, run
7 dnl a small program that executes the cpuid instruction with
8 dnl input OP. This can be used to detect the CPU type.
10 dnl On output, the values of the eax, ebx, ecx, and edx registers
11 dnl are stored as hexadecimal strings as "eax:ebx:ecx:edx" in
12 dnl the cache variable ax_cv_gcc_x86_cpuid_OP.
14 dnl If the cpuid instruction fails (because you are running a cross-compiler,
15 dnl or because you are not using gcc, or because you are on a processor
16 dnl that doesn't have this instruction), ax_cv_gcc_x86_cpuid_OP is set
17 dnl to the string "unknown".
19 dnl This macro mainly exists to be used in AX_GCC_ARCHFLAG.
21 dnl @version 2008-12-06
22 dnl @license GPLWithACException
23 dnl @author Steven G. Johnson <stevenj@alum.mit.edu> and Matteo Frigo.
24 AC_DEFUN([AX_GCC_X86_CPUID],
25 [AC_REQUIRE([AC_PROG_CC])
27 AC_CACHE_CHECK([for x86 cpuid $1 output], [ax_cv_gcc_x86_cpuid_$1],
28 [AC_RUN_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>], [
29 int op = $1, eax, ebx, ecx, edx;
31 #if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64)
32 __asm__("push %%rbx\n\t"
35 : "=a" (eax), "=c" (ecx), "=d" (edx)
37 __asm__("push %%rbx\n\t"
39 "mov %%rbx, %%rax\n\t"
41 : "=a" (ebx), "=c" (ecx), "=d" (edx)
44 __asm__("push %%ebx\n\t"
47 : "=a" (eax), "=c" (ecx), "=d" (edx)
49 __asm__("push %%ebx\n\t"
51 "mov %%ebx, %%eax\n\t"
53 : "=a" (ebx), "=c" (ecx), "=d" (edx)
56 f = fopen("conftest_cpuid", "w"); if (!f) return 1;
57 fprintf(f, "%x:%x:%x:%x\n", eax, ebx, ecx, edx);
61 [ax_cv_gcc_x86_cpuid_$1=`cat conftest_cpuid`; rm -f conftest_cpuid],
62 [ax_cv_gcc_x86_cpuid_$1=unknown; rm -f conftest_cpuid],
63 [ax_cv_gcc_x86_cpuid_$1=unknown])])