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?
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.
you can enable nan canonicalization if you require deterministic nan bit patterns as well
https://docs.rs/wasmtime/latest/wasmtime/struct.Config.html#method.cranelift_nan_canonicalization
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.
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!
Good news, thanks very much.
Last updated: Dec 23 2024 at 12:05 UTC