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.
This commit is contained in:
Lioncash 2018-07-13 09:39:56 -04:00 committed by MerryMage
parent ef57d75b32
commit d909b0919e

View file

@ -372,17 +372,20 @@ TEST_CASE("A64: Floating point instructions", "[a64]") {
}
TEST_CASE("A64: Small random block", "[a64]") {
std::array<u64, 31> regs;
std::array<Vector, 32> vecs;
std::vector<u32> instructions(5);
for (size_t iteration = 0; iteration < 100000; ++iteration) {
std::array<u64, 31> regs;
std::generate_n(regs.begin(), 31, []{ return RandInt<u64>(0, ~u64(0)); });
std::array<Vector, 32> vecs;
std::generate_n(vecs.begin(), 32, []{ return RandomVector(); });
std::vector<u32> 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<u64>(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<u32>(0, 0xF) << 28;
u32 fpcr = RandInt<u32>(0, 0x3) << 22; // randomize RMode