/* 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. */ #pragma once #include #include #include #include #include "common/bit_util.h" #include "common/common_types.h" #include "frontend/decoder/decoder_detail.h" #include "frontend/decoder/matcher.h" namespace Dynarmic { namespace A64 { template using Matcher = Decoder::Matcher; template std::vector> GetDecodeTable() { std::vector> table = { #define INST(fn, name, bitstring) Decoder::detail::detail>::GetMatcher(&Visitor::fn, name, bitstring), #include "a64.inc" #undef INST }; // If a matcher has more bits in its mask it is more specific, so it should come first. std::stable_sort(table.begin(), table.end(), [](const auto& matcher1, const auto& matcher2) { return Common::BitCount(matcher1.GetMask()) > Common::BitCount(matcher2.GetMask()); }); return table; } template boost::optional&> Decode(u32 instruction) { static const auto table = GetDecodeTable(); const auto matches_instruction = [instruction](const auto& matcher) { return matcher.Matches(instruction); }; auto iter = std::find_if(table.begin(), table.end(), matches_instruction); return iter != table.end() ? boost::optional&>(*iter) : boost::none; } } // namespace A64 } // namespace Dynarmic