\hypertarget{BA_8h}{
\section{BA.h File Reference}
\label{BA_8h}\index{BA.h@{BA.h}}
}
Bit array structure.  


{\tt \#include $<$PBI/BSWP.ih$>$}\par
\subsection*{Classes}
\begin{CompactItemize}
\item 
struct \hyperlink{struct__BA}{\_\-BA}
\begin{CompactList}\small\item\em 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. \item\end{CompactList}\end{CompactItemize}
\subsection*{Defines}
\begin{CompactItemize}
\item 
\hypertarget{BA_8h_5966683080ace4c196ca9c08e2240bc1}{
\#define \textbf{BA\_\-STORE}(\_\-out, \_\-buf)~BSWP\_\-\_\-store32b(\_\-out, \_\-buf)}
\label{BA_8h_5966683080ace4c196ca9c08e2240bc1}

\item 
\hypertarget{BA_8h_6c956bf5bacd016f767250e8b7cccf0a}{
\#define \textbf{BA\_\-LOAD}(\_\-out)~BSWP\_\-\_\-load32b(\_\-out)}
\label{BA_8h_6c956bf5bacd016f767250e8b7cccf0a}

\item 
\#define \textbf{BA\_\-WRITE\_\-R}(\_\-out, \_\-buffer, \_\-to\_\-go, \_\-bits, \_\-n)
\item 
\#define \textbf{BA\_\-WRITE\_\-L}(\_\-out, \_\-buffer, \_\-to\_\-go, \_\-bits, \_\-n)
\item 
\#define \textbf{BA\_\-FLUSH}(\_\-cur, \_\-buffer, \_\-togo)
\end{CompactItemize}
\subsection*{Typedefs}
\begin{CompactItemize}
\item 
\hypertarget{BA_8h_8d2bbbd99979370d0c45f5246fdce510}{
typedef struct \hyperlink{struct__BA}{\_\-BA} \hyperlink{BA_8h_8d2bbbd99979370d0c45f5246fdce510}{BA}}
\label{BA_8h_8d2bbbd99979370d0c45f5246fdce510}

\begin{CompactList}\small\item\em Typedef for struct \hyperlink{struct__BA}{\_\-BA}. \item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}
Bit array structure. 

\begin{Desc}
\item[Author:]JJRussell - \href{mailto:russell@slac.stanford.edu}{\tt russell@slac.stanford.edu}\end{Desc}


\footnotesize\begin{verbatim}

   CVS $Id: BA.h,v 1.4 2011/03/25 23:57:13 russell Exp $
\end{verbatim}
\normalsize


Provides a fast way to pack bits into an array. The bits are packed big endian style, i.e. msb -$>$ lsb 

\subsection{Define Documentation}
\hypertarget{BA_8h_5cb95566ed9f23880f08c3cf8c88a496}{
\index{BA.h@{BA.h}!BA\_\-FLUSH@{BA\_\-FLUSH}}
\index{BA\_\-FLUSH@{BA\_\-FLUSH}!BA.h@{BA.h}}
\subsubsection[{BA\_\-FLUSH}]{\setlength{\rightskip}{0pt plus 5cm}\#define BA\_\-FLUSH(\_\-cur, \/  \_\-buffer, \/  \_\-togo)}}
\label{BA_8h_5cb95566ed9f23880f08c3cf8c88a496}


\textbf{Value:}

\begin{Code}\begin{verbatim}if (_togo != 32)                         \
{                                        \
    _buffer <<= _togo;                   \
    BA_STORE(_cur, _buffer);             \
    _cur += 1;                           \
}
\end{verbatim}
\end{Code}
\hypertarget{BA_8h_98e2f96de68b809d7bdc82bc450bb0d2}{
\index{BA.h@{BA.h}!BA\_\-WRITE\_\-L@{BA\_\-WRITE\_\-L}}
\index{BA\_\-WRITE\_\-L@{BA\_\-WRITE\_\-L}!BA.h@{BA.h}}
\subsubsection[{BA\_\-WRITE\_\-L}]{\setlength{\rightskip}{0pt plus 5cm}\#define BA\_\-WRITE\_\-L(\_\-out, \/  \_\-buffer, \/  \_\-to\_\-go, \/  \_\-bits, \/  \_\-n)}}
\label{BA_8h_98e2f96de68b809d7bdc82bc450bb0d2}


\textbf{Value:}

\begin{Code}\begin{verbatim}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)
\end{verbatim}
\end{Code}
\hypertarget{BA_8h_1792453e0ec36f03156994fb1ab9325c}{
\index{BA.h@{BA.h}!BA\_\-WRITE\_\-R@{BA\_\-WRITE\_\-R}}
\index{BA\_\-WRITE\_\-R@{BA\_\-WRITE\_\-R}!BA.h@{BA.h}}
\subsubsection[{BA\_\-WRITE\_\-R}]{\setlength{\rightskip}{0pt plus 5cm}\#define BA\_\-WRITE\_\-R(\_\-out, \/  \_\-buffer, \/  \_\-to\_\-go, \/  \_\-bits, \/  \_\-n)}}
\label{BA_8h_1792453e0ec36f03156994fb1ab9325c}


\textbf{Value:}

\begin{Code}\begin{verbatim}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)
\end{verbatim}
\end{Code}
