ReactOS 0.4.16-dev-117-g38f21f9
huf_decompress.c File Reference
#include <string.h>
#include "compiler.h"
#include "bitstream.h"
#include "fse.h"
#include "huf.h"
#include "error_private.h"
Include dependency graph for huf_decompress.c:

Go to the source code of this file.

Classes

struct  DTableDesc
 
struct  HUF_DEltX1
 
struct  HUF_DEltX2
 
struct  sortedSymbol_t
 
struct  algo_time_t
 

Macros

#define HUF_STATIC_LINKING_ONLY
 
#define HUF_isError   ERR_isError
 
#define HUF_ALIGN(x, a)   HUF_ALIGN_MASK((x), (a) - 1)
 
#define HUF_ALIGN_MASK(x, mask)   (((x) + (mask)) & ~(mask))
 
#define HUF_DGEN(fn)
 
#define HUF_DECODE_SYMBOLX1_0(ptr, DStreamPtr)    *ptr++ = HUF_decodeSymbolX1(DStreamPtr, dt, dtLog)
 
#define HUF_DECODE_SYMBOLX1_1(ptr, DStreamPtr)
 
#define HUF_DECODE_SYMBOLX1_2(ptr, DStreamPtr)
 
#define HUF_DECODE_SYMBOLX2_0(ptr, DStreamPtr)    ptr += HUF_decodeSymbolX2(ptr, DStreamPtr, dt, dtLog)
 
#define HUF_DECODE_SYMBOLX2_1(ptr, DStreamPtr)
 
#define HUF_DECODE_SYMBOLX2_2(ptr, DStreamPtr)
 

Typedefs

typedef size_t(* HUF_decompress_usingDTable_t) (void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, const HUF_DTable *DTable)
 
typedef U32 rankValCol_t[HUF_TABLELOG_MAX+1]
 
typedef rankValCol_t rankVal_t[HUF_TABLELOG_MAX]
 
typedef size_t(* decompressionAlgo) (void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize)
 

Functions

static DTableDesc HUF_getDTableDesc (const HUF_DTable *table)
 
size_t HUF_readDTableX1_wksp (HUF_DTable *DTable, const void *src, size_t srcSize, void *workSpace, size_t wkspSize)
 
size_t HUF_readDTableX1 (HUF_DTable *DTable, const void *src, size_t srcSize)
 
FORCE_INLINE_TEMPLATE BYTE HUF_decodeSymbolX1 (BIT_DStream_t *Dstream, const HUF_DEltX1 *dt, const U32 dtLog)
 
HINT_INLINE size_t HUF_decodeStreamX1 (BYTE *p, BIT_DStream_t *const bitDPtr, BYTE *const pEnd, const HUF_DEltX1 *const dt, const U32 dtLog)
 
FORCE_INLINE_TEMPLATE size_t HUF_decompress1X1_usingDTable_internal_body (void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, const HUF_DTable *DTable)
 
FORCE_INLINE_TEMPLATE size_t HUF_decompress4X1_usingDTable_internal_body (void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, const HUF_DTable *DTable)
 
size_t HUF_decompress1X1_usingDTable (void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, const HUF_DTable *DTable)
 
size_t HUF_decompress1X1_DCtx_wksp (HUF_DTable *DCtx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, void *workSpace, size_t wkspSize)
 
size_t HUF_decompress1X1_DCtx (HUF_DTable *DCtx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize)
 
size_t HUF_decompress1X1 (void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize)
 
size_t HUF_decompress4X1_usingDTable (void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, const HUF_DTable *DTable)
 
static size_t HUF_decompress4X1_DCtx_wksp_bmi2 (HUF_DTable *dctx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, void *workSpace, size_t wkspSize, int bmi2)
 
size_t HUF_decompress4X1_DCtx_wksp (HUF_DTable *dctx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, void *workSpace, size_t wkspSize)
 
size_t HUF_decompress4X1_DCtx (HUF_DTable *dctx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize)
 
size_t HUF_decompress4X1 (void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize)
 
static void HUF_fillDTableX2Level2 (HUF_DEltX2 *DTable, U32 sizeLog, const U32 consumed, const U32 *rankValOrigin, const int minWeight, const sortedSymbol_t *sortedSymbols, const U32 sortedListSize, U32 nbBitsBaseline, U16 baseSeq)
 
static void HUF_fillDTableX2 (HUF_DEltX2 *DTable, const U32 targetLog, const sortedSymbol_t *sortedList, const U32 sortedListSize, const U32 *rankStart, rankVal_t rankValOrigin, const U32 maxWeight, const U32 nbBitsBaseline)
 
size_t HUF_readDTableX2_wksp (HUF_DTable *DTable, const void *src, size_t srcSize, void *workSpace, size_t wkspSize)
 
size_t HUF_readDTableX2 (HUF_DTable *DTable, const void *src, size_t srcSize)
 
FORCE_INLINE_TEMPLATE U32 HUF_decodeSymbolX2 (void *op, BIT_DStream_t *DStream, const HUF_DEltX2 *dt, const U32 dtLog)
 
FORCE_INLINE_TEMPLATE U32 HUF_decodeLastSymbolX2 (void *op, BIT_DStream_t *DStream, const HUF_DEltX2 *dt, const U32 dtLog)
 
HINT_INLINE size_t HUF_decodeStreamX2 (BYTE *p, BIT_DStream_t *bitDPtr, BYTE *const pEnd, const HUF_DEltX2 *const dt, const U32 dtLog)
 
FORCE_INLINE_TEMPLATE size_t HUF_decompress1X2_usingDTable_internal_body (void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, const HUF_DTable *DTable)
 
FORCE_INLINE_TEMPLATE size_t HUF_decompress4X2_usingDTable_internal_body (void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, const HUF_DTable *DTable)
 
size_t HUF_decompress1X2_usingDTable (void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, const HUF_DTable *DTable)
 
size_t HUF_decompress1X2_DCtx_wksp (HUF_DTable *DCtx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, void *workSpace, size_t wkspSize)
 
size_t HUF_decompress1X2_DCtx (HUF_DTable *DCtx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize)
 
size_t HUF_decompress1X2 (void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize)
 
size_t HUF_decompress4X2_usingDTable (void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, const HUF_DTable *DTable)
 
static size_t HUF_decompress4X2_DCtx_wksp_bmi2 (HUF_DTable *dctx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, void *workSpace, size_t wkspSize, int bmi2)
 
size_t HUF_decompress4X2_DCtx_wksp (HUF_DTable *dctx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, void *workSpace, size_t wkspSize)
 
size_t HUF_decompress4X2_DCtx (HUF_DTable *dctx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize)
 
size_t HUF_decompress4X2 (void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize)
 
size_t HUF_decompress1X_usingDTable (void *dst, size_t maxDstSize, const void *cSrc, size_t cSrcSize, const HUF_DTable *DTable)
 
size_t HUF_decompress4X_usingDTable (void *dst, size_t maxDstSize, const void *cSrc, size_t cSrcSize, const HUF_DTable *DTable)
 
U32 HUF_selectDecoder (size_t dstSize, size_t cSrcSize)
 
size_t HUF_decompress (void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize)
 
size_t HUF_decompress4X_DCtx (HUF_DTable *dctx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize)
 
size_t HUF_decompress4X_hufOnly (HUF_DTable *dctx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize)
 
size_t HUF_decompress4X_hufOnly_wksp (HUF_DTable *dctx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, void *workSpace, size_t wkspSize)
 
size_t HUF_decompress1X_DCtx_wksp (HUF_DTable *dctx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, void *workSpace, size_t wkspSize)
 
size_t HUF_decompress1X_DCtx (HUF_DTable *dctx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize)
 
size_t HUF_decompress1X_usingDTable_bmi2 (void *dst, size_t maxDstSize, const void *cSrc, size_t cSrcSize, const HUF_DTable *DTable, int bmi2)
 
size_t HUF_decompress1X1_DCtx_wksp_bmi2 (HUF_DTable *dctx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, void *workSpace, size_t wkspSize, int bmi2)
 
size_t HUF_decompress4X_usingDTable_bmi2 (void *dst, size_t maxDstSize, const void *cSrc, size_t cSrcSize, const HUF_DTable *DTable, int bmi2)
 
size_t HUF_decompress4X_hufOnly_wksp_bmi2 (HUF_DTable *dctx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, void *workSpace, size_t wkspSize, int bmi2)
 

Variables

static const algo_time_t algoTime [16][3]
 

Macro Definition Documentation

◆ HUF_ALIGN

#define HUF_ALIGN (   x,
  a 
)    HUF_ALIGN_MASK((x), (a) - 1)

Definition at line 49 of file huf_decompress.c.

◆ HUF_ALIGN_MASK

#define HUF_ALIGN_MASK (   x,
  mask 
)    (((x) + (mask)) & ~(mask))

Definition at line 50 of file huf_decompress.c.

◆ HUF_DECODE_SYMBOLX1_0

#define HUF_DECODE_SYMBOLX1_0 (   ptr,
  DStreamPtr 
)     *ptr++ = HUF_decodeSymbolX1(DStreamPtr, dt, dtLog)

Definition at line 203 of file huf_decompress.c.

◆ HUF_DECODE_SYMBOLX1_1

#define HUF_DECODE_SYMBOLX1_1 (   ptr,
  DStreamPtr 
)
Value:
if (MEM_64bits() || (HUF_TABLELOG_MAX<=12)) \
HUF_DECODE_SYMBOLX1_0(ptr, DStreamPtr)
MEM_STATIC unsigned MEM_64bits(void)
Definition: mem.h:184
static PVOID ptr
Definition: dispmode.c:27

Definition at line 206 of file huf_decompress.c.

◆ HUF_DECODE_SYMBOLX1_2

#define HUF_DECODE_SYMBOLX1_2 (   ptr,
  DStreamPtr 
)
Value:
if (MEM_64bits()) \
HUF_DECODE_SYMBOLX1_0(ptr, DStreamPtr)

Definition at line 210 of file huf_decompress.c.

◆ HUF_DECODE_SYMBOLX2_0

#define HUF_DECODE_SYMBOLX2_0 (   ptr,
  DStreamPtr 
)     ptr += HUF_decodeSymbolX2(ptr, DStreamPtr, dt, dtLog)

Definition at line 684 of file huf_decompress.c.

◆ HUF_DECODE_SYMBOLX2_1

#define HUF_DECODE_SYMBOLX2_1 (   ptr,
  DStreamPtr 
)
Value:
if (MEM_64bits() || (HUF_TABLELOG_MAX<=12)) \
ptr += HUF_decodeSymbolX2(ptr, DStreamPtr, dt, dtLog)
FORCE_INLINE_TEMPLATE U32 HUF_decodeSymbolX2(void *op, BIT_DStream_t *DStream, const HUF_DEltX2 *dt, const U32 dtLog)

Definition at line 687 of file huf_decompress.c.

◆ HUF_DECODE_SYMBOLX2_2

#define HUF_DECODE_SYMBOLX2_2 (   ptr,
  DStreamPtr 
)
Value:
if (MEM_64bits()) \
ptr += HUF_decodeSymbolX2(ptr, DStreamPtr, dt, dtLog)

Definition at line 691 of file huf_decompress.c.

◆ HUF_DGEN

#define HUF_DGEN (   fn)
Value:
static size_t fn(void* dst, size_t dstSize, void const* cSrc, \
size_t cSrcSize, HUF_DTable const* DTable, int bmi2) \
{ \
(void)bmi2; \
return fn##_body(dst, dstSize, cSrc, cSrcSize, DTable); \
}
GLenum GLenum dst
Definition: glext.h:6340
static GLenum _GLUfuncptr fn
Definition: wgl_font.c:159

Definition at line 87 of file huf_decompress.c.

◆ HUF_isError

#define HUF_isError   ERR_isError

Definition at line 43 of file huf_decompress.c.

◆ HUF_STATIC_LINKING_ONLY

#define HUF_STATIC_LINKING_ONLY

Definition at line 22 of file huf_decompress.c.

Typedef Documentation

◆ decompressionAlgo

typedef size_t(* decompressionAlgo) (void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize)

Definition at line 1054 of file huf_decompress.c.

◆ HUF_decompress_usingDTable_t

typedef size_t(* HUF_decompress_usingDTable_t) (void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, const HUF_DTable *DTable)

Definition at line 357 of file huf_decompress.c.

◆ rankVal_t

typedef rankValCol_t rankVal_t[HUF_TABLELOG_MAX]

Definition at line 463 of file huf_decompress.c.

◆ rankValCol_t

typedef U32 rankValCol_t[HUF_TABLELOG_MAX+1]

Definition at line 462 of file huf_decompress.c.

Function Documentation

◆ HUF_decodeLastSymbolX2()

FORCE_INLINE_TEMPLATE U32 HUF_decodeLastSymbolX2 ( void op,
BIT_DStream_t DStream,
const HUF_DEltX2 dt,
const U32  dtLog 
)

Definition at line 669 of file huf_decompress.c.

670{
671 size_t const val = BIT_lookBitsFast(DStream, dtLog); /* note : dtLog >= 1 */
672 memcpy(op, dt+val, 1);
673 if (dt[val].length==1) BIT_skipBits(DStream, dt[val].nbBits);
674 else {
675 if (DStream->bitsConsumed < (sizeof(DStream->bitContainer)*8)) {
676 BIT_skipBits(DStream, dt[val].nbBits);
677 if (DStream->bitsConsumed > (sizeof(DStream->bitContainer)*8))
678 /* ugly hack; works only because it's the last symbol. Note : can't easily extract nbBits from just this symbol */
679 DStream->bitsConsumed = (sizeof(DStream->bitContainer)*8);
680 } }
681 return 1;
682}
MEM_STATIC void BIT_skipBits(BIT_DStream_t *bitD, U32 nbBits)
Definition: bitstream.h:368
MEM_STATIC size_t BIT_lookBitsFast(const BIT_DStream_t *bitD, U32 nbBits)
Definition: bitstream.h:361
UINT op
Definition: effect.c:236
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLuint GLfloat * val
Definition: glext.h:7180
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned bitsConsumed
Definition: bitstream.h:93
size_t bitContainer
Definition: bitstream.h:92

Referenced by HUF_decodeStreamX2().

◆ HUF_decodeStreamX1()

HINT_INLINE size_t HUF_decodeStreamX1 ( BYTE p,
BIT_DStream_t *const  bitDPtr,
BYTE *const  pEnd,
const HUF_DEltX1 *const  dt,
const U32  dtLog 
)

Definition at line 215 of file huf_decompress.c.

216{
217 BYTE* const pStart = p;
218
219 /* up to 4 symbols at a time */
220 while ((BIT_reloadDStream(bitDPtr) == BIT_DStream_unfinished) & (p < pEnd-3)) {
221 HUF_DECODE_SYMBOLX1_2(p, bitDPtr);
222 HUF_DECODE_SYMBOLX1_1(p, bitDPtr);
223 HUF_DECODE_SYMBOLX1_2(p, bitDPtr);
224 HUF_DECODE_SYMBOLX1_0(p, bitDPtr);
225 }
226
227 /* [0-3] symbols remaining */
228 if (MEM_32bits())
229 while ((BIT_reloadDStream(bitDPtr) == BIT_DStream_unfinished) & (p < pEnd))
230 HUF_DECODE_SYMBOLX1_0(p, bitDPtr);
231
232 /* no more data to retrieve from bitstream, no need to reload */
233 while (p < pEnd)
234 HUF_DECODE_SYMBOLX1_0(p, bitDPtr);
235
236 return pEnd-pStart;
237}
MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t *bitD)
Definition: bitstream.h:416
@ BIT_DStream_unfinished
Definition: bitstream.h:99
MEM_STATIC unsigned MEM_32bits(void)
Definition: mem.h:183
GLfloat GLfloat p
Definition: glext.h:8902
#define HUF_DECODE_SYMBOLX1_2(ptr, DStreamPtr)
#define HUF_DECODE_SYMBOLX1_1(ptr, DStreamPtr)
#define HUF_DECODE_SYMBOLX1_0(ptr, DStreamPtr)
unsigned char BYTE
Definition: xxhash.c:193

Referenced by HUF_decompress1X1_usingDTable_internal_body(), and HUF_decompress4X1_usingDTable_internal_body().

◆ HUF_decodeStreamX2()

HINT_INLINE size_t HUF_decodeStreamX2 ( BYTE p,
BIT_DStream_t bitDPtr,
BYTE *const  pEnd,
const HUF_DEltX2 *const  dt,
const U32  dtLog 
)

Definition at line 696 of file huf_decompress.c.

698{
699 BYTE* const pStart = p;
700
701 /* up to 8 symbols at a time */
702 while ((BIT_reloadDStream(bitDPtr) == BIT_DStream_unfinished) & (p < pEnd-(sizeof(bitDPtr->bitContainer)-1))) {
703 HUF_DECODE_SYMBOLX2_2(p, bitDPtr);
704 HUF_DECODE_SYMBOLX2_1(p, bitDPtr);
705 HUF_DECODE_SYMBOLX2_2(p, bitDPtr);
706 HUF_DECODE_SYMBOLX2_0(p, bitDPtr);
707 }
708
709 /* closer to end : up to 2 symbols at a time */
710 while ((BIT_reloadDStream(bitDPtr) == BIT_DStream_unfinished) & (p <= pEnd-2))
711 HUF_DECODE_SYMBOLX2_0(p, bitDPtr);
712
713 while (p <= pEnd-2)
714 HUF_DECODE_SYMBOLX2_0(p, bitDPtr); /* no need to reload : reached the end of DStream */
715
716 if (p < pEnd)
717 p += HUF_decodeLastSymbolX2(p, bitDPtr, dt, dtLog);
718
719 return p-pStart;
720}
#define HUF_DECODE_SYMBOLX2_1(ptr, DStreamPtr)
#define HUF_DECODE_SYMBOLX2_0(ptr, DStreamPtr)
#define HUF_DECODE_SYMBOLX2_2(ptr, DStreamPtr)
FORCE_INLINE_TEMPLATE U32 HUF_decodeLastSymbolX2(void *op, BIT_DStream_t *DStream, const HUF_DEltX2 *dt, const U32 dtLog)

Referenced by HUF_decompress1X2_usingDTable_internal_body(), and HUF_decompress4X2_usingDTable_internal_body().

◆ HUF_decodeSymbolX1()

FORCE_INLINE_TEMPLATE BYTE HUF_decodeSymbolX1 ( BIT_DStream_t Dstream,
const HUF_DEltX1 dt,
const U32  dtLog 
)

Definition at line 195 of file huf_decompress.c.

196{
197 size_t const val = BIT_lookBitsFast(Dstream, dtLog); /* note : dtLog >= 1 */
198 BYTE const c = dt[val].byte;
199 BIT_skipBits(Dstream, dt[val].nbBits);
200 return c;
201}
const GLubyte * c
Definition: glext.h:8905
#define c
Definition: ke_i.h:80

◆ HUF_decodeSymbolX2()

FORCE_INLINE_TEMPLATE U32 HUF_decodeSymbolX2 ( void op,
BIT_DStream_t DStream,
const HUF_DEltX2 dt,
const U32  dtLog 
)

Definition at line 660 of file huf_decompress.c.

661{
662 size_t const val = BIT_lookBitsFast(DStream, dtLog); /* note : dtLog >= 1 */
663 memcpy(op, dt+val, 2);
664 BIT_skipBits(DStream, dt[val].nbBits);
665 return dt[val].length;
666}

◆ HUF_decompress()

size_t HUF_decompress ( void dst,
size_t  originalSize,
const void cSrc,
size_t  cSrcSize 
)

HUF_decompress() : Decompress HUF data from buffer 'cSrc', of size 'cSrcSize', into already allocated buffer 'dst', of minimum size 'dstSize'. originalSize : must be the exact size of original (uncompressed) data. Note : in contrast with FSE, HUF_decompress can regenerate RLE (cSrcSize==1) and uncompressed (cSrcSize==dstSize) data, because it knows size to regenerate (originalSize).

Returns
: size of regenerated data (== originalSize), or an error code, which can be tested using HUF_isError()

Definition at line 1056 of file huf_decompress.c.

1057{
1058#if !defined(HUF_FORCE_DECOMPRESS_X1) && !defined(HUF_FORCE_DECOMPRESS_X2)
1059 static const decompressionAlgo decompress[2] = { HUF_decompress4X1, HUF_decompress4X2 };
1060#endif
1061
1062 /* validation checks */
1063 if (dstSize == 0) return ERROR(dstSize_tooSmall);
1064 if (cSrcSize > dstSize) return ERROR(corruption_detected); /* invalid */
1065 if (cSrcSize == dstSize) { memcpy(dst, cSrc, dstSize); return dstSize; } /* not compressed */
1066 if (cSrcSize == 1) { memset(dst, *(const BYTE*)cSrc, dstSize); return dstSize; } /* RLE */
1067
1068 { U32 const algoNb = HUF_selectDecoder(dstSize, cSrcSize);
1069#if defined(HUF_FORCE_DECOMPRESS_X1)
1070 (void)algoNb;
1071 assert(algoNb == 0);
1072 return HUF_decompress4X1(dst, dstSize, cSrc, cSrcSize);
1073#elif defined(HUF_FORCE_DECOMPRESS_X2)
1074 (void)algoNb;
1075 assert(algoNb == 1);
1076 return HUF_decompress4X2(dst, dstSize, cSrc, cSrcSize);
1077#else
1078 return decompress[algoNb](dst, dstSize, cSrc, cSrcSize);
1079#endif
1080 }
1081}
#define assert(x)
Definition: debug.h:53
#define ERROR(name)
Definition: error_private.h:53
U32 HUF_selectDecoder(size_t dstSize, size_t cSrcSize)
size_t HUF_decompress4X2(void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize)
size_t HUF_decompress4X1(void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize)
size_t(* decompressionAlgo)(void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize)
#define memset(x, y, z)
Definition: compat.h:39
unsigned int U32
Definition: xxhash.c:195

◆ HUF_decompress1X1()

size_t HUF_decompress1X1 ( void dst,
size_t  dstSize,
const void cSrc,
size_t  cSrcSize 
)

Definition at line 400 of file huf_decompress.c.

401{
402 HUF_CREATE_STATIC_DTABLEX1(DTable, HUF_TABLELOG_MAX);
403 return HUF_decompress1X1_DCtx (DTable, dst, dstSize, cSrc, cSrcSize);
404}
size_t HUF_decompress1X1_DCtx(HUF_DTable *DCtx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize)

◆ HUF_decompress1X1_DCtx()

size_t HUF_decompress1X1_DCtx ( HUF_DTable *  DCtx,
void dst,
size_t  dstSize,
const void cSrc,
size_t  cSrcSize 
)

Definition at line 392 of file huf_decompress.c.

394{
395 U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32];
396 return HUF_decompress1X1_DCtx_wksp(DCtx, dst, dstSize, cSrc, cSrcSize,
397 workSpace, sizeof(workSpace));
398}
size_t HUF_decompress1X1_DCtx_wksp(HUF_DTable *DCtx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, void *workSpace, size_t wkspSize)

Referenced by HUF_decompress1X1().

◆ HUF_decompress1X1_DCtx_wksp()

size_t HUF_decompress1X1_DCtx_wksp ( HUF_DTable *  DCtx,
void dst,
size_t  dstSize,
const void cSrc,
size_t  cSrcSize,
void workSpace,
size_t  wkspSize 
)

Definition at line 377 of file huf_decompress.c.

380{
381 const BYTE* ip = (const BYTE*) cSrc;
382
383 size_t const hSize = HUF_readDTableX1_wksp(DCtx, cSrc, cSrcSize, workSpace, wkspSize);
384 if (HUF_isError(hSize)) return hSize;
385 if (hSize >= cSrcSize) return ERROR(srcSize_wrong);
386 ip += hSize; cSrcSize -= hSize;
387
388 return HUF_decompress1X1_usingDTable_internal(dst, dstSize, ip, cSrcSize, DCtx, /* bmi2 */ 0);
389}
size_t HUF_readDTableX1_wksp(HUF_DTable *DTable, const void *src, size_t srcSize, void *workSpace, size_t wkspSize)
#define HUF_isError
Definition: dhcpd.h:62

Referenced by HUF_decompress1X1_DCtx(), and HUF_decompress1X_DCtx_wksp().

◆ HUF_decompress1X1_DCtx_wksp_bmi2()

size_t HUF_decompress1X1_DCtx_wksp_bmi2 ( HUF_DTable *  dctx,
void dst,
size_t  dstSize,
const void cSrc,
size_t  cSrcSize,
void workSpace,
size_t  wkspSize,
int  bmi2 
)

Definition at line 1198 of file huf_decompress.c.

1199{
1200 const BYTE* ip = (const BYTE*) cSrc;
1201
1202 size_t const hSize = HUF_readDTableX1_wksp(dctx, cSrc, cSrcSize, workSpace, wkspSize);
1203 if (HUF_isError(hSize)) return hSize;
1204 if (hSize >= cSrcSize) return ERROR(srcSize_wrong);
1205 ip += hSize; cSrcSize -= hSize;
1206
1207 return HUF_decompress1X1_usingDTable_internal(dst, dstSize, ip, cSrcSize, dctx, bmi2);
1208}

◆ HUF_decompress1X1_usingDTable()

size_t HUF_decompress1X1_usingDTable ( void dst,
size_t  dstSize,
const void cSrc,
size_t  cSrcSize,
const HUF_DTable *  DTable 
)

Definition at line 367 of file huf_decompress.c.

371{
372 DTableDesc dtd = HUF_getDTableDesc(DTable);
373 if (dtd.tableType != 0) return ERROR(GENERIC);
374 return HUF_decompress1X1_usingDTable_internal(dst, dstSize, cSrc, cSrcSize, DTable, /* bmi2 */ 0);
375}
static DTableDesc HUF_getDTableDesc(const HUF_DTable *table)

◆ HUF_decompress1X1_usingDTable_internal_body()

FORCE_INLINE_TEMPLATE size_t HUF_decompress1X1_usingDTable_internal_body ( void dst,
size_t  dstSize,
const void cSrc,
size_t  cSrcSize,
const HUF_DTable *  DTable 
)

Definition at line 240 of file huf_decompress.c.

244{
245 BYTE* op = (BYTE*)dst;
246 BYTE* const oend = op + dstSize;
247 const void* dtPtr = DTable + 1;
248 const HUF_DEltX1* const dt = (const HUF_DEltX1*)dtPtr;
249 BIT_DStream_t bitD;
250 DTableDesc const dtd = HUF_getDTableDesc(DTable);
251 U32 const dtLog = dtd.tableLog;
252
253 CHECK_F( BIT_initDStream(&bitD, cSrc, cSrcSize) );
254
255 HUF_decodeStreamX1(op, &bitD, oend, dt, dtLog);
256
257 if (!BIT_endOfDStream(&bitD)) return ERROR(corruption_detected);
258
259 return dstSize;
260}
MEM_STATIC size_t BIT_initDStream(BIT_DStream_t *bitD, const void *srcBuffer, size_t srcSize)
Definition: bitstream.h:272
MEM_STATIC unsigned BIT_endOfDStream(const BIT_DStream_t *bitD)
Definition: bitstream.h:445
#define CHECK_F(f)
Definition: error_private.h:62
HINT_INLINE size_t HUF_decodeStreamX1(BYTE *p, BIT_DStream_t *const bitDPtr, BYTE *const pEnd, const HUF_DEltX1 *const dt, const U32 dtLog)

◆ HUF_decompress1X2()

size_t HUF_decompress1X2 ( void dst,
size_t  dstSize,
const void cSrc,
size_t  cSrcSize 
)

Definition at line 901 of file huf_decompress.c.

902{
903 HUF_CREATE_STATIC_DTABLEX2(DTable, HUF_TABLELOG_MAX);
904 return HUF_decompress1X2_DCtx(DTable, dst, dstSize, cSrc, cSrcSize);
905}
size_t HUF_decompress1X2_DCtx(HUF_DTable *DCtx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize)

◆ HUF_decompress1X2_DCtx()

size_t HUF_decompress1X2_DCtx ( HUF_DTable *  DCtx,
void dst,
size_t  dstSize,
const void cSrc,
size_t  cSrcSize 
)

Definition at line 893 of file huf_decompress.c.

895{
896 U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32];
897 return HUF_decompress1X2_DCtx_wksp(DCtx, dst, dstSize, cSrc, cSrcSize,
898 workSpace, sizeof(workSpace));
899}
size_t HUF_decompress1X2_DCtx_wksp(HUF_DTable *DCtx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, void *workSpace, size_t wkspSize)

Referenced by HUF_decompress1X2().

◆ HUF_decompress1X2_DCtx_wksp()

size_t HUF_decompress1X2_DCtx_wksp ( HUF_DTable *  DCtx,
void dst,
size_t  dstSize,
const void cSrc,
size_t  cSrcSize,
void workSpace,
size_t  wkspSize 
)

Definition at line 877 of file huf_decompress.c.

880{
881 const BYTE* ip = (const BYTE*) cSrc;
882
883 size_t const hSize = HUF_readDTableX2_wksp(DCtx, cSrc, cSrcSize,
884 workSpace, wkspSize);
885 if (HUF_isError(hSize)) return hSize;
886 if (hSize >= cSrcSize) return ERROR(srcSize_wrong);
887 ip += hSize; cSrcSize -= hSize;
888
889 return HUF_decompress1X2_usingDTable_internal(dst, dstSize, ip, cSrcSize, DCtx, /* bmi2 */ 0);
890}
size_t HUF_readDTableX2_wksp(HUF_DTable *DTable, const void *src, size_t srcSize, void *workSpace, size_t wkspSize)

Referenced by HUF_decompress1X2_DCtx(), and HUF_decompress1X_DCtx_wksp().

◆ HUF_decompress1X2_usingDTable()

size_t HUF_decompress1X2_usingDTable ( void dst,
size_t  dstSize,
const void cSrc,
size_t  cSrcSize,
const HUF_DTable *  DTable 
)

Definition at line 867 of file huf_decompress.c.

871{
872 DTableDesc dtd = HUF_getDTableDesc(DTable);
873 if (dtd.tableType != 1) return ERROR(GENERIC);
874 return HUF_decompress1X2_usingDTable_internal(dst, dstSize, cSrc, cSrcSize, DTable, /* bmi2 */ 0);
875}

◆ HUF_decompress1X2_usingDTable_internal_body()

FORCE_INLINE_TEMPLATE size_t HUF_decompress1X2_usingDTable_internal_body ( void dst,
size_t  dstSize,
const void cSrc,
size_t  cSrcSize,
const HUF_DTable *  DTable 
)

Definition at line 723 of file huf_decompress.c.

727{
728 BIT_DStream_t bitD;
729
730 /* Init */
731 CHECK_F( BIT_initDStream(&bitD, cSrc, cSrcSize) );
732
733 /* decode */
734 { BYTE* const ostart = (BYTE*) dst;
735 BYTE* const oend = ostart + dstSize;
736 const void* const dtPtr = DTable+1; /* force compiler to not use strict-aliasing */
737 const HUF_DEltX2* const dt = (const HUF_DEltX2*)dtPtr;
738 DTableDesc const dtd = HUF_getDTableDesc(DTable);
739 HUF_decodeStreamX2(ostart, &bitD, oend, dt, dtd.tableLog);
740 }
741
742 /* check */
743 if (!BIT_endOfDStream(&bitD)) return ERROR(corruption_detected);
744
745 /* decoded size */
746 return dstSize;
747}
HINT_INLINE size_t HUF_decodeStreamX2(BYTE *p, BIT_DStream_t *bitDPtr, BYTE *const pEnd, const HUF_DEltX2 *const dt, const U32 dtLog)

◆ HUF_decompress1X_DCtx()

size_t HUF_decompress1X_DCtx ( HUF_DTable *  dctx,
void dst,
size_t  dstSize,
const void cSrc,
size_t  cSrcSize 
)

Definition at line 1171 of file huf_decompress.c.

1173{
1174 U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32];
1175 return HUF_decompress1X_DCtx_wksp(dctx, dst, dstSize, cSrc, cSrcSize,
1176 workSpace, sizeof(workSpace));
1177}
size_t HUF_decompress1X_DCtx_wksp(HUF_DTable *dctx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, void *workSpace, size_t wkspSize)

◆ HUF_decompress1X_DCtx_wksp()

size_t HUF_decompress1X_DCtx_wksp ( HUF_DTable *  dctx,
void dst,
size_t  dstSize,
const void cSrc,
size_t  cSrcSize,
void workSpace,
size_t  wkspSize 
)

Definition at line 1141 of file huf_decompress.c.

1144{
1145 /* validation checks */
1146 if (dstSize == 0) return ERROR(dstSize_tooSmall);
1147 if (cSrcSize > dstSize) return ERROR(corruption_detected); /* invalid */
1148 if (cSrcSize == dstSize) { memcpy(dst, cSrc, dstSize); return dstSize; } /* not compressed */
1149 if (cSrcSize == 1) { memset(dst, *(const BYTE*)cSrc, dstSize); return dstSize; } /* RLE */
1150
1151 { U32 const algoNb = HUF_selectDecoder(dstSize, cSrcSize);
1152#if defined(HUF_FORCE_DECOMPRESS_X1)
1153 (void)algoNb;
1154 assert(algoNb == 0);
1155 return HUF_decompress1X1_DCtx_wksp(dctx, dst, dstSize, cSrc,
1156 cSrcSize, workSpace, wkspSize);
1157#elif defined(HUF_FORCE_DECOMPRESS_X2)
1158 (void)algoNb;
1159 assert(algoNb == 1);
1160 return HUF_decompress1X2_DCtx_wksp(dctx, dst, dstSize, cSrc,
1161 cSrcSize, workSpace, wkspSize);
1162#else
1163 return algoNb ? HUF_decompress1X2_DCtx_wksp(dctx, dst, dstSize, cSrc,
1164 cSrcSize, workSpace, wkspSize):
1165 HUF_decompress1X1_DCtx_wksp(dctx, dst, dstSize, cSrc,
1166 cSrcSize, workSpace, wkspSize);
1167#endif
1168 }
1169}

Referenced by HUF_decompress1X_DCtx().

◆ HUF_decompress1X_usingDTable()

size_t HUF_decompress1X_usingDTable ( void dst,
size_t  maxDstSize,
const void cSrc,
size_t  cSrcSize,
const HUF_DTable *  DTable 
)

Definition at line 961 of file huf_decompress.c.

964{
965 DTableDesc const dtd = HUF_getDTableDesc(DTable);
966#if defined(HUF_FORCE_DECOMPRESS_X1)
967 (void)dtd;
968 assert(dtd.tableType == 0);
969 return HUF_decompress1X1_usingDTable_internal(dst, maxDstSize, cSrc, cSrcSize, DTable, /* bmi2 */ 0);
970#elif defined(HUF_FORCE_DECOMPRESS_X2)
971 (void)dtd;
972 assert(dtd.tableType == 1);
973 return HUF_decompress1X2_usingDTable_internal(dst, maxDstSize, cSrc, cSrcSize, DTable, /* bmi2 */ 0);
974#else
975 return dtd.tableType ? HUF_decompress1X2_usingDTable_internal(dst, maxDstSize, cSrc, cSrcSize, DTable, /* bmi2 */ 0) :
976 HUF_decompress1X1_usingDTable_internal(dst, maxDstSize, cSrc, cSrcSize, DTable, /* bmi2 */ 0);
977#endif
978}

◆ HUF_decompress1X_usingDTable_bmi2()

size_t HUF_decompress1X_usingDTable_bmi2 ( void dst,
size_t  maxDstSize,
const void cSrc,
size_t  cSrcSize,
const HUF_DTable *  DTable,
int  bmi2 
)

Definition at line 1180 of file huf_decompress.c.

1181{
1182 DTableDesc const dtd = HUF_getDTableDesc(DTable);
1183#if defined(HUF_FORCE_DECOMPRESS_X1)
1184 (void)dtd;
1185 assert(dtd.tableType == 0);
1186 return HUF_decompress1X1_usingDTable_internal(dst, maxDstSize, cSrc, cSrcSize, DTable, bmi2);
1187#elif defined(HUF_FORCE_DECOMPRESS_X2)
1188 (void)dtd;
1189 assert(dtd.tableType == 1);
1190 return HUF_decompress1X2_usingDTable_internal(dst, maxDstSize, cSrc, cSrcSize, DTable, bmi2);
1191#else
1192 return dtd.tableType ? HUF_decompress1X2_usingDTable_internal(dst, maxDstSize, cSrc, cSrcSize, DTable, bmi2) :
1193 HUF_decompress1X1_usingDTable_internal(dst, maxDstSize, cSrc, cSrcSize, DTable, bmi2);
1194#endif
1195}

◆ HUF_decompress4X1()

size_t HUF_decompress4X1 ( void dst,
size_t  dstSize,
const void cSrc,
size_t  cSrcSize 
)

Definition at line 445 of file huf_decompress.c.

446{
447 HUF_CREATE_STATIC_DTABLEX1(DTable, HUF_TABLELOG_MAX);
448 return HUF_decompress4X1_DCtx(DTable, dst, dstSize, cSrc, cSrcSize);
449}
size_t HUF_decompress4X1_DCtx(HUF_DTable *dctx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize)

Referenced by HUF_decompress().

◆ HUF_decompress4X1_DCtx()

size_t HUF_decompress4X1_DCtx ( HUF_DTable *  dctx,
void dst,
size_t  dstSize,
const void cSrc,
size_t  cSrcSize 
)

Definition at line 439 of file huf_decompress.c.

440{
441 U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32];
442 return HUF_decompress4X1_DCtx_wksp(dctx, dst, dstSize, cSrc, cSrcSize,
443 workSpace, sizeof(workSpace));
444}
size_t HUF_decompress4X1_DCtx_wksp(HUF_DTable *dctx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, void *workSpace, size_t wkspSize)

Referenced by HUF_decompress4X1(), and HUF_decompress4X_DCtx().

◆ HUF_decompress4X1_DCtx_wksp()

size_t HUF_decompress4X1_DCtx_wksp ( HUF_DTable *  dctx,
void dst,
size_t  dstSize,
const void cSrc,
size_t  cSrcSize,
void workSpace,
size_t  wkspSize 
)

Definition at line 431 of file huf_decompress.c.

434{
435 return HUF_decompress4X1_DCtx_wksp_bmi2(dctx, dst, dstSize, cSrc, cSrcSize, workSpace, wkspSize, 0);
436}
static size_t HUF_decompress4X1_DCtx_wksp_bmi2(HUF_DTable *dctx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, void *workSpace, size_t wkspSize, int bmi2)

Referenced by HUF_decompress4X1_DCtx(), and HUF_decompress4X_hufOnly_wksp().

◆ HUF_decompress4X1_DCtx_wksp_bmi2()

static size_t HUF_decompress4X1_DCtx_wksp_bmi2 ( HUF_DTable *  dctx,
void dst,
size_t  dstSize,
const void cSrc,
size_t  cSrcSize,
void workSpace,
size_t  wkspSize,
int  bmi2 
)
static

Definition at line 416 of file huf_decompress.c.

419{
420 const BYTE* ip = (const BYTE*) cSrc;
421
422 size_t const hSize = HUF_readDTableX1_wksp (dctx, cSrc, cSrcSize,
423 workSpace, wkspSize);
424 if (HUF_isError(hSize)) return hSize;
425 if (hSize >= cSrcSize) return ERROR(srcSize_wrong);
426 ip += hSize; cSrcSize -= hSize;
427
428 return HUF_decompress4X1_usingDTable_internal(dst, dstSize, ip, cSrcSize, dctx, bmi2);
429}

Referenced by HUF_decompress4X1_DCtx_wksp(), and HUF_decompress4X_hufOnly_wksp_bmi2().

◆ HUF_decompress4X1_usingDTable()

size_t HUF_decompress4X1_usingDTable ( void dst,
size_t  dstSize,
const void cSrc,
size_t  cSrcSize,
const HUF_DTable *  DTable 
)

Definition at line 406 of file huf_decompress.c.

410{
411 DTableDesc dtd = HUF_getDTableDesc(DTable);
412 if (dtd.tableType != 0) return ERROR(GENERIC);
413 return HUF_decompress4X1_usingDTable_internal(dst, dstSize, cSrc, cSrcSize, DTable, /* bmi2 */ 0);
414}

◆ HUF_decompress4X1_usingDTable_internal_body()

FORCE_INLINE_TEMPLATE size_t HUF_decompress4X1_usingDTable_internal_body ( void dst,
size_t  dstSize,
const void cSrc,
size_t  cSrcSize,
const HUF_DTable *  DTable 
)

Definition at line 263 of file huf_decompress.c.

267{
268 /* Check */
269 if (cSrcSize < 10) return ERROR(corruption_detected); /* strict minimum : jump table + 1 byte per stream */
270
271 { const BYTE* const istart = (const BYTE*) cSrc;
272 BYTE* const ostart = (BYTE*) dst;
273 BYTE* const oend = ostart + dstSize;
274 BYTE* const olimit = oend - 3;
275 const void* const dtPtr = DTable + 1;
276 const HUF_DEltX1* const dt = (const HUF_DEltX1*)dtPtr;
277
278 /* Init */
279 BIT_DStream_t bitD1;
280 BIT_DStream_t bitD2;
281 BIT_DStream_t bitD3;
282 BIT_DStream_t bitD4;
283 size_t const length1 = MEM_readLE16(istart);
284 size_t const length2 = MEM_readLE16(istart+2);
285 size_t const length3 = MEM_readLE16(istart+4);
286 size_t const length4 = cSrcSize - (length1 + length2 + length3 + 6);
287 const BYTE* const istart1 = istart + 6; /* jumpTable */
288 const BYTE* const istart2 = istart1 + length1;
289 const BYTE* const istart3 = istart2 + length2;
290 const BYTE* const istart4 = istart3 + length3;
291 const size_t segmentSize = (dstSize+3) / 4;
292 BYTE* const opStart2 = ostart + segmentSize;
293 BYTE* const opStart3 = opStart2 + segmentSize;
294 BYTE* const opStart4 = opStart3 + segmentSize;
295 BYTE* op1 = ostart;
296 BYTE* op2 = opStart2;
297 BYTE* op3 = opStart3;
298 BYTE* op4 = opStart4;
299 DTableDesc const dtd = HUF_getDTableDesc(DTable);
300 U32 const dtLog = dtd.tableLog;
301 U32 endSignal = 1;
302
303 if (length4 > cSrcSize) return ERROR(corruption_detected); /* overflow */
304 CHECK_F( BIT_initDStream(&bitD1, istart1, length1) );
305 CHECK_F( BIT_initDStream(&bitD2, istart2, length2) );
306 CHECK_F( BIT_initDStream(&bitD3, istart3, length3) );
307 CHECK_F( BIT_initDStream(&bitD4, istart4, length4) );
308
309 /* up to 16 symbols per loop (4 symbols per stream) in 64-bit mode */
310 for ( ; (endSignal) & (op4 < olimit) ; ) {
311 HUF_DECODE_SYMBOLX1_2(op1, &bitD1);
312 HUF_DECODE_SYMBOLX1_2(op2, &bitD2);
313 HUF_DECODE_SYMBOLX1_2(op3, &bitD3);
314 HUF_DECODE_SYMBOLX1_2(op4, &bitD4);
315 HUF_DECODE_SYMBOLX1_1(op1, &bitD1);
316 HUF_DECODE_SYMBOLX1_1(op2, &bitD2);
317 HUF_DECODE_SYMBOLX1_1(op3, &bitD3);
318 HUF_DECODE_SYMBOLX1_1(op4, &bitD4);
319 HUF_DECODE_SYMBOLX1_2(op1, &bitD1);
320 HUF_DECODE_SYMBOLX1_2(op2, &bitD2);
321 HUF_DECODE_SYMBOLX1_2(op3, &bitD3);
322 HUF_DECODE_SYMBOLX1_2(op4, &bitD4);
323 HUF_DECODE_SYMBOLX1_0(op1, &bitD1);
324 HUF_DECODE_SYMBOLX1_0(op2, &bitD2);
325 HUF_DECODE_SYMBOLX1_0(op3, &bitD3);
326 HUF_DECODE_SYMBOLX1_0(op4, &bitD4);
327 endSignal &= BIT_reloadDStreamFast(&bitD1) == BIT_DStream_unfinished;
328 endSignal &= BIT_reloadDStreamFast(&bitD2) == BIT_DStream_unfinished;
329 endSignal &= BIT_reloadDStreamFast(&bitD3) == BIT_DStream_unfinished;
330 endSignal &= BIT_reloadDStreamFast(&bitD4) == BIT_DStream_unfinished;
331 }
332
333 /* check corruption */
334 /* note : should not be necessary : op# advance in lock step, and we control op4.
335 * but curiously, binary generated by gcc 7.2 & 7.3 with -mbmi2 runs faster when >=1 test is present */
336 if (op1 > opStart2) return ERROR(corruption_detected);
337 if (op2 > opStart3) return ERROR(corruption_detected);
338 if (op3 > opStart4) return ERROR(corruption_detected);
339 /* note : op4 supposed already verified within main loop */
340
341 /* finish bitStreams one by one */
342 HUF_decodeStreamX1(op1, &bitD1, opStart2, dt, dtLog);
343 HUF_decodeStreamX1(op2, &bitD2, opStart3, dt, dtLog);
344 HUF_decodeStreamX1(op3, &bitD3, opStart4, dt, dtLog);
345 HUF_decodeStreamX1(op4, &bitD4, oend, dt, dtLog);
346
347 /* check */
348 { U32 const endCheck = BIT_endOfDStream(&bitD1) & BIT_endOfDStream(&bitD2) & BIT_endOfDStream(&bitD3) & BIT_endOfDStream(&bitD4);
349 if (!endCheck) return ERROR(corruption_detected); }
350
351 /* decoded size */
352 return dstSize;
353 }
354}
MEM_STATIC BIT_DStream_status BIT_reloadDStreamFast(BIT_DStream_t *bitD)
Definition: bitstream.h:400
MEM_STATIC U16 MEM_readLE16(const void *memPtr)
Definition: mem.h:314

◆ HUF_decompress4X2()

size_t HUF_decompress4X2 ( void dst,
size_t  dstSize,
const void cSrc,
size_t  cSrcSize 
)

Definition at line 948 of file huf_decompress.c.

949{
950 HUF_CREATE_STATIC_DTABLEX2(DTable, HUF_TABLELOG_MAX);
951 return HUF_decompress4X2_DCtx(DTable, dst, dstSize, cSrc, cSrcSize);
952}
size_t HUF_decompress4X2_DCtx(HUF_DTable *dctx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize)

Referenced by HUF_decompress().

◆ HUF_decompress4X2_DCtx()

size_t HUF_decompress4X2_DCtx ( HUF_DTable *  dctx,
void dst,
size_t  dstSize,
const void cSrc,
size_t  cSrcSize 
)

Definition at line 940 of file huf_decompress.c.

942{
943 U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32];
944 return HUF_decompress4X2_DCtx_wksp(dctx, dst, dstSize, cSrc, cSrcSize,
945 workSpace, sizeof(workSpace));
946}
size_t HUF_decompress4X2_DCtx_wksp(HUF_DTable *dctx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, void *workSpace, size_t wkspSize)

Referenced by HUF_decompress4X2(), and HUF_decompress4X_DCtx().

◆ HUF_decompress4X2_DCtx_wksp()

size_t HUF_decompress4X2_DCtx_wksp ( HUF_DTable *  dctx,
void dst,
size_t  dstSize,
const void cSrc,
size_t  cSrcSize,
void workSpace,
size_t  wkspSize 
)

Definition at line 932 of file huf_decompress.c.

935{
936 return HUF_decompress4X2_DCtx_wksp_bmi2(dctx, dst, dstSize, cSrc, cSrcSize, workSpace, wkspSize, /* bmi2 */ 0);
937}
static size_t HUF_decompress4X2_DCtx_wksp_bmi2(HUF_DTable *dctx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, void *workSpace, size_t wkspSize, int bmi2)

Referenced by HUF_decompress4X2_DCtx(), and HUF_decompress4X_hufOnly_wksp().

◆ HUF_decompress4X2_DCtx_wksp_bmi2()

static size_t HUF_decompress4X2_DCtx_wksp_bmi2 ( HUF_DTable *  dctx,
void dst,
size_t  dstSize,
const void cSrc,
size_t  cSrcSize,
void workSpace,
size_t  wkspSize,
int  bmi2 
)
static

Definition at line 917 of file huf_decompress.c.

920{
921 const BYTE* ip = (const BYTE*) cSrc;
922
923 size_t hSize = HUF_readDTableX2_wksp(dctx, cSrc, cSrcSize,
924 workSpace, wkspSize);
925 if (HUF_isError(hSize)) return hSize;
926 if (hSize >= cSrcSize) return ERROR(srcSize_wrong);
927 ip += hSize; cSrcSize -= hSize;
928
929 return HUF_decompress4X2_usingDTable_internal(dst, dstSize, ip, cSrcSize, dctx, bmi2);
930}

Referenced by HUF_decompress4X2_DCtx_wksp(), and HUF_decompress4X_hufOnly_wksp_bmi2().

◆ HUF_decompress4X2_usingDTable()

size_t HUF_decompress4X2_usingDTable ( void dst,
size_t  dstSize,
const void cSrc,
size_t  cSrcSize,
const HUF_DTable *  DTable 
)

Definition at line 907 of file huf_decompress.c.

911{
912 DTableDesc dtd = HUF_getDTableDesc(DTable);
913 if (dtd.tableType != 1) return ERROR(GENERIC);
914 return HUF_decompress4X2_usingDTable_internal(dst, dstSize, cSrc, cSrcSize, DTable, /* bmi2 */ 0);
915}

◆ HUF_decompress4X2_usingDTable_internal_body()

FORCE_INLINE_TEMPLATE size_t HUF_decompress4X2_usingDTable_internal_body ( void dst,
size_t  dstSize,
const void cSrc,
size_t  cSrcSize,
const HUF_DTable *  DTable 
)

Definition at line 750 of file huf_decompress.c.

754{
755 if (cSrcSize < 10) return ERROR(corruption_detected); /* strict minimum : jump table + 1 byte per stream */
756
757 { const BYTE* const istart = (const BYTE*) cSrc;
758 BYTE* const ostart = (BYTE*) dst;
759 BYTE* const oend = ostart + dstSize;
760 BYTE* const olimit = oend - (sizeof(size_t)-1);
761 const void* const dtPtr = DTable+1;
762 const HUF_DEltX2* const dt = (const HUF_DEltX2*)dtPtr;
763
764 /* Init */
765 BIT_DStream_t bitD1;
766 BIT_DStream_t bitD2;
767 BIT_DStream_t bitD3;
768 BIT_DStream_t bitD4;
769 size_t const length1 = MEM_readLE16(istart);
770 size_t const length2 = MEM_readLE16(istart+2);
771 size_t const length3 = MEM_readLE16(istart+4);
772 size_t const length4 = cSrcSize - (length1 + length2 + length3 + 6);
773 const BYTE* const istart1 = istart + 6; /* jumpTable */
774 const BYTE* const istart2 = istart1 + length1;
775 const BYTE* const istart3 = istart2 + length2;
776 const BYTE* const istart4 = istart3 + length3;
777 size_t const segmentSize = (dstSize+3) / 4;
778 BYTE* const opStart2 = ostart + segmentSize;
779 BYTE* const opStart3 = opStart2 + segmentSize;
780 BYTE* const opStart4 = opStart3 + segmentSize;
781 BYTE* op1 = ostart;
782 BYTE* op2 = opStart2;
783 BYTE* op3 = opStart3;
784 BYTE* op4 = opStart4;
785 U32 endSignal = 1;
786 DTableDesc const dtd = HUF_getDTableDesc(DTable);
787 U32 const dtLog = dtd.tableLog;
788
789 if (length4 > cSrcSize) return ERROR(corruption_detected); /* overflow */
790 CHECK_F( BIT_initDStream(&bitD1, istart1, length1) );
791 CHECK_F( BIT_initDStream(&bitD2, istart2, length2) );
792 CHECK_F( BIT_initDStream(&bitD3, istart3, length3) );
793 CHECK_F( BIT_initDStream(&bitD4, istart4, length4) );
794
795 /* 16-32 symbols per loop (4-8 symbols per stream) */
796 for ( ; (endSignal) & (op4 < olimit); ) {
797#if defined(__clang__) && (defined(__x86_64__) || defined(__i386__))
798 HUF_DECODE_SYMBOLX2_2(op1, &bitD1);
799 HUF_DECODE_SYMBOLX2_1(op1, &bitD1);
800 HUF_DECODE_SYMBOLX2_2(op1, &bitD1);
801 HUF_DECODE_SYMBOLX2_0(op1, &bitD1);
802 HUF_DECODE_SYMBOLX2_2(op2, &bitD2);
803 HUF_DECODE_SYMBOLX2_1(op2, &bitD2);
804 HUF_DECODE_SYMBOLX2_2(op2, &bitD2);
805 HUF_DECODE_SYMBOLX2_0(op2, &bitD2);
806 endSignal &= BIT_reloadDStreamFast(&bitD1) == BIT_DStream_unfinished;
807 endSignal &= BIT_reloadDStreamFast(&bitD2) == BIT_DStream_unfinished;
808 HUF_DECODE_SYMBOLX2_2(op3, &bitD3);
809 HUF_DECODE_SYMBOLX2_1(op3, &bitD3);
810 HUF_DECODE_SYMBOLX2_2(op3, &bitD3);
811 HUF_DECODE_SYMBOLX2_0(op3, &bitD3);
812 HUF_DECODE_SYMBOLX2_2(op4, &bitD4);
813 HUF_DECODE_SYMBOLX2_1(op4, &bitD4);
814 HUF_DECODE_SYMBOLX2_2(op4, &bitD4);
815 HUF_DECODE_SYMBOLX2_0(op4, &bitD4);
816 endSignal &= BIT_reloadDStreamFast(&bitD3) == BIT_DStream_unfinished;
817 endSignal &= BIT_reloadDStreamFast(&bitD4) == BIT_DStream_unfinished;
818#else
819 HUF_DECODE_SYMBOLX2_2(op1, &bitD1);
820 HUF_DECODE_SYMBOLX2_2(op2, &bitD2);
821 HUF_DECODE_SYMBOLX2_2(op3, &bitD3);
822 HUF_DECODE_SYMBOLX2_2(op4, &bitD4);
823 HUF_DECODE_SYMBOLX2_1(op1, &bitD1);
824 HUF_DECODE_SYMBOLX2_1(op2, &bitD2);
825 HUF_DECODE_SYMBOLX2_1(op3, &bitD3);
826 HUF_DECODE_SYMBOLX2_1(op4, &bitD4);
827 HUF_DECODE_SYMBOLX2_2(op1, &bitD1);
828 HUF_DECODE_SYMBOLX2_2(op2, &bitD2);
829 HUF_DECODE_SYMBOLX2_2(op3, &bitD3);
830 HUF_DECODE_SYMBOLX2_2(op4, &bitD4);
831 HUF_DECODE_SYMBOLX2_0(op1, &bitD1);
832 HUF_DECODE_SYMBOLX2_0(op2, &bitD2);
833 HUF_DECODE_SYMBOLX2_0(op3, &bitD3);
834 HUF_DECODE_SYMBOLX2_0(op4, &bitD4);
835 endSignal = (U32)LIKELY(
840#endif
841 }
842
843 /* check corruption */
844 if (op1 > opStart2) return ERROR(corruption_detected);
845 if (op2 > opStart3) return ERROR(corruption_detected);
846 if (op3 > opStart4) return ERROR(corruption_detected);
847 /* note : op4 already verified within main loop */
848
849 /* finish bitStreams one by one */
850 HUF_decodeStreamX2(op1, &bitD1, opStart2, dt, dtLog);
851 HUF_decodeStreamX2(op2, &bitD2, opStart3, dt, dtLog);
852 HUF_decodeStreamX2(op3, &bitD3, opStart4, dt, dtLog);
853 HUF_decodeStreamX2(op4, &bitD4, oend, dt, dtLog);
854
855 /* check */
856 { U32 const endCheck = BIT_endOfDStream(&bitD1) & BIT_endOfDStream(&bitD2) & BIT_endOfDStream(&bitD3) & BIT_endOfDStream(&bitD4);
857 if (!endCheck) return ERROR(corruption_detected); }
858
859 /* decoded size */
860 return dstSize;
861 }
862}
#define LIKELY(x)
Definition: compiler.h:161
__kernel_size_t size_t
Definition: linux.h:237

◆ HUF_decompress4X_DCtx()

size_t HUF_decompress4X_DCtx ( HUF_DTable *  dctx,
void dst,
size_t  dstSize,
const void cSrc,
size_t  cSrcSize 
)

Definition at line 1083 of file huf_decompress.c.

1084{
1085 /* validation checks */
1086 if (dstSize == 0) return ERROR(dstSize_tooSmall);
1087 if (cSrcSize > dstSize) return ERROR(corruption_detected); /* invalid */
1088 if (cSrcSize == dstSize) { memcpy(dst, cSrc, dstSize); return dstSize; } /* not compressed */
1089 if (cSrcSize == 1) { memset(dst, *(const BYTE*)cSrc, dstSize); return dstSize; } /* RLE */
1090
1091 { U32 const algoNb = HUF_selectDecoder(dstSize, cSrcSize);
1092#if defined(HUF_FORCE_DECOMPRESS_X1)
1093 (void)algoNb;
1094 assert(algoNb == 0);
1095 return HUF_decompress4X1_DCtx(dctx, dst, dstSize, cSrc, cSrcSize);
1096#elif defined(HUF_FORCE_DECOMPRESS_X2)
1097 (void)algoNb;
1098 assert(algoNb == 1);
1099 return HUF_decompress4X2_DCtx(dctx, dst, dstSize, cSrc, cSrcSize);
1100#else
1101 return algoNb ? HUF_decompress4X2_DCtx(dctx, dst, dstSize, cSrc, cSrcSize) :
1102 HUF_decompress4X1_DCtx(dctx, dst, dstSize, cSrc, cSrcSize) ;
1103#endif
1104 }
1105}

◆ HUF_decompress4X_hufOnly()

size_t HUF_decompress4X_hufOnly ( HUF_DTable *  dctx,
void dst,
size_t  dstSize,
const void cSrc,
size_t  cSrcSize 
)

Definition at line 1107 of file huf_decompress.c.

1108{
1109 U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32];
1110 return HUF_decompress4X_hufOnly_wksp(dctx, dst, dstSize, cSrc, cSrcSize,
1111 workSpace, sizeof(workSpace));
1112}
size_t HUF_decompress4X_hufOnly_wksp(HUF_DTable *dctx, void *dst, size_t dstSize, const void *cSrc, size_t cSrcSize, void *workSpace, size_t wkspSize)

◆ HUF_decompress4X_hufOnly_wksp()

size_t HUF_decompress4X_hufOnly_wksp ( HUF_DTable *  dctx,
void dst,
size_t  dstSize,
const void cSrc,
size_t  cSrcSize,
void workSpace,
size_t  wkspSize 
)

Definition at line 1115 of file huf_decompress.c.

1119{
1120 /* validation checks */
1121 if (dstSize == 0) return ERROR(dstSize_tooSmall);
1122 if (cSrcSize == 0) return ERROR(corruption_detected);
1123
1124 { U32 const algoNb = HUF_selectDecoder(dstSize, cSrcSize);
1125#if defined(HUF_FORCE_DECOMPRESS_X1)
1126 (void)algoNb;
1127 assert(algoNb == 0);
1128 return HUF_decompress4X1_DCtx_wksp(dctx, dst, dstSize, cSrc, cSrcSize, workSpace, wkspSize);
1129#elif defined(HUF_FORCE_DECOMPRESS_X2)
1130 (void)algoNb;
1131 assert(algoNb == 1);
1132 return HUF_decompress4X2_DCtx_wksp(dctx, dst, dstSize, cSrc, cSrcSize, workSpace, wkspSize);
1133#else
1134 return algoNb ? HUF_decompress4X2_DCtx_wksp(dctx, dst, dstSize, cSrc,
1135 cSrcSize, workSpace, wkspSize):
1136 HUF_decompress4X1_DCtx_wksp(dctx, dst, dstSize, cSrc, cSrcSize, workSpace, wkspSize);
1137#endif
1138 }
1139}

Referenced by HUF_decompress4X_hufOnly().

◆ HUF_decompress4X_hufOnly_wksp_bmi2()

size_t HUF_decompress4X_hufOnly_wksp_bmi2 ( HUF_DTable *  dctx,
void dst,
size_t  dstSize,
const void cSrc,
size_t  cSrcSize,
void workSpace,
size_t  wkspSize,
int  bmi2 
)

Definition at line 1228 of file huf_decompress.c.

1229{
1230 /* validation checks */
1231 if (dstSize == 0) return ERROR(dstSize_tooSmall);
1232 if (cSrcSize == 0) return ERROR(corruption_detected);
1233
1234 { U32 const algoNb = HUF_selectDecoder(dstSize, cSrcSize);
1235#if defined(HUF_FORCE_DECOMPRESS_X1)
1236 (void)algoNb;
1237 assert(algoNb == 0);
1238 return HUF_decompress4X1_DCtx_wksp_bmi2(dctx, dst, dstSize, cSrc, cSrcSize, workSpace, wkspSize, bmi2);
1239#elif defined(HUF_FORCE_DECOMPRESS_X2)
1240 (void)algoNb;
1241 assert(algoNb == 1);
1242 return HUF_decompress4X2_DCtx_wksp_bmi2(dctx, dst, dstSize, cSrc, cSrcSize, workSpace, wkspSize, bmi2);
1243#else
1244 return algoNb ? HUF_decompress4X2_DCtx_wksp_bmi2(dctx, dst, dstSize, cSrc, cSrcSize, workSpace, wkspSize, bmi2) :
1245 HUF_decompress4X1_DCtx_wksp_bmi2(dctx, dst, dstSize, cSrc, cSrcSize, workSpace, wkspSize, bmi2);
1246#endif
1247 }
1248}

◆ HUF_decompress4X_usingDTable()

size_t HUF_decompress4X_usingDTable ( void dst,
size_t  maxDstSize,
const void cSrc,
size_t  cSrcSize,
const HUF_DTable *  DTable 
)

Definition at line 980 of file huf_decompress.c.

983{
984 DTableDesc const dtd = HUF_getDTableDesc(DTable);
985#if defined(HUF_FORCE_DECOMPRESS_X1)
986 (void)dtd;
987 assert(dtd.tableType == 0);
988 return HUF_decompress4X1_usingDTable_internal(dst, maxDstSize, cSrc, cSrcSize, DTable, /* bmi2 */ 0);
989#elif defined(HUF_FORCE_DECOMPRESS_X2)
990 (void)dtd;
991 assert(dtd.tableType == 1);
992 return HUF_decompress4X2_usingDTable_internal(dst, maxDstSize, cSrc, cSrcSize, DTable, /* bmi2 */ 0);
993#else
994 return dtd.tableType ? HUF_decompress4X2_usingDTable_internal(dst, maxDstSize, cSrc, cSrcSize, DTable, /* bmi2 */ 0) :
995 HUF_decompress4X1_usingDTable_internal(dst, maxDstSize, cSrc, cSrcSize, DTable, /* bmi2 */ 0);
996#endif
997}

◆ HUF_decompress4X_usingDTable_bmi2()

size_t HUF_decompress4X_usingDTable_bmi2 ( void dst,
size_t  maxDstSize,
const void cSrc,
size_t  cSrcSize,
const HUF_DTable *  DTable,
int  bmi2 
)

Definition at line 1211 of file huf_decompress.c.

1212{
1213 DTableDesc const dtd = HUF_getDTableDesc(DTable);
1214#if defined(HUF_FORCE_DECOMPRESS_X1)
1215 (void)dtd;
1216 assert(dtd.tableType == 0);
1217 return HUF_decompress4X1_usingDTable_internal(dst, maxDstSize, cSrc, cSrcSize, DTable, bmi2);
1218#elif defined(HUF_FORCE_DECOMPRESS_X2)
1219 (void)dtd;
1220 assert(dtd.tableType == 1);
1221 return HUF_decompress4X2_usingDTable_internal(dst, maxDstSize, cSrc, cSrcSize, DTable, bmi2);
1222#else
1223 return dtd.tableType ? HUF_decompress4X2_usingDTable_internal(dst, maxDstSize, cSrc, cSrcSize, DTable, bmi2) :
1224 HUF_decompress4X1_usingDTable_internal(dst, maxDstSize, cSrc, cSrcSize, DTable, bmi2);
1225#endif
1226}

◆ HUF_fillDTableX2()

static void HUF_fillDTableX2 ( HUF_DEltX2 DTable,
const U32  targetLog,
const sortedSymbol_t sortedList,
const U32  sortedListSize,
const U32 rankStart,
rankVal_t  rankValOrigin,
const U32  maxWeight,
const U32  nbBitsBaseline 
)
static

Definition at line 509 of file huf_decompress.c.

513{
514 U32 rankVal[HUF_TABLELOG_MAX + 1];
515 const int scaleLog = nbBitsBaseline - targetLog; /* note : targetLog >= srcLog, hence scaleLog <= 1 */
516 const U32 minBits = nbBitsBaseline - maxWeight;
517 U32 s;
518
519 memcpy(rankVal, rankValOrigin, sizeof(rankVal));
520
521 /* fill DTable */
522 for (s=0; s<sortedListSize; s++) {
523 const U16 symbol = sortedList[s].symbol;
524 const U32 weight = sortedList[s].weight;
525 const U32 nbBits = nbBitsBaseline - weight;
526 const U32 start = rankVal[weight];
527 const U32 length = 1 << (targetLog-nbBits);
528
529 if (targetLog-nbBits >= minBits) { /* enough room for a second symbol */
530 U32 sortedRank;
531 int minWeight = nbBits + scaleLog;
532 if (minWeight < 1) minWeight = 1;
533 sortedRank = rankStart[minWeight];
534 HUF_fillDTableX2Level2(DTable+start, targetLog-nbBits, nbBits,
535 rankValOrigin[nbBits], minWeight,
536 sortedList+sortedRank, sortedListSize-sortedRank,
537 nbBitsBaseline, symbol);
538 } else {
539 HUF_DEltX2 DElt;
540 MEM_writeLE16(&(DElt.sequence), symbol);
541 DElt.nbBits = (BYTE)(nbBits);
542 DElt.length = 1;
543 { U32 const end = start + length;
544 U32 u;
545 for (u = start; u < end; u++) DTable[u] = DElt;
546 } }
547 rankVal[weight] += length;
548 }
549}
MEM_STATIC void MEM_writeLE16(void *memPtr, U16 val)
Definition: mem.h:324
GLuint start
Definition: gl.h:1545
GLdouble s
Definition: gl.h:2039
GLuint GLuint end
Definition: gl.h:1545
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
Definition: glfuncs.h:240
static void HUF_fillDTableX2Level2(HUF_DEltX2 *DTable, U32 sizeLog, const U32 consumed, const U32 *rankValOrigin, const int minWeight, const sortedSymbol_t *sortedSymbols, const U32 sortedListSize, U32 nbBitsBaseline, U16 baseSeq)
weight
Definition: sortkey.c:157
unsigned short U16
Definition: xxhash.c:194

Referenced by HUF_readDTableX2_wksp().

◆ HUF_fillDTableX2Level2()

static void HUF_fillDTableX2Level2 ( HUF_DEltX2 DTable,
U32  sizeLog,
const U32  consumed,
const U32 rankValOrigin,
const int  minWeight,
const sortedSymbol_t sortedSymbols,
const U32  sortedListSize,
U32  nbBitsBaseline,
U16  baseSeq 
)
static

Definition at line 468 of file huf_decompress.c.

472{
473 HUF_DEltX2 DElt;
474 U32 rankVal[HUF_TABLELOG_MAX + 1];
475
476 /* get pre-calculated rankVal */
477 memcpy(rankVal, rankValOrigin, sizeof(rankVal));
478
479 /* fill skipped values */
480 if (minWeight>1) {
481 U32 i, skipSize = rankVal[minWeight];
482 MEM_writeLE16(&(DElt.sequence), baseSeq);
483 DElt.nbBits = (BYTE)(consumed);
484 DElt.length = 1;
485 for (i = 0; i < skipSize; i++)
486 DTable[i] = DElt;
487 }
488
489 /* fill DTable */
490 { U32 s; for (s=0; s<sortedListSize; s++) { /* note : sortedSymbols already skipped */
491 const U32 symbol = sortedSymbols[s].symbol;
492 const U32 weight = sortedSymbols[s].weight;
493 const U32 nbBits = nbBitsBaseline - weight;
494 const U32 length = 1 << (sizeLog-nbBits);
495 const U32 start = rankVal[weight];
496 U32 i = start;
497 const U32 end = start + length;
498
499 MEM_writeLE16(&(DElt.sequence), (U16)(baseSeq + (symbol << 8)));
500 DElt.nbBits = (BYTE)(nbBits + consumed);
501 DElt.length = 2;
502 do { DTable[i++] = DElt; } while (i<end); /* since length >= 1 */
503
504 rankVal[weight] += length;
505 } }
506}
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
Definition: glfuncs.h:248
int consumed
Definition: scanf.h:134

Referenced by HUF_fillDTableX2().

◆ HUF_getDTableDesc()

◆ HUF_readDTableX1()

size_t HUF_readDTableX1 ( HUF_DTable *  DTable,
const void src,
size_t  srcSize 
)

Definition at line 187 of file huf_decompress.c.

188{
189 U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32];
190 return HUF_readDTableX1_wksp(DTable, src, srcSize,
191 workSpace, sizeof(workSpace));
192}
GLenum src
Definition: glext.h:6340

◆ HUF_readDTableX1_wksp()

size_t HUF_readDTableX1_wksp ( HUF_DTable *  DTable,
const void src,
size_t  srcSize,
void workSpace,
size_t  wkspSize 
)

Definition at line 118 of file huf_decompress.c.

119{
120 U32 tableLog = 0;
121 U32 nbSymbols = 0;
122 size_t iSize;
123 void* const dtPtr = DTable + 1;
124 HUF_DEltX1* const dt = (HUF_DEltX1*)dtPtr;
125
126 U32* rankVal;
127 BYTE* huffWeight;
128 size_t spaceUsed32 = 0;
129
130 rankVal = (U32 *)workSpace + spaceUsed32;
131 spaceUsed32 += HUF_TABLELOG_ABSOLUTEMAX + 1;
132 huffWeight = (BYTE *)((U32 *)workSpace + spaceUsed32);
133 spaceUsed32 += HUF_ALIGN(HUF_SYMBOLVALUE_MAX + 1, sizeof(U32)) >> 2;
134
135 if ((spaceUsed32 << 2) > wkspSize) return ERROR(tableLog_tooLarge);
136
137 DEBUG_STATIC_ASSERT(sizeof(DTableDesc) == sizeof(HUF_DTable));
138 /* memset(huffWeight, 0, sizeof(huffWeight)); */ /* is not necessary, even though some analyzer complain ... */
139
140 iSize = HUF_readStats(huffWeight, HUF_SYMBOLVALUE_MAX + 1, rankVal, &nbSymbols, &tableLog, src, srcSize);
141 if (HUF_isError(iSize)) return iSize;
142
143 /* Table header */
144 { DTableDesc dtd = HUF_getDTableDesc(DTable);
145 if (tableLog > (U32)(dtd.maxTableLog+1)) return ERROR(tableLog_tooLarge); /* DTable too small, Huffman tree cannot fit in */
146 dtd.tableType = 0;
147 dtd.tableLog = (BYTE)tableLog;
148 memcpy(DTable, &dtd, sizeof(dtd));
149 }
150
151 /* Calculate starting value for each rank */
152 { U32 n, nextRankStart = 0;
153 for (n=1; n<tableLog+1; n++) {
154 U32 const current = nextRankStart;
155 nextRankStart += (rankVal[n] << (n-1));
156 rankVal[n] = current;
157 } }
158
159 /* fill DTable */
160 { U32 n;
161 size_t const nEnd = nbSymbols;
162 for (n=0; n<nEnd; n++) {
163 size_t const w = huffWeight[n];
164 size_t const length = (1 << w) >> 1;
165 size_t const uStart = rankVal[w];
166 size_t const uEnd = uStart + length;
167 size_t u;
169 D.byte = (BYTE)n;
170 D.nbBits = (BYTE)(tableLog + 1 - w);
171 rankVal[w] = (U32)uEnd;
172 if (length < 4) {
173 /* Use length in the loop bound so the compiler knows it is short. */
174 for (u = 0; u < length; ++u)
175 dt[uStart + u] = D;
176 } else {
177 /* Unroll the loop 4 times, we know it is a power of 2. */
178 for (u = uStart; u < uEnd; u += 4) {
179 dt[u + 0] = D;
180 dt[u + 1] = D;
181 dt[u + 2] = D;
182 dt[u + 3] = D;
183 } } } }
184 return iSize;
185}
#define D(d)
Definition: builtin.c:4557
#define DEBUG_STATIC_ASSERT(c)
Definition: debug.h:43
size_t HUF_readStats(BYTE *huffWeight, size_t hwSize, U32 *rankStats, U32 *nbSymbolsPtr, U32 *tableLogPtr, const void *src, size_t srcSize)
GLdouble n
Definition: glext.h:7729
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
#define HUF_ALIGN(x, a)
struct task_struct * current
Definition: linux.c:32

Referenced by HUF_decompress1X1_DCtx_wksp(), HUF_decompress1X1_DCtx_wksp_bmi2(), HUF_decompress4X1_DCtx_wksp_bmi2(), HUF_readDTableX1(), and ZSTD_loadDEntropy().

◆ HUF_readDTableX2()

size_t HUF_readDTableX2 ( HUF_DTable *  DTable,
const void src,
size_t  srcSize 
)

Definition at line 651 of file huf_decompress.c.

652{
653 U32 workSpace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32];
654 return HUF_readDTableX2_wksp(DTable, src, srcSize,
655 workSpace, sizeof(workSpace));
656}

◆ HUF_readDTableX2_wksp()

size_t HUF_readDTableX2_wksp ( HUF_DTable *  DTable,
const void src,
size_t  srcSize,
void workSpace,
size_t  wkspSize 
)

Definition at line 551 of file huf_decompress.c.

554{
555 U32 tableLog, maxW, sizeOfSort, nbSymbols;
556 DTableDesc dtd = HUF_getDTableDesc(DTable);
557 U32 const maxTableLog = dtd.maxTableLog;
558 size_t iSize;
559 void* dtPtr = DTable+1; /* force compiler to avoid strict-aliasing */
560 HUF_DEltX2* const dt = (HUF_DEltX2*)dtPtr;
561 U32 *rankStart;
562
563 rankValCol_t* rankVal;
564 U32* rankStats;
565 U32* rankStart0;
566 sortedSymbol_t* sortedSymbol;
567 BYTE* weightList;
568 size_t spaceUsed32 = 0;
569
570 rankVal = (rankValCol_t *)((U32 *)workSpace + spaceUsed32);
571 spaceUsed32 += (sizeof(rankValCol_t) * HUF_TABLELOG_MAX) >> 2;
572 rankStats = (U32 *)workSpace + spaceUsed32;
573 spaceUsed32 += HUF_TABLELOG_MAX + 1;
574 rankStart0 = (U32 *)workSpace + spaceUsed32;
575 spaceUsed32 += HUF_TABLELOG_MAX + 2;
576 sortedSymbol = (sortedSymbol_t *)workSpace + (spaceUsed32 * sizeof(U32)) / sizeof(sortedSymbol_t);
577 spaceUsed32 += HUF_ALIGN(sizeof(sortedSymbol_t) * (HUF_SYMBOLVALUE_MAX + 1), sizeof(U32)) >> 2;
578 weightList = (BYTE *)((U32 *)workSpace + spaceUsed32);
579 spaceUsed32 += HUF_ALIGN(HUF_SYMBOLVALUE_MAX + 1, sizeof(U32)) >> 2;
580
581 if ((spaceUsed32 << 2) > wkspSize) return ERROR(tableLog_tooLarge);
582
583 rankStart = rankStart0 + 1;
584 memset(rankStats, 0, sizeof(U32) * (2 * HUF_TABLELOG_MAX + 2 + 1));
585
586 DEBUG_STATIC_ASSERT(sizeof(HUF_DEltX2) == sizeof(HUF_DTable)); /* if compiler fails here, assertion is wrong */
587 if (maxTableLog > HUF_TABLELOG_MAX) return ERROR(tableLog_tooLarge);
588 /* memset(weightList, 0, sizeof(weightList)); */ /* is not necessary, even though some analyzer complain ... */
589
590 iSize = HUF_readStats(weightList, HUF_SYMBOLVALUE_MAX + 1, rankStats, &nbSymbols, &tableLog, src, srcSize);
591 if (HUF_isError(iSize)) return iSize;
592
593 /* check result */
594 if (tableLog > maxTableLog) return ERROR(tableLog_tooLarge); /* DTable can't fit code depth */
595
596 /* find maxWeight */
597 for (maxW = tableLog; rankStats[maxW]==0; maxW--) {} /* necessarily finds a solution before 0 */
598
599 /* Get start index of each weight */
600 { U32 w, nextRankStart = 0;
601 for (w=1; w<maxW+1; w++) {
602 U32 current = nextRankStart;
603 nextRankStart += rankStats[w];
604 rankStart[w] = current;
605 }
606 rankStart[0] = nextRankStart; /* put all 0w symbols at the end of sorted list*/
607 sizeOfSort = nextRankStart;
608 }
609
610 /* sort symbols by weight */
611 { U32 s;
612 for (s=0; s<nbSymbols; s++) {
613 U32 const w = weightList[s];
614 U32 const r = rankStart[w]++;
615 sortedSymbol[r].symbol = (BYTE)s;
616 sortedSymbol[r].weight = (BYTE)w;
617 }
618 rankStart[0] = 0; /* forget 0w symbols; this is beginning of weight(1) */
619 }
620
621 /* Build rankVal */
622 { U32* const rankVal0 = rankVal[0];
623 { int const rescale = (maxTableLog-tableLog) - 1; /* tableLog <= maxTableLog */
624 U32 nextRankVal = 0;
625 U32 w;
626 for (w=1; w<maxW+1; w++) {
627 U32 current = nextRankVal;
628 nextRankVal += rankStats[w] << (w+rescale);
629 rankVal0[w] = current;
630 } }
631 { U32 const minBits = tableLog+1 - maxW;
633 for (consumed = minBits; consumed < maxTableLog - minBits + 1; consumed++) {
634 U32* const rankValPtr = rankVal[consumed];
635 U32 w;
636 for (w = 1; w < maxW+1; w++) {
637 rankValPtr[w] = rankVal0[w] >> consumed;
638 } } } }
639
640 HUF_fillDTableX2(dt, maxTableLog,
641 sortedSymbol, sizeOfSort,
642 rankStart0, rankVal, maxW,
643 tableLog+1);
644
645 dtd.tableLog = (BYTE)maxTableLog;
646 dtd.tableType = 1;
647 memcpy(DTable, &dtd, sizeof(dtd));
648 return iSize;
649}
static const WCHAR maxW[]
Definition: math.c:53
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
U32 rankValCol_t[HUF_TABLELOG_MAX+1]
static void HUF_fillDTableX2(HUF_DEltX2 *DTable, const U32 targetLog, const sortedSymbol_t *sortedList, const U32 sortedListSize, const U32 *rankStart, rankVal_t rankValOrigin, const U32 maxWeight, const U32 nbBitsBaseline)

Referenced by HUF_decompress1X2_DCtx_wksp(), HUF_decompress4X2_DCtx_wksp_bmi2(), HUF_readDTableX2(), and ZSTD_loadDEntropy().

◆ HUF_selectDecoder()

U32 HUF_selectDecoder ( size_t  dstSize,
size_t  cSrcSize 
)

HUF_selectDecoder() : Tells which decoder is likely to decode faster, based on a set of pre-computed metrics.

Returns
: 0==HUF_decompress4X1, 1==HUF_decompress4X2 . Assumption : 0 < dstSize <= 128 KB

Definition at line 1029 of file huf_decompress.c.

1030{
1031 assert(dstSize > 0);
1032 assert(dstSize <= 128*1024);
1033#if defined(HUF_FORCE_DECOMPRESS_X1)
1034 (void)dstSize;
1035 (void)cSrcSize;
1036 return 0;
1037#elif defined(HUF_FORCE_DECOMPRESS_X2)
1038 (void)dstSize;
1039 (void)cSrcSize;
1040 return 1;
1041#else
1042 /* decoder timing evaluation */
1043 { U32 const Q = (cSrcSize >= dstSize) ? 15 : (U32)(cSrcSize * 16 / dstSize); /* Q < 16 */
1044 U32 const D256 = (U32)(dstSize >> 8);
1045 U32 const DTime0 = algoTime[Q][0].tableTime + (algoTime[Q][0].decode256Time * D256);
1046 U32 DTime1 = algoTime[Q][1].tableTime + (algoTime[Q][1].decode256Time * D256);
1047 DTime1 += DTime1 >> 3; /* advantage to algorithm using less memory, to reduce cache eviction */
1048 return DTime1 < DTime0;
1049 }
1050#endif
1051}
static const algo_time_t algoTime[16][3]

Referenced by HUF_decompress(), HUF_decompress1X_DCtx_wksp(), HUF_decompress4X_DCtx(), HUF_decompress4X_hufOnly_wksp(), and HUF_decompress4X_hufOnly_wksp_bmi2().

Variable Documentation

◆ algoTime

const algo_time_t algoTime[16][3]
static
Initial value:
=
{
{{0,0}, {1,1}, {2,2}},
{{0,0}, {1,1}, {2,2}},
{{ 38,130}, {1313, 74}, {2151, 38}},
{{ 448,128}, {1353, 74}, {2238, 41}},
{{ 556,128}, {1353, 74}, {2238, 47}},
{{ 714,128}, {1418, 74}, {2436, 53}},
{{ 883,128}, {1437, 74}, {2464, 61}},
{{ 897,128}, {1515, 75}, {2622, 68}},
{{ 926,128}, {1613, 75}, {2730, 75}},
{{ 947,128}, {1729, 77}, {3359, 77}},
{{1107,128}, {2083, 81}, {4006, 84}},
{{1177,128}, {2379, 87}, {4785, 88}},
{{1242,128}, {2415, 93}, {5155, 84}},
{{1349,128}, {2644,106}, {5260,106}},
{{1455,128}, {2422,124}, {4174,124}},
{{ 722,128}, {1891,145}, {1936,146}},
}

Definition at line 1002 of file huf_decompress.c.

Referenced by HUF_selectDecoder().