From b3d4c02098f6009f2f665c2f014c5df8c9b7e92f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 10 Apr 2018 13:36:25 -0400 Subject: [PATCH] A64: Implement SM3TT2A --- src/frontend/A64/decoder/a64.inc | 2 +- .../impl/simd_crypto_three_register.cpp | 42 ++++++++++++++++--- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/frontend/A64/decoder/a64.inc b/src/frontend/A64/decoder/a64.inc index a82e252a..7554f4f0 100644 --- a/src/frontend/A64/decoder/a64.inc +++ b/src/frontend/A64/decoder/a64.inc @@ -854,7 +854,7 @@ INST(USHLL, "USHLL, USHLL2", "0Q101 // Data Processing - FP and SIMD - Cryptographic three register INST(SM3TT1A, "SM3TT1A", "11001110010mmmmm10ii00nnnnnddddd") INST(SM3TT1B, "SM3TT1B", "11001110010mmmmm10ii01nnnnnddddd") -//INST(SM3TT2A, "SM3TT2A", "11001110010mmmmm10ii10nnnnnddddd") +INST(SM3TT2A, "SM3TT2A", "11001110010mmmmm10ii10nnnnnddddd") //INST(SM3TT2B, "SM3TT2B", "11001110010mmmmm10ii11nnnnnddddd") // Data Processing - FP and SIMD - SHA512 three register diff --git a/src/frontend/A64/translate/impl/simd_crypto_three_register.cpp b/src/frontend/A64/translate/impl/simd_crypto_three_register.cpp index 16c9a84b..bf97eba3 100644 --- a/src/frontend/A64/translate/impl/simd_crypto_three_register.cpp +++ b/src/frontend/A64/translate/impl/simd_crypto_three_register.cpp @@ -8,12 +8,12 @@ namespace Dynarmic::A64 { -enum class SM3TT1Variant { +enum class SM3TTVariant { A, B, }; -static void SM3TT1(TranslatorVisitor& v, Vec Vm, Imm<2> imm2, Vec Vn, Vec Vd, SM3TT1Variant behavior) { +static void SM3TT1(TranslatorVisitor& v, Vec Vm, Imm<2> imm2, Vec Vn, Vec Vd, SM3TTVariant behavior) { const IR::U128 d = v.ir.GetQ(Vd); const IR::U128 m = v.ir.GetQ(Vm); const IR::U128 n = v.ir.GetQ(Vn); @@ -28,7 +28,7 @@ static void SM3TT1(TranslatorVisitor& v, Vec Vm, Imm<2> imm2, Vec Vn, Vec Vd, SM const IR::U32 wj_prime = v.ir.VectorGetElement(32, m, index); const IR::U32 ss2 = v.ir.Eor(top_n, v.ir.RotateRight(top_d, v.ir.Imm8(20))); const IR::U32 tt1 = [&] { - if (behavior == SM3TT1Variant::A) { + if (behavior == SM3TTVariant::A) { return v.ir.Eor(after_low_d, v.ir.Eor(top_d, before_top_d)); } const IR::U32 tmp1 = v.ir.And(top_d, after_low_d); @@ -47,13 +47,45 @@ static void SM3TT1(TranslatorVisitor& v, Vec Vm, Imm<2> imm2, Vec Vn, Vec Vd, SM v.ir.SetQ(Vd, result); } +static void SM3TT2(TranslatorVisitor& v, Vec Vm, Imm<2> imm2, Vec Vn, Vec Vd, [[maybe_unused]] SM3TTVariant behavior) { + const IR::U128 d = v.ir.GetQ(Vd); + const IR::U128 m = v.ir.GetQ(Vm); + const IR::U128 n = v.ir.GetQ(Vn); + const u32 index = imm2.ZeroExtend(); + + const IR::U32 top_d = v.ir.VectorGetElement(32, d, 3); + const IR::U32 before_top_d = v.ir.VectorGetElement(32, d, 2); + const IR::U32 after_low_d = v.ir.VectorGetElement(32, d, 1); + const IR::U32 low_d = v.ir.VectorGetElement(32, d, 0); + const IR::U32 top_n = v.ir.VectorGetElement(32, n, 3); + + const IR::U32 wj = v.ir.VectorGetElement(32, m, index); + const IR::U32 tt2 = v.ir.Eor(after_low_d, v.ir.Eor(top_d, before_top_d)); + const IR::U32 final_tt2 = v.ir.Add(tt2, v.ir.Add(low_d, v.ir.Add(top_n, wj))); + const IR::U32 top_result = v.ir.Eor(final_tt2, v.ir.Eor(v.ir.RotateRight(final_tt2, v.ir.Imm8(23)), + v.ir.RotateRight(final_tt2, v.ir.Imm8(15)))); + + const IR::U128 zero_vector = v.ir.ZeroVector(); + const IR::U128 tmp1 = v.ir.VectorSetElement(32, zero_vector, 0, after_low_d); + const IR::U128 tmp2 = v.ir.VectorSetElement(32, tmp1, 1, v.ir.RotateRight(before_top_d, v.ir.Imm8(13))); + const IR::U128 tmp3 = v.ir.VectorSetElement(32, tmp2, 2, top_d); + const IR::U128 result = v.ir.VectorSetElement(32, tmp3, 3, top_result); + + v.ir.SetQ(Vd, result); +} + bool TranslatorVisitor::SM3TT1A(Vec Vm, Imm<2> imm2, Vec Vn, Vec Vd) { - SM3TT1(*this, Vm, imm2, Vn, Vd, SM3TT1Variant::A); + SM3TT1(*this, Vm, imm2, Vn, Vd, SM3TTVariant::A); return true; } bool TranslatorVisitor::SM3TT1B(Vec Vm, Imm<2> imm2, Vec Vn, Vec Vd) { - SM3TT1(*this, Vm, imm2, Vn, Vd, SM3TT1Variant::B); + SM3TT1(*this, Vm, imm2, Vn, Vd, SM3TTVariant::B); + return true; +} + +bool TranslatorVisitor::SM3TT2A(Vec Vm, Imm<2> imm2, Vec Vn, Vec Vd) { + SM3TT2(*this, Vm, imm2, Vn, Vd, SM3TTVariant::A); return true; }