riscv: Fix feenvupdate with FE_DFL_ENV (BZ 31022)
[glibc.git] / sysdeps / x86 / tst-ifunc-isa.h
blob739388cf09ca36c3d00578d3fe1b646c862f8742
1 /* IFUNC resolver with CPU_FEATURE_ACTIVE.
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 <sys/platform/x86.h>
21 enum isa
23 none,
24 sse2,
25 sse4_2,
26 avx,
27 avx2,
28 avx512f
31 enum isa
32 __attribute__ ((__optimize__ ("-fno-stack-protector")))
33 get_isa (void)
35 if (CPU_FEATURE_ACTIVE (AVX512F))
36 return avx512f;
37 if (CPU_FEATURE_ACTIVE (AVX2))
38 return avx2;
39 if (CPU_FEATURE_ACTIVE (AVX))
40 return avx;
41 if (CPU_FEATURE_ACTIVE (SSE4_2))
42 return sse4_2;
43 if (CPU_FEATURE_ACTIVE (SSE2))
44 return sse2;
45 return none;
48 static int
49 isa_sse2 (void)
51 return sse2;
54 static int
55 isa_sse4_2 (void)
57 return sse4_2;
60 static int
61 isa_avx (void)
63 return avx;
66 static int
67 isa_avx2 (void)
69 return avx2;
72 static int
73 isa_avx512f (void)
75 return avx512f;
78 static int
79 isa_none (void)
81 return none;
84 int foo (void) __attribute__ ((ifunc ("foo_ifunc")));
86 void *
87 __attribute__ ((__optimize__ ("-fno-stack-protector")))
88 foo_ifunc (void)
90 switch (get_isa ())
92 case avx512f:
93 return isa_avx512f;
94 case avx2:
95 return isa_avx2;
96 case avx:
97 return isa_avx;
98 case sse4_2:
99 return isa_sse4_2;
100 case sse2:
101 return isa_sse2;
102 default:
103 break;
105 return isa_none;