lut_from_list: Reduce number of required template arguments

This commit is contained in:
MerryMage 2020-04-04 09:52:06 +01:00
parent 8658afd8c5
commit fe583aa076
3 changed files with 32 additions and 28 deletions

View file

@ -857,14 +857,11 @@ static void EmitFPRound(BlockOfCode& code, EmitContext& ctx, IR::Inst* inst, siz
>; >;
using exact_list = mp::list<std::true_type, std::false_type>; using exact_list = mp::list<std::true_type, std::false_type>;
using key_type = std::tuple<size_t, FP::RoundingMode, bool>; static const auto lut = Common::GenerateLookupTableFromList(
using value_type = u64(*)(u64, FP::FPSR&, FP::FPCR);
static const auto lut = Common::GenerateLookupTableFromList<key_type, value_type>(
[](auto args) { [](auto args) {
return std::pair<key_type, value_type>{ return std::pair{
mp::lower_to_tuple_v<decltype(args)>, mp::lower_to_tuple_v<decltype(args)>,
static_cast<value_type>( static_cast<u64(*)(u64, FP::FPSR&, FP::FPCR)>(
[](u64 input, FP::FPSR& fpsr, FP::FPCR fpcr) { [](u64 input, FP::FPSR& fpsr, FP::FPCR fpcr) {
constexpr auto t = mp::lower_to_tuple_v<decltype(args)>; constexpr auto t = mp::lower_to_tuple_v<decltype(args)>;
constexpr size_t fsize = std::get<0>(t); constexpr size_t fsize = std::get<0>(t);
@ -1288,14 +1285,11 @@ static void EmitFPToFixed(BlockOfCode& code, EmitContext& ctx, IR::Inst* inst) {
mp::lift_value<FP::RoundingMode::ToNearest_TieAwayFromZero> mp::lift_value<FP::RoundingMode::ToNearest_TieAwayFromZero>
>; >;
using key_type = std::tuple<size_t, FP::RoundingMode>; static const auto lut = Common::GenerateLookupTableFromList(
using value_type = u64(*)(u64, FP::FPSR&, FP::FPCR);
static const auto lut = Common::GenerateLookupTableFromList<key_type, value_type>(
[](auto args) { [](auto args) {
return std::pair<key_type, value_type>{ return std::pair{
mp::lower_to_tuple_v<decltype(args)>, mp::lower_to_tuple_v<decltype(args)>,
static_cast<value_type>( static_cast<u64(*)(u64, FP::FPSR&, FP::FPCR)>(
[](u64 input, FP::FPSR& fpsr, FP::FPCR fpcr) { [](u64 input, FP::FPSR& fpsr, FP::FPCR fpcr) {
constexpr auto t = mp::lower_to_tuple_v<decltype(args)>; constexpr auto t = mp::lower_to_tuple_v<decltype(args)>;
constexpr size_t fbits = std::get<0>(t); constexpr size_t fbits = std::get<0>(t);

View file

@ -1213,14 +1213,11 @@ void EmitFPVectorRoundInt(BlockOfCode& code, EmitContext& ctx, IR::Inst* inst) {
>; >;
using exact_list = mp::list<std::true_type, std::false_type>; using exact_list = mp::list<std::true_type, std::false_type>;
using key_type = std::tuple<FP::RoundingMode, bool>; static const auto lut = Common::GenerateLookupTableFromList(
using value_type = void(*)(VectorArray<FPT>&, const VectorArray<FPT>&, FP::FPCR, FP::FPSR&);
static const auto lut = Common::GenerateLookupTableFromList<key_type, value_type>(
[](auto arg) { [](auto arg) {
return std::pair<key_type, value_type>{ return std::pair{
mp::lower_to_tuple_v<decltype(arg)>, mp::lower_to_tuple_v<decltype(arg)>,
static_cast<value_type>( static_cast<void(*)(VectorArray<FPT>&, const VectorArray<FPT>&, FP::FPCR, FP::FPSR&)>(
[](VectorArray<FPT>& output, const VectorArray<FPT>& input, FP::FPCR fpcr, FP::FPSR& fpsr) { [](VectorArray<FPT>& output, const VectorArray<FPT>& input, FP::FPCR fpcr, FP::FPSR& fpsr) {
constexpr auto t = mp::lower_to_tuple_v<decltype(arg)>; constexpr auto t = mp::lower_to_tuple_v<decltype(arg)>;
constexpr FP::RoundingMode rounding_mode = std::get<0>(t); constexpr FP::RoundingMode rounding_mode = std::get<0>(t);
@ -1475,14 +1472,11 @@ void EmitFPVectorToFixed(BlockOfCode& code, EmitContext& ctx, IR::Inst* inst) {
mp::lift_value<FP::RoundingMode::ToNearest_TieAwayFromZero> mp::lift_value<FP::RoundingMode::ToNearest_TieAwayFromZero>
>; >;
using key_type = std::tuple<size_t, FP::RoundingMode>; static const auto lut = Common::GenerateLookupTableFromList(
using value_type = void(*)(VectorArray<FPT>&, const VectorArray<FPT>&, FP::FPCR, FP::FPSR&);
static const auto lut = Common::GenerateLookupTableFromList<key_type, value_type>(
[](auto arg) { [](auto arg) {
return std::pair<key_type, value_type>{ return std::pair{
mp::lower_to_tuple_v<decltype(arg)>, mp::lower_to_tuple_v<decltype(arg)>,
static_cast<value_type>( static_cast<void(*)(VectorArray<FPT>&, const VectorArray<FPT>&, FP::FPCR, FP::FPSR&)>(
[](VectorArray<FPT>& output, const VectorArray<FPT>& input, FP::FPCR fpcr, FP::FPSR& fpsr) { [](VectorArray<FPT>& output, const VectorArray<FPT>& input, FP::FPCR fpcr, FP::FPSR& fpsr) {
constexpr auto t = mp::lower_to_tuple_v<decltype(arg)>; constexpr auto t = mp::lower_to_tuple_v<decltype(arg)>;
constexpr size_t fbits = std::get<0>(t); constexpr size_t fbits = std::get<0>(t);

View file

@ -6,17 +6,33 @@
#pragma once #pragma once
#include <array> #include <initializer_list>
#include <map> #include <map>
#include <type_traits>
#include <mp/metafunction/apply.h>
#include <mp/traits/is_instance_of_template.h>
#include <mp/typelist/list.h> #include <mp/typelist/list.h>
#ifdef _MSC_VER
#include <mp/typelist/head.h>
#endif
namespace Dynarmic::Common { namespace Dynarmic::Common {
template <typename KeyT, typename ValueT, typename Function, typename ...Values> template <typename Function, typename ...Values>
inline auto GenerateLookupTableFromList(Function f, mp::list<Values...>) { inline auto GenerateLookupTableFromList(Function f, mp::list<Values...>) {
static const std::array<std::pair<KeyT, ValueT>, sizeof...(Values)> pair_array{f(Values{})...}; #ifdef _MSC_VER
return std::map<KeyT, ValueT>(pair_array.begin(), pair_array.end()); using PairT = std::invoke_result_t<Function, mp::head<mp::list<Values...>>>;
#else
using PairT = std::common_type_t<std::invoke_result_t<Function, Values>...>;
#endif
using MapT = mp::apply<std::map, PairT>;
static_assert(mp::is_instance_of_template_v<std::pair, PairT>);
const std::initializer_list<PairT> pair_array{f(Values{})...};
return MapT(pair_array.begin(), pair_array.end());
} }
} // namespace Dynarmic::Common } // namespace Dynarmic::Common