mirror of
https://github.com/facebook/zstd.git
synced 2025-12-07 00:02:39 -05:00
Merge pull request #3075 from TocarIP/tokarip/bzhi
Use helper function for bit manipulations.
This commit is contained in:
commit
87406b5f3b
@ -162,6 +162,16 @@ MEM_STATIC size_t BIT_initCStream(BIT_CStream_t* bitC,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MEM_STATIC FORCE_INLINE_ATTR size_t BIT_getLowerBits(size_t bitContainer, U32 const nbBits)
|
||||||
|
{
|
||||||
|
#if defined(STATIC_BMI2) && STATIC_BMI2 == 1
|
||||||
|
return _bzhi_u64(bitContainer, nbBits);
|
||||||
|
#else
|
||||||
|
assert(nbBits < BIT_MASK_SIZE);
|
||||||
|
return bitContainer & BIT_mask[nbBits];
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/*! BIT_addBits() :
|
/*! BIT_addBits() :
|
||||||
* can add up to 31 bits into `bitC`.
|
* can add up to 31 bits into `bitC`.
|
||||||
* Note : does not check for register overflow ! */
|
* Note : does not check for register overflow ! */
|
||||||
@ -171,7 +181,7 @@ MEM_STATIC void BIT_addBits(BIT_CStream_t* bitC,
|
|||||||
DEBUG_STATIC_ASSERT(BIT_MASK_SIZE == 32);
|
DEBUG_STATIC_ASSERT(BIT_MASK_SIZE == 32);
|
||||||
assert(nbBits < BIT_MASK_SIZE);
|
assert(nbBits < BIT_MASK_SIZE);
|
||||||
assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8);
|
assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8);
|
||||||
bitC->bitContainer |= (value & BIT_mask[nbBits]) << bitC->bitPos;
|
bitC->bitContainer |= BIT_getLowerBits(value, nbBits) << bitC->bitPos;
|
||||||
bitC->bitPos += nbBits;
|
bitC->bitPos += nbBits;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,16 +319,6 @@ MEM_STATIC FORCE_INLINE_ATTR size_t BIT_getMiddleBits(size_t bitContainer, U32 c
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
MEM_STATIC FORCE_INLINE_ATTR size_t BIT_getLowerBits(size_t bitContainer, U32 const nbBits)
|
|
||||||
{
|
|
||||||
#if defined(STATIC_BMI2) && STATIC_BMI2 == 1
|
|
||||||
return _bzhi_u64(bitContainer, nbBits);
|
|
||||||
#else
|
|
||||||
assert(nbBits < BIT_MASK_SIZE);
|
|
||||||
return bitContainer & BIT_mask[nbBits];
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! BIT_lookBits() :
|
/*! BIT_lookBits() :
|
||||||
* Provides next n bits from local register.
|
* Provides next n bits from local register.
|
||||||
* local register is not modified.
|
* local register is not modified.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user