/* LzFindMt.c -- multithreaded Match finder for LZ algorithms\r
-2015-10-15 : Igor Pavlov : Public domain */\r
+2017-06-10 : Igor Pavlov : Public domain */\r
\r
#include "Precomp.h"\r
\r
\r
Event_Set(&p->canStart);\r
Event_Wait(&p->wasStarted);\r
+\r
+ // if (mt) MatchFinder_Init_LowHash(mt->MatchFinder);\r
}\r
else\r
{\r
UInt32 numProcessedBlocks = 0;\r
Event_Wait(&p->canStart);\r
Event_Set(&p->wasStarted);\r
+\r
+ MatchFinder_Init_HighHash(mt->MatchFinder);\r
+\r
for (;;)\r
{\r
if (p->exit)\r
if (num > kMtHashBlockSize - 2)\r
num = kMtHashBlockSize - 2;\r
mt->GetHeadsFunc(mf->buffer, mf->pos, mf->hash + mf->fixedHashSize, mf->hashMask, heads + 2, num, mf->crc);\r
- heads[0] += num;\r
+ heads[0] = 2 + num;\r
}\r
mf->pos += num;\r
mf->buffer += num;\r
MtSync_Construct(&p->btSync);\r
}\r
\r
-static void MatchFinderMt_FreeMem(CMatchFinderMt *p, ISzAlloc *alloc)\r
+static void MatchFinderMt_FreeMem(CMatchFinderMt *p, ISzAllocPtr alloc)\r
{\r
- alloc->Free(alloc, p->hashBuf);\r
+ ISzAlloc_Free(alloc, p->hashBuf);\r
p->hashBuf = NULL;\r
}\r
\r
-void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc)\r
+void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAllocPtr alloc)\r
{\r
MtSync_Destruct(&p->hashSync);\r
MtSync_Destruct(&p->btSync);\r
}\r
\r
SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,\r
- UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc)\r
+ UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAllocPtr alloc)\r
{\r
CMatchFinder *mf = p->MatchFinder;\r
p->historySize = historySize;\r
return SZ_ERROR_PARAM;\r
if (!p->hashBuf)\r
{\r
- p->hashBuf = (UInt32 *)alloc->Alloc(alloc, (kHashBufferSize + kBtBufferSize) * sizeof(UInt32));\r
+ p->hashBuf = (UInt32 *)ISzAlloc_Alloc(alloc, (kHashBufferSize + kBtBufferSize) * sizeof(UInt32));\r
if (!p->hashBuf)\r
return SZ_ERROR_MEM;\r
p->btBuf = p->hashBuf + kHashBufferSize;\r
}\r
\r
/* Call it after ReleaseStream / SetStream */\r
-void MatchFinderMt_Init(CMatchFinderMt *p)\r
+static void MatchFinderMt_Init(CMatchFinderMt *p)\r
{\r
CMatchFinder *mf = p->MatchFinder;\r
- p->btBufPos = p->btBufPosLimit = 0;\r
- p->hashBufPos = p->hashBufPosLimit = 0;\r
+ \r
+ p->btBufPos =\r
+ p->btBufPosLimit = 0;\r
+ p->hashBufPos =\r
+ p->hashBufPosLimit = 0;\r
\r
/* Init without data reading. We don't want to read data in this thread */\r
- MatchFinder_Init_2(mf, False);\r
+ MatchFinder_Init_3(mf, False);\r
+ MatchFinder_Init_LowHash(mf);\r
\r
p->pointerToCurPos = Inline_MatchFinder_GetPointerToCurrentPos(mf);\r
p->btNumAvailBytes = 0;\r
MT_HASH3_CALC\r
\r
curMatch2 = hash[ h2];\r
- curMatch3 = hash[kFix3HashSize + h3];\r
+ curMatch3 = (hash + kFix3HashSize)[h3];\r
\r
hash[ h2] = lzPos;\r
- hash[kFix3HashSize + h3] = lzPos;\r
+ (hash + kFix3HashSize)[h3] = lzPos;\r
\r
if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\r
{\r
MT_HASH4_CALC\r
\r
curMatch2 = hash[ h2];\r
- curMatch3 = hash[kFix3HashSize + h3];\r
- curMatch4 = hash[kFix4HashSize + h4];\r
+ curMatch3 = (hash + kFix3HashSize)[h3];\r
+ curMatch4 = (hash + kFix4HashSize)[h4];\r
\r
hash[ h2] = lzPos;\r
- hash[kFix3HashSize + h3] = lzPos;\r
- hash[kFix4HashSize + h4] = lzPos;\r
+ (hash + kFix3HashSize)[h3] = lzPos;\r
+ (hash + kFix4HashSize)[h4] = lzPos;\r
\r
if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])\r
{\r
UInt32 i;\r
for (i = 0; i < len; i += 2)\r
{\r
- *distances++ = *btBuf++;\r
- *distances++ = *btBuf++;\r
+ UInt32 v0 = btBuf[0];\r
+ UInt32 v1 = btBuf[1];\r
+ btBuf += 2;\r
+ distances[0] = v0;\r
+ distances[1] = v1;\r
+ distances += 2;\r
}\r
}\r
INCREASE_LZ_POS\r
distances2 = p->MixMatchesFunc(p, p->lzPos - btBuf[1], distances);\r
do\r
{\r
- *distances2++ = *btBuf++;\r
- *distances2++ = *btBuf++;\r
+ UInt32 v0 = btBuf[0];\r
+ UInt32 v1 = btBuf[1];\r
+ btBuf += 2;\r
+ distances2[0] = v0;\r
+ distances2[1] = v1;\r
+ distances2 += 2;\r
}\r
while ((len -= 2) != 0);\r
len = (UInt32)(distances2 - (distances));\r
SKIP_HEADER_MT(3)\r
UInt32 h2, h3;\r
MT_HASH3_CALC\r
- hash[kFix3HashSize + h3] =\r
+ (hash + kFix3HashSize)[h3] =\r
hash[ h2] =\r
p->lzPos;\r
SKIP_FOOTER_MT\r
SKIP_HEADER_MT(4)\r
UInt32 h2, h3, h4;\r
MT_HASH4_CALC\r
- hash[kFix4HashSize + h4] =\r
- hash[kFix3HashSize + h3] =\r
+ (hash + kFix4HashSize)[h4] =\r
+ (hash + kFix3HashSize)[h3] =\r
hash[ h2] =\r
p->lzPos;\r
SKIP_FOOTER_MT\r
{\r
case 2:\r
p->GetHeadsFunc = GetHeads2;\r
- p->MixMatchesFunc = (Mf_Mix_Matches)0;\r
+ p->MixMatchesFunc = (Mf_Mix_Matches)NULL;\r
vTable->Skip = (Mf_Skip_Func)MatchFinderMt0_Skip;\r
vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt2_GetMatches;\r
break;\r