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