1 /**************************************************************************
3 * Copyright 2013-2014 RAD Game Tools and Valve Software
4 * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 **************************************************************************/
27 /* LzFindMt.h -- multithreaded Match finder for LZ algorithms
28 2008-10-04 : Igor Pavlov : Public domain */
33 #include "lzma_Threads.h"
34 #include "lzma_LzFind.h"
39 #define kMtHashBlockSize (1 << 13)
40 #define kMtHashNumBlocks (1 << 3)
41 #define kMtHashNumBlocksMask (kMtHashNumBlocks - 1)
43 #define kMtBtBlockSize (1 << 14)
44 #define kMtBtNumBlocks (1 << 6)
45 #define kMtBtNumBlocksMask (kMtBtNumBlocks - 1)
47 typedef struct _CMtSync
55 CAutoResetEvent canStart;
56 CAutoResetEvent wasStarted;
57 CAutoResetEvent wasStopped;
58 CSemaphore freeSemaphore;
59 CSemaphore filledSemaphore;
60 Bool csWasInitialized;
63 UInt32 numProcessedBlocks;
66 typedef UInt32 *(*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances);
68 /* kMtCacheLineDummy must be >= size_of_CPU_cache_line */
69 #define kMtCacheLineDummy 128
71 typedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos,
72 UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc);
74 typedef struct _CMatchFinderMt
77 const Byte *pointerToCurPos;
82 UInt32 btNumAvailBytes;
89 Mf_Mix_Matches MixMatchesFunc;
93 Byte btDummy[kMtCacheLineDummy];
98 UInt32 hashBufPosLimit;
106 UInt32 cyclicBufferPos;
107 UInt32 cyclicBufferSize; /* it must be historySize + 1 */
112 /* Byte hashDummy[kMtCacheLineDummy]; */
115 Mf_GetHeads GetHeadsFunc;
116 CMatchFinder *MatchFinder;
119 void MatchFinderMt_Construct(CMatchFinderMt *p);
120 void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc);
121 SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,
122 UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc);
123 void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable);
124 void MatchFinderMt_ReleaseStream(CMatchFinderMt *p);