-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: softfloat support for GOARCH=wasm #62470
Comments
CC @golang/wasm |
This would presumably need to be an option in the |
Have we introduced a |
It seems truly ironic for a WASM implementation not to support floating point. |
ZK technology that supports floating point instructions is much harder than integer ones - especially since most ZK/blockchain applications use high-resolution integers (mostly 256-bit) to perform financial applications such as balance transfer, token swap, compound rate, etc. |
Hi there, I am working with @qizhou trying to deliver a provable WASM program. It would be greatly appreciated if we could be guided the pointers or links which implement f32/f64 as software float simulation (i.e. how the softfloat takes effect, it seems right now that the support is partially), thus we might do some handcraft change ourselves : ) |
Plus can confirm f32 is gone after using -d=softfloat
commands
|
I think this is a problem caused by the incompatibility of the math library with the softfloat compilation option. Take // src/math/floor.go Line 14
func Floor(x float64) float64 {
if haveArchFloor {
return archFloor(x)
}
return floor(x)
} When the compilation architecture is WASM , it will directly uses the corresponding underlying instructions of WASM (src/math/floor_wasm.s). Therefore, softfloat does not work! // src/math/floor_asm.go
//go:build 386 || amd64 || arm64 || ppc64 || ppc64le || s390x || wasm
package math
const haveArchFloor = true |
Okay now it looks more like a bug to me. Is there a way to pass the gcflag into math package in runtime? Or a build flag could help this. |
|
@randall77 Thanks. That makes sense. go/src/internal/buildcfg/cfg.go Line 137 in 0613896
|
Is this something we need a build option for, or could it just be the default behavior? |
Based on what I learned from Qi's proposal and conversation, my understanding is to, add a new build option. |
We have temporarily solved the issue by replacing f64.floor and f64.ceil using the following code (by @0x1cc ):
|
Should this be something we add a wasm arch build tagged file for in the math package? |
Not only for WASM, indeed, math package does not support softfloat well for all platform. In the example (fp.go) provided by Qi, even $ GOOS=linux GOARCH=386 GO386=softfloat go build fp.go
$ go tool objdump -S fp | grep FRNDINT
0x80a56be d9fc FRNDINT
0x80a56ee d9fc FRNDINT FRNDINT (Round to Integer) requires hardware support FPU. If we want to support softfloat for all platform (even for architectures that in general would have FPU), we need to modify the math package. In the current math package, when the architecture has an FPU, it will by default accelerate the computation using assembling code that takes advantage of the architecture's FPU. But this will lead to incompatibility with softfloat. As shown in the example above, |
@0x1cc : that is not a bug. |
But in any case, that's a separate issue than this one. @0x1cc Please open an new issue if you disagree with how softfloat is implemented on 386 (this issue is about wasm). |
@randall77 Thanks! Regarding the softfloat support for WASM, using The math package can leverage assembly code for performance optimization by default. However, when we require softfloat support, we can utilize an option to deactivate this feature. This option will enable softfloat support with |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as resolved.
This comment was marked as resolved.
To support softfloat in the Go math package, we propose adding a new build tag, let's call it go build -gcflags=all=-d=softfloat -tags=math_pure_go For additional details, please refer to the corresponding issue: GitHub Issue #63270. |
Can we close this issue in favor of the new proposal? |
Can you give more detail as to why you would prefer to add another Go platform variant rather than implement support in zkWASM for the necessary floating-point instructions? It seems like either way you'd be emulating floating-point arithmetic using a framework designed for integers. |
@johanbrandhorst Using a Like others, I also don't understand how many people need this feature. Is there enough need here that this is a platform that we ought to support? |
There are two separate questions, as I could think up: |
Note that The closest thing I can find to documentation is from Where did you see a mention of |
I find |
We are working on proving the execution of go-compiled WASM code using zero-knowledge (ZK) (see https://github.com/DelphinusLab/zkWasm). However, the current zkWASM prover cannot support floating point instructions (f32.xxx/f64.xxx). We tried to use
go build -gcflags=all=-d=softfloat
and we found most of the FP instructions are translated to INT ones exceptf64.load
,f64.store
,f64.ceil
,f64.floor
.Q: Is there a way to support softfloat explicitly for WASM or any flags to fully support softfloat?
Test code (fp.go):
Commands
The text was updated successfully, but these errors were encountered: