From 3c013bd9f87d88f9b4024f17efaee7a4ea266a5b Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 15 Apr 2018 02:40:21 -0400 Subject: [PATCH] A64: Implement SLI (scalar) --- src/frontend/A64/decoder/a64.inc | 2 +- .../impl/simd_scalar_shift_by_immediate.cpp | 61 +++++++++++++++---- 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/src/frontend/A64/decoder/a64.inc b/src/frontend/A64/decoder/a64.inc index 9f013c97..9a8bb9d2 100644 --- a/src/frontend/A64/decoder/a64.inc +++ b/src/frontend/A64/decoder/a64.inc @@ -482,7 +482,7 @@ INST(USRA_1, "USRA", "01111 //INST(URSHR_1, "URSHR", "011111110IIIIiii001001nnnnnddddd") //INST(URSRA_1, "URSRA", "011111110IIIIiii001101nnnnnddddd") INST(SRI_1, "SRI", "011111110IIIIiii010001nnnnnddddd") -//INST(SLI_1, "SLI", "011111110IIIIiii010101nnnnnddddd") +INST(SLI_1, "SLI", "011111110IIIIiii010101nnnnnddddd") //INST(SQSHLU_1, "SQSHLU", "011111110IIIIiii011001nnnnnddddd") //INST(UQSHL_imm_1, "UQSHL (immediate)", "011111110IIIIiii011101nnnnnddddd") //INST(SQSHRUN_1, "SQSHRUN, SQSHRUN2", "011111110IIIIiii100001nnnnnddddd") diff --git a/src/frontend/A64/translate/impl/simd_scalar_shift_by_immediate.cpp b/src/frontend/A64/translate/impl/simd_scalar_shift_by_immediate.cpp index edffa1e1..3b39a381 100644 --- a/src/frontend/A64/translate/impl/simd_scalar_shift_by_immediate.cpp +++ b/src/frontend/A64/translate/impl/simd_scalar_shift_by_immediate.cpp @@ -39,22 +39,61 @@ static void ShiftRight(TranslatorVisitor& v, Imm<4> immh, Imm<3> immb, Vec Vn, V v.V_scalar(esize, Vd, result); } +enum class ShiftDirection { + Left, + Right, +}; + +static void ShiftAndInsert(TranslatorVisitor& v, Imm<4> immh, Imm<3> immb, Vec Vn, Vec Vd, + ShiftDirection direction) { + const size_t esize = 64; + + const u8 shift_amount = [&] { + if (direction == ShiftDirection::Right) { + return static_cast((esize * 2) - concatenate(immh, immb).ZeroExtend()); + } + + return static_cast(concatenate(immh, immb).ZeroExtend() - esize); + }(); + + const u64 mask = [&] { + if (direction == ShiftDirection::Right) { + return shift_amount == esize ? 0 : Common::Ones(esize) >> shift_amount; + } + + return Common::Ones(esize) << shift_amount; + }(); + + const IR::U64 operand1 = v.V_scalar(esize, Vn); + const IR::U64 operand2 = v.V_scalar(esize, Vd); + + const IR::U64 shifted = [&] { + if (direction == ShiftDirection::Right) { + return v.ir.LogicalShiftRight(operand1, v.ir.Imm8(shift_amount)); + } + + return v.ir.LogicalShiftLeft(operand1, v.ir.Imm8(shift_amount)); + }(); + + const IR::U64 result = v.ir.Or(v.ir.And(operand2, v.ir.Not(v.ir.Imm64(mask))), shifted); + v.V_scalar(esize, Vd, result); +} + +bool TranslatorVisitor::SLI_1(Imm<4> immh, Imm<3> immb, Vec Vn, Vec Vd) { + if (!immh.Bit<3>()) { + return ReservedValue(); + } + + ShiftAndInsert(*this, immh, immb, Vn, Vd, ShiftDirection::Left); + return true; +} + bool TranslatorVisitor::SRI_1(Imm<4> immh, Imm<3> immb, Vec Vn, Vec Vd) { if (!immh.Bit<3>()) { return ReservedValue(); } - const size_t esize = 64; - const u8 shift_amount = static_cast((esize * 2) - concatenate(immh, immb).ZeroExtend()); - const u64 mask = shift_amount == esize ? 0 : Common::Ones(esize) >> shift_amount; - - const IR::U64 operand1 = V_scalar(esize, Vn); - const IR::U64 operand2 = V_scalar(esize, Vd); - - const IR::U64 shifted = ir.LogicalShiftRight(operand1, ir.Imm8(shift_amount)); - const IR::U64 result = ir.Or(ir.And(operand2, ir.Not(ir.Imm64(mask))), shifted); - - V_scalar(esize, Vd, result); + ShiftAndInsert(*this, immh, immb, Vn, Vd, ShiftDirection::Right); return true; }