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