فهرست منبع

WASM f32/f64 trunc and nearest to use WasmMath

VS13 CRT doesnt support round and trunc. Using CRT methods when SSE4.1 is
not available will break builds using VS13.

Modified trunc and nearest to use WasmMath library helper when SSE4.1 is not available.
Re enabling the feature and tests.
Arun 9 سال پیش
والد
کامیت
30314c9e18
4فایلهای تغییر یافته به همراه60 افزوده شده و 36 حذف شده
  1. 4 6
      lib/Backend/JnHelperMethod.cpp
  2. 4 4
      lib/WasmReader/WasmBinaryOpCodes.h
  3. 26 0
      test/wasm/misc.baseline
  4. 26 26
      test/wasm/misc.js

+ 4 - 6
lib/Backend/JnHelperMethod.cpp

@@ -221,18 +221,16 @@ DECLSPEC_GUARDIGNORE _NOINLINE void * const GetNonTableMethodAddress(JnHelperMet
         return (float(*)(float))ceil;
 
     case HelperDirectMath_TruncDb:
-        //return (double(*)(double))trunc;
+        return (double(*)(double)) Wasm::WasmMath::Trunc<double>;
 
     case HelperDirectMath_TruncFlt:
-        //return (float(*)(float))trunc;
+        return (float(*)(float)) Wasm::WasmMath::Trunc<float>;
 
     case HelperDirectMath_NearestDb:
-        //return (double(*)(double))round;
+        return (double(*)(double)) Wasm::WasmMath::Nearest<double>;
 
     case HelperDirectMath_NearestFlt:
-        //return (float(*)(float))round;
-        // todo:: change for the right helper
-        return (float(*)(float))ceil;
+        return (float(*)(float)) Wasm::WasmMath::Nearest<float>;
 
     //
     // These are statically initialized to an import thunk, but let's keep them out of the table in case a new CRT changes this

+ 4 - 4
lib/WasmReader/WasmBinaryOpCodes.h

@@ -193,8 +193,8 @@ WASM_UNARY__OPCODE(F32Neg,            0x7c, F_F , Neg_Flt        , false)
 WASM_BINARY_OPCODE(F32CopySign,       0x7d, F_FF, Copysign_Flt   , false)
 WASM_UNARY__OPCODE(F32Ceil,           0x7e, F_F , Ceil_Flt       , false)
 WASM_UNARY__OPCODE(F32Floor,          0x7f, F_F , Floor_Flt      , false)
-WASM_UNARY__OPCODE(F32Trunc,          0x80, F_F , Trunc_Flt      , true)
-WASM_UNARY__OPCODE(F32NearestInt,     0x81, F_F , Nearest_Flt    , true)
+WASM_UNARY__OPCODE(F32Trunc,          0x80, F_F , Trunc_Flt      , false)
+WASM_UNARY__OPCODE(F32NearestInt,     0x81, F_F , Nearest_Flt    , false)
 WASM_UNARY__OPCODE(F32Sqrt,           0x82, F_F , Sqrt_Flt       , false)
 WASM_BINARY_OPCODE(F32Eq,             0x83, I_FF, CmEq_Flt       , false)
 WASM_BINARY_OPCODE(F32Ne,             0x84, I_FF, CmNe_Flt       , false)
@@ -213,8 +213,8 @@ WASM_UNARY__OPCODE(F64Neg,            0x90, D_D , Neg_Db         , false)
 WASM_BINARY_OPCODE(F64CopySign,       0x91, D_DD, Copysign_Db    , true)
 WASM_UNARY__OPCODE(F64Ceil,           0x92, D_D , Ceil_Db        , false)
 WASM_UNARY__OPCODE(F64Floor,          0x93, D_D , Floor_Db       , false)
-WASM_UNARY__OPCODE(F64Trunc,          0x94, D_D , Trunc_Db       , true)
-WASM_UNARY__OPCODE(F64NearestInt,     0x95, D_D , Nearest_Db     , true)
+WASM_UNARY__OPCODE(F64Trunc,          0x94, D_D , Trunc_Db       , false)
+WASM_UNARY__OPCODE(F64NearestInt,     0x95, D_D , Nearest_Db     , false)
 WASM_UNARY__OPCODE(F64Sqrt,           0x96, D_D , Sqrt_Db        , false)
 WASM_BINARY_OPCODE(F64Eq,             0x97, I_DD, CmEq_Db        , false)
 WASM_BINARY_OPCODE(F64Ne,             0x98, I_DD, CmNe_Db        , false)

+ 26 - 0
test/wasm/misc.baseline

@@ -7,5 +7,31 @@
 1
 0
 0
+0
+-1
+NaN
+NaN
+Infinity
+-Infinity
+0
+-1
+NaN
+NaN
+Infinity
+-Infinity
 1
 0
+0
+-1
+-2
+NaN
+NaN
+Infinity
+-Infinity
+0
+-1
+-2
+NaN
+NaN
+Infinity
+-Infinity

+ 26 - 26
test/wasm/misc.js

@@ -15,32 +15,32 @@ print(a.f32copysign(255.0,1.0)); // == 255.0
 print(a.eqz(0)); // == 1
 print(a.eqz(-1)); // == 0
 print(a.eqz(1)); // == 0
-//print(a.trunc(0.5)); // == 0
-//print(a.trunc(-1.5)); // == -1
-//print(a.trunc(NaN)); // == NaN
-//print(a.trunc(-NaN)); // == NaN
-//print(a.trunc(Infinity)); // == Infinity
-//print(a.trunc(-Infinity)); // == -Infinity
-//print(a.f64trunc(0.5)); // == 0
-//print(a.f64trunc(-1.5)); // == -1
-//print(a.f64trunc(NaN)); // == NaN
-//print(a.f64trunc(-NaN)); // == NaN
-//print(a.f64trunc(Infinity)); // == Infinity
-//print(a.f64trunc(-Infinity)); // == -Infinity
+print(a.trunc(0.5)); // == 0
+print(a.trunc(-1.5)); // == -1
+print(a.trunc(NaN)); // == NaN
+print(a.trunc(-NaN)); // == NaN
+print(a.trunc(Infinity)); // == Infinity
+print(a.trunc(-Infinity)); // == -Infinity
+print(a.f64trunc(0.5)); // == 0
+print(a.f64trunc(-1.5)); // == -1
+print(a.f64trunc(NaN)); // == NaN
+print(a.f64trunc(-NaN)); // == NaN
+print(a.f64trunc(Infinity)); // == Infinity
+print(a.f64trunc(-Infinity)); // == -Infinity
 print(a.ifeqz(0)); // == 1
 print(a.ifeqz(-1)); // == 0
-//print(a.nearest(-0.1)); // == 0
-//print(a.nearest(-0.7)); // == -1
-//print(a.nearest(-1.5)); // == -2
-//print(a.nearest(NaN)); // == NaN
-//print(a.nearest(-NaN)); // == NaN
-//print(a.nearest(Infinity)); // == Infinity
-//print(a.nearest(-Infinity)); // == -Infinity
-//print(a.f64nearest(-0.1)); // == 0
-//print(a.f64nearest(-0.7)); // == -1
-//print(a.f64nearest(-1.5)); // == -2
-//print(a.f64nearest(NaN)); // == NaN
-//print(a.f64nearest(-NaN)); // == NaN
-//print(a.f64nearest(Infinity)); // == Infinity
-//print(a.f64nearest(-Infinity)); // == -Infinity
+print(a.nearest(-0.1)); // == 0
+print(a.nearest(-0.7)); // == -1
+print(a.nearest(-1.5)); // == -2
+print(a.nearest(NaN)); // == NaN
+print(a.nearest(-NaN)); // == NaN
+print(a.nearest(Infinity)); // == Infinity
+print(a.nearest(-Infinity)); // == -Infinity
+print(a.f64nearest(-0.1)); // == 0
+print(a.f64nearest(-0.7)); // == -1
+print(a.f64nearest(-1.5)); // == -2
+print(a.f64nearest(NaN)); // == NaN
+print(a.f64nearest(-NaN)); // == NaN
+print(a.f64nearest(Infinity)); // == Infinity
+print(a.f64nearest(-Infinity)); // == -Infinity
 //print(a.f64copysign(255.0,-1.0)); // == -255.0