From 5ebf496d4e80bf474e08d3b5a6e77484577dbbe4 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 29 Jul 2018 00:53:13 -0400 Subject: [PATCH] translate: Deduplicate GetDataSize() functions Avoids defining the same function multiple times in different files. --- .../translate/impl/floating_point_compare.cpp | 17 +------ .../floating_point_conditional_compare.cpp | 14 +----- .../floating_point_conditional_select.cpp | 14 +----- .../floating_point_conversion_fixed_point.cpp | 16 +----- .../floating_point_conversion_integer.cpp | 20 ++------ ...ing_point_data_processing_one_register.cpp | 31 ++++-------- ...g_point_data_processing_three_register.cpp | 21 ++------ ...ing_point_data_processing_two_register.cpp | 49 +++++++------------ src/frontend/A64/translate/impl/impl.h | 12 +++++ 9 files changed, 54 insertions(+), 140 deletions(-) diff --git a/src/frontend/A64/translate/impl/floating_point_compare.cpp b/src/frontend/A64/translate/impl/floating_point_compare.cpp index 5e8708ec..01ec66cb 100644 --- a/src/frontend/A64/translate/impl/floating_point_compare.cpp +++ b/src/frontend/A64/translate/impl/floating_point_compare.cpp @@ -10,22 +10,9 @@ namespace Dynarmic::A64 { namespace { -boost::optional GetDataSize(Imm<2> type) { - switch (type.ZeroExtend()) { - case 0b00: - return 32; - case 0b01: - return 64; - case 0b11: - // FP16Ext, unimplemented. - return boost::none; - } - return boost::none; -} - bool FPCompare(TranslatorVisitor& v, Imm<2> type, Vec Vm, Vec Vn, bool exc_on_qnan, bool cmp_with_zero) { - const auto datasize = GetDataSize(type); - if (!datasize) { + const auto datasize = FPGetDataSize(type); + if (!datasize || *datasize == 16) { return v.UnallocatedEncoding(); } diff --git a/src/frontend/A64/translate/impl/floating_point_conditional_compare.cpp b/src/frontend/A64/translate/impl/floating_point_conditional_compare.cpp index 88c1a5a0..72c14c91 100644 --- a/src/frontend/A64/translate/impl/floating_point_conditional_compare.cpp +++ b/src/frontend/A64/translate/impl/floating_point_conditional_compare.cpp @@ -10,20 +10,8 @@ namespace Dynarmic::A64 { namespace { -static boost::optional GetDataSize(Imm<2> type) { - switch (type.ZeroExtend()) { - case 0b00: - return 32; - case 0b01: - return 64; - case 0b11: - return 16; - } - return boost::none; -} - bool FPCompare(TranslatorVisitor& v, Imm<2> type, Vec Vm, Cond cond, Vec Vn, Imm<4> nzcv, bool exc_on_qnan) { - const auto datasize = GetDataSize(type); + const auto datasize = FPGetDataSize(type); if (!datasize || *datasize == 16) { return v.UnallocatedEncoding(); } diff --git a/src/frontend/A64/translate/impl/floating_point_conditional_select.cpp b/src/frontend/A64/translate/impl/floating_point_conditional_select.cpp index 5b016db4..f870f2c4 100644 --- a/src/frontend/A64/translate/impl/floating_point_conditional_select.cpp +++ b/src/frontend/A64/translate/impl/floating_point_conditional_select.cpp @@ -10,20 +10,8 @@ namespace Dynarmic::A64 { -static boost::optional GetDataSize(Imm<2> type) { - switch (type.ZeroExtend()) { - case 0b00: - return 32; - case 0b01: - return 64; - case 0b11: - return 16; - } - return boost::none; -} - bool TranslatorVisitor::FCSEL_float(Imm<2> type, Vec Vm, Cond cond, Vec Vn, Vec Vd) { - const auto datasize = GetDataSize(type); + const auto datasize = FPGetDataSize(type); if (!datasize || *datasize == 16) { return UnallocatedEncoding(); } diff --git a/src/frontend/A64/translate/impl/floating_point_conversion_fixed_point.cpp b/src/frontend/A64/translate/impl/floating_point_conversion_fixed_point.cpp index 8f4eb7df..b346dbd8 100644 --- a/src/frontend/A64/translate/impl/floating_point_conversion_fixed_point.cpp +++ b/src/frontend/A64/translate/impl/floating_point_conversion_fixed_point.cpp @@ -10,21 +10,9 @@ namespace Dynarmic::A64 { -static boost::optional GetDataSize(Imm<2> type) { - switch (type.ZeroExtend()) { - case 0b00: - return 32; - case 0b01: - return 64; - case 0b11: - return 16; - } - return boost::none; -} - bool TranslatorVisitor::FCVTZS_float_fix(bool sf, Imm<2> type, Imm<6> scale, Vec Vn, Reg Rd) { const size_t intsize = sf ? 64 : 32; - const auto fltsize = GetDataSize(type); + const auto fltsize = FPGetDataSize(type); if (!fltsize || *fltsize == 16) { return UnallocatedEncoding(); } @@ -55,7 +43,7 @@ bool TranslatorVisitor::FCVTZS_float_fix(bool sf, Imm<2> type, Imm<6> scale, Vec bool TranslatorVisitor::FCVTZU_float_fix(bool sf, Imm<2> type, Imm<6> scale, Vec Vn, Reg Rd) { const size_t intsize = sf ? 64 : 32; - const auto fltsize = GetDataSize(type); + const auto fltsize = FPGetDataSize(type); if (!fltsize || *fltsize == 16) { return UnallocatedEncoding(); } diff --git a/src/frontend/A64/translate/impl/floating_point_conversion_integer.cpp b/src/frontend/A64/translate/impl/floating_point_conversion_integer.cpp index ad581687..35f03411 100644 --- a/src/frontend/A64/translate/impl/floating_point_conversion_integer.cpp +++ b/src/frontend/A64/translate/impl/floating_point_conversion_integer.cpp @@ -11,21 +11,9 @@ namespace Dynarmic::A64 { -static boost::optional GetDataSize(Imm<2> type) { - switch (type.ZeroExtend()) { - case 0b00: - return 32; - case 0b01: - return 64; - case 0b11: - return 16; - } - return boost::none; -} - bool TranslatorVisitor::SCVTF_float_int(bool sf, Imm<2> type, Reg Rn, Vec Vd) { const size_t intsize = sf ? 64 : 32; - const auto fltsize = GetDataSize(type); + const auto fltsize = FPGetDataSize(type); if (!fltsize || *fltsize == 16) { return UnallocatedEncoding(); } @@ -52,7 +40,7 @@ bool TranslatorVisitor::SCVTF_float_int(bool sf, Imm<2> type, Reg Rn, Vec Vd) { bool TranslatorVisitor::UCVTF_float_int(bool sf, Imm<2> type, Reg Rn, Vec Vd) { const size_t intsize = sf ? 64 : 32; - const auto fltsize = GetDataSize(type); + const auto fltsize = FPGetDataSize(type); if (!fltsize || *fltsize == 16) { return UnallocatedEncoding(); } @@ -138,7 +126,7 @@ bool TranslatorVisitor::FMOV_float_gen(bool sf, Imm<2> type, Imm<1> rmode_0, Imm static bool FloaingPointConvertSignedInteger(TranslatorVisitor& v, bool sf, Imm<2> type, Vec Vn, Reg Rd, FP::RoundingMode rounding_mode) { const size_t intsize = sf ? 64 : 32; - const auto fltsize = GetDataSize(type); + const auto fltsize = FPGetDataSize(type); if (!fltsize || *fltsize == 16) { return v.UnallocatedEncoding(); } @@ -165,7 +153,7 @@ static bool FloaingPointConvertSignedInteger(TranslatorVisitor& v, bool sf, Imm< static bool FloaingPointConvertUnsignedInteger(TranslatorVisitor& v, bool sf, Imm<2> type, Vec Vn, Reg Rd, FP::RoundingMode rounding_mode) { const size_t intsize = sf ? 64 : 32; - const auto fltsize = GetDataSize(type); + const auto fltsize = FPGetDataSize(type); if (!fltsize || *fltsize == 16) { return v.UnallocatedEncoding(); } diff --git a/src/frontend/A64/translate/impl/floating_point_data_processing_one_register.cpp b/src/frontend/A64/translate/impl/floating_point_data_processing_one_register.cpp index 27bf35b2..2d392646 100644 --- a/src/frontend/A64/translate/impl/floating_point_data_processing_one_register.cpp +++ b/src/frontend/A64/translate/impl/floating_point_data_processing_one_register.cpp @@ -10,20 +10,8 @@ namespace Dynarmic::A64 { -static boost::optional GetDataSize(Imm<2> type) { - switch (type.ZeroExtend()) { - case 0b00: - return 32; - case 0b01: - return 64; - case 0b11: - return 16; - } - return boost::none; -} - bool TranslatorVisitor::FMOV_float(Imm<2> type, Vec Vn, Vec Vd) { - const boost::optional datasize = GetDataSize(type); + const auto datasize = FPGetDataSize(type); if (!datasize || *datasize == 16) { return UnallocatedEncoding(); } @@ -35,7 +23,7 @@ bool TranslatorVisitor::FMOV_float(Imm<2> type, Vec Vn, Vec Vd) { } bool TranslatorVisitor::FABS_float(Imm<2> type, Vec Vn, Vec Vd) { - boost::optional datasize = GetDataSize(type); + const auto datasize = FPGetDataSize(type); if (!datasize || *datasize == 16) { return UnallocatedEncoding(); } @@ -47,7 +35,7 @@ bool TranslatorVisitor::FABS_float(Imm<2> type, Vec Vn, Vec Vd) { } bool TranslatorVisitor::FNEG_float(Imm<2> type, Vec Vn, Vec Vd) { - boost::optional datasize = GetDataSize(type); + const auto datasize = FPGetDataSize(type); if (!datasize || *datasize == 16) { return UnallocatedEncoding(); } @@ -59,7 +47,7 @@ bool TranslatorVisitor::FNEG_float(Imm<2> type, Vec Vn, Vec Vd) { } bool TranslatorVisitor::FSQRT_float(Imm<2> type, Vec Vn, Vec Vd) { - boost::optional datasize = GetDataSize(type); + const auto datasize = FPGetDataSize(type); if (!datasize || *datasize == 16) { return UnallocatedEncoding(); } @@ -71,7 +59,7 @@ bool TranslatorVisitor::FSQRT_float(Imm<2> type, Vec Vn, Vec Vd) { } bool TranslatorVisitor::FMOV_float_imm(Imm<2> type, Imm<8> imm8, Vec Vd) { - boost::optional datasize = GetDataSize(type); + const auto datasize = FPGetDataSize(type); if (!datasize) { return UnallocatedEncoding(); } @@ -109,8 +97,8 @@ bool TranslatorVisitor::FCVT_float(Imm<2> type, Imm<2> opc, Vec Vn, Vec Vd) { return UnallocatedEncoding(); } - boost::optional srcsize = GetDataSize(type); - boost::optional dstsize = GetDataSize(opc); + const auto srcsize = FPGetDataSize(type); + const auto dstsize = FPGetDataSize(opc); if (!srcsize || !dstsize) { return UnallocatedEncoding(); @@ -152,8 +140,9 @@ bool TranslatorVisitor::FCVT_float(Imm<2> type, Imm<2> opc, Vec Vn, Vec Vd) { return true; } -bool FloatingPointRoundToIntegral(TranslatorVisitor& v, Imm<2> type, Vec Vn, Vec Vd, FP::RoundingMode rounding_mode, bool exact) { - const boost::optional datasize = GetDataSize(type); +static bool FloatingPointRoundToIntegral(TranslatorVisitor& v, Imm<2> type, Vec Vn, Vec Vd, + FP::RoundingMode rounding_mode, bool exact) { + const auto datasize = FPGetDataSize(type); if (!datasize || *datasize == 16) { return v.UnallocatedEncoding(); } diff --git a/src/frontend/A64/translate/impl/floating_point_data_processing_three_register.cpp b/src/frontend/A64/translate/impl/floating_point_data_processing_three_register.cpp index 488cedbe..a6cf8c96 100644 --- a/src/frontend/A64/translate/impl/floating_point_data_processing_three_register.cpp +++ b/src/frontend/A64/translate/impl/floating_point_data_processing_three_register.cpp @@ -10,21 +10,8 @@ namespace Dynarmic::A64 { -static boost::optional GetDataSize(Imm<2> type) { - switch (type.ZeroExtend()) { - case 0b00: - return 32; - case 0b01: - return 64; - case 0b11: - // FP16Ext, unimplemented. - return boost::none; - } - return boost::none; -} - bool TranslatorVisitor::FMADD_float(Imm<2> type, Vec Vm, Vec Va, Vec Vn, Vec Vd) { - const auto datasize = GetDataSize(type); + const auto datasize = FPGetDataSize(type); if (!datasize || *datasize == 16) { return UnallocatedEncoding(); } @@ -38,7 +25,7 @@ bool TranslatorVisitor::FMADD_float(Imm<2> type, Vec Vm, Vec Va, Vec Vn, Vec Vd) } bool TranslatorVisitor::FMSUB_float(Imm<2> type, Vec Vm, Vec Va, Vec Vn, Vec Vd) { - const auto datasize = GetDataSize(type); + const auto datasize = FPGetDataSize(type); if (!datasize || *datasize == 16) { return UnallocatedEncoding(); } @@ -52,7 +39,7 @@ bool TranslatorVisitor::FMSUB_float(Imm<2> type, Vec Vm, Vec Va, Vec Vn, Vec Vd) } bool TranslatorVisitor::FNMADD_float(Imm<2> type, Vec Vm, Vec Va, Vec Vn, Vec Vd) { - const auto datasize = GetDataSize(type); + const auto datasize = FPGetDataSize(type); if (!datasize || *datasize == 16) { return UnallocatedEncoding(); } @@ -66,7 +53,7 @@ bool TranslatorVisitor::FNMADD_float(Imm<2> type, Vec Vm, Vec Va, Vec Vn, Vec Vd } bool TranslatorVisitor::FNMSUB_float(Imm<2> type, Vec Vm, Vec Va, Vec Vn, Vec Vd) { - const auto datasize = GetDataSize(type); + const auto datasize = FPGetDataSize(type); if (!datasize || *datasize == 16) { return UnallocatedEncoding(); } diff --git a/src/frontend/A64/translate/impl/floating_point_data_processing_two_register.cpp b/src/frontend/A64/translate/impl/floating_point_data_processing_two_register.cpp index 2ec744f9..e76b312e 100644 --- a/src/frontend/A64/translate/impl/floating_point_data_processing_two_register.cpp +++ b/src/frontend/A64/translate/impl/floating_point_data_processing_two_register.cpp @@ -10,22 +10,9 @@ namespace Dynarmic::A64 { -static boost::optional GetDataSize(Imm<2> type) { - switch (type.ZeroExtend()) { - case 0b00: - return 32; - case 0b01: - return 64; - case 0b11: - // FP16Ext, unimplemented. - return boost::none; - } - return boost::none; -} - bool TranslatorVisitor::FMUL_float(Imm<2> type, Vec Vm, Vec Vn, Vec Vd) { - auto datasize = GetDataSize(type); - if (!datasize) { + const auto datasize = FPGetDataSize(type); + if (!datasize || *datasize == 16) { return UnallocatedEncoding(); } @@ -39,8 +26,8 @@ bool TranslatorVisitor::FMUL_float(Imm<2> type, Vec Vm, Vec Vn, Vec Vd) { } bool TranslatorVisitor::FDIV_float(Imm<2> type, Vec Vm, Vec Vn, Vec Vd) { - auto datasize = GetDataSize(type); - if (!datasize) { + const auto datasize = FPGetDataSize(type); + if (!datasize || *datasize == 16) { return UnallocatedEncoding(); } @@ -54,8 +41,8 @@ bool TranslatorVisitor::FDIV_float(Imm<2> type, Vec Vm, Vec Vn, Vec Vd) { } bool TranslatorVisitor::FADD_float(Imm<2> type, Vec Vm, Vec Vn, Vec Vd) { - auto datasize = GetDataSize(type); - if (!datasize) { + const auto datasize = FPGetDataSize(type); + if (!datasize || *datasize == 16) { return UnallocatedEncoding(); } @@ -69,8 +56,8 @@ bool TranslatorVisitor::FADD_float(Imm<2> type, Vec Vm, Vec Vn, Vec Vd) { } bool TranslatorVisitor::FSUB_float(Imm<2> type, Vec Vm, Vec Vn, Vec Vd) { - auto datasize = GetDataSize(type); - if (!datasize) { + const auto datasize = FPGetDataSize(type); + if (!datasize || *datasize == 16) { return UnallocatedEncoding(); } @@ -84,8 +71,8 @@ bool TranslatorVisitor::FSUB_float(Imm<2> type, Vec Vm, Vec Vn, Vec Vd) { } bool TranslatorVisitor::FMAX_float(Imm<2> type, Vec Vm, Vec Vn, Vec Vd) { - auto datasize = GetDataSize(type); - if (!datasize) { + const auto datasize = FPGetDataSize(type); + if (!datasize || *datasize == 16) { return UnallocatedEncoding(); } @@ -99,8 +86,8 @@ bool TranslatorVisitor::FMAX_float(Imm<2> type, Vec Vm, Vec Vn, Vec Vd) { } bool TranslatorVisitor::FMIN_float(Imm<2> type, Vec Vm, Vec Vn, Vec Vd) { - auto datasize = GetDataSize(type); - if (!datasize) { + const auto datasize = FPGetDataSize(type); + if (!datasize || *datasize == 16) { return UnallocatedEncoding(); } @@ -114,8 +101,8 @@ bool TranslatorVisitor::FMIN_float(Imm<2> type, Vec Vm, Vec Vn, Vec Vd) { } bool TranslatorVisitor::FMAXNM_float(Imm<2> type, Vec Vm, Vec Vn, Vec Vd) { - auto datasize = GetDataSize(type); - if (!datasize) { + const auto datasize = FPGetDataSize(type); + if (!datasize || *datasize == 16) { return UnallocatedEncoding(); } @@ -129,8 +116,8 @@ bool TranslatorVisitor::FMAXNM_float(Imm<2> type, Vec Vm, Vec Vn, Vec Vd) { } bool TranslatorVisitor::FMINNM_float(Imm<2> type, Vec Vm, Vec Vn, Vec Vd) { - auto datasize = GetDataSize(type); - if (!datasize) { + const auto datasize = FPGetDataSize(type); + if (!datasize || *datasize == 16) { return UnallocatedEncoding(); } @@ -144,8 +131,8 @@ bool TranslatorVisitor::FMINNM_float(Imm<2> type, Vec Vm, Vec Vn, Vec Vd) { } bool TranslatorVisitor::FNMUL_float(Imm<2> type, Vec Vm, Vec Vn, Vec Vd) { - auto datasize = GetDataSize(type); - if (!datasize) { + const auto datasize = FPGetDataSize(type); + if (!datasize || *datasize == 16) { return UnallocatedEncoding(); } diff --git a/src/frontend/A64/translate/impl/impl.h b/src/frontend/A64/translate/impl/impl.h index dd44f99a..06a9f02c 100644 --- a/src/frontend/A64/translate/impl/impl.h +++ b/src/frontend/A64/translate/impl/impl.h @@ -1014,4 +1014,16 @@ struct TranslatorVisitor final { bool FNMSUB_float(Imm<2> type, Vec Vm, Vec Va, Vec Vn, Vec Vd); }; +inline boost::optional FPGetDataSize(Imm<2> type) { + switch (type.ZeroExtend()) { + case 0b00: + return 32; + case 0b01: + return 64; + case 0b11: + return 16; + } + return boost::none; +} + } // namespace Dynarmic::A64