29 #ifndef PGF_BITSTREAM_H
30 #define PGF_BITSTREAM_H
37 static const UINT32
Filled = 0xFFFFFFFF;
40 #define MAKEU64(a, b) ((UINT64) (((UINT32) (a)) | ((UINT64) ((UINT32) (b))) << 32))
48 inline void SetBit(UINT32* stream, UINT32 pos) {
56 inline void ClearBit(UINT32* stream, UINT32 pos) {
65 inline bool GetBit(UINT32* stream, UINT32 pos) {
80 ASSERT(iLoInt <= iHiInt);
83 if (iLoInt == iHiInt) {
87 return (stream[iLoInt] & val) == val;
90 UINT64 v1 =
MAKEU64(stream[iLoInt], stream[iHiInt]);
91 UINT64 v2 = UINT64(val & mask) << (pos%
WordWidth);
92 return (v1 & v2) == v2;
102 inline void SetValueBlock(UINT32* stream, UINT32 pos, UINT32 val, UINT32 k) {
106 ASSERT(iLoInt <= iHiInt);
107 const UINT32 loMask =
Filled << offset;
110 if (iLoInt == iHiInt) {
112 stream[iLoInt] &= ~(loMask & hiMask);
113 stream[iLoInt] |= val << offset;
116 stream[iLoInt] &= ~loMask;
117 stream[iLoInt] |= val << offset;
118 stream[iHiInt] &= ~hiMask;
119 stream[iHiInt] |= val >> (
WordWidth - offset);
129 UINT32 count, hiCount;
135 if (iLoInt == iHiInt) {
137 count = stream[iLoInt] & (loMask & hiMask);
141 count = stream[iLoInt] & loMask;
143 hiCount = stream[iHiInt] & hiMask;
158 const UINT32 iLastInt = (pos + len - 1) >>
WordWidthLog;
163 if (iFirstInt == iLastInt) {
164 stream[iFirstInt] &= ~(startMask );
166 stream[iFirstInt] &= ~startMask;
167 for (UINT32 i = iFirstInt + 1; i <= iLastInt; i++) {
183 const UINT32 iLastInt = (pos + len - 1) >>
WordWidthLog;
188 if (iFirstInt == iLastInt) {
189 stream[iFirstInt] |= (startMask );
191 stream[iFirstInt] |= startMask;
192 for (UINT32 i = iFirstInt + 1; i <= iLastInt; i++) {
211 while (((*word & testMask) == 0) && (count < len)) {
215 word++; testMask = 1;
218 while ((count +
WordWidth <= len) && (*word == 0)) {
240 while (((*word & testMask) != 0) && (count < len)) {
244 word++; testMask = 1;
272 #endif //PGF_BITSTREAM_H