[Wasm] Define canonical representation for NaNs explicitly instead of depending on Kotlin's one
Surprisingly with `Float.NaN.toRawBits()` you can observe different values, which can lead to different wat files for the same input.
This commit is contained in:
committed by
Space Team
parent
151f5b90c7
commit
590400071b
@@ -146,7 +146,6 @@ class WasmIrToText : SExpressionBuilder() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun f32Str(x: WasmImmediate.ConstF32): String {
|
||||
val bits = x.rawBits.toInt()
|
||||
val v = Float.fromBits(bits)
|
||||
@@ -156,7 +155,8 @@ class WasmIrToText : SExpressionBuilder() {
|
||||
} else {
|
||||
"-"
|
||||
}
|
||||
if (bits != Float.NaN.toRawBits()) {
|
||||
|
||||
if (bits != F32_CANON_NAN) {
|
||||
val customPayload = bits and 0x7fffff
|
||||
"${sign}nan:0x${customPayload.toString(16)}"
|
||||
} else {
|
||||
@@ -182,7 +182,7 @@ class WasmIrToText : SExpressionBuilder() {
|
||||
} else {
|
||||
"-"
|
||||
}
|
||||
if (bits != Double.NaN.toRawBits()) {
|
||||
if (bits != F64_CANON_NAN) {
|
||||
val customPayload = bits and 0xfffffffffffff
|
||||
"${sign}nan:0x${customPayload.toString(16)}"
|
||||
} else {
|
||||
@@ -585,3 +585,7 @@ fun isValidWatIdentifierChar(c: Char): Boolean =
|
||||
// permitted identifiers: '?', '<'
|
||||
|| c in "!#$%&′*+-./:<=>?@\\^_`|~"
|
||||
|| c in "$.@_"
|
||||
|
||||
// https://webassembly.github.io/spec/core/syntax/values.html#floating-point
|
||||
private const val F32_CANON_NAN = 0x7FC0_0000
|
||||
private const val F64_CANON_NAN = 0x7FF8_0000_0000_0000L
|
||||
|
||||
Reference in New Issue
Block a user