aboutsummaryrefslogtreecommitdiffstats
path: root/libar2_hash.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2022-02-17 17:25:46 +0100
committerMattias Andrée <maandree@kth.se>2022-02-17 17:25:46 +0100
commit508fdf5722082d310f24b74f0a718f9138b0b042 (patch)
tree30146a21d371efb6dcc735d7862620b316161920 /libar2_hash.c
parentRemove obsolete macro (diff)
downloadlibar2-508fdf5722082d310f24b74f0a718f9138b0b042.tar.gz
libar2-508fdf5722082d310f24b74f0a718f9138b0b042.tar.bz2
libar2-508fdf5722082d310f24b74f0a718f9138b0b042.tar.xz
m style
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libar2_hash.c')
-rw-r--r--libar2_hash.c65
1 files changed, 33 insertions, 32 deletions
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
- }
}