netlist: simplify pfunction state handling. (nw)

Removes dependency on pstate.h.
This commit is contained in:
couriersud 2020-05-03 18:00:34 +02:00
parent b2c40086e6
commit fdc9787c23
4 changed files with 16 additions and 20 deletions

View File

@ -553,9 +553,10 @@ namespace analog
, m_R(*this, "RI", nlconst::magic(0.1)) , m_R(*this, "RI", nlconst::magic(0.1))
, m_V(*this, "V", nlconst::zero()) , m_V(*this, "V", nlconst::zero())
, m_func(*this,"FUNC", "") , m_func(*this,"FUNC", "")
, m_compiled(this->name() + ".FUNCC", this, this->state().run_state_manager()) , m_compiled()
, m_funcparam({nlconst::zero()}) , m_funcparam({nlconst::zero()})
{ {
m_compiled.save_state(*this, "m_compiled");
register_subalias("P", P()); register_subalias("P", P());
register_subalias("N", N()); register_subalias("N", N());
if (m_func() != "") if (m_func() != "")
@ -601,9 +602,10 @@ namespace analog
, m_t(*this, "m_t", nlconst::zero()) , m_t(*this, "m_t", nlconst::zero())
, m_I(*this, "I", nlconst::one()) , m_I(*this, "I", nlconst::one())
, m_func(*this,"FUNC", "") , m_func(*this,"FUNC", "")
, m_compiled(this->name() + ".FUNCC", this, this->state().run_state_manager()) , m_compiled()
, m_funcparam({nlconst::zero()}) , m_funcparam({nlconst::zero()})
{ {
m_compiled.save_state(*this, "m_compiled");
register_subalias("P", P()); register_subalias("P", P());
register_subalias("N", N()); register_subalias("N", N());
if (m_func() != "") if (m_func() != "")

View File

@ -127,9 +127,10 @@ namespace devices
, m_feedback(*this, "FB") , m_feedback(*this, "FB")
, m_Q(*this, "Q") , m_Q(*this, "Q")
, m_func(*this,"FUNC", "") , m_func(*this,"FUNC", "")
, m_compiled(this->name() + ".FUNCC", this, this->state().run_state_manager()) , m_compiled()
, m_funcparam({nlconst::zero()}) , m_funcparam({nlconst::zero()})
{ {
m_compiled.save_state(*this, "m_compiled");
if (m_func() != "") if (m_func() != "")
m_compiled.compile(m_func(), std::vector<pstring>({{pstring("T")}})); m_compiled.compile(m_func(), std::vector<pstring>({{pstring("T")}}));
connect(m_feedback, m_Q); connect(m_feedback, m_Q);
@ -395,8 +396,9 @@ namespace devices
, m_N(*this, "N", 1) , m_N(*this, "N", 1)
, m_func(*this, "FUNC", "A0") , m_func(*this, "FUNC", "A0")
, m_Q(*this, "Q") , m_Q(*this, "Q")
, m_compiled(this->name() + ".FUNCC", this, this->state().run_state_manager()) , m_compiled()
{ {
m_compiled.save_state(*this, "m_compiled");
std::vector<pstring> inps; std::vector<pstring> inps;
for (int i=0; i < m_N(); i++) for (int i=0; i < m_N(); i++)
{ {

View File

@ -9,7 +9,6 @@
/// ///
#include "pmath.h" #include "pmath.h"
#include "pstate.h"
#include "pstring.h" #include "pstring.h"
#include "putil.h" #include "putil.h"
@ -57,20 +56,7 @@ namespace plib {
using inputs_container = std::vector<pstring>; using inputs_container = std::vector<pstring>;
using values_container = std::vector<value_type>; using values_container = std::vector<value_type>;
/// \brief Constructor with state saving support /// \brief Constructor
///
/// \param name Name of this object
/// \param owner Owner of this object
/// \param state_manager State manager to handle saving object state
///
///
pfunction(const pstring &name, const void *owner, state_manager_t &state_manager)
: m_lfsr(0xace1U) // NOLINT
{
state_manager.save_item(owner, m_lfsr, name + ".lfsr");
}
/// \brief Constructor without state saving support
/// ///
pfunction() pfunction()
: m_lfsr(0xace1U) // NOLINT : m_lfsr(0xace1U) // NOLINT
@ -106,6 +92,12 @@ namespace plib {
/// ///
value_type evaluate(const values_container &values = values_container()) noexcept; value_type evaluate(const values_container &values = values_container()) noexcept;
template <typename ST, typename STR>
void save_state(ST &st, const STR &name)
{
st.save_item(m_lfsr, name, "m_lfsr");
}
private: private:
void compile_postfix(const inputs_container &inputs, void compile_postfix(const inputs_container &inputs,

View File

@ -199,7 +199,7 @@ namespace plib
} }
else else
{ {
// last value with error for log(s)/s // last value without error for log(s)/s
// double: 1.000000e-305 // double: 1.000000e-305
// float: 9.999999e-37 // float: 9.999999e-37
// FIXME: with 128 bit randoms log(s)/w will fail 1/(2^128) ~ 2.9e-39 // FIXME: with 128 bit randoms log(s)/w will fail 1/(2^128) ~ 2.9e-39