Skip to content

Commit

Permalink
Sync up go generate code in _gen
Browse files Browse the repository at this point in the history
  • Loading branch information
fwessels committed Jun 6, 2024
1 parent a4242ed commit c0f2a86
Showing 1 changed file with 41 additions and 5 deletions.
46 changes: 41 additions & 5 deletions _gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,48 @@ import (
)
`)
avx2funcs := string(` fAvx2 = galMulSlicesAvx2
fAvx2Xor = galMulSlicesAvx2Xor
`)

hasCodeGenImpl := string(` return &fAvx2, &fAvx2Xor, codeGen && pshufb && r.o.useAVX2 &&
byteCount >= codeGenMinSize && inputs+outputs >= codeGenMinShards &&
inputs <= codeGenMaxInputs && outputs <= codeGenMaxOutputs`)

if !pshufb {
avx2funcs = ""
hasCodeGenImpl = ` return nil, nil, false // no code generation for generic case (only GFNI cases) `
}

w.WriteString(fmt.Sprintf(`const (
avx2CodeGen = true
maxAvx2Inputs = %d
maxAvx2Outputs = %d
minAvx2Size = 64
)`, inputMax, outputMax))
codeGen = true
codeGenMaxGoroutines = 8
codeGenMaxInputs = %d
codeGenMaxOutputs = %d
minCodeGenSize = 64
)
var (
%s fGFNI = galMulSlicesGFNI
fGFNIXor = galMulSlicesGFNIXor
fAvxGFNI = galMulSlicesAvxGFNI
fAvxGFNIXor = galMulSlicesAvxGFNIXor
)
func (r *reedSolomon) hasCodeGen(byteCount int, inputs, outputs int) (_, _ *func(matrix []byte, in, out [][]byte, start, stop int) int, ok bool) {
%s
}
func (r *reedSolomon) canGFNI(byteCount int, inputs, outputs int) (_, _ *func(matrix []uint64, in, out [][]byte, start, stop int) int, ok bool) {
if r.o.useAvx512GFNI {
return &fGFNI, &fGFNIXor, codeGen &&
byteCount >= codeGenMinSize && inputs+outputs >= codeGenMinShards &&
inputs <= codeGenMaxInputs && outputs <= codeGenMaxOutputs
}
return &fAvxGFNI, &fAvxGFNIXor, codeGen && r.o.useAvxGNFI &&
byteCount >= codeGenMinSize && inputs+outputs >= codeGenMinShards &&
inputs <= codeGenMaxInputs && outputs <= codeGenMaxOutputs
}`, inputMax, outputMax, avx2funcs, hasCodeGenImpl))

if !pshufb {
w.WriteString("\n\nfunc galMulSlicesAvx2(matrix []byte, in, out [][]byte, start, stop int) int { panic(`no pshufb`)}\n")
Expand Down

0 comments on commit c0f2a86

Please sign in to comment.