acinclude/ax_gcc_x86_cpuid.m4
changeset 12190 04650c2fe44e
parent 5029 5d7d48157be7
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/acinclude/ax_gcc_x86_cpuid.m4	Sat Sep 15 09:24:04 2018 +0300
     1.3 @@ -0,0 +1,79 @@
     1.4 +# ===========================================================================
     1.5 +#     http://www.gnu.org/software/autoconf-archive/ax_gcc_x86_cpuid.html
     1.6 +# ===========================================================================
     1.7 +#
     1.8 +# SYNOPSIS
     1.9 +#
    1.10 +#   AX_GCC_X86_CPUID(OP)
    1.11 +#
    1.12 +# DESCRIPTION
    1.13 +#
    1.14 +#   On Pentium and later x86 processors, with gcc or a compiler that has a
    1.15 +#   compatible syntax for inline assembly instructions, run a small program
    1.16 +#   that executes the cpuid instruction with input OP. This can be used to
    1.17 +#   detect the CPU type.
    1.18 +#
    1.19 +#   On output, the values of the eax, ebx, ecx, and edx registers are stored
    1.20 +#   as hexadecimal strings as "eax:ebx:ecx:edx" in the cache variable
    1.21 +#   ax_cv_gcc_x86_cpuid_OP.
    1.22 +#
    1.23 +#   If the cpuid instruction fails (because you are running a
    1.24 +#   cross-compiler, or because you are not using gcc, or because you are on
    1.25 +#   a processor that doesn't have this instruction), ax_cv_gcc_x86_cpuid_OP
    1.26 +#   is set to the string "unknown".
    1.27 +#
    1.28 +#   This macro mainly exists to be used in AX_GCC_ARCHFLAG.
    1.29 +#
    1.30 +# LICENSE
    1.31 +#
    1.32 +#   Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
    1.33 +#   Copyright (c) 2008 Matteo Frigo
    1.34 +#
    1.35 +#   This program is free software: you can redistribute it and/or modify it
    1.36 +#   under the terms of the GNU General Public License as published by the
    1.37 +#   Free Software Foundation, either version 3 of the License, or (at your
    1.38 +#   option) any later version.
    1.39 +#
    1.40 +#   This program is distributed in the hope that it will be useful, but
    1.41 +#   WITHOUT ANY WARRANTY; without even the implied warranty of
    1.42 +#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
    1.43 +#   Public License for more details.
    1.44 +#
    1.45 +#   You should have received a copy of the GNU General Public License along
    1.46 +#   with this program. If not, see <http://www.gnu.org/licenses/>.
    1.47 +#
    1.48 +#   As a special exception, the respective Autoconf Macro's copyright owner
    1.49 +#   gives unlimited permission to copy, distribute and modify the configure
    1.50 +#   scripts that are the output of Autoconf when processing the Macro. You
    1.51 +#   need not follow the terms of the GNU General Public License when using
    1.52 +#   or distributing such scripts, even though portions of the text of the
    1.53 +#   Macro appear in them. The GNU General Public License (GPL) does govern
    1.54 +#   all other use of the material that constitutes the Autoconf Macro.
    1.55 +#
    1.56 +#   This special exception to the GPL applies to versions of the Autoconf
    1.57 +#   Macro released by the Autoconf Archive. When you make and distribute a
    1.58 +#   modified version of the Autoconf Macro, you may extend this special
    1.59 +#   exception to the GPL to apply to your modified version as well.
    1.60 +
    1.61 +#serial 7
    1.62 +
    1.63 +AC_DEFUN([AX_GCC_X86_CPUID],
    1.64 +[AC_REQUIRE([AC_PROG_CC])
    1.65 +AC_LANG_PUSH([C])
    1.66 +AC_CACHE_CHECK(for x86 cpuid $1 output, ax_cv_gcc_x86_cpuid_$1,
    1.67 + [AC_RUN_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>], [
    1.68 +     int op = $1, eax, ebx, ecx, edx;
    1.69 +     FILE *f;
    1.70 +      __asm__("cpuid"
    1.71 +        : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
    1.72 +        : "a" (op));
    1.73 +     f = fopen("conftest_cpuid", "w"); if (!f) return 1;
    1.74 +     fprintf(f, "%x:%x:%x:%x\n", eax, ebx, ecx, edx);
    1.75 +     fclose(f);
    1.76 +     return 0;
    1.77 +])],
    1.78 +     [ax_cv_gcc_x86_cpuid_$1=`cat conftest_cpuid`; rm -f conftest_cpuid],
    1.79 +     [ax_cv_gcc_x86_cpuid_$1=unknown; rm -f conftest_cpuid],
    1.80 +     [ax_cv_gcc_x86_cpuid_$1=unknown])])
    1.81 +AC_LANG_POP([C])
    1.82 +])