Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: generate uint32 arith only for babybear and koalabear #577

Merged
merged 2 commits into from
Dec 17, 2024

Conversation

gbotrel
Copy link
Collaborator

@gbotrel gbotrel commented Dec 16, 2024

To avoid breaking changes on caller side, small fields (< 31bits) will still generate uint64 arith for now.

@gbotrel gbotrel requested a review from ivokub December 16, 2024 16:06
@ivokub
Copy link
Collaborator

ivokub commented Dec 16, 2024

Suggested edit:

diff --git a/field/generator/options.go b/field/generator/options.go
index e89e8b1ad..71f7ee021 100644
--- a/field/generator/options.go
+++ b/field/generator/options.go
@@ -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 {
@@ -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)
 	}

@ivokub
Copy link
Collaborator

ivokub commented Dec 16, 2024

Suggested edit:

diff --git a/field/generator/generator_asm.go b/field/generator/generator_asm.go
index 8726ac7d7..a242433a3 100644
--- a/field/generator/generator_asm.go
+++ b/field/generator/generator_asm.go
@@ -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)
@@ -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)

Copy link
Collaborator

@ivokub ivokub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change looks good. However, I'm still unable to compile the tinyfield in gnark.

In generator.go I get panic as referencing to uninitialized config.Assembly. I suggested edit to make asm generation more precise (have set outputdir). And when looking at code, also handle some more errors.

Copy link
Collaborator

@ivokub ivokub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Now seems to work well with gnark.

@ivokub ivokub merged commit b998989 into master Dec 17, 2024
5 checks passed
@ivokub ivokub deleted the feat/small64bits branch December 17, 2024 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants