Update to 2.0.0 tree from current Fremantle build
[opencv] / autotools / aclocal / ax_gcc_x86_cpuid.m4
1 dnl @synopsis AX_GCC_X86_CPUID(OP)
2 dnl @summary run x86 cpuid instruction OP using gcc inline assembler
3 dnl @category Misc
4 dnl
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.
9 dnl
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.
13 dnl
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".
18 dnl
19 dnl This macro mainly exists to be used in AX_GCC_ARCHFLAG.
20 dnl
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])
26 AC_LANG_PUSH([C])
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;
30      FILE *f;
31 #if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64)
32      __asm__("push %%rbx\n\t"
33              "cpuid\n\t"
34              "pop %%rbx"
35              : "=a" (eax), "=c" (ecx), "=d" (edx)
36              : "a" (op));
37      __asm__("push %%rbx\n\t"
38              "cpuid\n\t"
39              "mov %%rbx, %%rax\n\t"
40              "pop %%rbx"
41              : "=a" (ebx), "=c" (ecx), "=d" (edx)
42              : "a" (op));
43 #else
44      __asm__("push %%ebx\n\t"
45              "cpuid\n\t"
46              "pop %%ebx"
47              : "=a" (eax), "=c" (ecx), "=d" (edx)
48              : "a" (op));
49      __asm__("push %%ebx\n\t"
50              "cpuid\n\t"
51              "mov %%ebx, %%eax\n\t"
52              "pop %%ebx"
53              : "=a" (ebx), "=c" (ecx), "=d" (edx)
54              : "a" (op));
55 #endif
56      f = fopen("conftest_cpuid", "w"); if (!f) return 1;
57      fprintf(f, "%x:%x:%x:%x\n", eax, ebx, ecx, edx);
58      fclose(f);
59      return 0;
60 ])], 
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])])
64 AC_LANG_POP([C])
65 ])