From 642b6c31d2508d629da2857d196eb27e15aa7c89 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Wed, 25 Jul 2018 13:54:48 +0100 Subject: [PATCH] A64: Implement MLA, MLS (by element), vector single/double variant --- src/frontend/A64/decoder/a64.inc | 4 +- src/frontend/A64/translate/impl/impl.h | 4 +- .../impl/simd_vector_x_indexed_element.cpp | 67 +++++++++++++------ 3 files changed, 51 insertions(+), 24 deletions(-) diff --git a/src/frontend/A64/decoder/a64.inc b/src/frontend/A64/decoder/a64.inc index 13faa2a5..e6edeb06 100644 --- a/src/frontend/A64/decoder/a64.inc +++ b/src/frontend/A64/decoder/a64.inc @@ -831,9 +831,9 @@ INST(MUL_elt, "MUL (by element)", "0Q001 //INST(SQRDMULH_elt_2, "SQRDMULH (by element)", "0Q001111zzLMmmmm1101H0nnnnnddddd") //INST(SDOT_elt, "SDOT (by element)", "0Q001111zzLMmmmm1110H0nnnnnddddd") //INST(FMLA_elt_3, "FMLA (by element)", "0Q00111100LMmmmm0001H0nnnnnddddd") -//INST(FMLA_elt_4, "FMLA (by element)", "0Q0011111zLMmmmm0001H0nnnnnddddd") +INST(FMLA_elt_4, "FMLA (by element)", "0Q0011111zLMmmmm0001H0nnnnnddddd") //INST(FMLS_elt_3, "FMLS (by element)", "0Q00111100LMmmmm0101H0nnnnnddddd") -//INST(FMLS_elt_4, "FMLS (by element)", "0Q0011111zLMmmmm0101H0nnnnnddddd") +INST(FMLS_elt_4, "FMLS (by element)", "0Q0011111zLMmmmm0101H0nnnnnddddd") //INST(FMUL_elt_3, "FMUL (by element)", "0Q00111100LMmmmm1001H0nnnnnddddd") INST(FMUL_elt_4, "FMUL (by element)", "0Q0011111zLMmmmm1001H0nnnnnddddd") //INST(FMLAL_elt_1, "FMLAL, FMLAL2 (by element)", "0Q0011111zLMmmmm0000H0nnnnnddddd") diff --git a/src/frontend/A64/translate/impl/impl.h b/src/frontend/A64/translate/impl/impl.h index f2fb710e..dd44f99a 100644 --- a/src/frontend/A64/translate/impl/impl.h +++ b/src/frontend/A64/translate/impl/impl.h @@ -900,9 +900,9 @@ struct TranslatorVisitor final { bool SQRDMULH_elt_2(bool Q, Imm<2> size, bool L, bool M, Vec Vm, bool H, Vec Vn, Vec Vd); bool SDOT_elt(bool Q, Imm<2> size, bool L, bool M, Vec Vm, bool H, Vec Vn, Vec Vd); bool FMLA_elt_3(bool Q, bool L, bool M, Vec Vm, bool H, Vec Vn, Vec Vd); - bool FMLA_elt_4(bool Q, bool sz, bool L, bool M, Vec Vm, bool H, Vec Vn, Vec Vd); + bool FMLA_elt_4(bool Q, bool sz, Imm<1> L, Imm<1> M, Imm<4> Vmlo, Imm<1> H, Vec Vn, Vec Vd); bool FMLS_elt_3(bool Q, bool L, bool M, Vec Vm, bool H, Vec Vn, Vec Vd); - bool FMLS_elt_4(bool Q, bool sz, bool L, bool M, Vec Vm, bool H, Vec Vn, Vec Vd); + bool FMLS_elt_4(bool Q, bool sz, Imm<1> L, Imm<1> M, Imm<4> Vmlo, Imm<1> H, Vec Vn, Vec Vd); bool FMUL_elt_3(bool Q, bool L, bool M, Vec Vm, bool H, Vec Vn, Vec Vd); bool FMUL_elt_4(bool Q, bool sz, Imm<1> L, Imm<1> M, Imm<4> Vmlo, Imm<1> H, Vec Vn, Vec Vd); bool FMLAL_elt_1(bool Q, bool sz, bool L, bool M, Vec Vm, bool H, Vec Vn, Vec Vd); diff --git a/src/frontend/A64/translate/impl/simd_vector_x_indexed_element.cpp b/src/frontend/A64/translate/impl/simd_vector_x_indexed_element.cpp index b0776509..c1aa8347 100644 --- a/src/frontend/A64/translate/impl/simd_vector_x_indexed_element.cpp +++ b/src/frontend/A64/translate/impl/simd_vector_x_indexed_element.cpp @@ -5,6 +5,7 @@ */ #include +#include "common/assert.h" #include "frontend/A64/translate/impl/impl.h" namespace Dynarmic::A64 { @@ -48,6 +49,43 @@ bool MultiplyByElement(TranslatorVisitor& v, bool Q, Imm<2> size, Imm<1> L, Imm< v.V(datasize, Vd, result); return true; } + +bool FPMultiplyByElement(TranslatorVisitor& v, bool Q, bool sz, Imm<1> L, Imm<1> M, Imm<4> Vmlo, Imm<1> H, Vec Vn, Vec Vd, + ExtraBehavior extra_behavior) { + if (sz && L == 1) { + return v.UnallocatedEncoding(); + } + if (sz && !Q) { + return v.ReservedValue(); + } + + const size_t idxdsize = H == 1 ? 128 : 64; + const size_t index = sz ? H.ZeroExtend() : concatenate(H, L).ZeroExtend(); + const Vec Vm = concatenate(M, Vmlo).ZeroExtend(); + const size_t esize = sz ? 64 : 32; + const size_t datasize = Q ? 128 : 64; + + const IR::UAny element2 = v.ir.VectorGetElement(esize, v.V(idxdsize, Vm), index); + const IR::U128 operand1 = v.V(datasize, Vn); + const IR::U128 operand2 = Q ? v.ir.VectorBroadcast(esize, element2) : v.ir.VectorBroadcastLower(esize, element2); + const IR::U128 operand3 = v.V(datasize, Vd); + + const IR::U128 result = [&]{ + switch (extra_behavior) { + case ExtraBehavior::None: + return v.ir.FPVectorMul(esize, operand1, operand2); + case ExtraBehavior::Accumulate: + return v.ir.FPVectorMulAdd(esize, operand3, operand1, operand2); + case ExtraBehavior::Subtract: + return v.ir.FPVectorMulAdd(esize, operand3, v.ir.FPVectorNeg(esize, operand1), operand2); + } + UNREACHABLE(); + return IR::U128{}; + }(); + v.V(datasize, Vd, result); + return true; +} + } // Anonymous namespace bool TranslatorVisitor::MLA_elt(bool Q, Imm<2> size, Imm<1> L, Imm<1> M, Imm<4> Vmlo, Imm<1> H, Vec Vn, Vec Vd) { @@ -62,27 +100,16 @@ bool TranslatorVisitor::MUL_elt(bool Q, Imm<2> size, Imm<1> L, Imm<1> M, Imm<4> return MultiplyByElement(*this, Q, size, L, M, Vmlo, H, Vn, Vd, ExtraBehavior::None); } +bool TranslatorVisitor::FMLA_elt_4(bool Q, bool sz, Imm<1> L, Imm<1> M, Imm<4> Vmlo, Imm<1> H, Vec Vn, Vec Vd) { + return FPMultiplyByElement(*this, Q, sz, L, M, Vmlo, H, Vn, Vd, ExtraBehavior::Accumulate); +} + +bool TranslatorVisitor::FMLS_elt_4(bool Q, bool sz, Imm<1> L, Imm<1> M, Imm<4> Vmlo, Imm<1> H, Vec Vn, Vec Vd) { + return FPMultiplyByElement(*this, Q, sz, L, M, Vmlo, H, Vn, Vd, ExtraBehavior::Subtract); +} + bool TranslatorVisitor::FMUL_elt_4(bool Q, bool sz, Imm<1> L, Imm<1> M, Imm<4> Vmlo, Imm<1> H, Vec Vn, Vec Vd) { - if (sz && L == 1) { - return UnallocatedEncoding(); - } - if (sz && !Q) { - return ReservedValue(); - } - - const size_t idxdsize = H == 1 ? 128 : 64; - const size_t index = sz ? H.ZeroExtend() : concatenate(H, L).ZeroExtend(); - const Vec Vm = concatenate(M, Vmlo).ZeroExtend(); - const size_t esize = sz ? 64 : 32; - const size_t datasize = Q ? 128 : 64; - - const IR::UAny element2 = ir.VectorGetElement(esize, V(idxdsize, Vm), index); - const IR::U128 operand1 = V(datasize, Vn); - const IR::U128 operand2 = Q ? ir.VectorBroadcast(esize, element2) : ir.VectorBroadcastLower(esize, element2); - - const IR::U128 result = ir.FPVectorMul(esize, operand1, operand2); - V(datasize, Vd, result); - return true; + return FPMultiplyByElement(*this, Q, sz, L, M, Vmlo, H, Vn, Vd, ExtraBehavior::None); } } // namespace Dynarmic::A64