Added support for CMP_APPROX to EQV_R and moved the code to a template.

This commit is contained in:
Chronos Ouroboros 2018-11-14 10:22:05 -02:00
parent 99849bc0c5
commit 5375a99cf6
2 changed files with 49 additions and 52 deletions

View file

@ -1219,27 +1219,7 @@ void JitCompiler::EmitLENV2()
void JitCompiler::EmitEQV2_R() void JitCompiler::EmitEQV2_R()
{ {
EmitComparisonOpcode([&](bool check, asmjit::Label& fail, asmjit::Label& success) { 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"); EmitVectorComparison<2> (check, fail, success);
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);
}
}); });
} }
@ -1406,37 +1386,7 @@ void JitCompiler::EmitLENV3()
void JitCompiler::EmitEQV3_R() void JitCompiler::EmitEQV3_R()
{ {
EmitComparisonOpcode([&](bool check, asmjit::Label& fail, asmjit::Label& success) { 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"); EmitVectorComparison<3> (check, fail, success);
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);
}
}); });
} }

View file

@ -72,6 +72,53 @@ private:
pc++; // This instruction uses two instruction slots - skip the next one 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);
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) static uint64_t ToMemAddress(const void *d)
{ {
return (uint64_t)(ptrdiff_t)d; return (uint64_t)(ptrdiff_t)d;