Skip to content

Commit e8448a3

Browse files
authored
Merge pull request #3080 from TocarIP/tokarip/static_bmi2
Enable STATIC_BMI2 for gcc/clang
2 parents 0c386af + 7c3d1cb commit e8448a3

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/common/bitstream.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ extern "C" {
3737
* Target specific
3838
=========================================*/
3939
#ifndef ZSTD_NO_INTRINSICS
40-
# if defined(__BMI__) && defined(__GNUC__)
41-
# include <immintrin.h> /* support for bextr (experimental) */
40+
# if (defined(__BMI__) || defined(__BMI2__)) && defined(__GNUC__)
41+
# include <immintrin.h> /* support for bextr (experimental)/bzhi */
4242
# elif defined(__ICCARM__)
4343
# include <intrinsics.h>
4444
# endif
@@ -164,8 +164,8 @@ MEM_STATIC size_t BIT_initCStream(BIT_CStream_t* bitC,
164164

165165
MEM_STATIC FORCE_INLINE_ATTR size_t BIT_getLowerBits(size_t bitContainer, U32 const nbBits)
166166
{
167-
#if defined(STATIC_BMI2) && STATIC_BMI2 == 1
168-
return _bzhi_u64(bitContainer, nbBits);
167+
#if defined(STATIC_BMI2) && STATIC_BMI2 == 1 && !defined(ZSTD_NO_INTRINSICS)
168+
return _bzhi_u64(bitContainer, nbBits);
169169
#else
170170
assert(nbBits < BIT_MASK_SIZE);
171171
return bitContainer & BIT_mask[nbBits];

lib/common/compiler.h

+2
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@
181181
# ifdef __AVX2__ //MSVC does not have a BMI2 specific flag, but every CPU that supports AVX2 also supports BMI2
182182
# define STATIC_BMI2 1
183183
# endif
184+
# elif defined(__BMI2__) && defined(__x86_64__) && defined(__GNUC__)
185+
# define STATIC_BMI2 1
184186
# endif
185187
#endif
186188

0 commit comments

Comments
 (0)