lut_from_list: Reduce number of required template arguments
This commit is contained in:
parent
8658afd8c5
commit
fe583aa076
3 changed files with 32 additions and 28 deletions
|
@ -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 key_type = std::tuple<size_t, FP::RoundingMode, bool>;
|
||||
using value_type = u64(*)(u64, FP::FPSR&, FP::FPCR);
|
||||
|
||||
static const auto lut = Common::GenerateLookupTableFromList<key_type, value_type>(
|
||||
static const auto lut = Common::GenerateLookupTableFromList(
|
||||
[](auto args) {
|
||||
return std::pair<key_type, value_type>{
|
||||
return std::pair{
|
||||
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) {
|
||||
constexpr auto t = mp::lower_to_tuple_v<decltype(args)>;
|
||||
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>
|
||||
>;
|
||||
|
||||
using key_type = std::tuple<size_t, FP::RoundingMode>;
|
||||
using value_type = u64(*)(u64, FP::FPSR&, FP::FPCR);
|
||||
|
||||
static const auto lut = Common::GenerateLookupTableFromList<key_type, value_type>(
|
||||
static const auto lut = Common::GenerateLookupTableFromList(
|
||||
[](auto args) {
|
||||
return std::pair<key_type, value_type>{
|
||||
return std::pair{
|
||||
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) {
|
||||
constexpr auto t = mp::lower_to_tuple_v<decltype(args)>;
|
||||
constexpr size_t fbits = std::get<0>(t);
|
||||
|
|
|
@ -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 key_type = std::tuple<FP::RoundingMode, bool>;
|
||||
using value_type = void(*)(VectorArray<FPT>&, const VectorArray<FPT>&, FP::FPCR, FP::FPSR&);
|
||||
|
||||
static const auto lut = Common::GenerateLookupTableFromList<key_type, value_type>(
|
||||
static const auto lut = Common::GenerateLookupTableFromList(
|
||||
[](auto arg) {
|
||||
return std::pair<key_type, value_type>{
|
||||
return std::pair{
|
||||
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) {
|
||||
constexpr auto t = mp::lower_to_tuple_v<decltype(arg)>;
|
||||
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>
|
||||
>;
|
||||
|
||||
using key_type = std::tuple<size_t, FP::RoundingMode>;
|
||||
using value_type = void(*)(VectorArray<FPT>&, const VectorArray<FPT>&, FP::FPCR, FP::FPSR&);
|
||||
|
||||
static const auto lut = Common::GenerateLookupTableFromList<key_type, value_type>(
|
||||
static const auto lut = Common::GenerateLookupTableFromList(
|
||||
[](auto arg) {
|
||||
return std::pair<key_type, value_type>{
|
||||
return std::pair{
|
||||
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) {
|
||||
constexpr auto t = mp::lower_to_tuple_v<decltype(arg)>;
|
||||
constexpr size_t fbits = std::get<0>(t);
|
||||
|
|
|
@ -6,17 +6,33 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <initializer_list>
|
||||
#include <map>
|
||||
#include <type_traits>
|
||||
|
||||
#include <mp/metafunction/apply.h>
|
||||
#include <mp/traits/is_instance_of_template.h>
|
||||
#include <mp/typelist/list.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <mp/typelist/head.h>
|
||||
#endif
|
||||
|
||||
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...>) {
|
||||
static const std::array<std::pair<KeyT, ValueT>, sizeof...(Values)> pair_array{f(Values{})...};
|
||||
return std::map<KeyT, ValueT>(pair_array.begin(), pair_array.end());
|
||||
#ifdef _MSC_VER
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue