diff --git a/src/emu/netlist/nl_base.h b/src/emu/netlist/nl_base.h index fff31602e6a..e472031baa6 100644 --- a/src/emu/netlist/nl_base.h +++ b/src/emu/netlist/nl_base.h @@ -1233,6 +1233,7 @@ namespace netlist pnamedlist_t m_started_devices; #endif + ATTR_COLD plog_base &log() { return m_log; } ATTR_COLD const plog_base &log() const { return m_log; } protected: diff --git a/src/emu/netlist/nl_setup.h b/src/emu/netlist/nl_setup.h index adb3ccebb5d..5f056439b3b 100644 --- a/src/emu/netlist/nl_setup.h +++ b/src/emu/netlist/nl_setup.h @@ -198,6 +198,7 @@ namespace netlist void model_parse(const pstring &model, model_map_t &map); + plog_base &log() { return netlist().log(); } const plog_base &log() const { return netlist().log(); } protected: diff --git a/src/emu/netlist/plib/pstring.c b/src/emu/netlist/plib/pstring.c index 46346f637db..a493707c247 100644 --- a/src/emu/netlist/plib/pstring.c +++ b/src/emu/netlist/plib/pstring.c @@ -14,6 +14,7 @@ #include "pstring.h" #include "palloc.h" +#include "plists.h" template<> pstr_t pstring_t::m_zero = pstr_t(0); @@ -305,6 +306,106 @@ long pstring_t::as_long(bool *error) const // static stuff ... // ---------------------------------------------------------------------------------------- +/* + * Cached allocation of string memory + * + * This improves startup performance by 30%. + */ + +#if 1 + +static pstack_t *stk = NULL; + +static inline unsigned countleadbits(unsigned x) +{ +#ifndef count_leading_zeros + unsigned msk; + unsigned ret; + if (x < 0x100) + { + msk = 0x80; + ret = 24; + } + else if (x < 0x10000) + { + msk = 0x8000; + ret = 16; + } + else if (x < 0x1000000) + { + msk = 0x800000; + ret = 8; + } + else + { + msk = 0x80000000; + ret = 0; + } + while ((msk & x) == 0 && ret < 31) + { + msk = msk >> 1; + ret++; + } + return ret; +#else + return count_leading_zeros(x); +#endif +} + +template +void pstring_t::sfree(pstr_t *s) +{ + s->m_ref_count--; + if (s->m_ref_count == 0 && s != &m_zero) + { + if (stk != NULL) + { + unsigned sn= ((32 - countleadbits(s->len())) + 1) / 2; + stk[sn].push(s); + } + else + pfree_array(((char *)s)); + //_mm_free(((char *)s)); + } +} + +template +pstr_t *pstring_t::salloc(int n) +{ + if (stk == NULL) + stk = palloc_array(pstack_t, 17); + pstr_t *p; + unsigned sn= ((32 - countleadbits(n)) + 1) / 2; + unsigned size = sizeof(pstr_t) + (1<<(sn * 2)) + 1; + if (stk[sn].empty()) + p = (pstr_t *) palloc_array(char, size); + else + { + //printf("%u %u\n", sn, (unsigned) stk[sn].count()); + p = stk[sn].pop(); + } + + // str_t *p = (str_t *) _mm_malloc(size, 8); + p->init(n); + return p; +} +template +void pstring_t::resetmem() +{ + if (stk != NULL) + { + for (unsigned i=0; i<=16; i++) + { + for (; stk[i].count() > 0; ) + pfree_array(stk[i].pop()); + } + pfree_array(stk); + stk = NULL; + } +} + + +#else template void pstring_t::sfree(pstr_t *s) { @@ -331,6 +432,8 @@ void pstring_t::resetmem() { // Release the 0 string } +#endif + // ---------------------------------------------------------------------------------------- // pstring ... diff --git a/src/emu/netlist/plib/pstring.h b/src/emu/netlist/plib/pstring.h index 9cc67327838..973ca02ad0f 100644 --- a/src/emu/netlist/plib/pstring.h +++ b/src/emu/netlist/plib/pstring.h @@ -22,21 +22,21 @@ struct pstr_t { //str_t() : m_ref_count(1), m_len(0) { m_str[0] = 0; } - pstr_t(const int alen) + pstr_t(const unsigned alen) { init(alen); } - void init(const int alen) + void init(const unsigned alen) { m_ref_count = 1; m_len = alen; m_str[0] = 0; } char *str() { return &m_str[0]; } - int len() const { return m_len; } + unsigned len() const { return m_len; } int m_ref_count; private: - int m_len; + unsigned m_len; char m_str[1]; }; @@ -548,47 +548,57 @@ template class pfmt_writer_t { public: - pfmt_writer_t() { } + pfmt_writer_t() : m_enabled(true) { } virtual ~pfmt_writer_t() { } ATTR_COLD void operator ()(const char *fmt) const { - if (build_enabled) vdowrite(fmt); + if (build_enabled && m_enabled) vdowrite(fmt); } template ATTR_COLD void operator ()(const char *fmt, const T1 &v1) const { - if (build_enabled) vdowrite(pfmt(fmt)(v1)); + if (build_enabled && m_enabled) vdowrite(pfmt(fmt)(v1)); } template ATTR_COLD void operator ()(const char *fmt, const T1 &v1, const T2 &v2) const { - if (build_enabled) vdowrite(pfmt(fmt)(v1)(v2)); + if (build_enabled && m_enabled) vdowrite(pfmt(fmt)(v1)(v2)); } template ATTR_COLD void operator ()(const char *fmt, const T1 &v1, const T2 &v2, const T3 &v3) const { - if (build_enabled) vdowrite(pfmt(fmt)(v1)(v2)(v3)); + if (build_enabled && m_enabled) vdowrite(pfmt(fmt)(v1)(v2)(v3)); } template ATTR_COLD void operator ()(const char *fmt, const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4) const { - if (build_enabled) vdowrite(pfmt(fmt)(v1)(v2)(v3)(v4)); + if (build_enabled && m_enabled) vdowrite(pfmt(fmt)(v1)(v2)(v3)(v4)); } template ATTR_COLD void operator ()(const char *fmt, const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4, const T5 &v5) const { - if (build_enabled) vdowrite(pfmt(fmt)(v1)(v2)(v3)(v4)(v5)); + if (build_enabled && m_enabled) vdowrite(pfmt(fmt)(v1)(v2)(v3)(v4)(v5)); } + void set_enabled(const bool v) + { + m_enabled = v; + } + + bool is_enabled() const { return m_enabled; } + protected: virtual void vdowrite(const pstring &ls) const {} +private: + bool m_enabled; + }; template diff --git a/src/emu/netlist/solver/nld_solver.h b/src/emu/netlist/solver/nld_solver.h index 6da438b19cb..608b744372a 100644 --- a/src/emu/netlist/solver/nld_solver.h +++ b/src/emu/netlist/solver/nld_solver.h @@ -135,7 +135,7 @@ public: ATTR_COLD int get_net_idx(net_t *net); inline eSolverType type() const { return m_type; } - const plog_base &log() const { return netlist().log(); } + plog_base &log() { return netlist().log(); } virtual void log_stats();