This commit is contained in:
Rachael Alexanderson 2018-11-15 10:36:51 -05:00
commit 228a9881b3
2 changed files with 75 additions and 65 deletions

View file

@ -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, double, double>([](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, double, double>([](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()
@ -1219,27 +1225,7 @@ void JitCompiler::EmitLENV2()
void JitCompiler::EmitEQV2_R()
{
EmitComparisonOpcode([&](bool check, asmjit::Label& fail, asmjit::Label& success) {
if (static_cast<bool>(A & CMP_APPROX)) I_FatalError("CMP_APPROX not implemented for EQV2_R.\n");
cc.ucomisd(regF[B], regF[C]);
if (check) {
cc.jp(success);
cc.jne(success);
}
else {
cc.jp(fail);
cc.jne(fail);
}
cc.ucomisd(regF[B + 1], regF[C + 1]);
if (check) {
cc.jp(success);
cc.je(fail);
}
else {
cc.jp(fail);
cc.jne(fail);
}
EmitVectorComparison<2> (check, fail, success);
});
}
@ -1406,37 +1392,7 @@ void JitCompiler::EmitLENV3()
void JitCompiler::EmitEQV3_R()
{
EmitComparisonOpcode([&](bool check, asmjit::Label& fail, asmjit::Label& success) {
if (static_cast<bool>(A & CMP_APPROX)) I_FatalError("CMP_APPROX not implemented for EQV3_R.\n");
cc.ucomisd(regF[B], regF[C]);
if (check) {
cc.jp(success);
cc.jne(success);
}
else {
cc.jp(fail);
cc.jne(fail);
}
cc.ucomisd(regF[B + 1], regF[C + 1]);
if (check) {
cc.jp(success);
cc.jne(success);
}
else {
cc.jp(fail);
cc.jne(fail);
}
cc.ucomisd(regF[B + 2], regF[C + 2]);
if (check) {
cc.jp(success);
cc.je(fail);
}
else {
cc.jp(fail);
cc.jne(fail);
}
EmitVectorComparison<3> (check, fail, success);
});
}

View file

@ -72,6 +72,60 @@ private:
pc++; // This instruction uses two instruction slots - skip the next one
}
template<int N>
void EmitVectorComparison(bool check, asmjit::Label& fail, asmjit::Label& success)
{
bool approx = static_cast<bool>(A & CMP_APPROX);
if (!approx)
{
for (int i = 0; i < N; i++)
{
cc.ucomisd(regF[B + i], regF[C + i]);
if (check)
{
cc.jp(success);
if (i == (N - 1))
{
cc.je(fail);
}
else
{
cc.jne(success);
}
}
else
{
cc.jp(fail);
cc.jne(fail);
}
}
}
else
{
auto tmp = newTempXmmSd();
const int64_t absMaskInt = 0x7FFFFFFFFFFFFFFF;
auto absMask = cc.newDoubleConst(asmjit::kConstScopeLocal, reinterpret_cast<const double&>(absMaskInt));
auto absMaskXmm = newTempXmmPd();
auto epsilon = cc.newDoubleConst(asmjit::kConstScopeLocal, VM_EPSILON);
auto epsilonXmm = newTempXmmSd();
for (int i = 0; i < N; i++)
{
cc.movsd(tmp, regF[B + i]);
cc.subsd(tmp, regF[C + i]);
cc.movsd(absMaskXmm, absMask);
cc.andpd(tmp, absMaskXmm);
cc.movsd(epsilonXmm, epsilon);
cc.ucomisd(epsilonXmm, tmp);
if (check) cc.ja(fail);
else cc.jna(fail);
}
}
}
static uint64_t ToMemAddress(const void *d)
{
return (uint64_t)(ptrdiff_t)d;