BitStream.h man page

BitStream.h —

Synopsis

#include 'PGFtypes.h'

Macros

#define MAKEU64(a, b) ((UINT64) (((UINT32) (a)) | ((UINT64) ((UINT32) (b))) << 32))
Make 64 bit unsigned integer from two 32 bit unsigned integers.

Functions

void SetBit (UINT32 *stream, UINT32 pos)

void ClearBit (UINT32 *stream, UINT32 pos)

bool GetBit (UINT32 *stream, UINT32 pos)

bool CompareBitBlock (UINT32 *stream, UINT32 pos, UINT32 k, UINT32 val)

void SetValueBlock (UINT32 *stream, UINT32 pos, UINT32 val, UINT32 k)

UINT32 GetValueBlock (UINT32 *stream, UINT32 pos, UINT32 k)

void ClearBitBlock (UINT32 *stream, UINT32 pos, UINT32 len)

void SetBitBlock (UINT32 *stream, UINT32 pos, UINT32 len)

UINT32 SeekBitRange (UINT32 *stream, UINT32 pos, UINT32 len)

UINT32 SeekBit1Range (UINT32 *stream, UINT32 pos, UINT32 len)

UINT32 AlignWordPos (UINT32 pos)

UINT32 NumberOfWords (UINT32 pos)

Variables

static const UINT32 Filled = 0xFFFFFFFF

Macro Definition Documentation

#define MAKEU64(a, b) ((UINT64) (((UINT32) (a)) | ((UINT64) ((UINT32) (b))) << 32))

Make 64 bit unsigned integer from two 32 bit unsigned integers.

Definition at line 40 of file BitStream.h.

Function Documentation

UINT32 AlignWordPos (UINT32 pos) [inline]

Compute bit position of the next 32-bit word

Parameters:

pos current bit stream position

Returns:

bit position of next 32-bit word

Definition at line 260 of file BitStream.h.

260                                        {
261 //      return ((pos + WordWidth - 1) >> WordWidthLog) << WordWidthLog;
262         return DWWIDTHBITS(pos);
263 }

void ClearBit (UINT32 * stream, UINT32 pos) [inline]

Set one bit of a bit stream to 0

Parameters:

stream A bit stream stored in array of unsigned integers
pos A valid zero-based position in the bit stream

Definition at line 56 of file BitStream.h.

56                                                  {
57         stream[pos >> WordWidthLog] &= ~(1 << (pos%WordWidth)); 
58 }

void ClearBitBlock (UINT32 * stream, UINT32 pos, UINT32 len) [inline]

Clear block of size at least len at position pos in stream

Parameters:

stream A bit stream stored in array of unsigned integers
pos A valid zero-based position in the bit stream
len Number of bits set to 0

Definition at line 155 of file BitStream.h.

155                                                                   {
156         ASSERT(len > 0);
157         const UINT32 iFirstInt = pos >> WordWidthLog;
158         const UINT32 iLastInt = (pos + len - 1) >> WordWidthLog;
159 
160         const UINT32 startMask = Filled << (pos%WordWidth);
161 //      const UINT32 endMask=Filled>>(WordWidth-1-((pos+len-1)%WordWidth));
162 
163         if (iFirstInt == iLastInt) {
164                 stream[iFirstInt] &= ~(startMask /*& endMask*/);
165         } else {
166                 stream[iFirstInt] &= ~startMask;
167                 for (UINT32 i = iFirstInt + 1; i <= iLastInt; i++) { // changed <=
168                         stream[i] = 0;
169                 }
170                 //stream[iLastInt] &= ~endMask;
171         }
172 }

bool CompareBitBlock (UINT32 * stream, UINT32 pos, UINT32 k, UINT32 val) [inline]

Compare k-bit binary representation of stream at position pos with val

Parameters:

stream A bit stream stored in array of unsigned integers
pos A valid zero-based position in the bit stream
k Number of bits to compare
val Value to compare with

Returns:

true if equal

Definition at line 77 of file BitStream.h.

77                                                                               {
78         const UINT32 iLoInt = pos >> WordWidthLog;
79         const UINT32 iHiInt = (pos + k - 1) >> WordWidthLog;
80         ASSERT(iLoInt <= iHiInt);
81         const UINT32 mask = (Filled >> (WordWidth - k));
82 
83         if (iLoInt == iHiInt) {
84                 // fits into one integer
85                 val &= mask;
86                 val <<= (pos%WordWidth);
87                 return (stream[iLoInt] & val) == val;
88         } else {
89                 // must be splitted over integer boundary
90                 UINT64 v1 = MAKEU64(stream[iLoInt], stream[iHiInt]);
91                 UINT64 v2 = UINT64(val & mask) << (pos%WordWidth);
92                 return (v1 & v2) == v2;
93         }
94 }

bool GetBit (UINT32 * stream, UINT32 pos) [inline]

Return one bit of a bit stream

Parameters:

stream A bit stream stored in array of unsigned integers
pos A valid zero-based position in the bit stream

Returns:

bit at position pos of bit stream stream

Definition at line 65 of file BitStream.h.

65                                                 {
66         return (stream[pos >> WordWidthLog] & (1 << (pos%WordWidth))) > 0;
67 
68 }

UINT32 GetValueBlock (UINT32 * stream, UINT32 pos, UINT32 k) [inline]

Read k-bit number from stream at position pos

Parameters:

stream A bit stream stored in array of unsigned integers
pos A valid zero-based position in the bit stream
k Number of bits to read: 1 <= k <= 32

Definition at line 128 of file BitStream.h.

128                                                                   {
129         UINT32 count, hiCount;
130         const UINT32 iLoInt = pos >> WordWidthLog;                              // integer of first bit
131         const UINT32 iHiInt = (pos + k - 1) >> WordWidthLog;            // integer of last bit
132         const UINT32 loMask = Filled << (pos%WordWidth);
133         const UINT32 hiMask = Filled >> (WordWidth - 1 - ((pos + k - 1)%WordWidth));
134         
135         if (iLoInt == iHiInt) {
136                 // inside integer boundary
137                 count = stream[iLoInt] & (loMask & hiMask);
138                 count >>= pos%WordWidth;
139         } else {
140                 // overlapping integer boundary
141                 count = stream[iLoInt] & loMask;
142                 count >>= pos%WordWidth;
143                 hiCount = stream[iHiInt] & hiMask;
144                 hiCount <<= WordWidth - (pos%WordWidth);
145                 count |= hiCount;
146         }
147         return count;
148 }

UINT32 NumberOfWords (UINT32 pos) [inline]

Compute number of the 32-bit words

Parameters:

pos Current bit stream position

Returns:

Number of 32-bit words

Definition at line 269 of file BitStream.h.

269                                         {
270         return (pos + WordWidth - 1) >> WordWidthLog;
271 }

UINT32 SeekBit1Range (UINT32 * stream, UINT32 pos, UINT32 len) [inline]

Returns the distance to the next 0 in stream at position pos. If no 0 is found within len bits, then len is returned.

Parameters:

stream A bit stream stored in array of unsigned integers
pos A valid zero-based position in the bit stream
len size of search area (in bits) return The distance to the next 0 in stream at position pos

Definition at line 235 of file BitStream.h.

235                                                                     {
236         UINT32 count = 0;
237         UINT32 testMask = 1 << (pos%WordWidth);
238         UINT32* word = stream + (pos >> WordWidthLog);
239 
240         while (((*word & testMask) != 0) && (count < len)) {
241                 count++; 
242                 testMask <<= 1;
243                 if (!testMask) {
244                         word++; testMask = 1;
245 
246                         // fast steps if all bits in a word are one
247                         while ((count + WordWidth <= len) && (*word == Filled)) {
248                                 word++; 
249                                 count += WordWidth;
250                         }
251                 }
252         }
253         return count;
254 }

UINT32 SeekBitRange (UINT32 * stream, UINT32 pos, UINT32 len) [inline]

Returns the distance to the next 1 in stream at position pos. If no 1 is found within len bits, then len is returned.

Parameters:

stream A bit stream stored in array of unsigned integers
pos A valid zero-based position in the bit stream
len size of search area (in bits) return The distance to the next 1 in stream at position pos

Definition at line 206 of file BitStream.h.

206                                                                    {
207         UINT32 count = 0;
208         UINT32 testMask = 1 << (pos%WordWidth);
209         UINT32* word = stream + (pos >> WordWidthLog);
210 
211         while (((*word & testMask) == 0) && (count < len)) {
212                 count++; 
213                 testMask <<= 1;
214                 if (!testMask) {
215                         word++; testMask = 1;
216 
217                         // fast steps if all bits in a word are zero
218                         while ((count + WordWidth <= len) && (*word == 0)) {
219                                 word++; 
220                                 count += WordWidth;
221                         }
222                 }
223         }
224 
225         return count;
226 }

void SetBit (UINT32 * stream, UINT32 pos) [inline]

Set one bit of a bit stream to 1

Parameters:

stream A bit stream stored in array of unsigned integers
pos A valid zero-based position in the bit stream

Definition at line 48 of file BitStream.h.

48                                                {
49         stream[pos >> WordWidthLog] |= (1 << (pos%WordWidth));
50 }

void SetBitBlock (UINT32 * stream, UINT32 pos, UINT32 len) [inline]

Set block of size at least len at position pos in stream

Parameters:

stream A bit stream stored in array of unsigned integers
pos A valid zero-based position in the bit stream
len Number of bits set to 1

Definition at line 179 of file BitStream.h.

179                                                                 {
180         ASSERT(len > 0);
181 
182         const UINT32 iFirstInt = pos >> WordWidthLog;
183         const UINT32 iLastInt = (pos + len - 1) >> WordWidthLog;
184 
185         const UINT32 startMask = Filled << (pos%WordWidth);
186 //      const UINT32 endMask=Filled>>(WordWidth-1-((pos+len-1)%WordWidth));
187 
188         if (iFirstInt == iLastInt) {
189                 stream[iFirstInt] |= (startMask /*& endMask*/);
190         } else {
191                 stream[iFirstInt] |= startMask;
192                 for (UINT32 i = iFirstInt + 1; i <= iLastInt; i++) { // changed <=
193                         stream[i] = Filled;
194                 }
195                 //stream[iLastInt] &= ~endMask;
196         }
197 }

void SetValueBlock (UINT32 * stream, UINT32 pos, UINT32 val, UINT32 k) [inline]

Store k-bit binary representation of val in stream at position pos

Parameters:

stream A bit stream stored in array of unsigned integers
pos A valid zero-based position in the bit stream
val Value to store in stream at position pos
k Number of bits of integer representation of val

Definition at line 102 of file BitStream.h.

102                                                                             {
103         const UINT32 offset = pos%WordWidth;
104         const UINT32 iLoInt = pos >> WordWidthLog;
105         const UINT32 iHiInt = (pos + k - 1) >> WordWidthLog;
106         ASSERT(iLoInt <= iHiInt);
107         const UINT32 loMask = Filled << offset;
108         const UINT32 hiMask = Filled >> (WordWidth - 1 - ((pos + k - 1)%WordWidth));
109 
110         if (iLoInt == iHiInt) {
111                 // fits into one integer
112                 stream[iLoInt] &= ~(loMask & hiMask); // clear bits
113                 stream[iLoInt] |= val << offset; // write value
114         } else {
115                 // must be splitted over integer boundary
116                 stream[iLoInt] &= ~loMask; // clear bits
117                 stream[iLoInt] |= val << offset; // write lower part of value
118                 stream[iHiInt] &= ~hiMask; // clear bits
119                 stream[iHiInt] |= val >> (WordWidth - offset); // write higher part of value
120         }
121 }

Variable Documentation

const UINT32 Filled = 0xFFFFFFFF [static]

Definition at line 37 of file BitStream.h.

Author

Generated automatically by Doxygen for libpgf from the source code.

Info

Thu Feb 4 2016 Version 6.14.12 libpgf