xref: /aosp_15_r20/external/lzma/C/LzFindMt.h (revision f6dc9357d832569d4d1f5d24eacdb3935a1ae8e6)
1 /* LzFindMt.h -- multithreaded Match finder for LZ algorithms
2 2024-01-22 : Igor Pavlov : Public domain */
3 
4 #ifndef ZIP7_INC_LZ_FIND_MT_H
5 #define ZIP7_INC_LZ_FIND_MT_H
6 
7 #include "LzFind.h"
8 #include "Threads.h"
9 
10 EXTERN_C_BEGIN
11 
12 typedef struct
13 {
14   UInt32 numProcessedBlocks;
15   CThread thread;
16   UInt64 affinity;
17 
18   BoolInt wasCreated;
19   BoolInt needStart;
20   BoolInt csWasInitialized;
21   BoolInt csWasEntered;
22 
23   BoolInt exit;
24   BoolInt stopWriting;
25 
26   CAutoResetEvent canStart;
27   CAutoResetEvent wasStopped;
28   CSemaphore freeSemaphore;
29   CSemaphore filledSemaphore;
30   CCriticalSection cs;
31   // UInt32 numBlocks_Sent;
32 } CMtSync;
33 
34 
35 struct CMatchFinderMt_;
36 
37 typedef UInt32 * (*Mf_Mix_Matches)(struct CMatchFinderMt_ *p, UInt32 matchMinPos, UInt32 *distances);
38 
39 /* kMtCacheLineDummy must be >= size_of_CPU_cache_line */
40 #define kMtCacheLineDummy 128
41 
42 typedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos,
43   UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc);
44 
45 typedef struct CMatchFinderMt_
46 {
47   /* LZ */
48   const Byte *pointerToCurPos;
49   UInt32 *btBuf;
50   const UInt32 *btBufPos;
51   const UInt32 *btBufPosLimit;
52   UInt32 lzPos;
53   UInt32 btNumAvailBytes;
54 
55   UInt32 *hash;
56   UInt32 fixedHashSize;
57   // UInt32 hash4Mask;
58   UInt32 historySize;
59   const UInt32 *crc;
60 
61   Mf_Mix_Matches MixMatchesFunc;
62   UInt32 failure_LZ_BT; // failure in BT transfered to LZ
63   // UInt32 failure_LZ_LZ; // failure in LZ tables
64   UInt32 failureBuf[1];
65   // UInt32 crc[256];
66 
67   /* LZ + BT */
68   CMtSync btSync;
69   Byte btDummy[kMtCacheLineDummy];
70 
71   /* BT */
72   UInt32 *hashBuf;
73   UInt32 hashBufPos;
74   UInt32 hashBufPosLimit;
75   UInt32 hashNumAvail;
76   UInt32 failure_BT;
77 
78 
79   CLzRef *son;
80   UInt32 matchMaxLen;
81   UInt32 numHashBytes;
82   UInt32 pos;
83   const Byte *buffer;
84   UInt32 cyclicBufferPos;
85   UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */
86   UInt32 cutValue;
87 
88   /* BT + Hash */
89   CMtSync hashSync;
90   /* Byte hashDummy[kMtCacheLineDummy]; */
91 
92   /* Hash */
93   Mf_GetHeads GetHeadsFunc;
94   CMatchFinder *MatchFinder;
95   // CMatchFinder MatchFinder;
96 } CMatchFinderMt;
97 
98 // only for Mt part
99 void MatchFinderMt_Construct(CMatchFinderMt *p);
100 void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAllocPtr alloc);
101 
102 SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,
103     UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAllocPtr alloc);
104 void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder2 *vTable);
105 
106 /* call MatchFinderMt_InitMt() before IMatchFinder::Init() */
107 SRes MatchFinderMt_InitMt(CMatchFinderMt *p);
108 void MatchFinderMt_ReleaseStream(CMatchFinderMt *p);
109 
110 EXTERN_C_END
111 
112 #endif
113