diff --git a/scripts/src/netlist.lua b/scripts/src/netlist.lua index 2fa85e9196b..543fa187e59 100644 --- a/scripts/src/netlist.lua +++ b/scripts/src/netlist.lua @@ -59,6 +59,7 @@ project "netlist" MAME_DIR .. "src/lib/netlist/plib/poptions.h", MAME_DIR .. "src/lib/netlist/plib/pparser.cpp", MAME_DIR .. "src/lib/netlist/plib/pparser.h", + MAME_DIR .. "src/lib/netlist/plib/ppmf.h", MAME_DIR .. "src/lib/netlist/plib/pstate.cpp", MAME_DIR .. "src/lib/netlist/plib/pstate.h", MAME_DIR .. "src/lib/netlist/plib/pstring.cpp", diff --git a/src/lib/netlist/analog/nld_bjt.cpp b/src/lib/netlist/analog/nld_bjt.cpp index a207e07aae3..355e92807cd 100644 --- a/src/lib/netlist/analog/nld_bjt.cpp +++ b/src/lib/netlist/analog/nld_bjt.cpp @@ -9,6 +9,8 @@ #include "analog/nld_bjt.h" #include "nl_setup.h" +#include + namespace netlist { namespace analog diff --git a/src/lib/netlist/analog/nld_fourterm.cpp b/src/lib/netlist/analog/nld_fourterm.cpp index c97707bf382..1e9ae74da40 100644 --- a/src/lib/netlist/analog/nld_fourterm.cpp +++ b/src/lib/netlist/analog/nld_fourterm.cpp @@ -9,6 +9,8 @@ #include "nld_fourterm.h" #include "nl_setup.h" +#include + namespace netlist { namespace analog diff --git a/src/lib/netlist/analog/nld_opamps.cpp b/src/lib/netlist/analog/nld_opamps.cpp index 35908442781..6461e352b91 100644 --- a/src/lib/netlist/analog/nld_opamps.cpp +++ b/src/lib/netlist/analog/nld_opamps.cpp @@ -10,6 +10,8 @@ #include "nld_opamps.h" #include "nl_errstr.h" +#include + namespace netlist { namespace analog diff --git a/src/lib/netlist/analog/nld_twoterm.cpp b/src/lib/netlist/analog/nld_twoterm.cpp index f676fe928ac..6dc69c499d7 100644 --- a/src/lib/netlist/analog/nld_twoterm.cpp +++ b/src/lib/netlist/analog/nld_twoterm.cpp @@ -5,12 +5,12 @@ * */ -#include - #include "solver/nld_solver.h" #include "nld_twoterm.h" +#include + namespace netlist { namespace analog diff --git a/src/lib/netlist/devices/nld_74123.cpp b/src/lib/netlist/devices/nld_74123.cpp index bcbfdcb106a..19b397f3b9f 100644 --- a/src/lib/netlist/devices/nld_74123.cpp +++ b/src/lib/netlist/devices/nld_74123.cpp @@ -10,6 +10,8 @@ #include "nlid_system.h" #include "analog/nld_twoterm.h" +#include + namespace netlist { namespace devices diff --git a/src/lib/netlist/devices/nld_log.cpp b/src/lib/netlist/devices/nld_log.cpp index 2065b36ddaf..d69bc6aa81e 100644 --- a/src/lib/netlist/devices/nld_log.cpp +++ b/src/lib/netlist/devices/nld_log.cpp @@ -5,7 +5,6 @@ * */ -#include #include "nl_base.h" #include "plib/pstream.h" #include "plib/pfmtlog.h" diff --git a/src/lib/netlist/devices/nld_truthtable.cpp b/src/lib/netlist/devices/nld_truthtable.cpp index e7cedfba13f..f59c379290b 100644 --- a/src/lib/netlist/devices/nld_truthtable.cpp +++ b/src/lib/netlist/devices/nld_truthtable.cpp @@ -121,7 +121,7 @@ uint_least64_t truthtable_desc_t::get_ignored_extended(uint_least64_t state) // desc // ---------------------------------------------------------------------------------------- -void truthtable_desc_t::help(unsigned cur, plib::pstring_vector_t list, +void truthtable_desc_t::help(unsigned cur, std::vector list, uint_least64_t state, uint_least64_t val, std::vector &timing_index) { pstring elem = list[cur].trim(); @@ -166,7 +166,7 @@ void truthtable_desc_t::help(unsigned cur, plib::pstring_vector_t list, } } -void truthtable_desc_t::setup(const plib::pstring_vector_t &truthtable, uint_least64_t disabled_ignore) +void truthtable_desc_t::setup(const std::vector &truthtable, uint_least64_t disabled_ignore) { unsigned line = 0; diff --git a/src/lib/netlist/devices/nld_truthtable.h b/src/lib/netlist/devices/nld_truthtable.h index 827cb26c9d7..9e004c0f098 100644 --- a/src/lib/netlist/devices/nld_truthtable.h +++ b/src/lib/netlist/devices/nld_truthtable.h @@ -10,12 +10,10 @@ #ifndef NLD_TRUTHTABLE_H_ #define NLD_TRUTHTABLE_H_ -#include -#include - #include "nl_setup.h" #include "nl_factory.h" #include "plib/plists.h" +#include "plib/putil.h" #define NETLIB_TRUTHTABLE(cname, nIN, nOUT) \ class NETLIB_NAME(cname) : public nld_truthtable_t \ @@ -112,10 +110,10 @@ namespace netlist { } - void setup(const plib::pstring_vector_t &desc, uint_least64_t disabled_ignore); + void setup(const std::vector &desc, uint_least64_t disabled_ignore); private: - void help(unsigned cur, plib::pstring_vector_t list, + void help(unsigned cur, std::vector list, uint_least64_t state, uint_least64_t val, std::vector &timing_index); static unsigned count_bits(uint_least64_t v); static uint_least64_t set_bits(uint_least64_t v, uint_least64_t b); @@ -176,7 +174,7 @@ namespace netlist template nld_truthtable_t(C &owner, const pstring &name, const logic_family_desc_t *fam, - truthtable_t *ttp, const plib::pstring_vector_t &desc) + truthtable_t *ttp, const std::vector &desc) : device_t(owner, name) , m_fam(*this, fam) , m_ign(*this, "m_ign", 0) @@ -363,7 +361,7 @@ namespace netlist state_var_u32 m_ign; state_var_s32 m_active; truthtable_t * m_ttp; - plib::pstring_vector_t m_desc; + std::vector m_desc; }; class netlist_base_factory_truthtable_t : public factory::element_t @@ -375,7 +373,7 @@ namespace netlist virtual ~netlist_base_factory_truthtable_t(); - plib::pstring_vector_t m_desc; + std::vector m_desc; const logic_family_desc_t *m_family; }; diff --git a/src/lib/netlist/devices/nlid_proxy.cpp b/src/lib/netlist/devices/nlid_proxy.cpp index 59f6f39420b..1586ad31830 100644 --- a/src/lib/netlist/devices/nlid_proxy.cpp +++ b/src/lib/netlist/devices/nlid_proxy.cpp @@ -5,7 +5,6 @@ * */ -//#include #include "nlid_proxy.h" #include "solver/nld_solver.h" //#include "plib/pstream.h" diff --git a/src/lib/netlist/devices/nlid_proxy.h b/src/lib/netlist/devices/nlid_proxy.h index f52e8f61907..9ba4fd69e3f 100644 --- a/src/lib/netlist/devices/nlid_proxy.h +++ b/src/lib/netlist/devices/nlid_proxy.h @@ -11,8 +11,6 @@ #ifndef NLID_PROXY_H_ #define NLID_PROXY_H_ -#include - #include "nl_setup.h" #include "nl_base.h" #include "nl_factory.h" diff --git a/src/lib/netlist/devices/nlid_system.h b/src/lib/netlist/devices/nlid_system.h index 5c29d40fd94..c1396235ef4 100644 --- a/src/lib/netlist/devices/nlid_system.h +++ b/src/lib/netlist/devices/nlid_system.h @@ -11,13 +11,10 @@ #ifndef NLID_SYSTEM_H_ #define NLID_SYSTEM_H_ -#include -#include -#include - #include "analog/nld_twoterm.h" #include "nl_base.h" #include "nl_time.h" +#include "nl_setup.h" #include "plib/palloc.h" #include "plib/pfmtlog.h" #include "plib/pfunction.h" diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index b1b4dac9341..307afd57788 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -9,20 +9,16 @@ #ifndef NLBASE_H_ #define NLBASE_H_ -#include -#include -#include -//#include -#include - #include "nl_lists.h" #include "nl_time.h" -#include "plib/palloc.h" +#include "plib/palloc.h" // owned_ptr #include "plib/pdynlib.h" #include "plib/pstate.h" #include "plib/pfmtlog.h" #include "plib/pstream.h" -#include "plib/pexception.h" +#include "plib/ppmf.h" + +#include // ---------------------------------------------------------------------------------------- // Type definitions diff --git a/src/lib/netlist/nl_dice_compat.h b/src/lib/netlist/nl_dice_compat.h index 209f18d82af..b0ebdb2e371 100644 --- a/src/lib/netlist/nl_dice_compat.h +++ b/src/lib/netlist/nl_dice_compat.h @@ -27,8 +27,11 @@ sed -e 's/#define \(.*\)"\(.*\)"[ \t]*,[ \t]*\(.*\)/NET_ALIAS(\1,\2.\3)/' src/ma #ifndef NL_CONVERT_CPP #include "devices/net_lib.h" #include "analog/nld_twoterm.h" + +#include #endif + /* -------------------------------------------------------------------- * Compatibility macros for DICE netlists ... * -------------------------------------------------------------------- */ diff --git a/src/lib/netlist/nl_factory.h b/src/lib/netlist/nl_factory.h index f5a38d416da..d154cdcf9ea 100644 --- a/src/lib/netlist/nl_factory.h +++ b/src/lib/netlist/nl_factory.h @@ -9,12 +9,6 @@ #ifndef NLFACTORY_H_ #define NLFACTORY_H_ -#include - -#include "nl_config.h" -#include "plib/palloc.h" -#include "plib/plists.h" -#include "plib/putil.h" #include "nl_base.h" #define NETLIB_DEVICE_IMPL(chip) \ diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index 2fbc4d5f6f5..842b8467a46 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -5,8 +5,6 @@ * */ -#include - #include "plib/palloc.h" #include "plib/putil.h" #include "nl_base.h" diff --git a/src/lib/netlist/nl_setup.h b/src/lib/netlist/nl_setup.h index 79a21a6815b..d9379ac6a57 100644 --- a/src/lib/netlist/nl_setup.h +++ b/src/lib/netlist/nl_setup.h @@ -8,19 +8,11 @@ #ifndef NLSETUP_H_ #define NLSETUP_H_ -#include -#include -#include -#include - -#include "plib/pstring.h" -#include "plib/pfmtlog.h" -#include "plib/pstream.h" -#include "plib/putil.h" -#include "plib/pparser.h" -#include "nl_config.h" #include "nl_base.h" #include "nl_factory.h" +#include "plib/pparser.h" + +#include //============================================================ // MACROS / inline netlist definitions @@ -125,7 +117,7 @@ namespace netlist unsigned long ni; unsigned long no; pstring def_param; - plib::pstring_vector_t desc; + std::vector desc; pstring family; }; diff --git a/src/lib/netlist/plib/palloc.cpp b/src/lib/netlist/plib/palloc.cpp index 2f1131601da..ceee5a75904 100644 --- a/src/lib/netlist/plib/palloc.cpp +++ b/src/lib/netlist/plib/palloc.cpp @@ -5,8 +5,6 @@ * */ -#include - #include "pconfig.h" #include "palloc.h" #include "pfmtlog.h" diff --git a/src/lib/netlist/plib/palloc.h b/src/lib/netlist/plib/palloc.h index 2d223180b3d..d71ebc7dbc5 100644 --- a/src/lib/netlist/plib/palloc.h +++ b/src/lib/netlist/plib/palloc.h @@ -10,9 +10,6 @@ #include #include -#include - -#include "pconfig.h" #include "pstring.h" namespace plib { diff --git a/src/lib/netlist/plib/pchrono.h b/src/lib/netlist/plib/pchrono.h index e37cd995ab5..5d64f9c4add 100644 --- a/src/lib/netlist/plib/pchrono.h +++ b/src/lib/netlist/plib/pchrono.h @@ -9,7 +9,6 @@ #define PCHRONO_H_ #include -#include #include #include "pconfig.h" diff --git a/src/lib/netlist/plib/pconfig.h b/src/lib/netlist/plib/pconfig.h index 756130dd190..82b1be6a16d 100644 --- a/src/lib/netlist/plib/pconfig.h +++ b/src/lib/netlist/plib/pconfig.h @@ -8,9 +8,8 @@ #ifndef PCONFIG_H_ #define PCONFIG_H_ +#include #include -#include -#include /* * Define this for more accurate measurements if you processor supports @@ -63,37 +62,9 @@ typedef __int128_t INT128; name &operator=(const name &); //============================================================ -// cut down delegate implementation +// Pointer to Member Function //============================================================ -/* - * - * NL_PMF_TYPE_GNUC_PMF - * Use standard pointer to member function syntax C++11 - * - * NL_PMF_TYPE_GNUC_PMF_CONV - * Use gnu extension and convert the pmf to a function pointer. - * This is not standard compliant and needs - * -Wno-pmf-conversions to compile. - * - * NL_PMF_TYPE_INTERNAL - * Use the same approach as MAME for deriving the function pointer. - * This is compiler-dependent as well - * - * Benchmarks for ./nltool -c run -f src/mame/machine/nl_pong.cpp -t 10 -n pong_fast - * - * NL_PMF_TYPE_INTERNAL: 215% 215% - * NL_PMF_TYPE_GNUC_PMF: 163% 196% - * NL_PMF_TYPE_GNUC_PMF_CONV: 215% 215% - * NL_PMF_TYPE_VIRTUAL: 213% 209% - * - * The whole exercise was done to avoid virtual calls. In prior versions of - * netlist, the INTERNAL and GNUC_PMF_CONV approach provided significant improvement. - * Since than, "hot" was removed from functions declared as virtual. - * This may explain that the recent benchmarks show no difference at all. - * - */ - // This will be autodetected // #define PPMF_TYPE 1 @@ -101,7 +72,6 @@ typedef __int128_t INT128; #define PPMF_TYPE_GNUC_PMF_CONV 1 #define PPMF_TYPE_INTERNAL 2 - #if defined(__GNUC__) /* does not work in versions over 4.7.x of 32bit MINGW */ #if defined(__MINGW32__) && !defined(__x86_64) && defined(__i386__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7))) @@ -134,145 +104,4 @@ typedef __int128_t INT128; #endif #endif -#if (PPMF_TYPE == PPMF_TYPE_GNUC_PMF_CONV) -#pragma GCC diagnostic ignored "-Wpmf-conversions" -#endif - -namespace plib { -/* - * The following class was derived from the MAME delegate.h code. - * It derives a pointer to a member function. - */ - -#if (PHAS_PMF_INTERNAL) - class mfp - { - public: - // construct from any member function pointer - class generic_class; - using generic_function = void (*)(); - - template - mfp(MemberFunctionType mftp) - : m_function(0), m_this_delta(0) - { - *reinterpret_cast(this) = mftp; - } - - template - static FunctionType get_mfp(MemberFunctionType mftp, ObjectType *object) - { - mfp mfpo(mftp); - //return mfpo.update_after_bind(object); - return reinterpret_cast( - mfpo.convert_to_generic(reinterpret_cast(object))); - } - - private: - // extract the generic function and adjust the object pointer - generic_function convert_to_generic(generic_class * object) const - { - // apply the "this" delta to the object first - generic_class * o_p_delta = reinterpret_cast(reinterpret_cast(object) + m_this_delta); - - // if the low bit of the vtable index is clear, then it is just a raw function pointer - if (!(m_function & 1)) - return reinterpret_cast(m_function); - - // otherwise, it is the byte index into the vtable where the actual function lives - std::uint8_t *vtable_base = *reinterpret_cast(o_p_delta); - return *reinterpret_cast(vtable_base + m_function - 1); - } - - // actual state - uintptr_t m_function; // first item can be one of two things: - // if even, it's a pointer to the function - // if odd, it's the byte offset into the vtable - int m_this_delta; // delta to apply to the 'this' pointer - }; -#endif - -#if (PPMF_TYPE == PPMF_TYPE_PMF) - template - class pmfp_base - { - public: - class generic_class; - using generic_function = R (generic_class::*)(Targs...); - pmfp_base() : m_func(nullptr) {} - - template - void set_base(MemberFunctionType mftp, O *object) - { - using function_ptr = R (O::*)(Targs...); - function_ptr t = mftp; - m_func = reinterpret_cast(t); - } - template - inline R call(O *obj, Targs... args) const - { - using function_ptr = R (O::*)(Targs...); - function_ptr t = reinterpret_cast(m_func); - return (obj->*t)(std::forward(args)...); - } - private: - generic_function m_func; - }; - -#elif ((PPMF_TYPE == PPMF_TYPE_GNUC_PMF_CONV) || (PPMF_TYPE == PPMF_TYPE_INTERNAL)) - template - class pmfp_base - { - public: - using generic_function = void (*)(); - - pmfp_base() : m_func(nullptr) {} - - template - void set_base(MemberFunctionType mftp, O *object) - { - #if (PPMF_TYPE == PPMF_TYPE_INTERNAL) - using function_ptr = MEMBER_ABI R (*)(O *obj, Targs... args); - m_func = reinterpret_cast(plib::mfp::get_mfp(mftp, object)); - #elif (PPMF_TYPE == PPMF_TYPE_GNUC_PMF_CONV) - R (O::* pFunc)(Targs...) = mftp; - m_func = reinterpret_cast((object->*pFunc)); - #endif - } - template - inline R call(O *obj, Targs... args) const - { - using function_ptr = MEMBER_ABI R (*)(O *obj, Targs... args); - return (reinterpret_cast(m_func))(obj, std::forward(args)...); - } - private: - generic_function m_func; - }; -#endif - - template - class pmfp : public pmfp_base - { - public: - class generic_class; - pmfp() : pmfp_base(), m_obj(nullptr) {} - - template - void set(MemberFunctionType mftp, O *object) - { - this->set_base(mftp, object); - m_obj = reinterpret_cast(object); - } - - inline R operator()(Targs... args) const - { - return this->call(m_obj, std::forward(args)...); - } - private: - generic_class *m_obj; - }; - - -} - #endif /* PCONFIG_H_ */ diff --git a/src/lib/netlist/plib/pdynlib.h b/src/lib/netlist/plib/pdynlib.h index e91b86e3a82..3a0c12a5f2d 100644 --- a/src/lib/netlist/plib/pdynlib.h +++ b/src/lib/netlist/plib/pdynlib.h @@ -7,10 +7,6 @@ #ifndef PDYNLIB_H_ #define PDYNLIB_H_ -#include -#include - -#include "pconfig.h" #include "pstring.h" namespace plib { diff --git a/src/lib/netlist/plib/pexception.h b/src/lib/netlist/plib/pexception.h index a4d3b3c498f..9ef3077a75d 100644 --- a/src/lib/netlist/plib/pexception.h +++ b/src/lib/netlist/plib/pexception.h @@ -10,7 +10,6 @@ #include -#include "pconfig.h" #include "pstring.h" namespace plib { diff --git a/src/lib/netlist/plib/pfmtlog.cpp b/src/lib/netlist/plib/pfmtlog.cpp index 4cd74837dbb..9451e11866d 100644 --- a/src/lib/netlist/plib/pfmtlog.cpp +++ b/src/lib/netlist/plib/pfmtlog.cpp @@ -6,11 +6,8 @@ */ #include -//FIXME:: pstring should be locale free -#include #include -#include - +#include #include #include "pfmtlog.h" diff --git a/src/lib/netlist/plib/pfmtlog.h b/src/lib/netlist/plib/pfmtlog.h index fbae59673d7..311cd547a3c 100644 --- a/src/lib/netlist/plib/pfmtlog.h +++ b/src/lib/netlist/plib/pfmtlog.h @@ -9,7 +9,6 @@ #include -#include "pconfig.h" #include "pstring.h" #include "ptypes.h" diff --git a/src/lib/netlist/plib/pfunction.h b/src/lib/netlist/plib/pfunction.h index 0f4960d4e1c..da61fe84e17 100644 --- a/src/lib/netlist/plib/pfunction.h +++ b/src/lib/netlist/plib/pfunction.h @@ -10,7 +10,6 @@ #include -#include "pconfig.h" #include "pstring.h" namespace plib { diff --git a/src/lib/netlist/plib/plists.h b/src/lib/netlist/plib/plists.h index fd9aaa5e176..c6ba2821790 100644 --- a/src/lib/netlist/plib/plists.h +++ b/src/lib/netlist/plib/plists.h @@ -10,10 +10,7 @@ #ifndef PLISTS_H_ #define PLISTS_H_ -#include #include -#include -#include #include "pstring.h" diff --git a/src/lib/netlist/plib/poptions.cpp b/src/lib/netlist/plib/poptions.cpp index c35b26836fb..5c67626fff6 100644 --- a/src/lib/netlist/plib/poptions.cpp +++ b/src/lib/netlist/plib/poptions.cpp @@ -56,7 +56,7 @@ namespace plib { return 1; } - int option_bool::parse(ATTR_UNUSED pstring argument) + int option_bool::parse(pstring argument) { m_val = true; return 0; diff --git a/src/lib/netlist/plib/poptions.h b/src/lib/netlist/plib/poptions.h index aa5ce07cbc8..b5f18c98a92 100644 --- a/src/lib/netlist/plib/poptions.h +++ b/src/lib/netlist/plib/poptions.h @@ -10,8 +10,6 @@ #ifndef POPTIONS_H_ #define POPTIONS_H_ -#include - #include "pstring.h" #include "plists.h" #include "putil.h" @@ -67,7 +65,7 @@ public: /* no_argument options will be called with "" argument */ - virtual int parse(ATTR_UNUSED pstring argument) = 0; + virtual int parse(pstring argument) = 0; pstring short_opt() { return m_short; } pstring long_opt() { return m_long; } @@ -116,7 +114,7 @@ public: : option(parent, ashort, along, help, false), m_val(false) {} - virtual int parse(ATTR_UNUSED pstring argument) override; + virtual int parse(pstring argument) override; bool operator ()() { return m_val; } private: diff --git a/src/lib/netlist/plib/pparser.cpp b/src/lib/netlist/plib/pparser.cpp index 9d25adffcbe..583e9e9e20c 100644 --- a/src/lib/netlist/plib/pparser.cpp +++ b/src/lib/netlist/plib/pparser.cpp @@ -8,7 +8,8 @@ #include #include "pparser.h" -#include "plib/palloc.h" +#include "palloc.h" +#include "putil.h" namespace plib { // ---------------------------------------------------------------------------------------- @@ -302,7 +303,7 @@ void ppreprocessor::error(const pstring &err) -double ppreprocessor::expr(const pstring_vector_t &sexpr, std::size_t &start, int prio) +double ppreprocessor::expr(const std::vector &sexpr, std::size_t &start, int prio) { double val; pstring tok=sexpr[start]; diff --git a/src/lib/netlist/plib/pparser.h b/src/lib/netlist/plib/pparser.h index 5bda079cc63..736f943376d 100644 --- a/src/lib/netlist/plib/pparser.h +++ b/src/lib/netlist/plib/pparser.h @@ -11,10 +11,9 @@ #include #include -#include "pconfig.h" #include "pstring.h" #include "plists.h" -#include "putil.h" +//#include "putil.h" #include "pstream.h" namespace plib { @@ -168,7 +167,7 @@ public: void process(putf8_reader &istrm, putf8_writer &ostrm); protected: - double expr(const plib::pstring_vector_t &sexpr, std::size_t &start, int prio); + double expr(const std::vector &sexpr, std::size_t &start, int prio); define_t *get_define(const pstring &name); pstring replace_macros(const pstring &line); virtual void error(const pstring &err); @@ -178,7 +177,7 @@ private: pstring process_line(const pstring &line); std::unordered_map m_defines; - plib::pstring_vector_t m_expr_sep; + std::vector m_expr_sep; std::uint_least64_t m_ifflag; // 31 if levels int m_level; diff --git a/src/lib/netlist/plib/ppmf.h b/src/lib/netlist/plib/ppmf.h new file mode 100644 index 00000000000..8cff664d08b --- /dev/null +++ b/src/lib/netlist/plib/ppmf.h @@ -0,0 +1,185 @@ +// license:GPL-2.0+ +// copyright-holders:Couriersud +/* + * ppmf.h + * + */ + +#ifndef PPMF_H_ +#define PPMF_H_ + +#include "pconfig.h" +#include +#include + + +/* + * + * NL_PMF_TYPE_GNUC_PMF + * Use standard pointer to member function syntax C++11 + * + * NL_PMF_TYPE_GNUC_PMF_CONV + * Use gnu extension and convert the pmf to a function pointer. + * This is not standard compliant and needs + * -Wno-pmf-conversions to compile. + * + * NL_PMF_TYPE_INTERNAL + * Use the same approach as MAME for deriving the function pointer. + * This is compiler-dependent as well + * + * Benchmarks for ./nltool -c run -f src/mame/machine/nl_pong.cpp -t 10 -n pong_fast + * + * NL_PMF_TYPE_INTERNAL: 215% 215% + * NL_PMF_TYPE_GNUC_PMF: 163% 196% + * NL_PMF_TYPE_GNUC_PMF_CONV: 215% 215% + * NL_PMF_TYPE_VIRTUAL: 213% 209% + * + * The whole exercise was done to avoid virtual calls. In prior versions of + * netlist, the INTERNAL and GNUC_PMF_CONV approach provided significant improvement. + * Since than, "hot" was removed from functions declared as virtual. + * This may explain that the recent benchmarks show no difference at all. + * + */ + +#if (PPMF_TYPE == PPMF_TYPE_GNUC_PMF_CONV) +#pragma GCC diagnostic ignored "-Wpmf-conversions" +#endif + +namespace plib { +/* + * The following class was derived from the MAME delegate.h code. + * It derives a pointer to a member function. + */ + +#if (PHAS_PMF_INTERNAL) + class mfp + { + public: + // construct from any member function pointer + class generic_class; + using generic_function = void (*)(); + + template + mfp(MemberFunctionType mftp) + : m_function(0), m_this_delta(0) + { + *reinterpret_cast(this) = mftp; + } + + template + static FunctionType get_mfp(MemberFunctionType mftp, ObjectType *object) + { + mfp mfpo(mftp); + //return mfpo.update_after_bind(object); + return reinterpret_cast( + mfpo.convert_to_generic(reinterpret_cast(object))); + } + + private: + // extract the generic function and adjust the object pointer + generic_function convert_to_generic(generic_class * object) const + { + // apply the "this" delta to the object first + generic_class * o_p_delta = reinterpret_cast(reinterpret_cast(object) + m_this_delta); + + // if the low bit of the vtable index is clear, then it is just a raw function pointer + if (!(m_function & 1)) + return reinterpret_cast(m_function); + + // otherwise, it is the byte index into the vtable where the actual function lives + std::uint8_t *vtable_base = *reinterpret_cast(o_p_delta); + return *reinterpret_cast(vtable_base + m_function - 1); + } + + // actual state + uintptr_t m_function; // first item can be one of two things: + // if even, it's a pointer to the function + // if odd, it's the byte offset into the vtable + int m_this_delta; // delta to apply to the 'this' pointer + }; +#endif + +#if (PPMF_TYPE == PPMF_TYPE_PMF) + template + class pmfp_base + { + public: + class generic_class; + using generic_function = R (generic_class::*)(Targs...); + pmfp_base() : m_func(nullptr) {} + + template + void set_base(MemberFunctionType mftp, O *object) + { + using function_ptr = R (O::*)(Targs...); + function_ptr t = mftp; + m_func = reinterpret_cast(t); + } + template + inline R call(O *obj, Targs... args) const + { + using function_ptr = R (O::*)(Targs...); + function_ptr t = reinterpret_cast(m_func); + return (obj->*t)(std::forward(args)...); + } + private: + generic_function m_func; + }; + +#elif ((PPMF_TYPE == PPMF_TYPE_GNUC_PMF_CONV) || (PPMF_TYPE == PPMF_TYPE_INTERNAL)) + template + class pmfp_base + { + public: + using generic_function = void (*)(); + + pmfp_base() : m_func(nullptr) {} + + template + void set_base(MemberFunctionType mftp, O *object) + { + #if (PPMF_TYPE == PPMF_TYPE_INTERNAL) + using function_ptr = MEMBER_ABI R (*)(O *obj, Targs... args); + m_func = reinterpret_cast(plib::mfp::get_mfp(mftp, object)); + #elif (PPMF_TYPE == PPMF_TYPE_GNUC_PMF_CONV) + R (O::* pFunc)(Targs...) = mftp; + m_func = reinterpret_cast((object->*pFunc)); + #endif + } + template + inline R call(O *obj, Targs... args) const + { + using function_ptr = MEMBER_ABI R (*)(O *obj, Targs... args); + return (reinterpret_cast(m_func))(obj, std::forward(args)...); + } + private: + generic_function m_func; + }; +#endif + + template + class pmfp : public pmfp_base + { + public: + class generic_class; + pmfp() : pmfp_base(), m_obj(nullptr) {} + + template + void set(MemberFunctionType mftp, O *object) + { + this->set_base(mftp, object); + m_obj = reinterpret_cast(object); + } + + inline R operator()(Targs... args) const + { + return this->call(m_obj, std::forward(args)...); + } + private: + generic_class *m_obj; + }; + + +} + +#endif /* PPMF_H_ */ diff --git a/src/lib/netlist/plib/pstate.h b/src/lib/netlist/plib/pstate.h index 7c25bf4d722..4256fa45152 100644 --- a/src/lib/netlist/plib/pstate.h +++ b/src/lib/netlist/plib/pstate.h @@ -8,13 +8,12 @@ #ifndef PSTATE_H_ #define PSTATE_H_ -#include -#include - -#include "plists.h" #include "pstring.h" #include "ptypes.h" +#include +#include + // ---------------------------------------------------------------------------------------- // state saving ... // ---------------------------------------------------------------------------------------- diff --git a/src/lib/netlist/plib/pstream.h b/src/lib/netlist/plib/pstream.h index b7584a49663..ffd9bfdeffc 100644 --- a/src/lib/netlist/plib/pstream.h +++ b/src/lib/netlist/plib/pstream.h @@ -7,9 +7,6 @@ #ifndef PSTREAM_H_ #define PSTREAM_H_ -#include -#include - #include "pconfig.h" #include "pstring.h" #include "pfmtlog.h" diff --git a/src/lib/netlist/plib/pstring.h b/src/lib/netlist/plib/pstring.h index e3dd475175e..80a8fc4e78e 100644 --- a/src/lib/netlist/plib/pstring.h +++ b/src/lib/netlist/plib/pstring.h @@ -7,13 +7,9 @@ #ifndef PSTRING_H_ #define PSTRING_H_ -#include -#include #include #include -#include "pconfig.h" - // ---------------------------------------------------------------------------------------- // pstring: immutable strings ... // diff --git a/src/lib/netlist/plib/ptypes.h b/src/lib/netlist/plib/ptypes.h index 9c477f71944..6aabed738e9 100644 --- a/src/lib/netlist/plib/ptypes.h +++ b/src/lib/netlist/plib/ptypes.h @@ -9,6 +9,7 @@ #define PTYPES_H_ #include +#include #include "pconfig.h" #include "pstring.h" diff --git a/src/lib/netlist/plib/putil.h b/src/lib/netlist/plib/putil.h index e340acbd8ec..97f3de1a626 100644 --- a/src/lib/netlist/plib/putil.h +++ b/src/lib/netlist/plib/putil.h @@ -8,10 +8,10 @@ #ifndef P_UTIL_H_ #define P_UTIL_H_ -#include - #include "plib/pstring.h" -#include "plib/plists.h" + +#include +#include namespace plib { diff --git a/src/lib/netlist/prg/nltool.cpp b/src/lib/netlist/prg/nltool.cpp index f63369839ef..84aa94a05a9 100644 --- a/src/lib/netlist/prg/nltool.cpp +++ b/src/lib/netlist/prg/nltool.cpp @@ -8,22 +8,12 @@ ****************************************************************************/ -#include -#include - #include "plib/poptions.h" -#include "plib/pstring.h" -#include "plib/plists.h" -#include "plib/ptypes.h" -#include "plib/pexception.h" #include "nl_setup.h" -#include "nl_factory.h" #include "nl_parser.h" #include "devices/net_lib.h" #include "tools/nl_convert.h" -#include - class tool_options_t : public plib::options { public: diff --git a/src/lib/netlist/prg/nlwav.cpp b/src/lib/netlist/prg/nlwav.cpp index 8612469431e..4f19e9b5960 100644 --- a/src/lib/netlist/prg/nlwav.cpp +++ b/src/lib/netlist/prg/nlwav.cpp @@ -1,6 +1,5 @@ // license:GPL-2.0+ // copyright-holders:Couriersud -#include #include #include "plib/pstring.h" #include "plib/plists.h" diff --git a/src/lib/netlist/solver/nld_matrix_solver.h b/src/lib/netlist/solver/nld_matrix_solver.h index e5f7bcf38b1..9c5d30f2795 100644 --- a/src/lib/netlist/solver/nld_matrix_solver.h +++ b/src/lib/netlist/solver/nld_matrix_solver.h @@ -10,6 +10,7 @@ #include "nl_base.h" #include "nl_errstr.h" +#include "plib/putil.h" namespace netlist { diff --git a/src/lib/netlist/solver/nld_ms_direct_lu.h b/src/lib/netlist/solver/nld_ms_direct_lu.h index c5ebb5f197a..c379cf8d055 100644 --- a/src/lib/netlist/solver/nld_ms_direct_lu.h +++ b/src/lib/netlist/solver/nld_ms_direct_lu.h @@ -4,7 +4,7 @@ * nld_ms_direct.h * */ - +#if 0 #ifndef NLD_MS_DIRECT_H_ #define NLD_MS_DIRECT_H_ @@ -634,3 +634,4 @@ matrix_solver_direct_t::matrix_solver_direct_t(const eSolverType } // namespace netlist #endif /* NLD_MS_DIRECT_H_ */ +#endif diff --git a/src/lib/netlist/solver/nld_solver.cpp b/src/lib/netlist/solver/nld_solver.cpp index cfdf411c553..4d461658c43 100644 --- a/src/lib/netlist/solver/nld_solver.cpp +++ b/src/lib/netlist/solver/nld_solver.cpp @@ -38,7 +38,6 @@ #include "omp.h" #endif -#include "plib/putil.h" #include "nld_solver.h" #include "nld_matrix_solver.h" diff --git a/src/lib/netlist/tools/nl_convert.cpp b/src/lib/netlist/tools/nl_convert.cpp index 59450335926..8a1d0b9a699 100644 --- a/src/lib/netlist/tools/nl_convert.cpp +++ b/src/lib/netlist/tools/nl_convert.cpp @@ -6,7 +6,6 @@ */ #include -#include #include #include #include "nl_convert.h" diff --git a/src/lib/netlist/tools/nl_convert.h b/src/lib/netlist/tools/nl_convert.h index 66aefaea038..d0d12c377e0 100644 --- a/src/lib/netlist/tools/nl_convert.h +++ b/src/lib/netlist/tools/nl_convert.h @@ -59,14 +59,14 @@ private: : m_name(aname), m_no_export(false) {} const pstring &name() { return m_name;} - plib::pstring_vector_t &terminals() { return m_terminals; } + std::vector &terminals() { return m_terminals; } void set_no_export() { m_no_export = true; } bool is_no_export() { return m_no_export; } private: pstring m_name; bool m_no_export; - plib::pstring_vector_t m_terminals; + std::vector m_terminals; }; struct dev_t