Skip to content

Commit

Permalink
feat: generate uint32 arith only for babybear and koalabear (#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
gbotrel authored Dec 17, 2024
1 parent afee195 commit b998989
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
5 changes: 4 additions & 1 deletion field/generator/config/field_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ func NewFieldConfig(packageName, elementName, modulus string, useAddChain bool)
}
// pre compute field constants
F.NbBits = bModulus.BitLen()
F.F31 = F.NbBits <= 31
// 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
F.NbWords = len(bModulus.Bits())
F.NbWordsLastIndex = F.NbWords - 1

Expand Down
10 changes: 8 additions & 2 deletions field/generator/generator_asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ func generateARM64(F *config.Field, asm *config.Assembly) (string, error) {
return "", nil
}

os.MkdirAll(asm.BuildDir, 0755)
err := os.MkdirAll(asm.BuildDir, 0755)
if err != nil {
return "", fmt.Errorf("failed to create directory %s: %w", asm.BuildDir, err)
}
pathSrc := filepath.Join(asm.BuildDir, fmt.Sprintf(arm64.ElementASMFileName, F.NbWords))

hash, ok := mARM64.Load(pathSrc)
Expand Down Expand Up @@ -70,7 +73,10 @@ func generateAMD64(F *config.Field, asm *config.Assembly) (string, error) {
if !F.GenerateOpsAMD64 {
return "", nil
}
os.MkdirAll(asm.BuildDir, 0755)
err := os.MkdirAll(asm.BuildDir, 0755)
if err != nil {
return "", fmt.Errorf("failed to create directory %s: %w", asm.BuildDir, err)
}
pathSrc := filepath.Join(asm.BuildDir, fmt.Sprintf(amd64.ElementASMFileName, F.NbWords))

hash, ok := mAMD64.Load(pathSrc)
Expand Down
8 changes: 5 additions & 3 deletions field/generator/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ func (cfg *generatorConfig) HasFFT() bool {
}

func (cfg *generatorConfig) HasArm64() bool {
return cfg.asmConfig != nil
return cfg.asmConfig != nil && cfg.asmConfig.BuildDir != ""
}

func (cfg *generatorConfig) HasAMD64() bool {
return cfg.asmConfig != nil
return cfg.asmConfig != nil && cfg.asmConfig.BuildDir != ""
}

func WithFFT(cfg *config.FFT) Option {
Expand All @@ -38,7 +38,9 @@ func WithASM(cfg *config.Assembly) Option {
// default options
func generatorOptions(opts ...Option) generatorConfig {
// apply options
opt := generatorConfig{}
opt := generatorConfig{
asmConfig: &config.Assembly{},
}
for _, option := range opts {
option(&opt)
}
Expand Down

0 comments on commit b998989

Please sign in to comment.