From 96b8f12a30099c02d9c70023c355f3fe5d6d9cbb Mon Sep 17 00:00:00 2001 From: Chronos Ouroboros Date: Wed, 14 Nov 2018 21:02:43 -0200 Subject: [PATCH] Fix the code for MODF_RK in the JIT compiler. --- src/scripting/vm/jit_math.cpp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/scripting/vm/jit_math.cpp b/src/scripting/vm/jit_math.cpp index 1fadbb362..7b557cfb3 100644 --- a/src/scripting/vm/jit_math.cpp +++ b/src/scripting/vm/jit_math.cpp @@ -757,21 +757,27 @@ void JitCompiler::EmitMODF_RR() void JitCompiler::EmitMODF_RK() { - auto label = EmitThrowExceptionLabel(X_DIVISION_BY_ZERO); - cc.ptest(regF[C], regF[C]); - cc.je(label); + if (konstf[C] == 0.) + { + EmitThrowException(X_DIVISION_BY_ZERO); + } + else + { + auto tmpPtr = newTempIntPtr(); + cc.mov(tmpPtr, asmjit::imm_ptr(&konstf[C])); - auto tmp = newTempXmmSd(); - cc.movsd(tmp, asmjit::x86::ptr(ToMemAddress(&konstf[C]))); + auto tmp = newTempXmmSd(); + cc.movsd(tmp, asmjit::x86::qword_ptr(tmpPtr)); - auto result = newResultXmmSd(); - auto call = CreateCall([](double a, double b) -> double { - return a - floor(a / b) * b; - }); - call->setRet(0, result); - call->setArg(0, regF[B]); - call->setArg(1, tmp); - cc.movsd(regF[A], result); + auto result = newResultXmmSd(); + auto call = CreateCall([](double a, double b) -> double { + return a - floor(a / b) * b; + }); + call->setRet(0, result); + call->setArg(0, regF[B]); + call->setArg(1, tmp); + cc.movsd(regF[A], result); + } } void JitCompiler::EmitMODF_KR()