Skip to content

Commit

Permalink
Try to access 'support' only atomically (#520)
Browse files Browse the repository at this point in the history
  • Loading branch information
rschu1ze authored Oct 8, 2023
1 parent c438bee commit 0e27348
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/isadetection.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,23 +198,23 @@ static inline uint32_t dynamic_croaring_detect_supported_architectures(void) {
if (ebx & cpuid_avx512f_bit) {
host_isa |= CROARING_AVX512F;
}

if (ebx & cpuid_avx512bw_bit) {
host_isa |= CROARING_AVX512BW;
}

if (ebx & cpuid_avx512dq_bit) {
host_isa |= CROARING_AVX512DQ;
}

if (ecx & cpuid_avx512vbmi2_bit) {
host_isa |= CROARING_AVX512VBMI2;
}

if (ecx & cpuid_avx512bitalg_bit) {
host_isa |= CROARING_AVX512BITALG;
}

if (ecx & cpuid_avx512vpopcntdq_bit) {
host_isa |= CROARING_AVX512VPOPCNTDQ;
}
Expand Down Expand Up @@ -267,7 +267,11 @@ int croaring_hardware_support(void) {
#elif defined(__AVX2__)

int croaring_hardware_support(void) {
static int support = 0xFFFFFFF;
static
#if CROARING_ATOMIC_IMPL == CROARING_ATOMIC_IMPL_C
_Atomic
#endif
int support = 0xFFFFFFF;
if(support == 0xFFFFFFF) {
bool avx512_support = false;
#if CROARING_COMPILER_SUPPORTS_AVX512
Expand All @@ -281,7 +285,11 @@ int croaring_hardware_support(void) {
#else

int croaring_hardware_support(void) {
static int support = 0xFFFFFFF;
static
#if CROARING_ATOMIC_IMPL == CROARING_ATOMIC_IMPL_C
_Atomic
#endif
int support = 0xFFFFFFF;
if(support == 0xFFFFFFF) {
bool has_avx2 = (croaring_detect_supported_architectures() & CROARING_AVX2) == CROARING_AVX2;
bool has_avx512 = false;
Expand Down

0 comments on commit 0e27348

Please sign in to comment.