Skip to content

Commit b9a74ea

Browse files
committed
[MERGE #1813 @Krovatkin] enabling Reinterpret_ITF in codegen + simple tests
Merge pull request #1813 from Krovatkin:reinterpret_master
2 parents 0f1795e + 97847fc commit b9a74ea

File tree

7 files changed

+48
-26
lines changed

7 files changed

+48
-26
lines changed

lib/Backend/IRBuilderAsmJs.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2688,8 +2688,9 @@ IRBuilderAsmJs::BuildFloat1Double1(Js::OpCodeAsmJs newOpcode, uint32 offset, Js:
26882688
void
26892689
IRBuilderAsmJs::BuildFloat1Int1(Js::OpCodeAsmJs newOpcode, uint32 offset, Js::RegSlot dstRegSlot, Js::RegSlot srcRegSlot)
26902690
{
2691-
Assert(newOpcode == Js::OpCodeAsmJs::Fround_Int || newOpcode == Js::OpCodeAsmJs::Conv_UTF);
2691+
Assert(newOpcode == Js::OpCodeAsmJs::Fround_Int || newOpcode == Js::OpCodeAsmJs::Conv_UTF || newOpcode == Js::OpCodeAsmJs::Reinterpret_ITF);
26922692

2693+
Js::OpCode op = Js::OpCode::Conv_Prim;
26932694
IR::RegOpnd * srcOpnd = nullptr;
26942695
switch (newOpcode)
26952696
{
@@ -2699,6 +2700,10 @@ IRBuilderAsmJs::BuildFloat1Int1(Js::OpCodeAsmJs newOpcode, uint32 offset, Js::Re
26992700
case Js::OpCodeAsmJs::Conv_UTF:
27002701
srcOpnd = BuildSrcOpnd(srcRegSlot, TyUint32);
27012702
break;
2703+
case Js::OpCodeAsmJs::Reinterpret_ITF:
2704+
srcOpnd = BuildSrcOpnd(srcRegSlot, TyInt32);
2705+
op = Js::OpCode::Reinterpret_Prim;
2706+
break;
27022707
default:
27032708
Assume(UNREACHED);
27042709
}
@@ -2708,7 +2713,7 @@ IRBuilderAsmJs::BuildFloat1Int1(Js::OpCodeAsmJs newOpcode, uint32 offset, Js::Re
27082713
IR::RegOpnd * dstOpnd = BuildDstOpnd(dstRegSlot, TyFloat32);
27092714
dstOpnd->SetValueType(ValueType::Float);
27102715

2711-
IR::Instr * instr = IR::Instr::New(Js::OpCode::Conv_Prim, dstOpnd, srcOpnd, m_func);
2716+
IR::Instr * instr = IR::Instr::New(op, dstOpnd, srcOpnd, m_func);
27122717
AddInstr(instr, offset);
27132718
}
27142719

lib/WasmReader/WasmBinaryOpCodes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ WASM_UNARY__OPCODE(F64PromoteF32, 0xbb, D_F , Conv_FTD , false)
278278
// Reinterpretations
279279
WASM_UNARY__OPCODE(I32ReinterpretF32, 0xbc, I_F , Reinterpret_FTI, false)
280280
WASM_UNARY__OPCODE(I64ReinterpretF64, 0xbd, L_D , Nop , true)
281-
WASM_UNARY__OPCODE(F32ReinterpretI32, 0xbe, F_I , Reinterpret_ITF, true)
281+
WASM_UNARY__OPCODE(F32ReinterpretI32, 0xbe, F_I , Reinterpret_ITF, false)
282282
WASM_UNARY__OPCODE(F64ReinterpretI64, 0xbf, D_L , Nop , true)
283283

284284
#undef WASM_OPCODE

test/WasmSpec/baselines/endianness.baseline

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,8 @@ endianness.wast:204: $assert_return_56 unexpectedly threw: Error: Compiling wasm
3434
endianness.wast:205: $assert_return_57 unexpectedly threw: Error: Compiling wasm failed: function wasm-function[5] at offset 6/19: Operator I64ExtendU_I32 NYI
3535
endianness.wast:206: $assert_return_58 unexpectedly threw: Error: Compiling wasm failed: function wasm-function[5] at offset 6/19: Operator I64ExtendU_I32 NYI
3636
endianness.wast:207: $assert_return_59 unexpectedly threw: Error: Compiling wasm failed: function wasm-function[5] at offset 6/19: Operator I64ExtendU_I32 NYI
37-
endianness.wast:209: $assert_return_60 unexpectedly threw: Error: Compiling wasm failed: function f32_store[21] at offset 13/14: Operator F32ReinterpretI32 NYI
38-
endianness.wast:210: $assert_return_61 unexpectedly threw: Error: Compiling wasm failed: function f32_store[21] at offset 13/14: Operator F32ReinterpretI32 NYI
39-
endianness.wast:211: $assert_return_62 unexpectedly threw: Error: Compiling wasm failed: function f32_store[21] at offset 13/14: Operator F32ReinterpretI32 NYI
40-
endianness.wast:212: $assert_return_63 unexpectedly threw: Error: Compiling wasm failed: function f32_store[21] at offset 13/14: Operator F32ReinterpretI32 NYI
4137
endianness.wast:214: $assert_return_64 unexpectedly threw: Error: Compiling wasm failed: function $assert_return_64[87] at offset 13/25: Operator I64ReinterpretF64 NYI
4238
endianness.wast:215: $assert_return_65 unexpectedly threw: Error: Compiling wasm failed: function $assert_return_65[88] at offset 13/25: Operator I64ReinterpretF64 NYI
4339
endianness.wast:216: $assert_return_66 unexpectedly threw: Error: Compiling wasm failed: function $assert_return_66[89] at offset 13/25: Operator I64ReinterpretF64 NYI
4440
endianness.wast:217: $assert_return_67 unexpectedly threw: Error: Compiling wasm failed: function $assert_return_67[90] at offset 13/25: Operator I64ReinterpretF64 NYI
45-
24/68 tests passed.
41+
28/68 tests passed.

test/wasm/f32.baseline

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,11 @@ Infinity
77
NaN
88
NaN
99
NaN
10+
Reinterpret tests
11+
0
12+
NaN
13+
-1
14+
-1.0393257141113281
15+
Infinity
16+
-Infinity
17+
NaN

test/wasm/f32.js

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1-
//-------------------------------------------------------------------------------------------------------
2-
// Copyright (C) Microsoft Corporation and contributors. All rights reserved.
3-
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4-
//-------------------------------------------------------------------------------------------------------
5-
6-
const blob = WScript.LoadBinaryFile('f32.wasm');
7-
const moduleBytesView = new Uint8Array(blob);
8-
var a = Wasm.instantiateModule(moduleBytesView, {}).exports;
9-
print(a.min(11, 11.01)); // 11
10-
print(a.max(11, 11.01)); // 11.010000228881836
11-
print(a.min(NaN, 11.01)); // NaN
12-
print(a.max(NaN, 11.01)); // NaN
13-
print(a.min(11, NaN)); // NaN
14-
print(a.max(1/0, 11.01)); // Infinity
15-
print(a.max(11.01, 0/0)); // NaN
16-
print(a.max(0/0, 11.01)); // NaN
17-
print(a.max(NaN, -NaN)); // NaN
18-
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft Corporation and contributors. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
const blob = WScript.LoadBinaryFile('f32.wasm');
7+
const moduleBytesView = new Uint8Array(blob);
8+
var a = Wasm.instantiateModule(moduleBytesView, {}).exports;
9+
print(a.min(11, 11.01)); // 11
10+
print(a.max(11, 11.01)); // 11.010000228881836
11+
print(a.min(NaN, 11.01)); // NaN
12+
print(a.max(NaN, 11.01)); // NaN
13+
print(a.min(11, NaN)); // NaN
14+
print(a.max(1/0, 11.01)); // Infinity
15+
print(a.max(11.01, 0/0)); // NaN
16+
print(a.max(0/0, 11.01)); // NaN
17+
print(a.max(NaN, -NaN)); // NaN
18+
print("Reinterpret tests");
19+
print(a.reinterpret_f2i(0))
20+
print(a.reinterpret_f2i(-1)) //NaN
21+
print(a.reinterpret_f2i(-1082130432));
22+
print(a.reinterpret_f2i(-1081800544));
23+
print(a.reinterpret_f2i(2139095040)); //Inf
24+
print(a.reinterpret_f2i(-8388608)); //-Inf
25+
print(a.reinterpret_f2i(-8388607)); //NaN
26+

test/wasm/f32.wasm

59 Bytes
Binary file not shown.

test/wasm/f32.wast

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@
1111
(func (export "max") (param f32) (param f32) (result f32)
1212
(return (f32.max (get_local 0) (get_local 1)))
1313
)
14+
15+
(func (export "reinterpret_f2i") (param i32) (result f32)
16+
(return (f32.reinterpret/i32 (get_local 0)))
17+
)
18+
1419
)

0 commit comments

Comments
 (0)