2022-07-03 10:08:30 +00:00
|
|
|
//go:build !appengine && !noasm && gc
|
|
|
|
// +build !appengine,!noasm,gc
|
|
|
|
|
|
|
|
package s2
|
|
|
|
|
2024-03-11 10:51:13 +00:00
|
|
|
import "github.com/klauspost/compress/internal/race"
|
|
|
|
|
2023-03-30 21:39:55 +00:00
|
|
|
const hasAmd64Asm = true
|
|
|
|
|
2022-07-03 10:08:30 +00:00
|
|
|
// encodeBlock encodes a non-empty src to a guaranteed-large-enough dst. It
|
|
|
|
// assumes that the varint-encoded length of the decompressed bytes has already
|
|
|
|
// been written.
|
|
|
|
//
|
|
|
|
// It also assumes that:
|
2023-02-27 09:21:58 +00:00
|
|
|
//
|
2022-07-03 10:08:30 +00:00
|
|
|
// len(dst) >= MaxEncodedLen(len(src)) &&
|
2023-02-27 09:21:58 +00:00
|
|
|
// minNonLiteralBlockSize <= len(src) && len(src) <= maxBlockSize
|
2022-07-03 10:08:30 +00:00
|
|
|
func encodeBlock(dst, src []byte) (d int) {
|
2024-03-11 10:51:13 +00:00
|
|
|
race.ReadSlice(src)
|
|
|
|
race.WriteSlice(dst)
|
|
|
|
|
2022-07-03 10:08:30 +00:00
|
|
|
const (
|
|
|
|
// Use 12 bit table when less than...
|
|
|
|
limit12B = 16 << 10
|
|
|
|
// Use 10 bit table when less than...
|
|
|
|
limit10B = 4 << 10
|
|
|
|
// Use 8 bit table when less than...
|
|
|
|
limit8B = 512
|
|
|
|
)
|
|
|
|
|
|
|
|
if len(src) >= 4<<20 {
|
|
|
|
return encodeBlockAsm(dst, src)
|
|
|
|
}
|
|
|
|
if len(src) >= limit12B {
|
|
|
|
return encodeBlockAsm4MB(dst, src)
|
|
|
|
}
|
|
|
|
if len(src) >= limit10B {
|
|
|
|
return encodeBlockAsm12B(dst, src)
|
|
|
|
}
|
|
|
|
if len(src) >= limit8B {
|
|
|
|
return encodeBlockAsm10B(dst, src)
|
|
|
|
}
|
|
|
|
if len(src) < minNonLiteralBlockSize {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return encodeBlockAsm8B(dst, src)
|
|
|
|
}
|
|
|
|
|
|
|
|
// encodeBlockBetter encodes a non-empty src to a guaranteed-large-enough dst. It
|
|
|
|
// assumes that the varint-encoded length of the decompressed bytes has already
|
|
|
|
// been written.
|
|
|
|
//
|
|
|
|
// It also assumes that:
|
2023-02-27 09:21:58 +00:00
|
|
|
//
|
2022-07-03 10:08:30 +00:00
|
|
|
// len(dst) >= MaxEncodedLen(len(src)) &&
|
2023-02-27 09:21:58 +00:00
|
|
|
// minNonLiteralBlockSize <= len(src) && len(src) <= maxBlockSize
|
2022-07-03 10:08:30 +00:00
|
|
|
func encodeBlockBetter(dst, src []byte) (d int) {
|
2024-03-11 10:51:13 +00:00
|
|
|
race.ReadSlice(src)
|
|
|
|
race.WriteSlice(dst)
|
|
|
|
|
2022-07-03 10:08:30 +00:00
|
|
|
const (
|
|
|
|
// Use 12 bit table when less than...
|
|
|
|
limit12B = 16 << 10
|
|
|
|
// Use 10 bit table when less than...
|
|
|
|
limit10B = 4 << 10
|
|
|
|
// Use 8 bit table when less than...
|
|
|
|
limit8B = 512
|
|
|
|
)
|
|
|
|
|
|
|
|
if len(src) > 4<<20 {
|
|
|
|
return encodeBetterBlockAsm(dst, src)
|
|
|
|
}
|
|
|
|
if len(src) >= limit12B {
|
|
|
|
return encodeBetterBlockAsm4MB(dst, src)
|
|
|
|
}
|
|
|
|
if len(src) >= limit10B {
|
|
|
|
return encodeBetterBlockAsm12B(dst, src)
|
|
|
|
}
|
|
|
|
if len(src) >= limit8B {
|
|
|
|
return encodeBetterBlockAsm10B(dst, src)
|
|
|
|
}
|
|
|
|
if len(src) < minNonLiteralBlockSize {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return encodeBetterBlockAsm8B(dst, src)
|
|
|
|
}
|
|
|
|
|
|
|
|
// encodeBlockSnappy encodes a non-empty src to a guaranteed-large-enough dst. It
|
|
|
|
// assumes that the varint-encoded length of the decompressed bytes has already
|
|
|
|
// been written.
|
|
|
|
//
|
|
|
|
// It also assumes that:
|
2023-02-27 09:21:58 +00:00
|
|
|
//
|
2022-07-03 10:08:30 +00:00
|
|
|
// len(dst) >= MaxEncodedLen(len(src)) &&
|
2023-02-27 09:21:58 +00:00
|
|
|
// minNonLiteralBlockSize <= len(src) && len(src) <= maxBlockSize
|
2022-07-03 10:08:30 +00:00
|
|
|
func encodeBlockSnappy(dst, src []byte) (d int) {
|
2024-03-11 10:51:13 +00:00
|
|
|
race.ReadSlice(src)
|
|
|
|
race.WriteSlice(dst)
|
|
|
|
|
2022-07-03 10:08:30 +00:00
|
|
|
const (
|
|
|
|
// Use 12 bit table when less than...
|
|
|
|
limit12B = 16 << 10
|
|
|
|
// Use 10 bit table when less than...
|
|
|
|
limit10B = 4 << 10
|
|
|
|
// Use 8 bit table when less than...
|
|
|
|
limit8B = 512
|
|
|
|
)
|
|
|
|
if len(src) >= 64<<10 {
|
|
|
|
return encodeSnappyBlockAsm(dst, src)
|
|
|
|
}
|
|
|
|
if len(src) >= limit12B {
|
|
|
|
return encodeSnappyBlockAsm64K(dst, src)
|
|
|
|
}
|
|
|
|
if len(src) >= limit10B {
|
|
|
|
return encodeSnappyBlockAsm12B(dst, src)
|
|
|
|
}
|
|
|
|
if len(src) >= limit8B {
|
|
|
|
return encodeSnappyBlockAsm10B(dst, src)
|
|
|
|
}
|
|
|
|
if len(src) < minNonLiteralBlockSize {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return encodeSnappyBlockAsm8B(dst, src)
|
|
|
|
}
|
|
|
|
|
|
|
|
// encodeBlockSnappy encodes a non-empty src to a guaranteed-large-enough dst. It
|
|
|
|
// assumes that the varint-encoded length of the decompressed bytes has already
|
|
|
|
// been written.
|
|
|
|
//
|
|
|
|
// It also assumes that:
|
2023-02-27 09:21:58 +00:00
|
|
|
//
|
2022-07-03 10:08:30 +00:00
|
|
|
// len(dst) >= MaxEncodedLen(len(src)) &&
|
2023-02-27 09:21:58 +00:00
|
|
|
// minNonLiteralBlockSize <= len(src) && len(src) <= maxBlockSize
|
2022-07-03 10:08:30 +00:00
|
|
|
func encodeBlockBetterSnappy(dst, src []byte) (d int) {
|
2024-03-11 10:51:13 +00:00
|
|
|
race.ReadSlice(src)
|
|
|
|
race.WriteSlice(dst)
|
|
|
|
|
2022-07-03 10:08:30 +00:00
|
|
|
const (
|
|
|
|
// Use 12 bit table when less than...
|
|
|
|
limit12B = 16 << 10
|
|
|
|
// Use 10 bit table when less than...
|
|
|
|
limit10B = 4 << 10
|
|
|
|
// Use 8 bit table when less than...
|
|
|
|
limit8B = 512
|
|
|
|
)
|
|
|
|
if len(src) >= 64<<10 {
|
|
|
|
return encodeSnappyBetterBlockAsm(dst, src)
|
|
|
|
}
|
|
|
|
if len(src) >= limit12B {
|
|
|
|
return encodeSnappyBetterBlockAsm64K(dst, src)
|
|
|
|
}
|
|
|
|
if len(src) >= limit10B {
|
|
|
|
return encodeSnappyBetterBlockAsm12B(dst, src)
|
|
|
|
}
|
|
|
|
if len(src) >= limit8B {
|
|
|
|
return encodeSnappyBetterBlockAsm10B(dst, src)
|
|
|
|
}
|
|
|
|
if len(src) < minNonLiteralBlockSize {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return encodeSnappyBetterBlockAsm8B(dst, src)
|
|
|
|
}
|