Stream: general

Topic: Will the float number computation be consistent in vary arch


view this post on Zulip Hoping White (Nov 06 2024 at 08:48):

I need to run logic in different architectures that must be consistent for computation. Usually, this is done by keeping all the numbers as integers. But this is cumbersome, I wonder if wasmtime/wasmi can keep the consistency?

view this post on Zulip Lann Martin (Nov 06 2024 at 13:40):

Could you expand on what you are concerned about? The Wasm spec permits nondeterministic NaN propagation in some cases but that shouldn't impact any (non-NaN) numeric results.

view this post on Zulip fitzgen (he/him) (Nov 06 2024 at 17:01):

you can enable nan canonicalization if you require deterministic nan bit patterns as well

view this post on Zulip fitzgen (he/him) (Nov 06 2024 at 17:01):

https://docs.rs/wasmtime/latest/wasmtime/struct.Config.html#method.cranelift_nan_canonicalization

view this post on Zulip Hoping White (Nov 07 2024 at 01:48):

I use wasmtime in gameplay, battle result is generated on the client side, and validated on the server side by replay. The client can be x86, x86_64, armv7, arm64, windows, linux, android or ios. The server side usually is x86_64 linux. The same algorithm may get different results using float numbers in different arches. So I wonder if WASM can keep float number deterministic calculation. We don't consider Nan issue, Nan is an error in our scenario.

view this post on Zulip Chris Fallin (Nov 07 2024 at 02:59):

The answer is yes, then; it will be deterministic by spec and both wasmtime and wasmi are spec-compliant (or aim to be anyway, and divergence in this sense is a bug).

We also do differential execution fuzzing between wasmtime and wasmi so this property should be fairly high-assurance in practice; of course let us know if that's not the case for you!

view this post on Zulip Hoping White (Nov 07 2024 at 06:46):

Good news, thanks very much.


Last updated: Dec 23 2024 at 12:05 UTC