Update files from GTKWave to the latest from svn
This commit is contained in:
parent
6183bf6cd7
commit
f7752caaac
|
|
@ -66,7 +66,7 @@ ifeq (@HAVE_LIBBZ2@,yes)
|
|||
O += sys_lxt.o lxt_write.o
|
||||
endif
|
||||
O += sys_lxt2.o lxt2_write.o
|
||||
O += sys_fst.o fstapi.o fastlz.o
|
||||
O += sys_fst.o fstapi.o fastlz.o lz4.o
|
||||
endif
|
||||
|
||||
# Object files for v2005_math.vpi
|
||||
|
|
|
|||
20
vpi/fastlz.c
20
vpi/fastlz.c
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
FastLZ - lightning-fast lossless compression library
|
||||
|
||||
Copyright (C) 2007 Ariya Hidayat (ariya@kde.org)
|
||||
|
|
@ -53,7 +53,7 @@
|
|||
#define FASTLZ_INLINE inline
|
||||
#elif defined(__BORLANDC__) || defined(_MSC_VER) || defined(__LCC__)
|
||||
#define FASTLZ_INLINE __inline
|
||||
#else
|
||||
#else
|
||||
#define FASTLZ_INLINE
|
||||
#endif
|
||||
|
||||
|
|
@ -87,7 +87,7 @@ int fastlz_decompress(const void* input, int length, void* output, int maxout);
|
|||
#define MAX_DISTANCE 8192
|
||||
|
||||
#if !defined(FASTLZ_STRICT_ALIGN)
|
||||
#define FASTLZ_READU16(p) *((const flzuint16*)(p))
|
||||
#define FASTLZ_READU16(p) *((const flzuint16*)(p))
|
||||
#else
|
||||
#define FASTLZ_READU16(p) ((p)[0] | (p)[1]<<8)
|
||||
#endif
|
||||
|
|
@ -215,7 +215,7 @@ static FASTLZ_INLINE int FASTLZ_COMPRESSOR(const void* input, int length, void*
|
|||
if(ip[0] == ip[-1] && FASTLZ_READU16(ip-1)==FASTLZ_READU16(ip+1))
|
||||
{
|
||||
distance = 1;
|
||||
ip += 3;
|
||||
/* ip += 3; */ /* scan-build, never used */
|
||||
ref = anchor - 1 + 3;
|
||||
goto match;
|
||||
}
|
||||
|
|
@ -233,7 +233,7 @@ static FASTLZ_INLINE int FASTLZ_COMPRESSOR(const void* input, int length, void*
|
|||
*hslot = anchor;
|
||||
|
||||
/* is this a match? check the first 3 bytes */
|
||||
if(distance==0 ||
|
||||
if(distance==0 ||
|
||||
#if FASTLZ_LEVEL==1
|
||||
(distance >= MAX_DISTANCE) ||
|
||||
#else
|
||||
|
|
@ -246,11 +246,11 @@ static FASTLZ_INLINE int FASTLZ_COMPRESSOR(const void* input, int length, void*
|
|||
/* far, needs at least 5-byte match */
|
||||
if(distance >= MAX_DISTANCE)
|
||||
{
|
||||
if(*ip++ != *ref++ || *ip++!= *ref++)
|
||||
if(*ip++ != *ref++ || *ip++!= *ref++)
|
||||
goto literal;
|
||||
len += 2;
|
||||
}
|
||||
|
||||
|
||||
match:
|
||||
#endif
|
||||
|
||||
|
|
@ -346,7 +346,7 @@ static FASTLZ_INLINE int FASTLZ_COMPRESSOR(const void* input, int length, void*
|
|||
while(len > MAX_LEN-2)
|
||||
{
|
||||
*op++ = (7 << 5) + (distance >> 8);
|
||||
*op++ = MAX_LEN - 2 - 7 -2;
|
||||
*op++ = MAX_LEN - 2 - 7 -2;
|
||||
*op++ = (distance & 255);
|
||||
len -= MAX_LEN-2;
|
||||
}
|
||||
|
|
@ -457,7 +457,7 @@ static FASTLZ_INLINE int FASTLZ_DECOMPRESSOR(const void* input, int length, void
|
|||
ref = op - ofs - MAX_DISTANCE;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef FASTLZ_SAFE
|
||||
if (FASTLZ_UNEXPECT_CONDITIONAL(op + len + 3 > op_limit))
|
||||
return 0;
|
||||
|
|
@ -530,7 +530,7 @@ static FASTLZ_INLINE int FASTLZ_DECOMPRESSOR(const void* input, int length, void
|
|||
return 0;
|
||||
#endif
|
||||
|
||||
*op++ = *ip++;
|
||||
*op++ = *ip++;
|
||||
for(--ctrl; ctrl; ctrl--)
|
||||
*op++ = *ip++;
|
||||
|
||||
|
|
|
|||
26
vpi/fastlz.h
26
vpi/fastlz.h
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
FastLZ - lightning-fast lossless compression library
|
||||
|
||||
Copyright (C) 2007 Ariya Hidayat (ariya@kde.org)
|
||||
|
|
@ -47,11 +47,11 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
/**
|
||||
Compress a block of data in the input buffer and returns the size of
|
||||
compressed block. The size of input buffer is specified by length. The
|
||||
Compress a block of data in the input buffer and returns the size of
|
||||
compressed block. The size of input buffer is specified by length. The
|
||||
minimum input buffer size is 16.
|
||||
|
||||
The output buffer must be at least 5% larger than the input buffer
|
||||
The output buffer must be at least 5% larger than the input buffer
|
||||
and can not be smaller than 66 bytes.
|
||||
|
||||
If the input is not compressible, the return value might be larger than
|
||||
|
|
@ -63,9 +63,9 @@ extern "C" {
|
|||
int fastlz_compress(const void* input, int length, void* output);
|
||||
|
||||
/**
|
||||
Decompress a block of compressed data and returns the size of the
|
||||
decompressed block. If error occurs, e.g. the compressed data is
|
||||
corrupted or the output buffer is not large enough, then 0 (zero)
|
||||
Decompress a block of compressed data and returns the size of the
|
||||
decompressed block. If error occurs, e.g. the compressed data is
|
||||
corrupted or the output buffer is not large enough, then 0 (zero)
|
||||
will be returned instead.
|
||||
|
||||
The input buffer and the output buffer can not overlap.
|
||||
|
|
@ -74,14 +74,14 @@ int fastlz_compress(const void* input, int length, void* output);
|
|||
more than what is specified in maxout.
|
||||
*/
|
||||
|
||||
int fastlz_decompress(const void* input, int length, void* output, int maxout);
|
||||
int fastlz_decompress(const void* input, int length, void* output, int maxout);
|
||||
|
||||
/**
|
||||
Compress a block of data in the input buffer and returns the size of
|
||||
compressed block. The size of input buffer is specified by length. The
|
||||
Compress a block of data in the input buffer and returns the size of
|
||||
compressed block. The size of input buffer is specified by length. The
|
||||
minimum input buffer size is 16.
|
||||
|
||||
The output buffer must be at least 5% larger than the input buffer
|
||||
The output buffer must be at least 5% larger than the input buffer
|
||||
and can not be smaller than 66 bytes.
|
||||
|
||||
If the input is not compressible, the return value might be larger than
|
||||
|
|
@ -89,14 +89,14 @@ int fastlz_decompress(const void* input, int length, void* output, int maxout);
|
|||
|
||||
The input buffer and the output buffer can not overlap.
|
||||
|
||||
Compression level can be specified in parameter level. At the moment,
|
||||
Compression level can be specified in parameter level. At the moment,
|
||||
only level 1 and level 2 are supported.
|
||||
Level 1 is the fastest compression and generally useful for short data.
|
||||
Level 2 is slightly slower but it gives better compression ratio.
|
||||
|
||||
Note that the compressed data, regardless of the level, can always be
|
||||
decompressed using the function fastlz_decompress above.
|
||||
*/
|
||||
*/
|
||||
|
||||
int fastlz_compress_level(int level, const void* input, int length, void* output);
|
||||
|
||||
|
|
|
|||
7410
vpi/fstapi.c
7410
vpi/fstapi.c
File diff suppressed because it is too large
Load Diff
284
vpi/fstapi.h
284
vpi/fstapi.h
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2009-2013 Tony Bybell.
|
||||
* Copyright (c) 2009-2014 Tony Bybell.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
|
|
@ -40,26 +40,35 @@ extern "C" {
|
|||
|
||||
typedef uint32_t fstHandle;
|
||||
|
||||
enum fstWriterPackType {
|
||||
FST_WR_PT_ZLIB = 0,
|
||||
FST_WR_PT_FASTLZ = 1,
|
||||
FST_WR_PT_LZ4 = 2
|
||||
};
|
||||
|
||||
enum fstFileType {
|
||||
FST_FT_MIN = 0,
|
||||
|
||||
FST_FT_VERILOG = 0,
|
||||
FST_FT_VHDL = 1,
|
||||
FST_FT_VERILOG_VHDL = 2,
|
||||
FST_FT_VERILOG_VHDL = 2,
|
||||
|
||||
FST_FT_MAX = 2
|
||||
};
|
||||
|
||||
enum fstBlockType {
|
||||
FST_BL_HDR = 0,
|
||||
FST_BL_HDR = 0,
|
||||
FST_BL_VCDATA = 1,
|
||||
FST_BL_BLACKOUT = 2,
|
||||
FST_BL_BLACKOUT = 2,
|
||||
FST_BL_GEOM = 3,
|
||||
FST_BL_HIER = 4,
|
||||
FST_BL_VCDATA_DYN_ALIAS = 5,
|
||||
FST_BL_HIER_LZ4 = 6,
|
||||
FST_BL_HIER_LZ4DUO = 7,
|
||||
FST_BL_VCDATA_DYN_ALIAS2 = 8,
|
||||
|
||||
FST_BL_ZWRAPPER = 254, /* indicates that whole trace is gz wrapped */
|
||||
FST_BL_SKIP = 255 /* used while block is being written */
|
||||
FST_BL_ZWRAPPER = 254, /* indicates that whole trace is gz wrapped */
|
||||
FST_BL_SKIP = 255 /* used while block is being written */
|
||||
};
|
||||
|
||||
enum fstScopeType {
|
||||
|
|
@ -99,7 +108,7 @@ enum fstScopeType {
|
|||
};
|
||||
|
||||
enum fstVarType {
|
||||
FST_VT_MIN = 0, /* start of vartypes */
|
||||
FST_VT_MIN = 0, /* start of vartypes */
|
||||
|
||||
FST_VT_VCD_EVENT = 0,
|
||||
FST_VT_VCD_INTEGER = 1,
|
||||
|
|
@ -109,7 +118,7 @@ enum fstVarType {
|
|||
FST_VT_VCD_REG = 5,
|
||||
FST_VT_VCD_SUPPLY0 = 6,
|
||||
FST_VT_VCD_SUPPLY1 = 7,
|
||||
FST_VT_VCD_TIME = 8,
|
||||
FST_VT_VCD_TIME = 8,
|
||||
FST_VT_VCD_TRI = 9,
|
||||
FST_VT_VCD_TRIAND = 10,
|
||||
FST_VT_VCD_TRIOR = 11,
|
||||
|
|
@ -120,21 +129,21 @@ enum fstVarType {
|
|||
FST_VT_VCD_WIRE = 16,
|
||||
FST_VT_VCD_WOR = 17,
|
||||
FST_VT_VCD_PORT = 18,
|
||||
FST_VT_VCD_SPARRAY = 19, /* used to define the rownum (index) port for a sparse array */
|
||||
FST_VT_VCD_SPARRAY = 19, /* used to define the rownum (index) port for a sparse array */
|
||||
FST_VT_VCD_REALTIME = 20,
|
||||
|
||||
FST_VT_GEN_STRING = 21, /* generic string type (max len is defined dynamically via fstWriterEmitVariableLengthValueChange) */
|
||||
FST_VT_GEN_STRING = 21, /* generic string type (max len is defined dynamically via fstWriterEmitVariableLengthValueChange) */
|
||||
|
||||
FST_VT_SV_BIT = 22,
|
||||
FST_VT_SV_LOGIC = 23,
|
||||
FST_VT_SV_INT = 24, /* declare as size = 32 */
|
||||
FST_VT_SV_SHORTINT = 25, /* declare as size = 16 */
|
||||
FST_VT_SV_LONGINT = 26, /* declare as size = 64 */
|
||||
FST_VT_SV_BYTE = 27, /* declare as size = 8 */
|
||||
FST_VT_SV_ENUM = 28, /* declare as appropriate type range */
|
||||
FST_VT_SV_SHORTREAL = 29, /* declare and emit same as FST_VT_VCD_REAL (needs to be emitted as double, not a float) */
|
||||
FST_VT_SV_INT = 24, /* declare as size = 32 */
|
||||
FST_VT_SV_SHORTINT = 25, /* declare as size = 16 */
|
||||
FST_VT_SV_LONGINT = 26, /* declare as size = 64 */
|
||||
FST_VT_SV_BYTE = 27, /* declare as size = 8 */
|
||||
FST_VT_SV_ENUM = 28, /* declare as appropriate type range */
|
||||
FST_VT_SV_SHORTREAL = 29, /* declare and emit same as FST_VT_VCD_REAL (needs to be emitted as double, not a float) */
|
||||
|
||||
FST_VT_MAX = 29 /* end of vartypes */
|
||||
FST_VT_MAX = 29 /* end of vartypes */
|
||||
};
|
||||
|
||||
enum fstVarDir {
|
||||
|
|
@ -165,7 +174,7 @@ enum fstHierType {
|
|||
enum fstAttrType {
|
||||
FST_AT_MIN = 0,
|
||||
|
||||
FST_AT_MISC = 0, /* self-contained: does not need matching FST_HT_ATTREND */
|
||||
FST_AT_MISC = 0, /* self-contained: does not need matching FST_HT_ATTREND */
|
||||
FST_AT_ARRAY = 1,
|
||||
FST_AT_ENUM = 2,
|
||||
FST_AT_PACK = 3,
|
||||
|
|
@ -176,9 +185,9 @@ enum fstAttrType {
|
|||
enum fstMiscType {
|
||||
FST_MT_MIN = 0,
|
||||
|
||||
FST_MT_COMMENT = 0, /* use fstWriterSetComment() to emit */
|
||||
FST_MT_ENVVAR = 1, /* use fstWriterSetEnvVar() to emit */
|
||||
FST_MT_SUPVAR = 2, /* use fstWriterCreateVar2() to emit */
|
||||
FST_MT_COMMENT = 0, /* use fstWriterSetComment() to emit */
|
||||
FST_MT_ENVVAR = 1, /* use fstWriterSetEnvVar() to emit */
|
||||
FST_MT_SUPVAR = 2, /* use fstWriterCreateVar2() to emit */
|
||||
FST_MT_PATHNAME = 3, /* reserved for fstWriterSetSourceStem() string -> number management */
|
||||
FST_MT_SOURCESTEM = 4, /* use fstWriterSetSourceStem() to emit */
|
||||
FST_MT_SOURCEISTEM = 5, /* use fstWriterSetSourceInstantiationStem() to emit */
|
||||
|
|
@ -265,7 +274,7 @@ enum fstSupplementalDataType {
|
|||
FST_SDT_MAX = 16,
|
||||
|
||||
FST_SDT_SVT_SHIFT_COUNT = 10, /* FST_SVT_* is ORed in by fstWriterCreateVar2() to the left after shifting FST_SDT_SVT_SHIFT_COUNT */
|
||||
FST_SDT_ABS_MAX = ((1<<(FST_SDT_SVT_SHIFT_COUNT))-1)
|
||||
FST_SDT_ABS_MAX = ((1<<(FST_SDT_SVT_SHIFT_COUNT))-1)
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -274,140 +283,141 @@ struct fstHier
|
|||
unsigned char htyp;
|
||||
|
||||
union {
|
||||
/* if htyp == FST_HT_SCOPE */
|
||||
struct fstHierScope {
|
||||
unsigned char typ; /* FST_ST_MIN ... FST_ST_MAX */
|
||||
const char *name;
|
||||
const char *component;
|
||||
uint32_t name_length; /* strlen(u.scope.name) */
|
||||
uint32_t component_length; /* strlen(u.scope.component) */
|
||||
} scope;
|
||||
/* if htyp == FST_HT_SCOPE */
|
||||
struct fstHierScope {
|
||||
unsigned char typ; /* FST_ST_MIN ... FST_ST_MAX */
|
||||
const char *name;
|
||||
const char *component;
|
||||
uint32_t name_length; /* strlen(u.scope.name) */
|
||||
uint32_t component_length; /* strlen(u.scope.component) */
|
||||
} scope;
|
||||
|
||||
/* if htyp == FST_HT_VAR */
|
||||
struct fstHierVar {
|
||||
unsigned char typ; /* FST_VT_MIN ... FST_VT_MAX */
|
||||
unsigned char direction; /* FST_VD_MIN ... FST_VD_MAX */
|
||||
unsigned char svt_workspace; /* zeroed out by FST reader, for client code use */
|
||||
unsigned char sdt_workspace; /* zeroed out by FST reader, for client code use */
|
||||
unsigned int sxt_workspace; /* zeroed out by FST reader, for client code use */
|
||||
const char *name;
|
||||
uint32_t length;
|
||||
fstHandle handle;
|
||||
uint32_t name_length; /* strlen(u.var.name) */
|
||||
unsigned is_alias : 1;
|
||||
} var;
|
||||
/* if htyp == FST_HT_VAR */
|
||||
struct fstHierVar {
|
||||
unsigned char typ; /* FST_VT_MIN ... FST_VT_MAX */
|
||||
unsigned char direction; /* FST_VD_MIN ... FST_VD_MAX */
|
||||
unsigned char svt_workspace; /* zeroed out by FST reader, for client code use */
|
||||
unsigned char sdt_workspace; /* zeroed out by FST reader, for client code use */
|
||||
unsigned int sxt_workspace; /* zeroed out by FST reader, for client code use */
|
||||
const char *name;
|
||||
uint32_t length;
|
||||
fstHandle handle;
|
||||
uint32_t name_length; /* strlen(u.var.name) */
|
||||
unsigned is_alias : 1;
|
||||
} var;
|
||||
|
||||
/* if htyp == FST_HT_ATTRBEGIN */
|
||||
struct fstHierAttr {
|
||||
unsigned char typ; /* FST_AT_MIN ... FST_AT_MAX */
|
||||
unsigned char subtype; /* from fstMiscType, fstArrayType, fstEnumValueType, fstPackType */
|
||||
const char *name;
|
||||
uint64_t arg; /* number of array elements, struct members, or some other payload (possibly ignored) */
|
||||
uint64_t arg_from_name; /* for when name is overloaded as a variable-length integer (FST_AT_MISC + FST_MT_SOURCESTEM) */
|
||||
uint32_t name_length; /* strlen(u.attr.name) */
|
||||
} attr;
|
||||
} u;
|
||||
/* if htyp == FST_HT_ATTRBEGIN */
|
||||
struct fstHierAttr {
|
||||
unsigned char typ; /* FST_AT_MIN ... FST_AT_MAX */
|
||||
unsigned char subtype; /* from fstMiscType, fstArrayType, fstEnumValueType, fstPackType */
|
||||
const char *name;
|
||||
uint64_t arg; /* number of array elements, struct members, or some other payload (possibly ignored) */
|
||||
uint64_t arg_from_name; /* for when name is overloaded as a variable-length integer (FST_AT_MISC + FST_MT_SOURCESTEM) */
|
||||
uint32_t name_length; /* strlen(u.attr.name) */
|
||||
} attr;
|
||||
} u;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* writer functions
|
||||
*/
|
||||
void fstWriterClose(void *ctx);
|
||||
void * fstWriterCreate(const char *nam, int use_compressed_hier);
|
||||
/* used for Verilog/SV */
|
||||
fstHandle fstWriterCreateVar(void *ctx, enum fstVarType vt, enum fstVarDir vd,
|
||||
uint32_t len, const char *nam, fstHandle aliasHandle);
|
||||
/* future expansion for VHDL and other languages. The variable type, data type, etc map onto
|
||||
the current Verilog/SV one. The "type" string is optional for a more verbose or custom description */
|
||||
fstHandle fstWriterCreateVar2(void *ctx, enum fstVarType vt, enum fstVarDir vd,
|
||||
uint32_t len, const char *nam, fstHandle aliasHandle,
|
||||
const char *type, enum fstSupplementalVarType svt, enum fstSupplementalDataType sdt);
|
||||
void fstWriterEmitValueChange(void *ctx, fstHandle handle, const void *val);
|
||||
void fstWriterEmitVariableLengthValueChange(void *ctx, fstHandle handle, const void *val, uint32_t len);
|
||||
void fstWriterEmitDumpActive(void *ctx, int enable);
|
||||
void fstWriterEmitTimeChange(void *ctx, uint64_t tim);
|
||||
void fstWriterFlushContext(void *ctx);
|
||||
int fstWriterGetDumpSizeLimitReached(void *ctx);
|
||||
int fstWriterGetFseekFailed(void *ctx);
|
||||
void fstWriterSetAttrBegin(void *ctx, enum fstAttrType attrtype, int subtype,
|
||||
const char *attrname, uint64_t arg);
|
||||
void fstWriterSetAttrEnd(void *ctx);
|
||||
void fstWriterSetComment(void *ctx, const char *comm);
|
||||
void fstWriterSetDate(void *ctx, const char *dat);
|
||||
void fstWriterSetDumpSizeLimit(void *ctx, uint64_t numbytes);
|
||||
void fstWriterSetEnvVar(void *ctx, const char *envvar);
|
||||
void fstWriterSetFileType(void *ctx, enum fstFileType filetype);
|
||||
void fstWriterSetPackType(void *ctx, int typ); /* type = 0 (libz), 1 (fastlz) */
|
||||
void fstWriterSetParallelMode(void *ctx, int enable);
|
||||
void fstWriterSetRepackOnClose(void *ctx, int enable); /* type = 0 (none), 1 (libz) */
|
||||
void fstWriterSetScope(void *ctx, enum fstScopeType scopetype,
|
||||
const char *scopename, const char *scopecomp);
|
||||
void fstWriterSetSourceInstantiationStem(void *ctx, const char *path, unsigned int line, unsigned int use_realpath);
|
||||
void fstWriterSetSourceStem(void *ctx, const char *path, unsigned int line, unsigned int use_realpath);
|
||||
void fstWriterSetTimescale(void *ctx, int ts);
|
||||
void fstWriterSetTimescaleFromString(void *ctx, const char *s);
|
||||
void fstWriterSetTimezero(void *ctx, int64_t tim);
|
||||
void fstWriterSetUpscope(void *ctx);
|
||||
void fstWriterSetVersion(void *ctx, const char *vers);
|
||||
void fstWriterClose(void *ctx);
|
||||
void * fstWriterCreate(const char *nam, int use_compressed_hier);
|
||||
/* used for Verilog/SV */
|
||||
fstHandle fstWriterCreateVar(void *ctx, enum fstVarType vt, enum fstVarDir vd,
|
||||
uint32_t len, const char *nam, fstHandle aliasHandle);
|
||||
/* future expansion for VHDL and other languages. The variable type, data type, etc map onto
|
||||
the current Verilog/SV one. The "type" string is optional for a more verbose or custom description */
|
||||
fstHandle fstWriterCreateVar2(void *ctx, enum fstVarType vt, enum fstVarDir vd,
|
||||
uint32_t len, const char *nam, fstHandle aliasHandle,
|
||||
const char *type, enum fstSupplementalVarType svt, enum fstSupplementalDataType sdt);
|
||||
void fstWriterEmitValueChange(void *ctx, fstHandle handle, const void *val);
|
||||
void fstWriterEmitVariableLengthValueChange(void *ctx, fstHandle handle, const void *val, uint32_t len);
|
||||
void fstWriterEmitDumpActive(void *ctx, int enable);
|
||||
void fstWriterEmitTimeChange(void *ctx, uint64_t tim);
|
||||
void fstWriterFlushContext(void *ctx);
|
||||
int fstWriterGetDumpSizeLimitReached(void *ctx);
|
||||
int fstWriterGetFseekFailed(void *ctx);
|
||||
void fstWriterSetAttrBegin(void *ctx, enum fstAttrType attrtype, int subtype,
|
||||
const char *attrname, uint64_t arg);
|
||||
void fstWriterSetAttrEnd(void *ctx);
|
||||
void fstWriterSetComment(void *ctx, const char *comm);
|
||||
void fstWriterSetDate(void *ctx, const char *dat);
|
||||
void fstWriterSetDumpSizeLimit(void *ctx, uint64_t numbytes);
|
||||
void fstWriterSetEnvVar(void *ctx, const char *envvar);
|
||||
void fstWriterSetFileType(void *ctx, enum fstFileType filetype);
|
||||
void fstWriterSetPackType(void *ctx, enum fstWriterPackType typ);
|
||||
void fstWriterSetParallelMode(void *ctx, int enable);
|
||||
void fstWriterSetRepackOnClose(void *ctx, int enable); /* type = 0 (none), 1 (libz) */
|
||||
void fstWriterSetScope(void *ctx, enum fstScopeType scopetype,
|
||||
const char *scopename, const char *scopecomp);
|
||||
void fstWriterSetSourceInstantiationStem(void *ctx, const char *path, unsigned int line, unsigned int use_realpath);
|
||||
void fstWriterSetSourceStem(void *ctx, const char *path, unsigned int line, unsigned int use_realpath);
|
||||
void fstWriterSetTimescale(void *ctx, int ts);
|
||||
void fstWriterSetTimescaleFromString(void *ctx, const char *s);
|
||||
void fstWriterSetTimezero(void *ctx, int64_t tim);
|
||||
void fstWriterSetUpscope(void *ctx);
|
||||
void fstWriterSetVersion(void *ctx, const char *vers);
|
||||
|
||||
|
||||
/*
|
||||
* reader functions
|
||||
*/
|
||||
void fstReaderClose(void *ctx);
|
||||
void fstReaderClrFacProcessMask(void *ctx, fstHandle facidx);
|
||||
void fstReaderClrFacProcessMaskAll(void *ctx);
|
||||
uint64_t fstReaderGetAliasCount(void *ctx);
|
||||
const char * fstReaderGetCurrentFlatScope(void *ctx);
|
||||
void * fstReaderGetCurrentScopeUserInfo(void *ctx);
|
||||
int fstReaderGetCurrentScopeLen(void *ctx);
|
||||
const char * fstReaderGetDateString(void *ctx);
|
||||
int fstReaderGetDoubleEndianMatchState(void *ctx);
|
||||
uint64_t fstReaderGetDumpActivityChangeTime(void *ctx, uint32_t idx);
|
||||
unsigned char fstReaderGetDumpActivityChangeValue(void *ctx, uint32_t idx);
|
||||
uint64_t fstReaderGetEndTime(void *ctx);
|
||||
int fstReaderGetFacProcessMask(void *ctx, fstHandle facidx);
|
||||
int fstReaderGetFileType(void *ctx);
|
||||
int fstReaderGetFseekFailed(void *ctx);
|
||||
fstHandle fstReaderGetMaxHandle(void *ctx);
|
||||
uint64_t fstReaderGetMemoryUsedByWriter(void *ctx);
|
||||
uint32_t fstReaderGetNumberDumpActivityChanges(void *ctx);
|
||||
uint64_t fstReaderGetScopeCount(void *ctx);
|
||||
uint64_t fstReaderGetStartTime(void *ctx);
|
||||
signed char fstReaderGetTimescale(void *ctx);
|
||||
int64_t fstReaderGetTimezero(void *ctx);
|
||||
uint64_t fstReaderGetValueChangeSectionCount(void *ctx);
|
||||
char * fstReaderGetValueFromHandleAtTime(void *ctx, uint64_t tim, fstHandle facidx, char *buf);
|
||||
uint64_t fstReaderGetVarCount(void *ctx);
|
||||
const char * fstReaderGetVersionString(void *ctx);
|
||||
void fstReaderClose(void *ctx);
|
||||
void fstReaderClrFacProcessMask(void *ctx, fstHandle facidx);
|
||||
void fstReaderClrFacProcessMaskAll(void *ctx);
|
||||
uint64_t fstReaderGetAliasCount(void *ctx);
|
||||
const char * fstReaderGetCurrentFlatScope(void *ctx);
|
||||
void * fstReaderGetCurrentScopeUserInfo(void *ctx);
|
||||
int fstReaderGetCurrentScopeLen(void *ctx);
|
||||
const char * fstReaderGetDateString(void *ctx);
|
||||
int fstReaderGetDoubleEndianMatchState(void *ctx);
|
||||
uint64_t fstReaderGetDumpActivityChangeTime(void *ctx, uint32_t idx);
|
||||
unsigned char fstReaderGetDumpActivityChangeValue(void *ctx, uint32_t idx);
|
||||
uint64_t fstReaderGetEndTime(void *ctx);
|
||||
int fstReaderGetFacProcessMask(void *ctx, fstHandle facidx);
|
||||
int fstReaderGetFileType(void *ctx);
|
||||
int fstReaderGetFseekFailed(void *ctx);
|
||||
fstHandle fstReaderGetMaxHandle(void *ctx);
|
||||
uint64_t fstReaderGetMemoryUsedByWriter(void *ctx);
|
||||
uint32_t fstReaderGetNumberDumpActivityChanges(void *ctx);
|
||||
uint64_t fstReaderGetScopeCount(void *ctx);
|
||||
uint64_t fstReaderGetStartTime(void *ctx);
|
||||
signed char fstReaderGetTimescale(void *ctx);
|
||||
int64_t fstReaderGetTimezero(void *ctx);
|
||||
uint64_t fstReaderGetValueChangeSectionCount(void *ctx);
|
||||
char * fstReaderGetValueFromHandleAtTime(void *ctx, uint64_t tim, fstHandle facidx, char *buf);
|
||||
uint64_t fstReaderGetVarCount(void *ctx);
|
||||
const char * fstReaderGetVersionString(void *ctx);
|
||||
struct fstHier *fstReaderIterateHier(void *ctx);
|
||||
int fstReaderIterateHierRewind(void *ctx);
|
||||
int fstReaderIterBlocks(void *ctx,
|
||||
void (*value_change_callback)(void *user_callback_data_pointer, uint64_t time, fstHandle facidx, const unsigned char *value),
|
||||
void *user_callback_data_pointer, FILE *vcdhandle);
|
||||
int fstReaderIterBlocks2(void *ctx,
|
||||
void (*value_change_callback)(void *user_callback_data_pointer, uint64_t time, fstHandle facidx, const unsigned char *value),
|
||||
void (*value_change_callback_varlen)(void *user_callback_data_pointer, uint64_t time, fstHandle facidx, const unsigned char *value, uint32_t len),
|
||||
void *user_callback_data_pointer, FILE *vcdhandle);
|
||||
void fstReaderIterBlocksSetNativeDoublesOnCallback(void *ctx, int enable);
|
||||
void * fstReaderOpen(const char *nam);
|
||||
void * fstReaderOpenForUtilitiesOnly(void);
|
||||
const char * fstReaderPopScope(void *ctx);
|
||||
int fstReaderProcessHier(void *ctx, FILE *vcdhandle);
|
||||
const char * fstReaderPushScope(void *ctx, const char *nam, void *user_info);
|
||||
void fstReaderResetScope(void *ctx);
|
||||
void fstReaderSetFacProcessMask(void *ctx, fstHandle facidx);
|
||||
void fstReaderSetFacProcessMaskAll(void *ctx);
|
||||
void fstReaderSetLimitTimeRange(void *ctx, uint64_t start_time, uint64_t end_time);
|
||||
void fstReaderSetUnlimitedTimeRange(void *ctx);
|
||||
int fstReaderIterateHierRewind(void *ctx);
|
||||
int fstReaderIterBlocks(void *ctx,
|
||||
void (*value_change_callback)(void *user_callback_data_pointer, uint64_t time, fstHandle facidx, const unsigned char *value),
|
||||
void *user_callback_data_pointer, FILE *vcdhandle);
|
||||
int fstReaderIterBlocks2(void *ctx,
|
||||
void (*value_change_callback)(void *user_callback_data_pointer, uint64_t time, fstHandle facidx, const unsigned char *value),
|
||||
void (*value_change_callback_varlen)(void *user_callback_data_pointer, uint64_t time, fstHandle facidx, const unsigned char *value, uint32_t len),
|
||||
void *user_callback_data_pointer, FILE *vcdhandle);
|
||||
void fstReaderIterBlocksSetNativeDoublesOnCallback(void *ctx, int enable);
|
||||
void * fstReaderOpen(const char *nam);
|
||||
void * fstReaderOpenForUtilitiesOnly(void);
|
||||
const char * fstReaderPopScope(void *ctx);
|
||||
int fstReaderProcessHier(void *ctx, FILE *vcdhandle);
|
||||
const char * fstReaderPushScope(void *ctx, const char *nam, void *user_info);
|
||||
void fstReaderResetScope(void *ctx);
|
||||
void fstReaderSetFacProcessMask(void *ctx, fstHandle facidx);
|
||||
void fstReaderSetFacProcessMaskAll(void *ctx);
|
||||
void fstReaderSetLimitTimeRange(void *ctx, uint64_t start_time, uint64_t end_time);
|
||||
void fstReaderSetUnlimitedTimeRange(void *ctx);
|
||||
void fstReaderSetVcdExtensions(void *ctx, int enable);
|
||||
|
||||
|
||||
/*
|
||||
* utility functions
|
||||
*/
|
||||
int fstUtilityBinToEsc(unsigned char *d, unsigned char *s, int len);
|
||||
int fstUtilityEscToBin(unsigned char *d, unsigned char *s, int len);
|
||||
int fstUtilityBinToEsc(unsigned char *d, unsigned char *s, int len);
|
||||
int fstUtilityEscToBin(unsigned char *d, unsigned char *s, int len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
120
vpi/lxt2_write.c
120
vpi/lxt2_write.c
|
|
@ -30,18 +30,18 @@
|
|||
|
||||
static char *lxt2_wr_vcd_truncate_bitvec(char *s)
|
||||
{
|
||||
char l, r;
|
||||
char l, r;
|
||||
|
||||
r=*s;
|
||||
if(r=='1')
|
||||
if(r=='1')
|
||||
{
|
||||
return s;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
s++;
|
||||
}
|
||||
|
||||
|
||||
for(;;s++)
|
||||
{
|
||||
l=r; r=*s;
|
||||
|
|
@ -50,7 +50,7 @@ for(;;s++)
|
|||
if(l!=r)
|
||||
{
|
||||
return(((l=='0')&&(r=='1'))?s:s-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -155,7 +155,7 @@ static lxt2_wr_ds_Tree * lxt2_wr_ds_insert(granmsk_t i, lxt2_wr_ds_Tree * t, int
|
|||
/* Insert i into the tree t, unless it's already there. */
|
||||
/* Return a pointer to the resulting tree. */
|
||||
lxt2_wr_ds_Tree * n;
|
||||
|
||||
|
||||
n = (lxt2_wr_ds_Tree *) calloc (1, sizeof (lxt2_wr_ds_Tree));
|
||||
if (n == NULL) {
|
||||
fprintf(stderr, "ds_insert: ran out of memory, exiting.\n");
|
||||
|
|
@ -245,7 +245,7 @@ static lxt2_wr_dslxt_Tree * lxt2_wr_dslxt_insert(char *i, lxt2_wr_dslxt_Tree * t
|
|||
/* Return a pointer to the resulting tree. */
|
||||
lxt2_wr_dslxt_Tree * n;
|
||||
int dir;
|
||||
|
||||
|
||||
n = (lxt2_wr_dslxt_Tree *) calloc (1, sizeof (lxt2_wr_dslxt_Tree));
|
||||
if (n == NULL) {
|
||||
fprintf(stderr, "dslxt_insert: ran out of memory, exiting.\n");
|
||||
|
|
@ -281,7 +281,7 @@ static lxt2_wr_dslxt_Tree * lxt2_wr_dslxt_insert(char *i, lxt2_wr_dslxt_Tree * t
|
|||
/*
|
||||
* functions which emit various big endian
|
||||
* data to a file
|
||||
*/
|
||||
*/
|
||||
static int lxt2_wr_emit_u8(struct lxt2_wr_trace *lt, int value)
|
||||
{
|
||||
unsigned char buf[1];
|
||||
|
|
@ -340,7 +340,7 @@ return(rc);
|
|||
* data to a file. (lt->position needs to be
|
||||
* fixed up on gzclose so the tables don't
|
||||
* get out of sync!)
|
||||
*/
|
||||
*/
|
||||
static int gzwrite_buffered(struct lxt2_wr_trace *lt)
|
||||
{
|
||||
int rc = 1;
|
||||
|
|
@ -446,7 +446,7 @@ return(rc);
|
|||
static int lxt2_wr_emit_stringz(struct lxt2_wr_trace *lt, char *value)
|
||||
{
|
||||
int rc=1;
|
||||
do
|
||||
do
|
||||
{
|
||||
rc&=lxt2_wr_emit_u8z(lt, *value);
|
||||
} while(*(value++));
|
||||
|
|
@ -473,7 +473,7 @@ for(p=s;*p;p++)
|
|||
{
|
||||
h=h^(g>>24);
|
||||
h=h^g;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
h^=h2; /* combine the two hashes */
|
||||
|
|
@ -500,17 +500,17 @@ struct lxt2_wr_symbol *temp;
|
|||
|
||||
hv=lxt2_wr_hash(s);
|
||||
if(!(temp=lt->sym[hv])) return(NULL); /* no hash entry, add here wanted to add */
|
||||
|
||||
|
||||
while(temp)
|
||||
{
|
||||
if(!strcmp(temp->name,s))
|
||||
{
|
||||
return(temp); /* in table already */
|
||||
return(temp); /* in table already */
|
||||
}
|
||||
if(!temp->next) break;
|
||||
temp=temp->next;
|
||||
}
|
||||
|
||||
|
||||
return(NULL); /* not found, add here if you want to add*/
|
||||
}
|
||||
|
||||
|
|
@ -535,13 +535,13 @@ if(lt->compress_fac_str)
|
|||
lxt2_wr_emit_u16z(lt, i);
|
||||
lxt2_wr_emit_stringz(lt, str+i);
|
||||
free(lt->compress_fac_str);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lxt2_wr_emit_u16z(lt, 0);
|
||||
lxt2_wr_emit_stringz(lt, str);
|
||||
}
|
||||
|
||||
|
||||
lt->compress_fac_str = (char *) malloc((lt->compress_fac_len=len)+1);
|
||||
strcpy(lt->compress_fac_str, str);
|
||||
}
|
||||
|
|
@ -567,10 +567,10 @@ while(lastch!=s->name)
|
|||
|
||||
if(*lastch=='[')
|
||||
{
|
||||
*lastch=0x00;
|
||||
*lastch=0x00;
|
||||
return;
|
||||
}
|
||||
lastch--;
|
||||
lastch--;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
@ -597,19 +597,19 @@ if((lt)&&(lt->numfacs))
|
|||
strip_brack(s);
|
||||
s=s->symchain;
|
||||
}
|
||||
else
|
||||
else
|
||||
for(i=0;i<lt->numfacs;i++)
|
||||
{
|
||||
lt->sorted_facs[lt->numfacs - i - 1] = s; /* facs were chained backwards so reverse to restore bitslicing */
|
||||
s=s->symchain;
|
||||
}
|
||||
}
|
||||
wave_msort(lt->sorted_facs, lt->numfacs);
|
||||
|
||||
if(lt->partial_preference)
|
||||
{
|
||||
/* move preferenced facs up */
|
||||
struct lxt2_wr_symbol **prefcache = aliascache;
|
||||
int prefs_encountered = 0;
|
||||
int prefs_encountered = 0;
|
||||
|
||||
facs_encountered = 0;
|
||||
for(i=0;i<lt->numfacs;i++)
|
||||
|
|
@ -700,7 +700,7 @@ if((lt)&&(lt->numfacs))
|
|||
free(lt->compress_fac_str); lt->compress_fac_str=NULL;
|
||||
lt->compress_fac_len=0;
|
||||
lt->zfacname_predec_size = lt->zpackcount;
|
||||
|
||||
|
||||
gzflush_buffered(lt, 1);
|
||||
fseeko(lt->handle, 0L, SEEK_END);
|
||||
lt->position=ftello(lt->handle);
|
||||
|
|
@ -746,7 +746,7 @@ if((lt)&&(lt->numfacs))
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
/*
|
||||
* initialize the trace and get back an lt context
|
||||
*/
|
||||
struct lxt2_wr_trace *lxt2_wr_init(const char *name)
|
||||
|
|
@ -805,15 +805,15 @@ if(lt)
|
|||
{
|
||||
lt->partial = 1;
|
||||
lt->partial_zip = (zipmode != 0);
|
||||
lt->partial_iter = LXT2_WR_PARTIAL_SIZE;
|
||||
lt->partial_iter = LXT2_WR_PARTIAL_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
void lxt2_wr_set_partial_preference(struct lxt2_wr_trace *lt, const char *name)
|
||||
{
|
||||
struct lxt2_wr_symbol *s;
|
||||
|
||||
if((lt)&&(name)&&(!lt->sorted_facs))
|
||||
|
||||
if((lt)&&(name)&&(!lt->sorted_facs))
|
||||
{
|
||||
s=lxt2_wr_symfind(lt, name);
|
||||
if(s)
|
||||
|
|
@ -852,8 +852,8 @@ if(lt)
|
|||
/*
|
||||
* set initial value of trace (0, 1, x, z) only legal vals
|
||||
*/
|
||||
void lxt2_wr_set_initial_value(struct lxt2_wr_trace *lt, char value)
|
||||
{
|
||||
void lxt2_wr_set_initial_value(struct lxt2_wr_trace *lt, char value)
|
||||
{
|
||||
if(lt)
|
||||
{
|
||||
switch(value)
|
||||
|
|
@ -991,7 +991,7 @@ return(sa);
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
/*
|
||||
* set current time/granule updating
|
||||
*/
|
||||
int lxt2_wr_inc_time_by_delta(struct lxt2_wr_trace *lt, unsigned int timeval)
|
||||
|
|
@ -1221,7 +1221,7 @@ if(using_partial)
|
|||
lxt2_wr_emit_u32(lt, partial_length+9); /* size of this section (uncompressed) */
|
||||
lxt2_wr_emit_u32(lt, iter); /* begin iter of section */
|
||||
fflush(lt->handle);
|
||||
|
||||
|
||||
lt->zhandle = gzdopen(dup(fileno(lt->handle)), lt->zmode);
|
||||
lt->zpackcount = 0;
|
||||
}
|
||||
|
|
@ -1331,7 +1331,7 @@ if((lt->timegranule>=lt->maxgranule)||(do_finalize)||(early_flush))
|
|||
lxt2_wr_emit_u32(lt, 0); /* size of this section (uncompressed) */
|
||||
lxt2_wr_emit_u32(lt, ~0); /* control section */
|
||||
fflush(lt->handle);
|
||||
|
||||
|
||||
lt->zhandle = gzdopen(dup(fileno(lt->handle)), lt->zmode);
|
||||
lt->zpackcount = 0;
|
||||
}
|
||||
|
|
@ -1354,9 +1354,9 @@ if((lt->timegranule>=lt->maxgranule)||(do_finalize)||(early_flush))
|
|||
exit(255);
|
||||
}
|
||||
|
||||
lxt2_wr_emit_stringz(lt, ds->item);
|
||||
lxt2_wr_emit_stringz(lt, ds->item);
|
||||
ds2 = ds->next;
|
||||
free(ds->item);
|
||||
free(ds->item);
|
||||
free(ds);
|
||||
ds = ds2;
|
||||
}
|
||||
|
|
@ -1382,7 +1382,7 @@ if((lt->timegranule>=lt->maxgranule)||(do_finalize)||(early_flush))
|
|||
#endif
|
||||
|
||||
dt2 = dt->next;
|
||||
free(dt);
|
||||
free(dt);
|
||||
dt = dt2;
|
||||
}
|
||||
lt->mapdict_head = lt->mapdict_curr = lt->mapdict = NULL;
|
||||
|
|
@ -1399,11 +1399,11 @@ if((lt->timegranule>=lt->maxgranule)||(do_finalize)||(early_flush))
|
|||
if(using_partial_zip)
|
||||
{
|
||||
off_t c_len;
|
||||
|
||||
|
||||
gzflush_buffered(lt, 1);
|
||||
fseeko(lt->handle, 0L, SEEK_END);
|
||||
lt->position=ftello(lt->handle);
|
||||
|
||||
|
||||
c_len = lt->position - current_iter_pos - 12;
|
||||
fseeko(lt->handle, current_iter_pos, SEEK_SET);
|
||||
|
||||
|
|
@ -1467,7 +1467,7 @@ if(lt)
|
|||
{
|
||||
lt->bumptime = 0;
|
||||
|
||||
if(!lt->flush_valid)
|
||||
if(!lt->flush_valid)
|
||||
{
|
||||
lt->timepos++;
|
||||
}
|
||||
|
|
@ -1475,7 +1475,7 @@ if(lt)
|
|||
{
|
||||
lt->flush_valid = 0;
|
||||
}
|
||||
|
||||
|
||||
if(lt->timepos == LXT2_WR_GRANULE_SIZE)
|
||||
{
|
||||
/* fprintf(stderr, "flushing granule to disk at time %d\n", (unsigned int)timeval); */
|
||||
|
|
@ -1484,7 +1484,7 @@ if(lt)
|
|||
}
|
||||
|
||||
/* fprintf(stderr, "updating time to %d (%d dict entries/%d bytes)\n", (unsigned int)timeval, lt->num_dict_entries, lt->dict_string_mem_required); */
|
||||
lt->timetable[lt->timepos] = timeval;
|
||||
lt->timetable[lt->timepos] = timeval;
|
||||
lt->lasttime = timeval;
|
||||
}
|
||||
}
|
||||
|
|
@ -1493,7 +1493,7 @@ if(lt)
|
|||
lt->timeset = 1;
|
||||
lt->mintime = lt->maxtime = timeval;
|
||||
|
||||
lt->timetable[lt->timepos] = timeval;
|
||||
lt->timetable[lt->timepos] = timeval;
|
||||
}
|
||||
|
||||
if( (!lt->timepos) && (!lt->timegranule) )
|
||||
|
|
@ -1524,7 +1524,7 @@ if(lt)
|
|||
else if (s->flags&LXT2_WR_SYM_F_DOUBLE)
|
||||
{
|
||||
double value = 0;
|
||||
|
||||
|
||||
sscanf(s->value, "%lg", &value);
|
||||
errno = 0;
|
||||
lxt2_wr_emit_value_double(lt, s, 0, value);
|
||||
|
|
@ -1625,7 +1625,7 @@ int rc=0;
|
|||
|
||||
if((!lt)||(lt->blackout)||(!s)||(row)) return(rc);
|
||||
|
||||
if(!lt->emitted)
|
||||
if(!lt->emitted)
|
||||
{
|
||||
lxt2_wr_emitfacs(lt);
|
||||
lt->emitted = 1;
|
||||
|
|
@ -1666,7 +1666,7 @@ if(s->flags&LXT2_WR_SYM_F_DOUBLE)
|
|||
|
||||
if(lt->dict_curr)
|
||||
{
|
||||
lt->dict_curr->next = lt->dict;
|
||||
lt->dict_curr->next = lt->dict;
|
||||
lt->dict_curr = lt->dict;
|
||||
}
|
||||
else
|
||||
|
|
@ -1707,7 +1707,7 @@ int rc=0;
|
|||
|
||||
if((!lt)||(lt->blackout)||(!s)||(!value)||(row)) return(rc);
|
||||
|
||||
if(!lt->emitted)
|
||||
if(!lt->emitted)
|
||||
{
|
||||
lxt2_wr_emitfacs(lt);
|
||||
lt->emitted = 1;
|
||||
|
|
@ -1746,7 +1746,7 @@ if(s->flags&LXT2_WR_SYM_F_STRING)
|
|||
|
||||
if(lt->dict_curr)
|
||||
{
|
||||
lt->dict_curr->next = lt->dict;
|
||||
lt->dict_curr->next = lt->dict;
|
||||
lt->dict_curr = lt->dict;
|
||||
}
|
||||
else
|
||||
|
|
@ -1791,7 +1791,7 @@ int i;
|
|||
|
||||
if((!lt)||(lt->blackout)||(!s)||(!value)||(!*value)||(row)) return(rc);
|
||||
|
||||
if(!lt->emitted)
|
||||
if(!lt->emitted)
|
||||
{
|
||||
lxt2_wr_emitfacs(lt);
|
||||
lt->emitted = 1;
|
||||
|
|
@ -1856,12 +1856,12 @@ if(!(s->flags&(LXT2_WR_SYM_F_DOUBLE|LXT2_WR_SYM_F_STRING)))
|
|||
prevch = *vpnt;
|
||||
while(*vpnt)
|
||||
{
|
||||
if(prevch == *vpnt)
|
||||
if(prevch == *vpnt)
|
||||
{
|
||||
vpnt++;
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
prevch = 0;
|
||||
break;
|
||||
}
|
||||
|
|
@ -1968,7 +1968,7 @@ idxchk: if(idx<0)
|
|||
|
||||
if(lt->dict_curr)
|
||||
{
|
||||
lt->dict_curr->next = lt->dict;
|
||||
lt->dict_curr->next = lt->dict;
|
||||
lt->dict_curr = lt->dict;
|
||||
}
|
||||
else
|
||||
|
|
@ -2016,15 +2016,15 @@ struct lxt2_wr_symbol *s;
|
|||
|
||||
if((lt)&&(!lt->blackout))
|
||||
{
|
||||
if(!lt->emitted)
|
||||
if(!lt->emitted)
|
||||
{
|
||||
lxt2_wr_emitfacs(lt);
|
||||
lt->emitted = 1;
|
||||
|
||||
|
||||
if(!lt->timeset)
|
||||
{
|
||||
lxt2_wr_set_time(lt, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s = lt->symchain;
|
||||
|
|
@ -2036,7 +2036,7 @@ if((lt)&&(!lt->blackout))
|
|||
{
|
||||
s->msk |= (LXT2_WR_GRAN_1VAL<<lt->timepos);
|
||||
s->chg[s->chgpos] = LXT2_WR_ENC_BLACKOUT;
|
||||
|
||||
|
||||
s->chgpos++;
|
||||
}
|
||||
else
|
||||
|
|
@ -2158,7 +2158,7 @@ if(lt)
|
|||
{
|
||||
struct lxt2_wr_symbol *s = lt->symchain;
|
||||
struct lxt2_wr_symbol *s2;
|
||||
|
||||
|
||||
while(s)
|
||||
{
|
||||
free(s->name);
|
||||
|
|
@ -2170,7 +2170,7 @@ if(lt)
|
|||
|
||||
lt->symchain=NULL;
|
||||
}
|
||||
|
||||
|
||||
free(lt->lxtname);
|
||||
free(lt->sorted_facs);
|
||||
fclose(lt->handle);
|
||||
|
|
@ -2193,13 +2193,13 @@ if(lt)
|
|||
|
||||
|
||||
/*
|
||||
* time zero offset
|
||||
* time zero offset
|
||||
*/
|
||||
void lxt2_wr_set_timezero(struct lxt2_wr_trace *lt, lxtstime_t timeval)
|
||||
{
|
||||
void lxt2_wr_set_timezero(struct lxt2_wr_trace *lt, lxtstime_t timeval)
|
||||
{
|
||||
if(lt)
|
||||
{
|
||||
{
|
||||
lt->timezero = timeval;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,19 +3,19 @@
|
|||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
|
@ -83,12 +83,12 @@ typedef unsigned long long granmsk_t;
|
|||
#define LXT2_WR_GRAN_1VAL (LXT2_WR_ULLDESC(1))
|
||||
#else
|
||||
typedef unsigned int granmsk_t;
|
||||
#define LXT2_WR_GRAN_0VAL (0)
|
||||
#define LXT2_WR_GRAN_0VAL (0)
|
||||
#define LXT2_WR_GRAN_1VAL (1)
|
||||
#endif
|
||||
|
||||
|
||||
enum LXT2_WR_Encodings {
|
||||
enum LXT2_WR_Encodings {
|
||||
LXT2_WR_ENC_0,
|
||||
LXT2_WR_ENC_1,
|
||||
LXT2_WR_ENC_INV,
|
||||
|
|
@ -132,12 +132,12 @@ struct lxt2_wr_ds_tree_node {
|
|||
*/
|
||||
typedef struct lxt2_wr_dslxt_tree_node lxt2_wr_dslxt_Tree;
|
||||
struct lxt2_wr_dslxt_tree_node {
|
||||
lxt2_wr_dslxt_Tree * left, * right;
|
||||
lxt2_wr_dslxt_Tree * left, * right;
|
||||
char *item;
|
||||
unsigned int val;
|
||||
lxt2_wr_dslxt_Tree * next;
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct lxt2_wr_trace
|
||||
{
|
||||
|
|
|
|||
154
vpi/lxt_write.c
154
vpi/lxt_write.c
|
|
@ -132,7 +132,7 @@ static dslxt_Tree * dslxt_insert(char *i, dslxt_Tree * t, unsigned int val) {
|
|||
/* Return a pointer to the resulting tree. */
|
||||
dslxt_Tree * n;
|
||||
int dir;
|
||||
|
||||
|
||||
n = (dslxt_Tree *) calloc (1, sizeof (dslxt_Tree));
|
||||
if (n == NULL) {
|
||||
fprintf(stderr, "dslxt_insert: ran out of memory, exiting.\n");
|
||||
|
|
@ -190,7 +190,7 @@ static dslxt_Tree * dslxt_delete(char *i, dslxt_Tree * t) {
|
|||
/*
|
||||
* functions which emit various big endian
|
||||
* data to a file
|
||||
*/
|
||||
*/
|
||||
static int lt_emit_u8(struct lt_trace *lt, int value)
|
||||
{
|
||||
unsigned char buf[1];
|
||||
|
|
@ -271,7 +271,7 @@ return(nmemb);
|
|||
static int lt_emit_string(struct lt_trace *lt, char *value)
|
||||
{
|
||||
int rc=1;
|
||||
do
|
||||
do
|
||||
{
|
||||
rc&=lt_emit_u8(lt, *value);
|
||||
} while(*(value++));
|
||||
|
|
@ -284,7 +284,7 @@ return(rc);
|
|||
* data to a file. (lt->position needs to be
|
||||
* fixed up on gzclose so the tables don't
|
||||
* get out of sync!)
|
||||
*/
|
||||
*/
|
||||
static int lt_emit_u8z(struct lt_trace *lt, int value)
|
||||
{
|
||||
unsigned char buf[1];
|
||||
|
|
@ -371,7 +371,7 @@ return(nmemb);
|
|||
static int lt_emit_stringz(struct lt_trace *lt, char *value)
|
||||
{
|
||||
int rc=1;
|
||||
do
|
||||
do
|
||||
{
|
||||
rc&=lt_emit_u8z(lt, *value);
|
||||
} while(*(value++));
|
||||
|
|
@ -383,7 +383,7 @@ return(rc);
|
|||
* data to a file. (lt->position needs to be
|
||||
* fixed up on BZ2_bzclose so the tables don't
|
||||
* get out of sync!)
|
||||
*/
|
||||
*/
|
||||
static int lt_emit_u8bz(struct lt_trace *lt, int value)
|
||||
{
|
||||
unsigned char buf[1];
|
||||
|
|
@ -470,7 +470,7 @@ return(nmemb);
|
|||
static int lt_emit_stringbz(struct lt_trace *lt, char *value)
|
||||
{
|
||||
int rc=1;
|
||||
do
|
||||
do
|
||||
{
|
||||
rc&=lt_emit_u8bz(lt, *value);
|
||||
} while(*(value++));
|
||||
|
|
@ -537,7 +537,7 @@ for(p=s;*p;p++)
|
|||
{
|
||||
h=h^(g>>24);
|
||||
h=h^g;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
h^=h2; /* combine the two hashes */
|
||||
|
|
@ -564,17 +564,17 @@ struct lt_symbol *temp;
|
|||
|
||||
hv=lt_hash(s);
|
||||
if(!(temp=lt->sym[hv])) return(NULL); /* no hash entry, add here wanted to add */
|
||||
|
||||
|
||||
while(temp)
|
||||
{
|
||||
if(!strcmp(temp->name,s))
|
||||
{
|
||||
return(temp); /* in table already */
|
||||
return(temp); /* in table already */
|
||||
}
|
||||
if(!temp->next) break;
|
||||
temp=temp->next;
|
||||
}
|
||||
|
||||
|
||||
return(NULL); /* not found, add here if you want to add*/
|
||||
}
|
||||
|
||||
|
|
@ -599,13 +599,13 @@ if(lt->compress_fac_str)
|
|||
lt_emit_u16z(lt, i);
|
||||
lt_emit_stringz(lt, str+i);
|
||||
free(lt->compress_fac_str);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lt_emit_u16z(lt, 0);
|
||||
lt_emit_stringz(lt, str);
|
||||
}
|
||||
|
||||
|
||||
lt->compress_fac_str = (char *) malloc((lt->compress_fac_len=len)+1);
|
||||
strcpy(lt->compress_fac_str, str);
|
||||
}
|
||||
|
|
@ -626,10 +626,10 @@ while(lastch!=s->name)
|
|||
|
||||
if(*lastch=='[')
|
||||
{
|
||||
*lastch=0x00;
|
||||
*lastch=0x00;
|
||||
return;
|
||||
}
|
||||
lastch--;
|
||||
lastch--;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
@ -655,12 +655,12 @@ if((lt)&&(lt->numfacs))
|
|||
strip_brack(s);
|
||||
s=s->symchain;
|
||||
}
|
||||
else
|
||||
else
|
||||
for(i=0;i<lt->numfacs;i++)
|
||||
{
|
||||
lt->sorted_facs[lt->numfacs - i - 1] = s; /* facs were chained backwards so reverse to restore bitslicing*/
|
||||
s=s->symchain;
|
||||
}
|
||||
}
|
||||
wave_msort(lt->sorted_facs, lt->numfacs);
|
||||
|
||||
for(i=0;i<lt->numfacs;i++)
|
||||
|
|
@ -688,7 +688,7 @@ if((lt)&&(lt->numfacs))
|
|||
free(lt->compress_fac_str); lt->compress_fac_str=NULL;
|
||||
lt->compress_fac_len=0;
|
||||
lt->zfacname_predec_size = lt->zpackcount;
|
||||
|
||||
|
||||
gzclose(lt->zhandle);
|
||||
fseeko(lt->handle, 0L, SEEK_END);
|
||||
lt->position=ftello(lt->handle);
|
||||
|
|
@ -723,13 +723,13 @@ if((lt)&&(lt->numfacs))
|
|||
if(is_interlaced_trace)
|
||||
{
|
||||
lt->zhandle = gzdopen(dup(fileno(lt->handle)), "wb9");
|
||||
|
||||
|
||||
lt->sync_table_offset = lt->position;
|
||||
for(i=0;i<lt->numfacs;i++)
|
||||
{
|
||||
lt_emit_u32z(lt, lt->sorted_facs[i]->last_change);
|
||||
}
|
||||
|
||||
|
||||
gzclose(lt->zhandle); lt->zhandle = NULL;
|
||||
fseeko(lt->handle, 0L, SEEK_END);
|
||||
lt->position=ftello(lt->handle);
|
||||
|
|
@ -740,7 +740,7 @@ if((lt)&&(lt->numfacs))
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
/*
|
||||
* initialize the trace and get back an lt context
|
||||
*/
|
||||
struct lt_trace *lt_init(const char *name)
|
||||
|
|
@ -866,7 +866,7 @@ switch(numbytes_trans&3)
|
|||
case 3: lt->lt_emit_u32(lt, numtrans); break;
|
||||
}
|
||||
|
||||
/* printf("Clock finish for '%s' at %lld ending with '%c' for %d repeats over a switch delta of %d\n",
|
||||
/* printf("Clock finish for '%s' at %lld ending with '%c' for %d repeats over a switch delta of %d\n",
|
||||
s->name, lt->timeval, s->clk_prevval, s->clk_numtrans - LT_CLKPACK, s->clk_delta); */
|
||||
s->clk_prevtrans = ULLDescriptor(~0);
|
||||
s->clk_numtrans = 0;
|
||||
|
|
@ -967,7 +967,7 @@ switch(numbytes_trans&3)
|
|||
case 3: lt->lt_emit_u32(lt, numtrans); break;
|
||||
}
|
||||
|
||||
/* printf("Clock finish for '%s' at %lld ending with '%08x' for %d repeats over a switch delta of %lld\n",
|
||||
/* printf("Clock finish for '%s' at %lld ending with '%08x' for %d repeats over a switch delta of %lld\n",
|
||||
s->name, lt->timeval, s->clk_prevval, s->clk_numtrans - LT_CLKPACK_M, s->clk_delta); */
|
||||
s->clk_prevtrans = ULLDescriptor(~0);
|
||||
s->clk_numtrans = 0;
|
||||
|
|
@ -1035,7 +1035,7 @@ for(i=0;i<lt->num_dict_entries;i++)
|
|||
/* fprintf(stderr, "%8d) '%s'\n", ds->val, ds->item); */
|
||||
lt_emit_stringz(lt, ds->item+1);
|
||||
}
|
||||
|
||||
|
||||
gzclose(lt->zhandle);
|
||||
fseeko(lt->handle, 0L, SEEK_END);
|
||||
lt->position=ftello(lt->handle);
|
||||
|
|
@ -1072,13 +1072,13 @@ if(lt)
|
|||
if(s->clk_numtrans > LT_CLKPACK_M) lt_flushclock_m(lt, s);
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
if(s->clk_numtrans > LT_CLKPACK) lt_flushclock(lt, s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
s=s->symchain;
|
||||
}
|
||||
}
|
||||
|
||||
lt_set_dumpon(lt); /* in case it was turned off */
|
||||
|
||||
|
|
@ -1134,7 +1134,7 @@ if(lt)
|
|||
while(t)
|
||||
{
|
||||
lt_emit_u32z(lt, t->position - lastposition); lastposition = t->position;
|
||||
t=t->next;
|
||||
t=t->next;
|
||||
}
|
||||
|
||||
t=lt->timehead;
|
||||
|
|
@ -1144,9 +1144,9 @@ if(lt)
|
|||
{
|
||||
lxttime_t delta = t->timeval - lasttime;
|
||||
lt_emit_u64z(lt, (int)(delta>>32), (int)delta); lasttime = t->timeval;
|
||||
|
||||
|
||||
t2=t->next;
|
||||
free(t);
|
||||
free(t);
|
||||
t=t2;
|
||||
}
|
||||
}
|
||||
|
|
@ -1155,12 +1155,12 @@ if(lt)
|
|||
while(t)
|
||||
{
|
||||
lt_emit_u32z(lt, (int)(t->timeval - lasttime)); lasttime = t->timeval;
|
||||
|
||||
|
||||
t2=t->next;
|
||||
free(t);
|
||||
free(t);
|
||||
t=t2;
|
||||
}
|
||||
|
||||
|
||||
lt->timehead = lt->timecurr = NULL;
|
||||
}
|
||||
|
||||
|
|
@ -1170,7 +1170,7 @@ if(lt)
|
|||
lt->ztime_table_size = lt->position - lt->ztime_table_size;
|
||||
}
|
||||
|
||||
if(lt->initial_value>=0)
|
||||
if(lt->initial_value>=0)
|
||||
{
|
||||
lt->initial_value_offset = lt->position;
|
||||
lt_emit_u8(lt, lt->initial_value);
|
||||
|
|
@ -1185,7 +1185,7 @@ if(lt)
|
|||
if(lt->double_used)
|
||||
{
|
||||
lt->double_test_offset = lt->position;
|
||||
lt_emit_double(lt, 3.14159);
|
||||
lt_emit_double(lt, 3.14159);
|
||||
}
|
||||
|
||||
if(lt->dumpoffcount)
|
||||
|
|
@ -1201,7 +1201,7 @@ if(lt)
|
|||
lt_emit_u64(lt, (int)((ltt->timeval)>>32), (int)ltt->timeval);
|
||||
ltt2 = ltt;
|
||||
ltt=ltt->next;
|
||||
free(ltt2);
|
||||
free(ltt2);
|
||||
}
|
||||
|
||||
lt->dumpoffhead = lt->dumpoffcurr = NULL;
|
||||
|
|
@ -1253,7 +1253,7 @@ if(lt)
|
|||
{
|
||||
struct lt_symbol *sc = lt->symchain;
|
||||
struct lt_symbol *s2;
|
||||
|
||||
|
||||
while(sc)
|
||||
{
|
||||
free(sc->name);
|
||||
|
|
@ -1262,7 +1262,7 @@ if(lt)
|
|||
sc=s2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
free(lt->sorted_facs);
|
||||
fclose(lt->handle);
|
||||
free(lt);
|
||||
|
|
@ -1368,7 +1368,7 @@ return(sa);
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
/*
|
||||
* set current time
|
||||
*/
|
||||
int lt_inc_time_by_delta(struct lt_trace *lt, unsigned int timeval)
|
||||
|
|
@ -1407,7 +1407,7 @@ if(lt)
|
|||
else
|
||||
{
|
||||
free(trl);
|
||||
goto bail;
|
||||
goto bail;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -1485,7 +1485,7 @@ if((lt)&&(!lt->emitted))
|
|||
}
|
||||
|
||||
/*
|
||||
* sets change interlace
|
||||
* sets change interlace
|
||||
*/
|
||||
void lt_set_no_interlace(struct lt_trace *lt)
|
||||
{
|
||||
|
|
@ -1510,12 +1510,12 @@ if((lt)&&(!lt->emitted)&&(!lt->sorted_facs))
|
|||
strip_brack(s);
|
||||
s=s->symchain;
|
||||
}
|
||||
else
|
||||
else
|
||||
for(i=0;i<lt->numfacs;i++)
|
||||
{
|
||||
lt->sorted_facs[lt->numfacs - i - 1] = s; /* facs were chained backwards so reverse to restore bitslicing */
|
||||
s=s->symchain;
|
||||
}
|
||||
}
|
||||
wave_msort(lt->sorted_facs, lt->numfacs);
|
||||
|
||||
for(i=0;i<lt->numfacs;i++)
|
||||
|
|
@ -1555,12 +1555,12 @@ if(lt)
|
|||
{
|
||||
int tag;
|
||||
switch(value)
|
||||
{
|
||||
{
|
||||
case '0': tag = 0; break;
|
||||
case '1': tag = 1; break;
|
||||
case 'Z':
|
||||
case 'Z':
|
||||
case 'z': tag = 2; break;
|
||||
case 'X':
|
||||
case 'X':
|
||||
case 'x': tag = 3; break;
|
||||
case 'H':
|
||||
case 'h': tag = 4; break;
|
||||
|
|
@ -1686,7 +1686,7 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
|
|||
s->clk_mask <<= 1;
|
||||
s->clk_mask |= 1;
|
||||
|
||||
if( ((s->clk_mask&0x1f)==0x1f) &&
|
||||
if( ((s->clk_mask&0x1f)==0x1f) &&
|
||||
( (delta1=(ivalue - s->clk_prevval1) & lt_optimask[s->len]) == ((s->clk_prevval1 - s->clk_prevval3) & lt_optimask[s->len]) ) &&
|
||||
( (delta2=(s->clk_prevval - s->clk_prevval2) & lt_optimask[s->len]) == ((s->clk_prevval2 - s->clk_prevval4) & lt_optimask[s->len]) ) &&
|
||||
( (delta1==delta2) || ((!delta1)&&(!delta2)) )
|
||||
|
|
@ -1862,7 +1862,7 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
|
|||
{
|
||||
tag = (numbytes<<4);
|
||||
}
|
||||
|
||||
|
||||
lt->lt_emit_u8(lt, tag);
|
||||
switch(numbytes&3)
|
||||
{
|
||||
|
|
@ -1883,7 +1883,7 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
|
|||
}
|
||||
lt->lt_emit_u8(lt, optimized ? (3+optimized1) : 0);
|
||||
}
|
||||
|
||||
|
||||
s->last_change = start_position;
|
||||
|
||||
if(s->rows>0)
|
||||
|
|
@ -1949,7 +1949,7 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
|
|||
{
|
||||
if(lt->num_dict_entries==(256*65536)) lt->dict32_offset = lt->position;
|
||||
}
|
||||
|
||||
|
||||
lt->num_dict_entries++;
|
||||
}
|
||||
|
||||
|
|
@ -1994,14 +1994,14 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
|
|||
value <<= (24-len);
|
||||
rc=lt->lt_emit_u24(lt, value);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
value <<= (32-len);
|
||||
rc=lt->lt_emit_u32(lt, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(lt->timebuff)
|
||||
{
|
||||
lt->timechangecount++;
|
||||
|
|
@ -2063,7 +2063,7 @@ if((s->flags)<_SYM_F_DOUBLE)
|
|||
{
|
||||
numbytes = 0;
|
||||
}
|
||||
|
||||
|
||||
start_position = lt->position;
|
||||
s->last_change = start_position;
|
||||
|
||||
|
|
@ -2119,7 +2119,7 @@ if((s->flags)<_SYM_F_DOUBLE)
|
|||
}
|
||||
|
||||
rc=lt->lt_emit_double(lt, value);
|
||||
|
||||
|
||||
if(lt->timebuff)
|
||||
{
|
||||
lt->timechangecount++;
|
||||
|
|
@ -2181,7 +2181,7 @@ if((s->flags)<_SYM_F_STRING)
|
|||
{
|
||||
numbytes = 0;
|
||||
}
|
||||
|
||||
|
||||
start_position = lt->position;
|
||||
s->last_change = start_position;
|
||||
|
||||
|
|
@ -2237,7 +2237,7 @@ if((s->flags)<_SYM_F_STRING)
|
|||
}
|
||||
|
||||
rc=lt->lt_emit_string(lt, value);
|
||||
|
||||
|
||||
if(lt->timebuff)
|
||||
{
|
||||
lt->timechangecount++;
|
||||
|
|
@ -2318,7 +2318,7 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
|
|||
s->clk_mask <<= 1;
|
||||
s->clk_mask |= legal;
|
||||
|
||||
if( ((s->clk_mask&0x1f)==0x1f) &&
|
||||
if( ((s->clk_mask&0x1f)==0x1f) &&
|
||||
( (delta1=(ivalue - s->clk_prevval1) & lt_optimask[s->len]) == ((s->clk_prevval1 - s->clk_prevval3) & lt_optimask[s->len]) ) &&
|
||||
( (delta2=(s->clk_prevval - s->clk_prevval2) & lt_optimask[s->len]) == ((s->clk_prevval2 - s->clk_prevval4) & lt_optimask[s->len]) ) &&
|
||||
( (delta1==delta2) || ((!delta1)&&(!delta2)) )
|
||||
|
|
@ -2350,7 +2350,7 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
|
|||
s->clk_prevval1 = s->clk_prevval;
|
||||
s->clk_prevval = ivalue;
|
||||
|
||||
/* printf("Clock value '%08x' for '%s' [len=%d] at %lld (#%d)\n",
|
||||
/* printf("Clock value '%08x' for '%s' [len=%d] at %lld (#%d)\n",
|
||||
ivalue, s->name, len, lt->timeval, s->clk_numtrans); */
|
||||
return(1);
|
||||
}
|
||||
|
|
@ -2480,12 +2480,12 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
|
|||
while((ch=*(pnt++)))
|
||||
{
|
||||
switch(ch)
|
||||
{
|
||||
{
|
||||
case '0':
|
||||
case '1': mvl|=LT_MVL_2; break;
|
||||
case 'Z':
|
||||
case 'z':
|
||||
case 'X':
|
||||
case 'Z':
|
||||
case 'z':
|
||||
case 'X':
|
||||
case 'x': mvl|=LT_MVL_4; break;
|
||||
default: mvl|=LT_MVL_9; break;
|
||||
}
|
||||
|
|
@ -2494,13 +2494,13 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
|
|||
}
|
||||
|
||||
switch(prevch)
|
||||
{
|
||||
{
|
||||
case 0x00: tagadd = 0; break;
|
||||
case '0': tagadd = 3; break;
|
||||
case '1': tagadd = 4; break;
|
||||
case 'Z':
|
||||
case 'Z':
|
||||
case 'z': tagadd = 5; break;
|
||||
case 'X':
|
||||
case 'X':
|
||||
case 'x': tagadd = 6; break;
|
||||
case 'H':
|
||||
case 'h': tagadd = 7; break;
|
||||
|
|
@ -2597,7 +2597,7 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
|
|||
int outval = 0;
|
||||
int thisval= 0;
|
||||
|
||||
pnt = value;
|
||||
pnt = value;
|
||||
|
||||
if((lt->dictmode)&&(len2>lt->mindictwidth))
|
||||
{
|
||||
|
|
@ -2628,7 +2628,7 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
|
|||
{
|
||||
if(lt->num_dict_entries==(256*65536)) lt->dict32_offset = lt->position;
|
||||
}
|
||||
|
||||
|
||||
lt->num_dict_entries++;
|
||||
}
|
||||
|
||||
|
|
@ -2666,8 +2666,8 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
|
|||
outval |= (thisval<<bitpos);
|
||||
bitpos--;
|
||||
if((bitpos==-1)||(i==len2-1))
|
||||
{
|
||||
lt->lt_emit_u8(lt, outval);
|
||||
{
|
||||
lt->lt_emit_u8(lt, outval);
|
||||
outval = 0;
|
||||
bitpos = 7;
|
||||
}
|
||||
|
|
@ -2681,7 +2681,7 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
|
|||
int outval = 0;
|
||||
int thisval= 0;
|
||||
|
||||
pnt = value;
|
||||
pnt = value;
|
||||
|
||||
for(i=0;i<len2;i++)
|
||||
{
|
||||
|
|
@ -2700,8 +2700,8 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
|
|||
outval |= (thisval<<bitpos);
|
||||
bitpos-=2;
|
||||
if((bitpos==-2)||(i==len2-1))
|
||||
{
|
||||
lt->lt_emit_u8(lt, outval);
|
||||
{
|
||||
lt->lt_emit_u8(lt, outval);
|
||||
outval = 0;
|
||||
bitpos = 6;
|
||||
}
|
||||
|
|
@ -2715,7 +2715,7 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
|
|||
int outval = 0;
|
||||
int thisval= 0;
|
||||
|
||||
pnt = value;
|
||||
pnt = value;
|
||||
|
||||
for(i=0;i<len2;i++)
|
||||
{
|
||||
|
|
@ -2744,8 +2744,8 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
|
|||
outval |= (thisval<<bitpos);
|
||||
bitpos-=4;
|
||||
if((bitpos==-4)||(i==len2-1))
|
||||
{
|
||||
lt->lt_emit_u8(lt, outval);
|
||||
{
|
||||
lt->lt_emit_u8(lt, outval);
|
||||
outval = 0;
|
||||
bitpos = 4;
|
||||
}
|
||||
|
|
@ -2755,7 +2755,7 @@ if(!(s->flags&(LT_SYM_F_DOUBLE|LT_SYM_F_STRING)))
|
|||
|
||||
rc=1;
|
||||
}
|
||||
|
||||
|
||||
if(lt->timebuff)
|
||||
{
|
||||
lt->timechangecount++;
|
||||
|
|
|
|||
|
|
@ -3,19 +3,19 @@
|
|||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
|
@ -47,11 +47,11 @@ extern "C" {
|
|||
|
||||
typedef struct dslxt_tree_node dslxt_Tree;
|
||||
struct dslxt_tree_node {
|
||||
dslxt_Tree * left, * right;
|
||||
dslxt_Tree * left, * right;
|
||||
char *item;
|
||||
unsigned int val;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#define LT_HDRID (0x0138)
|
||||
#define LT_VERSION (0x0004)
|
||||
|
|
@ -180,7 +180,7 @@ unsigned double_used : 1;
|
|||
unsigned do_strip_brackets : 1;
|
||||
unsigned clock_compress : 1;
|
||||
unsigned dictmode : 1; /* dictionary compression enabled */
|
||||
unsigned zmode : 2; /* for value changes */
|
||||
unsigned zmode : 2; /* for value changes */
|
||||
unsigned emitted : 1; /* gate off change field zmode changes when set */
|
||||
};
|
||||
|
||||
|
|
@ -252,9 +252,9 @@ void lt_set_dumpoff(struct lt_trace *lt);
|
|||
void lt_set_dumpon(struct lt_trace *lt);
|
||||
|
||||
/*
|
||||
* value change functions..note that if the value string len for
|
||||
* lt_emit_value_bit_string() is shorter than the symbol length
|
||||
* it will be left justified with the rightmost character used as
|
||||
* value change functions..note that if the value string len for
|
||||
* lt_emit_value_bit_string() is shorter than the symbol length
|
||||
* it will be left justified with the rightmost character used as
|
||||
* a repeat value that will be propagated to pad the value string out:
|
||||
*
|
||||
* "10x" for 8 bits becomes "10xxxxxx"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,877 @@
|
|||
/*
|
||||
LZ4 - Fast LZ compression algorithm
|
||||
Copyright (C) 2011-2014, Yann Collet.
|
||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
You can contact the author at :
|
||||
- LZ4 source repository : http://code.google.com/p/lz4/
|
||||
- LZ4 public forum : https://groups.google.com/forum/#!forum/lz4c
|
||||
*/
|
||||
|
||||
/**************************************
|
||||
Tuning parameters
|
||||
**************************************/
|
||||
/*
|
||||
* MEMORY_USAGE :
|
||||
* Memory usage formula : N->2^N Bytes (examples : 10 -> 1KB; 12 -> 4KB ; 16 -> 64KB; 20 -> 1MB; etc.)
|
||||
* Increasing memory usage improves compression ratio
|
||||
* Reduced memory usage can improve speed, due to cache effect
|
||||
* Default value is 14, for 16KB, which nicely fits into Intel x86 L1 cache
|
||||
*/
|
||||
#define MEMORY_USAGE 14
|
||||
|
||||
/*
|
||||
* HEAPMODE :
|
||||
* Select how default compression functions will allocate memory for their hash table,
|
||||
* in memory stack (0:default, fastest), or in memory heap (1:requires memory allocation (malloc)).
|
||||
*/
|
||||
#define HEAPMODE 0
|
||||
|
||||
|
||||
/**************************************
|
||||
CPU Feature Detection
|
||||
**************************************/
|
||||
/* 32 or 64 bits ? */
|
||||
#if (defined(__x86_64__) || defined(_M_X64) || defined(_WIN64) \
|
||||
|| defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__) \
|
||||
|| defined(__64BIT__) || defined(_LP64) || defined(__LP64__) \
|
||||
|| defined(__ia64) || defined(__itanium__) || defined(_M_IA64) ) /* Detects 64 bits mode */
|
||||
# define LZ4_ARCH64 1
|
||||
#else
|
||||
# define LZ4_ARCH64 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Little Endian or Big Endian ?
|
||||
* Overwrite the #define below if you know your architecture endianess
|
||||
*/
|
||||
#if defined (__GLIBC__)
|
||||
# include <endian.h>
|
||||
# if (__BYTE_ORDER == __BIG_ENDIAN)
|
||||
# define LZ4_BIG_ENDIAN 1
|
||||
# endif
|
||||
#elif (defined(__BIG_ENDIAN__) || defined(__BIG_ENDIAN) || defined(_BIG_ENDIAN)) && !(defined(__LITTLE_ENDIAN__) || defined(__LITTLE_ENDIAN) || defined(_LITTLE_ENDIAN))
|
||||
# define LZ4_BIG_ENDIAN 1
|
||||
#elif defined(__sparc) || defined(__sparc__) \
|
||||
|| defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) \
|
||||
|| defined(__hpux) || defined(__hppa) \
|
||||
|| defined(_MIPSEB) || defined(__s390__)
|
||||
# define LZ4_BIG_ENDIAN 1
|
||||
#else
|
||||
/* Little Endian assumed. PDP Endian and other very rare endian format are unsupported. */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Unaligned memory access is automatically enabled for "common" CPU, such as x86.
|
||||
* For others CPU, such as ARM, the compiler may be more cautious, inserting unnecessary extra code to ensure aligned access property
|
||||
* If you know your target CPU supports unaligned memory access, you want to force this option manually to improve performance
|
||||
*/
|
||||
#if defined(__ARM_FEATURE_UNALIGNED)
|
||||
# define LZ4_FORCE_UNALIGNED_ACCESS 1
|
||||
#endif
|
||||
|
||||
/* Define this parameter if your target system or compiler does not support hardware bit count */
|
||||
#if defined(_MSC_VER) && defined(_WIN32_WCE) /* Visual Studio for Windows CE does not support Hardware bit count */
|
||||
# define LZ4_FORCE_SW_BITCOUNT
|
||||
#endif
|
||||
|
||||
/*
|
||||
* BIG_ENDIAN_NATIVE_BUT_INCOMPATIBLE :
|
||||
* This option may provide a small boost to performance for some big endian cpu, although probably modest.
|
||||
* You may set this option to 1 if data will remain within closed environment.
|
||||
* This option is useless on Little_Endian CPU (such as x86)
|
||||
*/
|
||||
|
||||
/* #define BIG_ENDIAN_NATIVE_BUT_INCOMPATIBLE 1 */
|
||||
|
||||
|
||||
/**************************************
|
||||
Compiler Options
|
||||
**************************************/
|
||||
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */
|
||||
/* "restrict" is a known keyword */
|
||||
#else
|
||||
# define restrict /* Disable restrict */
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER /* Visual Studio */
|
||||
# define FORCE_INLINE static __forceinline
|
||||
# include <intrin.h> /* For Visual 2005 */
|
||||
# if LZ4_ARCH64 /* 64-bits */
|
||||
# pragma intrinsic(_BitScanForward64) /* For Visual 2005 */
|
||||
# pragma intrinsic(_BitScanReverse64) /* For Visual 2005 */
|
||||
# else /* 32-bits */
|
||||
# pragma intrinsic(_BitScanForward) /* For Visual 2005 */
|
||||
# pragma intrinsic(_BitScanReverse) /* For Visual 2005 */
|
||||
# endif
|
||||
# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
|
||||
#else
|
||||
# ifdef __GNUC__
|
||||
# define FORCE_INLINE static inline __attribute__((always_inline))
|
||||
# else
|
||||
# define FORCE_INLINE static inline
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER /* Visual Studio */
|
||||
# define lz4_bswap16(x) _byteswap_ushort(x)
|
||||
#else
|
||||
# define lz4_bswap16(x) ((unsigned short int) ((((x) >> 8) & 0xffu) | (((x) & 0xffu) << 8)))
|
||||
#endif
|
||||
|
||||
#define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
|
||||
|
||||
#if (GCC_VERSION >= 302) || (__INTEL_COMPILER >= 800) || defined(__clang__)
|
||||
# define expect(expr,value) (__builtin_expect ((expr),(value)) )
|
||||
#else
|
||||
# define expect(expr,value) (expr)
|
||||
#endif
|
||||
|
||||
#define likely(expr) expect((expr) != 0, 1)
|
||||
#define unlikely(expr) expect((expr) != 0, 0)
|
||||
|
||||
|
||||
/**************************************
|
||||
Memory routines
|
||||
**************************************/
|
||||
#include <stdlib.h> /* malloc, calloc, free */
|
||||
#define ALLOCATOR(n,s) calloc(n,s)
|
||||
#define FREEMEM free
|
||||
#include <string.h> /* memset, memcpy */
|
||||
#define MEM_INIT memset
|
||||
|
||||
|
||||
/**************************************
|
||||
Includes
|
||||
**************************************/
|
||||
#include "lz4.h"
|
||||
|
||||
|
||||
/**************************************
|
||||
Basic Types
|
||||
**************************************/
|
||||
#if defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */
|
||||
# include <stdint.h>
|
||||
typedef uint8_t BYTE;
|
||||
typedef uint16_t U16;
|
||||
typedef uint32_t U32;
|
||||
typedef int32_t S32;
|
||||
typedef uint64_t U64;
|
||||
#else
|
||||
typedef unsigned char BYTE;
|
||||
typedef unsigned short U16;
|
||||
typedef unsigned int U32;
|
||||
typedef signed int S32;
|
||||
typedef unsigned long long U64;
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) && !defined(LZ4_FORCE_UNALIGNED_ACCESS)
|
||||
# define _PACKED __attribute__ ((packed))
|
||||
#else
|
||||
# define _PACKED
|
||||
#endif
|
||||
|
||||
#if !defined(LZ4_FORCE_UNALIGNED_ACCESS) && !defined(__GNUC__)
|
||||
# if defined(__IBMC__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
|
||||
# pragma pack(1)
|
||||
# else
|
||||
# pragma pack(push, 1)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
typedef struct { U16 v; } _PACKED U16_S;
|
||||
typedef struct { U32 v; } _PACKED U32_S;
|
||||
typedef struct { U64 v; } _PACKED U64_S;
|
||||
typedef struct {size_t v;} _PACKED size_t_S;
|
||||
|
||||
#if !defined(LZ4_FORCE_UNALIGNED_ACCESS) && !defined(__GNUC__)
|
||||
# if defined(__SUNPRO_C) || defined(__SUNPRO_CC)
|
||||
# pragma pack(0)
|
||||
# else
|
||||
# pragma pack(pop)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define A16(x) (((U16_S *)(x))->v)
|
||||
#define A32(x) (((U32_S *)(x))->v)
|
||||
#define A64(x) (((U64_S *)(x))->v)
|
||||
#define AARCH(x) (((size_t_S *)(x))->v)
|
||||
|
||||
|
||||
/**************************************
|
||||
Constants
|
||||
**************************************/
|
||||
#define LZ4_HASHLOG (MEMORY_USAGE-2)
|
||||
#define HASHTABLESIZE (1 << MEMORY_USAGE)
|
||||
#define HASHNBCELLS4 (1 << LZ4_HASHLOG)
|
||||
|
||||
#define MINMATCH 4
|
||||
|
||||
#define COPYLENGTH 8
|
||||
#define LASTLITERALS 5
|
||||
#define MFLIMIT (COPYLENGTH+MINMATCH)
|
||||
static const int LZ4_minLength = (MFLIMIT+1);
|
||||
|
||||
#define KB *(1U<<10)
|
||||
#define MB *(1U<<20)
|
||||
#define GB *(1U<<30)
|
||||
|
||||
#define LZ4_64KLIMIT ((64 KB) + (MFLIMIT-1))
|
||||
#define SKIPSTRENGTH 6 /* Increasing this value will make the compression run slower on incompressible data */
|
||||
|
||||
#define MAXD_LOG 16
|
||||
#define MAX_DISTANCE ((1 << MAXD_LOG) - 1)
|
||||
|
||||
#define ML_BITS 4
|
||||
#define ML_MASK ((1U<<ML_BITS)-1)
|
||||
#define RUN_BITS (8-ML_BITS)
|
||||
#define RUN_MASK ((1U<<RUN_BITS)-1)
|
||||
|
||||
|
||||
/**************************************
|
||||
Structures and local types
|
||||
**************************************/
|
||||
typedef struct {
|
||||
U32 hashTable[HASHNBCELLS4];
|
||||
const BYTE* bufferStart;
|
||||
const BYTE* base;
|
||||
const BYTE* nextBlock;
|
||||
} LZ4_Data_Structure;
|
||||
|
||||
typedef enum { notLimited = 0, limited = 1 } limitedOutput_directive;
|
||||
typedef enum { byPtr, byU32, byU16 } tableType_t;
|
||||
|
||||
typedef enum { noPrefix = 0, withPrefix = 1 } prefix64k_directive;
|
||||
|
||||
typedef enum { endOnOutputSize = 0, endOnInputSize = 1 } endCondition_directive;
|
||||
typedef enum { full = 0, partial = 1 } earlyEnd_directive;
|
||||
|
||||
|
||||
/**************************************
|
||||
Architecture-specific macros
|
||||
**************************************/
|
||||
#define STEPSIZE sizeof(size_t)
|
||||
#define LZ4_COPYSTEP(d,s) { AARCH(d) = AARCH(s); d+=STEPSIZE; s+=STEPSIZE; }
|
||||
#define LZ4_COPY8(d,s) { LZ4_COPYSTEP(d,s); if (STEPSIZE<8) LZ4_COPYSTEP(d,s); }
|
||||
|
||||
#if (defined(LZ4_BIG_ENDIAN) && !defined(BIG_ENDIAN_NATIVE_BUT_INCOMPATIBLE))
|
||||
# define LZ4_READ_LITTLEENDIAN_16(d,s,p) { U16 v = A16(p); v = lz4_bswap16(v); d = (s) - v; }
|
||||
# define LZ4_WRITE_LITTLEENDIAN_16(p,i) { U16 v = (U16)(i); v = lz4_bswap16(v); A16(p) = v; p+=2; }
|
||||
#else /* Little Endian */
|
||||
# define LZ4_READ_LITTLEENDIAN_16(d,s,p) { d = (s) - A16(p); }
|
||||
# define LZ4_WRITE_LITTLEENDIAN_16(p,v) { A16(p) = v; p+=2; }
|
||||
#endif
|
||||
|
||||
|
||||
/**************************************
|
||||
Macros
|
||||
**************************************/
|
||||
#if LZ4_ARCH64 || !defined(__GNUC__)
|
||||
# define LZ4_WILDCOPY(d,s,e) { do { LZ4_COPY8(d,s) } while (d<e); } /* at the end, d>=e; */
|
||||
#else
|
||||
# define LZ4_WILDCOPY(d,s,e) { if (likely(e-d <= 8)) LZ4_COPY8(d,s) else do { LZ4_COPY8(d,s) } while (d<e); }
|
||||
#endif
|
||||
#define LZ4_SECURECOPY(d,s,e) { if (d<e) LZ4_WILDCOPY(d,s,e); }
|
||||
|
||||
|
||||
/****************************
|
||||
Private local functions
|
||||
****************************/
|
||||
#if LZ4_ARCH64
|
||||
|
||||
FORCE_INLINE int LZ4_NbCommonBytes (register U64 val)
|
||||
{
|
||||
# if defined(LZ4_BIG_ENDIAN)
|
||||
# if defined(_MSC_VER) && !defined(LZ4_FORCE_SW_BITCOUNT)
|
||||
unsigned long r = 0;
|
||||
_BitScanReverse64( &r, val );
|
||||
return (int)(r>>3);
|
||||
# elif defined(__GNUC__) && (GCC_VERSION >= 304) && !defined(LZ4_FORCE_SW_BITCOUNT)
|
||||
return (__builtin_clzll(val) >> 3);
|
||||
# else
|
||||
int r;
|
||||
if (!(val>>32)) { r=4; } else { r=0; val>>=32; }
|
||||
if (!(val>>16)) { r+=2; val>>=8; } else { val>>=24; }
|
||||
r += (!val);
|
||||
return r;
|
||||
# endif
|
||||
# else
|
||||
# if defined(_MSC_VER) && !defined(LZ4_FORCE_SW_BITCOUNT)
|
||||
unsigned long r = 0;
|
||||
_BitScanForward64( &r, val );
|
||||
return (int)(r>>3);
|
||||
# elif defined(__GNUC__) && (GCC_VERSION >= 304) && !defined(LZ4_FORCE_SW_BITCOUNT)
|
||||
return (__builtin_ctzll(val) >> 3);
|
||||
# else
|
||||
static const int DeBruijnBytePos[64] = { 0, 0, 0, 0, 0, 1, 1, 2, 0, 3, 1, 3, 1, 4, 2, 7, 0, 2, 3, 6, 1, 5, 3, 5, 1, 3, 4, 4, 2, 5, 6, 7, 7, 0, 1, 2, 3, 3, 4, 6, 2, 6, 5, 5, 3, 4, 5, 6, 7, 1, 2, 4, 6, 4, 4, 5, 7, 2, 6, 5, 7, 6, 7, 7 };
|
||||
return DeBruijnBytePos[((U64)((val & -(long long)val) * 0x0218A392CDABBD3FULL)) >> 58];
|
||||
# endif
|
||||
# endif
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
FORCE_INLINE int LZ4_NbCommonBytes (register U32 val)
|
||||
{
|
||||
# if defined(LZ4_BIG_ENDIAN)
|
||||
# if defined(_MSC_VER) && !defined(LZ4_FORCE_SW_BITCOUNT)
|
||||
unsigned long r = 0;
|
||||
_BitScanReverse( &r, val );
|
||||
return (int)(r>>3);
|
||||
# elif defined(__GNUC__) && (GCC_VERSION >= 304) && !defined(LZ4_FORCE_SW_BITCOUNT)
|
||||
return (__builtin_clz(val) >> 3);
|
||||
# else
|
||||
int r;
|
||||
if (!(val>>16)) { r=2; val>>=8; } else { r=0; val>>=24; }
|
||||
r += (!val);
|
||||
return r;
|
||||
# endif
|
||||
# else
|
||||
# if defined(_MSC_VER) && !defined(LZ4_FORCE_SW_BITCOUNT)
|
||||
unsigned long r;
|
||||
_BitScanForward( &r, val );
|
||||
return (int)(r>>3);
|
||||
# elif defined(__GNUC__) && (GCC_VERSION >= 304) && !defined(LZ4_FORCE_SW_BITCOUNT)
|
||||
return (__builtin_ctz(val) >> 3);
|
||||
# else
|
||||
static const int DeBruijnBytePos[32] = { 0, 0, 3, 0, 3, 1, 3, 0, 3, 2, 2, 1, 3, 2, 0, 1, 3, 3, 1, 2, 2, 2, 2, 0, 3, 1, 2, 0, 1, 0, 1, 1 };
|
||||
return DeBruijnBytePos[((U32)((val & -(S32)val) * 0x077CB531U)) >> 27];
|
||||
# endif
|
||||
# endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/****************************
|
||||
Compression functions
|
||||
****************************/
|
||||
FORCE_INLINE int LZ4_hashSequence(U32 sequence, tableType_t tableType)
|
||||
{
|
||||
if (tableType == byU16)
|
||||
return (((sequence) * 2654435761U) >> ((MINMATCH*8)-(LZ4_HASHLOG+1)));
|
||||
else
|
||||
return (((sequence) * 2654435761U) >> ((MINMATCH*8)-LZ4_HASHLOG));
|
||||
}
|
||||
|
||||
FORCE_INLINE int LZ4_hashPosition(const BYTE* p, tableType_t tableType) { return LZ4_hashSequence(A32(p), tableType); }
|
||||
|
||||
FORCE_INLINE void LZ4_putPositionOnHash(const BYTE* p, U32 h, void* tableBase, tableType_t tableType, const BYTE* srcBase)
|
||||
{
|
||||
switch (tableType)
|
||||
{
|
||||
case byPtr: { const BYTE** hashTable = (const BYTE**) tableBase; hashTable[h] = p; break; }
|
||||
case byU32: { U32* hashTable = (U32*) tableBase; hashTable[h] = (U32)(p-srcBase); break; }
|
||||
case byU16: { U16* hashTable = (U16*) tableBase; hashTable[h] = (U16)(p-srcBase); break; }
|
||||
}
|
||||
}
|
||||
|
||||
FORCE_INLINE void LZ4_putPosition(const BYTE* p, void* tableBase, tableType_t tableType, const BYTE* srcBase)
|
||||
{
|
||||
U32 h = LZ4_hashPosition(p, tableType);
|
||||
LZ4_putPositionOnHash(p, h, tableBase, tableType, srcBase);
|
||||
}
|
||||
|
||||
FORCE_INLINE const BYTE* LZ4_getPositionOnHash(U32 h, void* tableBase, tableType_t tableType, const BYTE* srcBase)
|
||||
{
|
||||
if (tableType == byPtr) { const BYTE** hashTable = (const BYTE**) tableBase; return hashTable[h]; }
|
||||
if (tableType == byU32) { U32* hashTable = (U32*) tableBase; return hashTable[h] + srcBase; }
|
||||
{ U16* hashTable = (U16*) tableBase; return hashTable[h] + srcBase; } /* default, to ensure a return */
|
||||
}
|
||||
|
||||
FORCE_INLINE const BYTE* LZ4_getPosition(const BYTE* p, void* tableBase, tableType_t tableType, const BYTE* srcBase)
|
||||
{
|
||||
U32 h = LZ4_hashPosition(p, tableType);
|
||||
return LZ4_getPositionOnHash(h, tableBase, tableType, srcBase);
|
||||
}
|
||||
|
||||
|
||||
FORCE_INLINE int LZ4_compress_generic(
|
||||
void* ctx,
|
||||
const char* source,
|
||||
char* dest,
|
||||
int inputSize,
|
||||
int maxOutputSize,
|
||||
|
||||
limitedOutput_directive limitedOutput,
|
||||
tableType_t tableType,
|
||||
prefix64k_directive prefix)
|
||||
{
|
||||
const BYTE* ip = (const BYTE*) source;
|
||||
const BYTE* const base = (prefix==withPrefix) ? ((LZ4_Data_Structure*)ctx)->base : (const BYTE*) source;
|
||||
const BYTE* const lowLimit = ((prefix==withPrefix) ? ((LZ4_Data_Structure*)ctx)->bufferStart : (const BYTE*)source);
|
||||
const BYTE* anchor = (const BYTE*) source;
|
||||
const BYTE* const iend = ip + inputSize;
|
||||
const BYTE* const mflimit = iend - MFLIMIT;
|
||||
const BYTE* const matchlimit = iend - LASTLITERALS;
|
||||
|
||||
BYTE* op = (BYTE*) dest;
|
||||
BYTE* const oend = op + maxOutputSize;
|
||||
|
||||
int length;
|
||||
const int skipStrength = SKIPSTRENGTH;
|
||||
U32 forwardH;
|
||||
|
||||
/* Init conditions */
|
||||
if ((U32)inputSize > (U32)LZ4_MAX_INPUT_SIZE) return 0; /* Unsupported input size, too large (or negative) */
|
||||
if ((prefix==withPrefix) && (ip != ((LZ4_Data_Structure*)ctx)->nextBlock)) return 0; /* must continue from end of previous block */
|
||||
if (prefix==withPrefix) ((LZ4_Data_Structure*)ctx)->nextBlock=iend; /* do it now, due to potential early exit */
|
||||
if ((tableType == byU16) && (inputSize>=(int)LZ4_64KLIMIT)) return 0; /* Size too large (not within 64K limit) */
|
||||
if (inputSize<LZ4_minLength) goto _last_literals; /* Input too small, no compression (all literals) */
|
||||
|
||||
/* First Byte */
|
||||
LZ4_putPosition(ip, ctx, tableType, base);
|
||||
ip++; forwardH = LZ4_hashPosition(ip, tableType);
|
||||
|
||||
/* Main Loop */
|
||||
for ( ; ; )
|
||||
{
|
||||
int findMatchAttempts = (1U << skipStrength) + 3;
|
||||
const BYTE* forwardIp = ip;
|
||||
const BYTE* ref;
|
||||
BYTE* token;
|
||||
|
||||
/* Find a match */
|
||||
do {
|
||||
U32 h = forwardH;
|
||||
int step = findMatchAttempts++ >> skipStrength;
|
||||
ip = forwardIp;
|
||||
forwardIp = ip + step;
|
||||
|
||||
if (unlikely(forwardIp > mflimit)) { goto _last_literals; }
|
||||
|
||||
forwardH = LZ4_hashPosition(forwardIp, tableType);
|
||||
ref = LZ4_getPositionOnHash(h, ctx, tableType, base);
|
||||
LZ4_putPositionOnHash(ip, h, ctx, tableType, base);
|
||||
|
||||
} while ((ref + MAX_DISTANCE < ip) || (A32(ref) != A32(ip)));
|
||||
|
||||
/* Catch up */
|
||||
while ((ip>anchor) && (ref > lowLimit) && (unlikely(ip[-1]==ref[-1]))) { ip--; ref--; }
|
||||
|
||||
/* Encode Literal length */
|
||||
length = (int)(ip - anchor);
|
||||
token = op++;
|
||||
if ((limitedOutput) && (unlikely(op + length + (2 + 1 + LASTLITERALS) + (length/255) > oend))) return 0; /* Check output limit */
|
||||
if (length>=(int)RUN_MASK)
|
||||
{
|
||||
int len = length-RUN_MASK;
|
||||
*token=(RUN_MASK<<ML_BITS);
|
||||
for(; len >= 255 ; len-=255) *op++ = 255;
|
||||
*op++ = (BYTE)len;
|
||||
}
|
||||
else *token = (BYTE)(length<<ML_BITS);
|
||||
|
||||
/* Copy Literals */
|
||||
{ BYTE* end=(op)+(length); LZ4_WILDCOPY(op,anchor,end); op=end; }
|
||||
|
||||
_next_match:
|
||||
/* Encode Offset */
|
||||
LZ4_WRITE_LITTLEENDIAN_16(op,(U16)(ip-ref));
|
||||
|
||||
/* Start Counting */
|
||||
ip+=MINMATCH; ref+=MINMATCH; /* MinMatch already verified */
|
||||
anchor = ip;
|
||||
while (likely(ip<matchlimit-(STEPSIZE-1)))
|
||||
{
|
||||
size_t diff = AARCH(ref) ^ AARCH(ip);
|
||||
if (!diff) { ip+=STEPSIZE; ref+=STEPSIZE; continue; }
|
||||
ip += LZ4_NbCommonBytes(diff);
|
||||
goto _endCount;
|
||||
}
|
||||
if (LZ4_ARCH64) if ((ip<(matchlimit-3)) && (A32(ref) == A32(ip))) { ip+=4; ref+=4; }
|
||||
if ((ip<(matchlimit-1)) && (A16(ref) == A16(ip))) { ip+=2; ref+=2; }
|
||||
if ((ip<matchlimit) && (*ref == *ip)) ip++;
|
||||
_endCount:
|
||||
|
||||
/* Encode MatchLength */
|
||||
length = (int)(ip - anchor);
|
||||
if ((limitedOutput) && (unlikely(op + (1 + LASTLITERALS) + (length>>8) > oend))) return 0; /* Check output limit */
|
||||
if (length>=(int)ML_MASK)
|
||||
{
|
||||
*token += ML_MASK;
|
||||
length -= ML_MASK;
|
||||
for (; length > 509 ; length-=510) { *op++ = 255; *op++ = 255; }
|
||||
if (length >= 255) { length-=255; *op++ = 255; }
|
||||
*op++ = (BYTE)length;
|
||||
}
|
||||
else *token += (BYTE)(length);
|
||||
|
||||
/* Test end of chunk */
|
||||
if (ip > mflimit) { anchor = ip; break; }
|
||||
|
||||
/* Fill table */
|
||||
LZ4_putPosition(ip-2, ctx, tableType, base);
|
||||
|
||||
/* Test next position */
|
||||
ref = LZ4_getPosition(ip, ctx, tableType, base);
|
||||
LZ4_putPosition(ip, ctx, tableType, base);
|
||||
if ((ref + MAX_DISTANCE >= ip) && (A32(ref) == A32(ip))) { token = op++; *token=0; goto _next_match; }
|
||||
|
||||
/* Prepare next loop */
|
||||
anchor = ip++;
|
||||
forwardH = LZ4_hashPosition(ip, tableType);
|
||||
}
|
||||
|
||||
_last_literals:
|
||||
/* Encode Last Literals */
|
||||
{
|
||||
int lastRun = (int)(iend - anchor);
|
||||
if ((limitedOutput) && (((char*)op - dest) + lastRun + 1 + ((lastRun+255-RUN_MASK)/255) > (U32)maxOutputSize)) return 0; /* Check output limit */
|
||||
if (lastRun>=(int)RUN_MASK) { *op++=(RUN_MASK<<ML_BITS); lastRun-=RUN_MASK; for(; lastRun >= 255 ; lastRun-=255) *op++ = 255; *op++ = (BYTE) lastRun; }
|
||||
else *op++ = (BYTE)(lastRun<<ML_BITS);
|
||||
memcpy(op, anchor, iend - anchor);
|
||||
op += iend-anchor;
|
||||
}
|
||||
|
||||
/* End */
|
||||
return (int) (((char*)op)-dest);
|
||||
}
|
||||
|
||||
|
||||
int LZ4_compress(const char* source, char* dest, int inputSize)
|
||||
{
|
||||
#if (HEAPMODE)
|
||||
void* ctx = ALLOCATOR(HASHNBCELLS4, 4); /* Aligned on 4-bytes boundaries */
|
||||
#else
|
||||
U32 ctx[1U<<(MEMORY_USAGE-2)] = {0}; /* Ensure data is aligned on 4-bytes boundaries */
|
||||
#endif
|
||||
int result;
|
||||
|
||||
if (inputSize < (int)LZ4_64KLIMIT)
|
||||
result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, 0, notLimited, byU16, noPrefix);
|
||||
else
|
||||
result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, 0, notLimited, (sizeof(void*)==8) ? byU32 : byPtr, noPrefix);
|
||||
|
||||
#if (HEAPMODE)
|
||||
FREEMEM(ctx);
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
int LZ4_compress_limitedOutput(const char* source, char* dest, int inputSize, int maxOutputSize)
|
||||
{
|
||||
#if (HEAPMODE)
|
||||
void* ctx = ALLOCATOR(HASHNBCELLS4, 4); /* Aligned on 4-bytes boundaries */
|
||||
#else
|
||||
U32 ctx[1U<<(MEMORY_USAGE-2)] = {0}; /* Ensure data is aligned on 4-bytes boundaries */
|
||||
#endif
|
||||
int result;
|
||||
|
||||
if (inputSize < (int)LZ4_64KLIMIT)
|
||||
result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limited, byU16, noPrefix);
|
||||
else
|
||||
result = LZ4_compress_generic((void*)ctx, source, dest, inputSize, maxOutputSize, limited, (sizeof(void*)==8) ? byU32 : byPtr, noPrefix);
|
||||
|
||||
#if (HEAPMODE)
|
||||
FREEMEM(ctx);
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*****************************
|
||||
Using external allocation
|
||||
*****************************/
|
||||
|
||||
int LZ4_sizeofState() { return 1 << MEMORY_USAGE; }
|
||||
|
||||
|
||||
int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize)
|
||||
{
|
||||
if (((size_t)(state)&3) != 0) return 0; /* Error : state is not aligned on 4-bytes boundary */
|
||||
MEM_INIT(state, 0, LZ4_sizeofState());
|
||||
|
||||
if (inputSize < (int)LZ4_64KLIMIT)
|
||||
return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, byU16, noPrefix);
|
||||
else
|
||||
return LZ4_compress_generic(state, source, dest, inputSize, 0, notLimited, (sizeof(void*)==8) ? byU32 : byPtr, noPrefix);
|
||||
}
|
||||
|
||||
|
||||
int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize)
|
||||
{
|
||||
if (((size_t)(state)&3) != 0) return 0; /* Error : state is not aligned on 4-bytes boundary */
|
||||
MEM_INIT(state, 0, LZ4_sizeofState());
|
||||
|
||||
if (inputSize < (int)LZ4_64KLIMIT)
|
||||
return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limited, byU16, noPrefix);
|
||||
else
|
||||
return LZ4_compress_generic(state, source, dest, inputSize, maxOutputSize, limited, (sizeof(void*)==8) ? byU32 : byPtr, noPrefix);
|
||||
}
|
||||
|
||||
|
||||
/****************************
|
||||
Stream functions
|
||||
****************************/
|
||||
|
||||
int LZ4_sizeofStreamState()
|
||||
{
|
||||
return sizeof(LZ4_Data_Structure);
|
||||
}
|
||||
|
||||
FORCE_INLINE void LZ4_init(LZ4_Data_Structure* lz4ds, const BYTE* base)
|
||||
{
|
||||
MEM_INIT(lz4ds->hashTable, 0, sizeof(lz4ds->hashTable));
|
||||
lz4ds->bufferStart = base;
|
||||
lz4ds->base = base;
|
||||
lz4ds->nextBlock = base;
|
||||
}
|
||||
|
||||
int LZ4_resetStreamState(void* state, const char* inputBuffer)
|
||||
{
|
||||
if ((((size_t)state) & 3) != 0) return 1; /* Error : pointer is not aligned on 4-bytes boundary */
|
||||
LZ4_init((LZ4_Data_Structure*)state, (const BYTE*)inputBuffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* LZ4_create (const char* inputBuffer)
|
||||
{
|
||||
void* lz4ds = ALLOCATOR(1, sizeof(LZ4_Data_Structure));
|
||||
LZ4_init ((LZ4_Data_Structure*)lz4ds, (const BYTE*)inputBuffer);
|
||||
return lz4ds;
|
||||
}
|
||||
|
||||
|
||||
int LZ4_free (void* LZ4_Data)
|
||||
{
|
||||
FREEMEM(LZ4_Data);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
char* LZ4_slideInputBuffer (void* LZ4_Data)
|
||||
{
|
||||
LZ4_Data_Structure* lz4ds = (LZ4_Data_Structure*)LZ4_Data;
|
||||
size_t delta = lz4ds->nextBlock - (lz4ds->bufferStart + 64 KB);
|
||||
|
||||
if ( (lz4ds->base - delta > lz4ds->base) /* underflow control */
|
||||
|| ((size_t)(lz4ds->nextBlock - lz4ds->base) > 0xE0000000) ) /* close to 32-bits limit */
|
||||
{
|
||||
size_t deltaLimit = (lz4ds->nextBlock - 64 KB) - lz4ds->base;
|
||||
int nH;
|
||||
|
||||
for (nH=0; nH < HASHNBCELLS4; nH++)
|
||||
{
|
||||
if ((size_t)(lz4ds->hashTable[nH]) < deltaLimit) lz4ds->hashTable[nH] = 0;
|
||||
else lz4ds->hashTable[nH] -= (U32)deltaLimit;
|
||||
}
|
||||
memcpy((void*)(lz4ds->bufferStart), (const void*)(lz4ds->nextBlock - 64 KB), 64 KB);
|
||||
lz4ds->base = lz4ds->bufferStart;
|
||||
lz4ds->nextBlock = lz4ds->base + 64 KB;
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy((void*)(lz4ds->bufferStart), (const void*)(lz4ds->nextBlock - 64 KB), 64 KB);
|
||||
lz4ds->nextBlock -= delta;
|
||||
lz4ds->base -= delta;
|
||||
}
|
||||
|
||||
return (char*)(lz4ds->nextBlock);
|
||||
}
|
||||
|
||||
|
||||
int LZ4_compress_continue (void* LZ4_Data, const char* source, char* dest, int inputSize)
|
||||
{
|
||||
return LZ4_compress_generic(LZ4_Data, source, dest, inputSize, 0, notLimited, byU32, withPrefix);
|
||||
}
|
||||
|
||||
|
||||
int LZ4_compress_limitedOutput_continue (void* LZ4_Data, const char* source, char* dest, int inputSize, int maxOutputSize)
|
||||
{
|
||||
return LZ4_compress_generic(LZ4_Data, source, dest, inputSize, maxOutputSize, limited, byU32, withPrefix);
|
||||
}
|
||||
|
||||
|
||||
/****************************
|
||||
Decompression functions
|
||||
****************************/
|
||||
|
||||
/*
|
||||
* This generic decompression function cover all use cases.
|
||||
* It shall be instanciated several times, using different sets of directives
|
||||
* Note that it is essential this generic function is really inlined,
|
||||
* in order to remove useless branches during compilation optimisation.
|
||||
*/
|
||||
FORCE_INLINE int LZ4_decompress_generic(
|
||||
const char* source,
|
||||
char* dest,
|
||||
int inputSize,
|
||||
int outputSize, /* If endOnInput==endOnInputSize, this value is the max size of Output Buffer. */
|
||||
|
||||
int endOnInput, /* endOnOutputSize, endOnInputSize */
|
||||
int prefix64k, /* noPrefix, withPrefix */
|
||||
int partialDecoding, /* full, partial */
|
||||
int targetOutputSize /* only used if partialDecoding==partial */
|
||||
)
|
||||
{
|
||||
/* Local Variables */
|
||||
const BYTE* restrict ip = (const BYTE*) source;
|
||||
const BYTE* ref;
|
||||
const BYTE* const iend = ip + inputSize;
|
||||
|
||||
BYTE* op = (BYTE*) dest;
|
||||
BYTE* const oend = op + outputSize;
|
||||
BYTE* cpy;
|
||||
BYTE* oexit = op + targetOutputSize;
|
||||
|
||||
/*const size_t dec32table[] = {0, 3, 2, 3, 0, 0, 0, 0}; / static reduces speed for LZ4_decompress_safe() on GCC64 */
|
||||
const size_t dec32table[] = {4-0, 4-3, 4-2, 4-3, 4-0, 4-0, 4-0, 4-0}; /* static reduces speed for LZ4_decompress_safe() on GCC64 */
|
||||
static const size_t dec64table[] = {0, 0, 0, (size_t)-1, 0, 1, 2, 3};
|
||||
|
||||
|
||||
/* Special cases */
|
||||
if ((partialDecoding) && (oexit> oend-MFLIMIT)) oexit = oend-MFLIMIT; /* targetOutputSize too high => decode everything */
|
||||
if ((endOnInput) && (unlikely(outputSize==0))) return ((inputSize==1) && (*ip==0)) ? 0 : -1; /* Empty output buffer */
|
||||
if ((!endOnInput) && (unlikely(outputSize==0))) return (*ip==0?1:-1);
|
||||
|
||||
|
||||
/* Main Loop */
|
||||
while (1)
|
||||
{
|
||||
unsigned token;
|
||||
size_t length;
|
||||
|
||||
/* get runlength */
|
||||
token = *ip++;
|
||||
if ((length=(token>>ML_BITS)) == RUN_MASK)
|
||||
{
|
||||
unsigned s=255;
|
||||
while (((endOnInput)?ip<iend:1) && (s==255))
|
||||
{
|
||||
s = *ip++;
|
||||
length += s;
|
||||
}
|
||||
}
|
||||
|
||||
/* copy literals */
|
||||
cpy = op+length;
|
||||
if (((endOnInput) && ((cpy>(partialDecoding?oexit:oend-MFLIMIT)) || (ip+length>iend-(2+1+LASTLITERALS))) )
|
||||
|| ((!endOnInput) && (cpy>oend-COPYLENGTH)))
|
||||
{
|
||||
if (partialDecoding)
|
||||
{
|
||||
if (cpy > oend) goto _output_error; /* Error : write attempt beyond end of output buffer */
|
||||
if ((endOnInput) && (ip+length > iend)) goto _output_error; /* Error : read attempt beyond end of input buffer */
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((!endOnInput) && (cpy != oend)) goto _output_error; /* Error : block decoding must stop exactly there */
|
||||
if ((endOnInput) && ((ip+length != iend) || (cpy > oend))) goto _output_error; /* Error : input must be consumed */
|
||||
}
|
||||
memcpy(op, ip, length);
|
||||
ip += length;
|
||||
op += length;
|
||||
break; /* Necessarily EOF, due to parsing restrictions */
|
||||
}
|
||||
LZ4_WILDCOPY(op, ip, cpy); ip -= (op-cpy); op = cpy;
|
||||
|
||||
/* get offset */
|
||||
LZ4_READ_LITTLEENDIAN_16(ref,cpy,ip); ip+=2;
|
||||
if ((prefix64k==noPrefix) && (unlikely(ref < (BYTE* const)dest))) goto _output_error; /* Error : offset outside destination buffer */
|
||||
|
||||
/* get matchlength */
|
||||
if ((length=(token&ML_MASK)) == ML_MASK)
|
||||
{
|
||||
while ((!endOnInput) || (ip<iend-(LASTLITERALS+1))) /* Ensure enough bytes remain for LASTLITERALS + token */
|
||||
{
|
||||
unsigned s = *ip++;
|
||||
length += s;
|
||||
if (s==255) continue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* copy repeated sequence */
|
||||
if (unlikely((op-ref)<(int)STEPSIZE))
|
||||
{
|
||||
const size_t dec64 = dec64table[(sizeof(void*)==4) ? 0 : op-ref];
|
||||
op[0] = ref[0];
|
||||
op[1] = ref[1];
|
||||
op[2] = ref[2];
|
||||
op[3] = ref[3];
|
||||
/*op += 4, ref += 4; ref -= dec32table[op-ref];
|
||||
A32(op) = A32(ref);
|
||||
op += STEPSIZE-4; ref -= dec64;*/
|
||||
ref += dec32table[op-ref];
|
||||
A32(op+4) = A32(ref);
|
||||
op += STEPSIZE; ref -= dec64;
|
||||
} else { LZ4_COPYSTEP(op,ref); }
|
||||
cpy = op + length - (STEPSIZE-4);
|
||||
|
||||
if (unlikely(cpy>oend-COPYLENGTH-(STEPSIZE-4)))
|
||||
{
|
||||
if (cpy > oend-LASTLITERALS) goto _output_error; /* Error : last 5 bytes must be literals */
|
||||
LZ4_SECURECOPY(op, ref, (oend-COPYLENGTH));
|
||||
while(op<cpy) *op++=*ref++;
|
||||
op=cpy;
|
||||
continue;
|
||||
}
|
||||
LZ4_WILDCOPY(op, ref, cpy);
|
||||
op=cpy; /* correction */
|
||||
}
|
||||
|
||||
/* end of decoding */
|
||||
if (endOnInput)
|
||||
return (int) (((char*)op)-dest); /* Nb of output bytes decoded */
|
||||
else
|
||||
return (int) (((char*)ip)-source); /* Nb of input bytes read */
|
||||
|
||||
/* Overflow error detected */
|
||||
_output_error:
|
||||
return (int) (-(((char*)ip)-source))-1;
|
||||
}
|
||||
|
||||
|
||||
int LZ4_decompress_safe(const char* source, char* dest, int inputSize, int maxOutputSize)
|
||||
{
|
||||
return LZ4_decompress_generic(source, dest, inputSize, maxOutputSize, endOnInputSize, noPrefix, full, 0);
|
||||
}
|
||||
|
||||
int LZ4_decompress_safe_withPrefix64k(const char* source, char* dest, int inputSize, int maxOutputSize)
|
||||
{
|
||||
return LZ4_decompress_generic(source, dest, inputSize, maxOutputSize, endOnInputSize, withPrefix, full, 0);
|
||||
}
|
||||
|
||||
int LZ4_decompress_safe_partial(const char* source, char* dest, int inputSize, int targetOutputSize, int maxOutputSize)
|
||||
{
|
||||
return LZ4_decompress_generic(source, dest, inputSize, maxOutputSize, endOnInputSize, noPrefix, partial, targetOutputSize);
|
||||
}
|
||||
|
||||
int LZ4_decompress_fast_withPrefix64k(const char* source, char* dest, int outputSize)
|
||||
{
|
||||
return LZ4_decompress_generic(source, dest, 0, outputSize, endOnOutputSize, withPrefix, full, 0);
|
||||
}
|
||||
|
||||
int LZ4_decompress_fast(const char* source, char* dest, int outputSize)
|
||||
{
|
||||
#ifdef _MSC_VER /* This version is faster with Visual */
|
||||
return LZ4_decompress_generic(source, dest, 0, outputSize, endOnOutputSize, noPrefix, full, 0);
|
||||
#else
|
||||
return LZ4_decompress_generic(source, dest, 0, outputSize, endOnOutputSize, withPrefix, full, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,252 @@
|
|||
/*
|
||||
LZ4 - Fast LZ compression algorithm
|
||||
Header File
|
||||
Copyright (C) 2011-2013, Yann Collet.
|
||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
You can contact the author at :
|
||||
- LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html
|
||||
- LZ4 source repository : http://code.google.com/p/lz4/
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**************************************
|
||||
Version
|
||||
**************************************/
|
||||
#define LZ4_VERSION_MAJOR 1 /* for major interface/format changes */
|
||||
#define LZ4_VERSION_MINOR 1 /* for minor interface/format changes */
|
||||
#define LZ4_VERSION_RELEASE 3 /* for tweaks, bug-fixes, or development */
|
||||
|
||||
|
||||
/**************************************
|
||||
Compiler Options
|
||||
**************************************/
|
||||
#if (defined(__GNUC__) && defined(__STRICT_ANSI__)) || (defined(_MSC_VER) && !defined(__cplusplus)) /* Visual Studio */
|
||||
# define inline __inline /* Visual C is not C99, but supports some kind of inline */
|
||||
#endif
|
||||
|
||||
|
||||
/**************************************
|
||||
Simple Functions
|
||||
**************************************/
|
||||
|
||||
int LZ4_compress (const char* source, char* dest, int inputSize);
|
||||
int LZ4_decompress_safe (const char* source, char* dest, int inputSize, int maxOutputSize);
|
||||
|
||||
/*
|
||||
LZ4_compress() :
|
||||
Compresses 'inputSize' bytes from 'source' into 'dest'.
|
||||
Destination buffer must be already allocated,
|
||||
and must be sized to handle worst cases situations (input data not compressible)
|
||||
Worst case size evaluation is provided by function LZ4_compressBound()
|
||||
inputSize : Max supported value is LZ4_MAX_INPUT_VALUE
|
||||
return : the number of bytes written in buffer dest
|
||||
or 0 if the compression fails
|
||||
|
||||
LZ4_decompress_safe() :
|
||||
maxOutputSize : is the size of the destination buffer (which must be already allocated)
|
||||
return : the number of bytes decoded in the destination buffer (necessarily <= maxOutputSize)
|
||||
If the source stream is detected malformed, the function will stop decoding and return a negative result.
|
||||
This function is protected against buffer overflow exploits (never writes outside of output buffer, and never reads outside of input buffer). Therefore, it is protected against malicious data packets
|
||||
*/
|
||||
|
||||
|
||||
/**************************************
|
||||
Advanced Functions
|
||||
**************************************/
|
||||
#define LZ4_MAX_INPUT_SIZE 0x7E000000 /* 2 113 929 216 bytes */
|
||||
#define LZ4_COMPRESSBOUND(isize) ((unsigned int)(isize) > (unsigned int)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16)
|
||||
static inline int LZ4_compressBound(int isize) { return LZ4_COMPRESSBOUND(isize); }
|
||||
|
||||
/*
|
||||
LZ4_compressBound() :
|
||||
Provides the maximum size that LZ4 may output in a "worst case" scenario (input data not compressible)
|
||||
primarily useful for memory allocation of output buffer.
|
||||
inline function is recommended for the general case,
|
||||
macro is also provided when result needs to be evaluated at compilation (such as stack memory allocation).
|
||||
|
||||
isize : is the input size. Max supported value is LZ4_MAX_INPUT_SIZE
|
||||
return : maximum output size in a "worst case" scenario
|
||||
or 0, if input size is too large ( > LZ4_MAX_INPUT_SIZE)
|
||||
*/
|
||||
|
||||
|
||||
int LZ4_compress_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize);
|
||||
|
||||
/*
|
||||
LZ4_compress_limitedOutput() :
|
||||
Compress 'inputSize' bytes from 'source' into an output buffer 'dest' of maximum size 'maxOutputSize'.
|
||||
If it cannot achieve it, compression will stop, and result of the function will be zero.
|
||||
This function never writes outside of provided output buffer.
|
||||
|
||||
inputSize : Max supported value is LZ4_MAX_INPUT_VALUE
|
||||
maxOutputSize : is the size of the destination buffer (which must be already allocated)
|
||||
return : the number of bytes written in buffer 'dest'
|
||||
or 0 if the compression fails
|
||||
*/
|
||||
|
||||
|
||||
int LZ4_decompress_fast (const char* source, char* dest, int outputSize);
|
||||
|
||||
/*
|
||||
LZ4_decompress_fast() :
|
||||
outputSize : is the original (uncompressed) size
|
||||
return : the number of bytes read from the source buffer (in other words, the compressed size)
|
||||
If the source stream is malformed, the function will stop decoding and return a negative result.
|
||||
note : This function is a bit faster than LZ4_decompress_safe()
|
||||
This function never writes outside of output buffers, but may read beyond input buffer in case of malicious data packet.
|
||||
Use this function preferably into a trusted environment (data to decode comes from a trusted source).
|
||||
Destination buffer must be already allocated. Its size must be a minimum of 'outputSize' bytes.
|
||||
*/
|
||||
|
||||
int LZ4_decompress_safe_partial (const char* source, char* dest, int inputSize, int targetOutputSize, int maxOutputSize);
|
||||
|
||||
/*
|
||||
LZ4_decompress_safe_partial() :
|
||||
This function decompress a compressed block of size 'inputSize' at position 'source'
|
||||
into output buffer 'dest' of size 'maxOutputSize'.
|
||||
The function tries to stop decompressing operation as soon as 'targetOutputSize' has been reached,
|
||||
reducing decompression time.
|
||||
return : the number of bytes decoded in the destination buffer (necessarily <= maxOutputSize)
|
||||
Note : this number can be < 'targetOutputSize' should the compressed block to decode be smaller.
|
||||
Always control how many bytes were decoded.
|
||||
If the source stream is detected malformed, the function will stop decoding and return a negative result.
|
||||
This function never writes outside of output buffer, and never reads outside of input buffer. It is therefore protected against malicious data packets
|
||||
*/
|
||||
|
||||
|
||||
int LZ4_sizeofState();
|
||||
int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize);
|
||||
int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
|
||||
|
||||
/*
|
||||
These functions are provided should you prefer to allocate memory for compression tables with your own allocation methods.
|
||||
To know how much memory must be allocated for the compression tables, use :
|
||||
int LZ4_sizeofState();
|
||||
|
||||
Note that tables must be aligned on 4-bytes boundaries, otherwise compression will fail (return code 0).
|
||||
|
||||
The allocated memory can be provided to the compressions functions using 'void* state' parameter.
|
||||
LZ4_compress_withState() and LZ4_compress_limitedOutput_withState() are equivalent to previously described functions.
|
||||
They just use the externally allocated memory area instead of allocating their own (on stack, or on heap).
|
||||
*/
|
||||
|
||||
|
||||
/**************************************
|
||||
Streaming Functions
|
||||
**************************************/
|
||||
void* LZ4_create (const char* inputBuffer);
|
||||
int LZ4_compress_continue (void* LZ4_Data, const char* source, char* dest, int inputSize);
|
||||
int LZ4_compress_limitedOutput_continue (void* LZ4_Data, const char* source, char* dest, int inputSize, int maxOutputSize);
|
||||
char* LZ4_slideInputBuffer (void* LZ4_Data);
|
||||
int LZ4_free (void* LZ4_Data);
|
||||
|
||||
/*
|
||||
These functions allow the compression of dependent blocks, where each block benefits from prior 64 KB within preceding blocks.
|
||||
In order to achieve this, it is necessary to start creating the LZ4 Data Structure, thanks to the function :
|
||||
|
||||
void* LZ4_create (const char* inputBuffer);
|
||||
The result of the function is the (void*) pointer on the LZ4 Data Structure.
|
||||
This pointer will be needed in all other functions.
|
||||
If the pointer returned is NULL, then the allocation has failed, and compression must be aborted.
|
||||
The only parameter 'const char* inputBuffer' must, obviously, point at the beginning of input buffer.
|
||||
The input buffer must be already allocated, and size at least 192KB.
|
||||
'inputBuffer' will also be the 'const char* source' of the first block.
|
||||
|
||||
All blocks are expected to lay next to each other within the input buffer, starting from 'inputBuffer'.
|
||||
To compress each block, use either LZ4_compress_continue() or LZ4_compress_limitedOutput_continue().
|
||||
Their behavior are identical to LZ4_compress() or LZ4_compress_limitedOutput(),
|
||||
but require the LZ4 Data Structure as their first argument, and check that each block starts right after the previous one.
|
||||
If next block does not begin immediately after the previous one, the compression will fail (return 0).
|
||||
|
||||
When it's no longer possible to lay the next block after the previous one (not enough space left into input buffer), a call to :
|
||||
char* LZ4_slideInputBuffer(void* LZ4_Data);
|
||||
must be performed. It will typically copy the latest 64KB of input at the beginning of input buffer.
|
||||
Note that, for this function to work properly, minimum size of an input buffer must be 192KB.
|
||||
==> The memory position where the next input data block must start is provided as the result of the function.
|
||||
|
||||
Compression can then resume, using LZ4_compress_continue() or LZ4_compress_limitedOutput_continue(), as usual.
|
||||
|
||||
When compression is completed, a call to LZ4_free() will release the memory used by the LZ4 Data Structure.
|
||||
*/
|
||||
|
||||
int LZ4_sizeofStreamState();
|
||||
int LZ4_resetStreamState(void* state, const char* inputBuffer);
|
||||
|
||||
/*
|
||||
These functions achieve the same result as :
|
||||
void* LZ4_create (const char* inputBuffer);
|
||||
|
||||
They are provided here to allow the user program to allocate memory using its own routines.
|
||||
|
||||
To know how much space must be allocated, use LZ4_sizeofStreamState();
|
||||
Note also that space must be 4-bytes aligned.
|
||||
|
||||
Once space is allocated, you must initialize it using : LZ4_resetStreamState(void* state, const char* inputBuffer);
|
||||
void* state is a pointer to the space allocated.
|
||||
It must be aligned on 4-bytes boundaries, and be large enough.
|
||||
The parameter 'const char* inputBuffer' must, obviously, point at the beginning of input buffer.
|
||||
The input buffer must be already allocated, and size at least 192KB.
|
||||
'inputBuffer' will also be the 'const char* source' of the first block.
|
||||
|
||||
The same space can be re-used multiple times, just by initializing it each time with LZ4_resetStreamState().
|
||||
return value of LZ4_resetStreamState() must be 0 is OK.
|
||||
Any other value means there was an error (typically, pointer is not aligned on 4-bytes boundaries).
|
||||
*/
|
||||
|
||||
|
||||
int LZ4_decompress_safe_withPrefix64k (const char* source, char* dest, int inputSize, int maxOutputSize);
|
||||
int LZ4_decompress_fast_withPrefix64k (const char* source, char* dest, int outputSize);
|
||||
|
||||
/*
|
||||
*_withPrefix64k() :
|
||||
These decoding functions work the same as their "normal name" versions,
|
||||
but can use up to 64KB of data in front of 'char* dest'.
|
||||
These functions are necessary to decode inter-dependant blocks.
|
||||
*/
|
||||
|
||||
|
||||
/**************************************
|
||||
Obsolete Functions
|
||||
**************************************/
|
||||
/*
|
||||
These functions are deprecated and should no longer be used.
|
||||
They are provided here for compatibility with existing user programs.
|
||||
*/
|
||||
static inline int LZ4_uncompress (const char* source, char* dest, int outputSize) { return LZ4_decompress_fast(source, dest, outputSize); }
|
||||
static inline int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize) { return LZ4_decompress_safe(source, dest, isize, maxOutputSize); }
|
||||
|
||||
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) Tony Bybell 1999.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
#ifndef WAVE_ALLOCA_H
|
||||
#define WAVE_ALLOCA_H
|
||||
#include <stdlib.h>
|
||||
#if HAVE_ALLOCA_H
|
||||
#ifdef HAVE_ALLOCA_H
|
||||
#include <alloca.h>
|
||||
#elif defined(__GNUC__)
|
||||
#ifndef __MINGW32__
|
||||
|
|
@ -25,5 +25,5 @@
|
|||
#define alloca _alloca
|
||||
#endif
|
||||
#define wave_alloca alloca
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue