Some netlist_time maintenance. Straightened code using it and added

support for 128 bit resolution on systems supporting it. This is however
disabled since all platforms I know don't have native support but
emulate 128 bit. (nw)
This commit is contained in:
couriersud 2015-08-14 20:30:30 +02:00
parent 32fd6a0342
commit 6ac50ea052
7 changed files with 83 additions and 53 deletions

View File

@ -255,8 +255,6 @@ ADDRESS_MAP_END
netlist_mame_device_t::netlist_mame_device_t(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, NETLIST_CORE, "Netlist core device", tag, owner, clock, "netlist_core", __FILE__),
m_icount(0),
m_div(0),
m_rem(0),
m_old(netlist::netlist_time::zero),
m_netlist(NULL),
m_setup(NULL),
@ -267,8 +265,6 @@ netlist_mame_device_t::netlist_mame_device_t(const machine_config &mconfig, cons
netlist_mame_device_t::netlist_mame_device_t(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *file)
: device_t(mconfig, type, name, tag, owner, clock, shortname, file),
m_icount(0),
m_div(0),
m_rem(0),
m_old(netlist::netlist_time::zero),
m_netlist(NULL),
m_setup(NULL),
@ -326,17 +322,17 @@ void netlist_mame_device_t::device_start()
save_state();
m_old = netlist::netlist_time::zero;
m_rem = 0;
m_rem = netlist::netlist_time::zero;
}
void netlist_mame_device_t::device_clock_changed()
{
//printf("device_clock_changed\n");
m_div = netlist::netlist_time::from_hz(clock()).as_raw();
m_div = netlist::netlist_time::from_hz(clock());
//m_rem = 0;
//NL_VERBOSE_OUT(("Setting clock %" I64FMT "d and divisor %d\n", clock(), m_div));
NL_VERBOSE_OUT(("Setting clock %d and divisor %d\n", clock(), m_div));
NL_VERBOSE_OUT(("Setting clock %d and divisor %f\n", clock(), m_div.as_double()));
//printf("Setting clock %d and divisor %d\n", clock(), m_div);
}
@ -345,7 +341,7 @@ void netlist_mame_device_t::device_reset()
{
LOG_DEV_CALLS(("device_reset\n"));
m_old = netlist::netlist_time::zero;
m_rem = 0;
m_rem = netlist::netlist_time::zero;
netlist().do_reset();
}
@ -383,9 +379,12 @@ void netlist_mame_device_t::device_timer(emu_timer &timer, device_timer_id id, i
ATTR_HOT ATTR_ALIGN void netlist_mame_device_t::update_time_x()
{
const netlist::netlist_time delta = netlist().time() - m_old + netlist::netlist_time::from_raw(m_rem);
m_old = netlist().time();
m_icount -= divu_64x32_rem(delta.as_raw(), m_div, &m_rem);
const netlist::netlist_time newt = netlist().time();
const netlist::netlist_time delta = newt - m_old + m_rem;
const UINT64 d = delta / m_div;
m_old = newt;
m_rem = delta - (m_div * d);
m_icount -= d;
}
ATTR_HOT ATTR_ALIGN void netlist_mame_device_t::check_mame_abort_slice()
@ -414,6 +413,12 @@ ATTR_COLD void netlist_mame_device_t::save_state()
if (td != NULL) save_pointer(td, s->m_name.cstr(), s->m_count);
}
break;
#if (PHAS_INT128)
case DT_INT128:
// FIXME: we are cheating here
save_pointer((char *) s->m_ptr, s->m_name.cstr(), s->m_count * sizeof(INT128));
break;
#endif
case DT_INT64:
save_pointer((INT64 *) s->m_ptr, s->m_name.cstr(), s->m_count);
break;
@ -529,13 +534,13 @@ ATTR_HOT void netlist_mame_cpu_device_t::execute_run()
m_genPC++;
m_genPC &= 255;
debugger_instruction_hook(this, m_genPC);
netlist().process_queue(netlist::netlist_time::from_raw(m_div));
netlist().process_queue(m_div);
update_time_x();
}
}
else
{
netlist().process_queue(netlist::netlist_time::from_raw(m_div) * m_icount);
netlist().process_queue(m_div * m_icount);
update_time_x();
}
}
@ -623,9 +628,9 @@ void netlist_mame_sound_device_t::sound_stream_update(sound_stream &stream, stre
netlist::netlist_time cur = netlist().time();
netlist().process_queue(netlist::netlist_time::from_raw(m_div) * samples);
netlist().process_queue(m_div * samples);
cur += (netlist::netlist_time::from_raw(m_div) * samples);
cur += (m_div * samples);
for (int i=0; i < m_num_outputs; i++)
{

View File

@ -143,13 +143,13 @@ protected:
//virtual void device_debug_setup();
virtual void device_clock_changed();
UINT32 m_div;
netlist::netlist_time m_div;
private:
void save_state();
/* timing support here - so sound can hijack it ... */
UINT32 m_rem;
netlist::netlist_time m_rem;
netlist::netlist_time m_old;
netlist_mame_t * m_netlist;

View File

@ -23,7 +23,8 @@
// net_list_time
// ----------------------------------------------------------------------------------------
#define RESOLUTION NETLIST_INTERNAL_RES
#undef ATTR_HOT
#define ATTR_HOT
namespace netlist
{
@ -31,71 +32,73 @@ namespace netlist
{
public:
#if (PHAS_INT128)
typedef UINT128 INTERNALTYPE;
static const pstate_data_type_e STATETYPE = DT_INT128;
#else
typedef UINT64 INTERNALTYPE;
static const pstate_data_type_e STATETYPE = DT_INT64;
#endif
static const INTERNALTYPE RESOLUTION = NETLIST_INTERNAL_RES;
ATTR_HOT /* inline */ netlist_time() : m_time(0) {}
ATTR_HOT netlist_time() : m_time(0) {}
ATTR_HOT netlist_time(const netlist_time &rhs) : m_time(rhs.m_time) {}
ATTR_HOT friend /* inline */ const netlist_time operator-(const netlist_time &left, const netlist_time &right);
ATTR_HOT friend /* inline */ const netlist_time operator+(const netlist_time &left, const netlist_time &right);
ATTR_HOT friend /* inline */ const netlist_time operator*(const netlist_time &left, const UINT32 factor);
ATTR_HOT friend /* inline */ UINT32 operator/(const netlist_time &left, const netlist_time &right);
ATTR_HOT friend /* inline */ bool operator>(const netlist_time &left, const netlist_time &right);
ATTR_HOT friend /* inline */ bool operator<(const netlist_time &left, const netlist_time &right);
ATTR_HOT friend /* inline */ bool operator>=(const netlist_time &left, const netlist_time &right);
ATTR_HOT friend /* inline */ bool operator<=(const netlist_time &left, const netlist_time &right);
ATTR_HOT friend /* inline */ bool operator!=(const netlist_time &left, const netlist_time &right);
ATTR_HOT friend const netlist_time operator-(const netlist_time &left, const netlist_time &right);
ATTR_HOT friend const netlist_time operator+(const netlist_time &left, const netlist_time &right);
ATTR_HOT friend const netlist_time operator*(const netlist_time &left, const UINT64 factor);
ATTR_HOT friend UINT64 operator/(const netlist_time &left, const netlist_time &right);
ATTR_HOT friend bool operator>(const netlist_time &left, const netlist_time &right);
ATTR_HOT friend bool operator<(const netlist_time &left, const netlist_time &right);
ATTR_HOT friend bool operator>=(const netlist_time &left, const netlist_time &right);
ATTR_HOT friend bool operator<=(const netlist_time &left, const netlist_time &right);
ATTR_HOT friend bool operator!=(const netlist_time &left, const netlist_time &right);
ATTR_HOT /* inline */ const netlist_time &operator=(const netlist_time &right) { m_time = right.m_time; return *this; }
ATTR_HOT /* inline */ const netlist_time &operator=(const double &right) { m_time = (INTERNALTYPE) ( right * (double) RESOLUTION); return *this; }
ATTR_HOT const netlist_time &operator=(const netlist_time &right) { m_time = right.m_time; return *this; }
// issues with ISO C++ standard
//ATTR_HOT /* inline */ operator double() const { return as_double(); }
ATTR_HOT const netlist_time &operator+=(const netlist_time &right) { m_time += right.m_time; return *this; }
ATTR_HOT /* inline */ const netlist_time &operator+=(const netlist_time &right) { m_time += right.m_time; return *this; }
ATTR_HOT /* inline */ INTERNALTYPE as_raw() const { return m_time; }
ATTR_HOT /* inline */ double as_double() const { return (double) m_time / (double) RESOLUTION; }
ATTR_HOT INTERNALTYPE as_raw() const { return m_time; }
ATTR_HOT double as_double() const { return (double) m_time / (double) RESOLUTION; }
// for save states ....
ATTR_HOT /* inline */ INTERNALTYPE *get_internaltype_ptr() { return &m_time; }
ATTR_HOT INTERNALTYPE *get_internaltype_ptr() { return &m_time; }
ATTR_HOT static /* inline */ const netlist_time from_nsec(const int ns) { return netlist_time((UINT64) ns * (RESOLUTION / U64(1000000000))); }
ATTR_HOT static /* inline */ const netlist_time from_usec(const int us) { return netlist_time((UINT64) us * (RESOLUTION / U64(1000000))); }
ATTR_HOT static /* inline */ const netlist_time from_msec(const int ms) { return netlist_time((UINT64) ms * (RESOLUTION / U64(1000))); }
ATTR_HOT static /* inline */ const netlist_time from_hz(const UINT64 hz) { return netlist_time(RESOLUTION / hz); }
ATTR_HOT static /* inline */ const netlist_time from_double(const double t) { return netlist_time((INTERNALTYPE) ( t * (double) RESOLUTION)); }
ATTR_HOT static /* inline */ const netlist_time from_raw(const INTERNALTYPE raw) { return netlist_time(raw); }
ATTR_HOT static const netlist_time from_nsec(const INTERNALTYPE ns) { return netlist_time(ns * (RESOLUTION / U64(1000000000))); }
ATTR_HOT static const netlist_time from_usec(const INTERNALTYPE us) { return netlist_time(us * (RESOLUTION / U64(1000000))); }
ATTR_HOT static const netlist_time from_msec(const INTERNALTYPE ms) { return netlist_time(ms * (RESOLUTION / U64(1000))); }
ATTR_HOT static const netlist_time from_hz(const INTERNALTYPE hz) { return netlist_time(RESOLUTION / hz); }
ATTR_HOT static const netlist_time from_double(const double t) { return netlist_time((INTERNALTYPE) ( t * (double) RESOLUTION)); }
ATTR_HOT static const netlist_time from_raw(const INTERNALTYPE raw) { return netlist_time(raw); }
static const netlist_time zero;
protected:
ATTR_HOT /* inline */ netlist_time(const INTERNALTYPE val) : m_time(val) {}
ATTR_HOT netlist_time(const INTERNALTYPE val) : m_time(val) {}
private:
INTERNALTYPE m_time;
};
#undef RESOLUTION
ATTR_HOT inline const netlist_time operator-(const netlist_time &left, const netlist_time &right)
{
return netlist_time::from_raw(left.m_time - right.m_time);
return netlist_time(left.m_time - right.m_time);
}
ATTR_HOT inline const netlist_time operator*(const netlist_time &left, const UINT32 factor)
ATTR_HOT inline const netlist_time operator*(const netlist_time &left, const UINT64 factor)
{
return netlist_time::from_raw(left.m_time * factor);
return netlist_time(left.m_time * factor);
}
ATTR_HOT inline UINT32 operator/(const netlist_time &left, const netlist_time &right)
ATTR_HOT inline UINT64 operator/(const netlist_time &left, const netlist_time &right)
{
return left.m_time / right.m_time;
}
ATTR_HOT inline const netlist_time operator+(const netlist_time &left, const netlist_time &right)
{
return netlist_time::from_raw(left.m_time + right.m_time);
return netlist_time(left.m_time + right.m_time);
}
ATTR_HOT inline bool operator<(const netlist_time &left, const netlist_time &right)
@ -127,7 +130,7 @@ namespace netlist
template<> ATTR_COLD inline void pstate_manager_t::save_item(netlist::netlist_time &nlt, const void *owner, const pstring &stname)
{
save_state_ptr(stname, DT_INT64, owner, sizeof(netlist::netlist_time::INTERNALTYPE), 1, nlt.get_internaltype_ptr(), false);
save_state_ptr(stname, netlist::netlist_time::STATETYPE, owner, sizeof(netlist::netlist_time::INTERNALTYPE), 1, nlt.get_internaltype_ptr(), false);
}

View File

@ -19,6 +19,18 @@
#define PSTANDALONE (0)
#endif
#define PHAS_INT128 (0)
#ifndef PHAS_INT128
#define PHAS_INT128 (0)
#endif
#if (PHAS_INT128)
typedef __uint128_t UINT128;
typedef __int128_t INT128;
#endif
#if !(PSTANDALONE)
#include "osdcore.h"
#include "eminline.h"

View File

@ -25,6 +25,9 @@ ATTR_COLD void pstate_manager_t::save_state_ptr(const pstring &stname, const pst
"NOT_SUPPORTED",
"DT_CUSTOM",
"DT_DOUBLE",
#if (PHAS_INT128)
"DT_INT128",
#endif
"DT_INT64",
"DT_INT16",
"DT_INT8",

View File

@ -32,6 +32,9 @@ enum pstate_data_type_e {
NOT_SUPPORTED,
DT_CUSTOM,
DT_DOUBLE,
#if (PHAS_INT128)
DT_INT128,
#endif
DT_INT64,
DT_INT16,
DT_INT8,
@ -63,6 +66,10 @@ NETLIST_SAVE_TYPE(double, DT_DOUBLE);
NETLIST_SAVE_TYPE(float, DT_FLOAT);
NETLIST_SAVE_TYPE(INT8, DT_INT8);
NETLIST_SAVE_TYPE(UINT8, DT_INT8);
#if (PHAS_INT128)
NETLIST_SAVE_TYPE(INT128, DT_INT128);
NETLIST_SAVE_TYPE(UINT128, DT_INT128);
#endif
NETLIST_SAVE_TYPE(INT64, DT_INT64);
NETLIST_SAVE_TYPE(UINT64, DT_INT64);
NETLIST_SAVE_TYPE(bool, DT_BOOLEAN);

View File

@ -477,7 +477,7 @@ ATTR_COLD void NETLIB_NAME(solver)::post_start()
m_params.m_accuracy = m_accuracy.Value();
m_params.m_gs_loops = m_gs_loops.Value();
m_params.m_nr_loops = m_nr_loops.Value();
m_params.m_nt_sync_delay = m_sync_delay.Value();
m_params.m_nt_sync_delay = netlist_time::from_double(m_sync_delay.Value());
m_params.m_lte = m_lte.Value();
m_params.m_sor = m_sor.Value();