|
25 | 25 |
|
26 | 26 | #if defined(HAVE_CPUID) || defined(HAVE_CPUID_INTEL) || \ |
27 | 27 | defined(HAVE_CPUID_AARCH64) |
28 | | - static cpuid_flags_t cpuid_flags = WC_CPUID_INITIALIZER; |
| 28 | + static cpuid_flags_atomic_t cpuid_flags = WC_CPUID_ATOMIC_INITIALIZER; |
29 | 29 | #endif |
30 | 30 |
|
31 | 31 | #ifdef HAVE_CPUID_INTEL |
|
49 | 49 | #define ECX 2 |
50 | 50 | #define EDX 3 |
51 | 51 |
|
52 | | - static word32 cpuid_flag(word32 leaf, word32 sub, word32 num, word32 bit) |
| 52 | + static cpuid_flags_t cpuid_flag(word32 leaf, word32 sub, word32 num, word32 bit) |
53 | 53 | { |
54 | 54 | int got_intel_cpu = 0; |
55 | 55 | int got_amd_cpu = 0; |
|
82 | 82 |
|
83 | 83 | static WC_INLINE void cpuid_set_flags(void) |
84 | 84 | { |
85 | | - if (WOLFSSL_ATOMIC_LOAD(cpuid_flags) == WC_CPUID_UNINITED_VAL) { |
86 | | - word32 new_cpuid_flags = 0, old_cpuid_flags = WC_CPUID_UNINITED_VAL; |
| 85 | + if (WOLFSSL_ATOMIC_LOAD(cpuid_flags) == WC_CPUID_INITIALIZER) { |
| 86 | + cpuid_flags_t new_cpuid_flags = 0, |
| 87 | + old_cpuid_flags = WC_CPUID_INITIALIZER; |
87 | 88 | if (cpuid_flag(1, 0, ECX, 28)) { new_cpuid_flags |= CPUID_AVX1 ; } |
88 | 89 | if (cpuid_flag(7, 0, EBX, 5)) { new_cpuid_flags |= CPUID_AVX2 ; } |
89 | 90 | if (cpuid_flag(7, 0, EBX, 8)) { new_cpuid_flags |= CPUID_BMI2 ; } |
|
115 | 116 |
|
116 | 117 | static WC_INLINE void cpuid_set_flags(void) |
117 | 118 | { |
118 | | - if (WOLFSSL_ATOMIC_LOAD(cpuid_flags) == WC_CPUID_UNINITED_VAL) { |
119 | | - word32 new_cpuid_flags = 0, old_cpuid_flags = WC_CPUID_UNINITED_VAL; |
| 119 | + if (WOLFSSL_ATOMIC_LOAD(cpuid_flags) == WC_CPUID_INITIALIZER) { |
| 120 | + cpuid_flags_t new_cpuid_flags = 0, |
| 121 | + old_cpuid_flags = WC_CPUID_INITIALIZER; |
120 | 122 | word64 features; |
121 | 123 |
|
122 | 124 | __asm__ __volatile ( |
|
158 | 160 |
|
159 | 161 | static WC_INLINE void cpuid_set_flags(void) |
160 | 162 | { |
161 | | - if (WOLFSSL_ATOMIC_LOAD(cpuid_flags) == WC_CPUID_UNINITED_VAL) { |
162 | | - word32 new_cpuid_flags = 0, old_cpuid_flags = WC_CPUID_UNINITED_VAL; |
| 163 | + if (WOLFSSL_ATOMIC_LOAD(cpuid_flags) == WC_CPUID_INITIALIZER) { |
| 164 | + cpuid_flags_t new_cpuid_flags = 0, |
| 165 | + old_cpuid_flags = WC_CPUID_INITIALIZER; |
163 | 166 | word64 hwcaps = getauxval(AT_HWCAP); |
164 | 167 |
|
165 | 168 | #ifndef WOLFSSL_ARMASM_NO_HW_CRYPTO |
|
204 | 207 |
|
205 | 208 | static WC_INLINE void cpuid_set_flags(void) |
206 | 209 | { |
207 | | - if (WOLFSSL_ATOMIC_LOAD(cpuid_flags) == WC_CPUID_UNINITED_VAL) { |
208 | | - word32 new_cpuid_flags = 0, old_cpuid_flags = WC_CPUID_UNINITED_VAL; |
| 210 | + if (WOLFSSL_ATOMIC_LOAD(cpuid_flags) == WC_CPUID_INITIALIZER) { |
| 211 | + cpuid_flags_t new_cpuid_flags = 0, |
| 212 | + old_cpuid_flags = WC_CPUID_INITIALIZER; |
209 | 213 | word64 features = android_getCpuFeatures(); |
210 | 214 |
|
211 | 215 | if (features & ANDROID_CPU_ARM_FEATURE_AES) |
|
237 | 241 |
|
238 | 242 | static WC_INLINE void cpuid_set_flags(void) |
239 | 243 | { |
240 | | - if (WOLFSSL_ATOMIC_LOAD(cpuid_flags) == WC_CPUID_UNINITED_VAL) { |
241 | | - word32 new_cpuid_flags = 0, old_cpuid_flags = WC_CPUID_UNINITED_VAL; |
| 244 | + if (WOLFSSL_ATOMIC_LOAD(cpuid_flags) == WC_CPUID_INITIALIZER) { |
| 245 | + cpuid_flags_t new_cpuid_flags = 0, |
| 246 | + old_cpuid_flags = WC_CPUID_INITIALIZER; |
242 | 247 | if (cpuid_get_sysctlbyname("hw.optional.arm.FEAT_AES") != 0) |
243 | 248 | new_cpuid_flags |= CPUID_AES; |
244 | 249 | if (cpuid_get_sysctlbyname("hw.optional.arm.FEAT_PMULL") != 0) |
|
269 | 274 |
|
270 | 275 | static WC_INLINE void cpuid_set_flags(void) |
271 | 276 | { |
272 | | - if (WOLFSSL_ATOMIC_LOAD(cpuid_flags) == WC_CPUID_UNINITED_VAL) { |
273 | | - word32 new_cpuid_flags = 0, old_cpuid_flags = WC_CPUID_UNINITED_VAL; |
| 277 | + if (WOLFSSL_ATOMIC_LOAD(cpuid_flags) == WC_CPUID_INITIALIZER) { |
| 278 | + cpuid_flags_t new_cpuid_flags = 0, |
| 279 | + old_cpuid_flags = WC_CPUID_INITIALIZER; |
274 | 280 | word64 features = 0; |
275 | 281 |
|
276 | 282 | elf_aux_info(AT_HWCAP, &features, sizeof(features)); |
|
301 | 307 | #else |
302 | 308 | static WC_INLINE void cpuid_set_flags(void) |
303 | 309 | { |
304 | | - if (WOLFSSL_ATOMIC_LOAD(cpuid_flags) == WC_CPUID_UNINITED_VAL) { |
305 | | - word32 new_cpuid_flags = 0, old_cpuid_flags = WC_CPUID_UNINITED_VAL; |
| 310 | + if (WOLFSSL_ATOMIC_LOAD(cpuid_flags) == WC_CPUID_INITIALIZER) { |
| 311 | + cpuid_flags_t new_cpuid_flags = 0, |
| 312 | + old_cpuid_flags = WC_CPUID_INITIALIZER; |
306 | 313 | #ifndef WOLFSSL_ARMASM_NO_HW_CRYPTO |
307 | 314 | new_cpuid_flags |= CPUID_AES; |
308 | 315 | new_cpuid_flags |= CPUID_PMULL; |
|
332 | 339 | #elif defined(HAVE_CPUID) |
333 | 340 | static WC_INLINE void cpuid_set_flags(void) |
334 | 341 | { |
335 | | - if (WOLFSSL_ATOMIC_LOAD(cpuid_flags) == WC_CPUID_UNINITED_VAL) { |
336 | | - word32 new_cpuid_flags = 0, old_cpuid_flags = WC_CPUID_UNINITED_VAL; |
| 342 | + if (WOLFSSL_ATOMIC_LOAD(cpuid_flags) == WC_CPUID_INITIALIZER) { |
| 343 | + cpuid_flags_t new_cpuid_flags = 0, |
| 344 | + old_cpuid_flags = WC_CPUID_INITIALIZER; |
337 | 345 | (void)wolfSSL_Atomic_Uint_CompareExchange |
338 | 346 | (&cpuid_flags, &old_cpuid_flags, new_cpuid_flags); |
339 | 347 | } |
|
342 | 350 |
|
343 | 351 | #ifdef HAVE_CPUID |
344 | 352 |
|
345 | | - word32 cpuid_get_flags(void) |
| 353 | + cpuid_flags_t cpuid_get_flags(void) |
346 | 354 | { |
347 | 355 | cpuid_set_flags(); |
348 | 356 | return WOLFSSL_ATOMIC_LOAD(cpuid_flags); |
349 | 357 | } |
350 | 358 |
|
351 | | - void cpuid_select_flags(word32 flags) |
| 359 | + void cpuid_select_flags(cpuid_flags_t flags) |
352 | 360 | { |
353 | 361 | WOLFSSL_ATOMIC_STORE(cpuid_flags, flags); |
354 | 362 | } |
355 | 363 |
|
356 | | - void cpuid_set_flag(word32 flag) |
| 364 | + void cpuid_set_flag(cpuid_flags_t flag) |
357 | 365 | { |
358 | | - word32 current_flags = WOLFSSL_ATOMIC_LOAD(cpuid_flags); |
| 366 | + cpuid_flags_t current_flags = WOLFSSL_ATOMIC_LOAD(cpuid_flags); |
359 | 367 | while (! wolfSSL_Atomic_Uint_CompareExchange |
360 | 368 | (&cpuid_flags, ¤t_flags, current_flags | flag)) |
361 | 369 | WC_RELAX_LONG_LOOP(); |
362 | 370 | } |
363 | 371 |
|
364 | | - void cpuid_clear_flag(word32 flag) |
| 372 | + void cpuid_clear_flag(cpuid_flags_t flag) |
365 | 373 | { |
366 | | - word32 current_flags = WOLFSSL_ATOMIC_LOAD(cpuid_flags); |
| 374 | + cpuid_flags_t current_flags = WOLFSSL_ATOMIC_LOAD(cpuid_flags); |
367 | 375 | while (! wolfSSL_Atomic_Uint_CompareExchange |
368 | 376 | (&cpuid_flags, ¤t_flags, current_flags & ~flag)) |
369 | 377 | WC_RELAX_LONG_LOOP(); |
|
0 commit comments