Hi,
I am currently working on a WebAssembly backend for the Go compiler. Progress so far is quite good, however I've run into some incompatibilities between the Go spec and the WebAssembly spec in rare edge cases. Here are two examples:
Example 1:
Dividing -1<<63 by -1.
Go spec:
"[...], if the dividend x is the most negative value for the int type of x, the quotient q = x / -1 is equal to x (and r = 0)."
WebAssembly spec:
"Else if j1 divided by j2 is 2^N−1, then the result is undefined."
Example 2:
Converting NaN to int.
Go spec:
"In all non-constant conversions involving floating-point or complex values, if the result type cannot represent the value the conversion succeeds but the result value is implementation-dependent."
WebAssembly spec:
"If z is a NaN, then the result is undefined." [hint: "undefined" means it crashes on V8, so the operation does not succeed]
I am not yet sure how to resolve those situations. Adding checks to every occurrence of those operations would probably affect performance and since those special cases seem like they almost never happen in real world code, it feels to me like the performance impact would not be justified.
Are there any opinions or ideas on this? I could create actual performance benchmarks if desired.
Best,
Richard