xref: /OK3568_Linux_fs/kernel/lib/zstd/fse.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * FSE : Finite State Entropy codec
3*4882a593Smuzhiyun  * Public Prototypes declaration
4*4882a593Smuzhiyun  * Copyright (C) 2013-2016, Yann Collet.
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * Redistribution and use in source and binary forms, with or without
9*4882a593Smuzhiyun  * modification, are permitted provided that the following conditions are
10*4882a593Smuzhiyun  * met:
11*4882a593Smuzhiyun  *
12*4882a593Smuzhiyun  *   * Redistributions of source code must retain the above copyright
13*4882a593Smuzhiyun  * notice, this list of conditions and the following disclaimer.
14*4882a593Smuzhiyun  *   * Redistributions in binary form must reproduce the above
15*4882a593Smuzhiyun  * copyright notice, this list of conditions and the following disclaimer
16*4882a593Smuzhiyun  * in the documentation and/or other materials provided with the
17*4882a593Smuzhiyun  * distribution.
18*4882a593Smuzhiyun  *
19*4882a593Smuzhiyun  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20*4882a593Smuzhiyun  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21*4882a593Smuzhiyun  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22*4882a593Smuzhiyun  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23*4882a593Smuzhiyun  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24*4882a593Smuzhiyun  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25*4882a593Smuzhiyun  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26*4882a593Smuzhiyun  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27*4882a593Smuzhiyun  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28*4882a593Smuzhiyun  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29*4882a593Smuzhiyun  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*4882a593Smuzhiyun  *
31*4882a593Smuzhiyun  * This program is free software; you can redistribute it and/or modify it under
32*4882a593Smuzhiyun  * the terms of the GNU General Public License version 2 as published by the
33*4882a593Smuzhiyun  * Free Software Foundation. This program is dual-licensed; you may select
34*4882a593Smuzhiyun  * either version 2 of the GNU General Public License ("GPL") or BSD license
35*4882a593Smuzhiyun  * ("BSD").
36*4882a593Smuzhiyun  *
37*4882a593Smuzhiyun  * You can contact the author at :
38*4882a593Smuzhiyun  * - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
39*4882a593Smuzhiyun  */
40*4882a593Smuzhiyun #ifndef FSE_H
41*4882a593Smuzhiyun #define FSE_H
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun /*-*****************************************
44*4882a593Smuzhiyun *  Dependencies
45*4882a593Smuzhiyun ******************************************/
46*4882a593Smuzhiyun #include <linux/types.h> /* size_t, ptrdiff_t */
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun /*-*****************************************
49*4882a593Smuzhiyun *  FSE_PUBLIC_API : control library symbols visibility
50*4882a593Smuzhiyun ******************************************/
51*4882a593Smuzhiyun #define FSE_PUBLIC_API
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun /*------   Version   ------*/
54*4882a593Smuzhiyun #define FSE_VERSION_MAJOR 0
55*4882a593Smuzhiyun #define FSE_VERSION_MINOR 9
56*4882a593Smuzhiyun #define FSE_VERSION_RELEASE 0
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun #define FSE_LIB_VERSION FSE_VERSION_MAJOR.FSE_VERSION_MINOR.FSE_VERSION_RELEASE
59*4882a593Smuzhiyun #define FSE_QUOTE(str) #str
60*4882a593Smuzhiyun #define FSE_EXPAND_AND_QUOTE(str) FSE_QUOTE(str)
61*4882a593Smuzhiyun #define FSE_VERSION_STRING FSE_EXPAND_AND_QUOTE(FSE_LIB_VERSION)
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun #define FSE_VERSION_NUMBER (FSE_VERSION_MAJOR * 100 * 100 + FSE_VERSION_MINOR * 100 + FSE_VERSION_RELEASE)
64*4882a593Smuzhiyun FSE_PUBLIC_API unsigned FSE_versionNumber(void); /**< library version number; to be used when checking dll version */
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun /*-*****************************************
67*4882a593Smuzhiyun *  Tool functions
68*4882a593Smuzhiyun ******************************************/
69*4882a593Smuzhiyun FSE_PUBLIC_API size_t FSE_compressBound(size_t size); /* maximum compressed size */
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun /* Error Management */
72*4882a593Smuzhiyun FSE_PUBLIC_API unsigned FSE_isError(size_t code); /* tells if a return value is an error code */
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun /*-*****************************************
75*4882a593Smuzhiyun *  FSE detailed API
76*4882a593Smuzhiyun ******************************************/
77*4882a593Smuzhiyun /*!
78*4882a593Smuzhiyun FSE_compress() does the following:
79*4882a593Smuzhiyun 1. count symbol occurrence from source[] into table count[]
80*4882a593Smuzhiyun 2. normalize counters so that sum(count[]) == Power_of_2 (2^tableLog)
81*4882a593Smuzhiyun 3. save normalized counters to memory buffer using writeNCount()
82*4882a593Smuzhiyun 4. build encoding table 'CTable' from normalized counters
83*4882a593Smuzhiyun 5. encode the data stream using encoding table 'CTable'
84*4882a593Smuzhiyun 
85*4882a593Smuzhiyun FSE_decompress() does the following:
86*4882a593Smuzhiyun 1. read normalized counters with readNCount()
87*4882a593Smuzhiyun 2. build decoding table 'DTable' from normalized counters
88*4882a593Smuzhiyun 3. decode the data stream using decoding table 'DTable'
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun The following API allows targeting specific sub-functions for advanced tasks.
91*4882a593Smuzhiyun For example, it's possible to compress several blocks using the same 'CTable',
92*4882a593Smuzhiyun or to save and provide normalized distribution using external method.
93*4882a593Smuzhiyun */
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun /* *** COMPRESSION *** */
96*4882a593Smuzhiyun /*! FSE_optimalTableLog():
97*4882a593Smuzhiyun 	dynamically downsize 'tableLog' when conditions are met.
98*4882a593Smuzhiyun 	It saves CPU time, by using smaller tables, while preserving or even improving compression ratio.
99*4882a593Smuzhiyun 	@return : recommended tableLog (necessarily <= 'maxTableLog') */
100*4882a593Smuzhiyun FSE_PUBLIC_API unsigned FSE_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue);
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun /*! FSE_normalizeCount():
103*4882a593Smuzhiyun 	normalize counts so that sum(count[]) == Power_of_2 (2^tableLog)
104*4882a593Smuzhiyun 	'normalizedCounter' is a table of short, of minimum size (maxSymbolValue+1).
105*4882a593Smuzhiyun 	@return : tableLog,
106*4882a593Smuzhiyun 			  or an errorCode, which can be tested using FSE_isError() */
107*4882a593Smuzhiyun FSE_PUBLIC_API size_t FSE_normalizeCount(short *normalizedCounter, unsigned tableLog, const unsigned *count, size_t srcSize, unsigned maxSymbolValue);
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun /*! FSE_NCountWriteBound():
110*4882a593Smuzhiyun 	Provides the maximum possible size of an FSE normalized table, given 'maxSymbolValue' and 'tableLog'.
111*4882a593Smuzhiyun 	Typically useful for allocation purpose. */
112*4882a593Smuzhiyun FSE_PUBLIC_API size_t FSE_NCountWriteBound(unsigned maxSymbolValue, unsigned tableLog);
113*4882a593Smuzhiyun 
114*4882a593Smuzhiyun /*! FSE_writeNCount():
115*4882a593Smuzhiyun 	Compactly save 'normalizedCounter' into 'buffer'.
116*4882a593Smuzhiyun 	@return : size of the compressed table,
117*4882a593Smuzhiyun 			  or an errorCode, which can be tested using FSE_isError(). */
118*4882a593Smuzhiyun FSE_PUBLIC_API size_t FSE_writeNCount(void *buffer, size_t bufferSize, const short *normalizedCounter, unsigned maxSymbolValue, unsigned tableLog);
119*4882a593Smuzhiyun 
120*4882a593Smuzhiyun /*! Constructor and Destructor of FSE_CTable.
121*4882a593Smuzhiyun 	Note that FSE_CTable size depends on 'tableLog' and 'maxSymbolValue' */
122*4882a593Smuzhiyun typedef unsigned FSE_CTable; /* don't allocate that. It's only meant to be more restrictive than void* */
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun /*! FSE_compress_usingCTable():
125*4882a593Smuzhiyun 	Compress `src` using `ct` into `dst` which must be already allocated.
126*4882a593Smuzhiyun 	@return : size of compressed data (<= `dstCapacity`),
127*4882a593Smuzhiyun 			  or 0 if compressed data could not fit into `dst`,
128*4882a593Smuzhiyun 			  or an errorCode, which can be tested using FSE_isError() */
129*4882a593Smuzhiyun FSE_PUBLIC_API size_t FSE_compress_usingCTable(void *dst, size_t dstCapacity, const void *src, size_t srcSize, const FSE_CTable *ct);
130*4882a593Smuzhiyun 
131*4882a593Smuzhiyun /*!
132*4882a593Smuzhiyun Tutorial :
133*4882a593Smuzhiyun ----------
134*4882a593Smuzhiyun The first step is to count all symbols. FSE_count() does this job very fast.
135*4882a593Smuzhiyun Result will be saved into 'count', a table of unsigned int, which must be already allocated, and have 'maxSymbolValuePtr[0]+1' cells.
136*4882a593Smuzhiyun 'src' is a table of bytes of size 'srcSize'. All values within 'src' MUST be <= maxSymbolValuePtr[0]
137*4882a593Smuzhiyun maxSymbolValuePtr[0] will be updated, with its real value (necessarily <= original value)
138*4882a593Smuzhiyun FSE_count() will return the number of occurrence of the most frequent symbol.
139*4882a593Smuzhiyun This can be used to know if there is a single symbol within 'src', and to quickly evaluate its compressibility.
140*4882a593Smuzhiyun If there is an error, the function will return an ErrorCode (which can be tested using FSE_isError()).
141*4882a593Smuzhiyun 
142*4882a593Smuzhiyun The next step is to normalize the frequencies.
143*4882a593Smuzhiyun FSE_normalizeCount() will ensure that sum of frequencies is == 2 ^'tableLog'.
144*4882a593Smuzhiyun It also guarantees a minimum of 1 to any Symbol with frequency >= 1.
145*4882a593Smuzhiyun You can use 'tableLog'==0 to mean "use default tableLog value".
146*4882a593Smuzhiyun If you are unsure of which tableLog value to use, you can ask FSE_optimalTableLog(),
147*4882a593Smuzhiyun which will provide the optimal valid tableLog given sourceSize, maxSymbolValue, and a user-defined maximum (0 means "default").
148*4882a593Smuzhiyun 
149*4882a593Smuzhiyun The result of FSE_normalizeCount() will be saved into a table,
150*4882a593Smuzhiyun called 'normalizedCounter', which is a table of signed short.
151*4882a593Smuzhiyun 'normalizedCounter' must be already allocated, and have at least 'maxSymbolValue+1' cells.
152*4882a593Smuzhiyun The return value is tableLog if everything proceeded as expected.
153*4882a593Smuzhiyun It is 0 if there is a single symbol within distribution.
154*4882a593Smuzhiyun If there is an error (ex: invalid tableLog value), the function will return an ErrorCode (which can be tested using FSE_isError()).
155*4882a593Smuzhiyun 
156*4882a593Smuzhiyun 'normalizedCounter' can be saved in a compact manner to a memory area using FSE_writeNCount().
157*4882a593Smuzhiyun 'buffer' must be already allocated.
158*4882a593Smuzhiyun For guaranteed success, buffer size must be at least FSE_headerBound().
159*4882a593Smuzhiyun The result of the function is the number of bytes written into 'buffer'.
160*4882a593Smuzhiyun If there is an error, the function will return an ErrorCode (which can be tested using FSE_isError(); ex : buffer size too small).
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun 'normalizedCounter' can then be used to create the compression table 'CTable'.
163*4882a593Smuzhiyun The space required by 'CTable' must be already allocated, using FSE_createCTable().
164*4882a593Smuzhiyun You can then use FSE_buildCTable() to fill 'CTable'.
165*4882a593Smuzhiyun If there is an error, both functions will return an ErrorCode (which can be tested using FSE_isError()).
166*4882a593Smuzhiyun 
167*4882a593Smuzhiyun 'CTable' can then be used to compress 'src', with FSE_compress_usingCTable().
168*4882a593Smuzhiyun Similar to FSE_count(), the convention is that 'src' is assumed to be a table of char of size 'srcSize'
169*4882a593Smuzhiyun The function returns the size of compressed data (without header), necessarily <= `dstCapacity`.
170*4882a593Smuzhiyun If it returns '0', compressed data could not fit into 'dst'.
171*4882a593Smuzhiyun If there is an error, the function will return an ErrorCode (which can be tested using FSE_isError()).
172*4882a593Smuzhiyun */
173*4882a593Smuzhiyun 
174*4882a593Smuzhiyun /* *** DECOMPRESSION *** */
175*4882a593Smuzhiyun 
176*4882a593Smuzhiyun /*! FSE_readNCount():
177*4882a593Smuzhiyun 	Read compactly saved 'normalizedCounter' from 'rBuffer'.
178*4882a593Smuzhiyun 	@return : size read from 'rBuffer',
179*4882a593Smuzhiyun 			  or an errorCode, which can be tested using FSE_isError().
180*4882a593Smuzhiyun 			  maxSymbolValuePtr[0] and tableLogPtr[0] will also be updated with their respective values */
181*4882a593Smuzhiyun FSE_PUBLIC_API size_t FSE_readNCount(short *normalizedCounter, unsigned *maxSymbolValuePtr, unsigned *tableLogPtr, const void *rBuffer, size_t rBuffSize);
182*4882a593Smuzhiyun 
183*4882a593Smuzhiyun /*! Constructor and Destructor of FSE_DTable.
184*4882a593Smuzhiyun 	Note that its size depends on 'tableLog' */
185*4882a593Smuzhiyun typedef unsigned FSE_DTable; /* don't allocate that. It's just a way to be more restrictive than void* */
186*4882a593Smuzhiyun 
187*4882a593Smuzhiyun /*! FSE_buildDTable():
188*4882a593Smuzhiyun 	Builds 'dt', which must be already allocated, using FSE_createDTable().
189*4882a593Smuzhiyun 	return : 0, or an errorCode, which can be tested using FSE_isError() */
190*4882a593Smuzhiyun FSE_PUBLIC_API size_t FSE_buildDTable_wksp(FSE_DTable *dt, const short *normalizedCounter, unsigned maxSymbolValue, unsigned tableLog, void *workspace, size_t workspaceSize);
191*4882a593Smuzhiyun 
192*4882a593Smuzhiyun /*! FSE_decompress_usingDTable():
193*4882a593Smuzhiyun 	Decompress compressed source `cSrc` of size `cSrcSize` using `dt`
194*4882a593Smuzhiyun 	into `dst` which must be already allocated.
195*4882a593Smuzhiyun 	@return : size of regenerated data (necessarily <= `dstCapacity`),
196*4882a593Smuzhiyun 			  or an errorCode, which can be tested using FSE_isError() */
197*4882a593Smuzhiyun FSE_PUBLIC_API size_t FSE_decompress_usingDTable(void *dst, size_t dstCapacity, const void *cSrc, size_t cSrcSize, const FSE_DTable *dt);
198*4882a593Smuzhiyun 
199*4882a593Smuzhiyun /*!
200*4882a593Smuzhiyun Tutorial :
201*4882a593Smuzhiyun ----------
202*4882a593Smuzhiyun (Note : these functions only decompress FSE-compressed blocks.
203*4882a593Smuzhiyun  If block is uncompressed, use memcpy() instead
204*4882a593Smuzhiyun  If block is a single repeated byte, use memset() instead )
205*4882a593Smuzhiyun 
206*4882a593Smuzhiyun The first step is to obtain the normalized frequencies of symbols.
207*4882a593Smuzhiyun This can be performed by FSE_readNCount() if it was saved using FSE_writeNCount().
208*4882a593Smuzhiyun 'normalizedCounter' must be already allocated, and have at least 'maxSymbolValuePtr[0]+1' cells of signed short.
209*4882a593Smuzhiyun In practice, that means it's necessary to know 'maxSymbolValue' beforehand,
210*4882a593Smuzhiyun or size the table to handle worst case situations (typically 256).
211*4882a593Smuzhiyun FSE_readNCount() will provide 'tableLog' and 'maxSymbolValue'.
212*4882a593Smuzhiyun The result of FSE_readNCount() is the number of bytes read from 'rBuffer'.
213*4882a593Smuzhiyun Note that 'rBufferSize' must be at least 4 bytes, even if useful information is less than that.
214*4882a593Smuzhiyun If there is an error, the function will return an error code, which can be tested using FSE_isError().
215*4882a593Smuzhiyun 
216*4882a593Smuzhiyun The next step is to build the decompression tables 'FSE_DTable' from 'normalizedCounter'.
217*4882a593Smuzhiyun This is performed by the function FSE_buildDTable().
218*4882a593Smuzhiyun The space required by 'FSE_DTable' must be already allocated using FSE_createDTable().
219*4882a593Smuzhiyun If there is an error, the function will return an error code, which can be tested using FSE_isError().
220*4882a593Smuzhiyun 
221*4882a593Smuzhiyun `FSE_DTable` can then be used to decompress `cSrc`, with FSE_decompress_usingDTable().
222*4882a593Smuzhiyun `cSrcSize` must be strictly correct, otherwise decompression will fail.
223*4882a593Smuzhiyun FSE_decompress_usingDTable() result will tell how many bytes were regenerated (<=`dstCapacity`).
224*4882a593Smuzhiyun If there is an error, the function will return an error code, which can be tested using FSE_isError(). (ex: dst buffer too small)
225*4882a593Smuzhiyun */
226*4882a593Smuzhiyun 
227*4882a593Smuzhiyun /* *** Dependency *** */
228*4882a593Smuzhiyun #include "bitstream.h"
229*4882a593Smuzhiyun 
230*4882a593Smuzhiyun /* *****************************************
231*4882a593Smuzhiyun *  Static allocation
232*4882a593Smuzhiyun *******************************************/
233*4882a593Smuzhiyun /* FSE buffer bounds */
234*4882a593Smuzhiyun #define FSE_NCOUNTBOUND 512
235*4882a593Smuzhiyun #define FSE_BLOCKBOUND(size) (size + (size >> 7))
236*4882a593Smuzhiyun #define FSE_COMPRESSBOUND(size) (FSE_NCOUNTBOUND + FSE_BLOCKBOUND(size)) /* Macro version, useful for static allocation */
237*4882a593Smuzhiyun 
238*4882a593Smuzhiyun /* It is possible to statically allocate FSE CTable/DTable as a table of FSE_CTable/FSE_DTable using below macros */
239*4882a593Smuzhiyun #define FSE_CTABLE_SIZE_U32(maxTableLog, maxSymbolValue) (1 + (1 << (maxTableLog - 1)) + ((maxSymbolValue + 1) * 2))
240*4882a593Smuzhiyun #define FSE_DTABLE_SIZE_U32(maxTableLog) (1 + (1 << maxTableLog))
241*4882a593Smuzhiyun 
242*4882a593Smuzhiyun /* *****************************************
243*4882a593Smuzhiyun *  FSE advanced API
244*4882a593Smuzhiyun *******************************************/
245*4882a593Smuzhiyun /* FSE_count_wksp() :
246*4882a593Smuzhiyun  * Same as FSE_count(), but using an externally provided scratch buffer.
247*4882a593Smuzhiyun  * `workSpace` size must be table of >= `1024` unsigned
248*4882a593Smuzhiyun  */
249*4882a593Smuzhiyun size_t FSE_count_wksp(unsigned *count, unsigned *maxSymbolValuePtr, const void *source, size_t sourceSize, unsigned *workSpace);
250*4882a593Smuzhiyun 
251*4882a593Smuzhiyun /* FSE_countFast_wksp() :
252*4882a593Smuzhiyun  * Same as FSE_countFast(), but using an externally provided scratch buffer.
253*4882a593Smuzhiyun  * `workSpace` must be a table of minimum `1024` unsigned
254*4882a593Smuzhiyun  */
255*4882a593Smuzhiyun size_t FSE_countFast_wksp(unsigned *count, unsigned *maxSymbolValuePtr, const void *src, size_t srcSize, unsigned *workSpace);
256*4882a593Smuzhiyun 
257*4882a593Smuzhiyun /*! FSE_count_simple
258*4882a593Smuzhiyun  * Same as FSE_countFast(), but does not use any additional memory (not even on stack).
259*4882a593Smuzhiyun  * This function is unsafe, and will segfault if any value within `src` is `> *maxSymbolValuePtr` (presuming it's also the size of `count`).
260*4882a593Smuzhiyun */
261*4882a593Smuzhiyun size_t FSE_count_simple(unsigned *count, unsigned *maxSymbolValuePtr, const void *src, size_t srcSize);
262*4882a593Smuzhiyun 
263*4882a593Smuzhiyun unsigned FSE_optimalTableLog_internal(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue, unsigned minus);
264*4882a593Smuzhiyun /**< same as FSE_optimalTableLog(), which used `minus==2` */
265*4882a593Smuzhiyun 
266*4882a593Smuzhiyun size_t FSE_buildCTable_raw(FSE_CTable *ct, unsigned nbBits);
267*4882a593Smuzhiyun /**< build a fake FSE_CTable, designed for a flat distribution, where each symbol uses nbBits */
268*4882a593Smuzhiyun 
269*4882a593Smuzhiyun size_t FSE_buildCTable_rle(FSE_CTable *ct, unsigned char symbolValue);
270*4882a593Smuzhiyun /**< build a fake FSE_CTable, designed to compress always the same symbolValue */
271*4882a593Smuzhiyun 
272*4882a593Smuzhiyun /* FSE_buildCTable_wksp() :
273*4882a593Smuzhiyun  * Same as FSE_buildCTable(), but using an externally allocated scratch buffer (`workSpace`).
274*4882a593Smuzhiyun  * `wkspSize` must be >= `(1<<tableLog)`.
275*4882a593Smuzhiyun  */
276*4882a593Smuzhiyun size_t FSE_buildCTable_wksp(FSE_CTable *ct, const short *normalizedCounter, unsigned maxSymbolValue, unsigned tableLog, void *workSpace, size_t wkspSize);
277*4882a593Smuzhiyun 
278*4882a593Smuzhiyun size_t FSE_buildDTable_raw(FSE_DTable *dt, unsigned nbBits);
279*4882a593Smuzhiyun /**< build a fake FSE_DTable, designed to read a flat distribution where each symbol uses nbBits */
280*4882a593Smuzhiyun 
281*4882a593Smuzhiyun size_t FSE_buildDTable_rle(FSE_DTable *dt, unsigned char symbolValue);
282*4882a593Smuzhiyun /**< build a fake FSE_DTable, designed to always generate the same symbolValue */
283*4882a593Smuzhiyun 
284*4882a593Smuzhiyun size_t FSE_decompress_wksp(void *dst, size_t dstCapacity, const void *cSrc, size_t cSrcSize, unsigned maxLog, void *workspace, size_t workspaceSize);
285*4882a593Smuzhiyun /**< same as FSE_decompress(), using an externally allocated `workSpace` produced with `FSE_DTABLE_SIZE_U32(maxLog)` */
286*4882a593Smuzhiyun 
287*4882a593Smuzhiyun /* *****************************************
288*4882a593Smuzhiyun *  FSE symbol compression API
289*4882a593Smuzhiyun *******************************************/
290*4882a593Smuzhiyun /*!
291*4882a593Smuzhiyun    This API consists of small unitary functions, which highly benefit from being inlined.
292*4882a593Smuzhiyun    Hence their body are included in next section.
293*4882a593Smuzhiyun */
294*4882a593Smuzhiyun typedef struct {
295*4882a593Smuzhiyun 	ptrdiff_t value;
296*4882a593Smuzhiyun 	const void *stateTable;
297*4882a593Smuzhiyun 	const void *symbolTT;
298*4882a593Smuzhiyun 	unsigned stateLog;
299*4882a593Smuzhiyun } FSE_CState_t;
300*4882a593Smuzhiyun 
301*4882a593Smuzhiyun static void FSE_initCState(FSE_CState_t *CStatePtr, const FSE_CTable *ct);
302*4882a593Smuzhiyun 
303*4882a593Smuzhiyun static void FSE_encodeSymbol(BIT_CStream_t *bitC, FSE_CState_t *CStatePtr, unsigned symbol);
304*4882a593Smuzhiyun 
305*4882a593Smuzhiyun static void FSE_flushCState(BIT_CStream_t *bitC, const FSE_CState_t *CStatePtr);
306*4882a593Smuzhiyun 
307*4882a593Smuzhiyun /**<
308*4882a593Smuzhiyun These functions are inner components of FSE_compress_usingCTable().
309*4882a593Smuzhiyun They allow the creation of custom streams, mixing multiple tables and bit sources.
310*4882a593Smuzhiyun 
311*4882a593Smuzhiyun A key property to keep in mind is that encoding and decoding are done **in reverse direction**.
312*4882a593Smuzhiyun So the first symbol you will encode is the last you will decode, like a LIFO stack.
313*4882a593Smuzhiyun 
314*4882a593Smuzhiyun You will need a few variables to track your CStream. They are :
315*4882a593Smuzhiyun 
316*4882a593Smuzhiyun FSE_CTable    ct;         // Provided by FSE_buildCTable()
317*4882a593Smuzhiyun BIT_CStream_t bitStream;  // bitStream tracking structure
318*4882a593Smuzhiyun FSE_CState_t  state;      // State tracking structure (can have several)
319*4882a593Smuzhiyun 
320*4882a593Smuzhiyun 
321*4882a593Smuzhiyun The first thing to do is to init bitStream and state.
322*4882a593Smuzhiyun 	size_t errorCode = BIT_initCStream(&bitStream, dstBuffer, maxDstSize);
323*4882a593Smuzhiyun 	FSE_initCState(&state, ct);
324*4882a593Smuzhiyun 
325*4882a593Smuzhiyun Note that BIT_initCStream() can produce an error code, so its result should be tested, using FSE_isError();
326*4882a593Smuzhiyun You can then encode your input data, byte after byte.
327*4882a593Smuzhiyun FSE_encodeSymbol() outputs a maximum of 'tableLog' bits at a time.
328*4882a593Smuzhiyun Remember decoding will be done in reverse direction.
329*4882a593Smuzhiyun 	FSE_encodeByte(&bitStream, &state, symbol);
330*4882a593Smuzhiyun 
331*4882a593Smuzhiyun At any time, you can also add any bit sequence.
332*4882a593Smuzhiyun Note : maximum allowed nbBits is 25, for compatibility with 32-bits decoders
333*4882a593Smuzhiyun 	BIT_addBits(&bitStream, bitField, nbBits);
334*4882a593Smuzhiyun 
335*4882a593Smuzhiyun The above methods don't commit data to memory, they just store it into local register, for speed.
336*4882a593Smuzhiyun Local register size is 64-bits on 64-bits systems, 32-bits on 32-bits systems (size_t).
337*4882a593Smuzhiyun Writing data to memory is a manual operation, performed by the flushBits function.
338*4882a593Smuzhiyun 	BIT_flushBits(&bitStream);
339*4882a593Smuzhiyun 
340*4882a593Smuzhiyun Your last FSE encoding operation shall be to flush your last state value(s).
341*4882a593Smuzhiyun 	FSE_flushState(&bitStream, &state);
342*4882a593Smuzhiyun 
343*4882a593Smuzhiyun Finally, you must close the bitStream.
344*4882a593Smuzhiyun The function returns the size of CStream in bytes.
345*4882a593Smuzhiyun If data couldn't fit into dstBuffer, it will return a 0 ( == not compressible)
346*4882a593Smuzhiyun If there is an error, it returns an errorCode (which can be tested using FSE_isError()).
347*4882a593Smuzhiyun 	size_t size = BIT_closeCStream(&bitStream);
348*4882a593Smuzhiyun */
349*4882a593Smuzhiyun 
350*4882a593Smuzhiyun /* *****************************************
351*4882a593Smuzhiyun *  FSE symbol decompression API
352*4882a593Smuzhiyun *******************************************/
353*4882a593Smuzhiyun typedef struct {
354*4882a593Smuzhiyun 	size_t state;
355*4882a593Smuzhiyun 	const void *table; /* precise table may vary, depending on U16 */
356*4882a593Smuzhiyun } FSE_DState_t;
357*4882a593Smuzhiyun 
358*4882a593Smuzhiyun static void FSE_initDState(FSE_DState_t *DStatePtr, BIT_DStream_t *bitD, const FSE_DTable *dt);
359*4882a593Smuzhiyun 
360*4882a593Smuzhiyun static unsigned char FSE_decodeSymbol(FSE_DState_t *DStatePtr, BIT_DStream_t *bitD);
361*4882a593Smuzhiyun 
362*4882a593Smuzhiyun static unsigned FSE_endOfDState(const FSE_DState_t *DStatePtr);
363*4882a593Smuzhiyun 
364*4882a593Smuzhiyun /**<
365*4882a593Smuzhiyun Let's now decompose FSE_decompress_usingDTable() into its unitary components.
366*4882a593Smuzhiyun You will decode FSE-encoded symbols from the bitStream,
367*4882a593Smuzhiyun and also any other bitFields you put in, **in reverse order**.
368*4882a593Smuzhiyun 
369*4882a593Smuzhiyun You will need a few variables to track your bitStream. They are :
370*4882a593Smuzhiyun 
371*4882a593Smuzhiyun BIT_DStream_t DStream;    // Stream context
372*4882a593Smuzhiyun FSE_DState_t  DState;     // State context. Multiple ones are possible
373*4882a593Smuzhiyun FSE_DTable*   DTablePtr;  // Decoding table, provided by FSE_buildDTable()
374*4882a593Smuzhiyun 
375*4882a593Smuzhiyun The first thing to do is to init the bitStream.
376*4882a593Smuzhiyun 	errorCode = BIT_initDStream(&DStream, srcBuffer, srcSize);
377*4882a593Smuzhiyun 
378*4882a593Smuzhiyun You should then retrieve your initial state(s)
379*4882a593Smuzhiyun (in reverse flushing order if you have several ones) :
380*4882a593Smuzhiyun 	errorCode = FSE_initDState(&DState, &DStream, DTablePtr);
381*4882a593Smuzhiyun 
382*4882a593Smuzhiyun You can then decode your data, symbol after symbol.
383*4882a593Smuzhiyun For information the maximum number of bits read by FSE_decodeSymbol() is 'tableLog'.
384*4882a593Smuzhiyun Keep in mind that symbols are decoded in reverse order, like a LIFO stack (last in, first out).
385*4882a593Smuzhiyun 	unsigned char symbol = FSE_decodeSymbol(&DState, &DStream);
386*4882a593Smuzhiyun 
387*4882a593Smuzhiyun You can retrieve any bitfield you eventually stored into the bitStream (in reverse order)
388*4882a593Smuzhiyun Note : maximum allowed nbBits is 25, for 32-bits compatibility
389*4882a593Smuzhiyun 	size_t bitField = BIT_readBits(&DStream, nbBits);
390*4882a593Smuzhiyun 
391*4882a593Smuzhiyun All above operations only read from local register (which size depends on size_t).
392*4882a593Smuzhiyun Refueling the register from memory is manually performed by the reload method.
393*4882a593Smuzhiyun 	endSignal = FSE_reloadDStream(&DStream);
394*4882a593Smuzhiyun 
395*4882a593Smuzhiyun BIT_reloadDStream() result tells if there is still some more data to read from DStream.
396*4882a593Smuzhiyun BIT_DStream_unfinished : there is still some data left into the DStream.
397*4882a593Smuzhiyun BIT_DStream_endOfBuffer : Dstream reached end of buffer. Its container may no longer be completely filled.
398*4882a593Smuzhiyun BIT_DStream_completed : Dstream reached its exact end, corresponding in general to decompression completed.
399*4882a593Smuzhiyun BIT_DStream_tooFar : Dstream went too far. Decompression result is corrupted.
400*4882a593Smuzhiyun 
401*4882a593Smuzhiyun When reaching end of buffer (BIT_DStream_endOfBuffer), progress slowly, notably if you decode multiple symbols per loop,
402*4882a593Smuzhiyun to properly detect the exact end of stream.
403*4882a593Smuzhiyun After each decoded symbol, check if DStream is fully consumed using this simple test :
404*4882a593Smuzhiyun 	BIT_reloadDStream(&DStream) >= BIT_DStream_completed
405*4882a593Smuzhiyun 
406*4882a593Smuzhiyun When it's done, verify decompression is fully completed, by checking both DStream and the relevant states.
407*4882a593Smuzhiyun Checking if DStream has reached its end is performed by :
408*4882a593Smuzhiyun 	BIT_endOfDStream(&DStream);
409*4882a593Smuzhiyun Check also the states. There might be some symbols left there, if some high probability ones (>50%) are possible.
410*4882a593Smuzhiyun 	FSE_endOfDState(&DState);
411*4882a593Smuzhiyun */
412*4882a593Smuzhiyun 
413*4882a593Smuzhiyun /* *****************************************
414*4882a593Smuzhiyun *  FSE unsafe API
415*4882a593Smuzhiyun *******************************************/
416*4882a593Smuzhiyun static unsigned char FSE_decodeSymbolFast(FSE_DState_t *DStatePtr, BIT_DStream_t *bitD);
417*4882a593Smuzhiyun /* faster, but works only if nbBits is always >= 1 (otherwise, result will be corrupted) */
418*4882a593Smuzhiyun 
419*4882a593Smuzhiyun /* *****************************************
420*4882a593Smuzhiyun *  Implementation of inlined functions
421*4882a593Smuzhiyun *******************************************/
422*4882a593Smuzhiyun typedef struct {
423*4882a593Smuzhiyun 	int deltaFindState;
424*4882a593Smuzhiyun 	U32 deltaNbBits;
425*4882a593Smuzhiyun } FSE_symbolCompressionTransform; /* total 8 bytes */
426*4882a593Smuzhiyun 
FSE_initCState(FSE_CState_t * statePtr,const FSE_CTable * ct)427*4882a593Smuzhiyun ZSTD_STATIC void FSE_initCState(FSE_CState_t *statePtr, const FSE_CTable *ct)
428*4882a593Smuzhiyun {
429*4882a593Smuzhiyun 	const void *ptr = ct;
430*4882a593Smuzhiyun 	const U16 *u16ptr = (const U16 *)ptr;
431*4882a593Smuzhiyun 	const U32 tableLog = ZSTD_read16(ptr);
432*4882a593Smuzhiyun 	statePtr->value = (ptrdiff_t)1 << tableLog;
433*4882a593Smuzhiyun 	statePtr->stateTable = u16ptr + 2;
434*4882a593Smuzhiyun 	statePtr->symbolTT = ((const U32 *)ct + 1 + (tableLog ? (1 << (tableLog - 1)) : 1));
435*4882a593Smuzhiyun 	statePtr->stateLog = tableLog;
436*4882a593Smuzhiyun }
437*4882a593Smuzhiyun 
438*4882a593Smuzhiyun /*! FSE_initCState2() :
439*4882a593Smuzhiyun *   Same as FSE_initCState(), but the first symbol to include (which will be the last to be read)
440*4882a593Smuzhiyun *   uses the smallest state value possible, saving the cost of this symbol */
FSE_initCState2(FSE_CState_t * statePtr,const FSE_CTable * ct,U32 symbol)441*4882a593Smuzhiyun ZSTD_STATIC void FSE_initCState2(FSE_CState_t *statePtr, const FSE_CTable *ct, U32 symbol)
442*4882a593Smuzhiyun {
443*4882a593Smuzhiyun 	FSE_initCState(statePtr, ct);
444*4882a593Smuzhiyun 	{
445*4882a593Smuzhiyun 		const FSE_symbolCompressionTransform symbolTT = ((const FSE_symbolCompressionTransform *)(statePtr->symbolTT))[symbol];
446*4882a593Smuzhiyun 		const U16 *stateTable = (const U16 *)(statePtr->stateTable);
447*4882a593Smuzhiyun 		U32 nbBitsOut = (U32)((symbolTT.deltaNbBits + (1 << 15)) >> 16);
448*4882a593Smuzhiyun 		statePtr->value = (nbBitsOut << 16) - symbolTT.deltaNbBits;
449*4882a593Smuzhiyun 		statePtr->value = stateTable[(statePtr->value >> nbBitsOut) + symbolTT.deltaFindState];
450*4882a593Smuzhiyun 	}
451*4882a593Smuzhiyun }
452*4882a593Smuzhiyun 
FSE_encodeSymbol(BIT_CStream_t * bitC,FSE_CState_t * statePtr,U32 symbol)453*4882a593Smuzhiyun ZSTD_STATIC void FSE_encodeSymbol(BIT_CStream_t *bitC, FSE_CState_t *statePtr, U32 symbol)
454*4882a593Smuzhiyun {
455*4882a593Smuzhiyun 	const FSE_symbolCompressionTransform symbolTT = ((const FSE_symbolCompressionTransform *)(statePtr->symbolTT))[symbol];
456*4882a593Smuzhiyun 	const U16 *const stateTable = (const U16 *)(statePtr->stateTable);
457*4882a593Smuzhiyun 	U32 nbBitsOut = (U32)((statePtr->value + symbolTT.deltaNbBits) >> 16);
458*4882a593Smuzhiyun 	BIT_addBits(bitC, statePtr->value, nbBitsOut);
459*4882a593Smuzhiyun 	statePtr->value = stateTable[(statePtr->value >> nbBitsOut) + symbolTT.deltaFindState];
460*4882a593Smuzhiyun }
461*4882a593Smuzhiyun 
FSE_flushCState(BIT_CStream_t * bitC,const FSE_CState_t * statePtr)462*4882a593Smuzhiyun ZSTD_STATIC void FSE_flushCState(BIT_CStream_t *bitC, const FSE_CState_t *statePtr)
463*4882a593Smuzhiyun {
464*4882a593Smuzhiyun 	BIT_addBits(bitC, statePtr->value, statePtr->stateLog);
465*4882a593Smuzhiyun 	BIT_flushBits(bitC);
466*4882a593Smuzhiyun }
467*4882a593Smuzhiyun 
468*4882a593Smuzhiyun /* ======    Decompression    ====== */
469*4882a593Smuzhiyun 
470*4882a593Smuzhiyun typedef struct {
471*4882a593Smuzhiyun 	U16 tableLog;
472*4882a593Smuzhiyun 	U16 fastMode;
473*4882a593Smuzhiyun } FSE_DTableHeader; /* sizeof U32 */
474*4882a593Smuzhiyun 
475*4882a593Smuzhiyun typedef struct {
476*4882a593Smuzhiyun 	unsigned short newState;
477*4882a593Smuzhiyun 	unsigned char symbol;
478*4882a593Smuzhiyun 	unsigned char nbBits;
479*4882a593Smuzhiyun } FSE_decode_t; /* size == U32 */
480*4882a593Smuzhiyun 
FSE_initDState(FSE_DState_t * DStatePtr,BIT_DStream_t * bitD,const FSE_DTable * dt)481*4882a593Smuzhiyun ZSTD_STATIC void FSE_initDState(FSE_DState_t *DStatePtr, BIT_DStream_t *bitD, const FSE_DTable *dt)
482*4882a593Smuzhiyun {
483*4882a593Smuzhiyun 	const void *ptr = dt;
484*4882a593Smuzhiyun 	const FSE_DTableHeader *const DTableH = (const FSE_DTableHeader *)ptr;
485*4882a593Smuzhiyun 	DStatePtr->state = BIT_readBits(bitD, DTableH->tableLog);
486*4882a593Smuzhiyun 	BIT_reloadDStream(bitD);
487*4882a593Smuzhiyun 	DStatePtr->table = dt + 1;
488*4882a593Smuzhiyun }
489*4882a593Smuzhiyun 
FSE_peekSymbol(const FSE_DState_t * DStatePtr)490*4882a593Smuzhiyun ZSTD_STATIC BYTE FSE_peekSymbol(const FSE_DState_t *DStatePtr)
491*4882a593Smuzhiyun {
492*4882a593Smuzhiyun 	FSE_decode_t const DInfo = ((const FSE_decode_t *)(DStatePtr->table))[DStatePtr->state];
493*4882a593Smuzhiyun 	return DInfo.symbol;
494*4882a593Smuzhiyun }
495*4882a593Smuzhiyun 
FSE_updateState(FSE_DState_t * DStatePtr,BIT_DStream_t * bitD)496*4882a593Smuzhiyun ZSTD_STATIC void FSE_updateState(FSE_DState_t *DStatePtr, BIT_DStream_t *bitD)
497*4882a593Smuzhiyun {
498*4882a593Smuzhiyun 	FSE_decode_t const DInfo = ((const FSE_decode_t *)(DStatePtr->table))[DStatePtr->state];
499*4882a593Smuzhiyun 	U32 const nbBits = DInfo.nbBits;
500*4882a593Smuzhiyun 	size_t const lowBits = BIT_readBits(bitD, nbBits);
501*4882a593Smuzhiyun 	DStatePtr->state = DInfo.newState + lowBits;
502*4882a593Smuzhiyun }
503*4882a593Smuzhiyun 
FSE_decodeSymbol(FSE_DState_t * DStatePtr,BIT_DStream_t * bitD)504*4882a593Smuzhiyun ZSTD_STATIC BYTE FSE_decodeSymbol(FSE_DState_t *DStatePtr, BIT_DStream_t *bitD)
505*4882a593Smuzhiyun {
506*4882a593Smuzhiyun 	FSE_decode_t const DInfo = ((const FSE_decode_t *)(DStatePtr->table))[DStatePtr->state];
507*4882a593Smuzhiyun 	U32 const nbBits = DInfo.nbBits;
508*4882a593Smuzhiyun 	BYTE const symbol = DInfo.symbol;
509*4882a593Smuzhiyun 	size_t const lowBits = BIT_readBits(bitD, nbBits);
510*4882a593Smuzhiyun 
511*4882a593Smuzhiyun 	DStatePtr->state = DInfo.newState + lowBits;
512*4882a593Smuzhiyun 	return symbol;
513*4882a593Smuzhiyun }
514*4882a593Smuzhiyun 
515*4882a593Smuzhiyun /*! FSE_decodeSymbolFast() :
516*4882a593Smuzhiyun 	unsafe, only works if no symbol has a probability > 50% */
FSE_decodeSymbolFast(FSE_DState_t * DStatePtr,BIT_DStream_t * bitD)517*4882a593Smuzhiyun ZSTD_STATIC BYTE FSE_decodeSymbolFast(FSE_DState_t *DStatePtr, BIT_DStream_t *bitD)
518*4882a593Smuzhiyun {
519*4882a593Smuzhiyun 	FSE_decode_t const DInfo = ((const FSE_decode_t *)(DStatePtr->table))[DStatePtr->state];
520*4882a593Smuzhiyun 	U32 const nbBits = DInfo.nbBits;
521*4882a593Smuzhiyun 	BYTE const symbol = DInfo.symbol;
522*4882a593Smuzhiyun 	size_t const lowBits = BIT_readBitsFast(bitD, nbBits);
523*4882a593Smuzhiyun 
524*4882a593Smuzhiyun 	DStatePtr->state = DInfo.newState + lowBits;
525*4882a593Smuzhiyun 	return symbol;
526*4882a593Smuzhiyun }
527*4882a593Smuzhiyun 
FSE_endOfDState(const FSE_DState_t * DStatePtr)528*4882a593Smuzhiyun ZSTD_STATIC unsigned FSE_endOfDState(const FSE_DState_t *DStatePtr) { return DStatePtr->state == 0; }
529*4882a593Smuzhiyun 
530*4882a593Smuzhiyun /* **************************************************************
531*4882a593Smuzhiyun *  Tuning parameters
532*4882a593Smuzhiyun ****************************************************************/
533*4882a593Smuzhiyun /*!MEMORY_USAGE :
534*4882a593Smuzhiyun *  Memory usage formula : N->2^N Bytes (examples : 10 -> 1KB; 12 -> 4KB ; 16 -> 64KB; 20 -> 1MB; etc.)
535*4882a593Smuzhiyun *  Increasing memory usage improves compression ratio
536*4882a593Smuzhiyun *  Reduced memory usage can improve speed, due to cache effect
537*4882a593Smuzhiyun *  Recommended max value is 14, for 16KB, which nicely fits into Intel x86 L1 cache */
538*4882a593Smuzhiyun #ifndef FSE_MAX_MEMORY_USAGE
539*4882a593Smuzhiyun #define FSE_MAX_MEMORY_USAGE 14
540*4882a593Smuzhiyun #endif
541*4882a593Smuzhiyun #ifndef FSE_DEFAULT_MEMORY_USAGE
542*4882a593Smuzhiyun #define FSE_DEFAULT_MEMORY_USAGE 13
543*4882a593Smuzhiyun #endif
544*4882a593Smuzhiyun 
545*4882a593Smuzhiyun /*!FSE_MAX_SYMBOL_VALUE :
546*4882a593Smuzhiyun *  Maximum symbol value authorized.
547*4882a593Smuzhiyun *  Required for proper stack allocation */
548*4882a593Smuzhiyun #ifndef FSE_MAX_SYMBOL_VALUE
549*4882a593Smuzhiyun #define FSE_MAX_SYMBOL_VALUE 255
550*4882a593Smuzhiyun #endif
551*4882a593Smuzhiyun 
552*4882a593Smuzhiyun /* **************************************************************
553*4882a593Smuzhiyun *  template functions type & suffix
554*4882a593Smuzhiyun ****************************************************************/
555*4882a593Smuzhiyun #define FSE_FUNCTION_TYPE BYTE
556*4882a593Smuzhiyun #define FSE_FUNCTION_EXTENSION
557*4882a593Smuzhiyun #define FSE_DECODE_TYPE FSE_decode_t
558*4882a593Smuzhiyun 
559*4882a593Smuzhiyun /* ***************************************************************
560*4882a593Smuzhiyun *  Constants
561*4882a593Smuzhiyun *****************************************************************/
562*4882a593Smuzhiyun #define FSE_MAX_TABLELOG (FSE_MAX_MEMORY_USAGE - 2)
563*4882a593Smuzhiyun #define FSE_MAX_TABLESIZE (1U << FSE_MAX_TABLELOG)
564*4882a593Smuzhiyun #define FSE_MAXTABLESIZE_MASK (FSE_MAX_TABLESIZE - 1)
565*4882a593Smuzhiyun #define FSE_DEFAULT_TABLELOG (FSE_DEFAULT_MEMORY_USAGE - 2)
566*4882a593Smuzhiyun #define FSE_MIN_TABLELOG 5
567*4882a593Smuzhiyun 
568*4882a593Smuzhiyun #define FSE_TABLELOG_ABSOLUTE_MAX 15
569*4882a593Smuzhiyun #if FSE_MAX_TABLELOG > FSE_TABLELOG_ABSOLUTE_MAX
570*4882a593Smuzhiyun #error "FSE_MAX_TABLELOG > FSE_TABLELOG_ABSOLUTE_MAX is not supported"
571*4882a593Smuzhiyun #endif
572*4882a593Smuzhiyun 
573*4882a593Smuzhiyun #define FSE_TABLESTEP(tableSize) ((tableSize >> 1) + (tableSize >> 3) + 3)
574*4882a593Smuzhiyun 
575*4882a593Smuzhiyun #endif /* FSE_H */
576