\hypertarget{APE_8c}{
\section{APE.c File Reference}
\label{APE_8c}\index{APE.c@{APE.c}}
}
Arithmetic Word Encoder, implementation file. 

{\tt \#include \char`\"{}APC.h\char`\"{}}\par
{\tt \#include \char`\"{}LDT/APE.h\char`\"{}}\par
{\tt \#include \char`\"{}ffs.h\char`\"{}}\par
{\tt \#include \char`\"{}bswp.h\char`\"{}}\par


Include dependency graph for APE.c:\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=141pt]{APE_8c__incl}
\end{center}
\end{figure}
\subsection*{Typedefs}
\begin{CompactItemize}
\item 
\hypertarget{APE_8c_f6bf9908ffa057216893899af1f195ed}{
typedef enum \hyperlink{APE_8c_ec86191850354e58f871f18e37ab2b41}{\_\-APE\_\-symType} \hyperlink{APE_8c_f6bf9908ffa057216893899af1f195ed}{APE\_\-symType}}
\label{APE_8c_f6bf9908ffa057216893899af1f195ed}

\begin{CompactList}\small\item\em Typedef for enum \_\-APE\_\-symType. \item\end{CompactList}\end{CompactItemize}
\subsection*{Enumerations}
\begin{CompactItemize}
\item 
enum \hyperlink{APE_8c_ec86191850354e58f871f18e37ab2b41}{\_\-APE\_\-symType} \{ \par
\hyperlink{APE_8c_ec86191850354e58f871f18e37ab2b41b2d90bd0a757342f79f493e0e3593aa7}{APE\_\-SYMTYPE\_\-K\_\-IMMEDIATE} =  -1, 
\par
\hyperlink{APE_8c_ec86191850354e58f871f18e37ab2b4163b3c9b51090aab169dfa8d5da139383}{APE\_\-SYMTYPE\_\-K\_\-ARRAY\_\-BYTE} =  0, 
\par
\hyperlink{APE_8c_ec86191850354e58f871f18e37ab2b41e3fe87a5560658e80c8c94a9d6e2fbbd}{APE\_\-SYMTYPE\_\-K\_\-ARRAY\_\-SHORT} =  1
 \}
\begin{CompactList}\small\item\em PBS/BSWP.ih\char`\"{}. \item\end{CompactList}\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
static \_\-\_\-inline unsigned long long \hyperlink{APE_8c_11ff4ec2bd5e1197fee77aa5ec378b00}{scale} (\hyperlink{union__APE__cv}{APE\_\-cv} cv, const unsigned int table\mbox{[}2\mbox{]})
\begin{CompactList}\small\item\em Scales the input lo and hi condition value/limits using the table values. \item\end{CompactList}\item 
static \_\-\_\-inline unsigned long long int \hyperlink{APE_8c_7a74c352ebc3516be910c5621d5b4c02}{reduce\_\-h01} (\hyperlink{union__APE__cv}{APE\_\-cv} cv, int cnt)
\begin{CompactList}\small\item\em Reduces the specified condition values when the both the lo and hi limits lie in the same half, {\em i.e\/}. either both are in the lower half or both are in the upper half. \item\end{CompactList}\item 
static \_\-\_\-inline unsigned long long int \hyperlink{APE_8c_62a759880a9b8dcc4498803a761acc2c}{reduce\_\-q12} (\hyperlink{union__APE__cv}{APE\_\-cv} cv)
\begin{CompactList}\small\item\em Reduces the specified condition values when the lo and hi straddle the mid-point, {\em i.e\/}. the lo limit is in Q1 and the hi limit is in Q2. \item\end{CompactList}\item 
static \_\-\_\-inline int \hyperlink{APE_8c_89712e6d9bf4d9ffb2ddb020024369e8}{encode} (\hyperlink{struct__APE__etx}{APE\_\-etx} $\ast$etx, const unsigned int $\ast$table, const void $\ast$syms, int nsyms, int symType)
\begin{CompactList}\small\item\em Encodes an\begin{enumerate}
\item immediate value\item array of unsigned char symbols\item array of unsigned short int symbols. \end{enumerate}
\item\end{CompactList}\item 
static \_\-\_\-inline int \hyperlink{APE_8c_ccd471570e054def661928e34f43a7fe}{encode\_\-list} (\hyperlink{struct__APE__etx}{APE\_\-etx} $\ast$etx, const unsigned int $\ast$$\ast$tables, const void $\ast$syms, int nsyms, int symType)
\begin{CompactList}\small\item\em Encodes an\begin{enumerate}
\item immediate value\item array of unsigned char symbols\item array of unsigned short int symbols. \end{enumerate}
\item\end{CompactList}\item 
static int \hyperlink{APE_8c_ac34bbce5abd62b2ea56eafc97236417}{set} (\hyperlink{struct__APE__etx}{APE\_\-etx} $\ast$etx, unsigned char $\ast$out, unsigned int boff, const unsigned char $\ast$max)
\begin{CompactList}\small\item\em Sets the output context. \item\end{CompactList}\item 
int \hyperlink{APE_8c_9c837ca41b6686cf90421d70a922c8d7}{APE\_\-encode} (\hyperlink{struct__APE__etx}{APE\_\-etx} $\ast$etx, const unsigned int $\ast$table, unsigned int sym)
\begin{CompactList}\small\item\em Encodes one symbol. \item\end{CompactList}\item 
int \hyperlink{APE_8c_3876be55c4dccbd38ee28dcb28a14a82}{APE\_\-bencode} (\hyperlink{struct__APE__etx}{APE\_\-etx} $\ast$etx, const unsigned int $\ast$table, const unsigned char $\ast$syms, int nsyms)
\begin{CompactList}\small\item\em Encodes an array of unsigned char symbols. \item\end{CompactList}\item 
int \hyperlink{APE_8c_7e9749f69a8ca2b4c167199a280d3a66}{APE\_\-blencode} (\hyperlink{struct__APE__etx}{APE\_\-etx} $\ast$etx, const unsigned int $\ast$$\ast$tables, unsigned char const $\ast$syms, int nsyms)
\begin{CompactList}\small\item\em Encodes an array of unsigned char symbols. \item\end{CompactList}\item 
int \hyperlink{APE_8c_2f54e98eb1bf7b80b9385929e18c3218}{APE\_\-sencode} (\hyperlink{struct__APE__etx}{APE\_\-etx} $\ast$etx, const unsigned int $\ast$table, const unsigned short $\ast$syms, int nsyms)
\begin{CompactList}\small\item\em Encodes an array of unsigned char symbols. \item\end{CompactList}\item 
int \hyperlink{APE_8c_762086e55ef44742cd9aedc2ccea9f3c}{APE\_\-slencode} (\hyperlink{struct__APE__etx}{APE\_\-etx} $\ast$etx, const unsigned int $\ast$$\ast$tables, unsigned short const $\ast$syms, int nsyms)
\begin{CompactList}\small\item\em Encodes an array of unsigned short integer symbols each with their own table. \item\end{CompactList}\item 
int \hyperlink{APE_8c_96d50e9d31bf7a651c77a21596863674}{APE\_\-reset} (\hyperlink{struct__APE__etx}{APE\_\-etx} $\ast$etx, unsigned char $\ast$out, unsigned int boff, const unsigned char $\ast$max)
\begin{CompactList}\small\item\em Resets the output context. \item\end{CompactList}\item 
int \hyperlink{APE_8c_88d2c574b45a8a27314fad84ca9f2eea}{APE\_\-start} (\hyperlink{struct__APE__etx}{APE\_\-etx} $\ast$etx, unsigned char $\ast$out, unsigned int boff, const unsigned char $\ast$max)
\begin{CompactList}\small\item\em Initializes the encoding context. \item\end{CompactList}\item 
unsigned int \hyperlink{APE_8c_6e5bf225c4335dc77e5f03c69193a300}{APE\_\-bcompress} (unsigned char $\ast$out, unsigned int boff, unsigned char $\ast$max, const unsigned int $\ast$table, const unsigned char $\ast$in, int cnt, int $\ast$unencoded)
\begin{CompactList}\small\item\em Convenience routine to compress a byte stream. \item\end{CompactList}\item 
int \hyperlink{APE_8c_cee5053cd7ae849f356e4c1eb8200b6f}{APE\_\-finish} (\hyperlink{struct__APE__etx}{APE\_\-etx} $\ast$etx)
\begin{CompactList}\small\item\em Finishes the encoding by flushing out any currently buffered bits. \item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}
Arithmetic Word Encoder, implementation file. 

\begin{Desc}
\item[Author:]JJRussell - \href{mailto:russell@slac.stanford.edu}{\tt russell@slac.stanford.edu}\end{Desc}
Implementation of the routines to encode symbols using an arithmetic probability encoding technique. To achieve performance goals, these routines must be used with a model builder that forces a particular normalization of the cumulative probability. While such tables may be constructed in a variety of ways, APM\_\-build is an example of such a routine and is anticipated to be the model table builder. 

\subsection{Enumeration Type Documentation}
\hypertarget{APE_8c_ec86191850354e58f871f18e37ab2b41}{
\index{APE.c@{APE.c}!_APE_symType@{\_\-APE\_\-symType}}
\index{_APE_symType@{\_\-APE\_\-symType}!APE.c@{APE.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}enum {\bf \_\-APE\_\-symType}}}
\label{APE_8c_ec86191850354e58f871f18e37ab2b41}


PBS/BSWP.ih\char`\"{}. 

The symbol type being encoded \begin{Desc}
\item[Enumerator: ]\par
\begin{description}
\index{APE_SYMTYPE_K_IMMEDIATE@{APE\_\-SYMTYPE\_\-K\_\-IMMEDIATE}!APE.c@{APE.c}}\index{APE.c@{APE.c}!APE_SYMTYPE_K_IMMEDIATE@{APE\_\-SYMTYPE\_\-K\_\-IMMEDIATE}}\item[{\em 
\hypertarget{APE_8c_ec86191850354e58f871f18e37ab2b41b2d90bd0a757342f79f493e0e3593aa7}{
APE\_\-SYMTYPE\_\-K\_\-IMMEDIATE}
\label{APE_8c_ec86191850354e58f871f18e37ab2b41b2d90bd0a757342f79f493e0e3593aa7}
}]Symbol type is an immediate \index{APE_SYMTYPE_K_ARRAY_BYTE@{APE\_\-SYMTYPE\_\-K\_\-ARRAY\_\-BYTE}!APE.c@{APE.c}}\index{APE.c@{APE.c}!APE_SYMTYPE_K_ARRAY_BYTE@{APE\_\-SYMTYPE\_\-K\_\-ARRAY\_\-BYTE}}\item[{\em 
\hypertarget{APE_8c_ec86191850354e58f871f18e37ab2b4163b3c9b51090aab169dfa8d5da139383}{
APE\_\-SYMTYPE\_\-K\_\-ARRAY\_\-BYTE}
\label{APE_8c_ec86191850354e58f871f18e37ab2b4163b3c9b51090aab169dfa8d5da139383}
}]Symbol type is an byte array \index{APE_SYMTYPE_K_ARRAY_SHORT@{APE\_\-SYMTYPE\_\-K\_\-ARRAY\_\-SHORT}!APE.c@{APE.c}}\index{APE.c@{APE.c}!APE_SYMTYPE_K_ARRAY_SHORT@{APE\_\-SYMTYPE\_\-K\_\-ARRAY\_\-SHORT}}\item[{\em 
\hypertarget{APE_8c_ec86191850354e58f871f18e37ab2b41e3fe87a5560658e80c8c94a9d6e2fbbd}{
APE\_\-SYMTYPE\_\-K\_\-ARRAY\_\-SHORT}
\label{APE_8c_ec86191850354e58f871f18e37ab2b41e3fe87a5560658e80c8c94a9d6e2fbbd}
}]Symbol type is a short array \end{description}
\end{Desc}



\subsection{Function Documentation}
\hypertarget{APE_8c_6e5bf225c4335dc77e5f03c69193a300}{
\index{APE.c@{APE.c}!APE_bcompress@{APE\_\-bcompress}}
\index{APE_bcompress@{APE\_\-bcompress}!APE.c@{APE.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}unsigned int APE\_\-bcompress (unsigned char $\ast$ {\em out}, unsigned int {\em boff}, unsigned char $\ast$ {\em max}, const unsigned int $\ast$ {\em table}, const unsigned char $\ast$ {\em in}, int {\em cnt}, int $\ast$ {\em unencoded})}}
\label{APE_8c_6e5bf225c4335dc77e5f03c69193a300}


Convenience routine to compress a byte stream. 

\begin{Desc}
\item[Returns:]The number of bits needed to encoded the byte stream. If negative the all the symbols could not be encoded and {\em unencoded\/} should be checked for the count of those symbols not encoded.\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em out}]The output buffer \item[{\em boff}]The current bit offset \item[{\em max}]The maximum output address (actually 1 byte past it) \item[{\em table}]The encoding table \item[{\em in}]The input buffer of symbols. \item[{\em cnt}]The number of input symbols. \item[{\em unencoded}]The number of input symbols left to encode. If successful this will be 0.\end{description}
\end{Desc}
This is a convenience routine, combining \hyperlink{APE_8c_88d2c574b45a8a27314fad84ca9f2eea}{APE\_\-start()}, \hyperlink{APE_8c_9c837ca41b6686cf90421d70a922c8d7}{APE\_\-encode()} and \hyperlink{APE_8c_cee5053cd7ae849f356e4c1eb8200b6f}{APE\_\-finish()}. It can be used iff the same table is used to encode all the symbols. \hypertarget{APE_8c_3876be55c4dccbd38ee28dcb28a14a82}{
\index{APE.c@{APE.c}!APE_bencode@{APE\_\-bencode}}
\index{APE_bencode@{APE\_\-bencode}!APE.c@{APE.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int APE\_\-bencode ({\bf APE\_\-etx} $\ast$ {\em etx}, const unsigned int $\ast$ {\em table}, const unsigned char $\ast$ {\em syms}, int {\em nsyms})}}
\label{APE_8c_3876be55c4dccbd38ee28dcb28a14a82}


Encodes an array of unsigned char symbols. 

\begin{Desc}
\item[Returns:]Number of symbols remaining to be encoded. If this is 0, all symbols where encoded.\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em etx}]The encoding context \item[{\em table}]The encoding table \item[{\em syms}]The array of symbols to encode \item[{\em nsyms}]The number of symbols \end{description}
\end{Desc}
\hypertarget{APE_8c_7e9749f69a8ca2b4c167199a280d3a66}{
\index{APE.c@{APE.c}!APE_blencode@{APE\_\-blencode}}
\index{APE_blencode@{APE\_\-blencode}!APE.c@{APE.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int APE\_\-blencode ({\bf APE\_\-etx} $\ast$ {\em etx}, const unsigned int $\ast$$\ast$ {\em tables}, unsigned char const $\ast$ {\em syms}, int {\em nsyms})}}
\label{APE_8c_7e9749f69a8ca2b4c167199a280d3a66}


Encodes an array of unsigned char symbols. 

\begin{Desc}
\item[Returns:]Number of symbols remaining to be encoded. If this is 0, all symbols where encoded.\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em etx}]The encoding context \item[{\em tables}]The encoding table \item[{\em syms}]The array of symbols to encode \item[{\em nsyms}]The number of symbols \end{description}
\end{Desc}
\hypertarget{APE_8c_9c837ca41b6686cf90421d70a922c8d7}{
\index{APE.c@{APE.c}!APE_encode@{APE\_\-encode}}
\index{APE_encode@{APE\_\-encode}!APE.c@{APE.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int APE\_\-encode ({\bf APE\_\-etx} $\ast$ {\em etx}, const unsigned int $\ast$ {\em table}, unsigned int {\em sym})}}
\label{APE_8c_9c837ca41b6686cf90421d70a922c8d7}


Encodes one symbol. 

\begin{Desc}
\item[Returns:]Number of symbols remaining to be encoded. If this is 0, the symbol was successfully encoded.\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em etx}]The encoding context \item[{\em table}]The encoding table \item[{\em sym}]The symbol to encode \end{description}
\end{Desc}
\hypertarget{APE_8c_cee5053cd7ae849f356e4c1eb8200b6f}{
\index{APE.c@{APE.c}!APE_finish@{APE\_\-finish}}
\index{APE_finish@{APE\_\-finish}!APE.c@{APE.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}unsigned int APE\_\-finish ({\bf APE\_\-etx} $\ast$ {\em etx})}}
\label{APE_8c_cee5053cd7ae849f356e4c1eb8200b6f}


Finishes the encoding by flushing out any currently buffered bits. 

\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em If}]$>$ 0, the number of encoded bits. If $<$ 0, the number of bits needed to encode the final piece\end{description}
\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em etx}]The encoding context\end{description}
\end{Desc}
\begin{Desc}
\item[]At the end of the encoding, there is some context that needs flushing. This flushing may contribute more bits to the output stream. If there are not enough bits to hold this context, the number of extra bits needed to flush the context are returned as a negative number. In this case, the user should write all the currently committed data and then reset the output buffer.\end{Desc}
The array to write out is from etx-$>$beg + etx-$>$bbeg (the beginning output address + beginning bit number to ext-$>$ba.out (the current output address). Once written, the user should call APE\_\-reset to reset the output buffer.

If there is enough room, the number of encoded bits is returned as a positive number. \hypertarget{APE_8c_96d50e9d31bf7a651c77a21596863674}{
\index{APE.c@{APE.c}!APE_reset@{APE\_\-reset}}
\index{APE_reset@{APE\_\-reset}!APE.c@{APE.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int APE\_\-reset ({\bf APE\_\-etx} $\ast$ {\em etx}, unsigned char $\ast$ {\em out}, unsigned int {\em boff}, const unsigned char $\ast$ {\em max})}}
\label{APE_8c_96d50e9d31bf7a651c77a21596863674}


Resets the output context. 

\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 0,If}]successful \item[{\em -1,If}]failed to provide at least 1 byte of memory.\end{description}
\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em etx}]The encoding context to reset \item[{\em out}]The output buffer. \item[{\em boff}]The bit offset into the output buffer. \item[{\em max}]The maximum output address (actually 1 byte past it)\end{description}
\end{Desc}
Note that since the AWx routines are bit encoders/decoders, one needs to specify the offsets into the buffers as bit offsets. In general, at least one byte of memory needs to be provided. There is no check for this failure \hypertarget{APE_8c_2f54e98eb1bf7b80b9385929e18c3218}{
\index{APE.c@{APE.c}!APE_sencode@{APE\_\-sencode}}
\index{APE_sencode@{APE\_\-sencode}!APE.c@{APE.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int APE\_\-sencode ({\bf APE\_\-etx} $\ast$ {\em etx}, const unsigned int $\ast$ {\em table}, const unsigned short $\ast$ {\em syms}, int {\em nsyms})}}
\label{APE_8c_2f54e98eb1bf7b80b9385929e18c3218}


Encodes an array of unsigned char symbols. 

\begin{Desc}
\item[Returns:]Number of symbols remaining to be encoded. If this is 0, all symbols where encoded.\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em etx}]The encoding context \item[{\em table}]The encoding table \item[{\em syms}]The array of symbols to encode \item[{\em nsyms}]The number of symbols \end{description}
\end{Desc}
\hypertarget{APE_8c_762086e55ef44742cd9aedc2ccea9f3c}{
\index{APE.c@{APE.c}!APE_slencode@{APE\_\-slencode}}
\index{APE_slencode@{APE\_\-slencode}!APE.c@{APE.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int APE\_\-slencode ({\bf APE\_\-etx} $\ast$ {\em etx}, const unsigned int $\ast$$\ast$ {\em tables}, unsigned short const $\ast$ {\em syms}, int {\em nsyms})}}
\label{APE_8c_762086e55ef44742cd9aedc2ccea9f3c}


Encodes an array of unsigned short integer symbols each with their own table. 

\begin{Desc}
\item[Returns:]Number of symbols remaining to be encoded. If this is 0, all symbols where encoded.\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em etx}]The encoding context \item[{\em tables}]The encoding table \item[{\em syms}]The array of symbols to encode \item[{\em nsyms}]The number of symbols \end{description}
\end{Desc}
\hypertarget{APE_8c_88d2c574b45a8a27314fad84ca9f2eea}{
\index{APE.c@{APE.c}!APE_start@{APE\_\-start}}
\index{APE_start@{APE\_\-start}!APE.c@{APE.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int APE\_\-start ({\bf APE\_\-etx} $\ast$ {\em etx}, unsigned char $\ast$ {\em out}, unsigned int {\em boff}, const unsigned char $\ast$ {\em max})}}
\label{APE_8c_88d2c574b45a8a27314fad84ca9f2eea}


Initializes the encoding context. 

\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 0,Currently,always}]0. This may expand to a status code if necessary\end{description}
\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em etx}]The encoding context to initialize \item[{\em out}]The output buffer \item[{\em boff}]The bit offset into the output buffer \item[{\em max}]The maximum output address (actually 1 byte past it)\end{description}
\end{Desc}
Note that since the AWx routines are bit encoders/decoders, one needs to specify the offsets into the buffers as bit offsets. \hypertarget{APE_8c_89712e6d9bf4d9ffb2ddb020024369e8}{
\index{APE.c@{APE.c}!encode@{encode}}
\index{encode@{encode}!APE.c@{APE.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}static int encode ({\bf APE\_\-etx} $\ast$ {\em etx}, const unsigned int $\ast$ {\em table}, const void $\ast$ {\em syms}, int {\em nsyms}, int {\em symType})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{APE_8c_89712e6d9bf4d9ffb2ddb020024369e8}


Encodes an\begin{enumerate}
\item immediate value\item array of unsigned char symbols\item array of unsigned short int symbols. \end{enumerate}


\begin{Desc}
\item[Returns:]Number of symbols remaining to be encoded. If this is 0, all symbols where encoded.\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em etx}]The encoding context \item[{\em table}]The encoding table \item[{\em syms}]The array of symbols to encode \item[{\em nsyms}]The number of symbols \item[{\em symType}]The type of symbol(s) being encoded\begin{itemize}
\item $<$ 0 =$>$ immediate value\item = 0 =$>$ array of unsigned char symbols\item $>$ 0 =$>$ array of unsigned short int symbols \end{itemize}
\end{description}
\end{Desc}
\hypertarget{APE_8c_ccd471570e054def661928e34f43a7fe}{
\index{APE.c@{APE.c}!encode_list@{encode\_\-list}}
\index{encode_list@{encode\_\-list}!APE.c@{APE.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline int encode\_\-list ({\bf APE\_\-etx} $\ast$ {\em etx}, const unsigned int $\ast$$\ast$ {\em tables}, const void $\ast$ {\em syms}, int {\em nsyms}, int {\em symType})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{APE_8c_ccd471570e054def661928e34f43a7fe}


Encodes an\begin{enumerate}
\item immediate value\item array of unsigned char symbols\item array of unsigned short int symbols. \end{enumerate}


\begin{Desc}
\item[Returns:]Number of symbols remaining to be encoded. If this is 0, all symbols where encoded.\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em etx}]The encoding context \item[{\em tables}]The encoding table \item[{\em syms}]The array of symbols to encode \item[{\em nsyms}]The number of symbols \item[{\em symType}]The type of symbol(s) being encoded\begin{itemize}
\item $<$ 0 =$>$ immediate value\item = 0 =$>$ array of unsigned char symbols\item $>$ 0 =$>$ array of unsigned short int symbols \end{itemize}
\end{description}
\end{Desc}
\hypertarget{APE_8c_7a74c352ebc3516be910c5621d5b4c02}{
\index{APE.c@{APE.c}!reduce_h01@{reduce\_\-h01}}
\index{reduce_h01@{reduce\_\-h01}!APE.c@{APE.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline unsigned long long int reduce\_\-h01 ({\bf APE\_\-cv} {\em cv}, int {\em cnt})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{APE_8c_7a74c352ebc3516be910c5621d5b4c02}


Reduces the specified condition values when the both the lo and hi limits lie in the same half, {\em i.e\/}. either both are in the lower half or both are in the upper half. 

\begin{Desc}
\item[Returns:]The new condition value\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em cv}]The condition values to reduce. \item[{\em cnt}]The number of identical bits.\end{description}
\end{Desc}
These number of bits specified by {\em cnt\/} are removed from the top of both the lo and hi limits. The lo limit replaces these bits on the bottom with 0's, while the high limit replaces them with 1's \hypertarget{APE_8c_62a759880a9b8dcc4498803a761acc2c}{
\index{APE.c@{APE.c}!reduce_q12@{reduce\_\-q12}}
\index{reduce_q12@{reduce\_\-q12}!APE.c@{APE.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline unsigned long long int reduce\_\-q12 ({\bf APE\_\-cv} {\em cv})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{APE_8c_62a759880a9b8dcc4498803a761acc2c}


Reduces the specified condition values when the lo and hi straddle the mid-point, {\em i.e\/}. the lo limit is in Q1 and the hi limit is in Q2. 

\begin{Desc}
\item[Returns:]The new condition value\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em cv}]The condition values to reduce.\end{description}
\end{Desc}
In this reduction, only the top bit of each the lo and hi limits is removed. \hypertarget{APE_8c_11ff4ec2bd5e1197fee77aa5ec378b00}{
\index{APE.c@{APE.c}!scale@{scale}}
\index{scale@{scale}!APE.c@{APE.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline unsigned long long scale ({\bf APE\_\-cv} {\em cv}, const unsigned int {\em table}\mbox{[}2\mbox{]})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{APE_8c_11ff4ec2bd5e1197fee77aa5ec378b00}


Scales the input lo and hi condition value/limits using the table values. 

\begin{Desc}
\item[Returns:]The rescaled lo and hi condition values/limits\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em cv}]The current condtion value \item[{\em table}]The table values \end{description}
\end{Desc}
\hypertarget{APE_8c_ac34bbce5abd62b2ea56eafc97236417}{
\index{APE.c@{APE.c}!set@{set}}
\index{set@{set}!APE.c@{APE.c}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int set ({\bf APE\_\-etx} $\ast$ {\em etx}, unsigned char $\ast$ {\em out}, unsigned int {\em boff}, const unsigned char $\ast$ {\em max})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{APE_8c_ac34bbce5abd62b2ea56eafc97236417}


Sets the output context. 

\begin{Desc}
\item[Returns:]The bit offset into the current output\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em etx}]The encoding context to reset \item[{\em out}]The output buffer \item[{\em boff}]The bit offset into the output buffer \item[{\em max}]The maximum output address (actually 1 byte past it)\end{description}
\end{Desc}
Note that since the AWx routines are bit encoders/decoders, one needs to specify the offsets into the buffers as bit offsets. 