Skip to content

Commit

Permalink
Some pedantic netlist changes. (nw)
Browse files Browse the repository at this point in the history
  • Loading branch information
couriersud committed Aug 27, 2015
1 parent 12d07f9 commit bce5387
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/emu/netlist/nl_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,7 @@ namespace netlist
pnamedlist_t<core_device_t *> m_started_devices;
#endif

ATTR_COLD plog_base<NL_DEBUG> &log() { return m_log; }
ATTR_COLD const plog_base<NL_DEBUG> &log() const { return m_log; }

protected:
Expand Down
1 change: 1 addition & 0 deletions src/emu/netlist/nl_setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ namespace netlist

void model_parse(const pstring &model, model_map_t &map);

plog_base<NL_DEBUG> &log() { return netlist().log(); }
const plog_base<NL_DEBUG> &log() const { return netlist().log(); }

protected:
Expand Down
103 changes: 103 additions & 0 deletions src/emu/netlist/plib/pstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "pstring.h"
#include "palloc.h"
#include "plists.h"

template<>
pstr_t pstring_t<putf8_traits>::m_zero = pstr_t(0);
Expand Down Expand Up @@ -305,6 +306,106 @@ long pstring_t<F>::as_long(bool *error) const
// static stuff ...
// ----------------------------------------------------------------------------------------

/*
* Cached allocation of string memory
*
* This improves startup performance by 30%.
*/

#if 1

static pstack_t<pstr_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<typename F>
void pstring_t<F>::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<typename F>
pstr_t *pstring_t<F>::salloc(int n)
{
if (stk == NULL)
stk = palloc_array(pstack_t<pstr_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<typename F>
void pstring_t<F>::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<typename F>
void pstring_t<F>::sfree(pstr_t *s)
{
Expand All @@ -331,6 +432,8 @@ void pstring_t<F>::resetmem()
{
// Release the 0 string
}
#endif


// ----------------------------------------------------------------------------------------
// pstring ...
Expand Down
32 changes: 21 additions & 11 deletions src/emu/netlist/plib/pstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
};

Expand Down Expand Up @@ -548,47 +548,57 @@ template <bool build_enabled = true>
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<typename T1>
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<typename T1, typename T2>
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<typename T1, typename T2, typename T3>
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<typename T1, typename T2, typename T3, typename T4>
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<typename T1, typename T2, typename T3, typename T4, typename T5>
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 <plog_level L, bool build_enabled = true>
Expand Down
2 changes: 1 addition & 1 deletion src/emu/netlist/solver/nld_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class matrix_solver_t : public device_t
ATTR_COLD int get_net_idx(net_t *net);

inline eSolverType type() const { return m_type; }
const plog_base<NL_DEBUG> &log() const { return netlist().log(); }
plog_base<NL_DEBUG> &log() { return netlist().log(); }

virtual void log_stats();

Expand Down

0 comments on commit bce5387

Please sign in to comment.