From ee17f4c6d295e82733673f824e7dba81a33e245b Mon Sep 17 00:00:00 2001 From: Pavel P Date: Sat, 18 Jan 2025 21:32:30 +0200 Subject: [PATCH] Use _bzhi_u32 for 32-bit builds when building with STATIC_BMI2 `_bzhi_u64` is available only for 64-bit builds, while `BIT_getLowerBits` expects `nbBits` to be less than `BIT_MASK_SIZE` (`BIT_MASK_SIZE` is 32) --- lib/common/bitstream.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/common/bitstream.h b/lib/common/bitstream.h index a1dac889d..c9c645416 100644 --- a/lib/common/bitstream.h +++ b/lib/common/bitstream.h @@ -162,7 +162,11 @@ MEM_STATIC size_t BIT_initCStream(BIT_CStream_t* bitC, FORCE_INLINE_TEMPLATE size_t BIT_getLowerBits(size_t bitContainer, U32 const nbBits) { #if defined(STATIC_BMI2) && STATIC_BMI2 == 1 && !defined(ZSTD_NO_INTRINSICS) - return _bzhi_u64(bitContainer, nbBits); +#if defined(__x86_64__) || defined(_M_X64) + return _bzhi_u64(bitContainer, nbBits); +#else + return _bzhi_u32(bitContainer, nbBits); +#endif #else assert(nbBits < BIT_MASK_SIZE); return bitContainer & BIT_mask[nbBits]; -- 2.47.2