comparison contrib/python-zstandard/zstd/common/fse.h @ 30822:b54a2984cdd4

zstd: vendor python-zstandard 0.6.0 Commit 63c68d6f5fc8de4afd9bde81b13b537beb4e47e8 from https://github.com/indygreg/python-zstandard is imported without modifications (other than removing unwanted files). This includes minor performance and feature improvements. It also changes the vendored zstd library from 1.1.1 to 1.1.2. # no-check-commit
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 14 Jan 2017 19:41:43 -0800
parents 2e484bdea8c4
children b1fb341d8a61
comparison
equal deleted inserted replaced
30821:7005c03f7387 30822:b54a2984cdd4
284 /* FSE buffer bounds */ 284 /* FSE buffer bounds */
285 #define FSE_NCOUNTBOUND 512 285 #define FSE_NCOUNTBOUND 512
286 #define FSE_BLOCKBOUND(size) (size + (size>>7)) 286 #define FSE_BLOCKBOUND(size) (size + (size>>7))
287 #define FSE_COMPRESSBOUND(size) (FSE_NCOUNTBOUND + FSE_BLOCKBOUND(size)) /* Macro version, useful for static allocation */ 287 #define FSE_COMPRESSBOUND(size) (FSE_NCOUNTBOUND + FSE_BLOCKBOUND(size)) /* Macro version, useful for static allocation */
288 288
289 /* It is possible to statically allocate FSE CTable/DTable as a table of unsigned using below macros */ 289 /* It is possible to statically allocate FSE CTable/DTable as a table of FSE_CTable/FSE_DTable using below macros */
290 #define FSE_CTABLE_SIZE_U32(maxTableLog, maxSymbolValue) (1 + (1<<(maxTableLog-1)) + ((maxSymbolValue+1)*2)) 290 #define FSE_CTABLE_SIZE_U32(maxTableLog, maxSymbolValue) (1 + (1<<(maxTableLog-1)) + ((maxSymbolValue+1)*2))
291 #define FSE_DTABLE_SIZE_U32(maxTableLog) (1 + (1<<maxTableLog)) 291 #define FSE_DTABLE_SIZE_U32(maxTableLog) (1 + (1<<maxTableLog))
292 292
293 293
294 /* ***************************************** 294 /* *****************************************
295 * FSE advanced API 295 * FSE advanced API
296 *******************************************/ 296 *******************************************/
297 /* FSE_count_wksp() :
298 * Same as FSE_count(), but using an externally provided scratch buffer.
299 * `workSpace` size must be table of >= `1024` unsigned
300 */
301 size_t FSE_count_wksp(unsigned* count, unsigned* maxSymbolValuePtr,
302 const void* source, size_t sourceSize, unsigned* workSpace);
303
304 /** FSE_countFast() :
305 * same as FSE_count(), but blindly trusts that all byte values within src are <= *maxSymbolValuePtr
306 */
297 size_t FSE_countFast(unsigned* count, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize); 307 size_t FSE_countFast(unsigned* count, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize);
298 /**< same as FSE_count(), but blindly trusts that all byte values within src are <= *maxSymbolValuePtr */ 308
309 /* FSE_countFast_wksp() :
310 * Same as FSE_countFast(), but using an externally provided scratch buffer.
311 * `workSpace` must be a table of minimum `1024` unsigned
312 */
313 size_t FSE_countFast_wksp(unsigned* count, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize, unsigned* workSpace);
314
315 /*! FSE_count_simple
316 * Same as FSE_countFast(), but does not use any additional memory (not even on stack).
317 * This function is unsafe, and will segfault if any value within `src` is `> *maxSymbolValuePtr` (presuming it's also the size of `count`).
318 */
319 size_t FSE_count_simple(unsigned* count, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize);
320
321
299 322
300 unsigned FSE_optimalTableLog_internal(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue, unsigned minus); 323 unsigned FSE_optimalTableLog_internal(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue, unsigned minus);
301 /**< same as FSE_optimalTableLog(), which used `minus==2` */ 324 /**< same as FSE_optimalTableLog(), which used `minus==2` */
302 325
326 /* FSE_compress_wksp() :
327 * Same as FSE_compress2(), but using an externally allocated scratch buffer (`workSpace`).
328 * FSE_WKSP_SIZE_U32() provides the minimum size required for `workSpace` as a table of FSE_CTable.
329 */
330 #define FSE_WKSP_SIZE_U32(maxTableLog, maxSymbolValue) ( FSE_CTABLE_SIZE_U32(maxTableLog, maxSymbolValue) + (1<<((maxTableLog>2)?(maxTableLog-2):0)) )
331 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);
332
303 size_t FSE_buildCTable_raw (FSE_CTable* ct, unsigned nbBits); 333 size_t FSE_buildCTable_raw (FSE_CTable* ct, unsigned nbBits);
304 /**< build a fake FSE_CTable, designed to not compress an input, where each symbol uses nbBits */ 334 /**< build a fake FSE_CTable, designed for a flat distribution, where each symbol uses nbBits */
305 335
306 size_t FSE_buildCTable_rle (FSE_CTable* ct, unsigned char symbolValue); 336 size_t FSE_buildCTable_rle (FSE_CTable* ct, unsigned char symbolValue);
307 /**< build a fake FSE_CTable, designed to compress always the same symbolValue */ 337 /**< build a fake FSE_CTable, designed to compress always the same symbolValue */
308 338
339 /* FSE_buildCTable_wksp() :
340 * Same as FSE_buildCTable(), but using an externally allocated scratch buffer (`workSpace`).
341 * `wkspSize` must be >= `(1<<tableLog)`.
342 */
343 size_t FSE_buildCTable_wksp(FSE_CTable* ct, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize);
344
309 size_t FSE_buildDTable_raw (FSE_DTable* dt, unsigned nbBits); 345 size_t FSE_buildDTable_raw (FSE_DTable* dt, unsigned nbBits);
310 /**< build a fake FSE_DTable, designed to read an uncompressed bitstream where each symbol uses nbBits */ 346 /**< build a fake FSE_DTable, designed to read a flat distribution where each symbol uses nbBits */
311 347
312 size_t FSE_buildDTable_rle (FSE_DTable* dt, unsigned char symbolValue); 348 size_t FSE_buildDTable_rle (FSE_DTable* dt, unsigned char symbolValue);
313 /**< build a fake FSE_DTable, designed to always generate the same symbolValue */ 349 /**< build a fake FSE_DTable, designed to always generate the same symbolValue */
350
351 size_t FSE_decompress_wksp(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, FSE_DTable* workSpace, unsigned maxLog);
352 /**< same as FSE_decompress(), using an externally allocated `workSpace` produced with `FSE_DTABLE_SIZE_U32(maxLog)` */
314 353
315 354
316 /* ***************************************** 355 /* *****************************************
317 * FSE symbol compression API 356 * FSE symbol compression API
318 *******************************************/ 357 *******************************************/
319 /*! 358 /*!
320 This API consists of small unitary functions, which highly benefit from being inlined. 359 This API consists of small unitary functions, which highly benefit from being inlined.
321 You will want to enable link-time-optimization to ensure these functions are properly inlined in your binary. 360 Hence their body are included in next section.
322 Visual seems to do it automatically. 361 */
323 For gcc or clang, you'll need to add -flto flag at compilation and linking stages. 362 typedef struct {
324 If none of these solutions is applicable, include "fse.c" directly.
325 */
326 typedef struct
327 {
328 ptrdiff_t value; 363 ptrdiff_t value;
329 const void* stateTable; 364 const void* stateTable;
330 const void* symbolTT; 365 const void* symbolTT;
331 unsigned stateLog; 366 unsigned stateLog;
332 } FSE_CState_t; 367 } FSE_CState_t;
382 417
383 418
384 /* ***************************************** 419 /* *****************************************
385 * FSE symbol decompression API 420 * FSE symbol decompression API
386 *******************************************/ 421 *******************************************/
387 typedef struct 422 typedef struct {
388 {
389 size_t state; 423 size_t state;
390 const void* table; /* precise table may vary, depending on U16 */ 424 const void* table; /* precise table may vary, depending on U16 */
391 } FSE_DState_t; 425 } FSE_DState_t;
392 426
393 427