15#if defined (__cplusplus)
32#if defined(FSE_DLL_EXPORT) && (FSE_DLL_EXPORT==1) && defined(__GNUC__) && (__GNUC__ >= 4)
33# define FSE_PUBLIC_API __attribute__ ((visibility ("default")))
34#elif defined(FSE_DLL_EXPORT) && (FSE_DLL_EXPORT==1)
35# define FSE_PUBLIC_API __declspec(dllexport)
36#elif defined(FSE_DLL_IMPORT) && (FSE_DLL_IMPORT==1)
37# define FSE_PUBLIC_API __declspec(dllimport)
39# define FSE_PUBLIC_API
43#define FSE_VERSION_MAJOR 0
44#define FSE_VERSION_MINOR 9
45#define FSE_VERSION_RELEASE 0
47#define FSE_LIB_VERSION FSE_VERSION_MAJOR.FSE_VERSION_MINOR.FSE_VERSION_RELEASE
48#define FSE_QUOTE(str) #str
49#define FSE_EXPAND_AND_QUOTE(str) FSE_QUOTE(str)
50#define FSE_VERSION_STRING FSE_EXPAND_AND_QUOTE(FSE_LIB_VERSION)
52#define FSE_VERSION_NUMBER (FSE_VERSION_MAJOR *100*100 + FSE_VERSION_MINOR *100 + FSE_VERSION_RELEASE)
68 const void*
src,
size_t srcSize);
81 const void* cSrc,
size_t cSrcSize);
143 const unsigned*
count,
size_t srcSize,
unsigned maxSymbolValue);
155 const short* normalizedCounter,
156 unsigned maxSymbolValue,
unsigned tableLog);
228 unsigned* maxSymbolValuePtr,
unsigned* tableLogPtr,
229 const void* rBuffer,
size_t rBuffSize);
279#if defined(FSE_STATIC_LINKING_ONLY) && !defined(FSE_H_FSE_STATIC_LINKING_ONLY)
280#define FSE_H_FSE_STATIC_LINKING_ONLY
290#define FSE_NCOUNTBOUND 512
291#define FSE_BLOCKBOUND(size) (size + (size>>7) + 4 + sizeof(size_t) )
292#define FSE_COMPRESSBOUND(size) (FSE_NCOUNTBOUND + FSE_BLOCKBOUND(size))
295#define FSE_CTABLE_SIZE_U32(maxTableLog, maxSymbolValue) (1 + (1<<(maxTableLog-1)) + ((maxSymbolValue+1)*2))
296#define FSE_DTABLE_SIZE_U32(maxTableLog) (1 + (1<<maxTableLog))
299#define FSE_CTABLE_SIZE(maxTableLog, maxSymbolValue) (FSE_CTABLE_SIZE_U32(maxTableLog, maxSymbolValue) * sizeof(FSE_CTable))
300#define FSE_DTABLE_SIZE(maxTableLog) (FSE_DTABLE_SIZE_U32(maxTableLog) * sizeof(FSE_DTable))
314#define FSE_WKSP_SIZE_U32(maxTableLog, maxSymbolValue) ( FSE_CTABLE_SIZE_U32(maxTableLog, maxSymbolValue) + ((maxTableLog > 12) ? (1 << (maxTableLog - 2)) : 1024) )
315size_t FSE_compress_wksp (
void*
dst,
size_t dstSize,
const void*
src,
size_t srcSize,
unsigned maxSymbolValue,
unsigned tableLog,
void* workSpace,
size_t wkspSize);
327size_t FSE_buildCTable_wksp(
FSE_CTable* ct,
const short* normalizedCounter,
unsigned maxSymbolValue,
unsigned tableLog,
void* workSpace,
size_t wkspSize);
353 const void* stateTable;
354 const void* symbolTT;
358static void FSE_initCState(FSE_CState_t* CStatePtr,
const FSE_CTable* ct);
360static void FSE_encodeSymbol(
BIT_CStream_t* bitC, FSE_CState_t* CStatePtr,
unsigned symbol);
362static void FSE_flushCState(
BIT_CStream_t* bitC,
const FSE_CState_t* CStatePtr);
419static unsigned char FSE_decodeSymbol(FSE_DState_t* DStatePtr,
BIT_DStream_t* bitD);
421static unsigned FSE_endOfDState(
const FSE_DState_t* DStatePtr);
476static unsigned char FSE_decodeSymbolFast(FSE_DState_t* DStatePtr,
BIT_DStream_t* bitD);
486} FSE_symbolCompressionTransform;
490 const void*
ptr = ct;
493 statePtr->value = (
ptrdiff_t)1<<tableLog;
494 statePtr->stateTable = u16ptr+2;
495 statePtr->symbolTT = ct + 1 + (tableLog ? (1<<(tableLog-1)) : 1);
496 statePtr->stateLog = tableLog;
505 FSE_initCState(statePtr, ct);
506 {
const FSE_symbolCompressionTransform symbolTT = ((
const FSE_symbolCompressionTransform*)(statePtr->symbolTT))[symbol];
507 const U16* stateTable = (
const U16*)(statePtr->stateTable);
508 U32 nbBitsOut = (
U32)((symbolTT.deltaNbBits + (1<<15)) >> 16);
509 statePtr->value = (nbBitsOut << 16) - symbolTT.deltaNbBits;
510 statePtr->value = stateTable[(statePtr->value >> nbBitsOut) + symbolTT.deltaFindState];
516 FSE_symbolCompressionTransform
const symbolTT = ((
const FSE_symbolCompressionTransform*)(statePtr->symbolTT))[symbol];
517 const U16*
const stateTable = (
const U16*)(statePtr->stateTable);
518 U32 const nbBitsOut = (
U32)((statePtr->value + symbolTT.deltaNbBits) >> 16);
520 statePtr->value = stateTable[ (statePtr->value >> nbBitsOut) + symbolTT.deltaFindState];
525 BIT_addBits(bitC, statePtr->value, statePtr->stateLog);
537 const FSE_symbolCompressionTransform* symbolTT = (
const FSE_symbolCompressionTransform*) symbolTTPtr;
538 return (symbolTT[symbolValue].deltaNbBits + ((1<<16)-1)) >> 16;
547 const FSE_symbolCompressionTransform* symbolTT = (
const FSE_symbolCompressionTransform*) symbolTTPtr;
548 U32 const minNbBits = symbolTT[symbolValue].deltaNbBits >> 16;
549 U32 const threshold = (minNbBits+1) << 16;
551 assert(accuracyLog < 31-tableLog);
552 {
U32 const tableSize = 1 << tableLog;
553 U32 const deltaFromThreshold = threshold - (symbolTT[symbolValue].deltaNbBits + tableSize);
554 U32 const normalizedDeltaFromThreshold = (deltaFromThreshold << accuracyLog) >> tableLog;
555 U32 const bitMultiplier = 1 << accuracyLog;
556 assert(symbolTT[symbolValue].deltaNbBits + tableSize <= threshold);
557 assert(normalizedDeltaFromThreshold <= bitMultiplier);
558 return (minNbBits+1)*bitMultiplier - normalizedDeltaFromThreshold;
572 unsigned short newState;
573 unsigned char symbol;
574 unsigned char nbBits;
579 const void*
ptr = dt;
580 const FSE_DTableHeader*
const DTableH = (
const FSE_DTableHeader*)
ptr;
581 DStatePtr->state =
BIT_readBits(bitD, DTableH->tableLog);
583 DStatePtr->table = dt + 1;
588 FSE_decode_t
const DInfo = ((
const FSE_decode_t*)(DStatePtr->table))[DStatePtr->state];
594 FSE_decode_t
const DInfo = ((
const FSE_decode_t*)(DStatePtr->table))[DStatePtr->state];
595 U32 const nbBits = DInfo.nbBits;
597 DStatePtr->state = DInfo.newState + lowBits;
602 FSE_decode_t
const DInfo = ((
const FSE_decode_t*)(DStatePtr->table))[DStatePtr->state];
603 U32 const nbBits = DInfo.nbBits;
604 BYTE const symbol = DInfo.symbol;
607 DStatePtr->state = DInfo.newState + lowBits;
615 FSE_decode_t
const DInfo = ((
const FSE_decode_t*)(DStatePtr->table))[DStatePtr->state];
616 U32 const nbBits = DInfo.nbBits;
617 BYTE const symbol = DInfo.symbol;
620 DStatePtr->state = DInfo.newState + lowBits;
624MEM_STATIC unsigned FSE_endOfDState(
const FSE_DState_t* DStatePtr)
626 return DStatePtr->state == 0;
631#ifndef FSE_COMMONDEFS_ONLY
641#ifndef FSE_MAX_MEMORY_USAGE
642# define FSE_MAX_MEMORY_USAGE 14
644#ifndef FSE_DEFAULT_MEMORY_USAGE
645# define FSE_DEFAULT_MEMORY_USAGE 13
651#ifndef FSE_MAX_SYMBOL_VALUE
652# define FSE_MAX_SYMBOL_VALUE 255
658#define FSE_FUNCTION_TYPE BYTE
659#define FSE_FUNCTION_EXTENSION
660#define FSE_DECODE_TYPE FSE_decode_t
669#define FSE_MAX_TABLELOG (FSE_MAX_MEMORY_USAGE-2)
670#define FSE_MAX_TABLESIZE (1U<<FSE_MAX_TABLELOG)
671#define FSE_MAXTABLESIZE_MASK (FSE_MAX_TABLESIZE-1)
672#define FSE_DEFAULT_TABLELOG (FSE_DEFAULT_MEMORY_USAGE-2)
673#define FSE_MIN_TABLELOG 5
675#define FSE_TABLELOG_ABSOLUTE_MAX 15
676#if FSE_MAX_TABLELOG > FSE_TABLELOG_ABSOLUTE_MAX
677# error "FSE_MAX_TABLELOG > FSE_TABLELOG_ABSOLUTE_MAX is not supported"
680#define FSE_TABLESTEP(tableSize) ((tableSize>>1) + (tableSize>>3) + 3)
686#if defined (__cplusplus)
MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t *bitD)
MEM_STATIC size_t BIT_readBits(BIT_DStream_t *bitD, unsigned nbBits)
MEM_STATIC void BIT_flushBits(BIT_CStream_t *bitC)
MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t *bitD, unsigned nbBits)
MEM_STATIC void BIT_addBits(BIT_CStream_t *bitC, size_t value, unsigned nbBits)
MEM_STATIC U16 MEM_read16(const void *memPtr)
__kernel_ptrdiff_t ptrdiff_t
FSE_PUBLIC_API size_t FSE_buildDTable(FSE_DTable *dt, const short *normalizedCounter, unsigned maxSymbolValue, unsigned tableLog)
FSE_PUBLIC_API size_t FSE_readNCount(short *normalizedCounter, unsigned *maxSymbolValuePtr, unsigned *tableLogPtr, const void *rBuffer, size_t rBuffSize)
FSE_PUBLIC_API size_t FSE_writeNCount(void *buffer, size_t bufferSize, const short *normalizedCounter, unsigned maxSymbolValue, unsigned tableLog)
FSE_PUBLIC_API FSE_CTable * FSE_createCTable(unsigned maxSymbolValue, unsigned tableLog)
FSE_PUBLIC_API size_t FSE_compress(void *dst, size_t dstCapacity, const void *src, size_t srcSize)
FSE_PUBLIC_API const char * FSE_getErrorName(size_t code)
FSE_PUBLIC_API void FSE_freeCTable(FSE_CTable *ct)
FSE_PUBLIC_API size_t FSE_buildCTable(FSE_CTable *ct, const short *normalizedCounter, unsigned maxSymbolValue, unsigned tableLog)
FSE_PUBLIC_API size_t FSE_decompress_usingDTable(void *dst, size_t dstCapacity, const void *cSrc, size_t cSrcSize, const FSE_DTable *dt)
FSE_PUBLIC_API size_t FSE_decompress(void *dst, size_t dstCapacity, const void *cSrc, size_t cSrcSize)
FSE_PUBLIC_API unsigned FSE_versionNumber(void)
FSE_PUBLIC_API size_t FSE_normalizeCount(short *normalizedCounter, unsigned tableLog, const unsigned *count, size_t srcSize, unsigned maxSymbolValue)
FSE_PUBLIC_API size_t FSE_NCountWriteBound(unsigned maxSymbolValue, unsigned tableLog)
FSE_PUBLIC_API size_t FSE_compress2(void *dst, size_t dstSize, const void *src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog)
FSE_PUBLIC_API unsigned FSE_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue)
FSE_PUBLIC_API FSE_DTable * FSE_createDTable(unsigned tableLog)
FSE_PUBLIC_API void FSE_freeDTable(FSE_DTable *dt)
FSE_PUBLIC_API size_t FSE_compressBound(size_t size)
FSE_PUBLIC_API size_t FSE_compress_usingCTable(void *dst, size_t dstCapacity, const void *src, size_t srcSize, const FSE_CTable *ct)
size_t FSE_compress_wksp(void *dst, size_t dstSize, const void *src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void *workSpace, size_t wkspSize)
size_t FSE_buildCTable_wksp(FSE_CTable *ct, const short *normalizedCounter, unsigned maxSymbolValue, unsigned tableLog, void *workSpace, size_t wkspSize)
unsigned FSE_optimalTableLog_internal(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue, unsigned minus)
size_t FSE_buildCTable_rle(FSE_CTable *ct, BYTE symbolValue)
size_t FSE_buildCTable_raw(FSE_CTable *ct, unsigned nbBits)
size_t FSE_decompress_wksp(void *dst, size_t dstCapacity, const void *cSrc, size_t cSrcSize, FSE_DTable *workSpace, unsigned maxLog)
size_t FSE_buildDTable_rle(FSE_DTable *dt, BYTE symbolValue)
size_t FSE_buildDTable_raw(FSE_DTable *dt, unsigned nbBits)
GLuint GLuint GLsizei count