mirror of
https://github.com/holub/mame
synced 2025-04-30 03:47:13 +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 process_queue(netlist_time_ext delta) noexcept;
|
||||||
void abort_current_queue_slice() noexcept
|
void abort_current_queue_slice() noexcept
|
||||||
{
|
{
|
||||||
if (!NL_USE_QUEUE_STATS || !m_use_stats)
|
qremove(nullptr);
|
||||||
m_queue.retime<false>(detail::queue_t::entry_t(m_time, nullptr));
|
qpush(m_time, nullptr);
|
||||||
else
|
|
||||||
m_queue.retime<true>(detail::queue_t::entry_t(m_time, nullptr));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const detail::queue_t &queue() const noexcept { return m_queue; }
|
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(); }
|
const log_type &log() const noexcept { return m_state.log(); }
|
||||||
|
|
||||||
void print_stats() const;
|
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; }
|
void enable_stats(bool val) noexcept { m_use_stats = val; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -115,8 +112,8 @@ namespace netlist
|
|||||||
|
|
||||||
//PALIGNAS_CACHELINE()
|
//PALIGNAS_CACHELINE()
|
||||||
//PALIGNAS(16)
|
//PALIGNAS(16)
|
||||||
detail::queue_t m_queue;
|
|
||||||
bool m_use_stats;
|
bool m_use_stats;
|
||||||
|
detail::queue_t m_queue;
|
||||||
// performance
|
// performance
|
||||||
plib::pperftime_t<true> m_stat_mainloop;
|
plib::pperftime_t<true> m_stat_mainloop;
|
||||||
plib::pperfcount_t<true> m_perf_out_processed;
|
plib::pperfcount_t<true> m_perf_out_processed;
|
||||||
|
@ -21,12 +21,13 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
namespace netlist
|
namespace netlist
|
||||||
{
|
{
|
||||||
namespace detail {
|
namespace detail {
|
||||||
// Use timed_queue_heap to use stdc++ heap functions instead of linear processing.
|
// 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>
|
// template <class T, bool TS>
|
||||||
// using timed_queue = plib::timed_queue_heap<T, TS>;
|
// using timed_queue = plib::timed_queue_heap<T, TS>;
|
||||||
|
|
||||||
|
@ -90,10 +90,10 @@ namespace netlist
|
|||||||
, m_solver(nullptr)
|
, m_solver(nullptr)
|
||||||
, m_time(netlist_time_ext::zero())
|
, m_time(netlist_time_ext::zero())
|
||||||
, m_mainclock(nullptr)
|
, m_mainclock(nullptr)
|
||||||
|
, m_use_stats(false)
|
||||||
, m_queue(config::MAX_QUEUE_SIZE::value,
|
, m_queue(config::MAX_QUEUE_SIZE::value,
|
||||||
detail::queue_t::id_delegate(&netlist_state_t :: find_net_id, &state),
|
detail::queue_t::id_delegate(&netlist_state_t :: find_net_id, &state),
|
||||||
detail::queue_t::obj_delegate(&netlist_state_t :: net_by_id, &state))
|
detail::queue_t::obj_delegate(&netlist_state_t :: net_by_id, &state))
|
||||||
, m_use_stats(false)
|
|
||||||
{
|
{
|
||||||
state.save(*this, static_cast<plib::state_manager_t::callback_t &>(m_queue), aname, "m_queue");
|
state.save(*this, static_cast<plib::state_manager_t::callback_t &>(m_queue), aname, "m_queue");
|
||||||
state.save(*this, m_time, aname, "m_time");
|
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 Pushes {1:15}", si.m_queue.m_prof_call());
|
||||||
log().verbose("Queue Moves {1:15}", si.m_queue.m_prof_sortmove());
|
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 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("");
|
||||||
|
|
||||||
log().verbose("Take the next lines with a grain of salt. They depend on the measurement implementation.");
|
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_t() noexcept = default;
|
||||||
uninitialised_array() 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;
|
~uninitialised_array() noexcept = default;
|
||||||
|
|
||||||
constexpr size_t size() const noexcept { return N; }
|
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
|
~static_vector() noexcept
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
|
@ -51,7 +51,10 @@ namespace plib
|
|||||||
::new(&m_v[i]) T();
|
::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()
|
~pmatrix2d()
|
||||||
{
|
{
|
||||||
|
@ -150,6 +150,7 @@ namespace plib {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void pop() noexcept { --m_end; }
|
void pop() noexcept { --m_end; }
|
||||||
|
|
||||||
const T &top() const noexcept { return *(m_end-1); }
|
const T &top() const noexcept { return *(m_end-1); }
|
||||||
|
|
||||||
template <bool KEEPSTAT, class R>
|
template <bool KEEPSTAT, class R>
|
||||||
@ -171,34 +172,6 @@ namespace plib {
|
|||||||
//printf("Element not found in delete %s\n", elem->name().c_str());
|
//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
|
void clear() noexcept
|
||||||
{
|
{
|
||||||
lock_guard_type lck(m_lock);
|
lock_guard_type lck(m_lock);
|
||||||
@ -230,7 +203,6 @@ namespace plib {
|
|||||||
pperfcount_t<true> m_prof_sortmove; // NOLINT
|
pperfcount_t<true> m_prof_sortmove; // NOLINT
|
||||||
pperfcount_t<true> m_prof_call; // NOLINT
|
pperfcount_t<true> m_prof_call; // NOLINT
|
||||||
pperfcount_t<true> m_prof_remove; // NOLINT
|
pperfcount_t<true> m_prof_remove; // NOLINT
|
||||||
pperfcount_t<true> m_prof_retime; // NOLINT
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T, bool TS>
|
template <class T, bool TS>
|
||||||
@ -240,7 +212,7 @@ namespace plib {
|
|||||||
|
|
||||||
struct compare
|
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)
|
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(); }
|
std::size_t capacity() const noexcept { return m_list.capacity(); }
|
||||||
bool empty() const noexcept { return &m_list[0] == m_end; }
|
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>
|
template <bool KEEPSTAT>
|
||||||
void push(T &&e) noexcept
|
void push(T &&e) noexcept
|
||||||
{
|
{
|
||||||
@ -266,12 +249,10 @@ namespace plib {
|
|||||||
m_prof_call.inc();
|
m_prof_call.inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
T pop() noexcept
|
void pop() noexcept
|
||||||
{
|
{
|
||||||
T ret(m_list[0]);
|
|
||||||
std::pop_heap(&m_list[0], m_end, compare());
|
std::pop_heap(&m_list[0], m_end, compare());
|
||||||
m_end--;
|
m_end--;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const T &top() const noexcept { return m_list[0]; }
|
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()
|
void clear()
|
||||||
{
|
{
|
||||||
lock_guard_type lck(m_lock);
|
lock_guard_type lck(m_lock);
|
||||||
@ -330,18 +293,16 @@ namespace plib {
|
|||||||
using lock_guard_type = std::lock_guard<mutex_type>;
|
using lock_guard_type = std::lock_guard<mutex_type>;
|
||||||
|
|
||||||
mutex_type m_lock;
|
mutex_type m_lock;
|
||||||
std::vector<T> m_list;
|
T * m_end;
|
||||||
T *m_end;
|
aligned_vector<T> m_list;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// profiling
|
// profiling
|
||||||
pperfcount_t<true> m_prof_sortmove; // NOLINT
|
pperfcount_t<true> m_prof_sortmove; // NOLINT
|
||||||
pperfcount_t<true> m_prof_call; // NOLINT
|
pperfcount_t<true> m_prof_call; // NOLINT
|
||||||
pperfcount_t<true> m_prof_remove; // NOLINT
|
pperfcount_t<true> m_prof_remove; // NOLINT
|
||||||
pperfcount_t<true> m_prof_retime; // NOLINT
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace plib
|
} // namespace plib
|
||||||
|
|
||||||
#endif // PTIMED_QUEUE_H_
|
#endif // PTIMED_QUEUE_H_
|
||||||
#include <cstdlib>
|
|
||||||
|
@ -34,7 +34,7 @@ namespace devices
|
|||||||
|
|
||||||
NETLIB_RESET(solver)
|
NETLIB_RESET(solver)
|
||||||
{
|
{
|
||||||
if (exec().use_stats())
|
if (exec().stats_enabled())
|
||||||
m_fb_step.set_delegate(NETLIB_DELEGATE(fb_step<true>));
|
m_fb_step.set_delegate(NETLIB_DELEGATE(fb_step<true>));
|
||||||
for (auto &s : m_mat_solvers)
|
for (auto &s : m_mat_solvers)
|
||||||
s->reset();
|
s->reset();
|
||||||
|
Loading…
Reference in New Issue
Block a user