//go:build !appengine && !noasm && gc
// +build !appengine,!noasm,gc

package s2

import (
	

	
)

const hasAmd64Asm = true

var encPools [4]sync.Pool

// 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:
//
//	len(dst) >= MaxEncodedLen(len(src)) &&
//	minNonLiteralBlockSize <= len(src) && len(src) <= maxBlockSize
func encodeBlock(,  []byte) ( int) {
	race.ReadSlice()
	race.WriteSlice()

	const (
		// Use 12 bit table when less than...
		 = 16 << 10
		// Use 10 bit table when less than...
		 = 4 << 10
		// Use 8 bit table when less than...
		 = 512
	)

	if len() >= 4<<20 {
		const ,  = 65536, 0
		,  := encPools[].Get().(*[]byte)
		if ! {
			 = &[]byte{}
		}
		race.WriteSlice([:])
		defer encPools[].Put()
		return encodeBlockAsm(, , )
	}
	if len() >=  {
		const ,  = 65536, 0
		,  := encPools[].Get().(*[]byte)
		if ! {
			 = &[]byte{}
		}
		race.WriteSlice([:])
		defer encPools[].Put()
		return encodeBlockAsm4MB(, , )
	}
	if len() >=  {
		const ,  = 16384, 1
		,  := encPools[].Get().(*[]byte)
		if ! {
			 = &[]byte{}
		}
		race.WriteSlice([:])
		defer encPools[].Put()
		return encodeBlockAsm12B(, , )
	}
	if len() >=  {
		const ,  = 4096, 2
		,  := encPools[].Get().(*[]byte)
		if ! {
			 = &[]byte{}
		}
		race.WriteSlice([:])
		defer encPools[].Put()
		return encodeBlockAsm10B(, , )
	}
	if len() < minNonLiteralBlockSize {
		return 0
	}
	const ,  = 1024, 3
	,  := encPools[].Get().(*[]byte)
	if ! {
		 = &[]byte{}
	}
	race.WriteSlice([:])
	defer encPools[].Put()
	return encodeBlockAsm8B(, , )
}

var encBetterPools [5]sync.Pool

// 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:
//
//	len(dst) >= MaxEncodedLen(len(src)) &&
//	minNonLiteralBlockSize <= len(src) && len(src) <= maxBlockSize
func encodeBlockBetter(,  []byte) ( int) {
	race.ReadSlice()
	race.WriteSlice()

	const (
		// Use 12 bit table when less than...
		 = 16 << 10
		// Use 10 bit table when less than...
		 = 4 << 10
		// Use 8 bit table when less than...
		 = 512
	)

	if len() > 4<<20 {
		const ,  = 589824, 0
		,  := encBetterPools[].Get().(*[]byte)
		if ! {
			 = &[]byte{}
		}
		race.WriteSlice([:])
		defer encBetterPools[].Put()
		return encodeBetterBlockAsm(, , )
	}
	if len() >=  {
		const ,  = 589824, 0
		,  := encBetterPools[].Get().(*[]byte)
		if ! {
			 = &[]byte{}
		}
		race.WriteSlice([:])
		defer encBetterPools[].Put()

		return encodeBetterBlockAsm4MB(, , )
	}
	if len() >=  {
		const ,  = 81920, 0
		,  := encBetterPools[].Get().(*[]byte)
		if ! {
			 = &[]byte{}
		}
		race.WriteSlice([:])
		defer encBetterPools[].Put()

		return encodeBetterBlockAsm12B(, , )
	}
	if len() >=  {
		const ,  = 20480, 1
		,  := encBetterPools[].Get().(*[]byte)
		if ! {
			 = &[]byte{}
		}
		race.WriteSlice([:])
		defer encBetterPools[].Put()
		return encodeBetterBlockAsm10B(, , )
	}
	if len() < minNonLiteralBlockSize {
		return 0
	}

	const ,  = 5120, 2
	,  := encBetterPools[].Get().(*[]byte)
	if ! {
		 = &[]byte{}
	}
	race.WriteSlice([:])
	defer encBetterPools[].Put()
	return encodeBetterBlockAsm8B(, , )
}

// 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:
//
//	len(dst) >= MaxEncodedLen(len(src)) &&
//	minNonLiteralBlockSize <= len(src) && len(src) <= maxBlockSize
func encodeBlockSnappy(,  []byte) ( int) {
	race.ReadSlice()
	race.WriteSlice()

	const (
		// Use 12 bit table when less than...
		 = 16 << 10
		// Use 10 bit table when less than...
		 = 4 << 10
		// Use 8 bit table when less than...
		 = 512
	)
	if len() > 65536 {
		const ,  = 65536, 0
		,  := encPools[].Get().(*[]byte)
		if ! {
			 = &[]byte{}
		}
		race.WriteSlice([:])
		defer encPools[].Put()
		return encodeSnappyBlockAsm(, , )
	}
	if len() >=  {
		const ,  = 65536, 0
		,  := encPools[].Get().(*[]byte)
		if ! {
			 = &[]byte{}
		}
		race.WriteSlice([:])
		defer encPools[].Put()
		return encodeSnappyBlockAsm64K(, , )
	}
	if len() >=  {
		const ,  = 16384, 1
		,  := encPools[].Get().(*[]byte)
		if ! {
			 = &[]byte{}
		}
		race.WriteSlice([:])
		defer encPools[].Put()
		return encodeSnappyBlockAsm12B(, , )
	}
	if len() >=  {
		const ,  = 4096, 2
		,  := encPools[].Get().(*[]byte)
		if ! {
			 = &[]byte{}
		}
		race.WriteSlice([:])
		defer encPools[].Put()
		return encodeSnappyBlockAsm10B(, , )
	}
	if len() < minNonLiteralBlockSize {
		return 0
	}
	const ,  = 1024, 3
	,  := encPools[].Get().(*[]byte)
	if ! {
		 = &[]byte{}
	}
	race.WriteSlice([:])
	defer encPools[].Put()
	return encodeSnappyBlockAsm8B(, , )
}

// 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:
//
//	len(dst) >= MaxEncodedLen(len(src)) &&
//	minNonLiteralBlockSize <= len(src) && len(src) <= maxBlockSize
func encodeBlockBetterSnappy(,  []byte) ( int) {
	race.ReadSlice()
	race.WriteSlice()

	const (
		// Use 12 bit table when less than...
		 = 16 << 10
		// Use 10 bit table when less than...
		 = 4 << 10
		// Use 8 bit table when less than...
		 = 512
	)
	if len() > 65536 {
		const ,  = 589824, 0
		,  := encBetterPools[].Get().(*[]byte)
		if ! {
			 = &[]byte{}
		}
		race.WriteSlice([:])
		defer encBetterPools[].Put()
		return encodeSnappyBetterBlockAsm(, , )
	}

	if len() >=  {
		const ,  = 294912, 4
		,  := encBetterPools[].Get().(*[]byte)
		if ! {
			 = &[]byte{}
		}
		race.WriteSlice([:])
		defer encBetterPools[].Put()

		return encodeSnappyBetterBlockAsm64K(, , )
	}
	if len() >=  {
		const ,  = 81920, 0
		,  := encBetterPools[].Get().(*[]byte)
		if ! {
			 = &[]byte{}
		}
		race.WriteSlice([:])
		defer encBetterPools[].Put()

		return encodeSnappyBetterBlockAsm12B(, , )
	}
	if len() >=  {
		const ,  = 20480, 1
		,  := encBetterPools[].Get().(*[]byte)
		if ! {
			 = &[]byte{}
		}
		race.WriteSlice([:])
		defer encBetterPools[].Put()
		return encodeSnappyBetterBlockAsm10B(, , )
	}
	if len() < minNonLiteralBlockSize {
		return 0
	}

	const ,  = 5120, 2
	,  := encBetterPools[].Get().(*[]byte)
	if ! {
		 = &[]byte{}
	}
	race.WriteSlice([:])
	defer encBetterPools[].Put()
	return encodeSnappyBetterBlockAsm8B(, , )
}