|
@@ -20,7 +20,7 @@ type dEntrySingle struct {
|
|
|
|
|
|
// double-symbols decoding
|
|
// double-symbols decoding
|
|
type dEntryDouble struct {
|
|
type dEntryDouble struct {
|
|
- seq uint16
|
|
|
|
|
|
+ seq [4]byte
|
|
nBits uint8
|
|
nBits uint8
|
|
len uint8
|
|
len uint8
|
|
}
|
|
}
|
|
@@ -344,35 +344,241 @@ func (d *Decoder) decompress1X8Bit(dst, src []byte) ([]byte, error) {
|
|
var buf [256]byte
|
|
var buf [256]byte
|
|
var off uint8
|
|
var off uint8
|
|
|
|
|
|
- shift := (8 - d.actualTableLog) & 7
|
|
|
|
-
|
|
|
|
- //fmt.Printf("mask: %b, tl:%d\n", mask, d.actualTableLog)
|
|
|
|
- for br.off >= 4 {
|
|
|
|
- br.fillFast()
|
|
|
|
- v := dt[br.peekByteFast()>>shift]
|
|
|
|
- br.advance(uint8(v.entry))
|
|
|
|
- buf[off+0] = uint8(v.entry >> 8)
|
|
|
|
-
|
|
|
|
- v = dt[br.peekByteFast()>>shift]
|
|
|
|
- br.advance(uint8(v.entry))
|
|
|
|
- buf[off+1] = uint8(v.entry >> 8)
|
|
|
|
-
|
|
|
|
- v = dt[br.peekByteFast()>>shift]
|
|
|
|
- br.advance(uint8(v.entry))
|
|
|
|
- buf[off+2] = uint8(v.entry >> 8)
|
|
|
|
-
|
|
|
|
- v = dt[br.peekByteFast()>>shift]
|
|
|
|
- br.advance(uint8(v.entry))
|
|
|
|
- buf[off+3] = uint8(v.entry >> 8)
|
|
|
|
-
|
|
|
|
- off += 4
|
|
|
|
- if off == 0 {
|
|
|
|
- if len(dst)+256 > maxDecodedSize {
|
|
|
|
- br.close()
|
|
|
|
- return nil, ErrMaxDecodedSizeExceeded
|
|
|
|
|
|
+ switch d.actualTableLog {
|
|
|
|
+ case 8:
|
|
|
|
+ const shift = 8 - 8
|
|
|
|
+ for br.off >= 4 {
|
|
|
|
+ br.fillFast()
|
|
|
|
+ v := dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+0] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ v = dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+1] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ v = dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+2] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ v = dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+3] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ off += 4
|
|
|
|
+ if off == 0 {
|
|
|
|
+ if len(dst)+256 > maxDecodedSize {
|
|
|
|
+ br.close()
|
|
|
|
+ return nil, ErrMaxDecodedSizeExceeded
|
|
|
|
+ }
|
|
|
|
+ dst = append(dst, buf[:]...)
|
|
}
|
|
}
|
|
- dst = append(dst, buf[:]...)
|
|
|
|
}
|
|
}
|
|
|
|
+ case 7:
|
|
|
|
+ const shift = 8 - 7
|
|
|
|
+ for br.off >= 4 {
|
|
|
|
+ br.fillFast()
|
|
|
|
+ v := dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+0] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ v = dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+1] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ v = dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+2] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ v = dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+3] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ off += 4
|
|
|
|
+ if off == 0 {
|
|
|
|
+ if len(dst)+256 > maxDecodedSize {
|
|
|
|
+ br.close()
|
|
|
|
+ return nil, ErrMaxDecodedSizeExceeded
|
|
|
|
+ }
|
|
|
|
+ dst = append(dst, buf[:]...)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ case 6:
|
|
|
|
+ const shift = 8 - 6
|
|
|
|
+ for br.off >= 4 {
|
|
|
|
+ br.fillFast()
|
|
|
|
+ v := dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+0] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ v = dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+1] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ v = dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+2] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ v = dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+3] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ off += 4
|
|
|
|
+ if off == 0 {
|
|
|
|
+ if len(dst)+256 > maxDecodedSize {
|
|
|
|
+ br.close()
|
|
|
|
+ return nil, ErrMaxDecodedSizeExceeded
|
|
|
|
+ }
|
|
|
|
+ dst = append(dst, buf[:]...)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ case 5:
|
|
|
|
+ const shift = 8 - 5
|
|
|
|
+ for br.off >= 4 {
|
|
|
|
+ br.fillFast()
|
|
|
|
+ v := dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+0] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ v = dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+1] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ v = dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+2] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ v = dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+3] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ off += 4
|
|
|
|
+ if off == 0 {
|
|
|
|
+ if len(dst)+256 > maxDecodedSize {
|
|
|
|
+ br.close()
|
|
|
|
+ return nil, ErrMaxDecodedSizeExceeded
|
|
|
|
+ }
|
|
|
|
+ dst = append(dst, buf[:]...)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ case 4:
|
|
|
|
+ const shift = 8 - 4
|
|
|
|
+ for br.off >= 4 {
|
|
|
|
+ br.fillFast()
|
|
|
|
+ v := dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+0] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ v = dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+1] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ v = dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+2] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ v = dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+3] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ off += 4
|
|
|
|
+ if off == 0 {
|
|
|
|
+ if len(dst)+256 > maxDecodedSize {
|
|
|
|
+ br.close()
|
|
|
|
+ return nil, ErrMaxDecodedSizeExceeded
|
|
|
|
+ }
|
|
|
|
+ dst = append(dst, buf[:]...)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ case 3:
|
|
|
|
+ const shift = 8 - 3
|
|
|
|
+ for br.off >= 4 {
|
|
|
|
+ br.fillFast()
|
|
|
|
+ v := dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+0] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ v = dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+1] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ v = dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+2] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ v = dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+3] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ off += 4
|
|
|
|
+ if off == 0 {
|
|
|
|
+ if len(dst)+256 > maxDecodedSize {
|
|
|
|
+ br.close()
|
|
|
|
+ return nil, ErrMaxDecodedSizeExceeded
|
|
|
|
+ }
|
|
|
|
+ dst = append(dst, buf[:]...)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ case 2:
|
|
|
|
+ const shift = 8 - 2
|
|
|
|
+ for br.off >= 4 {
|
|
|
|
+ br.fillFast()
|
|
|
|
+ v := dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+0] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ v = dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+1] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ v = dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+2] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ v = dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+3] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ off += 4
|
|
|
|
+ if off == 0 {
|
|
|
|
+ if len(dst)+256 > maxDecodedSize {
|
|
|
|
+ br.close()
|
|
|
|
+ return nil, ErrMaxDecodedSizeExceeded
|
|
|
|
+ }
|
|
|
|
+ dst = append(dst, buf[:]...)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ case 1:
|
|
|
|
+ const shift = 8 - 1
|
|
|
|
+ for br.off >= 4 {
|
|
|
|
+ br.fillFast()
|
|
|
|
+ v := dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+0] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ v = dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+1] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ v = dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+2] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ v = dt[uint8(br.value>>(56+shift))]
|
|
|
|
+ br.advance(uint8(v.entry))
|
|
|
|
+ buf[off+3] = uint8(v.entry >> 8)
|
|
|
|
+
|
|
|
|
+ off += 4
|
|
|
|
+ if off == 0 {
|
|
|
|
+ if len(dst)+256 > maxDecodedSize {
|
|
|
|
+ br.close()
|
|
|
|
+ return nil, ErrMaxDecodedSizeExceeded
|
|
|
|
+ }
|
|
|
|
+ dst = append(dst, buf[:]...)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ default:
|
|
|
|
+ return nil, fmt.Errorf("invalid tablelog: %d", d.actualTableLog)
|
|
}
|
|
}
|
|
|
|
|
|
if len(dst)+int(off) > maxDecodedSize {
|
|
if len(dst)+int(off) > maxDecodedSize {
|
|
@@ -383,6 +589,8 @@ func (d *Decoder) decompress1X8Bit(dst, src []byte) ([]byte, error) {
|
|
|
|
|
|
// br < 4, so uint8 is fine
|
|
// br < 4, so uint8 is fine
|
|
bitsLeft := int8(uint8(br.off)*8 + (64 - br.bitsRead))
|
|
bitsLeft := int8(uint8(br.off)*8 + (64 - br.bitsRead))
|
|
|
|
+ shift := (8 - d.actualTableLog) & 7
|
|
|
|
+
|
|
for bitsLeft > 0 {
|
|
for bitsLeft > 0 {
|
|
if br.bitsRead >= 64-8 {
|
|
if br.bitsRead >= 64-8 {
|
|
for br.off > 0 {
|
|
for br.off > 0 {
|
|
@@ -423,24 +631,24 @@ func (d *Decoder) decompress1X8BitExactly(dst, src []byte) ([]byte, error) {
|
|
var buf [256]byte
|
|
var buf [256]byte
|
|
var off uint8
|
|
var off uint8
|
|
|
|
|
|
- const shift = 0
|
|
|
|
|
|
+ const shift = 56
|
|
|
|
|
|
//fmt.Printf("mask: %b, tl:%d\n", mask, d.actualTableLog)
|
|
//fmt.Printf("mask: %b, tl:%d\n", mask, d.actualTableLog)
|
|
for br.off >= 4 {
|
|
for br.off >= 4 {
|
|
br.fillFast()
|
|
br.fillFast()
|
|
- v := dt[br.peekByteFast()>>shift]
|
|
|
|
|
|
+ v := dt[uint8(br.value>>shift)]
|
|
br.advance(uint8(v.entry))
|
|
br.advance(uint8(v.entry))
|
|
buf[off+0] = uint8(v.entry >> 8)
|
|
buf[off+0] = uint8(v.entry >> 8)
|
|
|
|
|
|
- v = dt[br.peekByteFast()>>shift]
|
|
|
|
|
|
+ v = dt[uint8(br.value>>shift)]
|
|
br.advance(uint8(v.entry))
|
|
br.advance(uint8(v.entry))
|
|
buf[off+1] = uint8(v.entry >> 8)
|
|
buf[off+1] = uint8(v.entry >> 8)
|
|
|
|
|
|
- v = dt[br.peekByteFast()>>shift]
|
|
|
|
|
|
+ v = dt[uint8(br.value>>shift)]
|
|
br.advance(uint8(v.entry))
|
|
br.advance(uint8(v.entry))
|
|
buf[off+2] = uint8(v.entry >> 8)
|
|
buf[off+2] = uint8(v.entry >> 8)
|
|
|
|
|
|
- v = dt[br.peekByteFast()>>shift]
|
|
|
|
|
|
+ v = dt[uint8(br.value>>shift)]
|
|
br.advance(uint8(v.entry))
|
|
br.advance(uint8(v.entry))
|
|
buf[off+3] = uint8(v.entry >> 8)
|
|
buf[off+3] = uint8(v.entry >> 8)
|
|
|
|
|
|
@@ -474,7 +682,7 @@ func (d *Decoder) decompress1X8BitExactly(dst, src []byte) ([]byte, error) {
|
|
br.close()
|
|
br.close()
|
|
return nil, ErrMaxDecodedSizeExceeded
|
|
return nil, ErrMaxDecodedSizeExceeded
|
|
}
|
|
}
|
|
- v := dt[br.peekByteFast()>>shift]
|
|
|
|
|
|
+ v := dt[br.peekByteFast()]
|
|
nBits := uint8(v.entry)
|
|
nBits := uint8(v.entry)
|
|
br.advance(nBits)
|
|
br.advance(nBits)
|
|
bitsLeft -= int8(nBits)
|
|
bitsLeft -= int8(nBits)
|
|
@@ -545,23 +753,21 @@ func (d *Decoder) Decompress4X(dst, src []byte) ([]byte, error) {
|
|
br[stream2].fillFast()
|
|
br[stream2].fillFast()
|
|
|
|
|
|
val := br[stream].peekBitsFast(d.actualTableLog)
|
|
val := br[stream].peekBitsFast(d.actualTableLog)
|
|
- v := single[val&tlMask]
|
|
|
|
- br[stream].advance(uint8(v.entry))
|
|
|
|
- buf[off+bufoff*stream] = uint8(v.entry >> 8)
|
|
|
|
-
|
|
|
|
val2 := br[stream2].peekBitsFast(d.actualTableLog)
|
|
val2 := br[stream2].peekBitsFast(d.actualTableLog)
|
|
|
|
+ v := single[val&tlMask]
|
|
v2 := single[val2&tlMask]
|
|
v2 := single[val2&tlMask]
|
|
|
|
+ br[stream].advance(uint8(v.entry))
|
|
br[stream2].advance(uint8(v2.entry))
|
|
br[stream2].advance(uint8(v2.entry))
|
|
|
|
+ buf[off+bufoff*stream] = uint8(v.entry >> 8)
|
|
buf[off+bufoff*stream2] = uint8(v2.entry >> 8)
|
|
buf[off+bufoff*stream2] = uint8(v2.entry >> 8)
|
|
|
|
|
|
val = br[stream].peekBitsFast(d.actualTableLog)
|
|
val = br[stream].peekBitsFast(d.actualTableLog)
|
|
- v = single[val&tlMask]
|
|
|
|
- br[stream].advance(uint8(v.entry))
|
|
|
|
- buf[off+bufoff*stream+1] = uint8(v.entry >> 8)
|
|
|
|
-
|
|
|
|
val2 = br[stream2].peekBitsFast(d.actualTableLog)
|
|
val2 = br[stream2].peekBitsFast(d.actualTableLog)
|
|
|
|
+ v = single[val&tlMask]
|
|
v2 = single[val2&tlMask]
|
|
v2 = single[val2&tlMask]
|
|
|
|
+ br[stream].advance(uint8(v.entry))
|
|
br[stream2].advance(uint8(v2.entry))
|
|
br[stream2].advance(uint8(v2.entry))
|
|
|
|
+ buf[off+bufoff*stream+1] = uint8(v.entry >> 8)
|
|
buf[off+bufoff*stream2+1] = uint8(v2.entry >> 8)
|
|
buf[off+bufoff*stream2+1] = uint8(v2.entry >> 8)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -572,23 +778,21 @@ func (d *Decoder) Decompress4X(dst, src []byte) ([]byte, error) {
|
|
br[stream2].fillFast()
|
|
br[stream2].fillFast()
|
|
|
|
|
|
val := br[stream].peekBitsFast(d.actualTableLog)
|
|
val := br[stream].peekBitsFast(d.actualTableLog)
|
|
- v := single[val&tlMask]
|
|
|
|
- br[stream].advance(uint8(v.entry))
|
|
|
|
- buf[off+bufoff*stream] = uint8(v.entry >> 8)
|
|
|
|
-
|
|
|
|
val2 := br[stream2].peekBitsFast(d.actualTableLog)
|
|
val2 := br[stream2].peekBitsFast(d.actualTableLog)
|
|
|
|
+ v := single[val&tlMask]
|
|
v2 := single[val2&tlMask]
|
|
v2 := single[val2&tlMask]
|
|
|
|
+ br[stream].advance(uint8(v.entry))
|
|
br[stream2].advance(uint8(v2.entry))
|
|
br[stream2].advance(uint8(v2.entry))
|
|
|
|
+ buf[off+bufoff*stream] = uint8(v.entry >> 8)
|
|
buf[off+bufoff*stream2] = uint8(v2.entry >> 8)
|
|
buf[off+bufoff*stream2] = uint8(v2.entry >> 8)
|
|
|
|
|
|
val = br[stream].peekBitsFast(d.actualTableLog)
|
|
val = br[stream].peekBitsFast(d.actualTableLog)
|
|
- v = single[val&tlMask]
|
|
|
|
- br[stream].advance(uint8(v.entry))
|
|
|
|
- buf[off+bufoff*stream+1] = uint8(v.entry >> 8)
|
|
|
|
-
|
|
|
|
val2 = br[stream2].peekBitsFast(d.actualTableLog)
|
|
val2 = br[stream2].peekBitsFast(d.actualTableLog)
|
|
|
|
+ v = single[val&tlMask]
|
|
v2 = single[val2&tlMask]
|
|
v2 = single[val2&tlMask]
|
|
|
|
+ br[stream].advance(uint8(v.entry))
|
|
br[stream2].advance(uint8(v2.entry))
|
|
br[stream2].advance(uint8(v2.entry))
|
|
|
|
+ buf[off+bufoff*stream+1] = uint8(v.entry >> 8)
|
|
buf[off+bufoff*stream2+1] = uint8(v2.entry >> 8)
|
|
buf[off+bufoff*stream2+1] = uint8(v2.entry >> 8)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -706,10 +910,9 @@ func (d *Decoder) decompress4X8bit(dst, src []byte) ([]byte, error) {
|
|
out := dst
|
|
out := dst
|
|
dstEvery := (dstSize + 3) / 4
|
|
dstEvery := (dstSize + 3) / 4
|
|
|
|
|
|
- shift := (8 - d.actualTableLog) & 7
|
|
|
|
|
|
+ shift := (56 + (8 - d.actualTableLog)) & 63
|
|
|
|
|
|
const tlSize = 1 << 8
|
|
const tlSize = 1 << 8
|
|
- const tlMask = tlSize - 1
|
|
|
|
single := d.dt.single[:tlSize]
|
|
single := d.dt.single[:tlSize]
|
|
|
|
|
|
// Use temp table to avoid bound checks/append penalty.
|
|
// Use temp table to avoid bound checks/append penalty.
|
|
@@ -728,79 +931,91 @@ func (d *Decoder) decompress4X8bit(dst, src []byte) ([]byte, error) {
|
|
// Interleave 2 decodes.
|
|
// Interleave 2 decodes.
|
|
const stream = 0
|
|
const stream = 0
|
|
const stream2 = 1
|
|
const stream2 = 1
|
|
- br[stream].fillFast()
|
|
|
|
- br[stream2].fillFast()
|
|
|
|
-
|
|
|
|
- v := single[br[stream].peekByteFast()>>shift].entry
|
|
|
|
|
|
+ br1 := &br[stream]
|
|
|
|
+ br2 := &br[stream2]
|
|
|
|
+ br1.fillFast()
|
|
|
|
+ br2.fillFast()
|
|
|
|
+
|
|
|
|
+ v := single[uint8(br1.value>>shift)].entry
|
|
|
|
+ v2 := single[uint8(br2.value>>shift)].entry
|
|
|
|
+ br1.bitsRead += uint8(v)
|
|
|
|
+ br1.value <<= v & 63
|
|
|
|
+ br2.bitsRead += uint8(v2)
|
|
|
|
+ br2.value <<= v2 & 63
|
|
buf[off+bufoff*stream] = uint8(v >> 8)
|
|
buf[off+bufoff*stream] = uint8(v >> 8)
|
|
- br[stream].advance(uint8(v))
|
|
|
|
-
|
|
|
|
- v2 := single[br[stream2].peekByteFast()>>shift].entry
|
|
|
|
buf[off+bufoff*stream2] = uint8(v2 >> 8)
|
|
buf[off+bufoff*stream2] = uint8(v2 >> 8)
|
|
- br[stream2].advance(uint8(v2))
|
|
|
|
|
|
|
|
- v = single[br[stream].peekByteFast()>>shift].entry
|
|
|
|
|
|
+ v = single[uint8(br1.value>>shift)].entry
|
|
|
|
+ v2 = single[uint8(br2.value>>shift)].entry
|
|
|
|
+ br1.bitsRead += uint8(v)
|
|
|
|
+ br1.value <<= v & 63
|
|
|
|
+ br2.bitsRead += uint8(v2)
|
|
|
|
+ br2.value <<= v2 & 63
|
|
buf[off+bufoff*stream+1] = uint8(v >> 8)
|
|
buf[off+bufoff*stream+1] = uint8(v >> 8)
|
|
- br[stream].advance(uint8(v))
|
|
|
|
-
|
|
|
|
- v2 = single[br[stream2].peekByteFast()>>shift].entry
|
|
|
|
buf[off+bufoff*stream2+1] = uint8(v2 >> 8)
|
|
buf[off+bufoff*stream2+1] = uint8(v2 >> 8)
|
|
- br[stream2].advance(uint8(v2))
|
|
|
|
|
|
|
|
- v = single[br[stream].peekByteFast()>>shift].entry
|
|
|
|
|
|
+ v = single[uint8(br1.value>>shift)].entry
|
|
|
|
+ v2 = single[uint8(br2.value>>shift)].entry
|
|
|
|
+ br1.bitsRead += uint8(v)
|
|
|
|
+ br1.value <<= v & 63
|
|
|
|
+ br2.bitsRead += uint8(v2)
|
|
|
|
+ br2.value <<= v2 & 63
|
|
buf[off+bufoff*stream+2] = uint8(v >> 8)
|
|
buf[off+bufoff*stream+2] = uint8(v >> 8)
|
|
- br[stream].advance(uint8(v))
|
|
|
|
-
|
|
|
|
- v2 = single[br[stream2].peekByteFast()>>shift].entry
|
|
|
|
buf[off+bufoff*stream2+2] = uint8(v2 >> 8)
|
|
buf[off+bufoff*stream2+2] = uint8(v2 >> 8)
|
|
- br[stream2].advance(uint8(v2))
|
|
|
|
|
|
|
|
- v = single[br[stream].peekByteFast()>>shift].entry
|
|
|
|
- buf[off+bufoff*stream+3] = uint8(v >> 8)
|
|
|
|
- br[stream].advance(uint8(v))
|
|
|
|
-
|
|
|
|
- v2 = single[br[stream2].peekByteFast()>>shift].entry
|
|
|
|
|
|
+ v = single[uint8(br1.value>>shift)].entry
|
|
|
|
+ v2 = single[uint8(br2.value>>shift)].entry
|
|
|
|
+ br1.bitsRead += uint8(v)
|
|
|
|
+ br1.value <<= v & 63
|
|
|
|
+ br2.bitsRead += uint8(v2)
|
|
|
|
+ br2.value <<= v2 & 63
|
|
buf[off+bufoff*stream2+3] = uint8(v2 >> 8)
|
|
buf[off+bufoff*stream2+3] = uint8(v2 >> 8)
|
|
- br[stream2].advance(uint8(v2))
|
|
|
|
|
|
+ buf[off+bufoff*stream+3] = uint8(v >> 8)
|
|
}
|
|
}
|
|
|
|
|
|
{
|
|
{
|
|
const stream = 2
|
|
const stream = 2
|
|
const stream2 = 3
|
|
const stream2 = 3
|
|
- br[stream].fillFast()
|
|
|
|
- br[stream2].fillFast()
|
|
|
|
-
|
|
|
|
- v := single[br[stream].peekByteFast()>>shift].entry
|
|
|
|
|
|
+ br1 := &br[stream]
|
|
|
|
+ br2 := &br[stream2]
|
|
|
|
+ br1.fillFast()
|
|
|
|
+ br2.fillFast()
|
|
|
|
+
|
|
|
|
+ v := single[uint8(br1.value>>shift)].entry
|
|
|
|
+ v2 := single[uint8(br2.value>>shift)].entry
|
|
|
|
+ br1.bitsRead += uint8(v)
|
|
|
|
+ br1.value <<= v & 63
|
|
|
|
+ br2.bitsRead += uint8(v2)
|
|
|
|
+ br2.value <<= v2 & 63
|
|
buf[off+bufoff*stream] = uint8(v >> 8)
|
|
buf[off+bufoff*stream] = uint8(v >> 8)
|
|
- br[stream].advance(uint8(v))
|
|
|
|
-
|
|
|
|
- v2 := single[br[stream2].peekByteFast()>>shift].entry
|
|
|
|
buf[off+bufoff*stream2] = uint8(v2 >> 8)
|
|
buf[off+bufoff*stream2] = uint8(v2 >> 8)
|
|
- br[stream2].advance(uint8(v2))
|
|
|
|
|
|
|
|
- v = single[br[stream].peekByteFast()>>shift].entry
|
|
|
|
|
|
+ v = single[uint8(br1.value>>shift)].entry
|
|
|
|
+ v2 = single[uint8(br2.value>>shift)].entry
|
|
|
|
+ br1.bitsRead += uint8(v)
|
|
|
|
+ br1.value <<= v & 63
|
|
|
|
+ br2.bitsRead += uint8(v2)
|
|
|
|
+ br2.value <<= v2 & 63
|
|
buf[off+bufoff*stream+1] = uint8(v >> 8)
|
|
buf[off+bufoff*stream+1] = uint8(v >> 8)
|
|
- br[stream].advance(uint8(v))
|
|
|
|
-
|
|
|
|
- v2 = single[br[stream2].peekByteFast()>>shift].entry
|
|
|
|
buf[off+bufoff*stream2+1] = uint8(v2 >> 8)
|
|
buf[off+bufoff*stream2+1] = uint8(v2 >> 8)
|
|
- br[stream2].advance(uint8(v2))
|
|
|
|
|
|
|
|
- v = single[br[stream].peekByteFast()>>shift].entry
|
|
|
|
|
|
+ v = single[uint8(br1.value>>shift)].entry
|
|
|
|
+ v2 = single[uint8(br2.value>>shift)].entry
|
|
|
|
+ br1.bitsRead += uint8(v)
|
|
|
|
+ br1.value <<= v & 63
|
|
|
|
+ br2.bitsRead += uint8(v2)
|
|
|
|
+ br2.value <<= v2 & 63
|
|
buf[off+bufoff*stream+2] = uint8(v >> 8)
|
|
buf[off+bufoff*stream+2] = uint8(v >> 8)
|
|
- br[stream].advance(uint8(v))
|
|
|
|
-
|
|
|
|
- v2 = single[br[stream2].peekByteFast()>>shift].entry
|
|
|
|
buf[off+bufoff*stream2+2] = uint8(v2 >> 8)
|
|
buf[off+bufoff*stream2+2] = uint8(v2 >> 8)
|
|
- br[stream2].advance(uint8(v2))
|
|
|
|
-
|
|
|
|
- v = single[br[stream].peekByteFast()>>shift].entry
|
|
|
|
- buf[off+bufoff*stream+3] = uint8(v >> 8)
|
|
|
|
- br[stream].advance(uint8(v))
|
|
|
|
|
|
|
|
- v2 = single[br[stream2].peekByteFast()>>shift].entry
|
|
|
|
|
|
+ v = single[uint8(br1.value>>shift)].entry
|
|
|
|
+ v2 = single[uint8(br2.value>>shift)].entry
|
|
|
|
+ br1.bitsRead += uint8(v)
|
|
|
|
+ br1.value <<= v & 63
|
|
|
|
+ br2.bitsRead += uint8(v2)
|
|
|
|
+ br2.value <<= v2 & 63
|
|
buf[off+bufoff*stream2+3] = uint8(v2 >> 8)
|
|
buf[off+bufoff*stream2+3] = uint8(v2 >> 8)
|
|
- br[stream2].advance(uint8(v2))
|
|
|
|
|
|
+ buf[off+bufoff*stream+3] = uint8(v >> 8)
|
|
}
|
|
}
|
|
|
|
|
|
off += 4
|
|
off += 4
|
|
@@ -866,7 +1081,7 @@ func (d *Decoder) decompress4X8bit(dst, src []byte) ([]byte, error) {
|
|
}
|
|
}
|
|
|
|
|
|
// Read value and increment offset.
|
|
// Read value and increment offset.
|
|
- v := single[br.peekByteFast()>>shift].entry
|
|
|
|
|
|
+ v := single[uint8(br.value>>shift)].entry
|
|
nBits := uint8(v)
|
|
nBits := uint8(v)
|
|
br.advance(nBits)
|
|
br.advance(nBits)
|
|
bitsLeft -= int(nBits)
|
|
bitsLeft -= int(nBits)
|
|
@@ -914,7 +1129,7 @@ func (d *Decoder) decompress4X8bitExactly(dst, src []byte) ([]byte, error) {
|
|
out := dst
|
|
out := dst
|
|
dstEvery := (dstSize + 3) / 4
|
|
dstEvery := (dstSize + 3) / 4
|
|
|
|
|
|
- const shift = 0
|
|
|
|
|
|
+ const shift = 56
|
|
const tlSize = 1 << 8
|
|
const tlSize = 1 << 8
|
|
const tlMask = tlSize - 1
|
|
const tlMask = tlSize - 1
|
|
single := d.dt.single[:tlSize]
|
|
single := d.dt.single[:tlSize]
|
|
@@ -938,37 +1153,41 @@ func (d *Decoder) decompress4X8bitExactly(dst, src []byte) ([]byte, error) {
|
|
br[stream].fillFast()
|
|
br[stream].fillFast()
|
|
br[stream2].fillFast()
|
|
br[stream2].fillFast()
|
|
|
|
|
|
- v := single[br[stream].peekByteFast()>>shift].entry
|
|
|
|
|
|
+ v := single[uint8(br[stream].value>>shift)].entry
|
|
|
|
+ v2 := single[uint8(br[stream2].value>>shift)].entry
|
|
|
|
+ br[stream].bitsRead += uint8(v)
|
|
|
|
+ br[stream].value <<= v & 63
|
|
|
|
+ br[stream2].bitsRead += uint8(v2)
|
|
|
|
+ br[stream2].value <<= v2 & 63
|
|
buf[off+bufoff*stream] = uint8(v >> 8)
|
|
buf[off+bufoff*stream] = uint8(v >> 8)
|
|
- br[stream].advance(uint8(v))
|
|
|
|
-
|
|
|
|
- v2 := single[br[stream2].peekByteFast()>>shift].entry
|
|
|
|
buf[off+bufoff*stream2] = uint8(v2 >> 8)
|
|
buf[off+bufoff*stream2] = uint8(v2 >> 8)
|
|
- br[stream2].advance(uint8(v2))
|
|
|
|
|
|
|
|
- v = single[br[stream].peekByteFast()>>shift].entry
|
|
|
|
|
|
+ v = single[uint8(br[stream].value>>shift)].entry
|
|
|
|
+ v2 = single[uint8(br[stream2].value>>shift)].entry
|
|
|
|
+ br[stream].bitsRead += uint8(v)
|
|
|
|
+ br[stream].value <<= v & 63
|
|
|
|
+ br[stream2].bitsRead += uint8(v2)
|
|
|
|
+ br[stream2].value <<= v2 & 63
|
|
buf[off+bufoff*stream+1] = uint8(v >> 8)
|
|
buf[off+bufoff*stream+1] = uint8(v >> 8)
|
|
- br[stream].advance(uint8(v))
|
|
|
|
-
|
|
|
|
- v2 = single[br[stream2].peekByteFast()>>shift].entry
|
|
|
|
buf[off+bufoff*stream2+1] = uint8(v2 >> 8)
|
|
buf[off+bufoff*stream2+1] = uint8(v2 >> 8)
|
|
- br[stream2].advance(uint8(v2))
|
|
|
|
|
|
|
|
- v = single[br[stream].peekByteFast()>>shift].entry
|
|
|
|
|
|
+ v = single[uint8(br[stream].value>>shift)].entry
|
|
|
|
+ v2 = single[uint8(br[stream2].value>>shift)].entry
|
|
|
|
+ br[stream].bitsRead += uint8(v)
|
|
|
|
+ br[stream].value <<= v & 63
|
|
|
|
+ br[stream2].bitsRead += uint8(v2)
|
|
|
|
+ br[stream2].value <<= v2 & 63
|
|
buf[off+bufoff*stream+2] = uint8(v >> 8)
|
|
buf[off+bufoff*stream+2] = uint8(v >> 8)
|
|
- br[stream].advance(uint8(v))
|
|
|
|
-
|
|
|
|
- v2 = single[br[stream2].peekByteFast()>>shift].entry
|
|
|
|
buf[off+bufoff*stream2+2] = uint8(v2 >> 8)
|
|
buf[off+bufoff*stream2+2] = uint8(v2 >> 8)
|
|
- br[stream2].advance(uint8(v2))
|
|
|
|
|
|
|
|
- v = single[br[stream].peekByteFast()>>shift].entry
|
|
|
|
|
|
+ v = single[uint8(br[stream].value>>shift)].entry
|
|
|
|
+ v2 = single[uint8(br[stream2].value>>shift)].entry
|
|
|
|
+ br[stream].bitsRead += uint8(v)
|
|
|
|
+ br[stream].value <<= v & 63
|
|
|
|
+ br[stream2].bitsRead += uint8(v2)
|
|
|
|
+ br[stream2].value <<= v2 & 63
|
|
buf[off+bufoff*stream+3] = uint8(v >> 8)
|
|
buf[off+bufoff*stream+3] = uint8(v >> 8)
|
|
- br[stream].advance(uint8(v))
|
|
|
|
-
|
|
|
|
- v2 = single[br[stream2].peekByteFast()>>shift].entry
|
|
|
|
buf[off+bufoff*stream2+3] = uint8(v2 >> 8)
|
|
buf[off+bufoff*stream2+3] = uint8(v2 >> 8)
|
|
- br[stream2].advance(uint8(v2))
|
|
|
|
}
|
|
}
|
|
|
|
|
|
{
|
|
{
|
|
@@ -977,37 +1196,41 @@ func (d *Decoder) decompress4X8bitExactly(dst, src []byte) ([]byte, error) {
|
|
br[stream].fillFast()
|
|
br[stream].fillFast()
|
|
br[stream2].fillFast()
|
|
br[stream2].fillFast()
|
|
|
|
|
|
- v := single[br[stream].peekByteFast()>>shift].entry
|
|
|
|
|
|
+ v := single[uint8(br[stream].value>>shift)].entry
|
|
|
|
+ v2 := single[uint8(br[stream2].value>>shift)].entry
|
|
|
|
+ br[stream].bitsRead += uint8(v)
|
|
|
|
+ br[stream].value <<= v & 63
|
|
|
|
+ br[stream2].bitsRead += uint8(v2)
|
|
|
|
+ br[stream2].value <<= v2 & 63
|
|
buf[off+bufoff*stream] = uint8(v >> 8)
|
|
buf[off+bufoff*stream] = uint8(v >> 8)
|
|
- br[stream].advance(uint8(v))
|
|
|
|
-
|
|
|
|
- v2 := single[br[stream2].peekByteFast()>>shift].entry
|
|
|
|
buf[off+bufoff*stream2] = uint8(v2 >> 8)
|
|
buf[off+bufoff*stream2] = uint8(v2 >> 8)
|
|
- br[stream2].advance(uint8(v2))
|
|
|
|
|
|
|
|
- v = single[br[stream].peekByteFast()>>shift].entry
|
|
|
|
|
|
+ v = single[uint8(br[stream].value>>shift)].entry
|
|
|
|
+ v2 = single[uint8(br[stream2].value>>shift)].entry
|
|
|
|
+ br[stream].bitsRead += uint8(v)
|
|
|
|
+ br[stream].value <<= v & 63
|
|
|
|
+ br[stream2].bitsRead += uint8(v2)
|
|
|
|
+ br[stream2].value <<= v2 & 63
|
|
buf[off+bufoff*stream+1] = uint8(v >> 8)
|
|
buf[off+bufoff*stream+1] = uint8(v >> 8)
|
|
- br[stream].advance(uint8(v))
|
|
|
|
-
|
|
|
|
- v2 = single[br[stream2].peekByteFast()>>shift].entry
|
|
|
|
buf[off+bufoff*stream2+1] = uint8(v2 >> 8)
|
|
buf[off+bufoff*stream2+1] = uint8(v2 >> 8)
|
|
- br[stream2].advance(uint8(v2))
|
|
|
|
|
|
|
|
- v = single[br[stream].peekByteFast()>>shift].entry
|
|
|
|
|
|
+ v = single[uint8(br[stream].value>>shift)].entry
|
|
|
|
+ v2 = single[uint8(br[stream2].value>>shift)].entry
|
|
|
|
+ br[stream].bitsRead += uint8(v)
|
|
|
|
+ br[stream].value <<= v & 63
|
|
|
|
+ br[stream2].bitsRead += uint8(v2)
|
|
|
|
+ br[stream2].value <<= v2 & 63
|
|
buf[off+bufoff*stream+2] = uint8(v >> 8)
|
|
buf[off+bufoff*stream+2] = uint8(v >> 8)
|
|
- br[stream].advance(uint8(v))
|
|
|
|
-
|
|
|
|
- v2 = single[br[stream2].peekByteFast()>>shift].entry
|
|
|
|
buf[off+bufoff*stream2+2] = uint8(v2 >> 8)
|
|
buf[off+bufoff*stream2+2] = uint8(v2 >> 8)
|
|
- br[stream2].advance(uint8(v2))
|
|
|
|
|
|
|
|
- v = single[br[stream].peekByteFast()>>shift].entry
|
|
|
|
|
|
+ v = single[uint8(br[stream].value>>shift)].entry
|
|
|
|
+ v2 = single[uint8(br[stream2].value>>shift)].entry
|
|
|
|
+ br[stream].bitsRead += uint8(v)
|
|
|
|
+ br[stream].value <<= v & 63
|
|
|
|
+ br[stream2].bitsRead += uint8(v2)
|
|
|
|
+ br[stream2].value <<= v2 & 63
|
|
buf[off+bufoff*stream+3] = uint8(v >> 8)
|
|
buf[off+bufoff*stream+3] = uint8(v >> 8)
|
|
- br[stream].advance(uint8(v))
|
|
|
|
-
|
|
|
|
- v2 = single[br[stream2].peekByteFast()>>shift].entry
|
|
|
|
buf[off+bufoff*stream2+3] = uint8(v2 >> 8)
|
|
buf[off+bufoff*stream2+3] = uint8(v2 >> 8)
|
|
- br[stream2].advance(uint8(v2))
|
|
|
|
}
|
|
}
|
|
|
|
|
|
off += 4
|
|
off += 4
|
|
@@ -1073,7 +1296,7 @@ func (d *Decoder) decompress4X8bitExactly(dst, src []byte) ([]byte, error) {
|
|
}
|
|
}
|
|
|
|
|
|
// Read value and increment offset.
|
|
// Read value and increment offset.
|
|
- v := single[br.peekByteFast()>>shift].entry
|
|
|
|
|
|
+ v := single[br.peekByteFast()].entry
|
|
nBits := uint8(v)
|
|
nBits := uint8(v)
|
|
br.advance(nBits)
|
|
br.advance(nBits)
|
|
bitsLeft -= int(nBits)
|
|
bitsLeft -= int(nBits)
|