Update copyright dates with scripts/update-copyrights
[glibc.git] / sysdeps / unix / sysv / linux / x86_64 / tst-glibc-hwcaps-2.c
blob8121ce55620638b5253814091bba820bd6810b18
1 /* Check ISA level on shared object in glibc-hwcaps subdirectories.
2 Copyright (C) 2021-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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/>. */
19 #include <stdbool.h>
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <elf.h>
23 #include <get-isa-level.h>
24 #include <support/check.h>
25 #include <support/test-driver.h>
27 extern int dso_isa_level (void);
29 static int
30 do_test (void)
32 const struct cpu_features *cpu_features = __get_cpu_features ();
33 unsigned int isa_level = get_isa_level (cpu_features);
34 bool has_isa_baseline = ((isa_level & GNU_PROPERTY_X86_ISA_1_BASELINE)
35 == GNU_PROPERTY_X86_ISA_1_BASELINE);
36 bool has_isa_v2 = ((isa_level & GNU_PROPERTY_X86_ISA_1_V2)
37 == GNU_PROPERTY_X86_ISA_1_V2);
38 bool has_isa_v3 = ((isa_level & GNU_PROPERTY_X86_ISA_1_V3)
39 == GNU_PROPERTY_X86_ISA_1_V3);
40 bool has_isa_v4 = ((isa_level & GNU_PROPERTY_X86_ISA_1_V4)
41 == GNU_PROPERTY_X86_ISA_1_V4);
43 if (!has_isa_baseline)
44 return EXIT_FAILURE;
46 int level = dso_isa_level ();
47 int ret;
48 switch (level)
50 case 1:
51 case 2:
52 /* The default libx86-64-isa-level.so is used. */
53 printf ("The default shared library is used.\n");
54 if (has_isa_v3 || has_isa_v4 || (!has_isa_v2 && level == 2))
55 ret = EXIT_FAILURE;
56 else
57 ret = EXIT_SUCCESS;
58 break;
59 case 3:
60 /* libx86-64-isa-level.so marked as x86-64 ISA level 3 needed in
61 x86-64-v2 should be ignored on lesser CPU. */
62 printf ("x86-64 ISA level 3 shared library is used.\n");
63 if (has_isa_v4 || !has_isa_v3)
64 ret = EXIT_FAILURE;
65 else
66 ret = EXIT_SUCCESS;
67 break;
68 case 4:
69 /* libx86-64-isa-level.so marked as x86-64 ISA level 4 needed in
70 x86-64-v3 should be ignored on lesser CPU. */
71 printf ("x86-64 ISA level 4 shared library is used.\n");
72 if (has_isa_v4)
73 ret = EXIT_SUCCESS;
74 else
75 ret = EXIT_FAILURE;
76 break;
77 default:
78 abort ();
80 return ret;
83 #include <support/test-driver.c>