Michael Ferris před 8 roky
rodič
revize
b525f7cb1f

+ 3 - 1
lib/Backend/IRBuilderAsmJs.cpp

@@ -1549,7 +1549,7 @@ IRBuilderAsmJs::BuildWasmMemAccess(Js::OpCodeAsmJs newOpcode, uint32 offset, uin
     }
     AddInstr(instr, offset);
 
-#if DBG
+#if DBG && defined(ENABLE_WASM)
     if (newOpcode == Js::OpCodeAsmJs::StArrWasm && PHASE_TRACE(Js::WasmMemWritesPhase, m_func))
     {
         IR::Opnd* prevArg = nullptr;
@@ -1727,6 +1727,7 @@ IRBuilderAsmJs::BuildAsmCall(Js::OpCodeAsmJs newOpcode, uint32 offset, Js::ArgSl
         case Js::AsmJsRetType::Which::Void:
             break;
 
+#ifdef ENABLE_WASM_SIMD
         case Js::AsmJsRetType::Which::Float32x4:
             dstRegSlot = GetRegSlotFromSimd128Reg(ret);
             dstOpnd = BuildDstOpnd(dstRegSlot, TySimd128F4);
@@ -1771,6 +1772,7 @@ IRBuilderAsmJs::BuildAsmCall(Js::OpCodeAsmJs newOpcode, uint32 offset, Js::ArgSl
             dstRegSlot = GetRegSlotFromSimd128Reg(ret);
             dstOpnd = BuildDstOpnd(dstRegSlot, TySimd128U16);
             break;
+#endif
         default:
             Assume(UNREACHED);
         }

+ 2 - 0
lib/Backend/LowerMDShared.cpp

@@ -805,6 +805,7 @@ LowererMD::LowerRet(IR::Instr * retInstr)
         case Js::AsmJsRetType::Signed:
             regType = TyInt32;
             break;
+#ifdef ENABLE_WASM_SIMD
         case Js::AsmJsRetType::Float32x4:
             regType = TySimd128F4;
             break;
@@ -841,6 +842,7 @@ LowererMD::LowerRet(IR::Instr * retInstr)
         case Js::AsmJsRetType::Bool8x16:
             regType = TySimd128B16;
             break;
+#endif
         default:
             Assert(UNREACHED);
         }

+ 2 - 0
lib/Backend/amd64/LowererMDArch.cpp

@@ -2075,6 +2075,7 @@ LowererMDArch::LowerExitInstr(IR::ExitInstr * exitInstr)
         case Js::AsmJsRetType::Float:
             retReg = IR::RegOpnd::New(nullptr, this->GetRegReturnAsmJs(TyMachDouble), TyMachDouble, this->m_func);
             break;
+#ifdef ENABLE_WASM_SIMD
         case Js::AsmJsRetType::Int32x4:
             retReg = IR::RegOpnd::New(nullptr, this->GetRegReturnAsmJs(TySimd128I4), TySimd128I4, this->m_func);
             break;
@@ -2111,6 +2112,7 @@ LowererMDArch::LowerExitInstr(IR::ExitInstr * exitInstr)
         case Js::AsmJsRetType::Int64x2:
             retReg = IR::RegOpnd::New(nullptr, this->GetRegReturnAsmJs(TySimd128I2), TySimd128I2, this->m_func);
             break;
+#endif
         case Js::AsmJsRetType::Int64:
         case Js::AsmJsRetType::Signed:
             retReg = IR::RegOpnd::New(nullptr, this->GetRegReturn(TyMachReg), TyMachReg, this->m_func);

+ 9 - 2
lib/Runtime/Language/AsmJsEncoder.cpp

@@ -24,7 +24,13 @@ namespace Js
     template<> int AsmJsEncoder::GetOffset<Var>() const{return AsmJsJitTemplate::Globals::StackVarCount * sizeof( Var );}
     template<> int AsmJsEncoder::GetOffset<double>() const{ return mDoubleOffset; }
     template<> int AsmJsEncoder::GetOffset<float>() const{ return mFloatOffset; }
-    template<> int AsmJsEncoder::GetOffset<AsmJsSIMDValue>() const{ return mSimdOffset; }
+    template<> int AsmJsEncoder::GetOffset<AsmJsSIMDValue>() const { 
+#ifdef ENABLE_WASM_SIMD
+        return mSimdOffset;
+#else
+        return 0;
+#endif
+    }
 
     template<>
     void AsmJsEncoder::ReadOpTemplate<Js::SmallLayout>( OpCodeAsmJs op )
@@ -170,8 +176,9 @@ namespace Js
         mIntOffset = asmInfo->GetIntByteOffset() + GetOffset<Var>();
         mDoubleOffset = asmInfo->GetDoubleByteOffset() + GetOffset<Var>();
         mFloatOffset = asmInfo->GetFloatByteOffset() + GetOffset<Var>();
+#ifdef ENABLE_WASM_SIMD
         mSimdOffset = asmInfo->GetSimdByteOffset() + GetOffset<Var>();
-
+#endif
         NoRecoverMemoryArenaAllocator localAlloc(_u("BE-AsmJsEncoder"), GetPageAllocator(), Js::Throw::OutOfMemory);
         mLocalAlloc = &localAlloc;
 

+ 4 - 0
lib/Runtime/Language/AsmJsEncoder.h

@@ -40,7 +40,9 @@ namespace Js
         ArenaAllocator* mLocalAlloc;
         // Byte offset of first int and double
         int mIntOffset, mDoubleOffset, mFloatOffset;
+#ifdef ENABLE_WASM_SIMD
         int mSimdOffset;
+#endif
         // architecture dependant data to build templatized JIT
         void* mTemplateData;
     public:
@@ -116,6 +118,7 @@ namespace Js
 
         template <class T> void OP_AsmJsLoopBody(const unaligned T* playout);
 
+#ifdef ENABLE_WASM_SIMD
         template <class T> void OP_Simd128_LdF4(const unaligned T* playout);
         template <class T> void OP_Simd128_LdI4(const unaligned T* playout);
         template <class T> void OP_Simd128_LdD2(const unaligned T* playout);
@@ -219,6 +222,7 @@ namespace Js
         template <class T> void OP_Simd128_I_ArgOutF4(const unaligned T* playout);
         template <class T> void OP_Simd128_I_ArgOutI4(const unaligned T* playout);
         template <class T> void OP_Simd128_I_ArgOutD2(const unaligned T* playout);
+#endif // ENABLE_WASM_SIMD
     };
 }
 

+ 2 - 0
lib/Runtime/Language/AsmJsEncoder.inl

@@ -501,6 +501,7 @@ namespace Js
         }
     }
 
+#ifdef ENABLE_WASM_SIMD
     template <class T>
     void Js::AsmJsEncoder::OP_Simd128_LdF4(const unaligned T* playout)
     {
@@ -978,4 +979,5 @@ namespace Js
     {
         AsmJsJitTemplate::Simd128_I_ArgOut_D2::ApplyTemplate(this, mPc, playout->R0, CalculateOffset<AsmJsSIMDValue>(playout->D2_1));
     }
+#endif // ENABLE_WASM_SIMD
 }

+ 2 - 0
lib/Runtime/Language/AsmJsEncoderHandler.inl

@@ -195,6 +195,7 @@ EXDEF3    ( CUSTOM     , InvalidOpCode     , OP_Empty                , Empty
   DEF3_WMS( CUSTOM     , Fround_Int        , OP_SetFroundInt         , Float1Int1    )
   DEF3_WMS( CUSTOM     , AsmJsLoopBodyStart,OP_AsmJsLoopBody                 , AsmUnsigned1  )
 
+#ifdef ENABLE_WASM_SIMD
   DEF3_WMS( CUSTOM                              , Simd128_Ld_F4                 , OP_Simd128_LdF4                   , Float32x4_2            )
   DEF3_WMS( CUSTOM                              , Simd128_Ld_I4                 , OP_Simd128_LdI4                   , Int32x4_2              )
   //DEF3_WMS( CUSTOM                              , Simd128_Ld_D2                 , OP_Simd128_LdD2                   , Float64x2_2            )
@@ -314,6 +315,7 @@ EXDEF3    ( CUSTOM     , InvalidOpCode     , OP_Empty                , Empty
 
   DEF3_WMS( CUSTOM                              , Simd128_ReplaceLane_I4        , OP_Simd128_ReplaceLaneI4          , Int32x4_2Int2)
   DEF3_WMS( CUSTOM                              , Simd128_ReplaceLane_F4        , OP_Simd128_ReplaceLaneF4          , Float32x4_2Int1Float1)
+#endif
 
 // help the caller to undefine all the macros
 #undef DEF2

+ 3 - 1
lib/Runtime/Language/AsmJsTypes.cpp

@@ -302,7 +302,8 @@ namespace Js
         case AsmJS_ToInt32: which_   = Signed; break;
         case AsmJS_ToNumber: which_  = Double; break;
         case AsmJS_FRound: which_    = Float; break;
-        case AsmJS_Int32x4: which_   = Int32x4; break;
+#ifdef ENABLE_WASM_SIMD
+        case AsmJS_Int32x4: which_ = Int32x4; break;
         case AsmJS_Bool32x4: which_ = Bool32x4; break;
         case AsmJS_Bool16x8: which_ = Bool16x8; break;
         case AsmJS_Bool8x16: which_ = Bool8x16; break;
@@ -313,6 +314,7 @@ namespace Js
         case AsmJS_Uint32x4: which_ = Uint32x4; break;
         case AsmJS_Uint16x8: which_ = Uint16x8; break;
         case AsmJS_Uint8x16: which_ = Uint8x16; break;
+#endif
         }
     }
 

+ 0 - 2
lib/Runtime/Language/AsmJsTypes.h

@@ -295,7 +295,6 @@ namespace Js
         inline bool isInt64()const {return which_ == Int64; }
         inline bool isDouble()const {return which_ == Double; }
         inline bool isFloat()const {return which_ == Float; }
-#ifdef ENABLE_WASM_SIMD
         inline bool isInt32x4()const    { return which_ == Int32x4; }
         inline bool isBool32x4()const   { return which_ == Bool32x4; }
         inline bool isBool16x8()const   { return which_ == Bool16x8; }
@@ -311,7 +310,6 @@ namespace Js
                                                  isUint32x4() || isUint16x8() || isUint8x16() ||
                                                  isBool32x4() || isBool16x8() || isBool8x16() ||
                                                  isFloat32x4() || isFloat64x2() ; }
-#endif
         bool operator==( AsmJsVarType rhs ) const;
         bool operator!=( AsmJsVarType rhs ) const;
     };

+ 4 - 0
lib/Runtime/Language/AsmJsUtils.cpp

@@ -390,6 +390,7 @@ namespace Js
             returnValue = JavascriptNumber::NewWithCheck(floatRetVal, scriptContext);
             break;
         }
+#ifdef ENABLE_WASM_SIMD
         case AsmJsRetType::Bool32x4:
         case AsmJsRetType::Bool16x8:
         case AsmJsRetType::Bool8x16:
@@ -404,6 +405,7 @@ namespace Js
         case AsmJsRetType::Uint8x16:
             // Todo:: support test return object (like int64) for wasm.simd
             JavascriptError::ThrowTypeError(scriptContext, WASMERR_InvalidTypeConversion);
+#endif
         default:
             Assume(UNREACHED);
             JavascriptError::ThrowTypeError(scriptContext, WASMERR_InvalidTypeConversion);
@@ -515,6 +517,7 @@ namespace Js
             returnValue = JavascriptNumber::NewWithCheck((double)fval, func->GetScriptContext());
             break;
         }
+#ifdef ENABLE_WASM_SIMD
         case AsmJsRetType::Bool32x4:
         case AsmJsRetType::Bool16x8:
         case AsmJsRetType::Bool8x16:
@@ -542,6 +545,7 @@ namespace Js
             // Todo:: support test return object (like int64) for wasm.simd
             JavascriptError::ThrowTypeError(func->GetScriptContext(), WASMERR_InvalidTypeConversion);
             break;
+#endif
         default:
             Assume(UNREACHED);
             JavascriptError::ThrowTypeError(func->GetScriptContext(), WASMERR_InvalidTypeConversion);

+ 7 - 7
lib/Runtime/Language/InterpreterStackFrame.cpp

@@ -2097,14 +2097,10 @@ namespace Js
         case AsmJsRetType::Uint32x4:
         case AsmJsRetType::Uint16x8:
         case AsmJsRetType::Uint8x16:
-            if (Wasm::Simd::IsEnabled())
-            {
-                *(AsmJsSIMDValue*)retDst = asmJsReturn.simd;
-                break;
-            }
+            Assert(Wasm::Simd::IsEnabled());
+            *(AsmJsSIMDValue*)retDst = asmJsReturn.simd;
+            break;
 #endif
-
-            Assert(UNREACHED);
         // double return
         case AsmJsRetType::Double:
             *(double*)retDst = asmJsReturn.d;
@@ -2159,6 +2155,7 @@ namespace Js
             entryPoint = (void*)(AsmJsInterpreterInt64EP)Js::InterpreterStackFrame::AsmJsInterpreter < int64 > ;
             break;
         }
+#ifdef ENABLE_WASM_SIMD
         case Js::AsmJsRetType::Int32x4:
         case Js::AsmJsRetType::Bool32x4:
         case Js::AsmJsRetType::Bool16x8:
@@ -2174,6 +2171,7 @@ namespace Js
             entryPoint = (void*)Js::InterpreterStackFrame::AsmJsInterpreterSimdJs;
             break;
         }
+#endif
         default:
             Assume(UNREACHED);
         }
@@ -3113,12 +3111,14 @@ namespace Js
                 ++doubleArg;
                 argAddress += sizeof(double);
             }
+#ifdef ENABLE_WASM_SIMD
             else if (Wasm::Simd::IsEnabled() && info->GetArgType(i).isSIMD())
             {
                 *simdArg = *(AsmJsSIMDValue*)argAddress;
                 ++simdArg;
                 argAddress += sizeof(AsmJsSIMDValue);
             }
+#endif
             else
             {
                 AssertMsg(UNREACHED, "Invalid function arg type.");

+ 17 - 10
lib/WasmReader/WasmBinaryReader.cpp

@@ -5,6 +5,23 @@
 
 #include "WasmReaderPch.h"
 
+
+namespace Wasm
+{
+namespace Simd
+{
+bool IsEnabled()
+{
+#ifdef ENABLE_WASM_SIMD
+    return CONFIG_FLAG(WasmSimd);
+#else
+    return false;
+#endif
+}
+
+}
+}
+
 #ifdef ENABLE_WASM
 #include "WasmLimits.h"
 #if ENABLE_DEBUG_CONFIG_OPTIONS
@@ -13,7 +30,6 @@
 
 namespace Wasm
 {
-
 namespace Simd
 {
 void EnsureSimdIsEnabled()
@@ -23,14 +39,6 @@ void EnsureSimdIsEnabled()
         throw WasmCompilationException(_u("Wasm.Simd support is not enabled"));
     }
 }
-bool IsEnabled()
-{
-#ifdef ENABLE_WASM_SIMD
-    return CONFIG_FLAG(WasmSimd);
-#else
-    return false;
-#endif
-}
 }
 
 namespace WasmTypes
@@ -1450,5 +1458,4 @@ void WasmBinaryReader::CheckBytesLeft(uint32 bytesNeeded)
 }
 
 } // namespace Wasm
-
 #endif // ENABLE_WASM