MEM_STATIC unsigned BIT_highbit32 (register U32 val)
{
# if defined(_MSC_VER) /* Visual */
- unsigned long r;
+ unsigned long r=0;
_BitScanReverse ( &r, val );
return (unsigned) r;
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
#define ERROR_LIST(ITEM) \
ITEM(PREFIX(No_Error)) ITEM(PREFIX(GENERIC)) \
+ ITEM(PREFIX(memory_allocation)) \
ITEM(PREFIX(dstSize_tooSmall)) ITEM(PREFIX(srcSize_wrong)) \
ITEM(PREFIX(prefix_unknown)) ITEM(PREFIX(corruption_detected)) \
ITEM(PREFIX(tableLog_tooLarge)) ITEM(PREFIX(maxSymbolValue_tooLarge)) ITEM(PREFIX(maxSymbolValue_tooSmall)) \
* Increasing memory usage improves compression ratio
* Reduced memory usage can improve speed, due to cache effect
*/
-#define ZSTD_MEMORY_USAGE 17
+#define ZSTD_MEMORY_USAGE 16
/*!
* HEAPMODE :
U32 h = ZSTD_hashPtr(p);
const BYTE* r;
r = table[h] + start;
- ZSTD_addPtr(table, p, start);
+ table[h] = (U32)(p-start);
return r;
}
/* init */
+ if (ip-base < 4)
+ {
+ ZSTD_addPtr(HashTable, ip+0, base);
+ ZSTD_addPtr(HashTable, ip+1, base);
+ ZSTD_addPtr(HashTable, ip+2, base);
+ ZSTD_addPtr(HashTable, ip+3, base);
+ ip += 4;
+ }
ZSTD_resetSeqStore(seqStorePtr);
/* Main Search Loop */
- while (ip < ilimit)
+ while (ip <= ilimit)
{
- const BYTE* match = (const BYTE*) ZSTD_updateMatch(HashTable, ip, base);
+ const BYTE* match = ZSTD_updateMatch(HashTable, ip, base);
- if (!ZSTD_checkMatch(match,ip)) { ip += ((ip-anchor) >> g_searchStrength) + 1; continue; }
- /* catch up */
- while ((ip>anchor) && (match>base) && (ip[-1] == match[-1])) { ip--; match--; }
+ if (ZSTD_checkMatch(ip-offset_2,ip)) match = ip-offset_2;
+ if (!ZSTD_checkMatch(match,ip)) { ip += ((ip-anchor) >> g_searchStrength) + 1; offset_2 = offset_1; continue; }
+ while ((ip>anchor) && (match>base) && (ip[-1] == match[-1])) { ip--; match--; } /* catch up */
{
size_t litLength = ip-anchor;
size_t matchLength = ZSTD_count(ip+MINMATCH, match+MINMATCH, iend);
- size_t offsetCode;
- if (litLength) offset_2 = offset_1;
- offsetCode = ip-match;
+ size_t offsetCode = ip-match;
if (offsetCode == offset_2) offsetCode = 0;
offset_2 = offset_1;
offset_1 = ip-match;
/* Fill Table */
ZSTD_addPtr(HashTable, ip+1, base);
ip += matchLength + MINMATCH;
- if (ip<=iend-8) ZSTD_addPtr(HashTable, ip-2, base);
anchor = ip;
+ if (ip <= ilimit) ZSTD_addPtr(HashTable, ip-2, base);
}
}
/* Offset */
{
- static const size_t offsetPrefix[MaxOff+1] = { /* note : size_t faster than U32 */
+ static const U32 offsetPrefix[MaxOff+1] = {
1 /*fake*/, 1, 2, 4, 8, 16, 32, 64, 128, 256,
512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144,
524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, /*fake*/ 1, 1, 1, 1, 1 };
static unsigned ZSTD_highbit(U32 val)
{
# if defined(_MSC_VER) /* Visual */
- unsigned long r;
+ unsigned long r=0;
_BitScanReverse(&r, val);
return (unsigned)r;
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* GCC Intrinsic */
else /* 32 bits */
{
# if defined(_MSC_VER)
- unsigned long r;
+ unsigned long r=0;
_BitScanForward( &r, (U32)val );
return (int)(r>>3);
# elif defined(__GNUC__) && (__GNUC__ >= 3)
return 0;
}
-static void ZSTD_HC_resetCCtx_advanced (ZSTD_HC_CCtx* zc,
- ZSTD_HC_parameters params)
+static size_t ZSTD_HC_resetCCtx_advanced (ZSTD_HC_CCtx* zc,
+ ZSTD_HC_parameters params)
{
/* validate params */
if (params.windowLog > ZSTD_HC_WINDOWLOG_MAX) params.windowLog = ZSTD_HC_WINDOWLOG_MAX;
free(zc->workSpace);
zc->workSpaceSize = neededSpace;
zc->workSpace = malloc(neededSpace);
+ if (zc->workSpace == NULL) return ERROR(memory_allocation);
}
zc->hashTable = (U32*)zc->workSpace;
zc->chainTable = zc->hashTable + (1 << params.hashLog);
zc->seqStore.matchLengthStart = zc->seqStore.litLengthStart + (BLOCKSIZE>>2);
zc->seqStore.dumpsStart = zc->seqStore.matchLengthStart + (BLOCKSIZE>>2);
+ return 0;
}
static U32 ZSTD_HC_hashPtr(const void* ptr, U32 h) { return ZSTD_HC_hash(MEM_read32(ptr), h); }
//static const U64 prime5bytes = 889523592379ULL;
-//static U32 ZSTD_HC_hashPtr(const void* p, U32 h) { return ((MEM_read64(p) * prime5bytes) << (64-40)) >> (64-h); }
+//static U32 ZSTD_HC_hashPtr(const void* p, U32 h) { return (U32)((MEM_read64(p) * prime5bytes) << (64-40)) >> (64-h); }
#define NEXT_IN_CHAIN(d) chainTable[(d) & chainMask] /* flexible, CHAINSIZE dependent */
{
/* repcode */
if (MEM_read32(ip) == MEM_read32(ip - offset_2))
- /* store sequence */
{
+ /* store sequence */
size_t matchLength = ZSTD_count(ip+MINMATCH, ip+MINMATCH-offset_2, iend);
size_t litLength = ip-anchor;
size_t offset = offset_2;
continue;
}
+ offset_2 = offset_1; /* failed once : necessarily offset_1 now */
+
/* repcode at ip+1 */
if (MEM_read32(ip+1) == MEM_read32(ip+1 - offset_1))
{
size_t matchLength = ZSTD_count(ip+1+MINMATCH, ip+1+MINMATCH-offset_1, iend);
size_t litLength = ip+1-anchor;
- offset_2 = offset_1;
ZSTD_storeSeq(seqStorePtr, litLength, anchor, 0, matchLength);
ip += 1+matchLength+MINMATCH;
anchor = ip;
{
const BYTE* match;
size_t matchLength = ZSTD_HC_insertAndFindBestMatch(ctx, ip, iend, &match, maxSearches);
- if (!matchLength) { ip++; offset_2 = offset_1; continue; }
+ if (!matchLength) { ip++; continue; }
/* store sequence */
{
size_t litLength = ip-anchor;
- offset_2 = offset_1;
offset_1 = ip-match;
ZSTD_storeSeq(seqStorePtr, litLength, anchor, offset_1, matchLength-MINMATCH);
ip += matchLength;
if (ip != ctxPtr->end)
{
if (ctxPtr->end != NULL)
- ZSTD_HC_resetCCtx_advanced(ctxPtr, ctxPtr->params); /* reset */
+ ZSTD_HC_resetCCtx_advanced(ctxPtr, ctxPtr->params); /* just reset, but no need to re-alloc */
ctxPtr->base = ip;
}
void* dst, size_t maxDstSize,
const ZSTD_HC_parameters params)
{
+ size_t errorCode;
if (maxDstSize < 4) return ERROR(dstSize_tooSmall);
- ZSTD_HC_resetCCtx_advanced(ctx, params);
+ errorCode = ZSTD_HC_resetCCtx_advanced(ctx, params);
+ if (ZSTD_isError(errorCode)) return errorCode;
MEM_writeLE32(dst, ZSTD_magicNumber); /* Write Header */
return 4;
}
{
BYTE* const ostart = (BYTE*)dst;
BYTE* op = ostart;
+ size_t oSize;
/* correct params, to use less memory */
U32 srcLog = ZSTD_highbit((U32)srcSize-1) + 1;
if (params.chainLog > srcLog) params.chainLog = srcLog;
/* Header */
- size_t oSize = ZSTD_HC_compressBegin_advanced(ctx, dst, maxDstSize, params);
+ oSize = ZSTD_HC_compressBegin_advanced(ctx, dst, maxDstSize, params);
if(ZSTD_isError(oSize)) return oSize;
op += oSize;
maxDstSize -= oSize;
U64 inFileSize;
size_t benchedSize, readSize;
void* srcBuffer;
- int result;
+ int result=0;
/* Check file existence */
inFile = fopen(inFileName, "rb");
{
size_t benchedSize = 10000000;
void* srcBuffer = malloc(benchedSize);
- int result;
+ int result=0;
char name[20] = {0};
/* Memory allocation */
ZSTD_resetDCtx(dctx);
toRead = ZSTD_nextSrcSizeToDecompress(dctx) - sizeof(ZSTD_magicNumber);
if (toRead > MAXHEADERSIZE) EXM_THROW(30, "Not enough memory to read header");
- sizeCheck = fread(header+sizeof(ZSTD_magicNumber), (size_t)1, toRead, finput);
+ sizeCheck = fread(&header[sizeof(ZSTD_magicNumber)], 1, toRead, finput);
if (sizeCheck != toRead) EXM_THROW(31, "Read error : cannot read header");
sizeCheck = ZSTD_decompressContinue(dctx, NULL, 0, header, sizeof(ZSTD_magicNumber)+toRead); // Decode frame header
if (ZSTD_isError(sizeCheck)) EXM_THROW(32, "Error decoding header");
<ClCompile Include="..\..\..\lib\huff0.c" />\r
<ClCompile Include="..\..\..\lib\legacy\zstd_v01.c" />\r
<ClCompile Include="..\..\..\lib\zstd.c" />\r
+ <ClCompile Include="..\..\..\lib\zstdhc.c" />\r
<ClCompile Include="..\..\..\programs\datagen.c" />\r
<ClCompile Include="..\..\..\programs\fuzzer.c" />\r
<ClCompile Include="..\..\..\programs\xxhash.c" />\r
<ClInclude Include="..\..\..\lib\huff0_static.h" />\r
<ClInclude Include="..\..\..\lib\legacy\zstd_v01.h" />\r
<ClInclude Include="..\..\..\lib\zstd.h" />\r
+ <ClInclude Include="..\..\..\lib\zstdhc.h" />\r
+ <ClInclude Include="..\..\..\lib\zstdhc_static.h" />\r
+ <ClInclude Include="..\..\..\lib\zstd_internal.h" />\r
<ClInclude Include="..\..\..\lib\zstd_static.h" />\r
<ClInclude Include="..\..\..\programs\datagen.h" />\r
<ClInclude Include="..\..\..\programs\xxhash.h" />\r
<ClCompile Include="..\..\..\lib\huff0.c">\r
<Filter>Fichiers sources</Filter>\r
</ClCompile>\r
+ <ClCompile Include="..\..\..\lib\zstdhc.c">\r
+ <Filter>Fichiers sources</Filter>\r
+ </ClCompile>\r
</ItemGroup>\r
<ItemGroup>\r
<ClInclude Include="..\..\..\lib\fse.h">\r
<ClInclude Include="..\..\..\lib\huff0_static.h">\r
<Filter>Fichiers d%27en-tête</Filter>\r
</ClInclude>\r
+ <ClInclude Include="..\..\..\lib\zstd_internal.h">\r
+ <Filter>Fichiers d%27en-tête</Filter>\r
+ </ClInclude>\r
+ <ClInclude Include="..\..\..\lib\zstdhc.h">\r
+ <Filter>Fichiers d%27en-tête</Filter>\r
+ </ClInclude>\r
+ <ClInclude Include="..\..\..\lib\zstdhc_static.h">\r
+ <Filter>Fichiers d%27en-tête</Filter>\r
+ </ClInclude>\r
</ItemGroup>\r
</Project>
\ No newline at end of file
<ClCompile Include="..\..\..\lib\huff0.c" />\r
<ClCompile Include="..\..\..\lib\legacy\zstd_v01.c" />\r
<ClCompile Include="..\..\..\lib\zstd.c" />\r
+ <ClCompile Include="..\..\..\lib\zstdhc.c" />\r
<ClCompile Include="..\..\..\programs\bench.c" />\r
<ClCompile Include="..\..\..\programs\fileio.c" />\r
<ClCompile Include="..\..\..\programs\xxhash.c" />\r
<ClInclude Include="..\..\..\lib\huff0_static.h" />\r
<ClInclude Include="..\..\..\lib\legacy\zstd_v01.h" />\r
<ClInclude Include="..\..\..\lib\zstd.h" />\r
+ <ClInclude Include="..\..\..\lib\zstdhc.h" />\r
+ <ClInclude Include="..\..\..\lib\zstdhc_static.h" />\r
+ <ClInclude Include="..\..\..\lib\zstd_internal.h" />\r
<ClInclude Include="..\..\..\lib\zstd_static.h" />\r
<ClInclude Include="..\..\..\programs\bench.h" />\r
<ClInclude Include="..\..\..\programs\fileio.h" />\r
<ClCompile Include="..\..\..\lib\huff0.c">\r
<Filter>Fichiers sources</Filter>\r
</ClCompile>\r
+ <ClCompile Include="..\..\..\lib\zstdhc.c">\r
+ <Filter>Fichiers sources</Filter>\r
+ </ClCompile>\r
</ItemGroup>\r
<ItemGroup>\r
<ClInclude Include="..\..\..\lib\fse.h">\r
<ClInclude Include="..\..\..\lib\huff0_static.h">\r
<Filter>Fichiers d%27en-tête</Filter>\r
</ClInclude>\r
+ <ClInclude Include="..\..\..\lib\zstd_internal.h">\r
+ <Filter>Fichiers d%27en-tête</Filter>\r
+ </ClInclude>\r
+ <ClInclude Include="..\..\..\lib\zstdhc.h">\r
+ <Filter>Fichiers d%27en-tête</Filter>\r
+ </ClInclude>\r
+ <ClInclude Include="..\..\..\lib\zstdhc_static.h">\r
+ <Filter>Fichiers d%27en-tête</Filter>\r
+ </ClInclude>\r
</ItemGroup>\r
</Project>
\ No newline at end of file