Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion field/asm/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
element_2w/**
element_3w/**
element_7w/**
element_8w/**
element_8w/**
element_6b/**
2 changes: 1 addition & 1 deletion field/generator/asm/amd64/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func GenerateCommonASM(w io.Writer, nbWords, nbBits int, hasVector bool) error {
f.WriteLn("")

if nbWords == 1 {
if nbBits == 31 {
if nbBits <= 31 {
return GenerateF31ASM(f, hasVector)
} else {
panic("not implemented")
Expand Down
2 changes: 1 addition & 1 deletion field/generator/asm/arm64/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func GenerateCommonASM(w io.Writer, nbWords, nbBits int, hasVector bool) error {
f.WriteLn("")

if nbWords == 1 {
if nbBits == 31 {
if nbBits <= 31 {
return GenerateF31ASM(f, hasVector)
} else {
panic("not implemented")
Expand Down
6 changes: 2 additions & 4 deletions field/generator/config/field_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,8 @@ func NewFieldConfig(packageName, elementName, modulus string, useAddChain bool)
}
// pre compute field constants
F.NbBits = bModulus.BitLen()
// note: here we set F31 only for BabyBear and KoalaBear;
// we could do uint32 bit size for all fields with NbBits <= 31, but we keep it as is for now
// to avoid breaking changes
F.F31 = F.ModulusHex == "7f000001" || F.ModulusHex == "78000001" // F.NbBits <= 31

Comment thread
ivokub marked this conversation as resolved.
F.F31 = F.NbBits <= 31
F.NbWords = len(bModulus.Bits())
F.NbWordsLastIndex = F.NbWords - 1

Expand Down
24 changes: 12 additions & 12 deletions field/generator/generator_field.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,16 @@ func generateField(F *config.Field, outputDir, asmDirIncludePath, hashArm64, has

// purego files have no build tags if we don't generate asm
pureGoBuildTag := "purego || (!amd64 && !arm64)"
if !F.GenerateOpsAMD64 && !F.GenerateOpsARM64 {
if !(F.GenerateOpsAMD64 && hashAMD64 != "") && !(F.GenerateOpsARM64 && hashArm64 != "") {
pureGoBuildTag = ""
} else if !F.GenerateOpsARM64 {
} else if !(F.GenerateOpsARM64 && hashArm64 != "") {
pureGoBuildTag = "purego || (!amd64)"
}

pureGoVectorBuildTag := "purego || (!amd64 && !arm64)"
if !F.GenerateVectorOpsAMD64 && !F.GenerateVectorOpsARM64 {
if !(F.GenerateVectorOpsAMD64 && hashAMD64 != "") && !(F.GenerateVectorOpsARM64 && hashArm64 != "") {
pureGoVectorBuildTag = ""
} else if !F.GenerateVectorOpsARM64 {
} else if !(F.GenerateVectorOpsARM64 && hashArm64 != "") {
pureGoVectorBuildTag = "purego || (!amd64)"
}

Expand All @@ -154,18 +154,18 @@ func generateField(F *config.Field, outputDir, asmDirIncludePath, hashArm64, has
g.Go(generate("element_test.go", testFiles))
g.Go(generate("vector_test.go", []string{element.TestVector}))

g.Go(generate("element_amd64.s", []string{element.IncludeASM}, only(F.GenerateOpsAMD64), withBuildTag("!purego"), withData(amd64d)))
g.Go(generate("element_arm64.s", []string{element.IncludeASM}, only(F.GenerateOpsARM64), withBuildTag("!purego"), withData(arm64d)))
g.Go(generate("element_amd64.s", []string{element.IncludeASM}, only(F.GenerateOpsAMD64 && hashAMD64 != ""), withBuildTag("!purego"), withData(amd64d)))
g.Go(generate("element_arm64.s", []string{element.IncludeASM}, only(F.GenerateOpsARM64 && hashArm64 != ""), withBuildTag("!purego"), withData(arm64d)))

g.Go(generate("element_amd64.go", []string{element.OpsAMD64, element.MulDoc}, only(F.GenerateOpsAMD64 && !F.F31), withBuildTag("!purego")))
g.Go(generate("element_arm64.go", []string{element.OpsARM64, element.MulNoCarry, element.Reduce}, only(F.GenerateOpsARM64 && !F.F31), withBuildTag("!purego")))
g.Go(generate("element_amd64.go", []string{element.OpsAMD64, element.MulDoc}, only(F.GenerateOpsAMD64 && !F.F31 && hashAMD64 != ""), withBuildTag("!purego")))
g.Go(generate("element_arm64.go", []string{element.OpsARM64, element.MulNoCarry, element.Reduce}, only(F.GenerateOpsARM64 && !F.F31 && hashArm64 != ""), withBuildTag("!purego")))

g.Go(generate("element_purego.go", []string{element.OpsNoAsm, element.MulCIOS, element.MulNoCarry, element.Reduce, element.MulDoc}, withBuildTag(pureGoBuildTag)))

g.Go(generate("vector_amd64.go", []string{element.VectorOpsAmd64}, only(F.GenerateVectorOpsAMD64 && !F.F31), withBuildTag("!purego")))
g.Go(generate("vector_amd64.go", []string{element.VectorOpsAmd64F31}, only(F.GenerateVectorOpsAMD64 && F.F31), withBuildTag("!purego")))
g.Go(generate("vector_arm64.go", []string{element.VectorOpsArm64}, only(F.GenerateVectorOpsARM64 && !F.F31), withBuildTag("!purego")))
g.Go(generate("vector_arm64.go", []string{element.VectorOpsArm64F31}, only(F.GenerateVectorOpsARM64 && F.F31), withBuildTag("!purego")))
g.Go(generate("vector_amd64.go", []string{element.VectorOpsAmd64}, only(F.GenerateVectorOpsAMD64 && !F.F31 && hashAMD64 != ""), withBuildTag("!purego")))
g.Go(generate("vector_amd64.go", []string{element.VectorOpsAmd64F31}, only(F.GenerateVectorOpsAMD64 && F.F31 && hashAMD64 != ""), withBuildTag("!purego")))
g.Go(generate("vector_arm64.go", []string{element.VectorOpsArm64}, only(F.GenerateVectorOpsARM64 && !F.F31 && hashArm64 != ""), withBuildTag("!purego")))
g.Go(generate("vector_arm64.go", []string{element.VectorOpsArm64F31}, only(F.GenerateVectorOpsARM64 && F.F31 && hashArm64 != ""), withBuildTag("!purego")))

g.Go(generate("vector_purego.go", []string{element.VectorOpsPureGo}, withBuildTag(pureGoVectorBuildTag)))

Expand Down
2 changes: 1 addition & 1 deletion field/generator/internal/templates/element/ops_purego.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func MulBy{{$i}}(x *{{$.ElementName}}) {
// works for 0 <= n <= 32.
//
// N.B. n must be < 33.
func (z *Element) Mul2ExpNegN(x *Element, n uint32) *Element {
func (z *{{.ElementName}}) Mul2ExpNegN(x *{{.ElementName}}, n uint32) *{{.ElementName}} {
v := uint64(x[0]) << (32 - n)
z[0] = montReduce(v)
return z
Expand Down
2 changes: 1 addition & 1 deletion field/generator/internal/templates/element/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,7 @@ func Test{{toTitle .ElementName}}Mul2ExpNegN(t *testing.T) {
genA := gen()

properties.Property("x * 2⁻ᵏ == Mul2ExpNegN(x, k) for 0 <= k <= 32", prop.ForAll(
func(a testPairElement) bool {
func(a testPair{{.ElementName}}) bool {

var b, e, two {{.ElementName}}
var c [33]{{.ElementName}}
Expand Down