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

proposal: math: add math_pure_go flag to avoid assembly code #63270

Open
0x1cc opened this issue Sep 28, 2023 · 4 comments
Open

proposal: math: add math_pure_go flag to avoid assembly code #63270

0x1cc opened this issue Sep 28, 2023 · 4 comments
Labels
Milestone

Comments

@0x1cc
Copy link

0x1cc commented Sep 28, 2023

Introduction

In the current Go math package, when the architecture has a Floating-Point Unit (FPU), it accelerates floating-point computations using assembly code tailored to take advantage of the architecture's FPU. While this approach offers excellent performance, it creates compatibility issues with softfloat. To support softfloat, we can use -gcflags=all=-d=softfloat, which can convert floating-point calculations to softfloat within the compiler, but it doesn't impact any assembly code in the math package. (The related issue can be found here: [link to GitHub issue #62470].)

To address this issue, we propose introducing a new build tag that disables the math package from utilizing FPU-related assembly code for performance optimization, thereby providing support for softfloat.

Proposed Solution

To support softfloat in the Go math package, we propose adding a new build tag, let's call it math_pure_go, that users can apply to disable the use of FPU-specific assembly code in the math package. We can use the math_pure_go build tag to disable the assembly in math package. With the build tag -tags=math_pure_go and -gcflags=all=-d=softfloat, we can support softfloat for all platforms.

go build -gcflags=all=-d=softfloat -tags=math_pure_go

Benefit

  • This enhancement will make the Go math package compatible with softfloat, allowing Go to be used in environments or on architectures where hardware FPU support is not available or desired.
  • Users who require softfloat support will be able to utilize the math package without encountering compatibility issues.
  • The softfloat support is necessary in many scenarios, such as blockchain and cryptographic technologyies.
    • In blockchain technology, where determinism and consistency are critical, using softfloat ensures consistent results across various platforms. This is crucial for achieving consensus among nodes in a decentralized network.
    • Zero-knowledge proofs are cryptographic techniques that rely on precise and consistent mathematical operations. Softfloat support is essential for achieving consistent and predictable results when implementing zero-knowledge proof systems.
  • The proposal aligns with Go's philosophy of providing flexibility and compatibility across various platforms and use cases.
@0x1cc 0x1cc added the Proposal label Sep 28, 2023
@gopherbot gopherbot added this to the Proposal milestone Sep 28, 2023
@0x1cc
Copy link
Author

0x1cc commented Sep 28, 2023

The implementation for softfloat support in the math package can be found in this pull request: GitHub Pull Request #63271.

@ianlancetaylor ianlancetaylor changed the title proposal: Softfloat Support in the Go Math Package affected/package: math proposal: math: add math_pure_go flag to avoid assembly code Sep 28, 2023
@mvdan
Copy link
Member

mvdan commented Sep 28, 2023

What about the existing purego tag? #23172 cc @dsnet

@bcmills
Copy link
Contributor

bcmills commented Sep 28, 2023

While this approach offers excellent performance, it creates compatibility issues with softfloat.

We already have GOMIPS=softfloat, GO386=softfloat, etc. for specifying the use of softfloat implementations on specific platforms — it seems like a mistake to add yet another (orthogonal) way to specify that.

If softfloat support is really needed on WASM platforms, adding a GOWASM=softfloat seems like it would be a cleaner approach.

@FiloSottile
Copy link
Contributor

This should be fixable without a proposal by just adding purego support per #23172. It has other advantages, such as supporting other compilers. TinyGo is currently having to alias symbols in the math package:

https://github.com/tinygo-org/tinygo/blob/731532cd2b6353b60b443343b51296ec0fafae09/compiler/alias.go#L27-L31

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Incoming
Development

No branches or pull requests

5 participants