From d909b0919e1cad9a16c93ac7d1139adc753a804d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 13 Jul 2018 09:39:56 -0400 Subject: [PATCH] fuzz_with_unicorn: Move std::vector outside loop in small random block test case Avoids constructing and destructing the vector repeatedly, we can just alter the contents of the vector on each iteration instead. Also move out the std::array instances as well, like with the floating-point test case and the single random instruction test case. We can also use the regular form of std::generate and avoid hardcoding size values twice. --- tests/A64/fuzz_with_unicorn.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/tests/A64/fuzz_with_unicorn.cpp b/tests/A64/fuzz_with_unicorn.cpp index 96fbf62d..ccdf57f7 100644 --- a/tests/A64/fuzz_with_unicorn.cpp +++ b/tests/A64/fuzz_with_unicorn.cpp @@ -372,17 +372,20 @@ TEST_CASE("A64: Floating point instructions", "[a64]") { } TEST_CASE("A64: Small random block", "[a64]") { + std::array regs; + std::array vecs; + std::vector instructions(5); + for (size_t iteration = 0; iteration < 100000; ++iteration) { - std::array regs; - std::generate_n(regs.begin(), 31, []{ return RandInt(0, ~u64(0)); }); - std::array vecs; - std::generate_n(vecs.begin(), 32, []{ return RandomVector(); }); - std::vector instructions; - instructions.push_back(GenRandomInst(0, false)); - instructions.push_back(GenRandomInst(4, false)); - instructions.push_back(GenRandomInst(8, false)); - instructions.push_back(GenRandomInst(12, false)); - instructions.push_back(GenRandomInst(16, true)); + std::generate(regs.begin(), regs.end(), [] { return RandInt(0, ~u64(0)); }); + std::generate(vecs.begin(), vecs.end(), RandomVector); + + instructions[0] = GenRandomInst(0, false); + instructions[1] = GenRandomInst(4, false); + instructions[2] = GenRandomInst(8, false); + instructions[3] = GenRandomInst(12, false); + instructions[4] = GenRandomInst(16, true); + u32 pstate = RandInt(0, 0xF) << 28; u32 fpcr = RandInt(0, 0x3) << 22; // randomize RMode