From 769373b3ed8a54caeb4be47ea63b96ddfdbf0188 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 8 Apr 2018 20:49:43 -0400 Subject: [PATCH] A64: Implement SM3TT1A --- src/CMakeLists.txt | 1 + src/frontend/A64/decoder/a64.inc | 2 +- .../impl/simd_crypto_three_register.cpp | 38 +++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/frontend/A64/translate/impl/simd_crypto_three_register.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1e48bd65..be49a49c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -101,6 +101,7 @@ add_library(dynarmic frontend/A64/translate/impl/simd_aes.cpp frontend/A64/translate/impl/simd_copy.cpp frontend/A64/translate/impl/simd_crypto_four_register.cpp + frontend/A64/translate/impl/simd_crypto_three_register.cpp frontend/A64/translate/impl/simd_extract.cpp frontend/A64/translate/impl/simd_modified_immediate.cpp frontend/A64/translate/impl/simd_permute.cpp diff --git a/src/frontend/A64/decoder/a64.inc b/src/frontend/A64/decoder/a64.inc index 29d0705b..d8b416c4 100644 --- a/src/frontend/A64/decoder/a64.inc +++ b/src/frontend/A64/decoder/a64.inc @@ -852,7 +852,7 @@ INST(USHLL, "USHLL, USHLL2", "0Q101 //INST(FCMLA_elt, "FCMLA (by element)", "0Q101111zzLMmmmm0rr1H0nnnnnddddd") // Data Processing - FP and SIMD - Cryptographic three register -//INST(SM3TT1A, "SM3TT1A", "11001110010mmmmm10ii00nnnnnddddd") +INST(SM3TT1A, "SM3TT1A", "11001110010mmmmm10ii00nnnnnddddd") //INST(SM3TT1B, "SM3TT1B", "11001110010mmmmm10ii01nnnnnddddd") //INST(SM3TT2A, "SM3TT2A", "11001110010mmmmm10ii10nnnnnddddd") //INST(SM3TT2B, "SM3TT2B", "11001110010mmmmm10ii11nnnnnddddd") diff --git a/src/frontend/A64/translate/impl/simd_crypto_three_register.cpp b/src/frontend/A64/translate/impl/simd_crypto_three_register.cpp new file mode 100644 index 00000000..a6809576 --- /dev/null +++ b/src/frontend/A64/translate/impl/simd_crypto_three_register.cpp @@ -0,0 +1,38 @@ +/* This file is part of the dynarmic project. + * Copyright (c) 2018 MerryMage + * This software may be used and distributed according to the terms of the GNU + * General Public License version 2 or any later version. + */ + +#include "frontend/A64/translate/impl/impl.h" + +namespace Dynarmic::A64 { + +bool TranslatorVisitor::SM3TT1A(Vec Vm, Imm<2> imm2, Vec Vn, Vec Vd) { + const IR::U128 d = ir.GetQ(Vd); + const IR::U128 m = ir.GetQ(Vm); + const IR::U128 n = ir.GetQ(Vn); + const u32 index = imm2.ZeroExtend(); + + const IR::U32 top_d = ir.VectorGetElement(32, d, 3); + const IR::U32 before_top_d = ir.VectorGetElement(32, d, 2); + const IR::U32 after_low_d = ir.VectorGetElement(32, d, 1); + const IR::U32 low_d = ir.VectorGetElement(32, d, 0); + const IR::U32 top_n = ir.VectorGetElement(32, n, 3); + + const IR::U32 wj_prime = ir.VectorGetElement(32, m, index); + const IR::U32 ss2 = ir.Eor(top_n, ir.RotateRight(top_d, ir.Imm8(20))); + const IR::U32 tt1 = ir.Eor(after_low_d, ir.Eor(top_d, before_top_d)); + const IR::U32 final_tt1 = ir.Add(tt1, ir.Add(low_d, ir.Add(ss2, wj_prime))); + + const IR::U128 zero_vector = ir.ZeroVector(); + const IR::U128 tmp1 = ir.VectorSetElement(32, zero_vector, 0, after_low_d); + const IR::U128 tmp2 = ir.VectorSetElement(32, tmp1, 1, ir.RotateRight(before_top_d, ir.Imm8(23))); + const IR::U128 tmp3 = ir.VectorSetElement(32, tmp2, 2, top_d); + const IR::U128 result = ir.VectorSetElement(32, tmp3, 3, final_tt1); + + ir.SetQ(Vd, result); + return true; +} + +} // namespace Dynarmic::A64