Просмотр исходного кода

enabling Reinterpret_ITF in codegen + simple tests before we enable spec tests

Nikolay Korovaiko 9 лет назад
Родитель
Сommit
97847fcfdc

+ 7 - 2
lib/Backend/IRBuilderAsmJs.cpp

@@ -2688,8 +2688,9 @@ IRBuilderAsmJs::BuildFloat1Double1(Js::OpCodeAsmJs newOpcode, uint32 offset, Js:
 void
 IRBuilderAsmJs::BuildFloat1Int1(Js::OpCodeAsmJs newOpcode, uint32 offset, Js::RegSlot dstRegSlot, Js::RegSlot srcRegSlot)
 {
-    Assert(newOpcode == Js::OpCodeAsmJs::Fround_Int || newOpcode == Js::OpCodeAsmJs::Conv_UTF);
+    Assert(newOpcode == Js::OpCodeAsmJs::Fround_Int || newOpcode == Js::OpCodeAsmJs::Conv_UTF || newOpcode == Js::OpCodeAsmJs::Reinterpret_ITF);
 
+    Js::OpCode op = Js::OpCode::Conv_Prim;
     IR::RegOpnd * srcOpnd = nullptr;
     switch (newOpcode)
     {
@@ -2699,6 +2700,10 @@ IRBuilderAsmJs::BuildFloat1Int1(Js::OpCodeAsmJs newOpcode, uint32 offset, Js::Re
     case Js::OpCodeAsmJs::Conv_UTF:
         srcOpnd = BuildSrcOpnd(srcRegSlot, TyUint32);
         break;
+    case Js::OpCodeAsmJs::Reinterpret_ITF:
+        srcOpnd = BuildSrcOpnd(srcRegSlot, TyInt32);
+        op = Js::OpCode::Reinterpret_Prim;
+        break;
     default:
         Assume(UNREACHED);
     }
@@ -2708,7 +2713,7 @@ IRBuilderAsmJs::BuildFloat1Int1(Js::OpCodeAsmJs newOpcode, uint32 offset, Js::Re
     IR::RegOpnd * dstOpnd = BuildDstOpnd(dstRegSlot, TyFloat32);
     dstOpnd->SetValueType(ValueType::Float);
 
-    IR::Instr * instr = IR::Instr::New(Js::OpCode::Conv_Prim, dstOpnd, srcOpnd, m_func);
+    IR::Instr * instr = IR::Instr::New(op, dstOpnd, srcOpnd, m_func);
     AddInstr(instr, offset);
 }
 

+ 1 - 1
lib/WasmReader/WasmBinaryOpCodes.h

@@ -278,7 +278,7 @@ WASM_UNARY__OPCODE(F64PromoteF32,     0xbb, D_F , Conv_FTD       , false)
 // Reinterpretations
 WASM_UNARY__OPCODE(I32ReinterpretF32, 0xbc, I_F , Reinterpret_FTI, false)
 WASM_UNARY__OPCODE(I64ReinterpretF64, 0xbd, L_D , Nop            , true)
-WASM_UNARY__OPCODE(F32ReinterpretI32, 0xbe, F_I , Reinterpret_ITF, true)
+WASM_UNARY__OPCODE(F32ReinterpretI32, 0xbe, F_I , Reinterpret_ITF, false)
 WASM_UNARY__OPCODE(F64ReinterpretI64, 0xbf, D_L , Nop            , true)
 
 #undef WASM_OPCODE

+ 1 - 5
test/WasmSpec/baselines/endianness.baseline

@@ -34,12 +34,8 @@ endianness.wast:204: $assert_return_56 unexpectedly threw: Error: Compiling wasm
 endianness.wast:205: $assert_return_57 unexpectedly threw: Error: Compiling wasm failed: function wasm-function[5] at offset 6/19: Operator I64ExtendU_I32 NYI
 endianness.wast:206: $assert_return_58 unexpectedly threw: Error: Compiling wasm failed: function wasm-function[5] at offset 6/19: Operator I64ExtendU_I32 NYI
 endianness.wast:207: $assert_return_59 unexpectedly threw: Error: Compiling wasm failed: function wasm-function[5] at offset 6/19: Operator I64ExtendU_I32 NYI
-endianness.wast:209: $assert_return_60 unexpectedly threw: Error: Compiling wasm failed: function f32_store[21] at offset 13/14: Operator F32ReinterpretI32 NYI
-endianness.wast:210: $assert_return_61 unexpectedly threw: Error: Compiling wasm failed: function f32_store[21] at offset 13/14: Operator F32ReinterpretI32 NYI
-endianness.wast:211: $assert_return_62 unexpectedly threw: Error: Compiling wasm failed: function f32_store[21] at offset 13/14: Operator F32ReinterpretI32 NYI
-endianness.wast:212: $assert_return_63 unexpectedly threw: Error: Compiling wasm failed: function f32_store[21] at offset 13/14: Operator F32ReinterpretI32 NYI
 endianness.wast:214: $assert_return_64 unexpectedly threw: Error: Compiling wasm failed: function $assert_return_64[87] at offset 13/25: Operator I64ReinterpretF64 NYI
 endianness.wast:215: $assert_return_65 unexpectedly threw: Error: Compiling wasm failed: function $assert_return_65[88] at offset 13/25: Operator I64ReinterpretF64 NYI
 endianness.wast:216: $assert_return_66 unexpectedly threw: Error: Compiling wasm failed: function $assert_return_66[89] at offset 13/25: Operator I64ReinterpretF64 NYI
 endianness.wast:217: $assert_return_67 unexpectedly threw: Error: Compiling wasm failed: function $assert_return_67[90] at offset 13/25: Operator I64ReinterpretF64 NYI
-24/68 tests passed.
+28/68 tests passed.

+ 8 - 0
test/wasm/f32.baseline

@@ -7,3 +7,11 @@ Infinity
 NaN
 NaN
 NaN
+Reinterpret tests
+0
+NaN
+-1
+-1.0393257141113281
+Infinity
+-Infinity
+NaN

+ 26 - 18
test/wasm/f32.js

@@ -1,18 +1,26 @@
-//-------------------------------------------------------------------------------------------------------
-// Copyright (C) Microsoft Corporation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
-//-------------------------------------------------------------------------------------------------------
-
-const blob = WScript.LoadBinaryFile('f32.wasm');
-const moduleBytesView = new Uint8Array(blob);
-var a = Wasm.instantiateModule(moduleBytesView, {}).exports;
-print(a.min(11, 11.01)); // 11
-print(a.max(11, 11.01)); // 11.010000228881836
-print(a.min(NaN, 11.01)); // NaN
-print(a.max(NaN, 11.01)); // NaN
-print(a.min(11, NaN)); // NaN
-print(a.max(1/0, 11.01)); // Infinity
-print(a.max(11.01, 0/0)); // NaN
-print(a.max(0/0, 11.01)); // NaN
-print(a.max(NaN, -NaN)); // NaN
-
+//-------------------------------------------------------------------------------------------------------
+// Copyright (C) Microsoft Corporation and contributors. All rights reserved.
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
+
+const blob = WScript.LoadBinaryFile('f32.wasm');
+const moduleBytesView = new Uint8Array(blob);
+var a = Wasm.instantiateModule(moduleBytesView, {}).exports;
+print(a.min(11, 11.01)); // 11
+print(a.max(11, 11.01)); // 11.010000228881836
+print(a.min(NaN, 11.01)); // NaN
+print(a.max(NaN, 11.01)); // NaN
+print(a.min(11, NaN)); // NaN
+print(a.max(1/0, 11.01)); // Infinity
+print(a.max(11.01, 0/0)); // NaN
+print(a.max(0/0, 11.01)); // NaN
+print(a.max(NaN, -NaN)); // NaN
+print("Reinterpret tests");
+print(a.reinterpret_f2i(0))
+print(a.reinterpret_f2i(-1)) //NaN
+print(a.reinterpret_f2i(-1082130432));
+print(a.reinterpret_f2i(-1081800544));
+print(a.reinterpret_f2i(2139095040)); //Inf
+print(a.reinterpret_f2i(-8388608)); //-Inf
+print(a.reinterpret_f2i(-8388607)); //NaN
+

BIN
test/wasm/f32.wasm


+ 5 - 0
test/wasm/f32.wast

@@ -11,4 +11,9 @@
   (func (export "max") (param f32) (param f32) (result f32)
     (return (f32.max (get_local 0) (get_local 1)))
     )
+
+  (func (export "reinterpret_f2i") (param i32) (result f32)
+    (return (f32.reinterpret/i32 (get_local 0)))
+    )
+
 )