From 2180ee99438f16553c2c0070ea563d58068f633c Mon Sep 17 00:00:00 2001 From: jeremydixon22 Date: Fri, 29 May 2026 18:37:34 -0400 Subject: [PATCH] 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). --- src/distance-avx2.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/distance-avx2.c b/src/distance-avx2.c index 8e0da29..4108467 100644 --- a/src/distance-avx2.c +++ b/src/distance-avx2.c @@ -959,10 +959,11 @@ float int8_distance_cosine_avx2 (const void *a, const void *b, int n) { // MARK: - BIT - -// lookup table for popcount of 4-bit values -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); +// lookup table for popcount of 4-bit values (plain byte array — avoids GCC static-init restriction on intrinsics) +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}; static inline __m256i popcount_avx2(__m256i v) { + __m256i popcount_lut = _mm256_loadu_si256((const __m256i*)popcount_lut_bytes); __m256i low_mask = _mm256_set1_epi8(0x0f); __m256i lo = _mm256_and_si256(v, low_mask); __m256i hi = _mm256_and_si256(_mm256_srli_epi16(v, 4), low_mask);