From 508fdf5722082d310f24b74f0a718f9138b0b042 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 17 Feb 2022 17:25:46 +0100 Subject: m style MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libar2_hash.c | 65 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 33 insertions(+), 32 deletions(-) (limited to 'libar2_hash.c') diff --git a/libar2_hash.c b/libar2_hash.c index 435d48d..3ee6bca 100644 --- a/libar2_hash.c +++ b/libar2_hash.c @@ -674,45 +674,46 @@ libar2_init(void) static volatile int initialised = 0; static volatile atomic_flag spinlock = ATOMIC_FLAG_INIT; + if (initialised) + return; + + while (atomic_flag_test_and_set(&spinlock)); + if (!initialised) { - while (atomic_flag_test_and_set(&spinlock)); - - if (!initialised) { -#if 0 - __builtin_cpu_init(); - /* $covered{$ (we know that it works, but the test cannot enter every branch) */ - if (__builtin_cpu_supports("avx512f")) - libar2_internal_use_avx512f__(); - else if (__builtin_cpu_supports("avx2")) - libar2_internal_use_avx2__(); - else if (__builtin_cpu_supports("sse2")) +# if 0 + __builtin_cpu_init(); + /* $covered{$ (we know that it works, but the test cannot enter every branch) */ + if (__builtin_cpu_supports("avx512f")) + libar2_internal_use_avx512f__(); + else if (__builtin_cpu_supports("avx2")) + libar2_internal_use_avx2__(); + else if (__builtin_cpu_supports("sse2")) + libar2_internal_use_sse2__(); + else + libar2_internal_use_generic__(); + /* $covered}$ */ +# else + uint32_t x; + __asm__ volatile("cpuid" : "=b"(x) : "a"(7), "c"(0) : "edx"); + /* $covered{$ (we know that it works, but the test cannot enter every branch) */ + if (x & ((uint32_t)1 << 16)) { + libar2_internal_use_avx512f__(); + } else if (x & ((uint32_t)1 << 5)) { + libar2_internal_use_avx2__(); + } else { + __asm__ volatile("cpuid" : "=d"(x) : "a"(1) : "ebx", "ecx"); + if (x & ((uint32_t)1 << 26)) libar2_internal_use_sse2__(); else libar2_internal_use_generic__(); - /* $covered}$ */ -#else - uint32_t x; - __asm__ volatile("cpuid" : "=b"(x) : "a"(7), "c"(0) : "edx"); - /* $covered{$ (we know that it works, but the test cannot enter every branch) */ - if (x & ((uint32_t)1 << 16)) { - libar2_internal_use_avx512f__(); - } else if (x & ((uint32_t)1 << 5)) { - libar2_internal_use_avx2__(); - } else { - __asm__ volatile("cpuid" : "=d"(x) : "a"(1) : "ebx", "ecx"); - if (x & ((uint32_t)1 << 26)) - libar2_internal_use_sse2__(); - else - libar2_internal_use_generic__(); - } - /* $covered}$ */ -#endif - initialised = 1; } + /* $covered}$ */ +# endif + initialised = 1; + } - atomic_flag_clear(&spinlock); + atomic_flag_clear(&spinlock); #endif - } } -- cgit v1.2.3-70-g09d2