aboutsummaryrefslogtreecommitdiff
path: root/C/LzFindMt.c
diff options
context:
space:
mode:
Diffstat (limited to 'C/LzFindMt.c')
-rw-r--r--C/LzFindMt.c70
1 files changed, 38 insertions, 32 deletions
diff --git a/C/LzFindMt.c b/C/LzFindMt.c
index 4e67fc3..5253e6e 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
22021-12-21 : Igor Pavlov : Public domain */ 22023-04-02 : Igor Pavlov : Public domain */
3 3
4#include "Precomp.h" 4#include "Precomp.h"
5 5
@@ -69,7 +69,7 @@ extern UInt64 g_NumIters_Bytes;
69 UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ 69 UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
70 h3 = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); } 70 h3 = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }
71 71
72#define __MT_HASH4_CALC { \ 72#define MT_HASH4_CALC { \
73 UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ 73 UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
74 h2 = temp & (kHash2Size - 1); \ 74 h2 = temp & (kHash2Size - 1); \
75 temp ^= ((UInt32)cur[2] << 8); \ 75 temp ^= ((UInt32)cur[2] << 8); \
@@ -79,14 +79,14 @@ extern UInt64 g_NumIters_Bytes;
79*/ 79*/
80 80
81 81
82MY_NO_INLINE 82Z7_NO_INLINE
83static void MtSync_Construct(CMtSync *p) 83static void MtSync_Construct(CMtSync *p)
84{ 84{
85 p->affinity = 0; 85 p->affinity = 0;
86 p->wasCreated = False; 86 p->wasCreated = False;
87 p->csWasInitialized = False; 87 p->csWasInitialized = False;
88 p->csWasEntered = False; 88 p->csWasEntered = False;
89 Thread_Construct(&p->thread); 89 Thread_CONSTRUCT(&p->thread)
90 Event_Construct(&p->canStart); 90 Event_Construct(&p->canStart);
91 Event_Construct(&p->wasStopped); 91 Event_Construct(&p->wasStopped);
92 Semaphore_Construct(&p->freeSemaphore); 92 Semaphore_Construct(&p->freeSemaphore);
@@ -116,7 +116,7 @@ static void MtSync_Construct(CMtSync *p)
116 (p)->csWasEntered = False; } 116 (p)->csWasEntered = False; }
117 117
118 118
119MY_NO_INLINE 119Z7_NO_INLINE
120static UInt32 MtSync_GetNextBlock(CMtSync *p) 120static UInt32 MtSync_GetNextBlock(CMtSync *p)
121{ 121{
122 UInt32 numBlocks = 0; 122 UInt32 numBlocks = 0;
@@ -140,14 +140,14 @@ static UInt32 MtSync_GetNextBlock(CMtSync *p)
140 140
141 // buffer is UNLOCKED here 141 // buffer is UNLOCKED here
142 Semaphore_Wait(&p->filledSemaphore); 142 Semaphore_Wait(&p->filledSemaphore);
143 LOCK_BUFFER(p); 143 LOCK_BUFFER(p)
144 return numBlocks; 144 return numBlocks;
145} 145}
146 146
147 147
148/* if Writing (Processing) thread was started, we must call MtSync_StopWriting() */ 148/* if Writing (Processing) thread was started, we must call MtSync_StopWriting() */
149 149
150MY_NO_INLINE 150Z7_NO_INLINE
151static void MtSync_StopWriting(CMtSync *p) 151static void MtSync_StopWriting(CMtSync *p)
152{ 152{
153 if (!Thread_WasCreated(&p->thread) || p->needStart) 153 if (!Thread_WasCreated(&p->thread) || p->needStart)
@@ -185,7 +185,7 @@ static void MtSync_StopWriting(CMtSync *p)
185} 185}
186 186
187 187
188MY_NO_INLINE 188Z7_NO_INLINE
189static void MtSync_Destruct(CMtSync *p) 189static void MtSync_Destruct(CMtSync *p)
190{ 190{
191 PRF(printf("\nMtSync_Destruct %p\n", p)); 191 PRF(printf("\nMtSync_Destruct %p\n", p));
@@ -220,11 +220,11 @@ static void MtSync_Destruct(CMtSync *p)
220 220
221// #define RINOK_THREAD(x) { if ((x) != 0) return SZ_ERROR_THREAD; } 221// #define RINOK_THREAD(x) { if ((x) != 0) return SZ_ERROR_THREAD; }
222// we want to get real system error codes here instead of SZ_ERROR_THREAD 222// we want to get real system error codes here instead of SZ_ERROR_THREAD
223#define RINOK_THREAD(x) RINOK(x) 223#define RINOK_THREAD(x) RINOK_WRes(x)
224 224
225 225
226// call it before each new file (when new starting is required): 226// call it before each new file (when new starting is required):
227MY_NO_INLINE 227Z7_NO_INLINE
228static SRes MtSync_Init(CMtSync *p, UInt32 numBlocks) 228static SRes MtSync_Init(CMtSync *p, UInt32 numBlocks)
229{ 229{
230 WRes wres; 230 WRes wres;
@@ -245,12 +245,12 @@ static WRes MtSync_Create_WRes(CMtSync *p, THREAD_FUNC_TYPE startAddress, void *
245 if (p->wasCreated) 245 if (p->wasCreated)
246 return SZ_OK; 246 return SZ_OK;
247 247
248 RINOK_THREAD(CriticalSection_Init(&p->cs)); 248 RINOK_THREAD(CriticalSection_Init(&p->cs))
249 p->csWasInitialized = True; 249 p->csWasInitialized = True;
250 p->csWasEntered = False; 250 p->csWasEntered = False;
251 251
252 RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canStart)); 252 RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canStart))
253 RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStopped)); 253 RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStopped))
254 254
255 p->needStart = True; 255 p->needStart = True;
256 p->exit = True; /* p->exit is unused before (canStart) Event. 256 p->exit = True; /* p->exit is unused before (canStart) Event.
@@ -264,13 +264,13 @@ static WRes MtSync_Create_WRes(CMtSync *p, THREAD_FUNC_TYPE startAddress, void *
264 else 264 else
265 wres = Thread_Create(&p->thread, startAddress, obj); 265 wres = Thread_Create(&p->thread, startAddress, obj);
266 266
267 RINOK_THREAD(wres); 267 RINOK_THREAD(wres)
268 p->wasCreated = True; 268 p->wasCreated = True;
269 return SZ_OK; 269 return SZ_OK;
270} 270}
271 271
272 272
273MY_NO_INLINE 273Z7_NO_INLINE
274static SRes MtSync_Create(CMtSync *p, THREAD_FUNC_TYPE startAddress, void *obj) 274static SRes MtSync_Create(CMtSync *p, THREAD_FUNC_TYPE startAddress, void *obj)
275{ 275{
276 const WRes wres = MtSync_Create_WRes(p, startAddress, obj); 276 const WRes wres = MtSync_Create_WRes(p, startAddress, obj);
@@ -519,7 +519,7 @@ static void HashThreadFunc(CMatchFinderMt *mt)
519 if (mf->pos > (UInt32)kMtMaxValForNormalize - num) 519 if (mf->pos > (UInt32)kMtMaxValForNormalize - num)
520 { 520 {
521 const UInt32 subValue = (mf->pos - mf->historySize - 1); // & ~(UInt32)(kNormalizeAlign - 1); 521 const UInt32 subValue = (mf->pos - mf->historySize - 1); // & ~(UInt32)(kNormalizeAlign - 1);
522 Inline_MatchFinder_ReduceOffsets(mf, subValue); 522 MatchFinder_REDUCE_OFFSETS(mf, subValue)
523 MatchFinder_Normalize3(subValue, mf->hash + mf->fixedHashSize, (size_t)mf->hashMask + 1); 523 MatchFinder_Normalize3(subValue, mf->hash + mf->fixedHashSize, (size_t)mf->hashMask + 1);
524 } 524 }
525 525
@@ -560,7 +560,7 @@ static void HashThreadFunc(CMatchFinderMt *mt)
560*/ 560*/
561 561
562 562
563UInt32 * MY_FAST_CALL GetMatchesSpecN_2(const Byte *lenLimit, size_t pos, const Byte *cur, CLzRef *son, 563UInt32 * Z7_FASTCALL GetMatchesSpecN_2(const Byte *lenLimit, size_t pos, const Byte *cur, CLzRef *son,
564 UInt32 _cutValue, UInt32 *d, size_t _maxLen, const UInt32 *hash, const UInt32 *limit, const UInt32 *size, 564 UInt32 _cutValue, UInt32 *d, size_t _maxLen, const UInt32 *hash, const UInt32 *limit, const UInt32 *size,
565 size_t _cyclicBufferPos, UInt32 _cyclicBufferSize, 565 size_t _cyclicBufferPos, UInt32 _cyclicBufferSize,
566 UInt32 *posRes); 566 UInt32 *posRes);
@@ -749,7 +749,7 @@ static void BtFillBlock(CMatchFinderMt *p, UInt32 globalBlockIndex)
749} 749}
750 750
751 751
752MY_NO_INLINE 752Z7_NO_INLINE
753static void BtThreadFunc(CMatchFinderMt *mt) 753static void BtThreadFunc(CMatchFinderMt *mt)
754{ 754{
755 CMtSync *p = &mt->btSync; 755 CMtSync *p = &mt->btSync;
@@ -864,15 +864,15 @@ SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddB
864 if (!MatchFinder_Create(mf, historySize, keepAddBufferBefore, matchMaxLen, keepAddBufferAfter, alloc)) 864 if (!MatchFinder_Create(mf, historySize, keepAddBufferBefore, matchMaxLen, keepAddBufferAfter, alloc))
865 return SZ_ERROR_MEM; 865 return SZ_ERROR_MEM;
866 866
867 RINOK(MtSync_Create(&p->hashSync, HashThreadFunc2, p)); 867 RINOK(MtSync_Create(&p->hashSync, HashThreadFunc2, p))
868 RINOK(MtSync_Create(&p->btSync, BtThreadFunc2, p)); 868 RINOK(MtSync_Create(&p->btSync, BtThreadFunc2, p))
869 return SZ_OK; 869 return SZ_OK;
870} 870}
871 871
872 872
873SRes MatchFinderMt_InitMt(CMatchFinderMt *p) 873SRes MatchFinderMt_InitMt(CMatchFinderMt *p)
874{ 874{
875 RINOK(MtSync_Init(&p->hashSync, kMtHashNumBlocks)); 875 RINOK(MtSync_Init(&p->hashSync, kMtHashNumBlocks))
876 return MtSync_Init(&p->btSync, kMtBtNumBlocks); 876 return MtSync_Init(&p->btSync, kMtBtNumBlocks);
877} 877}
878 878
@@ -941,7 +941,7 @@ void MatchFinderMt_ReleaseStream(CMatchFinderMt *p)
941} 941}
942 942
943 943
944MY_NO_INLINE 944Z7_NO_INLINE
945static UInt32 MatchFinderMt_GetNextBlock_Bt(CMatchFinderMt *p) 945static UInt32 MatchFinderMt_GetNextBlock_Bt(CMatchFinderMt *p)
946{ 946{
947 if (p->failure_LZ_BT) 947 if (p->failure_LZ_BT)
@@ -1163,7 +1163,7 @@ UInt32* MatchFinderMt_GetMatches_Bt4(CMatchFinderMt *p, UInt32 *d)
1163*/ 1163*/
1164 1164
1165 1165
1166static UInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *d) 1166static UInt32 * MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *d)
1167{ 1167{
1168 UInt32 h2, h3, /* h4, */ c2, c3 /* , c4 */; 1168 UInt32 h2, h3, /* h4, */ c2, c3 /* , c4 */;
1169 UInt32 *hash = p->hash; 1169 UInt32 *hash = p->hash;
@@ -1179,9 +1179,8 @@ static UInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *d)
1179 (hash + kFix3HashSize)[h3] = m; 1179 (hash + kFix3HashSize)[h3] = m;
1180 // (hash + kFix4HashSize)[h4] = m; 1180 // (hash + kFix4HashSize)[h4] = m;
1181 1181
1182 #define _USE_H2 1182 // #define BT5_USE_H2
1183 1183 // #ifdef BT5_USE_H2
1184 #ifdef _USE_H2
1185 if (c2 >= matchMinPos && cur[(ptrdiff_t)c2 - (ptrdiff_t)m] == cur[0]) 1184 if (c2 >= matchMinPos && cur[(ptrdiff_t)c2 - (ptrdiff_t)m] == cur[0])
1186 { 1185 {
1187 d[1] = m - c2 - 1; 1186 d[1] = m - c2 - 1;
@@ -1197,8 +1196,8 @@ static UInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *d)
1197 } 1196 }
1198 d[0] = 3; 1197 d[0] = 3;
1199 d += 2; 1198 d += 2;
1200 1199
1201 #ifdef _USE_H4 1200 #ifdef BT5_USE_H4
1202 if (c4 >= matchMinPos) 1201 if (c4 >= matchMinPos)
1203 if ( 1202 if (
1204 cur[(ptrdiff_t)c4 - (ptrdiff_t)m] == cur[0] && 1203 cur[(ptrdiff_t)c4 - (ptrdiff_t)m] == cur[0] &&
@@ -1214,7 +1213,7 @@ static UInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *d)
1214 d[0] = 2; 1213 d[0] = 2;
1215 d += 2; 1214 d += 2;
1216 } 1215 }
1217 #endif 1216 // #endif
1218 1217
1219 if (c3 >= matchMinPos && cur[(ptrdiff_t)c3 - (ptrdiff_t)m] == cur[0]) 1218 if (c3 >= matchMinPos && cur[(ptrdiff_t)c3 - (ptrdiff_t)m] == cur[0])
1220 { 1219 {
@@ -1228,7 +1227,7 @@ static UInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *d)
1228 d += 2; 1227 d += 2;
1229 } 1228 }
1230 1229
1231 #ifdef _USE_H4 1230 #ifdef BT5_USE_H4
1232 if (c4 >= matchMinPos) 1231 if (c4 >= matchMinPos)
1233 if ( 1232 if (
1234 cur[(ptrdiff_t)c4 - (ptrdiff_t)m] == cur[0] && 1233 cur[(ptrdiff_t)c4 - (ptrdiff_t)m] == cur[0] &&
@@ -1244,7 +1243,7 @@ static UInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *d)
1244} 1243}
1245 1244
1246 1245
1247static UInt32* MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *d) 1246static UInt32 * MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *d)
1248{ 1247{
1249 const UInt32 *bt = p->btBufPos; 1248 const UInt32 *bt = p->btBufPos;
1250 const UInt32 len = *bt++; 1249 const UInt32 len = *bt++;
@@ -1268,7 +1267,7 @@ static UInt32* MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *d)
1268 1267
1269 1268
1270 1269
1271static UInt32* MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *d) 1270static UInt32 * MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *d)
1272{ 1271{
1273 const UInt32 *bt = p->btBufPos; 1272 const UInt32 *bt = p->btBufPos;
1274 UInt32 len = *bt++; 1273 UInt32 len = *bt++;
@@ -1398,3 +1397,10 @@ void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder2 *vTable)
1398 break; 1397 break;
1399 } 1398 }
1400} 1399}
1400
1401#undef RINOK_THREAD
1402#undef PRF
1403#undef MF
1404#undef GetUi24hi_from32
1405#undef LOCK_BUFFER
1406#undef UNLOCK_BUFFER