Michael Ferris 8 gadi atpakaļ
vecāks
revīzija
f00b4c495f

+ 7 - 5
lib/Backend/LowerMDShared.cpp

@@ -7008,20 +7008,22 @@ LowererMD::LoadFloatValue(IR::Opnd * opndDst, T value, IR::Instr * instrInsert)
     IR::Opnd * opnd;
 
     void* pValue = nullptr;
-    bool isFloat64 = opndDst->IsFloat64();
+    const bool isFloat64 = opndDst->IsFloat64();
+    IRType irtype = isFloat64 ? TyMachDouble : TyFloat32;
+    // Cast the value to the matching opndDst's type because T might not match
     if (isFloat64)
     {
-        pValue = NativeCodeDataNewNoFixup(instrInsert->m_func->GetNativeCodeDataAllocator(), DoubleType<DataDesc_LowererMD_LoadFloatValue_Double>, value);
+        pValue = NativeCodeDataNewNoFixup(instrInsert->m_func->GetNativeCodeDataAllocator(), DoubleType<DataDesc_LowererMD_LoadFloatValue_Double>, (double)value);
     }
     else
     {
         Assert(opndDst->IsFloat32());
-        pValue = (float*)NativeCodeDataNewNoFixup(instrInsert->m_func->GetNativeCodeDataAllocator(), FloatType<DataDesc_LowererMD_LoadFloatValue_Float>, (float)value);
+        pValue = NativeCodeDataNewNoFixup(instrInsert->m_func->GetNativeCodeDataAllocator(), FloatType<DataDesc_LowererMD_LoadFloatValue_Float>, (float)value);
     }
 
     if (!instrInsert->m_func->IsOOPJIT())
     {
-        opnd = IR::MemRefOpnd::New((void*)pValue, isFloat64 ? TyMachDouble : TyFloat32,
+        opnd = IR::MemRefOpnd::New((void*)pValue, irtype,
             instrInsert->m_func, isFloat64 ? IR::AddrOpndKindDynamicDoubleRef : IR::AddrOpndKindDynamicFloatRef);
     }
     else // OOP JIT
@@ -7034,7 +7036,7 @@ LowererMD::LoadFloatValue(IR::Opnd * opndDst, T value, IR::Instr * instrInsert)
             IR::MemRefOpnd::New(instrInsert->m_func->GetWorkItem()->GetWorkItemData()->nativeDataAddr, TyMachPtr, instrInsert->m_func, IR::AddrOpndKindDynamicNativeCodeDataRef),
             instrInsert);
 
-        opnd = IR::IndirOpnd::New(addressRegOpnd, offset, isFloat64 ? TyMachDouble : TyFloat32,
+        opnd = IR::IndirOpnd::New(addressRegOpnd, offset, irtype,
 #if DBG
             NativeCodeData::GetDataDescription(pValue, instrInsert->m_func->m_alloc),
 #endif

+ 0 - 1
lib/Runtime/Math/CMakeLists.txt

@@ -1,6 +1,5 @@
 add_library (Chakra.Runtime.Math OBJECT
     AsmJsMath.cpp
-    JavascriptSSE2MathOperators.cpp
     RuntimeMathPch.cpp
     )
 

+ 7 - 16
lib/Runtime/Math/WasmMath.inl

@@ -105,27 +105,18 @@ inline int WasmMath::Eqz(T value)
 template<>
 inline double WasmMath::Copysign(double aLeft, double aRight)
 {
-#if _M_IX86
-    double a = *(double*)Js::NumberConstants::AbsDoubleCst;
-    double b = *(double*)Js::NumberConstants::SgnDoubleBitCst;
-    __asm {
-        movq xmm0, aLeft;
-        movq xmm1, aRight;
-        movq xmm2, a;
-        movq xmm3, b;
-        andps xmm0, xmm2;
-        andps xmm1, xmm3;
-        xorps xmm0, xmm1;
-    }
-#else
-    return _copysign(aLeft, aRight);
-#endif
+    uint64 aLeftI64 = *(uint64*)(&aLeft);
+    uint64 aRightI64 = *(uint64*)(&aRight);
+    uint64 res = ((aLeftI64 & 0x7fffffffffffffffull) | (aRightI64 & 0x8000000000000000ull));
+    return *(double*)(&res);
 }
 
 template<>
 inline float WasmMath::Copysign(float aLeft, float aRight)
 {
-    uint32 res = ((*(uint32*)(&aLeft) & 0x7fffffffu) | (*(uint32*)(&aRight) & 0x80000000u));
+    uint32 aLeftI32 = *(uint32*)(&aLeft);
+    uint32 aRightI32 = *(uint32*)(&aRight);
+    uint32 res = ((aLeftI32 & 0x7fffffffu) | (aRightI32 & 0x80000000u));
     return *(float*)(&res);
 }