2 This file is part of the GNU C Library.
3 Copyright (C) 2020-2024 Free Software Foundation, Inc.
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.
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.
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/>. */
20 #include <cpu-features.h>
22 /* Get GNU_PROPERTY_X86_ISA_1_BASELINE and GNU_PROPERTY_X86_ISA_1_V[234]
26 get_isa_level (const struct cpu_features
*cpu_features
)
28 unsigned int isa_level
= 0;
30 if (CPU_FEATURE_USABLE_P (cpu_features
, CMOV
)
31 && CPU_FEATURE_USABLE_P (cpu_features
, CX8
)
32 && CPU_FEATURE_CPU_P (cpu_features
, FPU
)
33 && CPU_FEATURE_USABLE_P (cpu_features
, FXSR
)
34 && CPU_FEATURE_USABLE_P (cpu_features
, MMX
)
35 && CPU_FEATURE_USABLE_P (cpu_features
, SSE
)
36 && CPU_FEATURE_USABLE_P (cpu_features
, SSE2
))
38 isa_level
= GNU_PROPERTY_X86_ISA_1_BASELINE
;
39 if (CPU_FEATURE_USABLE_P (cpu_features
, CMPXCHG16B
)
40 && CPU_FEATURE_USABLE_P (cpu_features
, LAHF64_SAHF64
)
41 && CPU_FEATURE_USABLE_P (cpu_features
, POPCNT
)
42 && CPU_FEATURE_USABLE_P (cpu_features
, SSE3
)
43 && CPU_FEATURE_USABLE_P (cpu_features
, SSSE3
)
44 && CPU_FEATURE_USABLE_P (cpu_features
, SSE4_1
)
45 && CPU_FEATURE_USABLE_P (cpu_features
, SSE4_2
))
47 isa_level
|= GNU_PROPERTY_X86_ISA_1_V2
;
48 if (CPU_FEATURE_USABLE_P (cpu_features
, AVX
)
49 && CPU_FEATURE_USABLE_P (cpu_features
, AVX2
)
50 && CPU_FEATURE_USABLE_P (cpu_features
, BMI1
)
51 && CPU_FEATURE_USABLE_P (cpu_features
, BMI2
)
52 && CPU_FEATURE_USABLE_P (cpu_features
, F16C
)
53 && CPU_FEATURE_USABLE_P (cpu_features
, FMA
)
54 && CPU_FEATURE_USABLE_P (cpu_features
, LZCNT
)
55 && CPU_FEATURE_USABLE_P (cpu_features
, MOVBE
))
57 isa_level
|= GNU_PROPERTY_X86_ISA_1_V3
;
58 if (CPU_FEATURE_USABLE_P (cpu_features
, AVX512F
)
59 && CPU_FEATURE_USABLE_P (cpu_features
, AVX512BW
)
60 && CPU_FEATURE_USABLE_P (cpu_features
, AVX512CD
)
61 && CPU_FEATURE_USABLE_P (cpu_features
, AVX512DQ
)
62 && CPU_FEATURE_USABLE_P (cpu_features
, AVX512VL
))
63 isa_level
|= GNU_PROPERTY_X86_ISA_1_V4
;