mirror of
https://github.com/holub/mame
synced 2025-04-27 10:43:07 +03:00
netlist: simplify code.
This commit is contained in:
parent
c797d55aaf
commit
c0754c36cd
@ -38,10 +38,8 @@ namespace netlist
|
||||
void process_queue(netlist_time_ext delta) noexcept;
|
||||
void abort_current_queue_slice() noexcept
|
||||
{
|
||||
if (!NL_USE_QUEUE_STATS || !m_use_stats)
|
||||
m_queue.retime<false>(detail::queue_t::entry_t(m_time, nullptr));
|
||||
else
|
||||
m_queue.retime<true>(detail::queue_t::entry_t(m_time, nullptr));
|
||||
qremove(nullptr);
|
||||
qpush(m_time, nullptr);
|
||||
}
|
||||
|
||||
const detail::queue_t &queue() const noexcept { return m_queue; }
|
||||
@ -95,9 +93,8 @@ namespace netlist
|
||||
const log_type &log() const noexcept { return m_state.log(); }
|
||||
|
||||
void print_stats() const;
|
||||
bool use_stats() const { return m_use_stats; }
|
||||
|
||||
bool stats_enabled() const noexcept { return m_use_stats; }
|
||||
constexpr bool stats_enabled() const noexcept { return m_use_stats; }
|
||||
void enable_stats(bool val) noexcept { m_use_stats = val; }
|
||||
|
||||
private:
|
||||
@ -115,8 +112,8 @@ namespace netlist
|
||||
|
||||
//PALIGNAS_CACHELINE()
|
||||
//PALIGNAS(16)
|
||||
detail::queue_t m_queue;
|
||||
bool m_use_stats;
|
||||
detail::queue_t m_queue;
|
||||
// performance
|
||||
plib::pperftime_t<true> m_stat_mainloop;
|
||||
plib::pperfcount_t<true> m_perf_out_processed;
|
||||
|
@ -21,12 +21,13 @@
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
|
||||
namespace netlist
|
||||
{
|
||||
namespace detail {
|
||||
// Use timed_queue_heap to use stdc++ heap functions instead of linear processing.
|
||||
// This slows down processing by about 25% on a Kaby Lake.
|
||||
// This slows down processing by about 35% on a Kaby Lake.
|
||||
// template <class T, bool TS>
|
||||
// using timed_queue = plib::timed_queue_heap<T, TS>;
|
||||
|
||||
|
@ -86,14 +86,14 @@ namespace netlist
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
netlist_t::netlist_t(netlist_state_t &state, const pstring &aname)
|
||||
: m_state(state)
|
||||
, m_solver(nullptr)
|
||||
, m_time(netlist_time_ext::zero())
|
||||
, m_mainclock(nullptr)
|
||||
, m_queue(config::MAX_QUEUE_SIZE::value,
|
||||
detail::queue_t::id_delegate(&netlist_state_t :: find_net_id, &state),
|
||||
detail::queue_t::obj_delegate(&netlist_state_t :: net_by_id, &state))
|
||||
, m_use_stats(false)
|
||||
: m_state(state)
|
||||
, m_solver(nullptr)
|
||||
, m_time(netlist_time_ext::zero())
|
||||
, m_mainclock(nullptr)
|
||||
, m_use_stats(false)
|
||||
, m_queue(config::MAX_QUEUE_SIZE::value,
|
||||
detail::queue_t::id_delegate(&netlist_state_t :: find_net_id, &state),
|
||||
detail::queue_t::obj_delegate(&netlist_state_t :: net_by_id, &state))
|
||||
{
|
||||
state.save(*this, static_cast<plib::state_manager_t::callback_t &>(m_queue), aname, "m_queue");
|
||||
state.save(*this, m_time, aname, "m_time");
|
||||
@ -433,7 +433,6 @@ namespace netlist
|
||||
log().verbose("Queue Pushes {1:15}", si.m_queue.m_prof_call());
|
||||
log().verbose("Queue Moves {1:15}", si.m_queue.m_prof_sortmove());
|
||||
log().verbose("Queue Removes {1:15}", si.m_queue.m_prof_remove());
|
||||
log().verbose("Queue Retimes {1:15}", si.m_queue.m_prof_retime());
|
||||
log().verbose("");
|
||||
|
||||
log().verbose("Take the next lines with a grain of salt. They depend on the measurement implementation.");
|
||||
|
@ -42,7 +42,11 @@ namespace plib {
|
||||
//uninitialised_array_t() noexcept = default;
|
||||
uninitialised_array() noexcept = default;
|
||||
|
||||
PCOPYASSIGNMOVE(uninitialised_array, delete)
|
||||
uninitialised_array(const uninitialised_array &) = default;
|
||||
uninitialised_array &operator=(const uninitialised_array &) = default;
|
||||
uninitialised_array(uninitialised_array &&) noexcept = default;
|
||||
uninitialised_array &operator=(uninitialised_array &&) noexcept = default;
|
||||
|
||||
~uninitialised_array() noexcept = default;
|
||||
|
||||
constexpr size_t size() const noexcept { return N; }
|
||||
@ -111,7 +115,11 @@ namespace plib {
|
||||
{
|
||||
}
|
||||
|
||||
PCOPYASSIGNMOVE(static_vector, delete)
|
||||
static_vector(const static_vector &) = default;
|
||||
static_vector &operator=(const static_vector &) = default;
|
||||
static_vector(static_vector &&) noexcept = default;
|
||||
static_vector &operator=(static_vector &&) noexcept = default;
|
||||
|
||||
~static_vector() noexcept
|
||||
{
|
||||
clear();
|
||||
|
@ -51,7 +51,10 @@ namespace plib
|
||||
::new(&m_v[i]) T();
|
||||
}
|
||||
|
||||
PCOPYASSIGNMOVE(pmatrix2d, delete)
|
||||
pmatrix2d(const pmatrix2d &) = delete;
|
||||
pmatrix2d &operator=(const pmatrix2d &) = delete;
|
||||
pmatrix2d(pmatrix2d &&) noexcept = delete;
|
||||
pmatrix2d &operator=(pmatrix2d &&) noexcept = delete;
|
||||
|
||||
~pmatrix2d()
|
||||
{
|
||||
|
@ -150,6 +150,7 @@ namespace plib {
|
||||
}
|
||||
|
||||
void pop() noexcept { --m_end; }
|
||||
|
||||
const T &top() const noexcept { return *(m_end-1); }
|
||||
|
||||
template <bool KEEPSTAT, class R>
|
||||
@ -171,34 +172,6 @@ namespace plib {
|
||||
//printf("Element not found in delete %s\n", elem->name().c_str());
|
||||
}
|
||||
|
||||
template <bool KEEPSTAT, class R>
|
||||
void retime(R && elem) noexcept
|
||||
{
|
||||
// Lock
|
||||
lock_guard_type lck(m_lock);
|
||||
if (KEEPSTAT)
|
||||
m_prof_retime.inc();
|
||||
|
||||
for (R * i = m_end - 1; i > &m_list[0]; --i)
|
||||
{
|
||||
if (*i == elem) // partial equal!
|
||||
{
|
||||
*i = std::forward<R>(elem);
|
||||
while (*(i-1) < *i)
|
||||
{
|
||||
std::swap(*(i-1), *i);
|
||||
--i;
|
||||
}
|
||||
while (i < m_end && *i < *(i+1))
|
||||
{
|
||||
std::swap(*(i+1), *i);
|
||||
++i;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void clear() noexcept
|
||||
{
|
||||
lock_guard_type lck(m_lock);
|
||||
@ -230,7 +203,6 @@ namespace plib {
|
||||
pperfcount_t<true> m_prof_sortmove; // NOLINT
|
||||
pperfcount_t<true> m_prof_call; // NOLINT
|
||||
pperfcount_t<true> m_prof_remove; // NOLINT
|
||||
pperfcount_t<true> m_prof_retime; // NOLINT
|
||||
};
|
||||
|
||||
template <class T, bool TS>
|
||||
@ -240,7 +212,7 @@ namespace plib {
|
||||
|
||||
struct compare
|
||||
{
|
||||
constexpr bool operator()(const T &a, const T &b) const { return b <= a; }
|
||||
constexpr bool operator()(const T &a, const T &b) const noexcept { return b <= a; }
|
||||
};
|
||||
|
||||
explicit timed_queue_heap(const std::size_t list_size)
|
||||
@ -255,6 +227,17 @@ namespace plib {
|
||||
std::size_t capacity() const noexcept { return m_list.capacity(); }
|
||||
bool empty() const noexcept { return &m_list[0] == m_end; }
|
||||
|
||||
template<bool KEEPSTAT, typename... Args>
|
||||
void emplace(Args&&... args) noexcept
|
||||
{
|
||||
// Lock
|
||||
lock_guard_type lck(m_lock);
|
||||
*m_end++ = T(std::forward<Args>(args)...);
|
||||
std::push_heap(&m_list[0], m_end, compare());
|
||||
if (KEEPSTAT)
|
||||
m_prof_call.inc();
|
||||
}
|
||||
|
||||
template <bool KEEPSTAT>
|
||||
void push(T &&e) noexcept
|
||||
{
|
||||
@ -266,12 +249,10 @@ namespace plib {
|
||||
m_prof_call.inc();
|
||||
}
|
||||
|
||||
T pop() noexcept
|
||||
void pop() noexcept
|
||||
{
|
||||
T ret(m_list[0]);
|
||||
std::pop_heap(&m_list[0], m_end, compare());
|
||||
m_end--;
|
||||
return ret;
|
||||
}
|
||||
|
||||
const T &top() const noexcept { return m_list[0]; }
|
||||
@ -295,24 +276,6 @@ namespace plib {
|
||||
}
|
||||
}
|
||||
|
||||
template <bool KEEPSTAT>
|
||||
void retime(const T &elem) noexcept
|
||||
{
|
||||
// Lock
|
||||
lock_guard_type lck(m_lock);
|
||||
if (KEEPSTAT)
|
||||
m_prof_retime.inc();
|
||||
for (T * i = m_end - 1; i >= &m_list[0]; i--)
|
||||
{
|
||||
if (*i == elem) // partial equal!
|
||||
{
|
||||
*i = elem;
|
||||
std::make_heap(&m_list[0], m_end, compare());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
lock_guard_type lck(m_lock);
|
||||
@ -329,19 +292,17 @@ namespace plib {
|
||||
using mutex_type = pspin_mutex<TS>;
|
||||
using lock_guard_type = std::lock_guard<mutex_type>;
|
||||
|
||||
mutex_type m_lock;
|
||||
std::vector<T> m_list;
|
||||
T *m_end;
|
||||
mutex_type m_lock;
|
||||
T * m_end;
|
||||
aligned_vector<T> m_list;
|
||||
|
||||
public:
|
||||
// profiling
|
||||
pperfcount_t<true> m_prof_sortmove; // NOLINT
|
||||
pperfcount_t<true> m_prof_call; // NOLINT
|
||||
pperfcount_t<true> m_prof_remove; // NOLINT
|
||||
pperfcount_t<true> m_prof_retime; // NOLINT
|
||||
};
|
||||
|
||||
} // namespace plib
|
||||
|
||||
#endif // PTIMED_QUEUE_H_
|
||||
#include <cstdlib>
|
||||
|
@ -34,7 +34,7 @@ namespace devices
|
||||
|
||||
NETLIB_RESET(solver)
|
||||
{
|
||||
if (exec().use_stats())
|
||||
if (exec().stats_enabled())
|
||||
m_fb_step.set_delegate(NETLIB_DELEGATE(fb_step<true>));
|
||||
for (auto &s : m_mat_solvers)
|
||||
s->reset();
|
||||
|
Loading…
Reference in New Issue
Block a user