Skip to content

Commit 2180ee9

Browse files
committed
fix: replace static __m256i initializer with byte array to fix GCC 13 build
GCC 13 rejects _mm256_setr_epi8() as a file-scope static initializer because the intrinsic is not a constant expression, producing: error: initializer element is not constant Replace the static __m256i popcount_lut with a plain char[32] byte array (which is a valid constant initializer) and load it with _mm256_loadu_si256 at the top of popcount_avx2(). The loaded value is semantically identical; modern compilers hoist the load out of loops when the function is inlined. Tested on GCC 13.3 (Ubuntu 24.04, x86-64).
1 parent b68d34a commit 2180ee9

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/distance-avx2.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -959,10 +959,11 @@ float int8_distance_cosine_avx2 (const void *a, const void *b, int n) {
959959

960960
// MARK: - BIT -
961961

962-
// lookup table for popcount of 4-bit values
963-
static const __m256i popcount_lut = _mm256_setr_epi8(0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4);
962+
// lookup table for popcount of 4-bit values (plain byte array — avoids GCC static-init restriction on intrinsics)
963+
static const char popcount_lut_bytes[32] = {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
964964

965965
static inline __m256i popcount_avx2(__m256i v) {
966+
__m256i popcount_lut = _mm256_loadu_si256((const __m256i*)popcount_lut_bytes);
966967
__m256i low_mask = _mm256_set1_epi8(0x0f);
967968
__m256i lo = _mm256_and_si256(v, low_mask);
968969
__m256i hi = _mm256_and_si256(_mm256_srli_epi16(v, 4), low_mask);

0 commit comments

Comments
 (0)