]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/LzmaCompress/Sdk/C/LzFindMt.c
BaseTools Lzma: Update LZMA SDK version to 18.05
[mirror_edk2.git] / BaseTools / Source / C / LzmaCompress / Sdk / C / LzFindMt.c
index cb61e0953a01ec92a77bee1219389d8b8dbbb2e7..2563824fcdef0bbad7d3148e2f3050f760e3098f 100644 (file)
@@ -1,5 +1,5 @@
 /* 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
@@ -33,6 +33,8 @@ static void MtSync_GetNextBlock(CMtSync *p)
 \r
     Event_Set(&p->canStart);\r
     Event_Wait(&p->wasStarted);\r
+\r
+    // if (mt) MatchFinder_Init_LowHash(mt->MatchFinder);\r
   }\r
   else\r
   {\r
@@ -155,6 +157,9 @@ static void HashThreadFunc(CMatchFinderMt *mt)
     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
@@ -205,7 +210,7 @@ static void HashThreadFunc(CMatchFinderMt *mt)
             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
@@ -443,13 +448,13 @@ void MatchFinderMt_Construct(CMatchFinderMt *p)
   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
@@ -472,7 +477,7 @@ static THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE BtThreadFunc2(void *p)
 }\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
@@ -480,7 +485,7 @@ SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddB
     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
@@ -496,14 +501,18 @@ SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddB
 }\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
@@ -591,10 +600,10 @@ static UInt32 * MixMatches3(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *dista
   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
@@ -627,12 +636,12 @@ static UInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distan
   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
@@ -684,8 +693,12 @@ static UInt32 MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *distances)
     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
@@ -712,8 +725,12 @@ static UInt32 MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *distances)
     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
@@ -746,7 +763,7 @@ static void MatchFinderMt3_Skip(CMatchFinderMt *p, UInt32 num)
   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
@@ -758,8 +775,8 @@ static void MatchFinderMt4_Skip(CMatchFinderMt *p, UInt32 num)
   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
@@ -777,7 +794,7 @@ void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable)
   {\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