From 9364ba821ef9e0ceffc717dbe06a12a1e8375b2b Mon Sep 17 00:00:00 2001 From: Merry Date: Fri, 3 Feb 2023 22:16:29 +0000 Subject: [PATCH] tests: Support noopt mode --- tests/test_generator.cpp | 35 +++++++++++++++++++++-------------- tests/test_reader.cpp | 34 +++++++++++++++++++++------------- 2 files changed, 42 insertions(+), 27 deletions(-) diff --git a/tests/test_generator.cpp b/tests/test_generator.cpp index 024db15c..35f8ff39 100644 --- a/tests/test_generator.cpp +++ b/tests/test_generator.cpp @@ -383,10 +383,13 @@ u32 GenRandomA64Inst(u64 pc, bool is_last_inst) { } template -Dynarmic::A32::UserConfig GetA32UserConfig(TestEnv& testenv) { +Dynarmic::A32::UserConfig GetA32UserConfig(TestEnv& testenv, bool noopt) { Dynarmic::A32::UserConfig user_config; user_config.optimizations &= ~OptimizationFlag::FastDispatch; user_config.callbacks = &testenv; + if (noopt) { + user_config.optimizations = no_optimizations; + } return user_config; } @@ -473,16 +476,19 @@ void RunTestInstance(Dynarmic::A32::Jit& jit, fmt::print("===\n"); } -Dynarmic::A64::UserConfig GetA64UserConfig(A64TestEnv& jit_env) { +Dynarmic::A64::UserConfig GetA64UserConfig(A64TestEnv& jit_env, bool noopt) { Dynarmic::A64::UserConfig jit_user_config{&jit_env}; jit_user_config.optimizations &= ~OptimizationFlag::FastDispatch; // The below corresponds to the settings for qemu's aarch64_max_initfn jit_user_config.dczid_el0 = 7; jit_user_config.ctr_el0 = 0x80038003; + if (noopt) { + jit_user_config.optimizations = no_optimizations; + } return jit_user_config; } -template +template void RunTestInstance(Dynarmic::A64::Jit& jit, A64TestEnv& jit_env, const std::array& regs, @@ -567,9 +573,9 @@ void RunTestInstance(Dynarmic::A64::Jit& jit, } // Anonymous namespace -void TestThumb(size_t num_instructions, size_t num_iterations) { +void TestThumb(size_t num_instructions, size_t num_iterations, bool noopt) { ThumbTestEnv jit_env{}; - Dynarmic::A32::Jit jit{GetA32UserConfig(jit_env)}; + Dynarmic::A32::Jit jit{GetA32UserConfig(jit_env, noopt)}; std::array regs; std::array ext_reg; @@ -594,9 +600,9 @@ void TestThumb(size_t num_instructions, size_t num_iterations) { } } -void TestArm(size_t num_instructions, size_t num_iterations) { +void TestArm(size_t num_instructions, size_t num_iterations, bool noopt) { ArmTestEnv jit_env{}; - Dynarmic::A32::Jit jit{GetA32UserConfig(jit_env)}; + Dynarmic::A32::Jit jit{GetA32UserConfig(jit_env, noopt)}; std::array regs; std::array ext_reg; @@ -620,9 +626,9 @@ void TestArm(size_t num_instructions, size_t num_iterations) { } } -void TestA64(size_t num_instructions, size_t num_iterations) { +void TestA64(size_t num_instructions, size_t num_iterations, bool noopt) { A64TestEnv jit_env{}; - Dynarmic::A64::Jit jit{GetA64UserConfig(jit_env)}; + Dynarmic::A64::Jit jit{GetA64UserConfig(jit_env, noopt)}; std::array regs; std::array, 32> vecs; @@ -661,14 +667,15 @@ static std::optional str2sz(char const* s) { } int main(int argc, char* argv[]) { - if (argc != 5) { - fmt::print("Usage: {} \n", argv[0]); + if (argc < 5 || argc > 6) { + fmt::print("Usage: {} [noopt]\n", argv[0]); return 1; } const auto seed = str2sz(argv[2]); const auto instruction_count = str2sz(argv[3]); const auto iterator_count = str2sz(argv[4]); + const bool noopt = argc == 6 && (strcmp(argv[5], "noopt") == 0); if (!seed || !instruction_count || !iterator_count) { fmt::print("invalid numeric arguments\n"); @@ -678,11 +685,11 @@ int main(int argc, char* argv[]) { detail::g_rand_int_generator.seed(static_cast(*seed)); if (strcmp(argv[1], "thumb") == 0) { - TestThumb(*instruction_count, *iterator_count); + TestThumb(*instruction_count, *iterator_count, noopt); } else if (strcmp(argv[1], "arm") == 0) { - TestArm(*instruction_count, *iterator_count); + TestArm(*instruction_count, *iterator_count, noopt); } else if (strcmp(argv[1], "a64") == 0) { - TestA64(*instruction_count, *iterator_count); + TestA64(*instruction_count, *iterator_count, noopt); } else { fmt::print("unrecognized instruction class\n"); return 1; diff --git a/tests/test_reader.cpp b/tests/test_reader.cpp index 7c60a9f9..44d6e966 100644 --- a/tests/test_reader.cpp +++ b/tests/test_reader.cpp @@ -63,11 +63,14 @@ u64 ParseHex(std::string_view hex) { } template -Dynarmic::A32::UserConfig GetA32UserConfig(TestEnv& testenv) { +Dynarmic::A32::UserConfig GetA32UserConfig(TestEnv& testenv, bool noopt) { Dynarmic::A32::UserConfig user_config; user_config.optimizations &= ~OptimizationFlag::FastDispatch; user_config.callbacks = &testenv; user_config.very_verbose_debugging_output = true; + if (noopt) { + user_config.optimizations = no_optimizations; + } return user_config; } @@ -154,13 +157,16 @@ void RunTestInstance(Dynarmic::A32::Jit& jit, fmt::print("===\n"); } -A64::UserConfig GetA64UserConfig(A64TestEnv& jit_env) { +A64::UserConfig GetA64UserConfig(A64TestEnv& jit_env, bool noopt) { A64::UserConfig jit_user_config{&jit_env}; jit_user_config.optimizations &= ~OptimizationFlag::FastDispatch; // The below corresponds to the settings for qemu's aarch64_max_initfn jit_user_config.dczid_el0 = 7; jit_user_config.ctr_el0 = 0x80038003; jit_user_config.very_verbose_debugging_output = true; + if (noopt) { + jit_user_config.optimizations = no_optimizations; + } return jit_user_config; } @@ -247,7 +253,7 @@ void RunTestInstance(A64::Jit& jit, fmt::print("===\n"); } -void RunThumb() { +void RunThumb(bool noopt) { std::array initial_regs{}; std::array initial_vecs{}; std::vector instructions{}; @@ -283,7 +289,7 @@ void RunThumb() { } ThumbTestEnv jit_env{}; - A32::Jit jit{GetA32UserConfig(jit_env)}; + A32::Jit jit{GetA32UserConfig(jit_env, noopt)}; RunTestInstance(jit, jit_env, initial_regs, @@ -294,7 +300,7 @@ void RunThumb() { instructions.size()); } -void RunArm() { +void RunArm(bool noopt) { std::array initial_regs{}; std::array initial_vecs{}; std::vector instructions{}; @@ -330,7 +336,7 @@ void RunArm() { } ArmTestEnv jit_env{}; - A32::Jit jit{GetA32UserConfig(jit_env)}; + A32::Jit jit{GetA32UserConfig(jit_env, noopt)}; RunTestInstance(jit, jit_env, initial_regs, @@ -341,7 +347,7 @@ void RunArm() { instructions.size()); } -void RunA64() { +void RunA64(bool noopt) { std::array initial_regs{}; std::array, 32> initial_vecs{}; std::vector instructions{}; @@ -385,7 +391,7 @@ void RunA64() { } A64TestEnv jit_env{}; - A64::Jit jit{GetA64UserConfig(jit_env)}; + A64::Jit jit{GetA64UserConfig(jit_env, noopt)}; RunTestInstance(jit, jit_env, initial_regs, @@ -399,17 +405,19 @@ void RunA64() { } int main(int argc, char** argv) { - if (argc != 2) { - fmt::print("Usage: {} \n", argv[0]); + if (argc < 2 || argc > 3) { + fmt::print("Usage: {} [noopt]\n", argv[0]); return 1; } + const bool noopt = argc == 3 && (strcmp(argv[2], "noopt") == 0); + if (strcmp(argv[1], "thumb") == 0) { - RunThumb(); + RunThumb(noopt); } else if (strcmp(argv[1], "arm") == 0) { - RunArm(); + RunArm(noopt); } else if (strcmp(argv[1], "a64") == 0) { - RunA64(); + RunA64(noopt); } else { fmt::print("unrecognized instruction class\n"); return 1;