GLAST / LAT > DAQ and FSW > FSW > Doxygen Index> LDT / dev > encdec / rhel6-64
#include <PBI/BSWP.ih>
Classes | |
struct | _BA |
Provides the bare minimum context to keep track of a buffered array of bits. Since, in general, the bits are buffered in a temporary structure before being output, they must be flushed. More... | |
Defines | |
#define | BA_STORE(_out, _buf) BSWP__store32b(_out, _buf) |
#define | BA_LOAD(_out) BSWP__load32b(_out) |
#define | BA_WRITE_R(_out, _buffer, _to_go, _bits, _n) |
#define | BA_WRITE_L(_out, _buffer, _to_go, _bits, _n) |
#define | BA_FLUSH(_cur, _buffer, _togo) |
Typedefs | |
typedef struct _BA | BA |
Typedef for struct _BA. |
CVS $Id: BA.h,v 1.4 2011/03/25 23:57:13 russell Exp $
Provides a fast way to pack bits into an array. The bits are packed big endian style, i.e. msb -> lsb
#define BA_FLUSH | ( | _cur, | |||
_buffer, | |||||
_togo | ) |
Value:
if (_togo != 32) \
{ \
_buffer <<= _togo; \
BA_STORE(_cur, _buffer); \
_cur += 1; \
}
#define BA_WRITE_L | ( | _out, | |||
_buffer, | |||||
_to_go, | |||||
_bits, | |||||
_n | ) |
Value:
do \ { \ int left = _n - _to_go; \ if (left >= 0) \ { \ /* Not enough room for all the bits, put in what will fit */ \ _buffer <<= _to_go; \ _buffer |= (unsigned)_bits >> (32 - _to_go); \ BA_STORE(_out, _buffer); \ printf ("Storing %x\n", *_out); \ _out++; \ _buffer = 0; \ if (left) \ { \ _buffer |= ((unsigned)_bits << _to_go) >> (32 - left); \ } \ _to_go = 32 - left; \ } \ else \ { \ /* Put the last bits in */ \ _buffer <<= _n; \ _buffer |= (unsigned)_bits >> (32 - _n); \ _to_go -= _n; \ } \ } while (0)
#define BA_WRITE_R | ( | _out, | |||
_buffer, | |||||
_to_go, | |||||
_bits, | |||||
_n | ) |
Value:
do \ { \ int left = _n - _to_go; \ /* _dprintf ("N:%2u B:%x T:%2u L:%3d", _n, _bits, _to_go, left); */ \ if (left >= 0) \ { \ /* Not enough room for all the bits, put in what will fit */ \ _buffer <<= _to_go; \ _buffer |= (unsigned)_bits >> left; \ BA_STORE(_out, _buffer); \ /* _dprintf (" %8.8x", *_out); */ \ _out++; \ /* _buffer = 0; */ \ if (left) \ { \ _buffer = ((unsigned)_bits & ((1 << left) - 1)); \ /* _dprintf (" %8.8x", _buffer); */ \ } \ /* _dprintf ("\n"); */ \ _to_go = 32 - left; \ } \ else \ { \ /* Put the last bits in */ \ _buffer <<= _n; \ _buffer |= (unsigned)_bits; \ /* _dprintf (" %8.8x\n", _buffer); */ \ _to_go -= _n; \ } \ } while (0)