]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/C/LzmaCompress/Sdk/C/LzFindMt.h
Check In tool source code based on Build tool project revision r1655.
[mirror_edk2.git] / BaseTools / Source / C / LzmaCompress / Sdk / C / LzFindMt.h
1 /* LzFindMt.h -- multithreaded Match finder for LZ algorithms
2 2008-10-04 : Igor Pavlov : Public domain */
3
4 #ifndef __LZFINDMT_H
5 #define __LZFINDMT_H
6
7 #include "Threads.h"
8 #include "LzFind.h"
9
10 #define kMtHashBlockSize (1 << 13)
11 #define kMtHashNumBlocks (1 << 3)
12 #define kMtHashNumBlocksMask (kMtHashNumBlocks - 1)
13
14 #define kMtBtBlockSize (1 << 14)
15 #define kMtBtNumBlocks (1 << 6)
16 #define kMtBtNumBlocksMask (kMtBtNumBlocks - 1)
17
18 typedef struct _CMtSync
19 {
20 Bool wasCreated;
21 Bool needStart;
22 Bool exit;
23 Bool stopWriting;
24
25 CThread thread;
26 CAutoResetEvent canStart;
27 CAutoResetEvent wasStarted;
28 CAutoResetEvent wasStopped;
29 CSemaphore freeSemaphore;
30 CSemaphore filledSemaphore;
31 Bool csWasInitialized;
32 Bool csWasEntered;
33 CCriticalSection cs;
34 UInt32 numProcessedBlocks;
35 } CMtSync;
36
37 typedef UInt32 * (*Mf_Mix_Matches)(void *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 UInt32 btBufPos;
51 UInt32 btBufPosLimit;
52 UInt32 lzPos;
53 UInt32 btNumAvailBytes;
54
55 UInt32 *hash;
56 UInt32 fixedHashSize;
57 UInt32 historySize;
58 const UInt32 *crc;
59
60 Mf_Mix_Matches MixMatchesFunc;
61
62 /* LZ + BT */
63 CMtSync btSync;
64 Byte btDummy[kMtCacheLineDummy];
65
66 /* BT */
67 UInt32 *hashBuf;
68 UInt32 hashBufPos;
69 UInt32 hashBufPosLimit;
70 UInt32 hashNumAvail;
71
72 CLzRef *son;
73 UInt32 matchMaxLen;
74 UInt32 numHashBytes;
75 UInt32 pos;
76 Byte *buffer;
77 UInt32 cyclicBufferPos;
78 UInt32 cyclicBufferSize; /* it must be historySize + 1 */
79 UInt32 cutValue;
80
81 /* BT + Hash */
82 CMtSync hashSync;
83 /* Byte hashDummy[kMtCacheLineDummy]; */
84
85 /* Hash */
86 Mf_GetHeads GetHeadsFunc;
87 CMatchFinder *MatchFinder;
88 } CMatchFinderMt;
89
90 void MatchFinderMt_Construct(CMatchFinderMt *p);
91 void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc);
92 SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,
93 UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc);
94 void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable);
95 void MatchFinderMt_ReleaseStream(CMatchFinderMt *p);
96
97 #endif