MM-40676: Bump dependencies (#19525)
https://mattermost.atlassian.net/browse/MM-40676 ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
440790dad6
Коммит
57eafbc6ca
4
vendor/github.com/klauspost/compress/.goreleaser.yml
сгенерированный
поставляемый
4
vendor/github.com/klauspost/compress/.goreleaser.yml
сгенерированный
поставляемый
@@ -3,6 +3,7 @@
|
||||
before:
|
||||
hooks:
|
||||
- ./gen.sh
|
||||
- go install mvdan.cc/garble@latest
|
||||
|
||||
builds:
|
||||
-
|
||||
@@ -31,6 +32,7 @@ builds:
|
||||
- mips64le
|
||||
goarm:
|
||||
- 7
|
||||
gobinary: garble
|
||||
-
|
||||
id: "s2d"
|
||||
binary: s2d
|
||||
@@ -57,6 +59,7 @@ builds:
|
||||
- mips64le
|
||||
goarm:
|
||||
- 7
|
||||
gobinary: garble
|
||||
-
|
||||
id: "s2sx"
|
||||
binary: s2sx
|
||||
@@ -84,6 +87,7 @@ builds:
|
||||
- mips64le
|
||||
goarm:
|
||||
- 7
|
||||
gobinary: garble
|
||||
|
||||
archives:
|
||||
-
|
||||
|
||||
14
vendor/github.com/klauspost/compress/README.md
сгенерированный
поставляемый
14
vendor/github.com/klauspost/compress/README.md
сгенерированный
поставляемый
@@ -17,6 +17,13 @@ This package provides various compression algorithms.
|
||||
|
||||
# changelog
|
||||
|
||||
* Jan 11, 2022 (v1.14.1)
|
||||
* s2: Add stream index in [#462](https://github.com/klauspost/compress/pull/462)
|
||||
* flate: Speed and efficiency improvements in [#439](https://github.com/klauspost/compress/pull/439) [#461](https://github.com/klauspost/compress/pull/461) [#455](https://github.com/klauspost/compress/pull/455) [#452](https://github.com/klauspost/compress/pull/452) [#458](https://github.com/klauspost/compress/pull/458)
|
||||
* zstd: Performance improvement in [#420]( https://github.com/klauspost/compress/pull/420) [#456](https://github.com/klauspost/compress/pull/456) [#437](https://github.com/klauspost/compress/pull/437) [#467](https://github.com/klauspost/compress/pull/467) [#468](https://github.com/klauspost/compress/pull/468)
|
||||
* zstd: add arm64 xxhash assembly in [#464](https://github.com/klauspost/compress/pull/464)
|
||||
* Add garbled for binaries for s2 in [#445](https://github.com/klauspost/compress/pull/445)
|
||||
|
||||
* Aug 30, 2021 (v1.13.5)
|
||||
* gz/zlib/flate: Alias stdlib errors [#425](https://github.com/klauspost/compress/pull/425)
|
||||
* s2: Add block support to commandline tools [#413](https://github.com/klauspost/compress/pull/413)
|
||||
@@ -432,6 +439,13 @@ For more information see my blog post on [Fast Linear Time Compression](http://b
|
||||
|
||||
This is implemented on Go 1.7 as "Huffman Only" mode, though not exposed for gzip.
|
||||
|
||||
# Other packages
|
||||
|
||||
Here are other packages of good quality and pure Go (no cgo wrappers or autoconverted code):
|
||||
|
||||
* [github.com/pierrec/lz4](https://github.com/pierrec/lz4) - strong multithreaded LZ4 compression.
|
||||
* [github.com/cosnicolaou/pbzip2](https://github.com/cosnicolaou/pbzip2) - multithreaded bzip2 decompression.
|
||||
* [github.com/dsnet/compress](https://github.com/dsnet/compress) - brotli decompression, bzip2 writer.
|
||||
|
||||
# license
|
||||
|
||||
|
||||
167
vendor/github.com/klauspost/compress/flate/deflate.go
сгенерированный
поставляемый
167
vendor/github.com/klauspost/compress/flate/deflate.go
сгенерированный
поставляемый
@@ -6,6 +6,7 @@
|
||||
package flate
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
@@ -37,15 +38,17 @@ const (
|
||||
maxMatchLength = 258 // The longest match for the compressor
|
||||
minOffsetSize = 1 // The shortest offset that makes any sense
|
||||
|
||||
// The maximum number of tokens we put into a single flat block, just too
|
||||
// stop things from getting too large.
|
||||
maxFlateBlockTokens = 1 << 14
|
||||
// The maximum number of tokens we will encode at the time.
|
||||
// Smaller sizes usually creates less optimal blocks.
|
||||
// Bigger can make context switching slow.
|
||||
// We use this for levels 7-9, so we make it big.
|
||||
maxFlateBlockTokens = 1 << 15
|
||||
maxStoreBlockSize = 65535
|
||||
hashBits = 17 // After 17 performance degrades
|
||||
hashSize = 1 << hashBits
|
||||
hashMask = (1 << hashBits) - 1
|
||||
hashShift = (hashBits + minMatchLength - 1) / minMatchLength
|
||||
maxHashOffset = 1 << 24
|
||||
maxHashOffset = 1 << 28
|
||||
|
||||
skipNever = math.MaxInt32
|
||||
|
||||
@@ -70,9 +73,9 @@ var levels = []compressionLevel{
|
||||
{0, 0, 0, 0, 0, 6},
|
||||
// Levels 7-9 use increasingly more lazy matching
|
||||
// and increasingly stringent conditions for "good enough".
|
||||
{8, 8, 24, 16, skipNever, 7},
|
||||
{10, 16, 24, 64, skipNever, 8},
|
||||
{32, 258, 258, 4096, skipNever, 9},
|
||||
{8, 12, 16, 24, skipNever, 7},
|
||||
{16, 30, 40, 64, skipNever, 8},
|
||||
{32, 258, 258, 1024, skipNever, 9},
|
||||
}
|
||||
|
||||
// advancedState contains state for the advanced levels, with bigger hash tables, etc.
|
||||
@@ -93,8 +96,9 @@ type advancedState struct {
|
||||
hashOffset int
|
||||
|
||||
// input window: unprocessed data is window[index:windowEnd]
|
||||
index int
|
||||
hashMatch [maxMatchLength + minMatchLength]uint32
|
||||
index int
|
||||
estBitsPerByte int
|
||||
hashMatch [maxMatchLength + minMatchLength]uint32
|
||||
|
||||
hash uint32
|
||||
ii uint16 // position of last match, intended to overflow to reset.
|
||||
@@ -103,6 +107,7 @@ type advancedState struct {
|
||||
type compressor struct {
|
||||
compressionLevel
|
||||
|
||||
h *huffmanEncoder
|
||||
w *huffmanBitWriter
|
||||
|
||||
// compression algorithm
|
||||
@@ -170,7 +175,8 @@ func (d *compressor) writeBlock(tok *tokens, index int, eof bool) error {
|
||||
window = d.window[d.blockStart:index]
|
||||
}
|
||||
d.blockStart = index
|
||||
d.w.writeBlock(tok, eof, window)
|
||||
//d.w.writeBlock(tok, eof, window)
|
||||
d.w.writeBlockDynamic(tok, eof, window, d.sync)
|
||||
return d.w.err
|
||||
}
|
||||
return nil
|
||||
@@ -263,7 +269,7 @@ func (d *compressor) fillWindow(b []byte) {
|
||||
// Try to find a match starting at index whose length is greater than prevSize.
|
||||
// We only look at chainCount possibilities before giving up.
|
||||
// pos = s.index, prevHead = s.chainHead-s.hashOffset, prevLength=minMatchLength-1, lookahead
|
||||
func (d *compressor) findMatch(pos int, prevHead int, prevLength int, lookahead int) (length, offset int, ok bool) {
|
||||
func (d *compressor) findMatch(pos int, prevHead int, lookahead int) (length, offset int, ok bool) {
|
||||
minMatchLook := maxMatchLength
|
||||
if lookahead < minMatchLook {
|
||||
minMatchLook = lookahead
|
||||
@@ -279,36 +285,75 @@ func (d *compressor) findMatch(pos int, prevHead int, prevLength int, lookahead
|
||||
|
||||
// If we've got a match that's good enough, only look in 1/4 the chain.
|
||||
tries := d.chain
|
||||
length = prevLength
|
||||
if length >= d.good {
|
||||
tries >>= 2
|
||||
}
|
||||
length = minMatchLength - 1
|
||||
|
||||
wEnd := win[pos+length]
|
||||
wPos := win[pos:]
|
||||
minIndex := pos - windowSize
|
||||
if minIndex < 0 {
|
||||
minIndex = 0
|
||||
}
|
||||
offset = 0
|
||||
|
||||
cGain := 0
|
||||
if d.chain < 100 {
|
||||
for i := prevHead; tries > 0; tries-- {
|
||||
if wEnd == win[i+length] {
|
||||
n := matchLen(win[i:i+minMatchLook], wPos)
|
||||
if n > length {
|
||||
length = n
|
||||
offset = pos - i
|
||||
ok = true
|
||||
if n >= nice {
|
||||
// The match is good enough that we don't try to find a better one.
|
||||
break
|
||||
}
|
||||
wEnd = win[pos+n]
|
||||
}
|
||||
}
|
||||
if i <= minIndex {
|
||||
// hashPrev[i & windowMask] has already been overwritten, so stop now.
|
||||
break
|
||||
}
|
||||
i = int(d.state.hashPrev[i&windowMask]) - d.state.hashOffset
|
||||
if i < minIndex {
|
||||
break
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Some like it higher (CSV), some like it lower (JSON)
|
||||
const baseCost = 6
|
||||
// Base is 4 bytes at with an additional cost.
|
||||
// Matches must be better than this.
|
||||
for i := prevHead; tries > 0; tries-- {
|
||||
if wEnd == win[i+length] {
|
||||
n := matchLen(win[i:i+minMatchLook], wPos)
|
||||
if n > length {
|
||||
// Calculate gain. Estimate
|
||||
newGain := d.h.bitLengthRaw(wPos[:n]) - int(offsetExtraBits[offsetCode(uint32(pos-i))]) - baseCost - int(lengthExtraBits[lengthCodes[(n-3)&255]])
|
||||
|
||||
if n > length && (n > minMatchLength || pos-i <= 4096) {
|
||||
length = n
|
||||
offset = pos - i
|
||||
ok = true
|
||||
if n >= nice {
|
||||
// The match is good enough that we don't try to find a better one.
|
||||
break
|
||||
//fmt.Println(n, "gain:", newGain, "prev:", cGain, "raw:", d.h.bitLengthRaw(wPos[:n]))
|
||||
if newGain > cGain {
|
||||
length = n
|
||||
offset = pos - i
|
||||
cGain = newGain
|
||||
ok = true
|
||||
if n >= nice {
|
||||
// The match is good enough that we don't try to find a better one.
|
||||
break
|
||||
}
|
||||
wEnd = win[pos+n]
|
||||
}
|
||||
wEnd = win[pos+n]
|
||||
}
|
||||
}
|
||||
if i == minIndex {
|
||||
if i <= minIndex {
|
||||
// hashPrev[i & windowMask] has already been overwritten, so stop now.
|
||||
break
|
||||
}
|
||||
i = int(d.state.hashPrev[i&windowMask]) - d.state.hashOffset
|
||||
if i < minIndex || i < 0 {
|
||||
if i < minIndex {
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -327,8 +372,7 @@ func (d *compressor) writeStoredBlock(buf []byte) error {
|
||||
// of the supplied slice.
|
||||
// The caller must ensure that len(b) >= 4.
|
||||
func hash4(b []byte) uint32 {
|
||||
b = b[:4]
|
||||
return hash4u(uint32(b[3])|uint32(b[2])<<8|uint32(b[1])<<16|uint32(b[0])<<24, hashBits)
|
||||
return hash4u(binary.LittleEndian.Uint32(b), hashBits)
|
||||
}
|
||||
|
||||
// bulkHash4 will compute hashes using the same
|
||||
@@ -337,11 +381,12 @@ func bulkHash4(b []byte, dst []uint32) {
|
||||
if len(b) < 4 {
|
||||
return
|
||||
}
|
||||
hb := uint32(b[3]) | uint32(b[2])<<8 | uint32(b[1])<<16 | uint32(b[0])<<24
|
||||
hb := binary.LittleEndian.Uint32(b)
|
||||
|
||||
dst[0] = hash4u(hb, hashBits)
|
||||
end := len(b) - 4 + 1
|
||||
for i := 1; i < end; i++ {
|
||||
hb = (hb << 8) | uint32(b[i+3])
|
||||
hb = (hb >> 8) | uint32(b[i+3])<<24
|
||||
dst[i] = hash4u(hb, hashBits)
|
||||
}
|
||||
}
|
||||
@@ -374,10 +419,21 @@ func (d *compressor) deflateLazy() {
|
||||
if d.windowEnd-s.index < minMatchLength+maxMatchLength && !d.sync {
|
||||
return
|
||||
}
|
||||
if d.windowEnd != s.index && d.chain > 100 {
|
||||
// Get literal huffman coder.
|
||||
if d.h == nil {
|
||||
d.h = newHuffmanEncoder(maxFlateBlockTokens)
|
||||
}
|
||||
var tmp [256]uint16
|
||||
for _, v := range d.window[s.index:d.windowEnd] {
|
||||
tmp[v]++
|
||||
}
|
||||
d.h.generate(tmp[:], 15)
|
||||
}
|
||||
|
||||
s.maxInsertIndex = d.windowEnd - (minMatchLength - 1)
|
||||
if s.index < s.maxInsertIndex {
|
||||
s.hash = hash4(d.window[s.index : s.index+minMatchLength])
|
||||
s.hash = hash4(d.window[s.index:])
|
||||
}
|
||||
|
||||
for {
|
||||
@@ -410,7 +466,7 @@ func (d *compressor) deflateLazy() {
|
||||
}
|
||||
if s.index < s.maxInsertIndex {
|
||||
// Update the hash
|
||||
s.hash = hash4(d.window[s.index : s.index+minMatchLength])
|
||||
s.hash = hash4(d.window[s.index:])
|
||||
ch := s.hashHead[s.hash&hashMask]
|
||||
s.chainHead = int(ch)
|
||||
s.hashPrev[s.index&windowMask] = ch
|
||||
@@ -426,12 +482,37 @@ func (d *compressor) deflateLazy() {
|
||||
}
|
||||
|
||||
if s.chainHead-s.hashOffset >= minIndex && lookahead > prevLength && prevLength < d.lazy {
|
||||
if newLength, newOffset, ok := d.findMatch(s.index, s.chainHead-s.hashOffset, minMatchLength-1, lookahead); ok {
|
||||
if newLength, newOffset, ok := d.findMatch(s.index, s.chainHead-s.hashOffset, lookahead); ok {
|
||||
s.length = newLength
|
||||
s.offset = newOffset
|
||||
}
|
||||
}
|
||||
|
||||
if prevLength >= minMatchLength && s.length <= prevLength {
|
||||
// Check for better match at end...
|
||||
//
|
||||
// checkOff must be >=2 since we otherwise risk checking s.index
|
||||
// Offset of 2 seems to yield best results.
|
||||
const checkOff = 2
|
||||
prevIndex := s.index - 1
|
||||
if prevIndex+prevLength+checkOff < s.maxInsertIndex {
|
||||
end := lookahead
|
||||
if lookahead > maxMatchLength {
|
||||
end = maxMatchLength
|
||||
}
|
||||
end += prevIndex
|
||||
idx := prevIndex + prevLength - (4 - checkOff)
|
||||
h := hash4(d.window[idx:])
|
||||
ch2 := int(s.hashHead[h&hashMask]) - s.hashOffset - prevLength + (4 - checkOff)
|
||||
if ch2 > minIndex {
|
||||
length := matchLen(d.window[prevIndex:end], d.window[ch2:])
|
||||
// It seems like a pure length metric is best.
|
||||
if length > prevLength {
|
||||
prevLength = length
|
||||
prevOffset = prevIndex - ch2
|
||||
}
|
||||
}
|
||||
}
|
||||
// There was a match at the previous step, and the current match is
|
||||
// not better. Output the previous match.
|
||||
d.tokens.AddMatch(uint32(prevLength-3), uint32(prevOffset-minOffsetSize))
|
||||
@@ -479,6 +560,7 @@ func (d *compressor) deflateLazy() {
|
||||
}
|
||||
d.tokens.Reset()
|
||||
}
|
||||
s.ii = 0
|
||||
} else {
|
||||
// Reset, if we got a match this run.
|
||||
if s.length >= minMatchLength {
|
||||
@@ -498,13 +580,12 @@ func (d *compressor) deflateLazy() {
|
||||
|
||||
// If we have a long run of no matches, skip additional bytes
|
||||
// Resets when s.ii overflows after 64KB.
|
||||
if s.ii > 31 {
|
||||
n := int(s.ii >> 5)
|
||||
if n := int(s.ii) - d.chain; n > 0 {
|
||||
n = 1 + int(n>>6)
|
||||
for j := 0; j < n; j++ {
|
||||
if s.index >= d.windowEnd-1 {
|
||||
break
|
||||
}
|
||||
|
||||
d.tokens.AddLiteral(d.window[s.index-1])
|
||||
if d.tokens.n == maxFlateBlockTokens {
|
||||
if d.err = d.writeBlock(&d.tokens, s.index, false); d.err != nil {
|
||||
@@ -512,6 +593,14 @@ func (d *compressor) deflateLazy() {
|
||||
}
|
||||
d.tokens.Reset()
|
||||
}
|
||||
// Index...
|
||||
if s.index < s.maxInsertIndex {
|
||||
h := hash4(d.window[s.index:])
|
||||
ch := s.hashHead[h]
|
||||
s.chainHead = int(ch)
|
||||
s.hashPrev[s.index&windowMask] = ch
|
||||
s.hashHead[h] = uint32(s.index + s.hashOffset)
|
||||
}
|
||||
s.index++
|
||||
}
|
||||
// Flush last byte
|
||||
@@ -611,7 +700,9 @@ func (d *compressor) write(b []byte) (n int, err error) {
|
||||
}
|
||||
n = len(b)
|
||||
for len(b) > 0 {
|
||||
d.step(d)
|
||||
if d.windowEnd == len(d.window) || d.sync {
|
||||
d.step(d)
|
||||
}
|
||||
b = b[d.fill(d, b):]
|
||||
if d.err != nil {
|
||||
return 0, d.err
|
||||
@@ -652,13 +743,13 @@ func (d *compressor) init(w io.Writer, level int) (err error) {
|
||||
level = 5
|
||||
fallthrough
|
||||
case level >= 1 && level <= 6:
|
||||
d.w.logNewTablePenalty = 8
|
||||
d.w.logNewTablePenalty = 7
|
||||
d.fast = newFastEnc(level)
|
||||
d.window = make([]byte, maxStoreBlockSize)
|
||||
d.fill = (*compressor).fillBlock
|
||||
d.step = (*compressor).storeFast
|
||||
case 7 <= level && level <= 9:
|
||||
d.w.logNewTablePenalty = 10
|
||||
d.w.logNewTablePenalty = 8
|
||||
d.state = &advancedState{}
|
||||
d.compressionLevel = levels[level]
|
||||
d.initDeflate()
|
||||
|
||||
2
vendor/github.com/klauspost/compress/flate/fast_encoder.go
сгенерированный
поставляемый
2
vendor/github.com/klauspost/compress/flate/fast_encoder.go
сгенерированный
поставляемый
@@ -213,11 +213,9 @@ func (e *fastGen) Reset() {
|
||||
// matchLen returns the maximum length.
|
||||
// 'a' must be the shortest of the two.
|
||||
func matchLen(a, b []byte) int {
|
||||
b = b[:len(a)]
|
||||
var checked int
|
||||
|
||||
for len(a) >= 8 {
|
||||
b = b[:len(a)]
|
||||
if diff := binary.LittleEndian.Uint64(a) ^ binary.LittleEndian.Uint64(b); diff != 0 {
|
||||
return checked + (bits.TrailingZeros64(diff) >> 3)
|
||||
}
|
||||
|
||||
199
vendor/github.com/klauspost/compress/flate/huffman_bit_writer.go
сгенерированный
поставляемый
199
vendor/github.com/klauspost/compress/flate/huffman_bit_writer.go
сгенерированный
поставляемый
@@ -52,18 +52,18 @@ var lengthBase = [32]uint8{
|
||||
}
|
||||
|
||||
// offset code word extra bits.
|
||||
var offsetExtraBits = [64]int8{
|
||||
var offsetExtraBits = [32]int8{
|
||||
0, 0, 0, 0, 1, 1, 2, 2, 3, 3,
|
||||
4, 4, 5, 5, 6, 6, 7, 7, 8, 8,
|
||||
9, 9, 10, 10, 11, 11, 12, 12, 13, 13,
|
||||
/* extended window */
|
||||
14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20,
|
||||
14, 14,
|
||||
}
|
||||
|
||||
var offsetCombined = [32]uint32{}
|
||||
|
||||
func init() {
|
||||
var offsetBase = [64]uint32{
|
||||
var offsetBase = [32]uint32{
|
||||
/* normal deflate */
|
||||
0x000000, 0x000001, 0x000002, 0x000003, 0x000004,
|
||||
0x000006, 0x000008, 0x00000c, 0x000010, 0x000018,
|
||||
@@ -73,9 +73,7 @@ func init() {
|
||||
0x001800, 0x002000, 0x003000, 0x004000, 0x006000,
|
||||
|
||||
/* extended window */
|
||||
0x008000, 0x00c000, 0x010000, 0x018000, 0x020000,
|
||||
0x030000, 0x040000, 0x060000, 0x080000, 0x0c0000,
|
||||
0x100000, 0x180000, 0x200000, 0x300000,
|
||||
0x008000, 0x00c000,
|
||||
}
|
||||
|
||||
for i := range offsetCombined[:] {
|
||||
@@ -155,37 +153,33 @@ func (w *huffmanBitWriter) reset(writer io.Writer) {
|
||||
w.lastHuffMan = false
|
||||
}
|
||||
|
||||
func (w *huffmanBitWriter) canReuse(t *tokens) (offsets, lits bool) {
|
||||
offsets, lits = true, true
|
||||
func (w *huffmanBitWriter) canReuse(t *tokens) (ok bool) {
|
||||
a := t.offHist[:offsetCodeCount]
|
||||
b := w.offsetFreq[:len(a)]
|
||||
for i := range a {
|
||||
if b[i] == 0 && a[i] != 0 {
|
||||
offsets = false
|
||||
break
|
||||
b := w.offsetEncoding.codes
|
||||
b = b[:len(a)]
|
||||
for i, v := range a {
|
||||
if v != 0 && b[i].len == 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
a = t.extraHist[:literalCount-256]
|
||||
b = w.literalFreq[256:literalCount]
|
||||
b = w.literalEncoding.codes[256:literalCount]
|
||||
b = b[:len(a)]
|
||||
for i := range a {
|
||||
if b[i] == 0 && a[i] != 0 {
|
||||
lits = false
|
||||
break
|
||||
for i, v := range a {
|
||||
if v != 0 && b[i].len == 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
if lits {
|
||||
a = t.litHist[:]
|
||||
b = w.literalFreq[:len(a)]
|
||||
for i := range a {
|
||||
if b[i] == 0 && a[i] != 0 {
|
||||
lits = false
|
||||
break
|
||||
}
|
||||
|
||||
a = t.litHist[:256]
|
||||
b = w.literalEncoding.codes[:len(a)]
|
||||
for i, v := range a {
|
||||
if v != 0 && b[i].len == 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return
|
||||
return true
|
||||
}
|
||||
|
||||
func (w *huffmanBitWriter) flush() {
|
||||
@@ -222,7 +216,7 @@ func (w *huffmanBitWriter) write(b []byte) {
|
||||
}
|
||||
|
||||
func (w *huffmanBitWriter) writeBits(b int32, nb uint16) {
|
||||
w.bits |= uint64(b) << w.nbits
|
||||
w.bits |= uint64(b) << (w.nbits & 63)
|
||||
w.nbits += nb
|
||||
if w.nbits >= 48 {
|
||||
w.writeOutBits()
|
||||
@@ -423,7 +417,7 @@ func (w *huffmanBitWriter) storedSize(in []byte) (int, bool) {
|
||||
|
||||
func (w *huffmanBitWriter) writeCode(c hcode) {
|
||||
// The function does not get inlined if we "& 63" the shift.
|
||||
w.bits |= uint64(c.code) << w.nbits
|
||||
w.bits |= uint64(c.code) << (w.nbits & 63)
|
||||
w.nbits += c.len
|
||||
if w.nbits >= 48 {
|
||||
w.writeOutBits()
|
||||
@@ -566,7 +560,7 @@ func (w *huffmanBitWriter) writeBlock(tokens *tokens, eof bool, input []byte) {
|
||||
w.lastHeader = 0
|
||||
}
|
||||
numLiterals, numOffsets := w.indexTokens(tokens, false)
|
||||
w.generate(tokens)
|
||||
w.generate()
|
||||
var extraBits int
|
||||
storedSize, storable := w.storedSize(input)
|
||||
if storable {
|
||||
@@ -595,7 +589,7 @@ func (w *huffmanBitWriter) writeBlock(tokens *tokens, eof bool, input []byte) {
|
||||
}
|
||||
|
||||
// Stored bytes?
|
||||
if storable && storedSize < size {
|
||||
if storable && storedSize <= size {
|
||||
w.writeStoredHeader(len(input), eof)
|
||||
w.writeBytes(input)
|
||||
return
|
||||
@@ -634,22 +628,39 @@ func (w *huffmanBitWriter) writeBlockDynamic(tokens *tokens, eof bool, input []b
|
||||
w.lastHeader = 0
|
||||
w.lastHuffMan = false
|
||||
}
|
||||
if !sync {
|
||||
tokens.Fill()
|
||||
|
||||
// fillReuse enables filling of empty values.
|
||||
// This will make encodings always reusable without testing.
|
||||
// However, this does not appear to benefit on most cases.
|
||||
const fillReuse = false
|
||||
|
||||
// Check if we can reuse...
|
||||
if !fillReuse && w.lastHeader > 0 && !w.canReuse(tokens) {
|
||||
w.writeCode(w.literalEncoding.codes[endBlockMarker])
|
||||
w.lastHeader = 0
|
||||
}
|
||||
|
||||
numLiterals, numOffsets := w.indexTokens(tokens, !sync)
|
||||
extraBits := 0
|
||||
ssize, storable := w.storedSize(input)
|
||||
|
||||
const usePrefs = true
|
||||
if storable || w.lastHeader > 0 {
|
||||
extraBits = w.extraBitSize()
|
||||
}
|
||||
|
||||
var size int
|
||||
|
||||
// Check if we should reuse.
|
||||
if w.lastHeader > 0 {
|
||||
// Estimate size for using a new table.
|
||||
// Use the previous header size as the best estimate.
|
||||
newSize := w.lastHeader + tokens.EstimatedBits()
|
||||
newSize += newSize >> w.logNewTablePenalty
|
||||
newSize += int(w.literalEncoding.codes[endBlockMarker].len) + newSize>>w.logNewTablePenalty
|
||||
|
||||
// The estimated size is calculated as an optimal table.
|
||||
// We add a penalty to make it more realistic and re-use a bit more.
|
||||
reuseSize := w.dynamicReuseSize(w.literalEncoding, w.offsetEncoding) + w.extraBitSize()
|
||||
reuseSize := w.dynamicReuseSize(w.literalEncoding, w.offsetEncoding) + extraBits
|
||||
|
||||
// Check if a new table is better.
|
||||
if newSize < reuseSize {
|
||||
@@ -660,35 +671,79 @@ func (w *huffmanBitWriter) writeBlockDynamic(tokens *tokens, eof bool, input []b
|
||||
} else {
|
||||
size = reuseSize
|
||||
}
|
||||
|
||||
if preSize := w.fixedSize(extraBits) + 7; usePrefs && preSize < size {
|
||||
// Check if we get a reasonable size decrease.
|
||||
if storable && ssize <= size {
|
||||
w.writeStoredHeader(len(input), eof)
|
||||
w.writeBytes(input)
|
||||
return
|
||||
}
|
||||
w.writeFixedHeader(eof)
|
||||
if !sync {
|
||||
tokens.AddEOB()
|
||||
}
|
||||
w.writeTokens(tokens.Slice(), fixedLiteralEncoding.codes, fixedOffsetEncoding.codes)
|
||||
return
|
||||
}
|
||||
// Check if we get a reasonable size decrease.
|
||||
if ssize, storable := w.storedSize(input); storable && ssize < (size+size>>4) {
|
||||
if storable && ssize <= size {
|
||||
w.writeStoredHeader(len(input), eof)
|
||||
w.writeBytes(input)
|
||||
w.lastHeader = 0
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// We want a new block/table
|
||||
if w.lastHeader == 0 {
|
||||
w.generate(tokens)
|
||||
if fillReuse && !sync {
|
||||
w.fillTokens()
|
||||
numLiterals, numOffsets = maxNumLit, maxNumDist
|
||||
} else {
|
||||
w.literalFreq[endBlockMarker] = 1
|
||||
}
|
||||
|
||||
w.generate()
|
||||
// Generate codegen and codegenFrequencies, which indicates how to encode
|
||||
// the literalEncoding and the offsetEncoding.
|
||||
w.generateCodegen(numLiterals, numOffsets, w.literalEncoding, w.offsetEncoding)
|
||||
w.codegenEncoding.generate(w.codegenFreq[:], 7)
|
||||
|
||||
var numCodegens int
|
||||
size, numCodegens = w.dynamicSize(w.literalEncoding, w.offsetEncoding, w.extraBitSize())
|
||||
// Store bytes, if we don't get a reasonable improvement.
|
||||
if ssize, storable := w.storedSize(input); storable && ssize < (size+size>>4) {
|
||||
if fillReuse && !sync {
|
||||
// Reindex for accurate size...
|
||||
w.indexTokens(tokens, true)
|
||||
}
|
||||
size, numCodegens = w.dynamicSize(w.literalEncoding, w.offsetEncoding, extraBits)
|
||||
|
||||
// Store predefined, if we don't get a reasonable improvement.
|
||||
if preSize := w.fixedSize(extraBits); usePrefs && preSize <= size {
|
||||
// Store bytes, if we don't get an improvement.
|
||||
if storable && ssize <= preSize {
|
||||
w.writeStoredHeader(len(input), eof)
|
||||
w.writeBytes(input)
|
||||
return
|
||||
}
|
||||
w.writeFixedHeader(eof)
|
||||
if !sync {
|
||||
tokens.AddEOB()
|
||||
}
|
||||
w.writeTokens(tokens.Slice(), fixedLiteralEncoding.codes, fixedOffsetEncoding.codes)
|
||||
return
|
||||
}
|
||||
|
||||
if storable && ssize <= size {
|
||||
// Store bytes, if we don't get an improvement.
|
||||
w.writeStoredHeader(len(input), eof)
|
||||
w.writeBytes(input)
|
||||
w.lastHeader = 0
|
||||
return
|
||||
}
|
||||
|
||||
// Write Huffman table.
|
||||
w.writeDynamicHeader(numLiterals, numOffsets, numCodegens, eof)
|
||||
w.lastHeader, _ = w.headerSize()
|
||||
if !sync {
|
||||
w.lastHeader, _ = w.headerSize()
|
||||
}
|
||||
w.lastHuffMan = false
|
||||
}
|
||||
|
||||
@@ -699,6 +754,19 @@ func (w *huffmanBitWriter) writeBlockDynamic(tokens *tokens, eof bool, input []b
|
||||
w.writeTokens(tokens.Slice(), w.literalEncoding.codes, w.offsetEncoding.codes)
|
||||
}
|
||||
|
||||
func (w *huffmanBitWriter) fillTokens() {
|
||||
for i, v := range w.literalFreq[:literalCount] {
|
||||
if v == 0 {
|
||||
w.literalFreq[i] = 1
|
||||
}
|
||||
}
|
||||
for i, v := range w.offsetFreq[:offsetCodeCount] {
|
||||
if v == 0 {
|
||||
w.offsetFreq[i] = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// indexTokens indexes a slice of tokens, and updates
|
||||
// literalFreq and offsetFreq, and generates literalEncoding
|
||||
// and offsetEncoding.
|
||||
@@ -733,7 +801,7 @@ func (w *huffmanBitWriter) indexTokens(t *tokens, filled bool) (numLiterals, num
|
||||
return
|
||||
}
|
||||
|
||||
func (w *huffmanBitWriter) generate(t *tokens) {
|
||||
func (w *huffmanBitWriter) generate() {
|
||||
w.literalEncoding.generate(w.literalFreq[:literalCount], 15)
|
||||
w.offsetEncoding.generate(w.offsetFreq[:offsetCodeCount], 15)
|
||||
}
|
||||
@@ -768,7 +836,7 @@ func (w *huffmanBitWriter) writeTokens(tokens []token, leCodes, oeCodes []hcode)
|
||||
if t < matchType {
|
||||
//w.writeCode(lits[t.literal()])
|
||||
c := lits[t.literal()]
|
||||
bits |= uint64(c.code) << nbits
|
||||
bits |= uint64(c.code) << (nbits & 63)
|
||||
nbits += c.len
|
||||
if nbits >= 48 {
|
||||
binary.LittleEndian.PutUint64(w.bytes[nbytes:], bits)
|
||||
@@ -796,7 +864,7 @@ func (w *huffmanBitWriter) writeTokens(tokens []token, leCodes, oeCodes []hcode)
|
||||
} else {
|
||||
// inlined
|
||||
c := lengths[lengthCode&31]
|
||||
bits |= uint64(c.code) << nbits
|
||||
bits |= uint64(c.code) << (nbits & 63)
|
||||
nbits += c.len
|
||||
if nbits >= 48 {
|
||||
binary.LittleEndian.PutUint64(w.bytes[nbytes:], bits)
|
||||
@@ -819,7 +887,7 @@ func (w *huffmanBitWriter) writeTokens(tokens []token, leCodes, oeCodes []hcode)
|
||||
if extraLengthBits > 0 {
|
||||
//w.writeBits(extraLength, extraLengthBits)
|
||||
extraLength := int32(length - lengthBase[lengthCode&31])
|
||||
bits |= uint64(extraLength) << nbits
|
||||
bits |= uint64(extraLength) << (nbits & 63)
|
||||
nbits += extraLengthBits
|
||||
if nbits >= 48 {
|
||||
binary.LittleEndian.PutUint64(w.bytes[nbytes:], bits)
|
||||
@@ -846,7 +914,7 @@ func (w *huffmanBitWriter) writeTokens(tokens []token, leCodes, oeCodes []hcode)
|
||||
} else {
|
||||
// inlined
|
||||
c := offs[offsetCode]
|
||||
bits |= uint64(c.code) << nbits
|
||||
bits |= uint64(c.code) << (nbits & 63)
|
||||
nbits += c.len
|
||||
if nbits >= 48 {
|
||||
binary.LittleEndian.PutUint64(w.bytes[nbytes:], bits)
|
||||
@@ -867,7 +935,7 @@ func (w *huffmanBitWriter) writeTokens(tokens []token, leCodes, oeCodes []hcode)
|
||||
offsetComb := offsetCombined[offsetCode]
|
||||
if offsetComb > 1<<16 {
|
||||
//w.writeBits(extraOffset, extraOffsetBits)
|
||||
bits |= uint64(offset&matchOffsetOnlyMask-(offsetComb&0xffff)) << nbits
|
||||
bits |= uint64(offset-(offsetComb&0xffff)) << (nbits & 63)
|
||||
nbits += uint16(offsetComb >> 16)
|
||||
if nbits >= 48 {
|
||||
binary.LittleEndian.PutUint64(w.bytes[nbytes:], bits)
|
||||
@@ -996,10 +1064,41 @@ func (w *huffmanBitWriter) writeBlockHuff(eof bool, input []byte, sync bool) {
|
||||
encoding := w.literalEncoding.codes[:256]
|
||||
// Go 1.16 LOVES having these on stack. At least 1.5x the speed.
|
||||
bits, nbits, nbytes := w.bits, w.nbits, w.nbytes
|
||||
|
||||
// Unroll, write 3 codes/loop.
|
||||
// Fastest number of unrolls.
|
||||
for len(input) > 3 {
|
||||
// We must have at least 48 bits free.
|
||||
if nbits >= 8 {
|
||||
n := nbits >> 3
|
||||
binary.LittleEndian.PutUint64(w.bytes[nbytes:], bits)
|
||||
bits >>= (n * 8) & 63
|
||||
nbits -= n * 8
|
||||
nbytes += uint8(n)
|
||||
}
|
||||
if nbytes >= bufferFlushSize {
|
||||
if w.err != nil {
|
||||
nbytes = 0
|
||||
return
|
||||
}
|
||||
_, w.err = w.writer.Write(w.bytes[:nbytes])
|
||||
nbytes = 0
|
||||
}
|
||||
a, b := encoding[input[0]], encoding[input[1]]
|
||||
bits |= uint64(a.code) << (nbits & 63)
|
||||
bits |= uint64(b.code) << ((nbits + a.len) & 63)
|
||||
c := encoding[input[2]]
|
||||
nbits += b.len + a.len
|
||||
bits |= uint64(c.code) << (nbits & 63)
|
||||
nbits += c.len
|
||||
input = input[3:]
|
||||
}
|
||||
|
||||
// Remaining...
|
||||
for _, t := range input {
|
||||
// Bitwriting inlined, ~30% speedup
|
||||
c := encoding[t]
|
||||
bits |= uint64(c.code) << nbits
|
||||
bits |= uint64(c.code) << (nbits & 63)
|
||||
nbits += c.len
|
||||
if debugDeflate {
|
||||
count += int(c.len)
|
||||
|
||||
4
vendor/github.com/klauspost/compress/flate/huffman_code.go
сгенерированный
поставляемый
4
vendor/github.com/klauspost/compress/flate/huffman_code.go
сгенерированный
поставляемый
@@ -129,9 +129,7 @@ func (h *huffmanEncoder) bitLength(freq []uint16) int {
|
||||
func (h *huffmanEncoder) bitLengthRaw(b []byte) int {
|
||||
var total int
|
||||
for _, f := range b {
|
||||
if f != 0 {
|
||||
total += int(h.codes[f].len)
|
||||
}
|
||||
total += int(h.codes[f].len)
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
||||
9
vendor/github.com/klauspost/compress/flate/inflate.go
сгенерированный
поставляемый
9
vendor/github.com/klauspost/compress/flate/inflate.go
сгенерированный
поставляемый
@@ -328,11 +328,17 @@ func (f *decompressor) nextBlock() {
|
||||
switch typ {
|
||||
case 0:
|
||||
f.dataBlock()
|
||||
if debugDecode {
|
||||
fmt.Println("stored block")
|
||||
}
|
||||
case 1:
|
||||
// compressed, fixed Huffman tables
|
||||
f.hl = &fixedHuffmanDecoder
|
||||
f.hd = nil
|
||||
f.huffmanBlockDecoder()()
|
||||
if debugDecode {
|
||||
fmt.Println("predefinied huffman block")
|
||||
}
|
||||
case 2:
|
||||
// compressed, dynamic Huffman tables
|
||||
if f.err = f.readHuffman(); f.err != nil {
|
||||
@@ -341,6 +347,9 @@ func (f *decompressor) nextBlock() {
|
||||
f.hl = &f.h1
|
||||
f.hd = &f.h2
|
||||
f.huffmanBlockDecoder()()
|
||||
if debugDecode {
|
||||
fmt.Println("dynamic huffman block")
|
||||
}
|
||||
default:
|
||||
// 3 is reserved.
|
||||
if debugDecode {
|
||||
|
||||
19
vendor/github.com/klauspost/compress/flate/token.go
сгенерированный
поставляемый
19
vendor/github.com/klauspost/compress/flate/token.go
сгенерированный
поставляемый
@@ -129,11 +129,11 @@ var offsetCodes14 = [256]uint32{
|
||||
type token uint32
|
||||
|
||||
type tokens struct {
|
||||
nLits int
|
||||
extraHist [32]uint16 // codes 256->maxnumlit
|
||||
offHist [32]uint16 // offset codes
|
||||
litHist [256]uint16 // codes 0->255
|
||||
n uint16 // Must be able to contain maxStoreBlockSize
|
||||
nFilled int
|
||||
n uint16 // Must be able to contain maxStoreBlockSize
|
||||
tokens [maxStoreBlockSize + 1]token
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ func (t *tokens) Reset() {
|
||||
return
|
||||
}
|
||||
t.n = 0
|
||||
t.nLits = 0
|
||||
t.nFilled = 0
|
||||
for i := range t.litHist[:] {
|
||||
t.litHist[i] = 0
|
||||
}
|
||||
@@ -161,12 +161,12 @@ func (t *tokens) Fill() {
|
||||
for i, v := range t.litHist[:] {
|
||||
if v == 0 {
|
||||
t.litHist[i] = 1
|
||||
t.nLits++
|
||||
t.nFilled++
|
||||
}
|
||||
}
|
||||
for i, v := range t.extraHist[:literalCount-256] {
|
||||
if v == 0 {
|
||||
t.nLits++
|
||||
t.nFilled++
|
||||
t.extraHist[i] = 1
|
||||
}
|
||||
}
|
||||
@@ -202,14 +202,12 @@ func emitLiteral(dst *tokens, lit []byte) {
|
||||
dst.litHist[v]++
|
||||
}
|
||||
dst.n += uint16(len(lit))
|
||||
dst.nLits += len(lit)
|
||||
}
|
||||
|
||||
func (t *tokens) AddLiteral(lit byte) {
|
||||
t.tokens[t.n] = token(lit)
|
||||
t.litHist[lit]++
|
||||
t.n++
|
||||
t.nLits++
|
||||
}
|
||||
|
||||
// from https://stackoverflow.com/a/28730362
|
||||
@@ -230,8 +228,9 @@ func (t *tokens) EstimatedBits() int {
|
||||
shannon := float32(0)
|
||||
bits := int(0)
|
||||
nMatches := 0
|
||||
if t.nLits > 0 {
|
||||
invTotal := 1.0 / float32(t.nLits)
|
||||
total := int(t.n) + t.nFilled
|
||||
if total > 0 {
|
||||
invTotal := 1.0 / float32(total)
|
||||
for _, v := range t.litHist[:] {
|
||||
if v > 0 {
|
||||
n := float32(v)
|
||||
@@ -275,7 +274,6 @@ func (t *tokens) AddMatch(xlength uint32, xoffset uint32) {
|
||||
}
|
||||
oCode := offsetCode(xoffset)
|
||||
xoffset |= oCode << 16
|
||||
t.nLits++
|
||||
|
||||
t.extraHist[lengthCodes1[uint8(xlength)]]++
|
||||
t.offHist[oCode]++
|
||||
@@ -301,7 +299,6 @@ func (t *tokens) AddMatchLong(xlength int32, xoffset uint32) {
|
||||
}
|
||||
xlength -= xl
|
||||
xl -= baseMatchLength
|
||||
t.nLits++
|
||||
t.extraHist[lengthCodes1[uint8(xl)]]++
|
||||
t.offHist[oc]++
|
||||
t.tokens[t.n] = token(matchType | uint32(xl)<<lengthShift | xoffset)
|
||||
|
||||
230
vendor/github.com/klauspost/compress/huff0/decompress.go
сгенерированный
поставляемый
230
vendor/github.com/klauspost/compress/huff0/decompress.go
сгенерированный
поставляемый
@@ -20,7 +20,7 @@ type dEntrySingle struct {
|
||||
|
||||
// double-symbols decoding
|
||||
type dEntryDouble struct {
|
||||
seq uint16
|
||||
seq [4]byte
|
||||
nBits uint8
|
||||
len uint8
|
||||
}
|
||||
@@ -753,23 +753,21 @@ func (d *Decoder) Decompress4X(dst, src []byte) ([]byte, error) {
|
||||
br[stream2].fillFast()
|
||||
|
||||
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)
|
||||
v := single[val&tlMask]
|
||||
v2 := single[val2&tlMask]
|
||||
br[stream].advance(uint8(v.entry))
|
||||
br[stream2].advance(uint8(v2.entry))
|
||||
buf[off+bufoff*stream] = uint8(v.entry >> 8)
|
||||
buf[off+bufoff*stream2] = uint8(v2.entry >> 8)
|
||||
|
||||
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)
|
||||
v = single[val&tlMask]
|
||||
v2 = single[val2&tlMask]
|
||||
br[stream].advance(uint8(v.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)
|
||||
}
|
||||
|
||||
@@ -780,23 +778,21 @@ func (d *Decoder) Decompress4X(dst, src []byte) ([]byte, error) {
|
||||
br[stream2].fillFast()
|
||||
|
||||
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)
|
||||
v := single[val&tlMask]
|
||||
v2 := single[val2&tlMask]
|
||||
br[stream].advance(uint8(v.entry))
|
||||
br[stream2].advance(uint8(v2.entry))
|
||||
buf[off+bufoff*stream] = uint8(v.entry >> 8)
|
||||
buf[off+bufoff*stream2] = uint8(v2.entry >> 8)
|
||||
|
||||
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)
|
||||
v = single[val&tlMask]
|
||||
v2 = single[val2&tlMask]
|
||||
br[stream].advance(uint8(v.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)
|
||||
}
|
||||
|
||||
@@ -914,7 +910,7 @@ func (d *Decoder) decompress4X8bit(dst, src []byte) ([]byte, error) {
|
||||
out := dst
|
||||
dstEvery := (dstSize + 3) / 4
|
||||
|
||||
shift := (8 - d.actualTableLog) & 7
|
||||
shift := (56 + (8 - d.actualTableLog)) & 63
|
||||
|
||||
const tlSize = 1 << 8
|
||||
single := d.dt.single[:tlSize]
|
||||
@@ -935,79 +931,91 @@ func (d *Decoder) decompress4X8bit(dst, src []byte) ([]byte, error) {
|
||||
// Interleave 2 decodes.
|
||||
const stream = 0
|
||||
const stream2 = 1
|
||||
br[stream].fillFast()
|
||||
br[stream2].fillFast()
|
||||
br1 := &br[stream]
|
||||
br2 := &br[stream2]
|
||||
br1.fillFast()
|
||||
br2.fillFast()
|
||||
|
||||
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] = uint8(v >> 8)
|
||||
br[stream].advance(uint8(v))
|
||||
|
||||
v2 := single[br[stream2].peekByteFast()>>shift].entry
|
||||
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)
|
||||
br[stream].advance(uint8(v))
|
||||
|
||||
v2 = single[br[stream2].peekByteFast()>>shift].entry
|
||||
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)
|
||||
br[stream].advance(uint8(v))
|
||||
|
||||
v2 = single[br[stream2].peekByteFast()>>shift].entry
|
||||
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)
|
||||
br[stream2].advance(uint8(v2))
|
||||
buf[off+bufoff*stream+3] = uint8(v >> 8)
|
||||
}
|
||||
|
||||
{
|
||||
const stream = 2
|
||||
const stream2 = 3
|
||||
br[stream].fillFast()
|
||||
br[stream2].fillFast()
|
||||
br1 := &br[stream]
|
||||
br2 := &br[stream2]
|
||||
br1.fillFast()
|
||||
br2.fillFast()
|
||||
|
||||
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] = uint8(v >> 8)
|
||||
br[stream].advance(uint8(v))
|
||||
|
||||
v2 := single[br[stream2].peekByteFast()>>shift].entry
|
||||
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)
|
||||
br[stream].advance(uint8(v))
|
||||
|
||||
v2 = single[br[stream2].peekByteFast()>>shift].entry
|
||||
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)
|
||||
br[stream].advance(uint8(v))
|
||||
|
||||
v2 = single[br[stream2].peekByteFast()>>shift].entry
|
||||
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)
|
||||
br[stream2].advance(uint8(v2))
|
||||
buf[off+bufoff*stream+3] = uint8(v >> 8)
|
||||
}
|
||||
|
||||
off += 4
|
||||
@@ -1073,7 +1081,7 @@ func (d *Decoder) decompress4X8bit(dst, src []byte) ([]byte, error) {
|
||||
}
|
||||
|
||||
// Read value and increment offset.
|
||||
v := single[br.peekByteFast()>>shift].entry
|
||||
v := single[uint8(br.value>>shift)].entry
|
||||
nBits := uint8(v)
|
||||
br.advance(nBits)
|
||||
bitsLeft -= int(nBits)
|
||||
@@ -1121,7 +1129,7 @@ func (d *Decoder) decompress4X8bitExactly(dst, src []byte) ([]byte, error) {
|
||||
out := dst
|
||||
dstEvery := (dstSize + 3) / 4
|
||||
|
||||
const shift = 0
|
||||
const shift = 56
|
||||
const tlSize = 1 << 8
|
||||
const tlMask = tlSize - 1
|
||||
single := d.dt.single[:tlSize]
|
||||
@@ -1145,37 +1153,41 @@ func (d *Decoder) decompress4X8bitExactly(dst, src []byte) ([]byte, error) {
|
||||
br[stream].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)
|
||||
br[stream].advance(uint8(v))
|
||||
|
||||
v2 := single[br[stream2].peekByteFast()>>shift].entry
|
||||
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)
|
||||
br[stream].advance(uint8(v))
|
||||
|
||||
v2 = single[br[stream2].peekByteFast()>>shift].entry
|
||||
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)
|
||||
br[stream].advance(uint8(v))
|
||||
|
||||
v2 = single[br[stream2].peekByteFast()>>shift].entry
|
||||
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)
|
||||
br[stream].advance(uint8(v))
|
||||
|
||||
v2 = single[br[stream2].peekByteFast()>>shift].entry
|
||||
buf[off+bufoff*stream2+3] = uint8(v2 >> 8)
|
||||
br[stream2].advance(uint8(v2))
|
||||
}
|
||||
|
||||
{
|
||||
@@ -1184,37 +1196,41 @@ func (d *Decoder) decompress4X8bitExactly(dst, src []byte) ([]byte, error) {
|
||||
br[stream].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)
|
||||
br[stream].advance(uint8(v))
|
||||
|
||||
v2 := single[br[stream2].peekByteFast()>>shift].entry
|
||||
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)
|
||||
br[stream].advance(uint8(v))
|
||||
|
||||
v2 = single[br[stream2].peekByteFast()>>shift].entry
|
||||
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)
|
||||
br[stream].advance(uint8(v))
|
||||
|
||||
v2 = single[br[stream2].peekByteFast()>>shift].entry
|
||||
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)
|
||||
br[stream].advance(uint8(v))
|
||||
|
||||
v2 = single[br[stream2].peekByteFast()>>shift].entry
|
||||
buf[off+bufoff*stream2+3] = uint8(v2 >> 8)
|
||||
br[stream2].advance(uint8(v2))
|
||||
}
|
||||
|
||||
off += 4
|
||||
@@ -1280,7 +1296,7 @@ func (d *Decoder) decompress4X8bitExactly(dst, src []byte) ([]byte, error) {
|
||||
}
|
||||
|
||||
// Read value and increment offset.
|
||||
v := single[br.peekByteFast()>>shift].entry
|
||||
v := single[br.peekByteFast()].entry
|
||||
nBits := uint8(v)
|
||||
br.advance(nBits)
|
||||
bitsLeft -= int(nBits)
|
||||
|
||||
256
vendor/github.com/klauspost/compress/s2/README.md
сгенерированный
поставляемый
256
vendor/github.com/klauspost/compress/s2/README.md
сгенерированный
поставляемый
@@ -20,6 +20,7 @@ This is important, so you don't have to worry about spending CPU cycles on alrea
|
||||
* Concurrent stream compression
|
||||
* Faster decompression, even for Snappy compatible content
|
||||
* Ability to quickly skip forward in compressed stream
|
||||
* Random seeking with indexes
|
||||
* Compatible with reading Snappy compressed content
|
||||
* Smaller block size overhead on incompressible blocks
|
||||
* Block concatenation
|
||||
@@ -29,8 +30,8 @@ This is important, so you don't have to worry about spending CPU cycles on alrea
|
||||
|
||||
## Drawbacks over Snappy
|
||||
|
||||
* Not optimized for 32 bit systems.
|
||||
* Streams use slightly more memory due to larger blocks and concurrency (configurable).
|
||||
* Not optimized for 32 bit systems
|
||||
* Streams use slightly more memory due to larger blocks and concurrency (configurable)
|
||||
|
||||
# Usage
|
||||
|
||||
@@ -141,7 +142,7 @@ Binaries can be downloaded on the [Releases Page](https://github.com/klauspost/c
|
||||
|
||||
Installing then requires Go to be installed. To install them, use:
|
||||
|
||||
`go install github.com/klauspost/compress/s2/cmd/s2c && go install github.com/klauspost/compress/s2/cmd/s2d`
|
||||
`go install github.com/klauspost/compress/s2/cmd/s2c@latest && go install github.com/klauspost/compress/s2/cmd/s2d@latest`
|
||||
|
||||
To build binaries to the current folder use:
|
||||
|
||||
@@ -176,6 +177,8 @@ Options:
|
||||
Compress faster, but with a minor compression loss
|
||||
-help
|
||||
Display help
|
||||
-index
|
||||
Add seek index (default true)
|
||||
-o string
|
||||
Write output to another file. Single input file only
|
||||
-pad string
|
||||
@@ -217,11 +220,15 @@ Options:
|
||||
Display help
|
||||
-o string
|
||||
Write output to another file. Single input file only
|
||||
-q Don't write any output to terminal, except errors
|
||||
-offset string
|
||||
Start at offset. Examples: 92, 64K, 256K, 1M, 4M. Requires Index
|
||||
-q Don't write any output to terminal, except errors
|
||||
-rm
|
||||
Delete source file(s) after successful decompression
|
||||
Delete source file(s) after successful decompression
|
||||
-safe
|
||||
Do not overwrite output files
|
||||
Do not overwrite output files
|
||||
-tail string
|
||||
Return last of compressed file. Examples: 92, 64K, 256K, 1M, 4M. Requires Index
|
||||
-verify
|
||||
Verify files, but do not write output
|
||||
```
|
||||
@@ -633,12 +640,12 @@ Compression and speed is typically a bit better `MaxEncodedLen` is also smaller
|
||||
Comparison of [`webdevdata.org-2015-01-07-subset`](https://files.klauspost.com/compress/webdevdata.org-2015-01-07-4GB-subset.7z),
|
||||
53927 files, total input size: 4,014,735,833 bytes. amd64, single goroutine used:
|
||||
|
||||
| Encoder | Size | MB/s | Reduction |
|
||||
|-----------------------|------------|--------|------------
|
||||
| snappy.Encode | 1128706759 | 725.59 | 71.89% |
|
||||
| s2.EncodeSnappy | 1093823291 | 899.16 | 72.75% |
|
||||
| s2.EncodeSnappyBetter | 1001158548 | 578.49 | 75.06% |
|
||||
| s2.EncodeSnappyBest | 944507998 | 66.00 | 76.47% |
|
||||
| Encoder | Size | MB/s | Reduction |
|
||||
|-----------------------|------------|------------|------------
|
||||
| snappy.Encode | 1128706759 | 725.59 | 71.89% |
|
||||
| s2.EncodeSnappy | 1093823291 | **899.16** | 72.75% |
|
||||
| s2.EncodeSnappyBetter | 1001158548 | 578.49 | 75.06% |
|
||||
| s2.EncodeSnappyBest | 944507998 | 66.00 | **76.47%**|
|
||||
|
||||
## Streams
|
||||
|
||||
@@ -649,11 +656,11 @@ Comparison of different streams, AMD Ryzen 3950x, 16 cores. Size and throughput:
|
||||
|
||||
| File | snappy.NewWriter | S2 Snappy | S2 Snappy, Better | S2 Snappy, Best |
|
||||
|-----------------------------|--------------------------|---------------------------|--------------------------|-------------------------|
|
||||
| nyc-taxi-data-10M.csv | 1316042016 - 517.54MB/s | 1307003093 - 8406.29MB/s | 1174534014 - 4984.35MB/s | 1115904679 - 177.81MB/s |
|
||||
| enwik10 | 5088294643 - 433.45MB/s | 5175840939 - 8454.52MB/s | 4560784526 - 4403.10MB/s | 4340299103 - 159.71MB/s |
|
||||
| 10gb.tar | 6056946612 - 703.25MB/s | 6208571995 - 9035.75MB/s | 5741646126 - 2402.08MB/s | 5548973895 - 171.17MB/s |
|
||||
| github-june-2days-2019.json | 1525176492 - 908.11MB/s | 1476519054 - 12625.93MB/s | 1400547532 - 6163.61MB/s | 1321887137 - 200.71MB/s |
|
||||
| consensus.db.10gb | 5412897703 - 1054.38MB/s | 5354073487 - 12634.82MB/s | 5335069899 - 2472.23MB/s | 5201000954 - 166.32MB/s |
|
||||
| nyc-taxi-data-10M.csv | 1316042016 - 539.47MB/s | 1307003093 - 10132.73MB/s | 1174534014 - 5002.44MB/s | 1115904679 - 177.97MB/s |
|
||||
| enwik10 (xml) | 5088294643 - 451.13MB/s | 5175840939 - 9440.69MB/s | 4560784526 - 4487.21MB/s | 4340299103 - 158.92MB/s |
|
||||
| 10gb.tar (mixed) | 6056946612 - 729.73MB/s | 6208571995 - 9978.05MB/s | 5741646126 - 4919.98MB/s | 5548973895 - 180.44MB/s |
|
||||
| github-june-2days-2019.json | 1525176492 - 933.00MB/s | 1476519054 - 13150.12MB/s | 1400547532 - 5803.40MB/s | 1321887137 - 204.29MB/s |
|
||||
| consensus.db.10gb (db) | 5412897703 - 1102.14MB/s | 5354073487 - 13562.91MB/s | 5335069899 - 5294.73MB/s | 5201000954 - 175.72MB/s |
|
||||
|
||||
# Decompression
|
||||
|
||||
@@ -679,7 +686,220 @@ The 10 byte 'stream identifier' of the second stream can optionally be stripped,
|
||||
|
||||
Blocks can be concatenated using the `ConcatBlocks` function.
|
||||
|
||||
Snappy blocks/streams can safely be concatenated with S2 blocks and streams.
|
||||
Snappy blocks/streams can safely be concatenated with S2 blocks and streams.
|
||||
Streams with indexes (see below) will currently not work on concatenated streams.
|
||||
|
||||
# Stream Seek Index
|
||||
|
||||
S2 and Snappy streams can have indexes. These indexes will allow random seeking within the compressed data.
|
||||
|
||||
The index can either be appended to the stream as a skippable block or returned for separate storage.
|
||||
|
||||
When the index is appended to a stream it will be skipped by regular decoders,
|
||||
so the output remains compatible with other decoders.
|
||||
|
||||
## Creating an Index
|
||||
|
||||
To automatically add an index to a stream, add `WriterAddIndex()` option to your writer.
|
||||
Then the index will be added to the stream when `Close()` is called.
|
||||
|
||||
```
|
||||
// Add Index to stream...
|
||||
enc := s2.NewWriter(w, s2.WriterAddIndex())
|
||||
io.Copy(enc, r)
|
||||
enc.Close()
|
||||
```
|
||||
|
||||
If you want to store the index separately, you can use `CloseIndex()` instead of the regular `Close()`.
|
||||
This will return the index. Note that `CloseIndex()` should only be called once, and you shouldn't call `Close()`.
|
||||
|
||||
```
|
||||
// Get index for separate storage...
|
||||
enc := s2.NewWriter(w)
|
||||
io.Copy(enc, r)
|
||||
index, err := enc.CloseIndex()
|
||||
```
|
||||
|
||||
The `index` can then be used needing to read from the stream.
|
||||
This means the index can be used without needing to seek to the end of the stream
|
||||
or for manually forwarding streams. See below.
|
||||
|
||||
Finally, an existing S2/Snappy stream can be indexed using the `s2.IndexStream(r io.Reader)` function.
|
||||
|
||||
## Using Indexes
|
||||
|
||||
To use indexes there is a `ReadSeeker(random bool, index []byte) (*ReadSeeker, error)` function available.
|
||||
|
||||
Calling ReadSeeker will return an [io.ReadSeeker](https://pkg.go.dev/io#ReadSeeker) compatible version of the reader.
|
||||
|
||||
If 'random' is specified the returned io.Seeker can be used for random seeking, otherwise only forward seeking is supported.
|
||||
Enabling random seeking requires the original input to support the [io.Seeker](https://pkg.go.dev/io#Seeker) interface.
|
||||
|
||||
```
|
||||
dec := s2.NewReader(r)
|
||||
rs, err := dec.ReadSeeker(false, nil)
|
||||
rs.Seek(wantOffset, io.SeekStart)
|
||||
```
|
||||
|
||||
Get a seeker to seek forward. Since no index is provided, the index is read from the stream.
|
||||
This requires that an index was added and that `r` supports the [io.Seeker](https://pkg.go.dev/io#Seeker) interface.
|
||||
|
||||
A custom index can be specified which will be used if supplied.
|
||||
When using a custom index, it will not be read from the input stream.
|
||||
|
||||
```
|
||||
dec := s2.NewReader(r)
|
||||
rs, err := dec.ReadSeeker(false, index)
|
||||
rs.Seek(wantOffset, io.SeekStart)
|
||||
```
|
||||
|
||||
This will read the index from `index`. Since we specify non-random (forward only) seeking `r` does not have to be an io.Seeker
|
||||
|
||||
```
|
||||
dec := s2.NewReader(r)
|
||||
rs, err := dec.ReadSeeker(true, index)
|
||||
rs.Seek(wantOffset, io.SeekStart)
|
||||
```
|
||||
|
||||
Finally, since we specify that we want to do random seeking `r` must be an io.Seeker.
|
||||
|
||||
The returned [ReadSeeker](https://pkg.go.dev/github.com/klauspost/compress/s2#ReadSeeker) contains a shallow reference to the existing Reader,
|
||||
meaning changes performed to one is reflected in the other.
|
||||
|
||||
To check if a stream contains an index at the end, the `(*Index).LoadStream(rs io.ReadSeeker) error` can be used.
|
||||
|
||||
## Manually Forwarding Streams
|
||||
|
||||
Indexes can also be read outside the decoder using the [Index](https://pkg.go.dev/github.com/klauspost/compress/s2#Index) type.
|
||||
This can be used for parsing indexes, either separate or in streams.
|
||||
|
||||
In some cases it may not be possible to serve a seekable stream.
|
||||
This can for instance be an HTTP stream, where the Range request
|
||||
is sent at the start of the stream.
|
||||
|
||||
With a little bit of extra code it is still possible to use indexes
|
||||
to forward to specific offset with a single forward skip.
|
||||
|
||||
It is possible to load the index manually like this:
|
||||
```
|
||||
var index s2.Index
|
||||
_, err = index.Load(idxBytes)
|
||||
```
|
||||
|
||||
This can be used to figure out how much to offset the compressed stream:
|
||||
|
||||
```
|
||||
compressedOffset, uncompressedOffset, err := index.Find(wantOffset)
|
||||
```
|
||||
|
||||
The `compressedOffset` is the number of bytes that should be skipped
|
||||
from the beginning of the compressed file.
|
||||
|
||||
The `uncompressedOffset` will then be offset of the uncompressed bytes returned
|
||||
when decoding from that position. This will always be <= wantOffset.
|
||||
|
||||
When creating a decoder it must be specified that it should *not* expect a stream identifier
|
||||
at the beginning of the stream. Assuming the io.Reader `r` has been forwarded to `compressedOffset`
|
||||
we create the decoder like this:
|
||||
|
||||
```
|
||||
dec := s2.NewReader(r, s2.ReaderIgnoreStreamIdentifier())
|
||||
```
|
||||
|
||||
We are not completely done. We still need to forward the stream the uncompressed bytes we didn't want.
|
||||
This is done using the regular "Skip" function:
|
||||
|
||||
```
|
||||
err = dec.Skip(wantOffset - uncompressedOffset)
|
||||
```
|
||||
|
||||
This will ensure that we are at exactly the offset we want, and reading from `dec` will start at the requested offset.
|
||||
|
||||
## Index Format:
|
||||
|
||||
Each block is structured as a snappy skippable block, with the chunk ID 0x99.
|
||||
|
||||
The block can be read from the front, but contains information so it can be read from the back as well.
|
||||
|
||||
Numbers are stored as fixed size little endian values or [zigzag encoded](https://developers.google.com/protocol-buffers/docs/encoding#signed_integers) [base 128 varints](https://developers.google.com/protocol-buffers/docs/encoding),
|
||||
with un-encoded value length of 64 bits, unless other limits are specified.
|
||||
|
||||
| Content | Format |
|
||||
|---------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------|
|
||||
| ID, `[1]byte` | Always 0x99. |
|
||||
| Data Length, `[3]byte` | 3 byte little-endian length of the chunk in bytes, following this. |
|
||||
| Header `[6]byte` | Header, must be `[115, 50, 105, 100, 120, 0]` or in text: "s2idx\x00". |
|
||||
| UncompressedSize, Varint | Total Uncompressed size. |
|
||||
| CompressedSize, Varint | Total Compressed size if known. Should be -1 if unknown. |
|
||||
| EstBlockSize, Varint | Block Size, used for guessing uncompressed offsets. Must be >= 0. |
|
||||
| Entries, Varint | Number of Entries in index, must be < 65536 and >=0. |
|
||||
| HasUncompressedOffsets `byte` | 0 if no uncompressed offsets are present, 1 if present. Other values are invalid. |
|
||||
| UncompressedOffsets, [Entries]VarInt | Uncompressed offsets. See below how to decode. |
|
||||
| CompressedOffsets, [Entries]VarInt | Compressed offsets. See below how to decode. |
|
||||
| Block Size, `[4]byte` | Little Endian total encoded size (including header and trailer). Can be used for searching backwards to start of block. |
|
||||
| Trailer `[6]byte` | Trailer, must be `[0, 120, 100, 105, 50, 115]` or in text: "\x00xdi2s". Can be used for identifying block from end of stream. |
|
||||
|
||||
For regular streams the uncompressed offsets are fully predictable,
|
||||
so `HasUncompressedOffsets` allows to specify that compressed blocks all have
|
||||
exactly `EstBlockSize` bytes of uncompressed content.
|
||||
|
||||
Entries *must* be in order, starting with the lowest offset,
|
||||
and there *must* be no uncompressed offset duplicates.
|
||||
Entries *may* point to the start of a skippable block,
|
||||
but it is then not allowed to also have an entry for the next block since
|
||||
that would give an uncompressed offset duplicate.
|
||||
|
||||
There is no requirement for all blocks to be represented in the index.
|
||||
In fact there is a maximum of 65536 block entries in an index.
|
||||
|
||||
The writer can use any method to reduce the number of entries.
|
||||
An implicit block start at 0,0 can be assumed.
|
||||
|
||||
### Decoding entries:
|
||||
|
||||
```
|
||||
// Read Uncompressed entries.
|
||||
// Each assumes EstBlockSize delta from previous.
|
||||
for each entry {
|
||||
uOff = 0
|
||||
if HasUncompressedOffsets == 1 {
|
||||
uOff = ReadVarInt // Read value from stream
|
||||
}
|
||||
|
||||
// Except for the first entry, use previous values.
|
||||
if entryNum == 0 {
|
||||
entry[entryNum].UncompressedOffset = uOff
|
||||
continue
|
||||
}
|
||||
|
||||
// Uncompressed uses previous offset and adds EstBlockSize
|
||||
entry[entryNum].UncompressedOffset = entry[entryNum-1].UncompressedOffset + EstBlockSize
|
||||
}
|
||||
|
||||
|
||||
// Guess that the first block will be 50% of uncompressed size.
|
||||
// Integer truncating division must be used.
|
||||
CompressGuess := EstBlockSize / 2
|
||||
|
||||
// Read Compressed entries.
|
||||
// Each assumes CompressGuess delta from previous.
|
||||
// CompressGuess is adjusted for each value.
|
||||
for each entry {
|
||||
cOff = ReadVarInt // Read value from stream
|
||||
|
||||
// Except for the first entry, use previous values.
|
||||
if entryNum == 0 {
|
||||
entry[entryNum].CompressedOffset = cOff
|
||||
continue
|
||||
}
|
||||
|
||||
// Compressed uses previous and our estimate.
|
||||
entry[entryNum].CompressedOffset = entry[entryNum-1].CompressedOffset + CompressGuess + cOff
|
||||
|
||||
// Adjust compressed offset for next loop, integer truncating division must be used.
|
||||
CompressGuess += cOff/2
|
||||
}
|
||||
```
|
||||
|
||||
# Format Extensions
|
||||
|
||||
|
||||
229
vendor/github.com/klauspost/compress/s2/decode.go
сгенерированный
поставляемый
229
vendor/github.com/klauspost/compress/s2/decode.go
сгенерированный
поставляемый
@@ -8,7 +8,9 @@ package s2
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -22,6 +24,16 @@ var (
|
||||
ErrUnsupported = errors.New("s2: unsupported input")
|
||||
)
|
||||
|
||||
// ErrCantSeek is returned if the stream cannot be seeked.
|
||||
type ErrCantSeek struct {
|
||||
Reason string
|
||||
}
|
||||
|
||||
// Error returns the error as string.
|
||||
func (e ErrCantSeek) Error() string {
|
||||
return fmt.Sprintf("s2: Can't seek because %s", e.Reason)
|
||||
}
|
||||
|
||||
// DecodedLen returns the length of the decoded block.
|
||||
func DecodedLen(src []byte) (int, error) {
|
||||
v, _, err := decodedLen(src)
|
||||
@@ -88,6 +100,7 @@ func NewReader(r io.Reader, opts ...ReaderOption) *Reader {
|
||||
} else {
|
||||
nr.buf = make([]byte, MaxEncodedLen(defaultBlockSize)+checksumSize)
|
||||
}
|
||||
nr.readHeader = nr.ignoreStreamID
|
||||
nr.paramsOK = true
|
||||
return &nr
|
||||
}
|
||||
@@ -131,12 +144,41 @@ func ReaderAllocBlock(blockSize int) ReaderOption {
|
||||
}
|
||||
}
|
||||
|
||||
// ReaderIgnoreStreamIdentifier will make the reader skip the expected
|
||||
// stream identifier at the beginning of the stream.
|
||||
// This can be used when serving a stream that has been forwarded to a specific point.
|
||||
func ReaderIgnoreStreamIdentifier() ReaderOption {
|
||||
return func(r *Reader) error {
|
||||
r.ignoreStreamID = true
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ReaderSkippableCB will register a callback for chuncks with the specified ID.
|
||||
// ID must be a Reserved skippable chunks ID, 0x80-0xfd (inclusive).
|
||||
// For each chunk with the ID, the callback is called with the content.
|
||||
// Any returned non-nil error will abort decompression.
|
||||
// Only one callback per ID is supported, latest sent will be used.
|
||||
func ReaderSkippableCB(id uint8, fn func(r io.Reader) error) ReaderOption {
|
||||
return func(r *Reader) error {
|
||||
if id < 0x80 || id > 0xfd {
|
||||
return fmt.Errorf("ReaderSkippableCB: Invalid id provided, must be 0x80-0xfd (inclusive)")
|
||||
}
|
||||
r.skippableCB[id] = fn
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Reader is an io.Reader that can read Snappy-compressed bytes.
|
||||
type Reader struct {
|
||||
r io.Reader
|
||||
err error
|
||||
decoded []byte
|
||||
buf []byte
|
||||
r io.Reader
|
||||
err error
|
||||
decoded []byte
|
||||
buf []byte
|
||||
skippableCB [0x80]func(r io.Reader) error
|
||||
blockStart int64 // Uncompressed offset at start of current.
|
||||
index *Index
|
||||
|
||||
// decoded[i:j] contains decoded bytes that have not yet been passed on.
|
||||
i, j int
|
||||
// maximum block size allowed.
|
||||
@@ -144,10 +186,11 @@ type Reader struct {
|
||||
// maximum expected buffer size.
|
||||
maxBufSize int
|
||||
// alloc a buffer this size if > 0.
|
||||
lazyBuf int
|
||||
readHeader bool
|
||||
paramsOK bool
|
||||
snappyFrame bool
|
||||
lazyBuf int
|
||||
readHeader bool
|
||||
paramsOK bool
|
||||
snappyFrame bool
|
||||
ignoreStreamID bool
|
||||
}
|
||||
|
||||
// ensureBufferSize will ensure that the buffer can take at least n bytes.
|
||||
@@ -172,11 +215,12 @@ func (r *Reader) Reset(reader io.Reader) {
|
||||
if !r.paramsOK {
|
||||
return
|
||||
}
|
||||
r.index = nil
|
||||
r.r = reader
|
||||
r.err = nil
|
||||
r.i = 0
|
||||
r.j = 0
|
||||
r.readHeader = false
|
||||
r.readHeader = r.ignoreStreamID
|
||||
}
|
||||
|
||||
func (r *Reader) readFull(p []byte, allowEOF bool) (ok bool) {
|
||||
@@ -189,11 +233,24 @@ func (r *Reader) readFull(p []byte, allowEOF bool) (ok bool) {
|
||||
return true
|
||||
}
|
||||
|
||||
// skipN will skip n bytes.
|
||||
// skippable will skip n bytes.
|
||||
// If the supplied reader supports seeking that is used.
|
||||
// tmp is used as a temporary buffer for reading.
|
||||
// The supplied slice does not need to be the size of the read.
|
||||
func (r *Reader) skipN(tmp []byte, n int, allowEOF bool) (ok bool) {
|
||||
func (r *Reader) skippable(tmp []byte, n int, allowEOF bool, id uint8) (ok bool) {
|
||||
if id < 0x80 {
|
||||
r.err = fmt.Errorf("interbal error: skippable id < 0x80")
|
||||
return false
|
||||
}
|
||||
if fn := r.skippableCB[id-0x80]; fn != nil {
|
||||
rd := io.LimitReader(r.r, int64(n))
|
||||
r.err = fn(rd)
|
||||
if r.err != nil {
|
||||
return false
|
||||
}
|
||||
_, r.err = io.CopyBuffer(ioutil.Discard, rd, tmp)
|
||||
return r.err == nil
|
||||
}
|
||||
if rs, ok := r.r.(io.ReadSeeker); ok {
|
||||
_, err := rs.Seek(int64(n), io.SeekCurrent)
|
||||
if err == nil {
|
||||
@@ -247,6 +304,7 @@ func (r *Reader) Read(p []byte) (int, error) {
|
||||
// https://github.com/google/snappy/blob/master/framing_format.txt
|
||||
switch chunkType {
|
||||
case chunkTypeCompressedData:
|
||||
r.blockStart += int64(r.j)
|
||||
// Section 4.2. Compressed data (chunk type 0x00).
|
||||
if chunkLen < checksumSize {
|
||||
r.err = ErrCorrupt
|
||||
@@ -294,6 +352,7 @@ func (r *Reader) Read(p []byte) (int, error) {
|
||||
continue
|
||||
|
||||
case chunkTypeUncompressedData:
|
||||
r.blockStart += int64(r.j)
|
||||
// Section 4.3. Uncompressed data (chunk type 0x01).
|
||||
if chunkLen < checksumSize {
|
||||
r.err = ErrCorrupt
|
||||
@@ -357,17 +416,20 @@ func (r *Reader) Read(p []byte) (int, error) {
|
||||
|
||||
if chunkType <= 0x7f {
|
||||
// Section 4.5. Reserved unskippable chunks (chunk types 0x02-0x7f).
|
||||
// fmt.Printf("ERR chunktype: 0x%x\n", chunkType)
|
||||
r.err = ErrUnsupported
|
||||
return 0, r.err
|
||||
}
|
||||
// Section 4.4 Padding (chunk type 0xfe).
|
||||
// Section 4.6. Reserved skippable chunks (chunk types 0x80-0xfd).
|
||||
if chunkLen > maxBlockSize {
|
||||
if chunkLen > maxChunkSize {
|
||||
// fmt.Printf("ERR chunkLen: 0x%x\n", chunkLen)
|
||||
r.err = ErrUnsupported
|
||||
return 0, r.err
|
||||
}
|
||||
|
||||
if !r.skipN(r.buf, chunkLen, false) {
|
||||
// fmt.Printf("skippable: ID: 0x%x, len: 0x%x\n", chunkType, chunkLen)
|
||||
if !r.skippable(r.buf, chunkLen, false, chunkType) {
|
||||
return 0, r.err
|
||||
}
|
||||
}
|
||||
@@ -396,7 +458,7 @@ func (r *Reader) Skip(n int64) error {
|
||||
return nil
|
||||
}
|
||||
n -= int64(r.j - r.i)
|
||||
r.i, r.j = 0, 0
|
||||
r.i = r.j
|
||||
}
|
||||
|
||||
// Buffer empty; read blocks until we have content.
|
||||
@@ -420,6 +482,7 @@ func (r *Reader) Skip(n int64) error {
|
||||
// https://github.com/google/snappy/blob/master/framing_format.txt
|
||||
switch chunkType {
|
||||
case chunkTypeCompressedData:
|
||||
r.blockStart += int64(r.j)
|
||||
// Section 4.2. Compressed data (chunk type 0x00).
|
||||
if chunkLen < checksumSize {
|
||||
r.err = ErrCorrupt
|
||||
@@ -468,6 +531,7 @@ func (r *Reader) Skip(n int64) error {
|
||||
r.i, r.j = 0, dLen
|
||||
continue
|
||||
case chunkTypeUncompressedData:
|
||||
r.blockStart += int64(r.j)
|
||||
// Section 4.3. Uncompressed data (chunk type 0x01).
|
||||
if chunkLen < checksumSize {
|
||||
r.err = ErrCorrupt
|
||||
@@ -528,19 +592,138 @@ func (r *Reader) Skip(n int64) error {
|
||||
r.err = ErrUnsupported
|
||||
return r.err
|
||||
}
|
||||
if chunkLen > maxBlockSize {
|
||||
if chunkLen > maxChunkSize {
|
||||
r.err = ErrUnsupported
|
||||
return r.err
|
||||
}
|
||||
// Section 4.4 Padding (chunk type 0xfe).
|
||||
// Section 4.6. Reserved skippable chunks (chunk types 0x80-0xfd).
|
||||
if !r.skipN(r.buf, chunkLen, false) {
|
||||
if !r.skippable(r.buf, chunkLen, false, chunkType) {
|
||||
return r.err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ReadSeeker provides random or forward seeking in compressed content.
|
||||
// See Reader.ReadSeeker
|
||||
type ReadSeeker struct {
|
||||
*Reader
|
||||
}
|
||||
|
||||
// ReadSeeker will return an io.ReadSeeker compatible version of the reader.
|
||||
// If 'random' is specified the returned io.Seeker can be used for
|
||||
// random seeking, otherwise only forward seeking is supported.
|
||||
// Enabling random seeking requires the original input to support
|
||||
// the io.Seeker interface.
|
||||
// A custom index can be specified which will be used if supplied.
|
||||
// When using a custom index, it will not be read from the input stream.
|
||||
// The returned ReadSeeker contains a shallow reference to the existing Reader,
|
||||
// meaning changes performed to one is reflected in the other.
|
||||
func (r *Reader) ReadSeeker(random bool, index []byte) (*ReadSeeker, error) {
|
||||
// Read index if provided.
|
||||
if len(index) != 0 {
|
||||
if r.index == nil {
|
||||
r.index = &Index{}
|
||||
}
|
||||
if _, err := r.index.Load(index); err != nil {
|
||||
return nil, ErrCantSeek{Reason: "loading index returned: " + err.Error()}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if input is seekable
|
||||
rs, ok := r.r.(io.ReadSeeker)
|
||||
if !ok {
|
||||
if !random {
|
||||
return &ReadSeeker{Reader: r}, nil
|
||||
}
|
||||
return nil, ErrCantSeek{Reason: "input stream isn't seekable"}
|
||||
}
|
||||
|
||||
if r.index != nil {
|
||||
// Seekable and index, ok...
|
||||
return &ReadSeeker{Reader: r}, nil
|
||||
}
|
||||
|
||||
// Load from stream.
|
||||
r.index = &Index{}
|
||||
|
||||
// Read current position.
|
||||
pos, err := rs.Seek(0, io.SeekCurrent)
|
||||
if err != nil {
|
||||
return nil, ErrCantSeek{Reason: "seeking input returned: " + err.Error()}
|
||||
}
|
||||
err = r.index.LoadStream(rs)
|
||||
if err != nil {
|
||||
if err == ErrUnsupported {
|
||||
return nil, ErrCantSeek{Reason: "input stream does not contain an index"}
|
||||
}
|
||||
return nil, ErrCantSeek{Reason: "reading index returned: " + err.Error()}
|
||||
}
|
||||
|
||||
// reset position.
|
||||
_, err = rs.Seek(pos, io.SeekStart)
|
||||
if err != nil {
|
||||
return nil, ErrCantSeek{Reason: "seeking input returned: " + err.Error()}
|
||||
}
|
||||
return &ReadSeeker{Reader: r}, nil
|
||||
}
|
||||
|
||||
// Seek allows seeking in compressed data.
|
||||
func (r *ReadSeeker) Seek(offset int64, whence int) (int64, error) {
|
||||
if r.err != nil {
|
||||
return 0, r.err
|
||||
}
|
||||
if offset == 0 && whence == io.SeekCurrent {
|
||||
return r.blockStart + int64(r.i), nil
|
||||
}
|
||||
if !r.readHeader {
|
||||
// Make sure we read the header.
|
||||
_, r.err = r.Read([]byte{})
|
||||
}
|
||||
rs, ok := r.r.(io.ReadSeeker)
|
||||
if r.index == nil || !ok {
|
||||
if whence == io.SeekCurrent && offset >= 0 {
|
||||
err := r.Skip(offset)
|
||||
return r.blockStart + int64(r.i), err
|
||||
}
|
||||
if whence == io.SeekStart && offset >= r.blockStart+int64(r.i) {
|
||||
err := r.Skip(offset - r.blockStart - int64(r.i))
|
||||
return r.blockStart + int64(r.i), err
|
||||
}
|
||||
return 0, ErrUnsupported
|
||||
|
||||
}
|
||||
|
||||
switch whence {
|
||||
case io.SeekCurrent:
|
||||
offset += r.blockStart + int64(r.i)
|
||||
case io.SeekEnd:
|
||||
offset = -offset
|
||||
}
|
||||
c, u, err := r.index.Find(offset)
|
||||
if err != nil {
|
||||
return r.blockStart + int64(r.i), err
|
||||
}
|
||||
|
||||
// Seek to next block
|
||||
_, err = rs.Seek(c, io.SeekStart)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if offset < 0 {
|
||||
offset = r.index.TotalUncompressed + offset
|
||||
}
|
||||
|
||||
r.i = r.j // Remove rest of current block.
|
||||
if u < offset {
|
||||
// Forward inside block
|
||||
return offset, r.Skip(offset - u)
|
||||
}
|
||||
return offset, nil
|
||||
}
|
||||
|
||||
// ReadByte satisfies the io.ByteReader interface.
|
||||
func (r *Reader) ReadByte() (byte, error) {
|
||||
if r.err != nil {
|
||||
@@ -563,3 +746,17 @@ func (r *Reader) ReadByte() (byte, error) {
|
||||
}
|
||||
return 0, io.ErrNoProgress
|
||||
}
|
||||
|
||||
// SkippableCB will register a callback for chunks with the specified ID.
|
||||
// ID must be a Reserved skippable chunks ID, 0x80-0xfe (inclusive).
|
||||
// For each chunk with the ID, the callback is called with the content.
|
||||
// Any returned non-nil error will abort decompression.
|
||||
// Only one callback per ID is supported, latest sent will be used.
|
||||
// Sending a nil function will disable previous callbacks.
|
||||
func (r *Reader) SkippableCB(id uint8, fn func(r io.Reader) error) error {
|
||||
if id < 0x80 || id > chunkTypePadding {
|
||||
return fmt.Errorf("ReaderSkippableCB: Invalid id provided, must be 0x80-0xfe (inclusive)")
|
||||
}
|
||||
r.skippableCB[id] = fn
|
||||
return nil
|
||||
}
|
||||
|
||||
249
vendor/github.com/klauspost/compress/s2/encode.go
сгенерированный
поставляемый
249
vendor/github.com/klauspost/compress/s2/encode.go
сгенерированный
поставляемый
@@ -395,23 +395,26 @@ type Writer struct {
|
||||
// ibuf is a buffer for the incoming (uncompressed) bytes.
|
||||
ibuf []byte
|
||||
|
||||
blockSize int
|
||||
obufLen int
|
||||
concurrency int
|
||||
written int64
|
||||
output chan chan result
|
||||
buffers sync.Pool
|
||||
pad int
|
||||
blockSize int
|
||||
obufLen int
|
||||
concurrency int
|
||||
written int64
|
||||
uncompWritten int64 // Bytes sent to compression
|
||||
output chan chan result
|
||||
buffers sync.Pool
|
||||
pad int
|
||||
|
||||
writer io.Writer
|
||||
randSrc io.Reader
|
||||
writerWg sync.WaitGroup
|
||||
index Index
|
||||
|
||||
// wroteStreamHeader is whether we have written the stream header.
|
||||
wroteStreamHeader bool
|
||||
paramsOK bool
|
||||
snappy bool
|
||||
flushOnWrite bool
|
||||
appendIndex bool
|
||||
level uint8
|
||||
}
|
||||
|
||||
@@ -422,7 +425,11 @@ const (
|
||||
levelBest
|
||||
)
|
||||
|
||||
type result []byte
|
||||
type result struct {
|
||||
b []byte
|
||||
// Uncompressed start offset
|
||||
startOffset int64
|
||||
}
|
||||
|
||||
// err returns the previously set error.
|
||||
// If no error has been set it is set to err if not nil.
|
||||
@@ -454,6 +461,9 @@ func (w *Writer) Reset(writer io.Writer) {
|
||||
w.wroteStreamHeader = false
|
||||
w.written = 0
|
||||
w.writer = writer
|
||||
w.uncompWritten = 0
|
||||
w.index.reset(w.blockSize)
|
||||
|
||||
// If we didn't get a writer, stop here.
|
||||
if writer == nil {
|
||||
return
|
||||
@@ -474,7 +484,8 @@ func (w *Writer) Reset(writer io.Writer) {
|
||||
// Get a queued write.
|
||||
for write := range toWrite {
|
||||
// Wait for the data to be available.
|
||||
in := <-write
|
||||
input := <-write
|
||||
in := input.b
|
||||
if len(in) > 0 {
|
||||
if w.err(nil) == nil {
|
||||
// Don't expose data from previous buffers.
|
||||
@@ -485,11 +496,12 @@ func (w *Writer) Reset(writer io.Writer) {
|
||||
err = io.ErrShortBuffer
|
||||
}
|
||||
_ = w.err(err)
|
||||
w.err(w.index.add(w.written, input.startOffset))
|
||||
w.written += int64(n)
|
||||
}
|
||||
}
|
||||
if cap(in) >= w.obufLen {
|
||||
w.buffers.Put([]byte(in))
|
||||
w.buffers.Put(in)
|
||||
}
|
||||
// close the incoming write request.
|
||||
// This can be used for synchronizing flushes.
|
||||
@@ -500,6 +512,9 @@ func (w *Writer) Reset(writer io.Writer) {
|
||||
|
||||
// Write satisfies the io.Writer interface.
|
||||
func (w *Writer) Write(p []byte) (nRet int, errRet error) {
|
||||
if err := w.err(nil); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if w.flushOnWrite {
|
||||
return w.write(p)
|
||||
}
|
||||
@@ -535,6 +550,9 @@ func (w *Writer) Write(p []byte) (nRet int, errRet error) {
|
||||
// The return value n is the number of bytes read.
|
||||
// Any error except io.EOF encountered during the read is also returned.
|
||||
func (w *Writer) ReadFrom(r io.Reader) (n int64, err error) {
|
||||
if err := w.err(nil); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if len(w.ibuf) > 0 {
|
||||
err := w.Flush()
|
||||
if err != nil {
|
||||
@@ -577,6 +595,85 @@ func (w *Writer) ReadFrom(r io.Reader) (n int64, err error) {
|
||||
return n, w.err(nil)
|
||||
}
|
||||
|
||||
// AddSkippableBlock will add a skippable block to the stream.
|
||||
// The ID must be 0x80-0xfe (inclusive).
|
||||
// Length of the skippable block must be <= 16777215 bytes.
|
||||
func (w *Writer) AddSkippableBlock(id uint8, data []byte) (err error) {
|
||||
if err := w.err(nil); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(data) == 0 {
|
||||
return nil
|
||||
}
|
||||
if id < 0x80 || id > chunkTypePadding {
|
||||
return fmt.Errorf("invalid skippable block id %x", id)
|
||||
}
|
||||
if len(data) > maxChunkSize {
|
||||
return fmt.Errorf("skippable block excessed maximum size")
|
||||
}
|
||||
var header [4]byte
|
||||
chunkLen := 4 + len(data)
|
||||
header[0] = id
|
||||
header[1] = uint8(chunkLen >> 0)
|
||||
header[2] = uint8(chunkLen >> 8)
|
||||
header[3] = uint8(chunkLen >> 16)
|
||||
if w.concurrency == 1 {
|
||||
write := func(b []byte) error {
|
||||
n, err := w.writer.Write(b)
|
||||
if err = w.err(err); err != nil {
|
||||
return err
|
||||
}
|
||||
if n != len(data) {
|
||||
return w.err(io.ErrShortWrite)
|
||||
}
|
||||
w.written += int64(n)
|
||||
return w.err(nil)
|
||||
}
|
||||
if !w.wroteStreamHeader {
|
||||
w.wroteStreamHeader = true
|
||||
if w.snappy {
|
||||
if err := write([]byte(magicChunkSnappy)); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := write([]byte(magicChunk)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := write(header[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := write(data); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Create output...
|
||||
if !w.wroteStreamHeader {
|
||||
w.wroteStreamHeader = true
|
||||
hWriter := make(chan result)
|
||||
w.output <- hWriter
|
||||
if w.snappy {
|
||||
hWriter <- result{startOffset: w.uncompWritten, b: []byte(magicChunkSnappy)}
|
||||
} else {
|
||||
hWriter <- result{startOffset: w.uncompWritten, b: []byte(magicChunk)}
|
||||
}
|
||||
}
|
||||
|
||||
// Copy input.
|
||||
inbuf := w.buffers.Get().([]byte)[:4]
|
||||
copy(inbuf, header[:])
|
||||
inbuf = append(inbuf, data...)
|
||||
|
||||
output := make(chan result, 1)
|
||||
// Queue output.
|
||||
w.output <- output
|
||||
output <- result{startOffset: w.uncompWritten, b: inbuf}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// EncodeBuffer will add a buffer to the stream.
|
||||
// This is the fastest way to encode a stream,
|
||||
// but the input buffer cannot be written to by the caller
|
||||
@@ -614,9 +711,9 @@ func (w *Writer) EncodeBuffer(buf []byte) (err error) {
|
||||
hWriter := make(chan result)
|
||||
w.output <- hWriter
|
||||
if w.snappy {
|
||||
hWriter <- []byte(magicChunkSnappy)
|
||||
hWriter <- result{startOffset: w.uncompWritten, b: []byte(magicChunkSnappy)}
|
||||
} else {
|
||||
hWriter <- []byte(magicChunk)
|
||||
hWriter <- result{startOffset: w.uncompWritten, b: []byte(magicChunk)}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -632,6 +729,10 @@ func (w *Writer) EncodeBuffer(buf []byte) (err error) {
|
||||
output := make(chan result)
|
||||
// Queue output now, so we keep order.
|
||||
w.output <- output
|
||||
res := result{
|
||||
startOffset: w.uncompWritten,
|
||||
}
|
||||
w.uncompWritten += int64(len(uncompressed))
|
||||
go func() {
|
||||
checksum := crc(uncompressed)
|
||||
|
||||
@@ -664,7 +765,8 @@ func (w *Writer) EncodeBuffer(buf []byte) (err error) {
|
||||
obuf[7] = uint8(checksum >> 24)
|
||||
|
||||
// Queue final output.
|
||||
output <- obuf
|
||||
res.b = obuf
|
||||
output <- res
|
||||
}()
|
||||
}
|
||||
return nil
|
||||
@@ -708,9 +810,9 @@ func (w *Writer) write(p []byte) (nRet int, errRet error) {
|
||||
hWriter := make(chan result)
|
||||
w.output <- hWriter
|
||||
if w.snappy {
|
||||
hWriter <- []byte(magicChunkSnappy)
|
||||
hWriter <- result{startOffset: w.uncompWritten, b: []byte(magicChunkSnappy)}
|
||||
} else {
|
||||
hWriter <- []byte(magicChunk)
|
||||
hWriter <- result{startOffset: w.uncompWritten, b: []byte(magicChunk)}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -731,6 +833,11 @@ func (w *Writer) write(p []byte) (nRet int, errRet error) {
|
||||
output := make(chan result)
|
||||
// Queue output now, so we keep order.
|
||||
w.output <- output
|
||||
res := result{
|
||||
startOffset: w.uncompWritten,
|
||||
}
|
||||
w.uncompWritten += int64(len(uncompressed))
|
||||
|
||||
go func() {
|
||||
checksum := crc(uncompressed)
|
||||
|
||||
@@ -763,7 +870,8 @@ func (w *Writer) write(p []byte) (nRet int, errRet error) {
|
||||
obuf[7] = uint8(checksum >> 24)
|
||||
|
||||
// Queue final output.
|
||||
output <- obuf
|
||||
res.b = obuf
|
||||
output <- res
|
||||
|
||||
// Put unused buffer back in pool.
|
||||
w.buffers.Put(inbuf)
|
||||
@@ -793,9 +901,9 @@ func (w *Writer) writeFull(inbuf []byte) (errRet error) {
|
||||
hWriter := make(chan result)
|
||||
w.output <- hWriter
|
||||
if w.snappy {
|
||||
hWriter <- []byte(magicChunkSnappy)
|
||||
hWriter <- result{startOffset: w.uncompWritten, b: []byte(magicChunkSnappy)}
|
||||
} else {
|
||||
hWriter <- []byte(magicChunk)
|
||||
hWriter <- result{startOffset: w.uncompWritten, b: []byte(magicChunk)}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -806,6 +914,11 @@ func (w *Writer) writeFull(inbuf []byte) (errRet error) {
|
||||
output := make(chan result)
|
||||
// Queue output now, so we keep order.
|
||||
w.output <- output
|
||||
res := result{
|
||||
startOffset: w.uncompWritten,
|
||||
}
|
||||
w.uncompWritten += int64(len(uncompressed))
|
||||
|
||||
go func() {
|
||||
checksum := crc(uncompressed)
|
||||
|
||||
@@ -838,7 +951,8 @@ func (w *Writer) writeFull(inbuf []byte) (errRet error) {
|
||||
obuf[7] = uint8(checksum >> 24)
|
||||
|
||||
// Queue final output.
|
||||
output <- obuf
|
||||
res.b = obuf
|
||||
output <- res
|
||||
|
||||
// Put unused buffer back in pool.
|
||||
w.buffers.Put(inbuf)
|
||||
@@ -912,7 +1026,10 @@ func (w *Writer) writeSync(p []byte) (nRet int, errRet error) {
|
||||
if n != len(obuf) {
|
||||
return 0, w.err(io.ErrShortWrite)
|
||||
}
|
||||
w.err(w.index.add(w.written, w.uncompWritten))
|
||||
w.written += int64(n)
|
||||
w.uncompWritten += int64(len(uncompressed))
|
||||
|
||||
if chunkType == chunkTypeUncompressedData {
|
||||
// Write uncompressed data.
|
||||
n, err := w.writer.Write(uncompressed)
|
||||
@@ -961,38 +1078,87 @@ func (w *Writer) Flush() error {
|
||||
res := make(chan result)
|
||||
w.output <- res
|
||||
// Block until this has been picked up.
|
||||
res <- nil
|
||||
res <- result{b: nil, startOffset: w.uncompWritten}
|
||||
// When it is closed, we have flushed.
|
||||
<-res
|
||||
return w.err(nil)
|
||||
}
|
||||
|
||||
// Close calls Flush and then closes the Writer.
|
||||
// Calling Close multiple times is ok.
|
||||
// Calling Close multiple times is ok,
|
||||
// but calling CloseIndex after this will make it not return the index.
|
||||
func (w *Writer) Close() error {
|
||||
_, err := w.closeIndex(w.appendIndex)
|
||||
return err
|
||||
}
|
||||
|
||||
// CloseIndex calls Close and returns an index on first call.
|
||||
// This is not required if you are only adding index to a stream.
|
||||
func (w *Writer) CloseIndex() ([]byte, error) {
|
||||
return w.closeIndex(true)
|
||||
}
|
||||
|
||||
func (w *Writer) closeIndex(idx bool) ([]byte, error) {
|
||||
err := w.Flush()
|
||||
if w.output != nil {
|
||||
close(w.output)
|
||||
w.writerWg.Wait()
|
||||
w.output = nil
|
||||
}
|
||||
if w.err(nil) == nil && w.writer != nil && w.pad > 0 {
|
||||
add := calcSkippableFrame(w.written, int64(w.pad))
|
||||
frame, err := skippableFrame(w.ibuf[:0], add, w.randSrc)
|
||||
if err = w.err(err); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err2 := w.writer.Write(frame)
|
||||
_ = w.err(err2)
|
||||
}
|
||||
_ = w.err(errClosed)
|
||||
if err == errClosed {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
const skippableFrameHeader = 4
|
||||
var index []byte
|
||||
if w.err(nil) == nil && w.writer != nil {
|
||||
// Create index.
|
||||
if idx {
|
||||
compSize := int64(-1)
|
||||
if w.pad <= 1 {
|
||||
compSize = w.written
|
||||
}
|
||||
index = w.index.appendTo(w.ibuf[:0], w.uncompWritten, compSize)
|
||||
// Count as written for padding.
|
||||
if w.appendIndex {
|
||||
w.written += int64(len(index))
|
||||
}
|
||||
if true {
|
||||
_, err := w.index.Load(index)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if w.pad > 1 {
|
||||
tmp := w.ibuf[:0]
|
||||
if len(index) > 0 {
|
||||
// Allocate another buffer.
|
||||
tmp = w.buffers.Get().([]byte)[:0]
|
||||
defer w.buffers.Put(tmp)
|
||||
}
|
||||
add := calcSkippableFrame(w.written, int64(w.pad))
|
||||
frame, err := skippableFrame(tmp, add, w.randSrc)
|
||||
if err = w.err(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
n, err2 := w.writer.Write(frame)
|
||||
if err2 == nil && n != len(frame) {
|
||||
err2 = io.ErrShortWrite
|
||||
}
|
||||
_ = w.err(err2)
|
||||
}
|
||||
if len(index) > 0 && w.appendIndex {
|
||||
n, err2 := w.writer.Write(index)
|
||||
if err2 == nil && n != len(index) {
|
||||
err2 = io.ErrShortWrite
|
||||
}
|
||||
_ = w.err(err2)
|
||||
}
|
||||
}
|
||||
err = w.err(errClosed)
|
||||
if err == errClosed {
|
||||
return index, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// calcSkippableFrame will return a total size to be added for written
|
||||
// to be divisible by multiple.
|
||||
@@ -1057,6 +1223,15 @@ func WriterConcurrency(n int) WriterOption {
|
||||
}
|
||||
}
|
||||
|
||||
// WriterAddIndex will append an index to the end of a stream
|
||||
// when it is closed.
|
||||
func WriterAddIndex() WriterOption {
|
||||
return func(w *Writer) error {
|
||||
w.appendIndex = true
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// WriterBetterCompression will enable better compression.
|
||||
// EncodeBetter compresses better than Encode but typically with a
|
||||
// 10-40% speed decrease on both compression and decompression.
|
||||
|
||||
525
vendor/github.com/klauspost/compress/s2/index.go
сгенерированный
поставляемый
Обычный файл
525
vendor/github.com/klauspost/compress/s2/index.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,525 @@
|
||||
// Copyright (c) 2022+ Klaus Post. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package s2
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
const (
|
||||
S2IndexHeader = "s2idx\x00"
|
||||
S2IndexTrailer = "\x00xdi2s"
|
||||
maxIndexEntries = 1 << 16
|
||||
)
|
||||
|
||||
// Index represents an S2/Snappy index.
|
||||
type Index struct {
|
||||
TotalUncompressed int64 // Total Uncompressed size if known. Will be -1 if unknown.
|
||||
TotalCompressed int64 // Total Compressed size if known. Will be -1 if unknown.
|
||||
info []struct {
|
||||
compressedOffset int64
|
||||
uncompressedOffset int64
|
||||
}
|
||||
estBlockUncomp int64
|
||||
}
|
||||
|
||||
func (i *Index) reset(maxBlock int) {
|
||||
i.estBlockUncomp = int64(maxBlock)
|
||||
i.TotalCompressed = -1
|
||||
i.TotalUncompressed = -1
|
||||
if len(i.info) > 0 {
|
||||
i.info = i.info[:0]
|
||||
}
|
||||
}
|
||||
|
||||
// allocInfos will allocate an empty slice of infos.
|
||||
func (i *Index) allocInfos(n int) {
|
||||
if n > maxIndexEntries {
|
||||
panic("n > maxIndexEntries")
|
||||
}
|
||||
i.info = make([]struct {
|
||||
compressedOffset int64
|
||||
uncompressedOffset int64
|
||||
}, 0, n)
|
||||
}
|
||||
|
||||
// add an uncompressed and compressed pair.
|
||||
// Entries must be sent in order.
|
||||
func (i *Index) add(compressedOffset, uncompressedOffset int64) error {
|
||||
if i == nil {
|
||||
return nil
|
||||
}
|
||||
lastIdx := len(i.info) - 1
|
||||
if lastIdx >= 0 {
|
||||
latest := i.info[lastIdx]
|
||||
if latest.uncompressedOffset == uncompressedOffset {
|
||||
// Uncompressed didn't change, don't add entry,
|
||||
// but update start index.
|
||||
latest.compressedOffset = compressedOffset
|
||||
i.info[lastIdx] = latest
|
||||
return nil
|
||||
}
|
||||
if latest.uncompressedOffset > uncompressedOffset {
|
||||
return fmt.Errorf("internal error: Earlier uncompressed received (%d > %d)", latest.uncompressedOffset, uncompressedOffset)
|
||||
}
|
||||
if latest.compressedOffset > compressedOffset {
|
||||
return fmt.Errorf("internal error: Earlier compressed received (%d > %d)", latest.uncompressedOffset, uncompressedOffset)
|
||||
}
|
||||
}
|
||||
i.info = append(i.info, struct {
|
||||
compressedOffset int64
|
||||
uncompressedOffset int64
|
||||
}{compressedOffset: compressedOffset, uncompressedOffset: uncompressedOffset})
|
||||
return nil
|
||||
}
|
||||
|
||||
// Find the offset at or before the wanted (uncompressed) offset.
|
||||
// If offset is 0 or positive it is the offset from the beginning of the file.
|
||||
// If the uncompressed size is known, the offset must be within the file.
|
||||
// If an offset outside the file is requested io.ErrUnexpectedEOF is returned.
|
||||
// If the offset is negative, it is interpreted as the distance from the end of the file,
|
||||
// where -1 represents the last byte.
|
||||
// If offset from the end of the file is requested, but size is unknown,
|
||||
// ErrUnsupported will be returned.
|
||||
func (i *Index) Find(offset int64) (compressedOff, uncompressedOff int64, err error) {
|
||||
if i.TotalUncompressed < 0 {
|
||||
return 0, 0, ErrCorrupt
|
||||
}
|
||||
if offset < 0 {
|
||||
offset = i.TotalUncompressed + offset
|
||||
if offset < 0 {
|
||||
return 0, 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
}
|
||||
if offset > i.TotalUncompressed {
|
||||
return 0, 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
for _, info := range i.info {
|
||||
if info.uncompressedOffset > offset {
|
||||
break
|
||||
}
|
||||
compressedOff = info.compressedOffset
|
||||
uncompressedOff = info.uncompressedOffset
|
||||
}
|
||||
return compressedOff, uncompressedOff, nil
|
||||
}
|
||||
|
||||
// reduce to stay below maxIndexEntries
|
||||
func (i *Index) reduce() {
|
||||
if len(i.info) < maxIndexEntries && i.estBlockUncomp >= 1<<20 {
|
||||
return
|
||||
}
|
||||
|
||||
// Algorithm, keep 1, remove removeN entries...
|
||||
removeN := (len(i.info) + 1) / maxIndexEntries
|
||||
src := i.info
|
||||
j := 0
|
||||
|
||||
// Each block should be at least 1MB, but don't reduce below 1000 entries.
|
||||
for i.estBlockUncomp*(int64(removeN)+1) < 1<<20 && len(i.info)/(removeN+1) > 1000 {
|
||||
removeN++
|
||||
}
|
||||
for idx := 0; idx < len(src); idx++ {
|
||||
i.info[j] = src[idx]
|
||||
j++
|
||||
idx += removeN
|
||||
}
|
||||
i.info = i.info[:j]
|
||||
// Update maxblock estimate.
|
||||
i.estBlockUncomp += i.estBlockUncomp * int64(removeN)
|
||||
}
|
||||
|
||||
func (i *Index) appendTo(b []byte, uncompTotal, compTotal int64) []byte {
|
||||
i.reduce()
|
||||
var tmp [binary.MaxVarintLen64]byte
|
||||
|
||||
initSize := len(b)
|
||||
// We make the start a skippable header+size.
|
||||
b = append(b, ChunkTypeIndex, 0, 0, 0)
|
||||
b = append(b, []byte(S2IndexHeader)...)
|
||||
// Total Uncompressed size
|
||||
n := binary.PutVarint(tmp[:], uncompTotal)
|
||||
b = append(b, tmp[:n]...)
|
||||
// Total Compressed size
|
||||
n = binary.PutVarint(tmp[:], compTotal)
|
||||
b = append(b, tmp[:n]...)
|
||||
// Put EstBlockUncomp size
|
||||
n = binary.PutVarint(tmp[:], i.estBlockUncomp)
|
||||
b = append(b, tmp[:n]...)
|
||||
// Put length
|
||||
n = binary.PutVarint(tmp[:], int64(len(i.info)))
|
||||
b = append(b, tmp[:n]...)
|
||||
|
||||
// Check if we should add uncompressed offsets
|
||||
var hasUncompressed byte
|
||||
for idx, info := range i.info {
|
||||
if idx == 0 {
|
||||
if info.uncompressedOffset != 0 {
|
||||
hasUncompressed = 1
|
||||
break
|
||||
}
|
||||
continue
|
||||
}
|
||||
if info.uncompressedOffset != i.info[idx-1].uncompressedOffset+i.estBlockUncomp {
|
||||
hasUncompressed = 1
|
||||
break
|
||||
}
|
||||
}
|
||||
b = append(b, hasUncompressed)
|
||||
|
||||
// Add each entry
|
||||
if hasUncompressed == 1 {
|
||||
for idx, info := range i.info {
|
||||
uOff := info.uncompressedOffset
|
||||
if idx > 0 {
|
||||
prev := i.info[idx-1]
|
||||
uOff -= prev.uncompressedOffset + (i.estBlockUncomp)
|
||||
}
|
||||
n = binary.PutVarint(tmp[:], uOff)
|
||||
b = append(b, tmp[:n]...)
|
||||
}
|
||||
}
|
||||
|
||||
// Initial compressed size estimate.
|
||||
cPredict := i.estBlockUncomp / 2
|
||||
|
||||
for idx, info := range i.info {
|
||||
cOff := info.compressedOffset
|
||||
if idx > 0 {
|
||||
prev := i.info[idx-1]
|
||||
cOff -= prev.compressedOffset + cPredict
|
||||
// Update compressed size prediction, with half the error.
|
||||
cPredict += cOff / 2
|
||||
}
|
||||
n = binary.PutVarint(tmp[:], cOff)
|
||||
b = append(b, tmp[:n]...)
|
||||
}
|
||||
|
||||
// Add Total Size.
|
||||
// Stored as fixed size for easier reading.
|
||||
binary.LittleEndian.PutUint32(tmp[:], uint32(len(b)-initSize+4+len(S2IndexTrailer)))
|
||||
b = append(b, tmp[:4]...)
|
||||
// Trailer
|
||||
b = append(b, []byte(S2IndexTrailer)...)
|
||||
|
||||
// Update size
|
||||
chunkLen := len(b) - initSize - skippableFrameHeader
|
||||
b[initSize+1] = uint8(chunkLen >> 0)
|
||||
b[initSize+2] = uint8(chunkLen >> 8)
|
||||
b[initSize+3] = uint8(chunkLen >> 16)
|
||||
//fmt.Printf("chunklen: 0x%x Uncomp:%d, Comp:%d\n", chunkLen, uncompTotal, compTotal)
|
||||
return b
|
||||
}
|
||||
|
||||
// Load a binary index.
|
||||
// A zero value Index can be used or a previous one can be reused.
|
||||
func (i *Index) Load(b []byte) ([]byte, error) {
|
||||
if len(b) <= 4+len(S2IndexHeader)+len(S2IndexTrailer) {
|
||||
return b, io.ErrUnexpectedEOF
|
||||
}
|
||||
if b[0] != ChunkTypeIndex {
|
||||
return b, ErrCorrupt
|
||||
}
|
||||
chunkLen := int(b[1]) | int(b[2])<<8 | int(b[3])<<16
|
||||
b = b[4:]
|
||||
|
||||
// Validate we have enough...
|
||||
if len(b) < chunkLen {
|
||||
return b, io.ErrUnexpectedEOF
|
||||
}
|
||||
if !bytes.Equal(b[:len(S2IndexHeader)], []byte(S2IndexHeader)) {
|
||||
return b, ErrUnsupported
|
||||
}
|
||||
b = b[len(S2IndexHeader):]
|
||||
|
||||
// Total Uncompressed
|
||||
if v, n := binary.Varint(b); n <= 0 || v < 0 {
|
||||
return b, ErrCorrupt
|
||||
} else {
|
||||
i.TotalUncompressed = v
|
||||
b = b[n:]
|
||||
}
|
||||
|
||||
// Total Compressed
|
||||
if v, n := binary.Varint(b); n <= 0 {
|
||||
return b, ErrCorrupt
|
||||
} else {
|
||||
i.TotalCompressed = v
|
||||
b = b[n:]
|
||||
}
|
||||
|
||||
// Read EstBlockUncomp
|
||||
if v, n := binary.Varint(b); n <= 0 {
|
||||
return b, ErrCorrupt
|
||||
} else {
|
||||
if v < 0 {
|
||||
return b, ErrCorrupt
|
||||
}
|
||||
i.estBlockUncomp = v
|
||||
b = b[n:]
|
||||
}
|
||||
|
||||
var entries int
|
||||
if v, n := binary.Varint(b); n <= 0 {
|
||||
return b, ErrCorrupt
|
||||
} else {
|
||||
if v < 0 || v > maxIndexEntries {
|
||||
return b, ErrCorrupt
|
||||
}
|
||||
entries = int(v)
|
||||
b = b[n:]
|
||||
}
|
||||
if cap(i.info) < entries {
|
||||
i.allocInfos(entries)
|
||||
}
|
||||
i.info = i.info[:entries]
|
||||
|
||||
if len(b) < 1 {
|
||||
return b, io.ErrUnexpectedEOF
|
||||
}
|
||||
hasUncompressed := b[0]
|
||||
b = b[1:]
|
||||
if hasUncompressed&1 != hasUncompressed {
|
||||
return b, ErrCorrupt
|
||||
}
|
||||
|
||||
// Add each uncompressed entry
|
||||
for idx := range i.info {
|
||||
var uOff int64
|
||||
if hasUncompressed != 0 {
|
||||
// Load delta
|
||||
if v, n := binary.Varint(b); n <= 0 {
|
||||
return b, ErrCorrupt
|
||||
} else {
|
||||
uOff = v
|
||||
b = b[n:]
|
||||
}
|
||||
}
|
||||
|
||||
if idx > 0 {
|
||||
prev := i.info[idx-1].uncompressedOffset
|
||||
uOff += prev + (i.estBlockUncomp)
|
||||
if uOff <= prev {
|
||||
return b, ErrCorrupt
|
||||
}
|
||||
}
|
||||
if uOff < 0 {
|
||||
return b, ErrCorrupt
|
||||
}
|
||||
i.info[idx].uncompressedOffset = uOff
|
||||
}
|
||||
|
||||
// Initial compressed size estimate.
|
||||
cPredict := i.estBlockUncomp / 2
|
||||
|
||||
// Add each compressed entry
|
||||
for idx := range i.info {
|
||||
var cOff int64
|
||||
if v, n := binary.Varint(b); n <= 0 {
|
||||
return b, ErrCorrupt
|
||||
} else {
|
||||
cOff = v
|
||||
b = b[n:]
|
||||
}
|
||||
|
||||
if idx > 0 {
|
||||
// Update compressed size prediction, with half the error.
|
||||
cPredictNew := cPredict + cOff/2
|
||||
|
||||
prev := i.info[idx-1].compressedOffset
|
||||
cOff += prev + cPredict
|
||||
if cOff <= prev {
|
||||
return b, ErrCorrupt
|
||||
}
|
||||
cPredict = cPredictNew
|
||||
}
|
||||
if cOff < 0 {
|
||||
return b, ErrCorrupt
|
||||
}
|
||||
i.info[idx].compressedOffset = cOff
|
||||
}
|
||||
if len(b) < 4+len(S2IndexTrailer) {
|
||||
return b, io.ErrUnexpectedEOF
|
||||
}
|
||||
// Skip size...
|
||||
b = b[4:]
|
||||
|
||||
// Check trailer...
|
||||
if !bytes.Equal(b[:len(S2IndexTrailer)], []byte(S2IndexTrailer)) {
|
||||
return b, ErrCorrupt
|
||||
}
|
||||
return b[len(S2IndexTrailer):], nil
|
||||
}
|
||||
|
||||
// LoadStream will load an index from the end of the supplied stream.
|
||||
// ErrUnsupported will be returned if the signature cannot be found.
|
||||
// ErrCorrupt will be returned if unexpected values are found.
|
||||
// io.ErrUnexpectedEOF is returned if there are too few bytes.
|
||||
// IO errors are returned as-is.
|
||||
func (i *Index) LoadStream(rs io.ReadSeeker) error {
|
||||
// Go to end.
|
||||
_, err := rs.Seek(-10, io.SeekEnd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var tmp [10]byte
|
||||
_, err = io.ReadFull(rs, tmp[:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Check trailer...
|
||||
if !bytes.Equal(tmp[4:4+len(S2IndexTrailer)], []byte(S2IndexTrailer)) {
|
||||
return ErrUnsupported
|
||||
}
|
||||
sz := binary.LittleEndian.Uint32(tmp[:4])
|
||||
if sz > maxChunkSize+skippableFrameHeader {
|
||||
return ErrCorrupt
|
||||
}
|
||||
_, err = rs.Seek(-int64(sz), io.SeekEnd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Read index.
|
||||
buf := make([]byte, sz)
|
||||
_, err = io.ReadFull(rs, buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = i.Load(buf)
|
||||
return err
|
||||
}
|
||||
|
||||
// IndexStream will return an index for a stream.
|
||||
// The stream structure will be checked, but
|
||||
// data within blocks is not verified.
|
||||
// The returned index can either be appended to the end of the stream
|
||||
// or stored separately.
|
||||
func IndexStream(r io.Reader) ([]byte, error) {
|
||||
var i Index
|
||||
var buf [maxChunkSize]byte
|
||||
var readHeader bool
|
||||
for {
|
||||
_, err := io.ReadFull(r, buf[:4])
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
return i.appendTo(nil, i.TotalUncompressed, i.TotalCompressed), nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
// Start of this chunk.
|
||||
startChunk := i.TotalCompressed
|
||||
i.TotalCompressed += 4
|
||||
|
||||
chunkType := buf[0]
|
||||
if !readHeader {
|
||||
if chunkType != chunkTypeStreamIdentifier {
|
||||
return nil, ErrCorrupt
|
||||
}
|
||||
readHeader = true
|
||||
}
|
||||
chunkLen := int(buf[1]) | int(buf[2])<<8 | int(buf[3])<<16
|
||||
if chunkLen < checksumSize {
|
||||
return nil, ErrCorrupt
|
||||
}
|
||||
|
||||
i.TotalCompressed += int64(chunkLen)
|
||||
_, err = io.ReadFull(r, buf[:chunkLen])
|
||||
if err != nil {
|
||||
return nil, io.ErrUnexpectedEOF
|
||||
}
|
||||
// The chunk types are specified at
|
||||
// https://github.com/google/snappy/blob/master/framing_format.txt
|
||||
switch chunkType {
|
||||
case chunkTypeCompressedData:
|
||||
// Section 4.2. Compressed data (chunk type 0x00).
|
||||
// Skip checksum.
|
||||
dLen, err := DecodedLen(buf[checksumSize:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if dLen > maxBlockSize {
|
||||
return nil, ErrCorrupt
|
||||
}
|
||||
if i.estBlockUncomp == 0 {
|
||||
// Use first block for estimate...
|
||||
i.estBlockUncomp = int64(dLen)
|
||||
}
|
||||
err = i.add(startChunk, i.TotalUncompressed)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
i.TotalUncompressed += int64(dLen)
|
||||
continue
|
||||
case chunkTypeUncompressedData:
|
||||
n2 := chunkLen - checksumSize
|
||||
if n2 > maxBlockSize {
|
||||
return nil, ErrCorrupt
|
||||
}
|
||||
if i.estBlockUncomp == 0 {
|
||||
// Use first block for estimate...
|
||||
i.estBlockUncomp = int64(n2)
|
||||
}
|
||||
err = i.add(startChunk, i.TotalUncompressed)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
i.TotalUncompressed += int64(n2)
|
||||
continue
|
||||
case chunkTypeStreamIdentifier:
|
||||
// Section 4.1. Stream identifier (chunk type 0xff).
|
||||
if chunkLen != len(magicBody) {
|
||||
return nil, ErrCorrupt
|
||||
}
|
||||
|
||||
if string(buf[:len(magicBody)]) != magicBody {
|
||||
if string(buf[:len(magicBody)]) != magicBodySnappy {
|
||||
return nil, ErrCorrupt
|
||||
}
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
if chunkType <= 0x7f {
|
||||
// Section 4.5. Reserved unskippable chunks (chunk types 0x02-0x7f).
|
||||
return nil, ErrUnsupported
|
||||
}
|
||||
if chunkLen > maxChunkSize {
|
||||
return nil, ErrUnsupported
|
||||
}
|
||||
// Section 4.4 Padding (chunk type 0xfe).
|
||||
// Section 4.6. Reserved skippable chunks (chunk types 0x80-0xfd).
|
||||
}
|
||||
}
|
||||
|
||||
// JSON returns the index as JSON text.
|
||||
func (i *Index) JSON() []byte {
|
||||
x := struct {
|
||||
TotalUncompressed int64 `json:"total_uncompressed"` // Total Uncompressed size if known. Will be -1 if unknown.
|
||||
TotalCompressed int64 `json:"total_compressed"` // Total Compressed size if known. Will be -1 if unknown.
|
||||
Offsets []struct {
|
||||
CompressedOffset int64 `json:"compressed"`
|
||||
UncompressedOffset int64 `json:"uncompressed"`
|
||||
} `json:"offsets"`
|
||||
EstBlockUncomp int64 `json:"est_block_uncompressed"`
|
||||
}{
|
||||
TotalUncompressed: i.TotalUncompressed,
|
||||
TotalCompressed: i.TotalCompressed,
|
||||
EstBlockUncomp: i.estBlockUncomp,
|
||||
}
|
||||
for _, v := range i.info {
|
||||
x.Offsets = append(x.Offsets, struct {
|
||||
CompressedOffset int64 `json:"compressed"`
|
||||
UncompressedOffset int64 `json:"uncompressed"`
|
||||
}{CompressedOffset: v.compressedOffset, UncompressedOffset: v.uncompressedOffset})
|
||||
}
|
||||
b, _ := json.MarshalIndent(x, "", " ")
|
||||
return b
|
||||
}
|
||||
4
vendor/github.com/klauspost/compress/s2/s2.go
сгенерированный
поставляемый
4
vendor/github.com/klauspost/compress/s2/s2.go
сгенерированный
поставляемый
@@ -87,6 +87,9 @@ const (
|
||||
// minBlockSize is the minimum size of block setting when creating a writer.
|
||||
minBlockSize = 4 << 10
|
||||
|
||||
skippableFrameHeader = 4
|
||||
maxChunkSize = 1<<24 - 1 // 16777215
|
||||
|
||||
// Default block size
|
||||
defaultBlockSize = 1 << 20
|
||||
|
||||
@@ -99,6 +102,7 @@ const (
|
||||
const (
|
||||
chunkTypeCompressedData = 0x00
|
||||
chunkTypeUncompressedData = 0x01
|
||||
ChunkTypeIndex = 0x99
|
||||
chunkTypePadding = 0xfe
|
||||
chunkTypeStreamIdentifier = 0xff
|
||||
)
|
||||
|
||||
15
vendor/github.com/klauspost/compress/zstd/bitreader.go
сгенерированный
поставляемый
15
vendor/github.com/klauspost/compress/zstd/bitreader.go
сгенерированный
поставляемый
@@ -50,16 +50,23 @@ func (b *bitReader) getBits(n uint8) int {
|
||||
if n == 0 /*|| b.bitsRead >= 64 */ {
|
||||
return 0
|
||||
}
|
||||
return b.getBitsFast(n)
|
||||
return int(b.get32BitsFast(n))
|
||||
}
|
||||
|
||||
// getBitsFast requires that at least one bit is requested every time.
|
||||
// get32BitsFast requires that at least one bit is requested every time.
|
||||
// There are no checks if the buffer is filled.
|
||||
func (b *bitReader) getBitsFast(n uint8) int {
|
||||
func (b *bitReader) get32BitsFast(n uint8) uint32 {
|
||||
const regMask = 64 - 1
|
||||
v := uint32((b.value << (b.bitsRead & regMask)) >> ((regMask + 1 - n) & regMask))
|
||||
b.bitsRead += n
|
||||
return int(v)
|
||||
return v
|
||||
}
|
||||
|
||||
func (b *bitReader) get16BitsFast(n uint8) uint16 {
|
||||
const regMask = 64 - 1
|
||||
v := uint16((b.value << (b.bitsRead & regMask)) >> ((regMask + 1 - n) & regMask))
|
||||
b.bitsRead += n
|
||||
return v
|
||||
}
|
||||
|
||||
// fillFast() will make sure at least 32 bits are available.
|
||||
|
||||
22
vendor/github.com/klauspost/compress/zstd/bitwriter.go
сгенерированный
поставляемый
22
vendor/github.com/klauspost/compress/zstd/bitwriter.go
сгенерированный
поставляемый
@@ -38,7 +38,7 @@ func (b *bitWriter) addBits16NC(value uint16, bits uint8) {
|
||||
b.nBits += bits
|
||||
}
|
||||
|
||||
// addBits32NC will add up to 32 bits.
|
||||
// addBits32NC will add up to 31 bits.
|
||||
// It will not check if there is space for them,
|
||||
// so the caller must ensure that it has flushed recently.
|
||||
func (b *bitWriter) addBits32NC(value uint32, bits uint8) {
|
||||
@@ -46,6 +46,26 @@ func (b *bitWriter) addBits32NC(value uint32, bits uint8) {
|
||||
b.nBits += bits
|
||||
}
|
||||
|
||||
// addBits64NC will add up to 64 bits.
|
||||
// There must be space for 32 bits.
|
||||
func (b *bitWriter) addBits64NC(value uint64, bits uint8) {
|
||||
if bits <= 31 {
|
||||
b.addBits32Clean(uint32(value), bits)
|
||||
return
|
||||
}
|
||||
b.addBits32Clean(uint32(value), 32)
|
||||
b.flush32()
|
||||
b.addBits32Clean(uint32(value>>32), bits-32)
|
||||
}
|
||||
|
||||
// addBits32Clean will add up to 32 bits.
|
||||
// It will not check if there is space for them.
|
||||
// The input must not contain more bits than specified.
|
||||
func (b *bitWriter) addBits32Clean(value uint32, bits uint8) {
|
||||
b.bitContainer |= uint64(value) << (b.nBits & 63)
|
||||
b.nBits += bits
|
||||
}
|
||||
|
||||
// addBits16Clean will add up to 16 bits. value may not contain more set bits than indicated.
|
||||
// It will not check if there is space for them, so the caller must ensure that it has flushed recently.
|
||||
func (b *bitWriter) addBits16Clean(value uint16, bits uint8) {
|
||||
|
||||
24
vendor/github.com/klauspost/compress/zstd/blockdec.go
сгенерированный
поставляемый
24
vendor/github.com/klauspost/compress/zstd/blockdec.go
сгенерированный
поставляемый
@@ -76,12 +76,11 @@ type blockDec struct {
|
||||
// Window size of the block.
|
||||
WindowSize uint64
|
||||
|
||||
history chan *history
|
||||
input chan struct{}
|
||||
result chan decodeOutput
|
||||
sequenceBuf []seq
|
||||
err error
|
||||
decWG sync.WaitGroup
|
||||
history chan *history
|
||||
input chan struct{}
|
||||
result chan decodeOutput
|
||||
err error
|
||||
decWG sync.WaitGroup
|
||||
|
||||
// Frame to use for singlethreaded decoding.
|
||||
// Should not be used by the decoder itself since parent may be another frame.
|
||||
@@ -512,18 +511,7 @@ func (b *blockDec) decodeCompressed(hist *history) error {
|
||||
nSeqs = 0x7f00 + int(in[1]) + (int(in[2]) << 8)
|
||||
in = in[3:]
|
||||
}
|
||||
// Allocate sequences
|
||||
if cap(b.sequenceBuf) < nSeqs {
|
||||
if b.lowMem {
|
||||
b.sequenceBuf = make([]seq, nSeqs)
|
||||
} else {
|
||||
// Allocate max
|
||||
b.sequenceBuf = make([]seq, nSeqs, maxSequences)
|
||||
}
|
||||
} else {
|
||||
// Reuse buffer
|
||||
b.sequenceBuf = b.sequenceBuf[:nSeqs]
|
||||
}
|
||||
|
||||
var seqs = &sequenceDecs{}
|
||||
if nSeqs > 0 {
|
||||
if len(in) < 1 {
|
||||
|
||||
98
vendor/github.com/klauspost/compress/zstd/blockenc.go
сгенерированный
поставляемый
98
vendor/github.com/klauspost/compress/zstd/blockenc.go
сгенерированный
поставляемый
@@ -51,7 +51,7 @@ func (b *blockEnc) init() {
|
||||
if cap(b.literals) < maxCompressedBlockSize {
|
||||
b.literals = make([]byte, 0, maxCompressedBlockSize)
|
||||
}
|
||||
const defSeqs = 200
|
||||
const defSeqs = 2000
|
||||
if cap(b.sequences) < defSeqs {
|
||||
b.sequences = make([]seq, 0, defSeqs)
|
||||
}
|
||||
@@ -426,7 +426,7 @@ func fuzzFseEncoder(data []byte) int {
|
||||
return 0
|
||||
}
|
||||
enc := fseEncoder{}
|
||||
hist := enc.Histogram()[:256]
|
||||
hist := enc.Histogram()
|
||||
maxSym := uint8(0)
|
||||
for i, v := range data {
|
||||
v = v & 63
|
||||
@@ -722,52 +722,53 @@ func (b *blockEnc) encode(org []byte, raw, rawAllLits bool) error {
|
||||
println("Encoded seq", seq, s, "codes:", s.llCode, s.mlCode, s.ofCode, "states:", ll.state, ml.state, of.state, "bits:", llB, mlB, ofB)
|
||||
}
|
||||
seq--
|
||||
if llEnc.maxBits+mlEnc.maxBits+ofEnc.maxBits <= 32 {
|
||||
// No need to flush (common)
|
||||
for seq >= 0 {
|
||||
s = b.sequences[seq]
|
||||
wr.flush32()
|
||||
llB, ofB, mlB := llTT[s.llCode], ofTT[s.ofCode], mlTT[s.mlCode]
|
||||
// tabelog max is 8 for all.
|
||||
of.encode(ofB)
|
||||
ml.encode(mlB)
|
||||
ll.encode(llB)
|
||||
wr.flush32()
|
||||
// Store sequences in reverse...
|
||||
for seq >= 0 {
|
||||
s = b.sequences[seq]
|
||||
|
||||
// We checked that all can stay within 32 bits
|
||||
wr.addBits32NC(s.litLen, llB.outBits)
|
||||
wr.addBits32NC(s.matchLen, mlB.outBits)
|
||||
wr.addBits32NC(s.offset, ofB.outBits)
|
||||
ofB := ofTT[s.ofCode]
|
||||
wr.flush32() // tablelog max is below 8 for each, so it will fill max 24 bits.
|
||||
//of.encode(ofB)
|
||||
nbBitsOut := (uint32(of.state) + ofB.deltaNbBits) >> 16
|
||||
dstState := int32(of.state>>(nbBitsOut&15)) + int32(ofB.deltaFindState)
|
||||
wr.addBits16NC(of.state, uint8(nbBitsOut))
|
||||
of.state = of.stateTable[dstState]
|
||||
|
||||
if debugSequences {
|
||||
println("Encoded seq", seq, s)
|
||||
}
|
||||
// Accumulate extra bits.
|
||||
outBits := ofB.outBits & 31
|
||||
extraBits := uint64(s.offset & bitMask32[outBits])
|
||||
extraBitsN := outBits
|
||||
|
||||
seq--
|
||||
mlB := mlTT[s.mlCode]
|
||||
//ml.encode(mlB)
|
||||
nbBitsOut = (uint32(ml.state) + mlB.deltaNbBits) >> 16
|
||||
dstState = int32(ml.state>>(nbBitsOut&15)) + int32(mlB.deltaFindState)
|
||||
wr.addBits16NC(ml.state, uint8(nbBitsOut))
|
||||
ml.state = ml.stateTable[dstState]
|
||||
|
||||
outBits = mlB.outBits & 31
|
||||
extraBits = extraBits<<outBits | uint64(s.matchLen&bitMask32[outBits])
|
||||
extraBitsN += outBits
|
||||
|
||||
llB := llTT[s.llCode]
|
||||
//ll.encode(llB)
|
||||
nbBitsOut = (uint32(ll.state) + llB.deltaNbBits) >> 16
|
||||
dstState = int32(ll.state>>(nbBitsOut&15)) + int32(llB.deltaFindState)
|
||||
wr.addBits16NC(ll.state, uint8(nbBitsOut))
|
||||
ll.state = ll.stateTable[dstState]
|
||||
|
||||
outBits = llB.outBits & 31
|
||||
extraBits = extraBits<<outBits | uint64(s.litLen&bitMask32[outBits])
|
||||
extraBitsN += outBits
|
||||
|
||||
wr.flush32()
|
||||
wr.addBits64NC(extraBits, extraBitsN)
|
||||
|
||||
if debugSequences {
|
||||
println("Encoded seq", seq, s)
|
||||
}
|
||||
} else {
|
||||
for seq >= 0 {
|
||||
s = b.sequences[seq]
|
||||
wr.flush32()
|
||||
llB, ofB, mlB := llTT[s.llCode], ofTT[s.ofCode], mlTT[s.mlCode]
|
||||
// tabelog max is below 8 for each.
|
||||
of.encode(ofB)
|
||||
ml.encode(mlB)
|
||||
ll.encode(llB)
|
||||
wr.flush32()
|
||||
|
||||
// ml+ll = max 32 bits total
|
||||
wr.addBits32NC(s.litLen, llB.outBits)
|
||||
wr.addBits32NC(s.matchLen, mlB.outBits)
|
||||
wr.flush32()
|
||||
wr.addBits32NC(s.offset, ofB.outBits)
|
||||
|
||||
if debugSequences {
|
||||
println("Encoded seq", seq, s)
|
||||
}
|
||||
|
||||
seq--
|
||||
}
|
||||
seq--
|
||||
}
|
||||
ml.flush(mlEnc.actualTableLog)
|
||||
of.flush(ofEnc.actualTableLog)
|
||||
@@ -801,14 +802,13 @@ func (b *blockEnc) genCodes() {
|
||||
// nothing to do
|
||||
return
|
||||
}
|
||||
|
||||
if len(b.sequences) > math.MaxUint16 {
|
||||
panic("can only encode up to 64K sequences")
|
||||
}
|
||||
// No bounds checks after here:
|
||||
llH := b.coders.llEnc.Histogram()[:256]
|
||||
ofH := b.coders.ofEnc.Histogram()[:256]
|
||||
mlH := b.coders.mlEnc.Histogram()[:256]
|
||||
llH := b.coders.llEnc.Histogram()
|
||||
ofH := b.coders.ofEnc.Histogram()
|
||||
mlH := b.coders.mlEnc.Histogram()
|
||||
for i := range llH {
|
||||
llH[i] = 0
|
||||
}
|
||||
@@ -820,7 +820,8 @@ func (b *blockEnc) genCodes() {
|
||||
}
|
||||
|
||||
var llMax, ofMax, mlMax uint8
|
||||
for i, seq := range b.sequences {
|
||||
for i := range b.sequences {
|
||||
seq := &b.sequences[i]
|
||||
v := llCode(seq.litLen)
|
||||
seq.llCode = v
|
||||
llH[v]++
|
||||
@@ -844,7 +845,6 @@ func (b *blockEnc) genCodes() {
|
||||
panic(fmt.Errorf("mlMax > maxMatchLengthSymbol (%d), matchlen: %d", mlMax, seq.matchLen))
|
||||
}
|
||||
}
|
||||
b.sequences[i] = seq
|
||||
}
|
||||
maxCount := func(a []uint32) int {
|
||||
var max uint32
|
||||
|
||||
98
vendor/github.com/klauspost/compress/zstd/decodeheader.go
сгенерированный
поставляемый
98
vendor/github.com/klauspost/compress/zstd/decodeheader.go
сгенерированный
поставляемый
@@ -5,6 +5,7 @@ package zstd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"io"
|
||||
)
|
||||
@@ -15,18 +16,50 @@ const HeaderMaxSize = 14 + 3
|
||||
|
||||
// Header contains information about the first frame and block within that.
|
||||
type Header struct {
|
||||
// Window Size the window of data to keep while decoding.
|
||||
// Will only be set if HasFCS is false.
|
||||
WindowSize uint64
|
||||
// SingleSegment specifies whether the data is to be decompressed into a
|
||||
// single contiguous memory segment.
|
||||
// It implies that WindowSize is invalid and that FrameContentSize is valid.
|
||||
SingleSegment bool
|
||||
|
||||
// Frame content size.
|
||||
// Expected size of the entire frame.
|
||||
FrameContentSize uint64
|
||||
// WindowSize is the window of data to keep while decoding.
|
||||
// Will only be set if SingleSegment is false.
|
||||
WindowSize uint64
|
||||
|
||||
// Dictionary ID.
|
||||
// If 0, no dictionary.
|
||||
DictionaryID uint32
|
||||
|
||||
// HasFCS specifies whether FrameContentSize has a valid value.
|
||||
HasFCS bool
|
||||
|
||||
// FrameContentSize is the expected uncompressed size of the entire frame.
|
||||
FrameContentSize uint64
|
||||
|
||||
// Skippable will be true if the frame is meant to be skipped.
|
||||
// This implies that FirstBlock.OK is false.
|
||||
Skippable bool
|
||||
|
||||
// SkippableID is the user-specific ID for the skippable frame.
|
||||
// Valid values are between 0 to 15, inclusive.
|
||||
SkippableID int
|
||||
|
||||
// SkippableSize is the length of the user data to skip following
|
||||
// the header.
|
||||
SkippableSize uint32
|
||||
|
||||
// HeaderSize is the raw size of the frame header.
|
||||
//
|
||||
// For normal frames, it includes the size of the magic number and
|
||||
// the size of the header (per section 3.1.1.1).
|
||||
// It does not include the size for any data blocks (section 3.1.1.2) nor
|
||||
// the size for the trailing content checksum.
|
||||
//
|
||||
// For skippable frames, this counts the size of the magic number
|
||||
// along with the size of the size field of the payload.
|
||||
// It does not include the size of the skippable payload itself.
|
||||
// The total frame size is the HeaderSize plus the SkippableSize.
|
||||
HeaderSize int
|
||||
|
||||
// First block information.
|
||||
FirstBlock struct {
|
||||
// OK will be set if first block could be decoded.
|
||||
@@ -51,17 +84,9 @@ type Header struct {
|
||||
CompressedSize int
|
||||
}
|
||||
|
||||
// Skippable will be true if the frame is meant to be skipped.
|
||||
// No other information will be populated.
|
||||
Skippable bool
|
||||
|
||||
// If set there is a checksum present for the block content.
|
||||
// The checksum field at the end is always 4 bytes long.
|
||||
HasCheckSum bool
|
||||
|
||||
// If this is true FrameContentSize will have a valid value
|
||||
HasFCS bool
|
||||
|
||||
SingleSegment bool
|
||||
}
|
||||
|
||||
// Decode the header from the beginning of the stream.
|
||||
@@ -71,39 +96,46 @@ type Header struct {
|
||||
// If there isn't enough input, io.ErrUnexpectedEOF is returned.
|
||||
// The FirstBlock.OK will indicate if enough information was available to decode the first block header.
|
||||
func (h *Header) Decode(in []byte) error {
|
||||
*h = Header{}
|
||||
if len(in) < 4 {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
h.HeaderSize += 4
|
||||
b, in := in[:4], in[4:]
|
||||
if !bytes.Equal(b, frameMagic) {
|
||||
if !bytes.Equal(b[1:4], skippableFrameMagic) || b[0]&0xf0 != 0x50 {
|
||||
return ErrMagicMismatch
|
||||
}
|
||||
*h = Header{Skippable: true}
|
||||
if len(in) < 4 {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
h.HeaderSize += 4
|
||||
h.Skippable = true
|
||||
h.SkippableID = int(b[0] & 0xf)
|
||||
h.SkippableSize = binary.LittleEndian.Uint32(in)
|
||||
return nil
|
||||
}
|
||||
if len(in) < 1 {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
|
||||
// Clear output
|
||||
*h = Header{}
|
||||
fhd, in := in[0], in[1:]
|
||||
h.SingleSegment = fhd&(1<<5) != 0
|
||||
h.HasCheckSum = fhd&(1<<2) != 0
|
||||
|
||||
if fhd&(1<<3) != 0 {
|
||||
return errors.New("reserved bit set on frame header")
|
||||
}
|
||||
|
||||
// Read Window_Descriptor
|
||||
// https://github.com/facebook/zstd/blob/dev/doc/zstd_compression_format.md#window_descriptor
|
||||
if len(in) < 1 {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
fhd, in := in[0], in[1:]
|
||||
h.HeaderSize++
|
||||
h.SingleSegment = fhd&(1<<5) != 0
|
||||
h.HasCheckSum = fhd&(1<<2) != 0
|
||||
if fhd&(1<<3) != 0 {
|
||||
return errors.New("reserved bit set on frame header")
|
||||
}
|
||||
|
||||
if !h.SingleSegment {
|
||||
if len(in) < 1 {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
var wd byte
|
||||
wd, in = in[0], in[1:]
|
||||
h.HeaderSize++
|
||||
windowLog := 10 + (wd >> 3)
|
||||
windowBase := uint64(1) << windowLog
|
||||
windowAdd := (windowBase / 8) * uint64(wd&0x7)
|
||||
@@ -120,9 +152,7 @@ func (h *Header) Decode(in []byte) error {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b, in = in[:size], in[size:]
|
||||
if b == nil {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
h.HeaderSize += int(size)
|
||||
switch size {
|
||||
case 1:
|
||||
h.DictionaryID = uint32(b[0])
|
||||
@@ -152,9 +182,7 @@ func (h *Header) Decode(in []byte) error {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b, in = in[:fcsSize], in[fcsSize:]
|
||||
if b == nil {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
h.HeaderSize += int(fcsSize)
|
||||
switch fcsSize {
|
||||
case 1:
|
||||
h.FrameContentSize = uint64(b[0])
|
||||
|
||||
24
vendor/github.com/klauspost/compress/zstd/enc_base.go
сгенерированный
поставляемый
24
vendor/github.com/klauspost/compress/zstd/enc_base.go
сгенерированный
поставляемый
@@ -108,11 +108,6 @@ func (e *fastBase) UseBlock(enc *blockEnc) {
|
||||
e.blk = enc
|
||||
}
|
||||
|
||||
func (e *fastBase) matchlenNoHist(s, t int32, src []byte) int32 {
|
||||
// Extend the match to be as long as possible.
|
||||
return int32(matchLen(src[s:], src[t:]))
|
||||
}
|
||||
|
||||
func (e *fastBase) matchlen(s, t int32, src []byte) int32 {
|
||||
if debugAsserts {
|
||||
if s < 0 {
|
||||
@@ -131,9 +126,24 @@ func (e *fastBase) matchlen(s, t int32, src []byte) int32 {
|
||||
panic(fmt.Sprintf("len(src)-s (%d) > maxCompressedBlockSize (%d)", len(src)-int(s), maxCompressedBlockSize))
|
||||
}
|
||||
}
|
||||
a := src[s:]
|
||||
b := src[t:]
|
||||
b = b[:len(a)]
|
||||
end := int32((len(a) >> 3) << 3)
|
||||
for i := int32(0); i < end; i += 8 {
|
||||
if diff := load6432(a, i) ^ load6432(b, i); diff != 0 {
|
||||
return i + int32(bits.TrailingZeros64(diff)>>3)
|
||||
}
|
||||
}
|
||||
|
||||
// Extend the match to be as long as possible.
|
||||
return int32(matchLen(src[s:], src[t:]))
|
||||
a = a[end:]
|
||||
b = b[end:]
|
||||
for i := range a {
|
||||
if a[i] != b[i] {
|
||||
return int32(i) + end
|
||||
}
|
||||
}
|
||||
return int32(len(a)) + end
|
||||
}
|
||||
|
||||
// Reset the encoding table.
|
||||
|
||||
139
vendor/github.com/klauspost/compress/zstd/enc_fast.go
сгенерированный
поставляемый
139
vendor/github.com/klauspost/compress/zstd/enc_fast.go
сгенерированный
поставляемый
@@ -6,8 +6,6 @@ package zstd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"math/bits"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -136,20 +134,7 @@ encodeLoop:
|
||||
// Consider history as well.
|
||||
var seq seq
|
||||
var length int32
|
||||
// length = 4 + e.matchlen(s+6, repIndex+4, src)
|
||||
{
|
||||
a := src[s+6:]
|
||||
b := src[repIndex+4:]
|
||||
endI := len(a) & (math.MaxInt32 - 7)
|
||||
length = int32(endI) + 4
|
||||
for i := 0; i < endI; i += 8 {
|
||||
if diff := load64(a, i) ^ load64(b, i); diff != 0 {
|
||||
length = int32(i+bits.TrailingZeros64(diff)>>3) + 4
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
length = 4 + e.matchlen(s+6, repIndex+4, src)
|
||||
seq.matchLen = uint32(length - zstdMinMatch)
|
||||
|
||||
// We might be able to match backwards.
|
||||
@@ -236,20 +221,7 @@ encodeLoop:
|
||||
}
|
||||
|
||||
// Extend the 4-byte match as long as possible.
|
||||
//l := e.matchlen(s+4, t+4, src) + 4
|
||||
var l int32
|
||||
{
|
||||
a := src[s+4:]
|
||||
b := src[t+4:]
|
||||
endI := len(a) & (math.MaxInt32 - 7)
|
||||
l = int32(endI) + 4
|
||||
for i := 0; i < endI; i += 8 {
|
||||
if diff := load64(a, i) ^ load64(b, i); diff != 0 {
|
||||
l = int32(i+bits.TrailingZeros64(diff)>>3) + 4
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
l := e.matchlen(s+4, t+4, src) + 4
|
||||
|
||||
// Extend backwards
|
||||
tMin := s - e.maxMatchOff
|
||||
@@ -286,20 +258,7 @@ encodeLoop:
|
||||
if o2 := s - offset2; canRepeat && load3232(src, o2) == uint32(cv) {
|
||||
// We have at least 4 byte match.
|
||||
// No need to check backwards. We come straight from a match
|
||||
//l := 4 + e.matchlen(s+4, o2+4, src)
|
||||
var l int32
|
||||
{
|
||||
a := src[s+4:]
|
||||
b := src[o2+4:]
|
||||
endI := len(a) & (math.MaxInt32 - 7)
|
||||
l = int32(endI) + 4
|
||||
for i := 0; i < endI; i += 8 {
|
||||
if diff := load64(a, i) ^ load64(b, i); diff != 0 {
|
||||
l = int32(i+bits.TrailingZeros64(diff)>>3) + 4
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
l := 4 + e.matchlen(s+4, o2+4, src)
|
||||
|
||||
// Store this, since we have it.
|
||||
nextHash := hashLen(cv, hashLog, tableFastHashLen)
|
||||
@@ -418,21 +377,7 @@ encodeLoop:
|
||||
if len(blk.sequences) > 2 && load3232(src, repIndex) == uint32(cv>>16) {
|
||||
// Consider history as well.
|
||||
var seq seq
|
||||
// length := 4 + e.matchlen(s+6, repIndex+4, src)
|
||||
// length := 4 + int32(matchLen(src[s+6:], src[repIndex+4:]))
|
||||
var length int32
|
||||
{
|
||||
a := src[s+6:]
|
||||
b := src[repIndex+4:]
|
||||
endI := len(a) & (math.MaxInt32 - 7)
|
||||
length = int32(endI) + 4
|
||||
for i := 0; i < endI; i += 8 {
|
||||
if diff := load64(a, i) ^ load64(b, i); diff != 0 {
|
||||
length = int32(i+bits.TrailingZeros64(diff)>>3) + 4
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
length := 4 + e.matchlen(s+6, repIndex+4, src)
|
||||
|
||||
seq.matchLen = uint32(length - zstdMinMatch)
|
||||
|
||||
@@ -522,21 +467,7 @@ encodeLoop:
|
||||
panic(fmt.Sprintf("t (%d) < 0 ", t))
|
||||
}
|
||||
// Extend the 4-byte match as long as possible.
|
||||
//l := e.matchlenNoHist(s+4, t+4, src) + 4
|
||||
// l := int32(matchLen(src[s+4:], src[t+4:])) + 4
|
||||
var l int32
|
||||
{
|
||||
a := src[s+4:]
|
||||
b := src[t+4:]
|
||||
endI := len(a) & (math.MaxInt32 - 7)
|
||||
l = int32(endI) + 4
|
||||
for i := 0; i < endI; i += 8 {
|
||||
if diff := load64(a, i) ^ load64(b, i); diff != 0 {
|
||||
l = int32(i+bits.TrailingZeros64(diff)>>3) + 4
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
l := e.matchlen(s+4, t+4, src) + 4
|
||||
|
||||
// Extend backwards
|
||||
tMin := s - e.maxMatchOff
|
||||
@@ -573,21 +504,7 @@ encodeLoop:
|
||||
if o2 := s - offset2; len(blk.sequences) > 2 && load3232(src, o2) == uint32(cv) {
|
||||
// We have at least 4 byte match.
|
||||
// No need to check backwards. We come straight from a match
|
||||
//l := 4 + e.matchlenNoHist(s+4, o2+4, src)
|
||||
// l := 4 + int32(matchLen(src[s+4:], src[o2+4:]))
|
||||
var l int32
|
||||
{
|
||||
a := src[s+4:]
|
||||
b := src[o2+4:]
|
||||
endI := len(a) & (math.MaxInt32 - 7)
|
||||
l = int32(endI) + 4
|
||||
for i := 0; i < endI; i += 8 {
|
||||
if diff := load64(a, i) ^ load64(b, i); diff != 0 {
|
||||
l = int32(i+bits.TrailingZeros64(diff)>>3) + 4
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
l := 4 + e.matchlen(s+4, o2+4, src)
|
||||
|
||||
// Store this, since we have it.
|
||||
nextHash := hashLen(cv, hashLog, tableFastHashLen)
|
||||
@@ -731,19 +648,7 @@ encodeLoop:
|
||||
// Consider history as well.
|
||||
var seq seq
|
||||
var length int32
|
||||
// length = 4 + e.matchlen(s+6, repIndex+4, src)
|
||||
{
|
||||
a := src[s+6:]
|
||||
b := src[repIndex+4:]
|
||||
endI := len(a) & (math.MaxInt32 - 7)
|
||||
length = int32(endI) + 4
|
||||
for i := 0; i < endI; i += 8 {
|
||||
if diff := load64(a, i) ^ load64(b, i); diff != 0 {
|
||||
length = int32(i+bits.TrailingZeros64(diff)>>3) + 4
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
length = 4 + e.matchlen(s+6, repIndex+4, src)
|
||||
|
||||
seq.matchLen = uint32(length - zstdMinMatch)
|
||||
|
||||
@@ -831,20 +736,7 @@ encodeLoop:
|
||||
}
|
||||
|
||||
// Extend the 4-byte match as long as possible.
|
||||
//l := e.matchlen(s+4, t+4, src) + 4
|
||||
var l int32
|
||||
{
|
||||
a := src[s+4:]
|
||||
b := src[t+4:]
|
||||
endI := len(a) & (math.MaxInt32 - 7)
|
||||
l = int32(endI) + 4
|
||||
for i := 0; i < endI; i += 8 {
|
||||
if diff := load64(a, i) ^ load64(b, i); diff != 0 {
|
||||
l = int32(i+bits.TrailingZeros64(diff)>>3) + 4
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
l := e.matchlen(s+4, t+4, src) + 4
|
||||
|
||||
// Extend backwards
|
||||
tMin := s - e.maxMatchOff
|
||||
@@ -881,20 +773,7 @@ encodeLoop:
|
||||
if o2 := s - offset2; canRepeat && load3232(src, o2) == uint32(cv) {
|
||||
// We have at least 4 byte match.
|
||||
// No need to check backwards. We come straight from a match
|
||||
//l := 4 + e.matchlen(s+4, o2+4, src)
|
||||
var l int32
|
||||
{
|
||||
a := src[s+4:]
|
||||
b := src[o2+4:]
|
||||
endI := len(a) & (math.MaxInt32 - 7)
|
||||
l = int32(endI) + 4
|
||||
for i := 0; i < endI; i += 8 {
|
||||
if diff := load64(a, i) ^ load64(b, i); diff != 0 {
|
||||
l = int32(i+bits.TrailingZeros64(diff)>>3) + 4
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
l := 4 + e.matchlen(s+4, o2+4, src)
|
||||
|
||||
// Store this, since we have it.
|
||||
nextHash := hashLen(cv, hashLog, tableFastHashLen)
|
||||
|
||||
10
vendor/github.com/klauspost/compress/zstd/encoder_options.go
сгенерированный
поставляемый
10
vendor/github.com/klauspost/compress/zstd/encoder_options.go
сгенерированный
поставляемый
@@ -24,6 +24,7 @@ type encoderOptions struct {
|
||||
allLitEntropy bool
|
||||
customWindow bool
|
||||
customALEntropy bool
|
||||
customBlockSize bool
|
||||
lowMem bool
|
||||
dict *dict
|
||||
}
|
||||
@@ -33,7 +34,7 @@ func (o *encoderOptions) setDefault() {
|
||||
concurrent: runtime.GOMAXPROCS(0),
|
||||
crc: true,
|
||||
single: nil,
|
||||
blockSize: 1 << 16,
|
||||
blockSize: maxCompressedBlockSize,
|
||||
windowSize: 8 << 20,
|
||||
level: SpeedDefault,
|
||||
allLitEntropy: true,
|
||||
@@ -106,6 +107,7 @@ func WithWindowSize(n int) EOption {
|
||||
o.customWindow = true
|
||||
if o.blockSize > o.windowSize {
|
||||
o.blockSize = o.windowSize
|
||||
o.customBlockSize = true
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -188,10 +190,9 @@ func EncoderLevelFromZstd(level int) EncoderLevel {
|
||||
return SpeedDefault
|
||||
case level >= 6 && level < 10:
|
||||
return SpeedBetterCompression
|
||||
case level >= 10:
|
||||
default:
|
||||
return SpeedBestCompression
|
||||
}
|
||||
return SpeedDefault
|
||||
}
|
||||
|
||||
// String provides a string representation of the compression level.
|
||||
@@ -222,6 +223,9 @@ func WithEncoderLevel(l EncoderLevel) EOption {
|
||||
switch o.level {
|
||||
case SpeedFastest:
|
||||
o.windowSize = 4 << 20
|
||||
if !o.customBlockSize {
|
||||
o.blockSize = 1 << 16
|
||||
}
|
||||
case SpeedDefault:
|
||||
o.windowSize = 8 << 20
|
||||
case SpeedBetterCompression:
|
||||
|
||||
2
vendor/github.com/klauspost/compress/zstd/fse_decoder.go
сгенерированный
поставляемый
2
vendor/github.com/klauspost/compress/zstd/fse_decoder.go
сгенерированный
поставляемый
@@ -379,7 +379,7 @@ func (s decSymbol) final() (int, uint8) {
|
||||
// This can only be used if no symbols are 0 bits.
|
||||
// At least tablelog bits must be available in the bit reader.
|
||||
func (s *fseState) nextFast(br *bitReader) (uint32, uint8) {
|
||||
lowBits := uint16(br.getBitsFast(s.state.nbBits()))
|
||||
lowBits := br.get16BitsFast(s.state.nbBits())
|
||||
s.state = s.dt[s.state.newState()+lowBits]
|
||||
return s.state.baseline(), s.state.addBits()
|
||||
}
|
||||
|
||||
5
vendor/github.com/klauspost/compress/zstd/fse_encoder.go
сгенерированный
поставляемый
5
vendor/github.com/klauspost/compress/zstd/fse_encoder.go
сгенерированный
поставляемый
@@ -62,9 +62,8 @@ func (s symbolTransform) String() string {
|
||||
// To indicate that you have populated the histogram call HistogramFinished
|
||||
// with the value of the highest populated symbol, as well as the number of entries
|
||||
// in the most populated entry. These are accepted at face value.
|
||||
// The returned slice will always be length 256.
|
||||
func (s *fseEncoder) Histogram() []uint32 {
|
||||
return s.count[:]
|
||||
func (s *fseEncoder) Histogram() *[256]uint32 {
|
||||
return &s.count
|
||||
}
|
||||
|
||||
// HistogramFinished can be called to indicate that the histogram has been populated.
|
||||
|
||||
1
vendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash_amd64.s
сгенерированный
поставляемый
1
vendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash_amd64.s
сгенерированный
поставляемый
@@ -1,6 +1,7 @@
|
||||
// +build !appengine
|
||||
// +build gc
|
||||
// +build !purego
|
||||
// +build !noasm
|
||||
|
||||
#include "textflag.h"
|
||||
|
||||
|
||||
186
vendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash_arm64.s
сгенерированный
поставляемый
Обычный файл
186
vendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash_arm64.s
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,186 @@
|
||||
// +build gc,!purego,!noasm
|
||||
|
||||
#include "textflag.h"
|
||||
|
||||
// Register allocation.
|
||||
#define digest R1
|
||||
#define h R2 // Return value.
|
||||
#define p R3 // Input pointer.
|
||||
#define len R4
|
||||
#define nblocks R5 // len / 32.
|
||||
#define prime1 R7
|
||||
#define prime2 R8
|
||||
#define prime3 R9
|
||||
#define prime4 R10
|
||||
#define prime5 R11
|
||||
#define v1 R12
|
||||
#define v2 R13
|
||||
#define v3 R14
|
||||
#define v4 R15
|
||||
#define x1 R20
|
||||
#define x2 R21
|
||||
#define x3 R22
|
||||
#define x4 R23
|
||||
|
||||
#define round(acc, x) \
|
||||
MADD prime2, acc, x, acc \
|
||||
ROR $64-31, acc \
|
||||
MUL prime1, acc \
|
||||
|
||||
// x = round(0, x).
|
||||
#define round0(x) \
|
||||
MUL prime2, x \
|
||||
ROR $64-31, x \
|
||||
MUL prime1, x \
|
||||
|
||||
#define mergeRound(x) \
|
||||
round0(x) \
|
||||
EOR x, h \
|
||||
MADD h, prime4, prime1, h \
|
||||
|
||||
// Update v[1-4] with 32-byte blocks. Assumes len >= 32.
|
||||
#define blocksLoop() \
|
||||
LSR $5, len, nblocks \
|
||||
PCALIGN $16 \
|
||||
loop: \
|
||||
LDP.P 32(p), (x1, x2) \
|
||||
round(v1, x1) \
|
||||
LDP -16(p), (x3, x4) \
|
||||
round(v2, x2) \
|
||||
SUB $1, nblocks \
|
||||
round(v3, x3) \
|
||||
round(v4, x4) \
|
||||
CBNZ nblocks, loop \
|
||||
|
||||
// The primes are repeated here to ensure that they're stored
|
||||
// in a contiguous array, so we can load them with LDP.
|
||||
DATA primes<> +0(SB)/8, $11400714785074694791
|
||||
DATA primes<> +8(SB)/8, $14029467366897019727
|
||||
DATA primes<>+16(SB)/8, $1609587929392839161
|
||||
DATA primes<>+24(SB)/8, $9650029242287828579
|
||||
DATA primes<>+32(SB)/8, $2870177450012600261
|
||||
GLOBL primes<>(SB), NOPTR+RODATA, $40
|
||||
|
||||
// func Sum64(b []byte) uint64
|
||||
TEXT ·Sum64(SB), NOFRAME+NOSPLIT, $0-32
|
||||
LDP b_base+0(FP), (p, len)
|
||||
|
||||
LDP primes<> +0(SB), (prime1, prime2)
|
||||
LDP primes<>+16(SB), (prime3, prime4)
|
||||
MOVD primes<>+32(SB), prime5
|
||||
|
||||
CMP $32, len
|
||||
CSEL LO, prime5, ZR, h // if len < 32 { h = prime5 } else { h = 0 }
|
||||
BLO afterLoop
|
||||
|
||||
ADD prime1, prime2, v1
|
||||
MOVD prime2, v2
|
||||
MOVD $0, v3
|
||||
NEG prime1, v4
|
||||
|
||||
blocksLoop()
|
||||
|
||||
ROR $64-1, v1, x1
|
||||
ROR $64-7, v2, x2
|
||||
ADD x1, x2
|
||||
ROR $64-12, v3, x3
|
||||
ROR $64-18, v4, x4
|
||||
ADD x3, x4
|
||||
ADD x2, x4, h
|
||||
|
||||
mergeRound(v1)
|
||||
mergeRound(v2)
|
||||
mergeRound(v3)
|
||||
mergeRound(v4)
|
||||
|
||||
afterLoop:
|
||||
ADD len, h
|
||||
|
||||
TBZ $4, len, try8
|
||||
LDP.P 16(p), (x1, x2)
|
||||
|
||||
round0(x1)
|
||||
ROR $64-27, h
|
||||
EOR x1 @> 64-27, h, h
|
||||
MADD h, prime4, prime1, h
|
||||
|
||||
round0(x2)
|
||||
ROR $64-27, h
|
||||
EOR x2 @> 64-27, h
|
||||
MADD h, prime4, prime1, h
|
||||
|
||||
try8:
|
||||
TBZ $3, len, try4
|
||||
MOVD.P 8(p), x1
|
||||
|
||||
round0(x1)
|
||||
ROR $64-27, h
|
||||
EOR x1 @> 64-27, h
|
||||
MADD h, prime4, prime1, h
|
||||
|
||||
try4:
|
||||
TBZ $2, len, try2
|
||||
MOVWU.P 4(p), x2
|
||||
|
||||
MUL prime1, x2
|
||||
ROR $64-23, h
|
||||
EOR x2 @> 64-23, h
|
||||
MADD h, prime3, prime2, h
|
||||
|
||||
try2:
|
||||
TBZ $1, len, try1
|
||||
MOVHU.P 2(p), x3
|
||||
AND $255, x3, x1
|
||||
LSR $8, x3, x2
|
||||
|
||||
MUL prime5, x1
|
||||
ROR $64-11, h
|
||||
EOR x1 @> 64-11, h
|
||||
MUL prime1, h
|
||||
|
||||
MUL prime5, x2
|
||||
ROR $64-11, h
|
||||
EOR x2 @> 64-11, h
|
||||
MUL prime1, h
|
||||
|
||||
try1:
|
||||
TBZ $0, len, end
|
||||
MOVBU (p), x4
|
||||
|
||||
MUL prime5, x4
|
||||
ROR $64-11, h
|
||||
EOR x4 @> 64-11, h
|
||||
MUL prime1, h
|
||||
|
||||
end:
|
||||
EOR h >> 33, h
|
||||
MUL prime2, h
|
||||
EOR h >> 29, h
|
||||
MUL prime3, h
|
||||
EOR h >> 32, h
|
||||
|
||||
MOVD h, ret+24(FP)
|
||||
RET
|
||||
|
||||
// func writeBlocks(d *Digest, b []byte) int
|
||||
//
|
||||
// Assumes len(b) >= 32.
|
||||
TEXT ·writeBlocks(SB), NOFRAME+NOSPLIT, $0-40
|
||||
LDP primes<>(SB), (prime1, prime2)
|
||||
|
||||
// Load state. Assume v[1-4] are stored contiguously.
|
||||
MOVD d+0(FP), digest
|
||||
LDP 0(digest), (v1, v2)
|
||||
LDP 16(digest), (v3, v4)
|
||||
|
||||
LDP b_base+8(FP), (p, len)
|
||||
|
||||
blocksLoop()
|
||||
|
||||
// Store updated state.
|
||||
STP (v1, v2), 0(digest)
|
||||
STP (v3, v4), 16(digest)
|
||||
|
||||
BIC $31, len
|
||||
MOVD len, ret+32(FP)
|
||||
RET
|
||||
@@ -1,5 +1,9 @@
|
||||
//go:build !appengine && gc && !purego
|
||||
// +build !appengine,gc,!purego
|
||||
//go:build (amd64 || arm64) && !appengine && gc && !purego && !noasm
|
||||
// +build amd64 arm64
|
||||
// +build !appengine
|
||||
// +build gc
|
||||
// +build !purego
|
||||
// +build !noasm
|
||||
|
||||
package xxhash
|
||||
|
||||
4
vendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash_other.go
сгенерированный
поставляемый
4
vendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash_other.go
сгенерированный
поставляемый
@@ -1,5 +1,5 @@
|
||||
//go:build !amd64 || appengine || !gc || purego
|
||||
// +build !amd64 appengine !gc purego
|
||||
//go:build (!amd64 && !arm64) || appengine || !gc || purego || noasm
|
||||
// +build !amd64,!arm64 appengine !gc purego noasm
|
||||
|
||||
package xxhash
|
||||
|
||||
|
||||
4
vendor/github.com/klauspost/compress/zstd/seqdec.go
сгенерированный
поставляемый
4
vendor/github.com/klauspost/compress/zstd/seqdec.go
сгенерированный
поставляемый
@@ -278,7 +278,7 @@ func (s *sequenceDecs) decode(seqs int, br *bitReader, hist []byte) error {
|
||||
mlState = mlTable[mlState.newState()&maxTableMask]
|
||||
ofState = ofTable[ofState.newState()&maxTableMask]
|
||||
} else {
|
||||
bits := br.getBitsFast(nBits)
|
||||
bits := br.get32BitsFast(nBits)
|
||||
lowBits := uint16(bits >> ((ofState.nbBits() + mlState.nbBits()) & 31))
|
||||
llState = llTable[(llState.newState()+lowBits)&maxTableMask]
|
||||
|
||||
@@ -326,7 +326,7 @@ func (s *sequenceDecs) updateAlt(br *bitReader) {
|
||||
s.offsets.state.state = s.offsets.state.dt[c.newState()]
|
||||
return
|
||||
}
|
||||
bits := br.getBitsFast(nBits)
|
||||
bits := br.get32BitsFast(nBits)
|
||||
lowBits := uint16(bits >> ((c.nbBits() + b.nbBits()) & 31))
|
||||
s.litLengths.state.state = s.litLengths.state.dt[a.newState()+lowBits]
|
||||
|
||||
|
||||
4
vendor/github.com/klauspost/cpuid/v2/README.md
сгенерированный
поставляемый
4
vendor/github.com/klauspost/cpuid/v2/README.md
сгенерированный
поставляемый
@@ -39,10 +39,10 @@ func main() {
|
||||
fmt.Println("ThreadsPerCore:", CPU.ThreadsPerCore)
|
||||
fmt.Println("LogicalCores:", CPU.LogicalCores)
|
||||
fmt.Println("Family", CPU.Family, "Model:", CPU.Model, "Vendor ID:", CPU.VendorID)
|
||||
fmt.Println("Features:", fmt.Sprintf(strings.Join(CPU.FeatureSet(), ",")))
|
||||
fmt.Println("Features:", strings.Join(CPU.FeatureSet(), ","))
|
||||
fmt.Println("Cacheline bytes:", CPU.CacheLine)
|
||||
fmt.Println("L1 Data Cache:", CPU.Cache.L1D, "bytes")
|
||||
fmt.Println("L1 Instruction Cache:", CPU.Cache.L1D, "bytes")
|
||||
fmt.Println("L1 Instruction Cache:", CPU.Cache.L1I, "bytes")
|
||||
fmt.Println("L2 Cache:", CPU.Cache.L2, "bytes")
|
||||
fmt.Println("L3 Cache:", CPU.Cache.L3, "bytes")
|
||||
fmt.Println("Frequency", CPU.Hz, "hz")
|
||||
|
||||
74
vendor/github.com/klauspost/cpuid/v2/cpuid.go
сгенерированный
поставляемый
74
vendor/github.com/klauspost/cpuid/v2/cpuid.go
сгенерированный
поставляемый
@@ -95,10 +95,13 @@ const (
|
||||
AVXSLOW // Indicates the CPU performs 2 128 bit operations instead of one.
|
||||
BMI1 // Bit Manipulation Instruction Set 1
|
||||
BMI2 // Bit Manipulation Instruction Set 2
|
||||
CETIBT // Intel CET Indirect Branch Tracking
|
||||
CETSS // Intel CET Shadow Stack
|
||||
CLDEMOTE // Cache Line Demote
|
||||
CLMUL // Carry-less Multiplication
|
||||
CLZERO // CLZERO instruction supported
|
||||
CMOV // i686 CMOV
|
||||
CMPXCHG8 // CMPXCHG8 instruction
|
||||
CPBOOST // Core Performance Boost
|
||||
CX16 // CMPXCHG16B Instruction
|
||||
ENQCMD // Enqueue Command
|
||||
@@ -106,6 +109,8 @@ const (
|
||||
F16C // Half-precision floating-point conversion
|
||||
FMA3 // Intel FMA 3. Does not imply AVX.
|
||||
FMA4 // Bulldozer FMA4 functions
|
||||
FXSR // FXSAVE, FXRESTOR instructions, CR4 bit 9
|
||||
FXSROPT // FXSAVE/FXRSTOR optimizations
|
||||
GFNI // Galois Field New Instructions
|
||||
HLE // Hardware Lock Elision
|
||||
HTT // Hyperthreading (enabled)
|
||||
@@ -123,16 +128,19 @@ const (
|
||||
IBSRIPINVALIDCHK // Instruction Based Sampling Feature (AMD)
|
||||
INT_WBINVD // WBINVD/WBNOINVD are interruptible.
|
||||
INVLPGB // NVLPGB and TLBSYNC instruction supported
|
||||
LAHF // LAHF/SAHF in long mode
|
||||
LZCNT // LZCNT instruction
|
||||
MCAOVERFLOW // MCA overflow recovery support.
|
||||
MCOMMIT // MCOMMIT instruction supported
|
||||
MMX // standard MMX
|
||||
MMXEXT // SSE integer functions or AMD MMX ext
|
||||
MOVBE // MOVBE instruction (big-endian)
|
||||
MOVDIR64B // Move 64 Bytes as Direct Store
|
||||
MOVDIRI // Move Doubleword as Direct Store
|
||||
MPX // Intel MPX (Memory Protection Extensions)
|
||||
MSRIRC // Instruction Retired Counter MSR available
|
||||
NX // NX (No-Execute) bit
|
||||
OSXSAVE // XSAVE enabled by OS
|
||||
POPCNT // POPCNT instruction
|
||||
RDPRU // RDPRU instruction supported
|
||||
RDRAND // RDRAND instruction is available
|
||||
@@ -140,6 +148,7 @@ const (
|
||||
RDTSCP // RDTSCP Instruction
|
||||
RTM // Restricted Transactional Memory
|
||||
RTM_ALWAYS_ABORT // Indicates that the loaded microcode is forcing RTM abort.
|
||||
SCE // SYSENTER and SYSEXIT instructions
|
||||
SERIALIZE // Serialize Instruction Execution
|
||||
SGX // Software Guard Extensions
|
||||
SGXLC // Software Guard Extensions Launch Control
|
||||
@@ -160,7 +169,9 @@ const (
|
||||
VPCLMULQDQ // Carry-Less Multiplication Quadword
|
||||
WAITPKG // TPAUSE, UMONITOR, UMWAIT
|
||||
WBNOINVD // Write Back and Do Not Invalidate Cache
|
||||
X87 // FPU
|
||||
XOP // Bulldozer XOP functions
|
||||
XSAVE // XSAVE, XRESTOR, XSETBV, XGETBV
|
||||
|
||||
// ARM features:
|
||||
AESARM // AES instructions
|
||||
@@ -311,6 +322,31 @@ func (c CPUInfo) Has(id FeatureID) bool {
|
||||
return c.featureSet.inSet(id)
|
||||
}
|
||||
|
||||
// https://en.wikipedia.org/wiki/X86-64#Microarchitecture_levels
|
||||
var level1Features = flagSetWith(CMOV, CMPXCHG8, X87, FXSR, MMX, SCE, SSE, SSE2)
|
||||
var level2Features = flagSetWith(CMOV, CMPXCHG8, X87, FXSR, MMX, SCE, SSE, SSE2, CX16, LAHF, POPCNT, SSE3, SSE4, SSE42, SSSE3)
|
||||
var level3Features = flagSetWith(CMOV, CMPXCHG8, X87, FXSR, MMX, SCE, SSE, SSE2, CX16, LAHF, POPCNT, SSE3, SSE4, SSE42, SSSE3, AVX, AVX2, BMI1, BMI2, F16C, FMA3, LZCNT, MOVBE, OSXSAVE)
|
||||
var level4Features = flagSetWith(CMOV, CMPXCHG8, X87, FXSR, MMX, SCE, SSE, SSE2, CX16, LAHF, POPCNT, SSE3, SSE4, SSE42, SSSE3, AVX, AVX2, BMI1, BMI2, F16C, FMA3, LZCNT, MOVBE, OSXSAVE, AVX512F, AVX512BW, AVX512CD, AVX512DQ, AVX512VL)
|
||||
|
||||
// X64Level returns the microarchitecture level detected on the CPU.
|
||||
// If features are lacking or non x64 mode, 0 is returned.
|
||||
// See https://en.wikipedia.org/wiki/X86-64#Microarchitecture_levels
|
||||
func (c CPUInfo) X64Level() int {
|
||||
if c.featureSet.hasSet(level4Features) {
|
||||
return 4
|
||||
}
|
||||
if c.featureSet.hasSet(level3Features) {
|
||||
return 3
|
||||
}
|
||||
if c.featureSet.hasSet(level2Features) {
|
||||
return 2
|
||||
}
|
||||
if c.featureSet.hasSet(level1Features) {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// Disable will disable one or several features.
|
||||
func (c *CPUInfo) Disable(ids ...FeatureID) bool {
|
||||
for _, id := range ids {
|
||||
@@ -335,9 +371,7 @@ func (c CPUInfo) IsVendor(v Vendor) bool {
|
||||
|
||||
func (c CPUInfo) FeatureSet() []string {
|
||||
s := make([]string, 0)
|
||||
for _, f := range c.featureSet.Strings() {
|
||||
s = append(s, f)
|
||||
}
|
||||
s = append(s, c.featureSet.Strings()...)
|
||||
return s
|
||||
}
|
||||
|
||||
@@ -499,6 +533,24 @@ func (s *flagSet) or(other flagSet) {
|
||||
}
|
||||
}
|
||||
|
||||
// hasSet returns whether all features are present.
|
||||
func (s flagSet) hasSet(other flagSet) bool {
|
||||
for i, v := range other[:] {
|
||||
if s[i]&v != v {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func flagSetWith(feat ...FeatureID) flagSet {
|
||||
var res flagSet
|
||||
for _, f := range feat {
|
||||
res.set(f)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// ParseFeature will parse the string and return the ID of the matching feature.
|
||||
// Will return UNKNOWN if not found.
|
||||
func ParseFeature(s string) FeatureID {
|
||||
@@ -708,6 +760,7 @@ func (c *CPUInfo) cacheSize() {
|
||||
if maxFunctionID() < 4 {
|
||||
return
|
||||
}
|
||||
c.Cache.L1I, c.Cache.L1D, c.Cache.L2, c.Cache.L3 = 0, 0, 0, 0
|
||||
for i := uint32(0); ; i++ {
|
||||
eax, ebx, ecx, _ := cpuidex(4, i)
|
||||
cacheType := eax & 15
|
||||
@@ -800,8 +853,6 @@ func (c *CPUInfo) cacheSize() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
type SGXEPCSection struct {
|
||||
@@ -865,9 +916,14 @@ func support() flagSet {
|
||||
family, model := familyModel()
|
||||
|
||||
_, _, c, d := cpuid(1)
|
||||
fs.setIf((d&(1<<0)) != 0, X87)
|
||||
fs.setIf((d&(1<<8)) != 0, CMPXCHG8)
|
||||
fs.setIf((d&(1<<11)) != 0, SCE)
|
||||
fs.setIf((d&(1<<15)) != 0, CMOV)
|
||||
fs.setIf((d&(1<<22)) != 0, MMXEXT)
|
||||
fs.setIf((d&(1<<23)) != 0, MMX)
|
||||
fs.setIf((d&(1<<25)) != 0, MMXEXT)
|
||||
fs.setIf((d&(1<<24)) != 0, FXSR)
|
||||
fs.setIf((d&(1<<25)) != 0, FXSROPT)
|
||||
fs.setIf((d&(1<<25)) != 0, SSE)
|
||||
fs.setIf((d&(1<<26)) != 0, SSE2)
|
||||
fs.setIf((c&1) != 0, SSE3)
|
||||
@@ -877,6 +933,7 @@ func support() flagSet {
|
||||
fs.setIf((c&0x00100000) != 0, SSE42)
|
||||
fs.setIf((c&(1<<25)) != 0, AESNI)
|
||||
fs.setIf((c&(1<<1)) != 0, CLMUL)
|
||||
fs.setIf(c&(1<<22) != 0, MOVBE)
|
||||
fs.setIf(c&(1<<23) != 0, POPCNT)
|
||||
fs.setIf(c&(1<<30) != 0, RDRAND)
|
||||
|
||||
@@ -892,6 +949,8 @@ func support() flagSet {
|
||||
if vend == AMD && (d&(1<<28)) != 0 && mfi >= 4 {
|
||||
fs.setIf(threadsPerCore() > 1, HTT)
|
||||
}
|
||||
fs.setIf(c&1<<26 != 0, XSAVE)
|
||||
fs.setIf(c&1<<27 != 0, OSXSAVE)
|
||||
// Check XGETBV/XSAVE (26), OXSAVE (27) and AVX (28) bits
|
||||
const avxCheck = 1<<26 | 1<<27 | 1<<28
|
||||
if c&avxCheck == avxCheck {
|
||||
@@ -936,6 +995,7 @@ func support() flagSet {
|
||||
fs.setIf(ebx&(1<<29) != 0, SHA)
|
||||
// CPUID.(EAX=7, ECX=0).ECX
|
||||
fs.setIf(ecx&(1<<5) != 0, WAITPKG)
|
||||
fs.setIf(ecx&(1<<7) != 0, CETSS)
|
||||
fs.setIf(ecx&(1<<25) != 0, CLDEMOTE)
|
||||
fs.setIf(ecx&(1<<27) != 0, MOVDIRI)
|
||||
fs.setIf(ecx&(1<<28) != 0, MOVDIR64B)
|
||||
@@ -945,6 +1005,7 @@ func support() flagSet {
|
||||
fs.setIf(edx&(1<<11) != 0, RTM_ALWAYS_ABORT)
|
||||
fs.setIf(edx&(1<<14) != 0, SERIALIZE)
|
||||
fs.setIf(edx&(1<<16) != 0, TSXLDTRK)
|
||||
fs.setIf(edx&(1<<20) != 0, CETIBT)
|
||||
fs.setIf(edx&(1<<26) != 0, IBPB)
|
||||
fs.setIf(edx&(1<<27) != 0, STIBP)
|
||||
|
||||
@@ -996,6 +1057,7 @@ func support() flagSet {
|
||||
fs.set(LZCNT)
|
||||
fs.set(POPCNT)
|
||||
}
|
||||
fs.setIf((c&(1<<0)) != 0, LAHF)
|
||||
fs.setIf((c&(1<<10)) != 0, IBS)
|
||||
fs.setIf((d&(1<<31)) != 0, AMD3DNOW)
|
||||
fs.setIf((d&(1<<30)) != 0, AMD3DNOWEXT)
|
||||
|
||||
3
vendor/github.com/klauspost/cpuid/v2/detect_arm64.go
сгенерированный
поставляемый
3
vendor/github.com/klauspost/cpuid/v2/detect_arm64.go
сгенерированный
поставляемый
@@ -1,6 +1,7 @@
|
||||
// Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file.
|
||||
|
||||
//+build arm64,!gccgo,!noasm,!appengine
|
||||
//go:build arm64 && !gccgo && !noasm && !appengine
|
||||
// +build arm64,!gccgo,!noasm,!appengine
|
||||
|
||||
package cpuid
|
||||
|
||||
|
||||
3
vendor/github.com/klauspost/cpuid/v2/detect_ref.go
сгенерированный
поставляемый
3
vendor/github.com/klauspost/cpuid/v2/detect_ref.go
сгенерированный
поставляемый
@@ -1,6 +1,7 @@
|
||||
// Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file.
|
||||
|
||||
//+build !amd64,!386,!arm64 gccgo noasm appengine
|
||||
//go:build (!amd64 && !386 && !arm64) || gccgo || noasm || appengine
|
||||
// +build !amd64,!386,!arm64 gccgo noasm appengine
|
||||
|
||||
package cpuid
|
||||
|
||||
|
||||
3
vendor/github.com/klauspost/cpuid/v2/detect_x86.go
сгенерированный
поставляемый
3
vendor/github.com/klauspost/cpuid/v2/detect_x86.go
сгенерированный
поставляемый
@@ -1,6 +1,7 @@
|
||||
// Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file.
|
||||
|
||||
//+build 386,!gccgo,!noasm,!appengine amd64,!gccgo,!noasm,!appengine
|
||||
//go:build (386 && !gccgo && !noasm && !appengine) || (amd64 && !gccgo && !noasm && !appengine)
|
||||
// +build 386,!gccgo,!noasm,!appengine amd64,!gccgo,!noasm,!appengine
|
||||
|
||||
package cpuid
|
||||
|
||||
|
||||
197
vendor/github.com/klauspost/cpuid/v2/featureid_string.go
сгенерированный
поставляемый
197
vendor/github.com/klauspost/cpuid/v2/featureid_string.go
сгенерированный
поставляемый
@@ -36,103 +36,114 @@ func _() {
|
||||
_ = x[AVXSLOW-26]
|
||||
_ = x[BMI1-27]
|
||||
_ = x[BMI2-28]
|
||||
_ = x[CLDEMOTE-29]
|
||||
_ = x[CLMUL-30]
|
||||
_ = x[CLZERO-31]
|
||||
_ = x[CMOV-32]
|
||||
_ = x[CPBOOST-33]
|
||||
_ = x[CX16-34]
|
||||
_ = x[ENQCMD-35]
|
||||
_ = x[ERMS-36]
|
||||
_ = x[F16C-37]
|
||||
_ = x[FMA3-38]
|
||||
_ = x[FMA4-39]
|
||||
_ = x[GFNI-40]
|
||||
_ = x[HLE-41]
|
||||
_ = x[HTT-42]
|
||||
_ = x[HWA-43]
|
||||
_ = x[HYPERVISOR-44]
|
||||
_ = x[IBPB-45]
|
||||
_ = x[IBS-46]
|
||||
_ = x[IBSBRNTRGT-47]
|
||||
_ = x[IBSFETCHSAM-48]
|
||||
_ = x[IBSFFV-49]
|
||||
_ = x[IBSOPCNT-50]
|
||||
_ = x[IBSOPCNTEXT-51]
|
||||
_ = x[IBSOPSAM-52]
|
||||
_ = x[IBSRDWROPCNT-53]
|
||||
_ = x[IBSRIPINVALIDCHK-54]
|
||||
_ = x[INT_WBINVD-55]
|
||||
_ = x[INVLPGB-56]
|
||||
_ = x[LZCNT-57]
|
||||
_ = x[MCAOVERFLOW-58]
|
||||
_ = x[MCOMMIT-59]
|
||||
_ = x[MMX-60]
|
||||
_ = x[MMXEXT-61]
|
||||
_ = x[MOVDIR64B-62]
|
||||
_ = x[MOVDIRI-63]
|
||||
_ = x[MPX-64]
|
||||
_ = x[MSRIRC-65]
|
||||
_ = x[NX-66]
|
||||
_ = x[POPCNT-67]
|
||||
_ = x[RDPRU-68]
|
||||
_ = x[RDRAND-69]
|
||||
_ = x[RDSEED-70]
|
||||
_ = x[RDTSCP-71]
|
||||
_ = x[RTM-72]
|
||||
_ = x[RTM_ALWAYS_ABORT-73]
|
||||
_ = x[SERIALIZE-74]
|
||||
_ = x[SGX-75]
|
||||
_ = x[SGXLC-76]
|
||||
_ = x[SHA-77]
|
||||
_ = x[SSE-78]
|
||||
_ = x[SSE2-79]
|
||||
_ = x[SSE3-80]
|
||||
_ = x[SSE4-81]
|
||||
_ = x[SSE42-82]
|
||||
_ = x[SSE4A-83]
|
||||
_ = x[SSSE3-84]
|
||||
_ = x[STIBP-85]
|
||||
_ = x[SUCCOR-86]
|
||||
_ = x[TBM-87]
|
||||
_ = x[TSXLDTRK-88]
|
||||
_ = x[VAES-89]
|
||||
_ = x[VMX-90]
|
||||
_ = x[VPCLMULQDQ-91]
|
||||
_ = x[WAITPKG-92]
|
||||
_ = x[WBNOINVD-93]
|
||||
_ = x[XOP-94]
|
||||
_ = x[AESARM-95]
|
||||
_ = x[ARMCPUID-96]
|
||||
_ = x[ASIMD-97]
|
||||
_ = x[ASIMDDP-98]
|
||||
_ = x[ASIMDHP-99]
|
||||
_ = x[ASIMDRDM-100]
|
||||
_ = x[ATOMICS-101]
|
||||
_ = x[CRC32-102]
|
||||
_ = x[DCPOP-103]
|
||||
_ = x[EVTSTRM-104]
|
||||
_ = x[FCMA-105]
|
||||
_ = x[FP-106]
|
||||
_ = x[FPHP-107]
|
||||
_ = x[GPA-108]
|
||||
_ = x[JSCVT-109]
|
||||
_ = x[LRCPC-110]
|
||||
_ = x[PMULL-111]
|
||||
_ = x[SHA1-112]
|
||||
_ = x[SHA2-113]
|
||||
_ = x[SHA3-114]
|
||||
_ = x[SHA512-115]
|
||||
_ = x[SM3-116]
|
||||
_ = x[SM4-117]
|
||||
_ = x[SVE-118]
|
||||
_ = x[lastID-119]
|
||||
_ = x[CETIBT-29]
|
||||
_ = x[CETSS-30]
|
||||
_ = x[CLDEMOTE-31]
|
||||
_ = x[CLMUL-32]
|
||||
_ = x[CLZERO-33]
|
||||
_ = x[CMOV-34]
|
||||
_ = x[CMPXCHG8-35]
|
||||
_ = x[CPBOOST-36]
|
||||
_ = x[CX16-37]
|
||||
_ = x[ENQCMD-38]
|
||||
_ = x[ERMS-39]
|
||||
_ = x[F16C-40]
|
||||
_ = x[FMA3-41]
|
||||
_ = x[FMA4-42]
|
||||
_ = x[FXSR-43]
|
||||
_ = x[FXSROPT-44]
|
||||
_ = x[GFNI-45]
|
||||
_ = x[HLE-46]
|
||||
_ = x[HTT-47]
|
||||
_ = x[HWA-48]
|
||||
_ = x[HYPERVISOR-49]
|
||||
_ = x[IBPB-50]
|
||||
_ = x[IBS-51]
|
||||
_ = x[IBSBRNTRGT-52]
|
||||
_ = x[IBSFETCHSAM-53]
|
||||
_ = x[IBSFFV-54]
|
||||
_ = x[IBSOPCNT-55]
|
||||
_ = x[IBSOPCNTEXT-56]
|
||||
_ = x[IBSOPSAM-57]
|
||||
_ = x[IBSRDWROPCNT-58]
|
||||
_ = x[IBSRIPINVALIDCHK-59]
|
||||
_ = x[INT_WBINVD-60]
|
||||
_ = x[INVLPGB-61]
|
||||
_ = x[LAHF-62]
|
||||
_ = x[LZCNT-63]
|
||||
_ = x[MCAOVERFLOW-64]
|
||||
_ = x[MCOMMIT-65]
|
||||
_ = x[MMX-66]
|
||||
_ = x[MMXEXT-67]
|
||||
_ = x[MOVBE-68]
|
||||
_ = x[MOVDIR64B-69]
|
||||
_ = x[MOVDIRI-70]
|
||||
_ = x[MPX-71]
|
||||
_ = x[MSRIRC-72]
|
||||
_ = x[NX-73]
|
||||
_ = x[OSXSAVE-74]
|
||||
_ = x[POPCNT-75]
|
||||
_ = x[RDPRU-76]
|
||||
_ = x[RDRAND-77]
|
||||
_ = x[RDSEED-78]
|
||||
_ = x[RDTSCP-79]
|
||||
_ = x[RTM-80]
|
||||
_ = x[RTM_ALWAYS_ABORT-81]
|
||||
_ = x[SCE-82]
|
||||
_ = x[SERIALIZE-83]
|
||||
_ = x[SGX-84]
|
||||
_ = x[SGXLC-85]
|
||||
_ = x[SHA-86]
|
||||
_ = x[SSE-87]
|
||||
_ = x[SSE2-88]
|
||||
_ = x[SSE3-89]
|
||||
_ = x[SSE4-90]
|
||||
_ = x[SSE42-91]
|
||||
_ = x[SSE4A-92]
|
||||
_ = x[SSSE3-93]
|
||||
_ = x[STIBP-94]
|
||||
_ = x[SUCCOR-95]
|
||||
_ = x[TBM-96]
|
||||
_ = x[TSXLDTRK-97]
|
||||
_ = x[VAES-98]
|
||||
_ = x[VMX-99]
|
||||
_ = x[VPCLMULQDQ-100]
|
||||
_ = x[WAITPKG-101]
|
||||
_ = x[WBNOINVD-102]
|
||||
_ = x[X87-103]
|
||||
_ = x[XOP-104]
|
||||
_ = x[XSAVE-105]
|
||||
_ = x[AESARM-106]
|
||||
_ = x[ARMCPUID-107]
|
||||
_ = x[ASIMD-108]
|
||||
_ = x[ASIMDDP-109]
|
||||
_ = x[ASIMDHP-110]
|
||||
_ = x[ASIMDRDM-111]
|
||||
_ = x[ATOMICS-112]
|
||||
_ = x[CRC32-113]
|
||||
_ = x[DCPOP-114]
|
||||
_ = x[EVTSTRM-115]
|
||||
_ = x[FCMA-116]
|
||||
_ = x[FP-117]
|
||||
_ = x[FPHP-118]
|
||||
_ = x[GPA-119]
|
||||
_ = x[JSCVT-120]
|
||||
_ = x[LRCPC-121]
|
||||
_ = x[PMULL-122]
|
||||
_ = x[SHA1-123]
|
||||
_ = x[SHA2-124]
|
||||
_ = x[SHA3-125]
|
||||
_ = x[SHA512-126]
|
||||
_ = x[SM3-127]
|
||||
_ = x[SM4-128]
|
||||
_ = x[SVE-129]
|
||||
_ = x[lastID-130]
|
||||
_ = x[firstID-0]
|
||||
}
|
||||
|
||||
const _FeatureID_name = "firstIDADXAESNIAMD3DNOWAMD3DNOWEXTAMXBF16AMXINT8AMXTILEAVXAVX2AVX512BF16AVX512BITALGAVX512BWAVX512CDAVX512DQAVX512ERAVX512FAVX512FP16AVX512IFMAAVX512PFAVX512VBMIAVX512VBMI2AVX512VLAVX512VNNIAVX512VP2INTERSECTAVX512VPOPCNTDQAVXSLOWBMI1BMI2CLDEMOTECLMULCLZEROCMOVCPBOOSTCX16ENQCMDERMSF16CFMA3FMA4GFNIHLEHTTHWAHYPERVISORIBPBIBSIBSBRNTRGTIBSFETCHSAMIBSFFVIBSOPCNTIBSOPCNTEXTIBSOPSAMIBSRDWROPCNTIBSRIPINVALIDCHKINT_WBINVDINVLPGBLZCNTMCAOVERFLOWMCOMMITMMXMMXEXTMOVDIR64BMOVDIRIMPXMSRIRCNXPOPCNTRDPRURDRANDRDSEEDRDTSCPRTMRTM_ALWAYS_ABORTSERIALIZESGXSGXLCSHASSESSE2SSE3SSE4SSE42SSE4ASSSE3STIBPSUCCORTBMTSXLDTRKVAESVMXVPCLMULQDQWAITPKGWBNOINVDXOPAESARMARMCPUIDASIMDASIMDDPASIMDHPASIMDRDMATOMICSCRC32DCPOPEVTSTRMFCMAFPFPHPGPAJSCVTLRCPCPMULLSHA1SHA2SHA3SHA512SM3SM4SVElastID"
|
||||
const _FeatureID_name = "firstIDADXAESNIAMD3DNOWAMD3DNOWEXTAMXBF16AMXINT8AMXTILEAVXAVX2AVX512BF16AVX512BITALGAVX512BWAVX512CDAVX512DQAVX512ERAVX512FAVX512FP16AVX512IFMAAVX512PFAVX512VBMIAVX512VBMI2AVX512VLAVX512VNNIAVX512VP2INTERSECTAVX512VPOPCNTDQAVXSLOWBMI1BMI2CETIBTCETSSCLDEMOTECLMULCLZEROCMOVCMPXCHG8CPBOOSTCX16ENQCMDERMSF16CFMA3FMA4FXSRFXSROPTGFNIHLEHTTHWAHYPERVISORIBPBIBSIBSBRNTRGTIBSFETCHSAMIBSFFVIBSOPCNTIBSOPCNTEXTIBSOPSAMIBSRDWROPCNTIBSRIPINVALIDCHKINT_WBINVDINVLPGBLAHFLZCNTMCAOVERFLOWMCOMMITMMXMMXEXTMOVBEMOVDIR64BMOVDIRIMPXMSRIRCNXOSXSAVEPOPCNTRDPRURDRANDRDSEEDRDTSCPRTMRTM_ALWAYS_ABORTSCESERIALIZESGXSGXLCSHASSESSE2SSE3SSE4SSE42SSE4ASSSE3STIBPSUCCORTBMTSXLDTRKVAESVMXVPCLMULQDQWAITPKGWBNOINVDX87XOPXSAVEAESARMARMCPUIDASIMDASIMDDPASIMDHPASIMDRDMATOMICSCRC32DCPOPEVTSTRMFCMAFPFPHPGPAJSCVTLRCPCPMULLSHA1SHA2SHA3SHA512SM3SM4SVElastID"
|
||||
|
||||
var _FeatureID_index = [...]uint16{0, 7, 10, 15, 23, 34, 41, 48, 55, 58, 62, 72, 84, 92, 100, 108, 116, 123, 133, 143, 151, 161, 172, 180, 190, 208, 223, 230, 234, 238, 246, 251, 257, 261, 268, 272, 278, 282, 286, 290, 294, 298, 301, 304, 307, 317, 321, 324, 334, 345, 351, 359, 370, 378, 390, 406, 416, 423, 428, 439, 446, 449, 455, 464, 471, 474, 480, 482, 488, 493, 499, 505, 511, 514, 530, 539, 542, 547, 550, 553, 557, 561, 565, 570, 575, 580, 585, 591, 594, 602, 606, 609, 619, 626, 634, 637, 643, 651, 656, 663, 670, 678, 685, 690, 695, 702, 706, 708, 712, 715, 720, 725, 730, 734, 738, 742, 748, 751, 754, 757, 763}
|
||||
var _FeatureID_index = [...]uint16{0, 7, 10, 15, 23, 34, 41, 48, 55, 58, 62, 72, 84, 92, 100, 108, 116, 123, 133, 143, 151, 161, 172, 180, 190, 208, 223, 230, 234, 238, 244, 249, 257, 262, 268, 272, 280, 287, 291, 297, 301, 305, 309, 313, 317, 324, 328, 331, 334, 337, 347, 351, 354, 364, 375, 381, 389, 400, 408, 420, 436, 446, 453, 457, 462, 473, 480, 483, 489, 494, 503, 510, 513, 519, 521, 528, 534, 539, 545, 551, 557, 560, 576, 579, 588, 591, 596, 599, 602, 606, 610, 614, 619, 624, 629, 634, 640, 643, 651, 655, 658, 668, 675, 683, 686, 689, 694, 700, 708, 713, 720, 727, 735, 742, 747, 752, 759, 763, 765, 769, 772, 777, 782, 787, 791, 795, 799, 805, 808, 811, 814, 820}
|
||||
|
||||
func (i FeatureID) String() string {
|
||||
if i < 0 || i >= FeatureID(len(_FeatureID_index)-1) {
|
||||
|
||||
2
vendor/github.com/klauspost/cpuid/v2/go.mod
сгенерированный
поставляемый
2
vendor/github.com/klauspost/cpuid/v2/go.mod
сгенерированный
поставляемый
@@ -1,3 +1,3 @@
|
||||
module github.com/klauspost/cpuid/v2
|
||||
|
||||
go 1.13
|
||||
go 1.15
|
||||
|
||||
5
vendor/github.com/klauspost/cpuid/v2/os_other_arm64.go
сгенерированный
поставляемый
5
vendor/github.com/klauspost/cpuid/v2/os_other_arm64.go
сгенерированный
поставляемый
@@ -1,8 +1,7 @@
|
||||
// Copyright (c) 2020 Klaus Post, released under MIT License. See LICENSE file.
|
||||
|
||||
// +build arm64
|
||||
// +build !linux
|
||||
// +build !darwin
|
||||
//go:build arm64 && !linux && !darwin
|
||||
// +build arm64,!linux,!darwin
|
||||
|
||||
package cpuid
|
||||
|
||||
|
||||
3
vendor/github.com/klauspost/cpuid/v2/os_safe_linux_arm64.go
сгенерированный
поставляемый
3
vendor/github.com/klauspost/cpuid/v2/os_safe_linux_arm64.go
сгенерированный
поставляемый
@@ -1,6 +1,7 @@
|
||||
// Copyright (c) 2021 Klaus Post, released under MIT License. See LICENSE file.
|
||||
|
||||
//+build nounsafe
|
||||
//go:build nounsafe
|
||||
// +build nounsafe
|
||||
|
||||
package cpuid
|
||||
|
||||
|
||||
3
vendor/github.com/klauspost/cpuid/v2/os_unsafe_linux_arm64.go
сгенерированный
поставляемый
3
vendor/github.com/klauspost/cpuid/v2/os_unsafe_linux_arm64.go
сгенерированный
поставляемый
@@ -1,6 +1,7 @@
|
||||
// Copyright (c) 2021 Klaus Post, released under MIT License. See LICENSE file.
|
||||
|
||||
//+build !nounsafe
|
||||
//go:build !nounsafe
|
||||
// +build !nounsafe
|
||||
|
||||
package cpuid
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user