diff --git a/src/frontend/A64/decoder/a64.inc b/src/frontend/A64/decoder/a64.inc index 8fd63f8a..6d22bd03 100644 --- a/src/frontend/A64/decoder/a64.inc +++ b/src/frontend/A64/decoder/a64.inc @@ -844,7 +844,7 @@ INST(MLA_elt, "MLA (by element)", "0Q101 //INST(UMLAL_elt, "UMLAL, UMLAL2 (by element)", "0Q101111zzLMmmmm0010H0nnnnnddddd") INST(MLS_elt, "MLS (by element)", "0Q101111zzLMmmmm0100H0nnnnnddddd") //INST(UMLSL_elt, "UMLSL, UMLSL2 (by element)", "0Q101111zzLMmmmm0110H0nnnnnddddd") -//INST(UMULL_elt, "UMULL, UMULL2 (by element)", "0Q101111zzLMmmmm1010H0nnnnnddddd") +INST(UMULL_elt, "UMULL, UMULL2 (by element)", "0Q101111zzLMmmmm1010H0nnnnnddddd") //INST(SQRDMLAH_elt_2, "SQRDMLAH (by element)", "0Q101111zzLMmmmm1101H0nnnnnddddd") INST(UDOT_elt, "UDOT (by element)", "0Q101111zzLMmmmm1110H0nnnnnddddd") //INST(SQRDMLSH_elt_2, "SQRDMLSH (by element)", "0Q101111zzLMmmmm1111H0nnnnnddddd") diff --git a/src/frontend/A64/translate/impl/impl.h b/src/frontend/A64/translate/impl/impl.h index fcf61d59..fc596da4 100644 --- a/src/frontend/A64/translate/impl/impl.h +++ b/src/frontend/A64/translate/impl/impl.h @@ -914,7 +914,7 @@ struct TranslatorVisitor final { bool UMLAL_elt(bool Q, Imm<2> size, bool L, bool M, Vec Vm, bool H, Vec Vn, Vec Vd); bool MLS_elt(bool Q, Imm<2> size, Imm<1> L, Imm<1> M, Imm<4> Vmlo, Imm<1> H, Vec Vn, Vec Vd); bool UMLSL_elt(bool Q, Imm<2> size, bool L, bool M, Vec Vm, bool H, Vec Vn, Vec Vd); - bool UMULL_elt(bool Q, Imm<2> size, bool L, bool M, Vec Vm, bool H, Vec Vn, Vec Vd); + bool UMULL_elt(bool Q, Imm<2> size, Imm<1> L, Imm<1> M, Imm<4> Vmlo, Imm<1> H, Vec Vn, Vec Vd); bool SQRDMLAH_elt_2(bool Q, Imm<2> size, bool L, bool M, Vec Vm, bool H, Vec Vn, Vec Vd); bool UDOT_elt(bool Q, Imm<2> size, Imm<1> L, Imm<1> M, Imm<4> Vmlo, Imm<1> H, Vec Vn, Vec Vd); bool SQRDMLSH_elt_2(bool Q, Imm<2> size, 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 ae79c352..df6979df 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 @@ -121,6 +121,49 @@ bool DotProduct(TranslatorVisitor& v, bool Q, Imm<2> size, Imm<1> L, Imm<1> M, I v.V(datasize, Vd, result); return true; } + +enum class Signedness { + Signed, + Unsigned +}; + +bool MultiplyLong(TranslatorVisitor& v, bool Q, Imm<2> size, Imm<1> L, Imm<1> M, Imm<4> Vmlo, + Imm<1> H, Vec Vn, Vec Vd, Signedness sign) { + if (size == 0b00 || size == 0b11) { + return v.UnallocatedEncoding(); + } + + const size_t idxsize = H == 1 ? 128 : 64; + const size_t esize = 8 << size.ZeroExtend(); + const size_t datasize = 64; + const auto [index, Vmhi] = [=] { + if (size == 0b01) { + return std::make_pair(concatenate(H, L, M).ZeroExtend(), Imm<1>{0}); + } + + return std::make_pair(concatenate(H, L).ZeroExtend(), M); + }(); + + const auto extend_operands = [&](const IR::U128& lhs, const IR::U128& rhs) { + if (sign == Signedness::Signed) { + return std::make_pair(v.ir.VectorSignExtend(esize, lhs), + v.ir.VectorSignExtend(esize, rhs)); + } + + return std::make_pair(v.ir.VectorZeroExtend(esize, lhs), + v.ir.VectorZeroExtend(esize, rhs)); + }; + + const IR::U128 operand1 = v.Vpart(datasize, Vn, Q); + const IR::U128 operand2 = v.V(idxsize, concatenate(Vmhi, Vmlo).ZeroExtend()); + const IR::U128 index_vector = v.ir.VectorBroadcast(esize, v.ir.VectorGetElement(esize, operand2, index)); + + const auto [extended_op1, extended_index] = extend_operands(operand1, index_vector); + const IR::U128 result = v.ir.VectorMultiply(2 * esize, extended_op1, extended_index); + + v.V(2 * 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) { @@ -148,30 +191,7 @@ bool TranslatorVisitor::FMUL_elt_4(bool Q, bool sz, Imm<1> L, Imm<1> M, Imm<4> V } bool TranslatorVisitor::SMULL_elt(bool Q, Imm<2> size, Imm<1> L, Imm<1> M, Imm<4> Vmlo, Imm<1> H, Vec Vn, Vec Vd) { - if (size == 0b00 || size == 0b11) { - return UnallocatedEncoding(); - } - - const size_t idxsize = H == 1 ? 128 : 64; - const size_t esize = 8 << size.ZeroExtend(); - const size_t datasize = 64; - const auto [index, Vmhi] = [=] { - if (size == 0b01) { - return std::make_pair(concatenate(H, L, M).ZeroExtend(), Imm<1>{0}); - } - - return std::make_pair(concatenate(H, L).ZeroExtend(), M); - }(); - - const IR::U128 operand1 = Vpart(datasize, Vn, Q); - const IR::U128 operand2 = V(idxsize, concatenate(Vmhi, Vmlo).ZeroExtend()); - const IR::U128 index_vector = ir.VectorBroadcast(esize, ir.VectorGetElement(esize, operand2, index)); - const IR::U128 result = ir.VectorMultiply(2 * esize, - ir.VectorSignExtend(esize, operand1), - ir.VectorSignExtend(esize, index_vector)); - - V(128, Vd, result); - return true; + return MultiplyLong(*this, Q, size, L, M, Vmlo, H, Vn, Vd, Signedness::Signed); } bool TranslatorVisitor::SQDMULH_elt_2(bool Q, Imm<2> size, Imm<1> L, Imm<1> M, Imm<4> Vmlo, Imm<1> H, Vec Vn, Vec Vd) { @@ -207,4 +227,8 @@ bool TranslatorVisitor::UDOT_elt(bool Q, Imm<2> size, Imm<1> L, Imm<1> M, Imm<4> return DotProduct(*this, Q, size, L, M, Vmlo, H, Vn, Vd, &IREmitter::ZeroExtendToWord); } +bool TranslatorVisitor::UMULL_elt(bool Q, Imm<2> size, Imm<1> L, Imm<1> M, Imm<4> Vmlo, Imm<1> H, Vec Vn, Vec Vd) { + return MultiplyLong(*this, Q, size, L, M, Vmlo, H, Vn, Vd, Signedness::Unsigned); +} + } // namespace Dynarmic::A64