1370b324cSopenharmony_ci/* LzFindMt.h -- multithreaded Match finder for LZ algorithms 2370b324cSopenharmony_ci2023-03-05 : Igor Pavlov : Public domain */ 3370b324cSopenharmony_ci 4370b324cSopenharmony_ci#ifndef ZIP7_INC_LZ_FIND_MT_H 5370b324cSopenharmony_ci#define ZIP7_INC_LZ_FIND_MT_H 6370b324cSopenharmony_ci 7370b324cSopenharmony_ci#include "LzFind.h" 8370b324cSopenharmony_ci#include "Threads.h" 9370b324cSopenharmony_ci 10370b324cSopenharmony_ciEXTERN_C_BEGIN 11370b324cSopenharmony_ci 12370b324cSopenharmony_citypedef struct 13370b324cSopenharmony_ci{ 14370b324cSopenharmony_ci UInt32 numProcessedBlocks; 15370b324cSopenharmony_ci CThread thread; 16370b324cSopenharmony_ci UInt64 affinity; 17370b324cSopenharmony_ci 18370b324cSopenharmony_ci BoolInt wasCreated; 19370b324cSopenharmony_ci BoolInt needStart; 20370b324cSopenharmony_ci BoolInt csWasInitialized; 21370b324cSopenharmony_ci BoolInt csWasEntered; 22370b324cSopenharmony_ci 23370b324cSopenharmony_ci BoolInt exit; 24370b324cSopenharmony_ci BoolInt stopWriting; 25370b324cSopenharmony_ci 26370b324cSopenharmony_ci CAutoResetEvent canStart; 27370b324cSopenharmony_ci CAutoResetEvent wasStopped; 28370b324cSopenharmony_ci CSemaphore freeSemaphore; 29370b324cSopenharmony_ci CSemaphore filledSemaphore; 30370b324cSopenharmony_ci CCriticalSection cs; 31370b324cSopenharmony_ci // UInt32 numBlocks_Sent; 32370b324cSopenharmony_ci} CMtSync; 33370b324cSopenharmony_ci 34370b324cSopenharmony_citypedef UInt32 * (*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances); 35370b324cSopenharmony_ci 36370b324cSopenharmony_ci/* kMtCacheLineDummy must be >= size_of_CPU_cache_line */ 37370b324cSopenharmony_ci#define kMtCacheLineDummy 128 38370b324cSopenharmony_ci 39370b324cSopenharmony_citypedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos, 40370b324cSopenharmony_ci UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc); 41370b324cSopenharmony_ci 42370b324cSopenharmony_citypedef struct 43370b324cSopenharmony_ci{ 44370b324cSopenharmony_ci /* LZ */ 45370b324cSopenharmony_ci const Byte *pointerToCurPos; 46370b324cSopenharmony_ci UInt32 *btBuf; 47370b324cSopenharmony_ci const UInt32 *btBufPos; 48370b324cSopenharmony_ci const UInt32 *btBufPosLimit; 49370b324cSopenharmony_ci UInt32 lzPos; 50370b324cSopenharmony_ci UInt32 btNumAvailBytes; 51370b324cSopenharmony_ci 52370b324cSopenharmony_ci UInt32 *hash; 53370b324cSopenharmony_ci UInt32 fixedHashSize; 54370b324cSopenharmony_ci // UInt32 hash4Mask; 55370b324cSopenharmony_ci UInt32 historySize; 56370b324cSopenharmony_ci const UInt32 *crc; 57370b324cSopenharmony_ci 58370b324cSopenharmony_ci Mf_Mix_Matches MixMatchesFunc; 59370b324cSopenharmony_ci UInt32 failure_LZ_BT; // failure in BT transfered to LZ 60370b324cSopenharmony_ci // UInt32 failure_LZ_LZ; // failure in LZ tables 61370b324cSopenharmony_ci UInt32 failureBuf[1]; 62370b324cSopenharmony_ci // UInt32 crc[256]; 63370b324cSopenharmony_ci 64370b324cSopenharmony_ci /* LZ + BT */ 65370b324cSopenharmony_ci CMtSync btSync; 66370b324cSopenharmony_ci Byte btDummy[kMtCacheLineDummy]; 67370b324cSopenharmony_ci 68370b324cSopenharmony_ci /* BT */ 69370b324cSopenharmony_ci UInt32 *hashBuf; 70370b324cSopenharmony_ci UInt32 hashBufPos; 71370b324cSopenharmony_ci UInt32 hashBufPosLimit; 72370b324cSopenharmony_ci UInt32 hashNumAvail; 73370b324cSopenharmony_ci UInt32 failure_BT; 74370b324cSopenharmony_ci 75370b324cSopenharmony_ci 76370b324cSopenharmony_ci CLzRef *son; 77370b324cSopenharmony_ci UInt32 matchMaxLen; 78370b324cSopenharmony_ci UInt32 numHashBytes; 79370b324cSopenharmony_ci UInt32 pos; 80370b324cSopenharmony_ci const Byte *buffer; 81370b324cSopenharmony_ci UInt32 cyclicBufferPos; 82370b324cSopenharmony_ci UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */ 83370b324cSopenharmony_ci UInt32 cutValue; 84370b324cSopenharmony_ci 85370b324cSopenharmony_ci /* BT + Hash */ 86370b324cSopenharmony_ci CMtSync hashSync; 87370b324cSopenharmony_ci /* Byte hashDummy[kMtCacheLineDummy]; */ 88370b324cSopenharmony_ci 89370b324cSopenharmony_ci /* Hash */ 90370b324cSopenharmony_ci Mf_GetHeads GetHeadsFunc; 91370b324cSopenharmony_ci CMatchFinder *MatchFinder; 92370b324cSopenharmony_ci // CMatchFinder MatchFinder; 93370b324cSopenharmony_ci} CMatchFinderMt; 94370b324cSopenharmony_ci 95370b324cSopenharmony_ci// only for Mt part 96370b324cSopenharmony_civoid MatchFinderMt_Construct(CMatchFinderMt *p); 97370b324cSopenharmony_civoid MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAllocPtr alloc); 98370b324cSopenharmony_ci 99370b324cSopenharmony_ciSRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore, 100370b324cSopenharmony_ci UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAllocPtr alloc); 101370b324cSopenharmony_civoid MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder2 *vTable); 102370b324cSopenharmony_ci 103370b324cSopenharmony_ci/* call MatchFinderMt_InitMt() before IMatchFinder::Init() */ 104370b324cSopenharmony_ciSRes MatchFinderMt_InitMt(CMatchFinderMt *p); 105370b324cSopenharmony_civoid MatchFinderMt_ReleaseStream(CMatchFinderMt *p); 106370b324cSopenharmony_ci 107370b324cSopenharmony_ciEXTERN_C_END 108370b324cSopenharmony_ci 109370b324cSopenharmony_ci#endif 110