• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* LzFindMt.h -- multithreaded Match finder for LZ algorithms
2 2018-07-04 : Igor Pavlov : Public domain */
3 
4 #ifndef __LZ_FIND_MT_H
5 #define __LZ_FIND_MT_H
6 
7 #include "LzFind.h"
8 #include "Threads.h"
9 
10 EXTERN_C_BEGIN
11 
12 #define kMtHashBlockSize (1 << 13)
13 #define kMtHashNumBlocks (1 << 3)
14 #define kMtHashNumBlocksMask (kMtHashNumBlocks - 1)
15 
16 #define kMtBtBlockSize (1 << 14)
17 #define kMtBtNumBlocks (1 << 6)
18 #define kMtBtNumBlocksMask (kMtBtNumBlocks - 1)
19 
20 typedef struct _CMtSync
21 {
22   BoolInt wasCreated;
23   BoolInt needStart;
24   BoolInt exit;
25   BoolInt stopWriting;
26 
27   CThread thread;
28   CAutoResetEvent canStart;
29   CAutoResetEvent wasStarted;
30   CAutoResetEvent wasStopped;
31   CSemaphore freeSemaphore;
32   CSemaphore filledSemaphore;
33   BoolInt csWasInitialized;
34   BoolInt csWasEntered;
35   CCriticalSection cs;
36   UInt32 numProcessedBlocks;
37 } CMtSync;
38 
39 typedef UInt32 * (*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances);
40 
41 /* kMtCacheLineDummy must be >= size_of_CPU_cache_line */
42 #define kMtCacheLineDummy 128
43 
44 typedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos,
45   UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc);
46 
47 typedef struct _CMatchFinderMt
48 {
49   /* LZ */
50   const Byte *pointerToCurPos;
51   UInt32 *btBuf;
52   UInt32 btBufPos;
53   UInt32 btBufPosLimit;
54   UInt32 lzPos;
55   UInt32 btNumAvailBytes;
56 
57   UInt32 *hash;
58   UInt32 fixedHashSize;
59   UInt32 historySize;
60   const UInt32 *crc;
61 
62   Mf_Mix_Matches MixMatchesFunc;
63 
64   /* LZ + BT */
65   CMtSync btSync;
66   Byte btDummy[kMtCacheLineDummy];
67 
68   /* BT */
69   UInt32 *hashBuf;
70   UInt32 hashBufPos;
71   UInt32 hashBufPosLimit;
72   UInt32 hashNumAvail;
73 
74   CLzRef *son;
75   UInt32 matchMaxLen;
76   UInt32 numHashBytes;
77   UInt32 pos;
78   const Byte *buffer;
79   UInt32 cyclicBufferPos;
80   UInt32 cyclicBufferSize; /* it must be historySize + 1 */
81   UInt32 cutValue;
82 
83   /* BT + Hash */
84   CMtSync hashSync;
85   /* Byte hashDummy[kMtCacheLineDummy]; */
86 
87   /* Hash */
88   Mf_GetHeads GetHeadsFunc;
89   CMatchFinder *MatchFinder;
90 } CMatchFinderMt;
91 
92 void MatchFinderMt_Construct(CMatchFinderMt *p);
93 void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAllocPtr alloc);
94 SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,
95     UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAllocPtr alloc);
96 void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable);
97 void MatchFinderMt_ReleaseStream(CMatchFinderMt *p);
98 
99 EXTERN_C_END
100 
101 #endif
102