aboutsummaryrefslogtreecommitdiff
path: root/C/LzFindMt.c
diff options
context:
space:
mode:
Diffstat (limited to 'C/LzFindMt.c')
-rw-r--r--C/LzFindMt.c58
1 files changed, 33 insertions, 25 deletions
diff --git a/C/LzFindMt.c b/C/LzFindMt.c
index 5253e6e..ac9d59d 100644
--- a/C/LzFindMt.c
+++ b/C/LzFindMt.c
@@ -1,5 +1,5 @@
1/* LzFindMt.c -- multithreaded Match finder for LZ algorithms 1/* LzFindMt.c -- multithreaded Match finder for LZ algorithms
22023-04-02 : Igor Pavlov : Public domain */ 22024-01-22 : Igor Pavlov : Public domain */
3 3
4#include "Precomp.h" 4#include "Precomp.h"
5 5
@@ -94,7 +94,7 @@ static void MtSync_Construct(CMtSync *p)
94} 94}
95 95
96 96
97#define DEBUG_BUFFER_LOCK // define it to debug lock state 97// #define DEBUG_BUFFER_LOCK // define it to debug lock state
98 98
99#ifdef DEBUG_BUFFER_LOCK 99#ifdef DEBUG_BUFFER_LOCK
100#include <stdlib.h> 100#include <stdlib.h>
@@ -877,8 +877,9 @@ SRes MatchFinderMt_InitMt(CMatchFinderMt *p)
877} 877}
878 878
879 879
880static void MatchFinderMt_Init(CMatchFinderMt *p) 880static void MatchFinderMt_Init(void *_p)
881{ 881{
882 CMatchFinderMt *p = (CMatchFinderMt *)_p;
882 CMatchFinder *mf = MF(p); 883 CMatchFinder *mf = MF(p);
883 884
884 p->btBufPos = 885 p->btBufPos =
@@ -981,8 +982,9 @@ static UInt32 MatchFinderMt_GetNextBlock_Bt(CMatchFinderMt *p)
981 982
982 983
983 984
984static const Byte * MatchFinderMt_GetPointerToCurrentPos(CMatchFinderMt *p) 985static const Byte * MatchFinderMt_GetPointerToCurrentPos(void *_p)
985{ 986{
987 CMatchFinderMt *p = (CMatchFinderMt *)_p;
986 return p->pointerToCurPos; 988 return p->pointerToCurPos;
987} 989}
988 990
@@ -990,8 +992,9 @@ static const Byte * MatchFinderMt_GetPointerToCurrentPos(CMatchFinderMt *p)
990#define GET_NEXT_BLOCK_IF_REQUIRED if (p->btBufPos == p->btBufPosLimit) MatchFinderMt_GetNextBlock_Bt(p); 992#define GET_NEXT_BLOCK_IF_REQUIRED if (p->btBufPos == p->btBufPosLimit) MatchFinderMt_GetNextBlock_Bt(p);
991 993
992 994
993static UInt32 MatchFinderMt_GetNumAvailableBytes(CMatchFinderMt *p) 995static UInt32 MatchFinderMt_GetNumAvailableBytes(void *_p)
994{ 996{
997 CMatchFinderMt *p = (CMatchFinderMt *)_p;
995 if (p->btBufPos != p->btBufPosLimit) 998 if (p->btBufPos != p->btBufPosLimit)
996 return p->btNumAvailBytes; 999 return p->btNumAvailBytes;
997 return MatchFinderMt_GetNextBlock_Bt(p); 1000 return MatchFinderMt_GetNextBlock_Bt(p);
@@ -1243,8 +1246,9 @@ static UInt32 * MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *d)
1243} 1246}
1244 1247
1245 1248
1246static UInt32 * MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *d) 1249static UInt32 * MatchFinderMt2_GetMatches(void *_p, UInt32 *d)
1247{ 1250{
1251 CMatchFinderMt *p = (CMatchFinderMt *)_p;
1248 const UInt32 *bt = p->btBufPos; 1252 const UInt32 *bt = p->btBufPos;
1249 const UInt32 len = *bt++; 1253 const UInt32 len = *bt++;
1250 const UInt32 *btLim = bt + len; 1254 const UInt32 *btLim = bt + len;
@@ -1267,8 +1271,9 @@ static UInt32 * MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *d)
1267 1271
1268 1272
1269 1273
1270static UInt32 * MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *d) 1274static UInt32 * MatchFinderMt_GetMatches(void *_p, UInt32 *d)
1271{ 1275{
1276 CMatchFinderMt *p = (CMatchFinderMt *)_p;
1272 const UInt32 *bt = p->btBufPos; 1277 const UInt32 *bt = p->btBufPos;
1273 UInt32 len = *bt++; 1278 UInt32 len = *bt++;
1274 const UInt32 avail = p->btNumAvailBytes - 1; 1279 const UInt32 avail = p->btNumAvailBytes - 1;
@@ -1315,14 +1320,16 @@ static UInt32 * MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *d)
1315#define SKIP_HEADER_MT(n) SKIP_HEADER2_MT if (p->btNumAvailBytes-- >= (n)) { const Byte *cur = p->pointerToCurPos; UInt32 *hash = p->hash; 1320#define SKIP_HEADER_MT(n) SKIP_HEADER2_MT if (p->btNumAvailBytes-- >= (n)) { const Byte *cur = p->pointerToCurPos; UInt32 *hash = p->hash;
1316#define SKIP_FOOTER_MT } INCREASE_LZ_POS p->btBufPos += (size_t)*p->btBufPos + 1; } while (--num != 0); 1321#define SKIP_FOOTER_MT } INCREASE_LZ_POS p->btBufPos += (size_t)*p->btBufPos + 1; } while (--num != 0);
1317 1322
1318static void MatchFinderMt0_Skip(CMatchFinderMt *p, UInt32 num) 1323static void MatchFinderMt0_Skip(void *_p, UInt32 num)
1319{ 1324{
1325 CMatchFinderMt *p = (CMatchFinderMt *)_p;
1320 SKIP_HEADER2_MT { p->btNumAvailBytes--; 1326 SKIP_HEADER2_MT { p->btNumAvailBytes--;
1321 SKIP_FOOTER_MT 1327 SKIP_FOOTER_MT
1322} 1328}
1323 1329
1324static void MatchFinderMt2_Skip(CMatchFinderMt *p, UInt32 num) 1330static void MatchFinderMt2_Skip(void *_p, UInt32 num)
1325{ 1331{
1332 CMatchFinderMt *p = (CMatchFinderMt *)_p;
1326 SKIP_HEADER_MT(2) 1333 SKIP_HEADER_MT(2)
1327 UInt32 h2; 1334 UInt32 h2;
1328 MT_HASH2_CALC 1335 MT_HASH2_CALC
@@ -1330,8 +1337,9 @@ static void MatchFinderMt2_Skip(CMatchFinderMt *p, UInt32 num)
1330 SKIP_FOOTER_MT 1337 SKIP_FOOTER_MT
1331} 1338}
1332 1339
1333static void MatchFinderMt3_Skip(CMatchFinderMt *p, UInt32 num) 1340static void MatchFinderMt3_Skip(void *_p, UInt32 num)
1334{ 1341{
1342 CMatchFinderMt *p = (CMatchFinderMt *)_p;
1335 SKIP_HEADER_MT(3) 1343 SKIP_HEADER_MT(3)
1336 UInt32 h2, h3; 1344 UInt32 h2, h3;
1337 MT_HASH3_CALC 1345 MT_HASH3_CALC
@@ -1361,39 +1369,39 @@ static void MatchFinderMt4_Skip(CMatchFinderMt *p, UInt32 num)
1361 1369
1362void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder2 *vTable) 1370void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder2 *vTable)
1363{ 1371{
1364 vTable->Init = (Mf_Init_Func)MatchFinderMt_Init; 1372 vTable->Init = MatchFinderMt_Init;
1365 vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinderMt_GetNumAvailableBytes; 1373 vTable->GetNumAvailableBytes = MatchFinderMt_GetNumAvailableBytes;
1366 vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinderMt_GetPointerToCurrentPos; 1374 vTable->GetPointerToCurrentPos = MatchFinderMt_GetPointerToCurrentPos;
1367 vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt_GetMatches; 1375 vTable->GetMatches = MatchFinderMt_GetMatches;
1368 1376
1369 switch (MF(p)->numHashBytes) 1377 switch (MF(p)->numHashBytes)
1370 { 1378 {
1371 case 2: 1379 case 2:
1372 p->GetHeadsFunc = GetHeads2; 1380 p->GetHeadsFunc = GetHeads2;
1373 p->MixMatchesFunc = (Mf_Mix_Matches)NULL; 1381 p->MixMatchesFunc = NULL;
1374 vTable->Skip = (Mf_Skip_Func)MatchFinderMt0_Skip; 1382 vTable->Skip = MatchFinderMt0_Skip;
1375 vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt2_GetMatches; 1383 vTable->GetMatches = MatchFinderMt2_GetMatches;
1376 break; 1384 break;
1377 case 3: 1385 case 3:
1378 p->GetHeadsFunc = MF(p)->bigHash ? GetHeads3b : GetHeads3; 1386 p->GetHeadsFunc = MF(p)->bigHash ? GetHeads3b : GetHeads3;
1379 p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches2; 1387 p->MixMatchesFunc = MixMatches2;
1380 vTable->Skip = (Mf_Skip_Func)MatchFinderMt2_Skip; 1388 vTable->Skip = MatchFinderMt2_Skip;
1381 break; 1389 break;
1382 case 4: 1390 case 4:
1383 p->GetHeadsFunc = MF(p)->bigHash ? GetHeads4b : GetHeads4; 1391 p->GetHeadsFunc = MF(p)->bigHash ? GetHeads4b : GetHeads4;
1384 1392
1385 // it's fast inline version of GetMatches() 1393 // it's fast inline version of GetMatches()
1386 // vTable->GetMatches = (Mf_GetMatches_Func)MatchFinderMt_GetMatches_Bt4; 1394 // vTable->GetMatches = MatchFinderMt_GetMatches_Bt4;
1387 1395
1388 p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches3; 1396 p->MixMatchesFunc = MixMatches3;
1389 vTable->Skip = (Mf_Skip_Func)MatchFinderMt3_Skip; 1397 vTable->Skip = MatchFinderMt3_Skip;
1390 break; 1398 break;
1391 default: 1399 default:
1392 p->GetHeadsFunc = MF(p)->bigHash ? GetHeads5b : GetHeads5; 1400 p->GetHeadsFunc = MF(p)->bigHash ? GetHeads5b : GetHeads5;
1393 p->MixMatchesFunc = (Mf_Mix_Matches)MixMatches4; 1401 p->MixMatchesFunc = MixMatches4;
1394 vTable->Skip = 1402 vTable->Skip =
1395 (Mf_Skip_Func)MatchFinderMt3_Skip; 1403 MatchFinderMt3_Skip;
1396 // (Mf_Skip_Func)MatchFinderMt4_Skip; 1404 // MatchFinderMt4_Skip;
1397 break; 1405 break;
1398 } 1406 }
1399} 1407}