(root)/
glibc-2.38/
sysdeps/
x86_64/
tst-glibc-hwcaps.c
       1  /* glibc-hwcaps subdirectory test.  x86_64 version.
       2     Copyright (C) 2020-2023 Free Software Foundation, Inc.
       3     This file is part of the GNU C Library.
       4  
       5     The GNU C Library is free software; you can redistribute it and/or
       6     modify it under the terms of the GNU Lesser General Public
       7     License as published by the Free Software Foundation; either
       8     version 2.1 of the License, or (at your option) any later version.
       9  
      10     The GNU C Library is distributed in the hope that it will be useful,
      11     but WITHOUT ANY WARRANTY; without even the implied warranty of
      12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13     Lesser General Public License for more details.
      14  
      15     You should have received a copy of the GNU Lesser General Public
      16     License along with the GNU C Library; if not, see
      17     <https://www.gnu.org/licenses/>.  */
      18  
      19  #include <stdio.h>
      20  #include <support/check.h>
      21  #include <sys/param.h>
      22  #include <elf.h>
      23  #include <get-isa-level.h>
      24  
      25  extern int marker2 (void);
      26  extern int marker3 (void);
      27  extern int marker4 (void);
      28  
      29  /* Return the x86-64-vN level, 1 for the baseline.  */
      30  static int
      31  compute_level (void)
      32  {
      33    const struct cpu_features *cpu_features = __get_cpu_features ();
      34    unsigned int isa_level = get_isa_level (cpu_features);
      35  
      36    if (!(isa_level & GNU_PROPERTY_X86_ISA_1_V2))
      37      return 1;
      38    if (!(isa_level & GNU_PROPERTY_X86_ISA_1_V3))
      39      return 2;
      40    if (!(isa_level & GNU_PROPERTY_X86_ISA_1_V4))
      41      return 3;
      42    return 4;
      43  }
      44  
      45  static int
      46  do_test (void)
      47  {
      48    int level = compute_level ();
      49    printf ("info: detected x86-64 micro-architecture level: %d\n", level);
      50    TEST_COMPARE (marker2 (), MIN (level, 2));
      51    TEST_COMPARE (marker3 (), MIN (level, 3));
      52    TEST_COMPARE (marker4 (), MIN (level, 4));
      53    return 0;
      54  }
      55  
      56  #include <support/test-driver.c>