CMSIS2000  0.0.7
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
lz4hc.c File Reference
#include <stdlib.h>
#include <string.h>
#include "lz4hc.h"
#include <stdint.h>
Include dependency graph for lz4hc.c:

Go to the source code of this file.

Data Structures

struct  _U16_S
struct  _U32_S
struct  _U64_S
struct  LZ4HC_Data_Structure

Macros

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

Typedefs

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

Functions

int LZ4_compressHC (const char *source, char *dest, int isize)
int LZ4_compressHCCtx (LZ4HC_Data_Structure *ctx, const char *source, char *dest, int isize)
static forceinline int LZ4_encodeSequence (const BYTE **ip, BYTE **op, const BYTE **anchor, int ml, const BYTE *ref)
static int LZ4_NbCommonBytes (register U32 val)
static forceinline size_t LZ4HC_CommonLength (const BYTE *p1, const BYTE *p2, const BYTE *const matchlimit)
static void * LZ4HC_Create (const BYTE *base)
static int LZ4HC_Free (void **LZ4HC_Data)
static int LZ4HC_Init (LZ4HC_Data_Structure *hc4, const BYTE *base)
static forceinline void LZ4HC_Insert (LZ4HC_Data_Structure *hc4, const BYTE *ip)
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)

Macro Definition Documentation

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

Definition at line 155 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 153 of file lz4hc.c.

#define AARCH   A32

Definition at line 202 of file lz4hc.c.

Referenced by LZ4HC_CommonLength(), and LZ4HC_InsertAndGetWiderMatch().

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

Definition at line 118 of file lz4hc.c.

Referenced by LZ4HC_Create().

#define BYTE   uint8_t

Definition at line 134 of file lz4hc.c.

#define COPYLENGTH   8

Definition at line 179 of file lz4hc.c.

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

Definition at line 236 of file lz4hc.c.

Referenced by LZ4HC_Insert(), and LZ4HC_InsertAndFindBestMatch().

#define DICTIONARY_LOGSIZE   16

Definition at line 163 of file lz4hc.c.

#define forceinline   inline

Definition at line 100 of file lz4hc.c.

#define FREEMEM   free

Definition at line 119 of file lz4hc.c.

Referenced by LZ4HC_Free().

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

Definition at line 237 of file lz4hc.c.

Referenced by LZ4HC_InsertAndFindBestMatch(), and LZ4HC_InsertAndGetWiderMatch().

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

Definition at line 233 of file lz4hc.c.

#define HASH_LOG   (DICTIONARY_LOGSIZE-1)

Definition at line 168 of file lz4hc.c.

#define HASH_MASK   (HASHTABLESIZE - 1)

Definition at line 170 of file lz4hc.c.

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

Definition at line 234 of file lz4hc.c.

Referenced by LZ4HC_Insert(), and LZ4HC_InsertAndFindBestMatch().

#define HASHTABLESIZE   (1 << HASH_LOG)

Definition at line 169 of file lz4hc.c.

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

Definition at line 180 of file lz4hc.c.

Referenced by LZ4_compressHCCtx().

#define LZ4_ARCH64   0

Definition at line 42 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 232 of file lz4hc.c.

Referenced by LZ4_encodeSequence().

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

Definition at line 107 of file lz4hc.c.

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

Definition at line 200 of file lz4hc.c.

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

Definition at line 199 of file lz4hc.c.

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

Definition at line 211 of file lz4hc.c.

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

Definition at line 231 of file lz4hc.c.

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

Definition at line 212 of file lz4hc.c.

Referenced by LZ4_encodeSequence().

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

Definition at line 172 of file lz4hc.c.

Referenced by LZ4HC_InsertAndFindBestMatch(), and LZ4HC_InsertAndGetWiderMatch().

#define MAXD   (1<<DICTIONARY_LOGSIZE)

Definition at line 164 of file lz4hc.c.

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

Definition at line 165 of file lz4hc.c.

#define MEM_INIT   memset

Definition at line 120 of file lz4hc.c.

Referenced by LZ4HC_Init().

#define MFLIMIT   (COPYLENGTH+MINMATCH)

Definition at line 181 of file lz4hc.c.

Referenced by LZ4_compressHCCtx().

#define MINLENGTH   (MFLIMIT+1)

Definition at line 182 of file lz4hc.c.

#define MINMATCH   4
#define ML_BITS   4

Definition at line 174 of file lz4hc.c.

Referenced by LZ4_compressHCCtx(), and LZ4_encodeSequence().

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

Definition at line 175 of file lz4hc.c.

Referenced by LZ4_compressHCCtx(), and LZ4_encodeSequence().

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

Definition at line 183 of file lz4hc.c.

Referenced by LZ4_compressHCCtx().

#define REPEAT_OPTIMIZATION
#define restrict

Definition at line 82 of file lz4hc.c.

#define RUN_BITS   (8-ML_BITS)

Definition at line 176 of file lz4hc.c.

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

Definition at line 177 of file lz4hc.c.

Referenced by LZ4_compressHCCtx(), and LZ4_encodeSequence().

#define S32   int32_t

Definition at line 137 of file lz4hc.c.

Referenced by LZ4_NbCommonBytes().

#define STEPSIZE   4

Definition at line 198 of file lz4hc.c.

Referenced by LZ4HC_CommonLength(), and LZ4HC_InsertAndGetWiderMatch().

#define U16   uint16_t
#define U32   uint32_t

Definition at line 136 of file lz4hc.c.

Referenced by LZ4_NbCommonBytes().

#define U64   uint64_t

Definition at line 138 of file lz4hc.c.

#define UARCH   U32

Definition at line 201 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

int LZ4_compressHC ( const char *  source,
char *  dest,
int  isize 
)

Definition at line 719 of file lz4hc.c.

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

Referenced by compress_file().

Here is the call graph for this function:

Here is the caller graph for this function:

int LZ4_compressHCCtx ( LZ4HC_Data_Structure ctx,
const char *  source,
char *  dest,
int  isize 
)

Definition at line 534 of file lz4hc.c.

References BYTE, LASTLITERALS, LZ4_encodeSequence(), LZ4HC_InsertAndFindBestMatch(), LZ4HC_InsertAndGetWiderMatch(), matchlimit, MFLIMIT, MINMATCH, ML_BITS, ML_MASK, NULL, OPTIMAL_ML, and RUN_MASK.

Referenced by LZ4_compressHC().

Here is the call graph for this function:

Here is the caller graph for this function:

static forceinline int LZ4_encodeSequence ( const BYTE **  ip,
BYTE **  op,
const BYTE **  anchor,
int  ml,
const BYTE ref 
)
static

Definition at line 500 of file lz4hc.c.

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

Referenced by LZ4_compressHCCtx().

Here is the caller graph for this function:

static int LZ4_NbCommonBytes ( register U32  val)
inlinestatic

Definition at line 277 of file lz4hc.c.

References S32, and U32.

Referenced by LZ4HC_CommonLength(), and LZ4HC_InsertAndGetWiderMatch().

Here is the caller graph for this function:

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

Definition at line 355 of file lz4hc.c.

References A16, A32, AARCH, LZ4_ARCH64, LZ4_NbCommonBytes(), STEPSIZE, and UARCH.

Referenced by LZ4HC_InsertAndFindBestMatch(), and LZ4HC_InsertAndGetWiderMatch().

Here is the call graph for this function:

Here is the caller graph for this function:

static void* LZ4HC_Create ( const BYTE base)
inlinestatic

Definition at line 319 of file lz4hc.c.

References ALLOCATOR, and LZ4HC_Init().

Referenced by LZ4_compressHC().

Here is the call graph for this function:

Here is the caller graph for this function:

static int LZ4HC_Free ( void **  LZ4HC_Data)
inlinestatic

Definition at line 328 of file lz4hc.c.

References FREEMEM, and NULL.

Referenced by LZ4_compressHC().

Here is the caller graph for this function:

static int LZ4HC_Init ( LZ4HC_Data_Structure hc4,
const BYTE base 
)
inlinestatic

Definition at line 309 of file lz4hc.c.

References LZ4HC_Data_Structure::base, LZ4HC_Data_Structure::chainTable, LZ4HC_Data_Structure::hashTable, LZ4_ARCH64, MEM_INIT, and LZ4HC_Data_Structure::nextToUpdate.

Referenced by LZ4HC_Create().

Here is the caller graph for this function:

static forceinline void LZ4HC_Insert ( LZ4HC_Data_Structure hc4,
const BYTE ip 
)
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

Definition at line 441 of file lz4hc.c.

References A16, A32, AARCH, LZ4HC_Data_Structure::base, LZ4HC_Data_Structure::chainTable, GETNEXT, HASH_POINTER, LZ4HC_Data_Structure::hashTable, HTYPE, INITBASE, LZ4_ARCH64, LZ4_NbCommonBytes(), LZ4HC_CommonLength(), LZ4HC_Insert(), MAX_DISTANCE, MAX_NB_ATTEMPTS, MINMATCH, STEPSIZE, U16, and UARCH.

Referenced by LZ4_compressHCCtx().

Here is the call graph for this function:

Here is the caller graph for this function: