LzFindMt.h 2.4 KB

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