38 static const uint32_t
Filled = 0xFFFFFFFF;
41#define MAKEU64(a, b) ((uint64_t) (((uint32_t) (a)) | ((uint64_t) ((uint32_t) (b))) << 32))
62 inline void SetBit(uint32_t* stream, uint32_t pos) {
70 inline void ClearBit(uint32_t* stream, uint32_t pos) {
79 inline bool GetBit(uint32_t* stream, uint32_t pos) {
91 inline bool CompareBitBlock(uint32_t* stream, uint32_t pos, uint32_t k, uint32_t val) {
94 ASSERT(iLoInt <= iHiInt);
97 if (iLoInt == iHiInt) {
101 return (stream[iLoInt] & val) == val;
104 uint64_t v1 =
MAKEU64(stream[iLoInt], stream[iHiInt]);
105 uint64_t v2 = uint64_t(val & mask) << (pos%
WordWidth);
106 return (v1 & v2) == v2;
116 inline void SetValueBlock(uint32_t* stream, uint32_t pos, uint32_t val, uint32_t k) {
120 ASSERT(iLoInt <= iHiInt);
121 const uint32_t loMask =
Filled << offset;
124 if (iLoInt == iHiInt) {
126 stream[iLoInt] &= ~(loMask & hiMask);
127 stream[iLoInt] |= val << offset;
130 stream[iLoInt] &= ~loMask;
131 stream[iLoInt] |= val << offset;
132 stream[iHiInt] &= ~hiMask;
133 stream[iHiInt] |= val >> (
WordWidth - offset);
143 uint32_t count, hiCount;
149 if (iLoInt == iHiInt) {
151 count = stream[iLoInt] & (loMask & hiMask);
155 count = stream[iLoInt] & loMask;
157 hiCount = stream[iHiInt] & hiMask;
172 const uint32_t iLastInt = (pos + len - 1) >>
WordWidthLog;
177 if (iFirstInt == iLastInt) {
178 stream[iFirstInt] &= ~(startMask );
180 stream[iFirstInt] &= ~startMask;
181 for (uint32_t i = iFirstInt + 1; i <= iLastInt; i++) {
193 inline void SetBitBlock(uint32_t* stream, uint32_t pos, uint32_t len) {
197 const uint32_t iLastInt = (pos + len - 1) >>
WordWidthLog;
202 if (iFirstInt == iLastInt) {
203 stream[iFirstInt] |= (startMask );
205 stream[iFirstInt] |= startMask;
206 for (uint32_t i = iFirstInt + 1; i <= iLastInt; i++) {
220 inline uint32_t
SeekBitRange(uint32_t* stream, uint32_t pos, uint32_t len) {
222 uint32_t testMask = 1 << (pos%
WordWidth);
225 while (((*word & testMask) == 0) && (count < len)) {
229 word++; testMask = 1;
232 while ((count +
WordWidth <= len) && (*word == 0)) {
249 inline uint32_t
SeekBit1Range(uint32_t* stream, uint32_t pos, uint32_t len) {
251 uint32_t testMask = 1 << (pos%
WordWidth);
254 while (((*word & testMask) != 0) && (count < len)) {
258 word++; testMask = 1;
274 inline void BitCopy(const uint8_t *sStream, uint32_t sPos, uint8_t *dStream, uint32_t dPos, uint32_t k) {
277 div_t divS = div(sPos, 8);
278 div_t divD = div(dPos, 8);
279 uint32_t sOff = divS.rem;
280 uint32_t dOff = divD.rem;
281 int32_t tmp = div(dPos + k - 1, 8).quot;
283 const uint8_t *sAddr = sStream + divS.quot;
284 uint8_t *dAddrS = dStream + divD.quot;
285 uint8_t *dAddrE = dStream + tmp;
288 uint8_t destSB = *dAddrS;
289 uint8_t destEB = *dAddrE;
292 int32_t shiftl, shiftr;
296 shiftr = dOff - sOff;
297 shiftl = 8 - dOff + sOff;
299 prec = *sAddr << (sOff - dOff);
300 shiftr = 8 - sOff + dOff;
301 shiftl = sOff - dOff;
305 for (dAddr = dAddrS; dAddr < dAddrE; dAddr++, sAddr++) {
306 *dAddr = prec | (*sAddr >> shiftr);
307 prec = *sAddr << shiftl;
310 if ((sPos + k)%8 == 0) {
313 *dAddr = prec | (*sAddr >> shiftr);
317 *dAddrS = (destSB & eMask) | (*dAddrS & (~eMask));
319 int32_t mind = (dPos + k) % 8;
320 eMask = (mind) ? lMask[mind] : lMask[8];
321 *dAddrE = (destEB & (~eMask)) | (*dAddrE & eMask);
#define MAKEU64(a, b)
Make 64 bit unsigned integer from two 32 bit unsigned integers.
void ClearBit(uint32_t *stream, uint32_t pos)
bool CompareBitBlock(uint32_t *stream, uint32_t pos, uint32_t k, uint32_t val)
void ClearBitBlock(uint32_t *stream, uint32_t pos, uint32_t len)
void SetBitBlock(uint32_t *stream, uint32_t pos, uint32_t len)
static const uint32_t Filled
void SetBit(uint32_t *stream, uint32_t pos)
void SetValueBlock(uint32_t *stream, uint32_t pos, uint32_t val, uint32_t k)
bool GetBit(uint32_t *stream, uint32_t pos)
uint32_t GetValueBlock(uint32_t *stream, uint32_t pos, uint32_t k)
uint32_t SeekBitRange(uint32_t *stream, uint32_t pos, uint32_t len)
uint32_t AlignWordPos(uint32_t pos)
uint32_t NumberOfWords(uint32_t pos)
uint32_t SeekBit1Range(uint32_t *stream, uint32_t pos, uint32_t len)