| 1 |
function testConversion0(resultType, opcode, paramType, op, expect) { |
| 2 |
if (resultType === 'i64') { |
| 3 |
wasmFullPassI64(`(module |
| 4 |
(func $run (param ${paramType}) (result ${resultType}) |
| 5 |
(${opcode} (local.get 0)) |
| 6 |
) |
| 7 |
)`, expect, {}, `${paramType}.const ${op}`); |
| 8 |
|
| 9 |
// The same, but now the input is a constant. |
| 10 |
wasmFullPassI64(`(module |
| 11 |
(func $run (result ${resultType}) |
| 12 |
(${opcode} (${paramType}.const ${op})) |
| 13 |
) |
| 14 |
)`, expect); |
| 15 |
} else if (paramType === 'i64') { |
| 16 |
wasmFullPass(`(module |
| 17 |
(func $f (param ${paramType}) (result ${resultType}) |
| 18 |
(${opcode} (local.get 0)) |
| 19 |
) |
| 20 |
(func (export "run") (result ${resultType}) |
| 21 |
i64.const ${op} |
| 22 |
call $f |
| 23 |
) |
| 24 |
)`, expect, {}); |
| 25 |
} else { |
| 26 |
wasmFullPass(`(module |
| 27 |
(func (param ${paramType}) (result ${resultType}) |
| 28 |
(${opcode} (local.get 0))) |
| 29 |
(export "run" (func 0)) |
| 30 |
)`, expect, {}, op); |
| 31 |
} |
| 32 |
|
| 33 |
for (var bad of ['i32', 'f32', 'f64', 'i64']) { |
| 34 |
if (bad !== resultType) { |
| 35 |
wasmFailValidateText( |
| 36 |
`(module (func (param ${paramType}) (result ${bad}) (${opcode} (local.get 0))))`, |
| 37 |
mismatchError(resultType, bad) |
| 38 |
); |
| 39 |
} |
| 40 |
|
| 41 |
if (bad !== paramType) { |
| 42 |
wasmFailValidateText( |
| 43 |
`(module (func (param ${bad}) (result ${resultType}) (${opcode} (local.get 0))))`, |
| 44 |
mismatchError(bad, paramType) |
| 45 |
); |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
function testConversion(resultType, opcode, paramType, op, expect) { |
| 51 |
testConversion0(resultType, `${resultType}.${opcode}`, paramType, op, expect); |
| 52 |
} |
| 53 |
|
| 54 |
function testSignExtension(resultType, opcode, paramType, op, expect) { |
| 55 |
testConversion0(resultType, `${resultType}.${opcode}`, paramType, op, expect); |
| 56 |
} |
| 57 |
|
| 58 |
function testTrap(resultType, opcode, paramType, op) { |
| 59 |
let func = wasmEvalText(`(module |
| 60 |
(func |
| 61 |
(param ${paramType}) |
| 62 |
(result ${resultType}) |
| 63 |
(${resultType}.${opcode} (local.get 0)) |
| 64 |
) |
| 65 |
(func |
| 66 |
(param ${paramType}) |
| 67 |
local.get 0 |
| 68 |
call 0 |
| 69 |
drop |
| 70 |
) |
| 71 |
(export "" (func 1)) |
| 72 |
)`).exports[""]; |
| 73 |
|
| 74 |
let expectedError = op === 'nan' ? /invalid conversion to integer/ : /integer overflow/; |
| 75 |
|
| 76 |
assertErrorMessage(() => func(jsify(op)), Error, expectedError); |
| 77 |
} |
| 78 |
|
| 79 |
var p = Math.pow; |
| 80 |
|
| 81 |
testConversion('i32', 'wrap_i64', 'i64', '0x100000028', 40); |
| 82 |
testConversion('i32', 'wrap_i64', 'i64', -10, -10); |
| 83 |
testConversion('i32', 'wrap_i64', 'i64', "0xffffffff7fffffff", 0x7fffffff); |
| 84 |
testConversion('i32', 'wrap_i64', 'i64', "0xffffffff00000000", 0); |
| 85 |
testConversion('i32', 'wrap_i64', 'i64', "0xfffffffeffffffff", -1); |
| 86 |
testConversion('i32', 'wrap_i64', 'i64', "0x1234567801abcdef", 0x01abcdef); |
| 87 |
testConversion('i32', 'wrap_i64', 'i64', "0x8000000000000002", 2); |
| 88 |
|
| 89 |
testConversion('i64', 'extend_i32_s', 'i32', 0, 0); |
| 90 |
testConversion('i64', 'extend_i32_s', 'i32', 1234, 1234); |
| 91 |
testConversion('i64', 'extend_i32_s', 'i32', -567, -567); |
| 92 |
testConversion('i64', 'extend_i32_s', 'i32', 0x7fffffff, "0x000000007fffffff"); |
| 93 |
testConversion('i64', 'extend_i32_s', 'i32', 0x80000000, "0xffffffff80000000"); |
| 94 |
|
| 95 |
testConversion('i64', 'extend_i32_u', 'i32', 0, 0); |
| 96 |
testConversion('i64', 'extend_i32_u', 'i32', 1234, 1234); |
| 97 |
testConversion('i64', 'extend_i32_u', 'i32', -567, "0x00000000fffffdc9"); |
| 98 |
testConversion('i64', 'extend_i32_u', 'i32', -1, "0x00000000ffffffff"); |
| 99 |
testConversion('i64', 'extend_i32_u', 'i32', 0x7fffffff, "0x000000007fffffff"); |
| 100 |
testConversion('i64', 'extend_i32_u', 'i32', 0x80000000, "0x0000000080000000"); |
| 101 |
|
| 102 |
testConversion('f32', 'convert_i64_s', 'i64', 1, 1.0); |
| 103 |
testConversion('f32', 'convert_i64_s', 'i64', -1, -1.0); |
| 104 |
testConversion('f32', 'convert_i64_s', 'i64', 0, 0.0); |
| 105 |
testConversion('f32', 'convert_i64_s', 'i64', "0x7fffffffffffffff", 9223372036854775807.0); |
| 106 |
testConversion('f32', 'convert_i64_s', 'i64', "0x8000000000000000", -9223372036854775808.0); |
| 107 |
testConversion('f32', 'convert_i64_s', 'i64', "0x11db9e76a2483", 314159275180032.0); |
| 108 |
testConversion('f32', 'convert_i64_s', 'i64', "0x7fffffff", 2147483648.0); // closest approx. |
| 109 |
testConversion('f32', 'convert_i64_s', 'i64', "0x80000000", 2147483648.0); |
| 110 |
testConversion('f32', 'convert_i64_s', 'i64', "0x80000001", 2147483648.0); // closest approx. |
| 111 |
|
| 112 |
// Interesting values at the boundaries. |
| 113 |
testConversion('f32', 'convert_i64_s', 'i64', "0x358a09a000000002", 3857906751034621952); |
| 114 |
testConversion('f32', 'convert_i64_s', 'i64', "0x8000004000000001", -9223371487098961920); |
| 115 |
testConversion('f32', 'convert_i64_s', 'i64', "0xffdfffffdfffffff", -9007200328482816); |
| 116 |
testConversion('f32', 'convert_i64_s', 'i64', "0x0020000020000001", 9007200328482816); |
| 117 |
testConversion('f32', 'convert_i64_s', 'i64', "0x7fffff4000000001", 9223371487098961920); |
| 118 |
|
| 119 |
testConversion('f64', 'convert_i64_s', 'i64', 1, 1.0); |
| 120 |
testConversion('f64', 'convert_i64_s', 'i64', -1, -1.0); |
| 121 |
testConversion('f64', 'convert_i64_s', 'i64', 0, 0.0); |
| 122 |
testConversion('f64', 'convert_i64_s', 'i64', "0x7fffffffffffffff", 9223372036854775807.0); |
| 123 |
testConversion('f64', 'convert_i64_s', 'i64', "0x8000000000000000", -9223372036854775808.0); |
| 124 |
testConversion('f64', 'convert_i64_s', 'i64', "0x10969d374b968e", 4669201609102990); |
| 125 |
testConversion('f64', 'convert_i64_s', 'i64', "0x7fffffff", 2147483647.0); |
| 126 |
testConversion('f64', 'convert_i64_s', 'i64', "0x80000000", 2147483648.0); |
| 127 |
testConversion('f64', 'convert_i64_s', 'i64', "0x80000001", 2147483649.0); |
| 128 |
|
| 129 |
testConversion('f32', 'convert_i64_u', 'i64', 1, 1.0); |
| 130 |
testConversion('f32', 'convert_i64_u', 'i64', 0, 0.0); |
| 131 |
testConversion('f32', 'convert_i64_u', 'i64', "0x7fffffffffffffff", 9223372036854775807.0); |
| 132 |
testConversion('f32', 'convert_i64_u', 'i64', "0x8000000000000000", 9223372036854775808.0); |
| 133 |
testConversion('f32', 'convert_i64_u', 'i64', -1, 18446744073709551616.0); |
| 134 |
testConversion('f32', 'convert_i64_u', 'i64', "0xffff0000ffff0000", 18446462598732840000.0); |
| 135 |
|
| 136 |
// Interesting values at the boundaries. |
| 137 |
testConversion('f32', 'convert_i64_u', 'i64', "0x100404900000008", 72128280609685500); |
| 138 |
testConversion('f32', 'convert_i64_u', 'i64', "0x7fffff4000000001", 9223371487098962000); |
| 139 |
testConversion('f32', 'convert_i64_u', 'i64', "0x0020000020000001", 9007200328482816); |
| 140 |
testConversion('f32', 'convert_i64_u', 'i64', "0x7fffffbfffffffff", 9223371487098961920); |
| 141 |
testConversion('f32', 'convert_i64_u', 'i64', "0x8000008000000001", 9223373136366403584); |
| 142 |
testConversion('f32', 'convert_i64_u', 'i64', "0xfffffe8000000001", 18446742974197923840); |
| 143 |
|
| 144 |
testConversion('f64', 'convert_i64_u', 'i64', 1, 1.0); |
| 145 |
testConversion('f64', 'convert_i64_u', 'i64', 0, 0.0); |
| 146 |
testConversion('f64', 'convert_i64_u', 'i64', "0x7fffffffffffffff", 9223372036854775807.0); |
| 147 |
testConversion('f64', 'convert_i64_u', 'i64', "0x8000000000000000", 9223372036854775808.0); |
| 148 |
testConversion('f64', 'convert_i64_u', 'i64', -1, 18446744073709551616.0); |
| 149 |
testConversion('f64', 'convert_i64_u', 'i64', "0xffff0000ffff0000", 18446462603027743000.0); |
| 150 |
testConversion('f64', 'convert_i64_u', 'i64', "0xbf869c3369c26401", 13800889852755077000); |
| 151 |
testConversion('f64', 'convert_i64_u', 'i64', "0x7fffff4000000001", 9223371212221054976); |
| 152 |
testConversion('f64', 'convert_i64_u', 'i64', "0x8000008000000001", 9223372586610589696); |
| 153 |
testConversion('f64', 'convert_i64_u', 'i64', "0xfffffe8000000001", 18446742424442109952); |
| 154 |
|
| 155 |
testConversion('i64', 'trunc_f64_s', 'f64', 0.0, 0); |
| 156 |
testConversion('i64', 'trunc_f64_s', 'f64', "-0.0", 0); |
| 157 |
testConversion('i64', 'trunc_f64_s', 'f64', 1.0, 1); |
| 158 |
testConversion('i64', 'trunc_f64_s', 'f64', 1.1, 1); |
| 159 |
testConversion('i64', 'trunc_f64_s', 'f64', 1.5, 1); |
| 160 |
testConversion('i64', 'trunc_f64_s', 'f64', 1.99, 1); |
| 161 |
testConversion('i64', 'trunc_f64_s', 'f64', 40.1, 40); |
| 162 |
testConversion('i64', 'trunc_f64_s', 'f64', -1.0, -1); |
| 163 |
testConversion('i64', 'trunc_f64_s', 'f64', -1.1, -1); |
| 164 |
testConversion('i64', 'trunc_f64_s', 'f64', -1.5, -1); |
| 165 |
testConversion('i64', 'trunc_f64_s', 'f64', -1.99, -1); |
| 166 |
testConversion('i64', 'trunc_f64_s', 'f64', -2.0, -2); |
| 167 |
testConversion('i64', 'trunc_f64_s', 'f64', 4294967296.1, "0x100000000"); |
| 168 |
testConversion('i64', 'trunc_f64_s', 'f64', -4294967296.8, "0xffffffff00000000"); |
| 169 |
testConversion('i64', 'trunc_f64_s', 'f64', 9223372036854774784.8, "0x7ffffffffffffc00"); |
| 170 |
testConversion('i64', 'trunc_f64_s', 'f64', -9223372036854775808.3, "0x8000000000000000"); |
| 171 |
|
| 172 |
testConversion('i64', 'trunc_f64_u', 'f64', 0.0, 0); |
| 173 |
testConversion('i64', 'trunc_f64_u', 'f64', "-0.0", 0); |
| 174 |
testConversion('i64', 'trunc_f64_u', 'f64', 1.0, 1); |
| 175 |
testConversion('i64', 'trunc_f64_u', 'f64', 1.1, 1); |
| 176 |
testConversion('i64', 'trunc_f64_u', 'f64', 1.5, 1); |
| 177 |
testConversion('i64', 'trunc_f64_u', 'f64', 1.99, 1); |
| 178 |
testConversion('i64', 'trunc_f64_u', 'f64', -0.9, 0); |
| 179 |
testConversion('i64', 'trunc_f64_u', 'f64', 40.1, 40); |
| 180 |
testConversion('i64', 'trunc_f64_u', 'f64', 4294967295, "0xffffffff"); |
| 181 |
testConversion('i64', 'trunc_f64_u', 'f64', 4294967296.1, "0x100000000"); |
| 182 |
testConversion('i64', 'trunc_f64_u', 'f64', 1e8, "0x5f5e100"); |
| 183 |
testConversion('i64', 'trunc_f64_u', 'f64', 1e16, "0x2386f26fc10000"); |
| 184 |
testConversion('i64', 'trunc_f64_u', 'f64', 9223372036854775808, "0x8000000000000000"); |
| 185 |
testConversion('i64', 'trunc_f64_u', 'f64', 18446744073709549568.1, -2048); |
| 186 |
|
| 187 |
testConversion('i64', 'trunc_f32_s', 'f32', 0.0, 0); |
| 188 |
testConversion('i64', 'trunc_f32_s', 'f32', "-0.0", 0); |
| 189 |
testConversion('i64', 'trunc_f32_s', 'f32', 1.0, 1); |
| 190 |
testConversion('i64', 'trunc_f32_s', 'f32', 1.1, 1); |
| 191 |
testConversion('i64', 'trunc_f32_s', 'f32', 1.5, 1); |
| 192 |
testConversion('i64', 'trunc_f32_s', 'f32', 1.99, 1); |
| 193 |
testConversion('i64', 'trunc_f32_s', 'f32', 40.1, 40); |
| 194 |
testConversion('i64', 'trunc_f32_s', 'f32', -1.0, -1); |
| 195 |
testConversion('i64', 'trunc_f32_s', 'f32', -1.1, -1); |
| 196 |
testConversion('i64', 'trunc_f32_s', 'f32', -1.5, -1); |
| 197 |
testConversion('i64', 'trunc_f32_s', 'f32', -1.99, -1); |
| 198 |
testConversion('i64', 'trunc_f32_s', 'f32', -2.0, -2); |
| 199 |
testConversion('i64', 'trunc_f32_s', 'f32', 4294967296.1, "0x100000000"); |
| 200 |
testConversion('i64', 'trunc_f32_s', 'f32', -4294967296.8, "0xffffffff00000000"); |
| 201 |
testConversion('i64', 'trunc_f32_s', 'f32', 9223371487098961920.0, "0x7fffff8000000000"); |
| 202 |
testConversion('i64', 'trunc_f32_s', 'f32', -9223372036854775808.3, "0x8000000000000000"); |
| 203 |
|
| 204 |
testConversion('i64', 'trunc_f32_u', 'f32', 0.0, 0); |
| 205 |
testConversion('i64', 'trunc_f32_u', 'f32', "-0.0", 0); |
| 206 |
testConversion('i64', 'trunc_f32_u', 'f32', 1.0, 1); |
| 207 |
testConversion('i64', 'trunc_f32_u', 'f32', 1.1, 1); |
| 208 |
testConversion('i64', 'trunc_f32_u', 'f32', 1.5, 1); |
| 209 |
testConversion('i64', 'trunc_f32_u', 'f32', 1.99, 1); |
| 210 |
testConversion('i64', 'trunc_f32_u', 'f32', -0.9, 0); |
| 211 |
testConversion('i64', 'trunc_f32_u', 'f32', 40.1, 40); |
| 212 |
testConversion('i64', 'trunc_f32_u', 'f32', 1e8, "0x5f5e100"); |
| 213 |
testConversion('i64', 'trunc_f32_u', 'f32', 4294967296, "0x100000000"); |
| 214 |
testConversion('i64', 'trunc_f32_u', 'f32', 18446742974197923840.0, "0xffffff0000000000"); |
| 215 |
|
| 216 |
testTrap('i64', 'trunc_f64_s', 'f64', 9223372036854776000.0); |
| 217 |
testTrap('i64', 'trunc_f64_s', 'f64', -9223372036854778000.0); |
| 218 |
testTrap('i64', 'trunc_f64_s', 'f64', "nan"); |
| 219 |
testTrap('i64', 'trunc_f64_s', 'f64', "inf"); |
| 220 |
testTrap('i64', 'trunc_f64_s', 'f64', "-inf"); |
| 221 |
|
| 222 |
testTrap('i64', 'trunc_f64_u', 'f64', -1); |
| 223 |
testTrap('i64', 'trunc_f64_u', 'f64', 18446744073709551616.0); |
| 224 |
testTrap('i64', 'trunc_f64_u', 'f64', "nan"); |
| 225 |
testTrap('i64', 'trunc_f64_u', 'f64', "inf"); |
| 226 |
testTrap('i64', 'trunc_f64_u', 'f64', "-inf"); |
| 227 |
|
| 228 |
testTrap('i64', 'trunc_f32_s', 'f32', 9223372036854776000.0); |
| 229 |
testTrap('i64', 'trunc_f32_s', 'f32', -9223372586610630000.0); |
| 230 |
testTrap('i64', 'trunc_f32_s', 'f32', "nan"); |
| 231 |
testTrap('i64', 'trunc_f32_s', 'f32', "inf"); |
| 232 |
testTrap('i64', 'trunc_f32_s', 'f32', "-inf"); |
| 233 |
|
| 234 |
testTrap('i64', 'trunc_f32_u', 'f32', 18446744073709551616.0); |
| 235 |
testTrap('i64', 'trunc_f32_u', 'f32', -1); |
| 236 |
testTrap('i64', 'trunc_f32_u', 'f32', "nan"); |
| 237 |
testTrap('i64', 'trunc_f32_u', 'f32', "inf"); |
| 238 |
testTrap('i64', 'trunc_f32_u', 'f32', "-inf"); |
| 239 |
|
| 240 |
testConversion('i64', 'reinterpret_f64', 'f64', 40.09999999999968, "0x40440ccccccccca0"); |
| 241 |
testConversion('f64', 'reinterpret_i64', 'i64', "0x40440ccccccccca0", 40.09999999999968); |
| 242 |
|
| 243 |
var u64max = '0xffffffffffffffff'; |
| 244 |
var s64max = '0x7fffffffffffffff'; |
| 245 |
var s64min = '-0x8000000000000000'; |
| 246 |
var s32max = 2147483647; |
| 247 |
var s32min = -2147483648; |
| 248 |
|
| 249 |
testConversion('i32', 'trunc_sat_f32_s', 'f32', NaN, 0); |
| 250 |
testConversion('i32', 'trunc_sat_f32_s', 'f32', Infinity, s32max); |
| 251 |
testConversion('i32', 'trunc_sat_f32_s', 'f32', -Infinity, s32min); |
| 252 |
testConversion('i32', 'trunc_sat_f32_s', 'f32', p(2, 31), s32max); |
| 253 |
testConversion('i32', 'trunc_sat_f32_s', 'f32', -p(2, 31) - 256, s32min); |
| 254 |
|
| 255 |
testConversion('i32', 'trunc_sat_f64_s', 'f64', NaN, 0); |
| 256 |
testConversion('i32', 'trunc_sat_f64_s', 'f64', Infinity, s32max); |
| 257 |
testConversion('i32', 'trunc_sat_f64_s', 'f64', -Infinity, s32min); |
| 258 |
testConversion('i32', 'trunc_sat_f64_s', 'f64', p(2, 31), s32max); |
| 259 |
testConversion('i32', 'trunc_sat_f64_s', 'f64', -p(2, 31) - 1, s32min); |
| 260 |
|
| 261 |
testConversion('i32', 'trunc_sat_f32_u', 'f32', NaN, 0); |
| 262 |
testConversion('i32', 'trunc_sat_f32_u', 'f32', Infinity, -1); |
| 263 |
testConversion('i32', 'trunc_sat_f32_u', 'f32', -Infinity, 0); |
| 264 |
testConversion('i32', 'trunc_sat_f32_u', 'f32', -1, 0); |
| 265 |
testConversion('i32', 'trunc_sat_f32_u', 'f32', p(2, 32), -1); |
| 266 |
|
| 267 |
testConversion('i32', 'trunc_sat_f64_u', 'f64', NaN, 0); |
| 268 |
testConversion('i32', 'trunc_sat_f64_u', 'f64', Infinity, -1); |
| 269 |
testConversion('i32', 'trunc_sat_f64_u', 'f64', -Infinity, 0); |
| 270 |
testConversion('i32', 'trunc_sat_f64_u', 'f64', -1, 0); |
| 271 |
testConversion('i32', 'trunc_sat_f64_u', 'f64', p(2, 32), -1); |
| 272 |
|
| 273 |
testConversion('i64', 'trunc_sat_f64_s', 'f64', 9223372036854776000.0, s64max); |
| 274 |
testConversion('i64', 'trunc_sat_f64_s', 'f64', -9223372036854778000.0, s64min); |
| 275 |
testConversion('i64', 'trunc_sat_f64_s', 'f64', 'nan', '0'); |
| 276 |
testConversion('i64', 'trunc_sat_f64_s', 'f64', 'inf', s64max); |
| 277 |
testConversion('i64', 'trunc_sat_f64_s', 'f64', '-inf', s64min); |
| 278 |
|
| 279 |
testConversion('i64', 'trunc_sat_f64_u', 'f64', -1, '0'); |
| 280 |
testConversion('i64', 'trunc_sat_f64_u', 'f64', 18446744073709551616.0, u64max); |
| 281 |
testConversion('i64', 'trunc_sat_f64_u', 'f64', 'nan', '0'); |
| 282 |
testConversion('i64', 'trunc_sat_f64_u', 'f64', 'inf', u64max); |
| 283 |
testConversion('i64', 'trunc_sat_f64_u', 'f64', '-inf', '0'); |
| 284 |
|
| 285 |
testConversion('i64', 'trunc_sat_f32_s', 'f32', 9223372036854776000.0, s64max); |
| 286 |
testConversion('i64', 'trunc_sat_f32_s', 'f32', -9223372586610630000.0, s64min); |
| 287 |
testConversion('i64', 'trunc_sat_f32_s', 'f32', 'nan', '0'); |
| 288 |
testConversion('i64', 'trunc_sat_f32_s', 'f32', 'inf', s64max); |
| 289 |
testConversion('i64', 'trunc_sat_f32_s', 'f32', '-inf', s64min); |
| 290 |
|
| 291 |
testConversion('i64', 'trunc_sat_f32_u', 'f32', 18446744073709551616.0, u64max); |
| 292 |
testConversion('i64', 'trunc_sat_f32_u', 'f32', -1, '0'); |
| 293 |
testConversion('i64', 'trunc_sat_f32_u', 'f32', 'nan', '0'); |
| 294 |
testConversion('i64', 'trunc_sat_f32_u', 'f32', 'inf', u64max); |
| 295 |
testConversion('i64', 'trunc_sat_f32_u', 'f32', '-inf', '0'); |
| 296 |
|
| 297 |
testSignExtension('i32', 'extend8_s', 'i32', 0x7F, 0x7F); |
| 298 |
testSignExtension('i32', 'extend8_s', 'i32', 0x80, -0x80); |
| 299 |
testSignExtension('i32', 'extend16_s', 'i32', 0x7FFF, 0x7FFF); |
| 300 |
testSignExtension('i32', 'extend16_s', 'i32', 0x8000, -0x8000); |
| 301 |
testSignExtension('i64', 'extend8_s', 'i64', 0x7F, 0x7F); |
| 302 |
testSignExtension('i64', 'extend8_s', 'i64', 0x80, -0x80); |
| 303 |
testSignExtension('i64', 'extend16_s', 'i64', 0x7FFF, 0x7FFF); |
| 304 |
testSignExtension('i64', 'extend16_s', 'i64', 0x8000, -0x8000); |
| 305 |
testSignExtension('i64', 'extend_i32_s', 'i32', 0x7FFFFFFF, 0x7FFFFFFF); |
| 306 |
testSignExtension('i64', 'extend_i32_s', 'i32', "0x80000000", "0xFFFFFFFF80000000"); |
| 307 |
|
| 308 |
// i32.trunc_s* : all values in ] -2**31 - 1; 2**31 [ are acceptable. |
| 309 |
// f32: |
| 310 |
testConversion('i32', 'trunc_f32_s', 'f32', 40.1, 40); |
| 311 |
testConversion('i32', 'trunc_f32_s', 'f32', p(2, 31) - 128, p(2, 31) - 128); // last f32 value exactly representable < 2**31. |
| 312 |
testConversion('i32', 'trunc_f32_s', 'f32', -p(2, 31), -p(2,31)); // last f32 value exactly representable > -2**31 - 1. |
| 313 |
|
| 314 |
testTrap('i32', 'trunc_f32_s', 'f32', 'nan'); |
| 315 |
testTrap('i32', 'trunc_f32_s', 'f32', 'inf'); |
| 316 |
testTrap('i32', 'trunc_f32_s', 'f32', '-inf'); |
| 317 |
testTrap('i32', 'trunc_f32_s', 'f32', p(2, 31)); |
| 318 |
testTrap('i32', 'trunc_f32_s', 'f32', -p(2,31) - 256); |
| 319 |
|
| 320 |
testConversion('i32', 'trunc_f64_s', 'f64', 40.1, 40); |
| 321 |
testConversion('i32', 'trunc_f64_s', 'f64', p(2,31) - 0.001, p(2,31) - 1); // example value near the top. |
| 322 |
testConversion('i32', 'trunc_f64_s', 'f64', -p(2,31) - 0.999, -p(2,31)); // example value near the bottom. |
| 323 |
|
| 324 |
// f64: |
| 325 |
testTrap('i32', 'trunc_f64_s', 'f64', 'nan'); |
| 326 |
testTrap('i32', 'trunc_f64_s', 'f64', 'inf'); |
| 327 |
testTrap('i32', 'trunc_f64_s', 'f64', '-inf'); |
| 328 |
testTrap('i32', 'trunc_f64_s', 'f64', p(2,31)); |
| 329 |
testTrap('i32', 'trunc_f64_s', 'f64', -p(2,31) - 1); |
| 330 |
|
| 331 |
// i32.trunc_u* : all values in ] -1; 2**32 [ are acceptable. |
| 332 |
// f32: |
| 333 |
testConversion('i32', 'trunc_f32_u', 'f32', 40.1, 40); |
| 334 |
testConversion('i32', 'trunc_f32_u', 'f32', p(2,31), p(2,31)|0); |
| 335 |
testConversion('i32', 'trunc_f32_u', 'f32', p(2,32) - 256, (p(2,32) - 256)|0); // last f32 value exactly representable < 2**32. |
| 336 |
testConversion('i32', 'trunc_f32_u', 'f32', -0.99, 0); // example value near the bottom. |
| 337 |
|
| 338 |
testTrap('i32', 'trunc_f32_u', 'f32', 'nan'); |
| 339 |
testTrap('i32', 'trunc_f32_u', 'f32', 'inf'); |
| 340 |
testTrap('i32', 'trunc_f32_u', 'f32', '-inf'); |
| 341 |
testTrap('i32', 'trunc_f32_u', 'f32', -1); |
| 342 |
testTrap('i32', 'trunc_f32_u', 'f32', p(2,32)); |
| 343 |
|
| 344 |
// f64: |
| 345 |
testConversion('i32', 'trunc_f64_u', 'f64', 40.1, 40); |
| 346 |
testConversion('i32', 'trunc_f64_u', 'f64', p(2,32) - 0.001, (p(2,32) - 1)|0); // example value near the top. |
| 347 |
testConversion('i32', 'trunc_f64_u', 'f64', -0.99999, 0); // example value near the bottom. |
| 348 |
|
| 349 |
testTrap('i32', 'trunc_f64_u', 'f64', 'nan'); |
| 350 |
testTrap('i32', 'trunc_f64_u', 'f64', 'inf'); |
| 351 |
testTrap('i32', 'trunc_f64_u', 'f64', '-inf'); |
| 352 |
testTrap('i32', 'trunc_f64_u', 'f64', -1); |
| 353 |
testTrap('i32', 'trunc_f64_u', 'f64', p(2,32)); |
| 354 |
|
| 355 |
// Other opcodes. |
| 356 |
testConversion('i32', 'reinterpret_f32', 'f32', 40.1, 1109419622); |
| 357 |
testConversion('f32', 'reinterpret_i32', 'i32', 40, 5.605193857299268e-44); |
| 358 |
|
| 359 |
testConversion('f32', 'convert_i32_s', 'i32', 40, 40); |
| 360 |
testConversion('f32', 'convert_i32_u', 'i32', 40, 40); |
| 361 |
|
| 362 |
testConversion('f64', 'convert_i32_s', 'i32', 40, 40); |
| 363 |
testConversion('f64', 'convert_i32_u', 'i32', 40, 40); |
| 364 |
|
| 365 |
testConversion('f32', 'demote_f64', 'f64', 40.1, 40.099998474121094); |
| 366 |
testConversion('f64', 'promote_f32', 'f32', 40.1, 40.099998474121094); |
| 367 |
|
| 368 |
// Non-canonical NaNs. |
| 369 |
|
| 370 |
// Wasm v1.1 spec 4.3.4 "Conversions", subsection demote(z): if z is a NaN but |
| 371 |
// not canonical, return any NaN. That is, the sign is arbitrary and the |
| 372 |
// payload is arbitrary, except that the most significant bit of the payload |
| 373 |
// must be set. We check simply that a quiet NaN is returned and ignore the |
| 374 |
// sign and payload. |
| 375 |
|
| 376 |
wasmFullPass(` |
| 377 |
(module |
| 378 |
(func (result i32) |
| 379 |
(i32.and |
| 380 |
(i32.const 0x7FC00000) |
| 381 |
(i32.reinterpret_f32 |
| 382 |
(f32.demote_f64 (f64.const -nan:0x4444444444444))))) |
| 383 |
(export "run" (func 0)))`, |
| 384 |
0x7FC00000); |
| 385 |
|
| 386 |
// Wasm v1.1 spec 4.3.4 "Conversions", subsection promote(z): if z is a NaN but |
| 387 |
// not canonical, return any NaN. See above. |
| 388 |
|
| 389 |
wasmFullPass(` |
| 390 |
(module |
| 391 |
(func (result i64) |
| 392 |
(i64.and |
| 393 |
(i64.const 0x7FF8000000000000) |
| 394 |
(i64.reinterpret_f64 (f64.promote_f32 (f32.const -nan:0x222222))))) |
| 395 |
(export "run" (func 0)))`, |
| 396 |
0x7FF8_0000_0000_0000n); |