]> git.cworth.org Git - vogl/blob - src/voglcore/lzma_LzFindMt.h
Initial vogl checkin
[vogl] / src / voglcore / lzma_LzFindMt.h
1 /**************************************************************************
2  *
3  * Copyright 2013-2014 RAD Game Tools and Valve Software
4  * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
5  * All Rights Reserved.
6  *
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:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
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
23  * THE SOFTWARE.
24  *
25  **************************************************************************/
26
27 /* LzFindMt.h -- multithreaded Match finder for LZ algorithms
28 2008-10-04 : Igor Pavlov : Public domain */
29
30 #ifndef __LZFINDMT_H
31 #define __LZFINDMT_H
32
33 #include "lzma_Threads.h"
34 #include "lzma_LzFind.h"
35
36 namespace vogl
37 {
38
39 #define kMtHashBlockSize (1 << 13)
40 #define kMtHashNumBlocks (1 << 3)
41 #define kMtHashNumBlocksMask (kMtHashNumBlocks - 1)
42
43 #define kMtBtBlockSize (1 << 14)
44 #define kMtBtNumBlocks (1 << 6)
45 #define kMtBtNumBlocksMask (kMtBtNumBlocks - 1)
46
47     typedef struct _CMtSync
48     {
49         Bool wasCreated;
50         Bool needStart;
51         Bool exit;
52         Bool stopWriting;
53
54         CThread thread;
55         CAutoResetEvent canStart;
56         CAutoResetEvent wasStarted;
57         CAutoResetEvent wasStopped;
58         CSemaphore freeSemaphore;
59         CSemaphore filledSemaphore;
60         Bool csWasInitialized;
61         Bool csWasEntered;
62         CCriticalSection cs;
63         UInt32 numProcessedBlocks;
64     } CMtSync;
65
66     typedef UInt32 *(*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances);
67
68 /* kMtCacheLineDummy must be >= size_of_CPU_cache_line */
69 #define kMtCacheLineDummy 128
70
71     typedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos,
72                                 UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc);
73
74     typedef struct _CMatchFinderMt
75     {
76         /* LZ */
77         const Byte *pointerToCurPos;
78         UInt32 *btBuf;
79         UInt32 btBufPos;
80         UInt32 btBufPosLimit;
81         UInt32 lzPos;
82         UInt32 btNumAvailBytes;
83
84         UInt32 *hash;
85         UInt32 fixedHashSize;
86         UInt32 historySize;
87         const UInt32 *crc;
88
89         Mf_Mix_Matches MixMatchesFunc;
90
91         /* LZ + BT */
92         CMtSync btSync;
93         Byte btDummy[kMtCacheLineDummy];
94
95         /* BT */
96         UInt32 *hashBuf;
97         UInt32 hashBufPos;
98         UInt32 hashBufPosLimit;
99         UInt32 hashNumAvail;
100
101         CLzRef *son;
102         UInt32 matchMaxLen;
103         UInt32 numHashBytes;
104         UInt32 pos;
105         Byte *buffer;
106         UInt32 cyclicBufferPos;
107         UInt32 cyclicBufferSize; /* it must be historySize + 1 */
108         UInt32 cutValue;
109
110         /* BT + Hash */
111         CMtSync hashSync;
112         /* Byte hashDummy[kMtCacheLineDummy]; */
113
114         /* Hash */
115         Mf_GetHeads GetHeadsFunc;
116         CMatchFinder *MatchFinder;
117     } CMatchFinderMt;
118
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);
125 }
126
127 #endif