diff options
Diffstat (limited to '')
-rw-r--r-- | CPP/7zip/Compress/BitlDecoder.h | 65 |
1 files changed, 59 insertions, 6 deletions
diff --git a/CPP/7zip/Compress/BitlDecoder.h b/CPP/7zip/Compress/BitlDecoder.h index 789ad1f..465c4d3 100644 --- a/CPP/7zip/Compress/BitlDecoder.h +++ b/CPP/7zip/Compress/BitlDecoder.h | |||
@@ -3,6 +3,8 @@ | |||
3 | #ifndef ZIP7_INC_BITL_DECODER_H | 3 | #ifndef ZIP7_INC_BITL_DECODER_H |
4 | #define ZIP7_INC_BITL_DECODER_H | 4 | #define ZIP7_INC_BITL_DECODER_H |
5 | 5 | ||
6 | #include "../../../C/CpuArch.h" | ||
7 | |||
6 | #include "../IStream.h" | 8 | #include "../IStream.h" |
7 | 9 | ||
8 | namespace NBitl { | 10 | namespace NBitl { |
@@ -10,10 +12,50 @@ namespace NBitl { | |||
10 | const unsigned kNumBigValueBits = 8 * 4; | 12 | const unsigned kNumBigValueBits = 8 * 4; |
11 | const unsigned kNumValueBytes = 3; | 13 | const unsigned kNumValueBytes = 3; |
12 | const unsigned kNumValueBits = 8 * kNumValueBytes; | 14 | const unsigned kNumValueBits = 8 * kNumValueBytes; |
13 | |||
14 | const UInt32 kMask = (1 << kNumValueBits) - 1; | 15 | const UInt32 kMask = (1 << kNumValueBits) - 1; |
15 | 16 | ||
16 | extern Byte kInvertTable[256]; | 17 | #if !defined(Z7_BITL_USE_REVERSE_BITS_TABLE) |
18 | #if 1 && defined(MY_CPU_ARM_OR_ARM64) \ | ||
19 | && (defined(MY_CPU_ARM64) || defined(__ARM_ARCH_6T2__) \ | ||
20 | || defined(__ARM_ARCH) && (__ARM_ARCH >= 7)) \ | ||
21 | && (defined(__GNUC__) && (__GNUC__ >= 4) \ | ||
22 | || defined(__clang__) && (__clang_major__ >= 4)) | ||
23 | #define Z7_BITL_USE_REVERSE_BITS_INSTRUCTION | ||
24 | #elif 1 | ||
25 | #define Z7_BITL_USE_REVERSE_BITS_TABLE | ||
26 | #endif | ||
27 | #endif | ||
28 | |||
29 | #if defined(Z7_BITL_USE_REVERSE_BITS_TABLE) | ||
30 | extern Byte kReverseTable[256]; | ||
31 | #endif | ||
32 | |||
33 | inline unsigned ReverseBits8(unsigned i) | ||
34 | { | ||
35 | #if defined(Z7_BITL_USE_REVERSE_BITS_TABLE) | ||
36 | return kReverseTable[i]; | ||
37 | #elif defined(Z7_BITL_USE_REVERSE_BITS_INSTRUCTION) | ||
38 | // rbit is available in ARMv6T2 and above | ||
39 | asm ("rbit " | ||
40 | #if defined(MY_CPU_ARM) | ||
41 | "%0,%0" // it uses default register size, | ||
42 | // but we need 32-bit register here. | ||
43 | // we must use it only if default register size is 32-bit. | ||
44 | // it will work incorrectly for ARM64. | ||
45 | #else | ||
46 | "%w0,%w0" // it uses 32-bit registers in ARM64. | ||
47 | // compiler for (MY_CPU_ARM) can't compile it. | ||
48 | #endif | ||
49 | : "+r" (i)); | ||
50 | return i >> 24; | ||
51 | #else | ||
52 | unsigned | ||
53 | x = ((i & 0x55) << 1) | ((i >> 1) & 0x55); | ||
54 | x = ((x & 0x33) << 2) | ((x >> 2) & 0x33); | ||
55 | return ((x & 0x0f) << 4) | (x >> 4); | ||
56 | #endif | ||
57 | } | ||
58 | |||
17 | 59 | ||
18 | /* TInByte must support "Extra Bytes" (bytes that can be read after the end of stream | 60 | /* TInByte must support "Extra Bytes" (bytes that can be read after the end of stream |
19 | TInByte::ReadByte() returns 0xFF after the end of stream | 61 | TInByte::ReadByte() returns 0xFF after the end of stream |
@@ -31,6 +73,7 @@ protected: | |||
31 | public: | 73 | public: |
32 | bool Create(UInt32 bufSize) { return _stream.Create(bufSize); } | 74 | bool Create(UInt32 bufSize) { return _stream.Create(bufSize); } |
33 | void SetStream(ISequentialInStream *inStream) { _stream.SetStream(inStream); } | 75 | void SetStream(ISequentialInStream *inStream) { _stream.SetStream(inStream); } |
76 | void ClearStreamPtr() { _stream.ClearStreamPtr(); } | ||
34 | void Init() | 77 | void Init() |
35 | { | 78 | { |
36 | _stream.Init(); | 79 | _stream.Init(); |
@@ -107,9 +150,9 @@ public: | |||
107 | { | 150 | { |
108 | for (; this->_bitPos >= 8; this->_bitPos -= 8) | 151 | for (; this->_bitPos >= 8; this->_bitPos -= 8) |
109 | { | 152 | { |
110 | Byte b = this->_stream.ReadByte(); | 153 | const unsigned b = this->_stream.ReadByte(); |
111 | _normalValue = ((UInt32)b << (kNumBigValueBits - this->_bitPos)) | _normalValue; | 154 | _normalValue = ((UInt32)b << (kNumBigValueBits - this->_bitPos)) | _normalValue; |
112 | this->_value = (this->_value << 8) | kInvertTable[b]; | 155 | this->_value = (this->_value << 8) | ReverseBits8(b); |
113 | } | 156 | } |
114 | } | 157 | } |
115 | 158 | ||
@@ -119,11 +162,18 @@ public: | |||
119 | Normalize(); | 162 | Normalize(); |
120 | return ((this->_value >> (8 - this->_bitPos)) & kMask) >> (kNumValueBits - numBits); | 163 | return ((this->_value >> (8 - this->_bitPos)) & kMask) >> (kNumValueBits - numBits); |
121 | } | 164 | } |
165 | |||
166 | Z7_FORCE_INLINE | ||
167 | UInt32 GetValue_InHigh32bits() | ||
168 | { | ||
169 | Normalize(); | ||
170 | return this->_value << this->_bitPos; | ||
171 | } | ||
122 | 172 | ||
123 | Z7_FORCE_INLINE | 173 | Z7_FORCE_INLINE |
124 | void MovePos(unsigned numBits) | 174 | void MovePos(size_t numBits) |
125 | { | 175 | { |
126 | this->_bitPos += numBits; | 176 | this->_bitPos += (unsigned)numBits; |
127 | _normalValue >>= numBits; | 177 | _normalValue >>= numBits; |
128 | } | 178 | } |
129 | 179 | ||
@@ -140,6 +190,9 @@ public: | |||
140 | 190 | ||
141 | Z7_FORCE_INLINE | 191 | Z7_FORCE_INLINE |
142 | Byte ReadDirectByte() { return this->_stream.ReadByte(); } | 192 | Byte ReadDirectByte() { return this->_stream.ReadByte(); } |
193 | |||
194 | Z7_FORCE_INLINE | ||
195 | size_t ReadDirectBytesPart(Byte *buf, size_t size) { return this->_stream.ReadBytesPart(buf, size); } | ||
143 | 196 | ||
144 | Z7_FORCE_INLINE | 197 | Z7_FORCE_INLINE |
145 | Byte ReadAlignedByte() | 198 | Byte ReadAlignedByte() |