Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
lz4hc.c File Reference
#include <stdlib.h>
#include <string.h>
#include "lz4hc.h"
#include <stdint.h>

Go to the source code of this file.

Classes

struct  _U16_S
 
struct  _U32_S
 
struct  _U64_S
 
struct  LZ4HC_Data_Structure
 

Macros

#define LZ4_ARCH64   0
 
#define restrict
 
#define forceinline   inline
 
#define lz4_bswap16(x)   ((unsigned short int) ((((x) >> 8) & 0xffu) | (((x) & 0xffu) << 8)))
 
#define ALLOCATOR(s)   calloc(1,s)
 
#define FREEMEM   free
 
#define MEM_INIT   memset
 
#define BYTE   uint8_t
 
#define U16   uint16_t
 
#define U32   uint32_t
 
#define S32   int32_t
 
#define U64   uint64_t
 
#define S64   int64_t
 
#define A64(x)   (((U64_S *)(x))->v)
 
#define A32(x)   (((U32_S *)(x))->v)
 
#define A16(x)   (((U16_S *)(x))->v)
 
#define MINMATCH   4
 
#define DICTIONARY_LOGSIZE   16
 
#define MAXD   (1<<DICTIONARY_LOGSIZE)
 
#define MAXD_MASK   ((U32)(MAXD - 1))
 
#define MAX_DISTANCE   (MAXD - 1)
 
#define HASH_LOG   (DICTIONARY_LOGSIZE-1)
 
#define HASHTABLESIZE   (1 << HASH_LOG)
 
#define HASH_MASK   (HASHTABLESIZE - 1)
 
#define MAX_NB_ATTEMPTS   256
 
#define ML_BITS   4
 
#define ML_MASK   (size_t)((1U<<ML_BITS)-1)
 
#define RUN_BITS   (8-ML_BITS)
 
#define RUN_MASK   ((1U<<RUN_BITS)-1)
 
#define COPYLENGTH   8
 
#define LASTLITERALS   5
 
#define MFLIMIT   (COPYLENGTH+MINMATCH)
 
#define MINLENGTH   (MFLIMIT+1)
 
#define OPTIMAL_ML   (int)((ML_MASK-1)+MINMATCH)
 
#define STEPSIZE   4
 
#define LZ4_COPYSTEP(s, d)   A32(d) = A32(s); d+=4; s+=4;
 
#define LZ4_COPYPACKET(s, d)   LZ4_COPYSTEP(s,d); LZ4_COPYSTEP(s,d);
 
#define UARCH   U32
 
#define AARCH   A32
 
#define HTYPE   const BYTE*
 
#define INITBASE(b, s)   const int b = 0
 
#define LZ4_READ_LITTLEENDIAN_16(d, s, p)   { d = (s) - A16(p); }
 
#define LZ4_WRITE_LITTLEENDIAN_16(p, v)   { A16(p) = v; p+=2; }
 
#define LZ4_WILDCOPY(s, d, e)   do { LZ4_COPYPACKET(s,d) } while (d<e);
 
#define LZ4_BLINDCOPY(s, d, l)   { BYTE* e=d+l; LZ4_WILDCOPY(s,d,e); d=e; }
 
#define HASH_FUNCTION(i)   (((i) * 2654435761U) >> ((MINMATCH*8)-HASH_LOG))
 
#define HASH_VALUE(p)   HASH_FUNCTION(A32(p))
 
#define HASH_POINTER(p)   (HashTable[HASH_VALUE(p)] + base)
 
#define DELTANEXT(p)   chainTable[(size_t)(p) & MAXD_MASK]
 
#define GETNEXT(p)   ((p) - (size_t)DELTANEXT(p))
 
#define REPEAT_OPTIMIZATION
 

Typedefs

typedef struct _U16_S U16_S
 
typedef struct _U32_S U32_S
 
typedef struct _U64_S U64_S
 

Functions

static int LZ4_NbCommonBytes (register U32 val)
 
static int LZ4HC_Init (LZ4HC_Data_Structure *hc4, const BYTE *base)
 
static void * LZ4HC_Create (const BYTE *base)
 
static int LZ4HC_Free (void **LZ4HC_Data)
 
static forceinline void LZ4HC_Insert (LZ4HC_Data_Structure *hc4, const BYTE *ip)
 
static forceinline size_t LZ4HC_CommonLength (const BYTE *p1, const BYTE *p2, const BYTE *const matchlimit)
 
static forceinline int LZ4HC_InsertAndFindBestMatch (LZ4HC_Data_Structure *hc4, const BYTE *ip, const BYTE *const matchlimit, const BYTE **matchpos)
 
static forceinline int LZ4HC_InsertAndGetWiderMatch (LZ4HC_Data_Structure *hc4, const BYTE *ip, const BYTE *startLimit, const BYTE *matchlimit, int longest, const BYTE **matchpos, const BYTE **startpos)
 
static forceinline int LZ4_encodeSequence (const BYTE **ip, BYTE **op, const BYTE **anchor, int matchLength, const BYTE *ref, BYTE *oend)
 
int LZ4_compressHCCtx (LZ4HC_Data_Structure *ctx, const char *source, char *dest, int inputSize, int maxOutputSize)
 
 CORE_EXPORT (int)
 

Macro Definition Documentation

#define A16 (   x)    (((U16_S *)(x))->v)

Definition at line 167 of file lz4hc.c.

Referenced by LZ4HC_CommonLength(), and LZ4HC_InsertAndGetWiderMatch().

#define A32 (   x)    (((U32_S *)(x))->v)
#define A64 (   x)    (((U64_S *)(x))->v)

Definition at line 165 of file lz4hc.c.

#define AARCH   A32

Definition at line 214 of file lz4hc.c.

Referenced by LZ4HC_CommonLength(), and LZ4HC_InsertAndGetWiderMatch().

#define ALLOCATOR (   s)    calloc(1,s)

Definition at line 128 of file lz4hc.c.

Referenced by LZ4HC_Create().

#define COPYLENGTH   8

Definition at line 191 of file lz4hc.c.

#define DELTANEXT (   p)    chainTable[(size_t)(p) & MAXD_MASK]

Definition at line 248 of file lz4hc.c.

Referenced by LZ4HC_Insert(), and LZ4HC_InsertAndFindBestMatch().

#define DICTIONARY_LOGSIZE   16

Definition at line 175 of file lz4hc.c.

#define forceinline   inline

Definition at line 97 of file lz4hc.c.

#define FREEMEM   free

Definition at line 129 of file lz4hc.c.

Referenced by LZ4HC_Free().

#define GETNEXT (   p)    ((p) - (size_t)DELTANEXT(p))

Definition at line 249 of file lz4hc.c.

Referenced by LZ4HC_InsertAndFindBestMatch(), and LZ4HC_InsertAndGetWiderMatch().

#define HASH_FUNCTION (   i)    (((i) * 2654435761U) >> ((MINMATCH*8)-HASH_LOG))

Definition at line 245 of file lz4hc.c.

#define HASH_LOG   (DICTIONARY_LOGSIZE-1)

Definition at line 180 of file lz4hc.c.

#define HASH_MASK   (HASHTABLESIZE - 1)

Definition at line 182 of file lz4hc.c.

#define HASH_POINTER (   p)    (HashTable[HASH_VALUE(p)] + base)
#define HASH_VALUE (   p)    HASH_FUNCTION(A32(p))

Definition at line 246 of file lz4hc.c.

Referenced by LZ4HC_Insert(), and LZ4HC_InsertAndFindBestMatch().

#define HASHTABLESIZE   (1 << HASH_LOG)

Definition at line 181 of file lz4hc.c.

#define HTYPE   const BYTE*
#define INITBASE (   b,
  s 
)    const int b = 0
#define LASTLITERALS   5

Definition at line 192 of file lz4hc.c.

Referenced by LZ4_compressHCCtx(), and LZ4_encodeSequence().

#define LZ4_ARCH64   0

Definition at line 45 of file lz4hc.c.

Referenced by LZ4HC_CommonLength(), LZ4HC_Init(), and LZ4HC_InsertAndGetWiderMatch().

#define LZ4_BLINDCOPY (   s,
  d,
 
)    { BYTE* e=d+l; LZ4_WILDCOPY(s,d,e); d=e; }

Definition at line 244 of file lz4hc.c.

Referenced by LZ4_encodeSequence().

#define lz4_bswap16 (   x)    ((unsigned short int) ((((x) >> 8) & 0xffu) | (((x) & 0xffu) << 8)))

Definition at line 117 of file lz4hc.c.

#define LZ4_COPYPACKET (   s,
 
)    LZ4_COPYSTEP(s,d); LZ4_COPYSTEP(s,d);

Definition at line 212 of file lz4hc.c.

#define LZ4_COPYSTEP (   s,
 
)    A32(d) = A32(s); d+=4; s+=4;

Definition at line 211 of file lz4hc.c.

#define LZ4_READ_LITTLEENDIAN_16 (   d,
  s,
 
)    { d = (s) - A16(p); }

Definition at line 223 of file lz4hc.c.

#define LZ4_WILDCOPY (   s,
  d,
 
)    do { LZ4_COPYPACKET(s,d) } while (d<e);

Definition at line 243 of file lz4hc.c.

#define LZ4_WRITE_LITTLEENDIAN_16 (   p,
 
)    { A16(p) = v; p+=2; }

Definition at line 224 of file lz4hc.c.

Referenced by LZ4_encodeSequence().

#define MAX_DISTANCE   (MAXD - 1)
#define MAX_NB_ATTEMPTS   256

Definition at line 184 of file lz4hc.c.

Referenced by LZ4HC_InsertAndFindBestMatch(), and LZ4HC_InsertAndGetWiderMatch().

#define MAXD   (1<<DICTIONARY_LOGSIZE)

Definition at line 176 of file lz4hc.c.

#define MAXD_MASK   ((U32)(MAXD - 1))

Definition at line 177 of file lz4hc.c.

#define MEM_INIT   memset

Definition at line 130 of file lz4hc.c.

Referenced by LZ4HC_Init().

#define MFLIMIT   (COPYLENGTH+MINMATCH)

Definition at line 193 of file lz4hc.c.

Referenced by LZ4_compressHCCtx().

#define MINLENGTH   (MFLIMIT+1)

Definition at line 194 of file lz4hc.c.

#define MINMATCH   4
#define ML_BITS   4

Definition at line 186 of file lz4hc.c.

Referenced by LZ4_compressHCCtx(), and LZ4_encodeSequence().

#define ML_MASK   (size_t)((1U<<ML_BITS)-1)

Definition at line 187 of file lz4hc.c.

Referenced by LZ4_compressHCCtx(), and LZ4_encodeSequence().

#define OPTIMAL_ML   (int)((ML_MASK-1)+MINMATCH)

Definition at line 195 of file lz4hc.c.

Referenced by LZ4_compressHCCtx().

#define REPEAT_OPTIMIZATION
#define restrict

Definition at line 87 of file lz4hc.c.

#define RUN_BITS   (8-ML_BITS)

Definition at line 188 of file lz4hc.c.

#define RUN_MASK   ((1U<<RUN_BITS)-1)

Definition at line 189 of file lz4hc.c.

Referenced by LZ4_compressHCCtx(), and LZ4_encodeSequence().

#define S32   int32_t

Definition at line 148 of file lz4hc.c.

Referenced by LZ4_NbCommonBytes().

#define S64   int64_t

Definition at line 150 of file lz4hc.c.

#define STEPSIZE   4

Definition at line 210 of file lz4hc.c.

Referenced by LZ4HC_CommonLength(), and LZ4HC_InsertAndGetWiderMatch().

#define U16   uint16_t
#define U32   uint32_t

Definition at line 147 of file lz4hc.c.

Referenced by LZ4_compressHCCtx(), and LZ4_NbCommonBytes().

#define U64   uint64_t

Definition at line 149 of file lz4hc.c.

#define UARCH   U32

Definition at line 213 of file lz4hc.c.

Referenced by LZ4HC_CommonLength(), and LZ4HC_InsertAndGetWiderMatch().

Typedef Documentation

typedef struct _U16_S U16_S
typedef struct _U32_S U32_S
typedef struct _U64_S U64_S

Function Documentation

CORE_EXPORT ( int  )

Definition at line 745 of file lz4hc.c.

References BYTE, LZ4_compressHCCtx(), LZ4HC_Create(), and LZ4HC_Free().

int LZ4_compressHCCtx ( LZ4HC_Data_Structure ctx,
const char *  source,
char *  dest,
int  inputSize,
int  maxOutputSize 
)
static forceinline int LZ4_encodeSequence ( const BYTE **  ip,
BYTE **  op,
const BYTE **  anchor,
int  matchLength,
const BYTE ref,
BYTE oend 
)
static

Definition at line 521 of file lz4hc.c.

References BYTE, LASTLITERALS, LZ4_BLINDCOPY, LZ4_WRITE_LITTLEENDIAN_16, MINMATCH, ML_BITS, ML_MASK, RUN_MASK, and U16.

Referenced by LZ4_compressHCCtx().

static int LZ4_NbCommonBytes ( register U32  val)
static

Definition at line 293 of file lz4hc.c.

References S32, and U32.

Referenced by LZ4HC_CommonLength(), and LZ4HC_InsertAndGetWiderMatch().

static forceinline size_t LZ4HC_CommonLength ( const BYTE p1,
const BYTE p2,
const BYTE *const  matchlimit 
)
static
static void* LZ4HC_Create ( const BYTE base)
static

Definition at line 340 of file lz4hc.c.

References ALLOCATOR, and LZ4HC_Init().

Referenced by CORE_EXPORT().

static int LZ4HC_Free ( void **  LZ4HC_Data)
static

Definition at line 349 of file lz4hc.c.

References FREEMEM.

Referenced by CORE_EXPORT().

static int LZ4HC_Init ( LZ4HC_Data_Structure hc4,
const BYTE base 
)
static
static forceinline int LZ4HC_InsertAndFindBestMatch ( LZ4HC_Data_Structure hc4,
const BYTE ip,
const BYTE *const  matchlimit,
const BYTE **  matchpos 
)
static
static forceinline int LZ4HC_InsertAndGetWiderMatch ( LZ4HC_Data_Structure hc4,
const BYTE ip,
const BYTE startLimit,
const BYTE matchlimit,
int  longest,
const BYTE **  matchpos,
const BYTE **  startpos 
)
static