dynarmic/tests/A64/inst_gen.h
Lioncash 7d52d7bef8 inst_gen: Compress loop into std::any_of in IsInvalidInstruction()
Same behavior, but using a more self-documenting function.
2020-04-22 20:46:18 +01:00

36 lines
1 KiB
C++

/* This file is part of the dynarmic project.
* Copyright (c) 2018 MerryMage
* This software may be used and distributed according to the terms of the GNU
* General Public License version 2 or any later version.
*/
#include <algorithm>
#include <cstring>
#include <vector>
#include "common/common_types.h"
struct InstructionGenerator final {
public:
explicit InstructionGenerator(const char* format);
u32 Generate() const;
u32 Bits() const { return bits; }
u32 Mask() const { return mask; }
bool Match(u32 inst) const { return (inst & mask) == bits; }
static void AddInvalidInstruction(const char* format) {
invalid_instructions.emplace_back(InstructionGenerator{format});
}
static bool IsInvalidInstruction(u32 inst) {
return std::any_of(invalid_instructions.begin(), invalid_instructions.end(),
[inst](const auto& invalid) { return invalid.Match(inst); });
}
private:
static inline std::vector<InstructionGenerator> invalid_instructions;
u32 bits = 0;
u32 mask = 0;
};