From 69a1d58a2b53709c7d257d7757dd3ea48823f8f7 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Sun, 21 Jun 2020 10:00:24 +0100 Subject: [PATCH] A32: Implement ASIMD VMULL --- src/frontend/A32/decoder/asimd.inc | 2 +- .../A32/translate/impl/asimd_three_same.cpp | 23 +++++++++++++++++++ .../A32/translate/impl/translate_arm.h | 1 + tests/A32/fuzz_arm.cpp | 1 + 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/frontend/A32/decoder/asimd.inc b/src/frontend/A32/decoder/asimd.inc index 99cdfb37..6ff00de6 100644 --- a/src/frontend/A32/decoder/asimd.inc +++ b/src/frontend/A32/decoder/asimd.inc @@ -30,7 +30,7 @@ INST(asimd_VCEQ_reg, "VCEG (register)", "111100110Dzznnnndddd100 INST(asimd_VMLA, "VMLA/VMLS", "1111001o0Dzznnnndddd1001NQM0mmmm") // ASIMD //INST(asimd_VMLAL, "VMLAL/VMLSL", "1111001U1Dzznnnndddd10o0N0M0mmmm") // ASIMD INST(asimd_VMUL, "VMUL", "1111001P0Dzznnnndddd1001NQM1mmmm") // ASIMD -//INST(asimd_VMULL, "VMULL", "1111001U1Dzznnnndddd11o0N0M0mmmm") // ASIMD +INST(asimd_VMULL, "VMULL", "1111001U1Dzznnnndddd11P0N0M0mmmm") // ASIMD //INST(asimd_VPMAX, "VPMAX/VPMIN", "1111001U0-CC--------1010---B----") // ASIMD //INST(asimd_VQDMULH, "VQDMULH", "111100100-CC--------1011---0----") // ASIMD //INST(asimd_VQRDMULH, "VQRDMULH", "111100110-CC--------1011---0----") // ASIMD diff --git a/src/frontend/A32/translate/impl/asimd_three_same.cpp b/src/frontend/A32/translate/impl/asimd_three_same.cpp index 8aef3d28..95f34713 100644 --- a/src/frontend/A32/translate/impl/asimd_three_same.cpp +++ b/src/frontend/A32/translate/impl/asimd_three_same.cpp @@ -550,6 +550,29 @@ bool ArmTranslatorVisitor::asimd_VMUL(bool P, bool D, size_t sz, size_t Vn, size return true; } +bool ArmTranslatorVisitor::asimd_VMULL(bool U, bool D, size_t sz, size_t Vn, size_t Vd, bool P, bool N, bool M, size_t Vm) { + if (sz == 0b11 || (P & (U || sz == 0b10)) || Common::Bit<0>(Vd)) { + return UndefinedInstruction(); + } + + const size_t esize = P ? (sz == 0b00 ? 8 : 64) : 8U << sz; + const auto d = ToVector(true, Vd, D); + const auto m = ToVector(false, Vm, M); + const auto n = ToVector(false, Vn, N); + + const auto extend_reg = [&](const auto& reg) { + return U ? ir.VectorZeroExtend(esize, reg) : ir.VectorSignExtend(esize, reg); + }; + + const auto reg_n = ir.GetVector(n); + const auto reg_m = ir.GetVector(m); + const auto result = P ? ir.VectorPolynomialMultiplyLong(esize, reg_m, reg_n) + : ir.VectorMultiply(2 * esize, extend_reg(reg_m), extend_reg(reg_n)); + + ir.SetVector(d, result); + return true; +} + bool ArmTranslatorVisitor::asimd_VPADD(bool D, size_t sz, size_t Vn, size_t Vd, bool N, bool Q, bool M, size_t Vm) { if (Q || 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 a9d3b690..ea4db9eb 100644 --- a/src/frontend/A32/translate/impl/translate_arm.h +++ b/src/frontend/A32/translate/impl/translate_arm.h @@ -476,6 +476,7 @@ struct ArmTranslatorVisitor final { bool asimd_VCEQ_reg(bool D, size_t sz, size_t Vn, size_t Vd, bool N, bool Q, bool M, size_t Vm); bool asimd_VMLA(bool op, bool D, size_t sz, size_t Vn, size_t Vd, bool N, bool Q, bool M, size_t Vm); bool asimd_VMUL(bool P, bool D, size_t sz, size_t Vn, size_t Vd, bool N, bool Q, bool M, size_t Vm); + bool asimd_VMULL(bool U, bool D, size_t sz, size_t Vn, size_t Vd, bool P, bool N, bool M, size_t Vm); bool asimd_VPADD(bool D, size_t sz, size_t Vn, size_t Vd, bool N, bool Q, bool M, size_t Vm); bool asimd_VADD_float(bool D, bool sz, size_t Vn, size_t Vd, bool N, bool Q, bool M, size_t Vm); bool asimd_VSUB_float(bool D, bool sz, size_t Vn, size_t Vd, bool N, bool Q, bool M, size_t Vm); diff --git a/tests/A32/fuzz_arm.cpp b/tests/A32/fuzz_arm.cpp index fb14b7ff..47a2bfac 100644 --- a/tests/A32/fuzz_arm.cpp +++ b/tests/A32/fuzz_arm.cpp @@ -64,6 +64,7 @@ bool ShouldTestInst(u32 instruction, u32 pc, bool is_last_inst) { // Currently unimplemented in Unicorn case IR::Opcode::FPVectorRecipEstimate16: case IR::Opcode::FPVectorRSqrtEstimate16: + case IR::Opcode::VectorPolynomialMultiplyLong64: return false; default: continue;