Skip to content

Commit

Permalink
Use runtime dispatching
Browse files Browse the repository at this point in the history
  • Loading branch information
WojciechMula committed Apr 28, 2022
1 parent c84368d commit 9a5c03b
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions huff0/decompress_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ func decompress4x_main_loop_bmi2(pbr0, pbr1, pbr2, pbr3 *bitReaderShifted,
type decompress4x_main_loop_fn func(pbr0, pbr1, pbr2, pbr3 *bitReaderShifted,
peekBits uint8, buf *byte, tbl *dEntrySingle) uint8

var decompress4x_main_loop decompress4x_main_loop_fn
var decompress4x_8b_main_loop decompress4x_main_loop_fn

// decompress4x_8b_loop_x86 is an x86 assembler implementation
// of Decompress4X when tablelog <= 8 which decodes 4 entries
// per loop.
Expand All @@ -44,16 +41,6 @@ func decompress4x_8b_main_loop_amd64(pbr0, pbr1, pbr2, pbr3 *bitReaderShifted,
func decompress4x_8b_main_loop_bmi2(pbr0, pbr1, pbr2, pbr3 *bitReaderShifted,
peekBits uint8, buf *byte, tbl *dEntrySingle) uint8

func init() {
if cpuinfo.HasBMI2() {
decompress4x_main_loop = decompress4x_main_loop_bmi2
decompress4x_8b_main_loop = decompress4x_8b_main_loop_bmi2
} else {
decompress4x_main_loop = decompress4x_main_loop_amd64
decompress4x_8b_main_loop = decompress4x_8b_main_loop_amd64
}
}

// fallback8BitSize is the size where using Go version is faster.
const fallback8BitSize = 800

Expand All @@ -73,6 +60,9 @@ func (d *Decoder) Decompress4X(dst, src []byte) ([]byte, error) {
if cap(dst) < fallback8BitSize && use8BitTables {
return d.decompress4X8bit(dst, src)
}

bmi2 := cpuinfo.HasBMI2()

var br [4]bitReaderShifted
// Decode "jump table"
start := 6
Expand Down Expand Up @@ -120,9 +110,17 @@ func (d *Decoder) Decompress4X(dst, src []byte) ([]byte, error) {
}

if use8BitTables {
off = decompress4x_8b_main_loop(&br[0], &br[1], &br[2], &br[3], peekBits, &buf[0][0], &single[0])
if bmi2 {
off = decompress4x_8b_main_loop_bmi2(&br[0], &br[1], &br[2], &br[3], peekBits, &buf[0][0], &single[0])
} else {
off = decompress4x_8b_main_loop_amd64(&br[0], &br[1], &br[2], &br[3], peekBits, &buf[0][0], &single[0])
}
} else {
off = decompress4x_main_loop(&br[0], &br[1], &br[2], &br[3], peekBits, &buf[0][0], &single[0])
if bmi2 {
off = decompress4x_main_loop_bmi2(&br[0], &br[1], &br[2], &br[3], peekBits, &buf[0][0], &single[0])
} else {
off = decompress4x_main_loop_amd64(&br[0], &br[1], &br[2], &br[3], peekBits, &buf[0][0], &single[0])
}
}
if debug {
fmt.Print("DEBUG: ")
Expand Down

0 comments on commit 9a5c03b

Please sign in to comment.