simd_two_register_misc: Factor out common comparison code
Gets rid of a tiny bit of duplicated code.
This commit is contained in:
parent
ed0b84da70
commit
0b1b131ec2
1 changed files with 50 additions and 79 deletions
|
@ -7,6 +7,49 @@
|
||||||
#include "frontend/A64/translate/impl/impl.h"
|
#include "frontend/A64/translate/impl/impl.h"
|
||||||
|
|
||||||
namespace Dynarmic::A64 {
|
namespace Dynarmic::A64 {
|
||||||
|
namespace {
|
||||||
|
enum class ComparisonType {
|
||||||
|
EQ,
|
||||||
|
GE,
|
||||||
|
GT,
|
||||||
|
LE,
|
||||||
|
LT,
|
||||||
|
};
|
||||||
|
|
||||||
|
bool CompareAgainstZero(TranslatorVisitor& v, bool Q, Imm<2> size, Vec Vn, Vec Vd, ComparisonType type) {
|
||||||
|
if (size == 0b11 && !Q) {
|
||||||
|
return v.ReservedValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t esize = 8 << size.ZeroExtend();
|
||||||
|
const size_t datasize = Q ? 128 : 64;
|
||||||
|
|
||||||
|
const IR::U128 operand = v.V(datasize, Vn);
|
||||||
|
const IR::U128 zero = v.ir.ZeroVector();
|
||||||
|
IR::U128 result = [&] {
|
||||||
|
switch (type) {
|
||||||
|
case ComparisonType::EQ:
|
||||||
|
return v.ir.VectorEqual(esize, operand, zero);
|
||||||
|
case ComparisonType::GE:
|
||||||
|
return v.ir.VectorGreaterEqualSigned(esize, operand, zero);
|
||||||
|
case ComparisonType::GT:
|
||||||
|
return v.ir.VectorGreaterSigned(esize, operand, zero);
|
||||||
|
case ComparisonType::LE:
|
||||||
|
return v.ir.VectorLessEqualSigned(esize, operand, zero);
|
||||||
|
case ComparisonType::LT:
|
||||||
|
default:
|
||||||
|
return v.ir.VectorLessSigned(esize, operand, zero);
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
|
||||||
|
if (datasize == 64) {
|
||||||
|
result = v.ir.VectorZeroUpper(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
v.V(datasize, Vd, result);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} // Anonymous namespace
|
||||||
|
|
||||||
bool TranslatorVisitor::CNT(bool Q, Imm<2> size, Vec Vn, Vec Vd) {
|
bool TranslatorVisitor::CNT(bool Q, Imm<2> size, Vec Vn, Vec Vd) {
|
||||||
if (size != 0b00) {
|
if (size != 0b00) {
|
||||||
|
@ -22,77 +65,23 @@ bool TranslatorVisitor::CNT(bool Q, Imm<2> size, Vec Vn, Vec Vd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TranslatorVisitor::CMGE_zero_2(bool Q, Imm<2> size, Vec Vn, Vec Vd) {
|
bool TranslatorVisitor::CMGE_zero_2(bool Q, Imm<2> size, Vec Vn, Vec Vd) {
|
||||||
if (size == 0b11 && !Q) {
|
return CompareAgainstZero(*this, Q, size, Vn, Vd, ComparisonType::GE);
|
||||||
return ReservedValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
const size_t esize = 8 << size.ZeroExtend();
|
|
||||||
const size_t datasize = Q ? 128 : 64;
|
|
||||||
|
|
||||||
const IR::U128 operand = V(datasize, Vn);
|
|
||||||
const IR::U128 zero = ir.ZeroVector();
|
|
||||||
IR::U128 result = ir.VectorGreaterEqualSigned(esize, operand, zero);
|
|
||||||
if (datasize == 64) {
|
|
||||||
result = ir.VectorZeroUpper(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
V(datasize, Vd, result);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TranslatorVisitor::CMGT_zero_2(bool Q, Imm<2> size, Vec Vn, Vec Vd) {
|
bool TranslatorVisitor::CMGT_zero_2(bool Q, Imm<2> size, Vec Vn, Vec Vd) {
|
||||||
if (size == 0b11 && !Q) {
|
return CompareAgainstZero(*this, Q, size, Vn, Vd, ComparisonType::GT);
|
||||||
return ReservedValue();
|
|
||||||
}
|
|
||||||
const size_t esize = 8 << size.ZeroExtend<size_t>();
|
|
||||||
const size_t datasize = Q ? 128 : 64;
|
|
||||||
|
|
||||||
const IR::U128 operand = V(datasize, Vn);
|
|
||||||
const IR::U128 zero = ir.ZeroVector();
|
|
||||||
IR::U128 result = ir.VectorGreaterSigned(esize, operand, zero);
|
|
||||||
if (datasize == 64) {
|
|
||||||
result = ir.VectorZeroUpper(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
V(datasize, Vd, result);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TranslatorVisitor::CMEQ_zero_2(bool Q, Imm<2> size, Vec Vn, Vec Vd) {
|
bool TranslatorVisitor::CMEQ_zero_2(bool Q, Imm<2> size, Vec Vn, Vec Vd) {
|
||||||
if (size == 0b11 && !Q) {
|
return CompareAgainstZero(*this, Q, size, Vn, Vd, ComparisonType::EQ);
|
||||||
return ReservedValue();
|
|
||||||
}
|
|
||||||
const size_t esize = 8 << size.ZeroExtend<size_t>();
|
|
||||||
const size_t datasize = Q ? 128 : 64;
|
|
||||||
|
|
||||||
const IR::U128 operand = V(datasize, Vn);
|
|
||||||
const IR::U128 zero = ir.ZeroVector();
|
|
||||||
IR::U128 result = ir.VectorEqual(esize, operand, zero);
|
|
||||||
if (datasize == 64) {
|
|
||||||
result = ir.VectorZeroUpper(result);
|
|
||||||
}
|
|
||||||
V(datasize, Vd, result);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TranslatorVisitor::CMLE_2(bool Q, Imm<2> size, Vec Vn, Vec Vd) {
|
bool TranslatorVisitor::CMLE_2(bool Q, Imm<2> size, Vec Vn, Vec Vd) {
|
||||||
if (size == 0b11 && !Q) {
|
return CompareAgainstZero(*this, Q, size, Vn, Vd, ComparisonType::LE);
|
||||||
return ReservedValue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t esize = 8 << size.ZeroExtend<size_t>();
|
bool TranslatorVisitor::CMLT_2(bool Q, Imm<2> size, Vec Vn, Vec Vd) {
|
||||||
const size_t datasize = Q ? 128 : 64;
|
return CompareAgainstZero(*this, Q, size, Vn, Vd, ComparisonType::LT);
|
||||||
|
|
||||||
const IR::U128 operand = V(datasize, Vn);
|
|
||||||
const IR::U128 zero = ir.ZeroVector();
|
|
||||||
|
|
||||||
IR::U128 result = ir.VectorLessEqualSigned(esize, operand, zero);
|
|
||||||
if (datasize == 64) {
|
|
||||||
result = ir.VectorZeroUpper(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
V(datasize, Vd, result);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TranslatorVisitor::ABS_2(bool Q, Imm<2> size, Vec Vn, Vec Vd) {
|
bool TranslatorVisitor::ABS_2(bool Q, Imm<2> size, Vec Vn, Vec Vd) {
|
||||||
|
@ -110,24 +99,6 @@ bool TranslatorVisitor::ABS_2(bool Q, Imm<2> size, Vec Vn, Vec Vd) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TranslatorVisitor::CMLT_2(bool Q, Imm<2> size, Vec Vn, Vec Vd) {
|
|
||||||
if (size == 0b11 && !Q) {
|
|
||||||
return ReservedValue();
|
|
||||||
}
|
|
||||||
const size_t esize = 8 << size.ZeroExtend<size_t>();
|
|
||||||
const size_t datasize = Q ? 128 : 64;
|
|
||||||
|
|
||||||
const IR::U128 operand = V(datasize, Vn);
|
|
||||||
const IR::U128 zero = ir.ZeroVector();
|
|
||||||
IR::U128 result = ir.VectorLessSigned(esize, operand, zero);
|
|
||||||
if (datasize == 64) {
|
|
||||||
result = ir.VectorZeroUpper(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
V(datasize, Vd, result);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TranslatorVisitor::XTN(bool Q, Imm<2> size, Vec Vn, Vec Vd) {
|
bool TranslatorVisitor::XTN(bool Q, Imm<2> size, Vec Vn, Vec Vd) {
|
||||||
if (size == 0b11) {
|
if (size == 0b11) {
|
||||||
return ReservedValue();
|
return ReservedValue();
|
||||||
|
|
Loading…
Reference in a new issue