A64: Implement SM3TT2A

This commit is contained in:
Lioncash 2018-04-10 13:36:25 -04:00 committed by MerryMage
parent 7fbccabd81
commit b3d4c02098
2 changed files with 38 additions and 6 deletions

View file

@ -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

View file

@ -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;
}