Skip to content

Commit b36a210

Browse files
authored
fix potential unterminated CROARING_TARGET_REGION (#456)
- bug case: `CROARING_TARGET_AVX512` is unterminated when `defined(__AVX2__) and !defined(__AVX512VBMI2__)` - fixes as: - termiate CROARING_TARGET_AVX2 with CROARING_UNTARGET_AVX2. the same to CROARING_TARGET_AVX512/CROARING_UNTARGET_AVX512. - define/undef CROARING_(UN)TARGET_{region} pair members at the same place.
1 parent ff08b57 commit b36a210

File tree

6 files changed

+107
-104
lines changed

6 files changed

+107
-104
lines changed

include/roaring/bitset_util.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ static inline __m256i popcount256(__m256i v) {
294294
const __m256i popcnt2 = _mm256_shuffle_epi8(lookupneg, hi);
295295
return _mm256_sad_epu8(popcnt1, popcnt2);
296296
}
297-
CROARING_UNTARGET_REGION
297+
CROARING_UNTARGET_AVX2
298298

299299
CROARING_TARGET_AVX2
300300
/**
@@ -306,7 +306,7 @@ static inline void CSA(__m256i *h, __m256i *l, __m256i a, __m256i b,
306306
*h = _mm256_or_si256(_mm256_and_si256(a, b), _mm256_and_si256(u, c));
307307
*l = _mm256_xor_si256(u, c);
308308
}
309-
CROARING_UNTARGET_REGION
309+
CROARING_UNTARGET_AVX2
310310

311311
CROARING_TARGET_AVX2
312312
/**
@@ -370,7 +370,7 @@ inline static uint64_t avx2_harley_seal_popcount256(const __m256i *data,
370370
(uint64_t)(_mm256_extract_epi64(total, 2)) +
371371
(uint64_t)(_mm256_extract_epi64(total, 3));
372372
}
373-
CROARING_UNTARGET_REGION
373+
CROARING_UNTARGET_AVX2
374374

375375
#define AVXPOPCNTFNC(opname, avx_intrinsic) \
376376
static inline uint64_t avx2_harley_seal_popcount256_##opname( \
@@ -554,27 +554,27 @@ CROARING_UNTARGET_REGION
554554

555555
CROARING_TARGET_AVX2
556556
AVXPOPCNTFNC(or, _mm256_or_si256)
557-
CROARING_UNTARGET_REGION
557+
CROARING_UNTARGET_AVX2
558558

559559
CROARING_TARGET_AVX2
560560
AVXPOPCNTFNC(union, _mm256_or_si256)
561-
CROARING_UNTARGET_REGION
561+
CROARING_UNTARGET_AVX2
562562

563563
CROARING_TARGET_AVX2
564564
AVXPOPCNTFNC(and, _mm256_and_si256)
565-
CROARING_UNTARGET_REGION
565+
CROARING_UNTARGET_AVX2
566566

567567
CROARING_TARGET_AVX2
568568
AVXPOPCNTFNC(intersection, _mm256_and_si256)
569-
CROARING_UNTARGET_REGION
569+
CROARING_UNTARGET_AVX2
570570

571571
CROARING_TARGET_AVX2
572572
AVXPOPCNTFNC (xor, _mm256_xor_si256)
573-
CROARING_UNTARGET_REGION
573+
CROARING_UNTARGET_AVX2
574574

575575
CROARING_TARGET_AVX2
576576
AVXPOPCNTFNC(andnot, _mm256_andnot_si256)
577-
CROARING_UNTARGET_REGION
577+
CROARING_UNTARGET_AVX2
578578

579579

580580
#define VPOPCNT_AND_ADD(ptr, i, accu) \
@@ -622,7 +622,7 @@ static inline uint64_t avx512_vpopcount(const __m512i* data, const uint64_t size
622622

623623
return simd_sum_epu64(total);
624624
}
625-
CROARING_UNTARGET_REGION
625+
CROARING_UNTARGET_AVX512
626626
#endif
627627

628628
#define AVXPOPCNTFNC512(opname, avx_intrinsic) \
@@ -693,7 +693,7 @@ AVXPOPCNTFNC512(and, _mm512_and_si512)
693693
AVXPOPCNTFNC512(intersection, _mm512_and_si512)
694694
AVXPOPCNTFNC512(xor, _mm512_xor_si512)
695695
AVXPOPCNTFNC512(andnot, _mm512_andnot_si512)
696-
CROARING_UNTARGET_REGION
696+
CROARING_UNTARGET_AVX512
697697
#endif
698698
/***
699699
* END Harley-Seal popcount functions.

include/roaring/portability.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,25 +333,28 @@ static inline int roaring_hamming(uint64_t x) {
333333
#define CROARING_UNTARGET_REGION
334334
#endif
335335

336+
336337
#define CROARING_TARGET_AVX2 CROARING_TARGET_REGION("avx2,bmi,pclmul,lzcnt")
337338
#define CROARING_TARGET_AVX512 CROARING_TARGET_REGION("bmi2,avx512f,avx512dq,avx512bw,avx512vbmi2,avx512bitalg,avx512vpopcntdq")
339+
#define CROARING_UNTARGET_AVX2 CROARING_UNTARGET_REGION
340+
#define CROARING_UNTARGET_AVX512 CROARING_UNTARGET_REGION
338341

339342
#ifdef __AVX2__
340343
// No need for runtime dispatching.
341344
// It is unnecessary and harmful to old clang to tag regions.
342345
#undef CROARING_TARGET_AVX2
343346
#define CROARING_TARGET_AVX2
344-
#undef CROARING_UNTARGET_REGION
345-
#define CROARING_UNTARGET_REGION
347+
#undef CROARING_UNTARGET_AVX2
348+
#define CROARING_UNTARGET_AVX2
346349
#endif
347350

348351
#if defined(__AVX512F__) && defined(__AVX512DQ__) && defined(__AVX512BW__) && defined(__AVX512VBMI2__) && defined(__AVX512BITALG__) && defined(__AVX512VPOPCNTDQ__)
349352
// No need for runtime dispatching.
350353
// It is unnecessary and harmful to old clang to tag regions.
351354
#undef CROARING_TARGET_AVX512
352355
#define CROARING_TARGET_AVX512
353-
#undef CROARING_UNTARGET_REGION
354-
#define CROARING_UNTARGET_REGION
356+
#undef CROARING_UNTARGET_AVX512
357+
#define CROARING_UNTARGET_AVX512
355358
#endif
356359

357360
// Allow unaligned memory access

src/array_util.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ int32_t intersect_vector16_inplace(uint16_t *__restrict__ A, size_t s_a,
536536
}
537537
return (int32_t)count;
538538
}
539-
CROARING_UNTARGET_REGION
539+
CROARING_UNTARGET_AVX2
540540

541541
CROARING_TARGET_AVX2
542542
int32_t intersect_vector16_cardinality(const uint16_t *__restrict__ A,
@@ -608,7 +608,7 @@ int32_t intersect_vector16_cardinality(const uint16_t *__restrict__ A,
608608
}
609609
return (int32_t)count;
610610
}
611-
CROARING_UNTARGET_REGION
611+
CROARING_UNTARGET_AVX2
612612

613613
CROARING_TARGET_AVX2
614614
/////////
@@ -752,7 +752,7 @@ int32_t difference_vector16(const uint16_t *__restrict__ A, size_t s_a,
752752
}
753753
return count;
754754
}
755-
CROARING_UNTARGET_REGION
755+
CROARING_UNTARGET_AVX2
756756
#endif // CROARING_IS_X64
757757

758758

@@ -1241,7 +1241,7 @@ static inline void sse_merge(const __m128i *vInput1,
12411241
*vecMax = _mm_max_epu16(vecTmp, *vecMax);
12421242
*vecMin = _mm_alignr_epi8(*vecMin, *vecMin, 2);
12431243
}
1244-
CROARING_UNTARGET_REGION
1244+
CROARING_UNTARGET_AVX2
12451245
// used by store_unique, generated by simdunion.py
12461246
static uint8_t uniqshuf[] = {
12471247
0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb,
@@ -1600,7 +1600,7 @@ static inline int store_unique(__m128i old, __m128i newval, uint16_t *output) {
16001600
_mm_storeu_si128((__m128i *)output, val);
16011601
return numberofnewvalues;
16021602
}
1603-
CROARING_UNTARGET_REGION
1603+
CROARING_UNTARGET_AVX2
16041604

16051605
// working in-place, this function overwrites the repeated values
16061606
// could be avoided?
@@ -1701,7 +1701,7 @@ uint32_t union_vector16(const uint16_t *__restrict__ array1, uint32_t length1,
17011701
}
17021702
return len;
17031703
}
1704-
CROARING_UNTARGET_REGION
1704+
CROARING_UNTARGET_AVX2
17051705

17061706
/**
17071707
* End of the SIMD 16-bit union code
@@ -1730,7 +1730,7 @@ static inline int store_unique_xor(__m128i old, __m128i newval,
17301730
_mm_storeu_si128((__m128i *)output, val);
17311731
return numberofnewvalues;
17321732
}
1733-
CROARING_UNTARGET_REGION
1733+
CROARING_UNTARGET_AVX2
17341734

17351735
// working in-place, this function overwrites the repeated values
17361736
// could be avoided? Warning: assumes len > 0
@@ -1848,7 +1848,7 @@ uint32_t xor_vector16(const uint16_t *__restrict__ array1, uint32_t length1,
18481848
}
18491849
return len;
18501850
}
1851-
CROARING_UNTARGET_REGION
1851+
CROARING_UNTARGET_AVX2
18521852
/**
18531853
* End of SIMD 16-bit XOR code
18541854
*/
@@ -2041,7 +2041,7 @@ static inline bool _avx512_memequals(const void *s1, const void *s2, size_t n) {
20412041

20422042
return true;
20432043
}
2044-
CROARING_UNTARGET_REGION
2044+
CROARING_UNTARGET_AVX512
20452045
#endif // CROARING_COMPILER_SUPPORTS_AVX512
20462046

20472047
CROARING_TARGET_AVX2
@@ -2084,7 +2084,7 @@ static inline bool _avx2_memequals(const void *s1, const void *s2, size_t n) {
20842084

20852085
return true;
20862086
}
2087-
CROARING_UNTARGET_REGION
2087+
CROARING_UNTARGET_AVX2
20882088
#endif
20892089

20902090
bool memequals(const void *s1, const void *s2, size_t n) {

src/bitset_util.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ size_t bitset_extract_setbits_avx512_uint16(const uint64_t *array, size_t length
661661

662662
return out - initout;
663663
}
664-
CROARING_UNTARGET_REGION
664+
CROARING_UNTARGET_AVX512
665665
#endif
666666

667667
CROARING_TARGET_AVX2
@@ -716,7 +716,7 @@ size_t bitset_extract_setbits_avx2(const uint64_t *words, size_t length,
716716
}
717717
return out - initout;
718718
}
719-
CROARING_UNTARGET_REGION
719+
CROARING_UNTARGET_AVX2
720720
#endif // CROARING_IS_X64
721721

722722
size_t bitset_extract_setbits(const uint64_t *words, size_t length,
@@ -820,7 +820,7 @@ size_t bitset_extract_setbits_sse_uint16(const uint64_t *words, size_t length,
820820
}
821821
return out - initout;
822822
}
823-
CROARING_UNTARGET_REGION
823+
CROARING_UNTARGET_AVX2
824824
#endif
825825

826826
/*

0 commit comments

Comments
 (0)