23#define FSE_STATIC_LINKING_ONLY
33#define FSE_isError ERR_isError
34#define FSE_STATIC_ASSERT(c) DEBUG_STATIC_ASSERT(c)
47#ifndef FSE_FUNCTION_EXTENSION
48# error "FSE_FUNCTION_EXTENSION must be defined"
50#ifndef FSE_FUNCTION_TYPE
51# error "FSE_FUNCTION_TYPE must be defined"
55#define FSE_CAT(X,Y) X##Y
56#define FSE_FUNCTION_NAME(X,Y) FSE_CAT(X,Y)
57#define FSE_TYPE_NAME(X,Y) FSE_CAT(X,Y)
59#define FSED_ALLOC_TAG 0x64455346
64 if (tableLog > FSE_TABLELOG_ABSOLUTE_MAX) tableLog = FSE_TABLELOG_ABSOLUTE_MAX;
75 void*
const tdPtr = dt+1;
76 FSE_DECODE_TYPE*
const tableDecode = (FSE_DECODE_TYPE*) (tdPtr);
77 U16 symbolNext[FSE_MAX_SYMBOL_VALUE+1];
79 U32 const maxSV1 = maxSymbolValue + 1;
80 U32 const tableSize = 1 << tableLog;
81 U32 highThreshold = tableSize-1;
84 if (maxSymbolValue > FSE_MAX_SYMBOL_VALUE)
return ERROR(maxSymbolValue_tooLarge);
85 if (tableLog > FSE_MAX_TABLELOG)
return ERROR(tableLog_tooLarge);
88 { FSE_DTableHeader DTableH;
89 DTableH.tableLog = (
U16)tableLog;
91 {
S16 const largeLimit= (
S16)(1 << (tableLog-1));
93 for (
s=0;
s<maxSV1;
s++) {
94 if (normalizedCounter[
s]==-1) {
95 tableDecode[highThreshold--].symbol = (FSE_FUNCTION_TYPE)
s;
98 if (normalizedCounter[
s] >= largeLimit) DTableH.fastMode=0;
99 symbolNext[
s] = normalizedCounter[
s];
101 memcpy(dt, &DTableH,
sizeof(DTableH));
105 {
U32 const tableMask = tableSize-1;
106 U32 const step = FSE_TABLESTEP(tableSize);
108 for (
s=0;
s<maxSV1;
s++) {
110 for (
i=0;
i<normalizedCounter[
s];
i++) {
111 tableDecode[position].symbol = (FSE_FUNCTION_TYPE)
s;
112 position = (position + step) & tableMask;
113 while (position > highThreshold) position = (position + step) & tableMask;
115 if (position!=0)
return ERROR(GENERIC);
120 for (
u=0;
u<tableSize;
u++) {
121 FSE_FUNCTION_TYPE
const symbol = (FSE_FUNCTION_TYPE)(tableDecode[
u].symbol);
122 U32 const nextState = symbolNext[symbol]++;
124 tableDecode[
u].newState = (
U16) ( (nextState << tableDecode[
u].nbBits) - tableSize);
131#ifndef FSE_COMMONDEFS_ONLY
139 FSE_DTableHeader*
const DTableH = (FSE_DTableHeader*)
ptr;
141 FSE_decode_t*
const cell = (FSE_decode_t*)dPtr;
143 DTableH->tableLog = 0;
144 DTableH->fastMode = 0;
147 cell->symbol = symbolValue;
157 FSE_DTableHeader*
const DTableH = (FSE_DTableHeader*)
ptr;
159 FSE_decode_t*
const dinfo = (FSE_decode_t*)dPtr;
160 const unsigned tableSize = 1 << nbBits;
161 const unsigned tableMask = tableSize - 1;
162 const unsigned maxSV1 = tableMask+1;
166 if (nbBits < 1)
return ERROR(GENERIC);
169 DTableH->tableLog = (
U16)nbBits;
170 DTableH->fastMode = 1;
171 for (
s=0;
s<maxSV1;
s++) {
172 dinfo[
s].newState = 0;
173 dinfo[
s].symbol = (
BYTE)
s;
174 dinfo[
s].nbBits = (
BYTE)nbBits;
181 void*
dst,
size_t maxDstSize,
182 const void* cSrc,
size_t cSrcSize,
187 BYTE*
const omax =
op + maxDstSize;
188 BYTE*
const olimit = omax-3;
197 FSE_initDState(&state1, &bitD, dt);
198 FSE_initDState(&state2, &bitD, dt);
200#define FSE_GETSYMBOL(statePtr) fast ? FSE_decodeSymbolFast(statePtr, &bitD) : FSE_decodeSymbol(statePtr, &bitD)
225 if (
op>(omax-2))
return ERROR(dstSize_tooSmall);
232 if (
op>(omax-2))
return ERROR(dstSize_tooSmall);
244 const void* cSrc,
size_t cSrcSize,
247 const void*
ptr = dt;
248 const FSE_DTableHeader* DTableH = (
const FSE_DTableHeader*)
ptr;
249 const U32 fastMode = DTableH->fastMode;
259 const BYTE*
const istart = (
const BYTE*)cSrc;
261 short counting[FSE_MAX_SYMBOL_VALUE+1];
263 unsigned maxSymbolValue = FSE_MAX_SYMBOL_VALUE;
266 size_t const NCountLength =
FSE_readNCount (counting, &maxSymbolValue, &tableLog, istart, cSrcSize);
267 if (
FSE_isError(NCountLength))
return NCountLength;
269 if (tableLog > maxLog)
return ERROR(tableLog_tooLarge);
271 cSrcSize -= NCountLength;
MEM_STATIC size_t BIT_initDStream(BIT_DStream_t *bitD, const void *srcBuffer, size_t srcSize)
MEM_STATIC unsigned BIT_highbit32(U32 val)
MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t *bitD)
size_t FSE_readNCount(short *normalizedCounter, unsigned *maxSVPtr, unsigned *tableLogPtr, const void *headerBuffer, size_t hbSize)
#define ExAllocatePoolWithTag(hernya, size, tag)
size_t FSE_decompress_wksp(void *dst, size_t dstCapacity, const void *cSrc, size_t cSrcSize, FSE_DTable *workSpace, unsigned maxLog)
FSE_DTable DTable_max_t[FSE_DTABLE_SIZE_U32(FSE_MAX_TABLELOG)]
size_t FSE_buildDTable_rle(FSE_DTable *dt, BYTE symbolValue)
size_t FSE_decompress_usingDTable(void *dst, size_t originalSize, const void *cSrc, size_t cSrcSize, const FSE_DTable *dt)
#define FSE_GETSYMBOL(statePtr)
size_t FSE_buildDTable(FSE_DTable *dt, const short *normalizedCounter, unsigned maxSymbolValue, unsigned tableLog)
void FSE_freeDTable(FSE_DTable *dt)
size_t FSE_buildDTable_raw(FSE_DTable *dt, unsigned nbBits)
FSE_DTable * FSE_createDTable(unsigned tableLog)
FORCE_INLINE_TEMPLATE size_t FSE_decompress_usingDTable_generic(void *dst, size_t maxDstSize, const void *cSrc, size_t cSrcSize, const FSE_DTable *dt, const unsigned fast)
size_t FSE_decompress(void *dst, size_t dstCapacity, const void *cSrc, size_t cSrcSize)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
#define memcpy(s1, s2, n)
#define FORCE_INLINE_TEMPLATE