2018-01-13 18:04:19 +00:00
|
|
|
/* This file is part of the dynarmic project.
|
|
|
|
* Copyright (c) 2018 MerryMage
|
2020-04-23 15:25:11 +01:00
|
|
|
* SPDX-License-Identifier: 0BSD
|
2018-01-13 18:04:19 +00:00
|
|
|
*/
|
|
|
|
|
2018-08-11 18:17:41 +01:00
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
#include <fmt/format.h>
|
|
|
|
#include <fmt/ostream.h>
|
|
|
|
|
2018-01-13 18:04:19 +00:00
|
|
|
#include "common/assert.h"
|
2018-08-11 18:17:41 +01:00
|
|
|
#include "common/fp/fpcr.h"
|
|
|
|
#include "common/fp/rounding_mode.h"
|
|
|
|
#include "fuzz_util.h"
|
2018-01-13 18:04:19 +00:00
|
|
|
#include "rand_int.h"
|
|
|
|
|
2018-08-11 18:17:41 +01:00
|
|
|
using namespace Dynarmic;
|
|
|
|
|
|
|
|
std::ostream& operator<<(std::ostream& o, Vector vec) {
|
|
|
|
return o << fmt::format("{:016x}'{:016x}", vec[1], vec[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector RandomVector() {
|
|
|
|
return {RandInt<u64>(0, ~u64(0)), RandInt<u64>(0, ~u64(0))};
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 RandomFpcr() {
|
|
|
|
FP::FPCR fpcr;
|
|
|
|
fpcr.AHP(RandInt(0, 1) == 0);
|
|
|
|
fpcr.DN(RandInt(0, 1) == 0);
|
|
|
|
fpcr.FZ(RandInt(0, 1) == 0);
|
|
|
|
fpcr.RMode(static_cast<FP::RoundingMode>(RandInt(0, 3)));
|
|
|
|
fpcr.FZ16(RandInt(0, 1) == 0);
|
|
|
|
return fpcr.Value();
|
|
|
|
}
|
|
|
|
|
2018-01-13 18:04:19 +00:00
|
|
|
InstructionGenerator::InstructionGenerator(const char* format){
|
|
|
|
ASSERT(std::strlen(format) == 32);
|
|
|
|
|
|
|
|
for (int i = 0; i < 32; i++) {
|
|
|
|
const u32 bit = 1u << (31 - i);
|
|
|
|
switch (format[i]) {
|
|
|
|
case '0':
|
|
|
|
mask |= bit;
|
|
|
|
break;
|
|
|
|
case '1':
|
|
|
|
bits |= bit;
|
|
|
|
mask |= bit;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// Do nothing
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 InstructionGenerator::Generate() const {
|
2018-11-24 00:55:27 +00:00
|
|
|
const u32 random = RandInt<u32>(0, 0xFFFFFFFF);
|
|
|
|
return bits | (random & ~mask);
|
2018-01-13 18:04:19 +00:00
|
|
|
}
|