From 06f7229c57b616e84c0d63e3fce1a2a6165f9e38 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 20 Jun 2020 15:48:20 -0400 Subject: [PATCH] A32: Implement ASIMD VPADAL (integer) --- src/frontend/A32/decoder/asimd.inc | 2 +- .../translate/impl/asimd_two_regs_misc.cpp | 59 +++++++++++++------ .../A32/translate/impl/translate_arm.h | 1 + 3 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/frontend/A32/decoder/asimd.inc b/src/frontend/A32/decoder/asimd.inc index a57ab0a4..642a2a62 100644 --- a/src/frontend/A32/decoder/asimd.inc +++ b/src/frontend/A32/decoder/asimd.inc @@ -86,7 +86,7 @@ INST(asimd_VCLS, "VCLS", "111100111D11zz00dddd010 INST(asimd_VCLZ, "VCLZ", "111100111D11zz00dddd01001QM0mmmm") // ASIMD INST(asimd_VCNT, "VCNT", "111100111D11zz00dddd01010QM0mmmm") // ASIMD INST(asimd_VMVN_reg, "VMVN_reg", "111100111D11zz00dddd01011QM0mmmm") // ASIMD -//INST(asimd_VPADAL, "VPADAL", "111100111-11--00----0110xx-0----") // ASIMD +INST(asimd_VPADAL, "VPADAL", "111100111D11zz00dddd0110oQM0mmmm") // ASIMD INST(asimd_VQABS, "VQABS", "111100111D11zz00dddd01110QM0mmmm") // ASIMD INST(asimd_VQNEG, "VQNEG", "111100111D11zz00dddd01111QM0mmmm") // ASIMD INST(asimd_VCGT_zero, "VCGT (zero)", "111100111D11zz01dddd0F000QM0mmmm") // ASIMD diff --git a/src/frontend/A32/translate/impl/asimd_two_regs_misc.cpp b/src/frontend/A32/translate/impl/asimd_two_regs_misc.cpp index 27f4dd65..c1764caa 100644 --- a/src/frontend/A32/translate/impl/asimd_two_regs_misc.cpp +++ b/src/frontend/A32/translate/impl/asimd_two_regs_misc.cpp @@ -67,6 +67,42 @@ bool CompareWithZero(ArmTranslatorVisitor& v, bool D, size_t sz, size_t Vd, bool return true; } +enum class AccumulateBehavior { + None, + Accumulate, +}; + +bool PairedAddOperation(ArmTranslatorVisitor& v, bool D, size_t sz, size_t Vd, bool op, bool Q, bool M, size_t Vm, + AccumulateBehavior accumulate) { + if (sz == 0b11) { + return v.UndefinedInstruction(); + } + + if (Q && (Common::Bit<0>(Vd) || Common::Bit<0>(Vm))) { + return v.UndefinedInstruction(); + } + + const size_t esize = 8U << sz; + const auto d = ToVector(Q, Vd, D); + const auto m = ToVector(Q, Vm, M); + + const auto reg_m = v.ir.GetVector(m); + const auto result = [&] { + const auto tmp = op ? v.ir.VectorPairedAddUnsignedWiden(esize, reg_m) + : v.ir.VectorPairedAddSignedWiden(esize, reg_m); + + if (accumulate == AccumulateBehavior::Accumulate) { + const auto reg_d = v.ir.GetVector(d); + return v.ir.VectorAdd(esize * 2, reg_d, tmp); + } + + return tmp; + }(); + + v.ir.SetVector(d, result); + return true; +} + } // Anonymous namespace bool ArmTranslatorVisitor::asimd_VREV(bool D, size_t sz, size_t Vd, size_t op, bool Q, bool M, size_t Vm) { @@ -130,24 +166,7 @@ bool ArmTranslatorVisitor::asimd_VREV(bool D, size_t sz, size_t Vd, size_t op, b } bool ArmTranslatorVisitor::asimd_VPADDL(bool D, size_t sz, size_t Vd, bool op, bool Q, bool M, size_t Vm) { - if (sz == 0b11) { - return UndefinedInstruction(); - } - - if (Q && (Common::Bit<0>(Vd) || Common::Bit<0>(Vm))) { - return UndefinedInstruction(); - } - - const size_t esize = 8U << sz; - const auto d = ToVector(Q, Vd, D); - const auto m = ToVector(Q, Vm, M); - - const auto reg_m = ir.GetVector(m); - const auto result = op ? ir.VectorPairedAddUnsignedWiden(esize, reg_m) - : ir.VectorPairedAddSignedWiden(esize, reg_m); - - ir.SetVector(d, result); - return true; + return PairedAddOperation(*this, D, sz, Vd, op, Q, M, Vm, AccumulateBehavior::None); } bool ArmTranslatorVisitor::asimd_VCLS(bool D, size_t sz, size_t Vd, bool Q, bool M, size_t Vm) { @@ -233,6 +252,10 @@ bool ArmTranslatorVisitor::asimd_VMVN_reg(bool D, size_t sz, size_t Vd, bool Q, return true; } +bool ArmTranslatorVisitor::asimd_VPADAL(bool D, size_t sz, size_t Vd, bool op, bool Q, bool M, size_t Vm) { + return PairedAddOperation(*this, D, sz, Vd, op, Q, M, Vm, AccumulateBehavior::Accumulate); +} + bool ArmTranslatorVisitor::asimd_VQABS(bool D, size_t sz, size_t Vd, bool Q, bool M, size_t Vm) { if (sz == 0b11) { return UndefinedInstruction(); diff --git a/src/frontend/A32/translate/impl/translate_arm.h b/src/frontend/A32/translate/impl/translate_arm.h index 53971def..4735497b 100644 --- a/src/frontend/A32/translate/impl/translate_arm.h +++ b/src/frontend/A32/translate/impl/translate_arm.h @@ -497,6 +497,7 @@ struct ArmTranslatorVisitor final { bool asimd_VCLZ(bool D, size_t sz, size_t Vd, bool Q, bool M, size_t Vm); bool asimd_VCNT(bool D, size_t sz, size_t Vd, bool Q, bool M, size_t Vm); bool asimd_VMVN_reg(bool D, size_t sz, size_t Vd, bool Q, bool M, size_t Vm); + bool asimd_VPADAL(bool D, size_t sz, size_t Vd, bool op, bool Q, bool M, size_t Vm); bool asimd_VQABS(bool D, size_t sz, size_t Vd, bool Q, bool M, size_t Vm); bool asimd_VQNEG(bool D, size_t sz, size_t Vd, bool Q, bool M, size_t Vm); bool asimd_VCGT_zero(bool D, size_t sz, size_t Vd, bool F, bool Q, bool M, size_t Vm);