1
+ // SPDX-License-Identifier: Apache-2.0
1
2
#include " simd_detector.h"
2
3
3
4
#include < cstdint>
11
12
12
13
void cpuid (int32_t out[4 ], int32_t eax, int32_t ecx);
13
14
uint64_t xgetbv (unsigned int index);
15
+ enum class Simd_Size
16
+ {
17
+ sse2,
18
+ avx,
19
+ };
14
20
auto detect_os_avx () -> bool;
15
21
auto detect_os_avx512 () -> bool;
16
22
@@ -54,12 +60,12 @@ auto detect_os_avx() -> bool
54
60
int32_t cpuInfo[4 ];
55
61
cpuid (cpuInfo, 1 , 0 );
56
62
57
- bool osUsesXSAVE_XRSTORE = (cpuInfo[2 ] & (1 << 27 )) != 0 ;
58
- bool cpuAVXSuport = (cpuInfo[2 ] & (1 << 28 )) != 0 ;
63
+ bool const osUsesXSAVE_XRSTORE = (cpuInfo[2 ] & (1 << 27 ));
64
+ bool const cpuAVXSuport = (cpuInfo[2 ] & (1 << 28 )) != 0 ;
59
65
60
66
if (osUsesXSAVE_XRSTORE && cpuAVXSuport)
61
67
{
62
- uint64_t xcrFeatureMask = xgetbv (_XCR_XFEATURE_ENABLED_MASK);
68
+ uint64_t const xcrFeatureMask = xgetbv (_XCR_XFEATURE_ENABLED_MASK);
63
69
avxSupported = (xcrFeatureMask & 0x6 ) == 0x6 ;
64
70
}
65
71
@@ -70,7 +76,7 @@ auto detect_os_avx512() -> bool
70
76
{
71
77
if (!detect_os_avx ())
72
78
return false ;
73
- uint64_t xcrFeatureMask = xgetbv (_XCR_XFEATURE_ENABLED_MASK);
79
+ uint64_t const xcrFeatureMask = xgetbv (_XCR_XFEATURE_ENABLED_MASK);
74
80
return (xcrFeatureMask & 0xe6 ) == 0xe6 ;
75
81
}
76
82
@@ -81,7 +87,7 @@ auto unicode::detail::max_simd_size() -> size_t
81
87
82
88
int32_t info[4 ];
83
89
cpuid (info, 0 , 0 );
84
- int nIds = info[0 ];
90
+ int const nIds = info[0 ];
85
91
86
92
// cpuid(info, 0x80000000, 0);
87
93
// uint32_t nExIds = info[0];
@@ -108,7 +114,7 @@ auto unicode::detail::max_simd_size() -> size_t
108
114
if (nIds >= 0x00000007 )
109
115
{
110
116
cpuid (info, 0x00000007 , 0 );
111
- bool HW_AVX2 = (info[1 ] & ((int ) 1 << 5 )) != 0 ;
117
+ bool const HW_AVX2 = (info[1 ] & ((int ) 1 << 5 )) != 0 ;
112
118
if (!HW_AVX2)
113
119
return 128 ;
114
120
@@ -121,13 +127,13 @@ auto unicode::detail::max_simd_size() -> size_t
121
127
// bool HW_PREFETCHWT1 = (info[2] & ((int) 1 << 0)) != 0;
122
128
// bool HW_RDPID = (info[2] & ((int) 1 << 22)) != 0;
123
129
124
- bool HW_AVX512_F = (info[1 ] & ((int ) 1 << 16 )) != 0 ;
130
+ bool const HW_AVX512_F = (info[1 ] & ((int ) 1 << 16 ));
125
131
// bool HW_AVX512_CD = (info[1] & ((int) 1 << 28)) != 0;
126
132
// bool HW_AVX512_PF = (info[1] & ((int) 1 << 26)) != 0;
127
133
// bool HW_AVX512_ER = (info[1] & ((int) 1 << 27)) != 0;
128
134
129
135
// bool HW_AVX512_VL = (info[1] & ((int) 1 << 31)) != 0;
130
- bool HW_AVX512_BW = (info[1 ] & ((int ) 1 << 30 )) != 0 ;
136
+ bool const HW_AVX512_BW = (info[1 ] & ((int ) 1 << 30 ));
131
137
// bool HW_AVX512_DQ = (info[1] & ((int) 1 << 17)) != 0;
132
138
133
139
// bool HW_AVX512_IFMA = (info[1] & ((int) 1 << 21)) != 0;
@@ -143,9 +149,9 @@ auto unicode::detail::max_simd_size() -> size_t
143
149
// bool HW_GFNI = (info[2] & ((int) 1 << 8)) != 0;
144
150
// bool HW_VAES = (info[2] & ((int) 1 << 9)) != 0;
145
151
// bool HW_AVX512_VPCLMUL = (info[2] & ((int) 1 << 10)) != 0;
146
- bool HW_AVX512_BITALG = (info[2 ] & ((int ) 1 << 12 )) != 0 ;
152
+ bool const HW_AVX512_BITALG = (info[2 ] & ((int ) 1 << 12 ));
147
153
148
- bool use512 = detect_os_avx512 () && HW_AVX512_F && HW_AVX512_BW && HW_AVX512_BITALG;
154
+ bool const use512 = detect_os_avx512 () && HW_AVX512_F && HW_AVX512_BW && HW_AVX512_BITALG;
149
155
if (!use512)
150
156
return 256 ;
151
157
else
0 commit comments