Fix state saving for pfunction lfsr. (nw)

This commit is contained in:
couriersud 2017-05-28 09:03:17 +02:00 committed by Vas Crabb
parent a0e5e36bd5
commit 2f31991e76
5 changed files with 23 additions and 4 deletions

View File

@ -392,6 +392,7 @@ public:
, m_R(*this, "R", 0.1) , m_R(*this, "R", 0.1)
, m_V(*this, "V", 0.0) , m_V(*this, "V", 0.0)
, m_func(*this,"FUNC", "") , m_func(*this,"FUNC", "")
, m_compiled(this->name() + ".FUNCC", this, this->netlist().state())
{ {
register_subalias("P", m_P); register_subalias("P", m_P);
register_subalias("N", m_N); register_subalias("N", m_N);
@ -422,6 +423,7 @@ public:
NETLIB_CONSTRUCTOR_DERIVED(CS, twoterm) NETLIB_CONSTRUCTOR_DERIVED(CS, twoterm)
, m_I(*this, "I", 1.0) , m_I(*this, "I", 1.0)
, m_func(*this,"FUNC", "") , m_func(*this,"FUNC", "")
, m_compiled(this->name() + ".FUNCC", this, this->netlist().state())
{ {
register_subalias("P", m_P); register_subalias("P", m_P);
register_subalias("N", m_N); register_subalias("N", m_N);

View File

@ -137,7 +137,7 @@ namespace netlist
{ {
m_vals[i] = (*m_I[i])(); m_vals[i] = (*m_I[i])();
} }
m_Q.push(m_precompiled.evaluate(m_vals)); m_Q.push(m_compiled.evaluate(m_vals));
} }

View File

@ -306,6 +306,7 @@ namespace netlist
, 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->netlist().state())
{ {
std::vector<pstring> inps; std::vector<pstring> inps;
for (int i=0; i < m_N(); i++) for (int i=0; i < m_N(); i++)
@ -315,7 +316,7 @@ namespace netlist
inps.push_back(n); inps.push_back(n);
m_vals.push_back(0.0); m_vals.push_back(0.0);
} }
m_precompiled.compile(inps, m_func()); m_compiled.compile(inps, m_func());
} }
protected: protected:
@ -331,7 +332,7 @@ namespace netlist
std::vector<std::unique_ptr<analog_input_t>> m_I; std::vector<std::unique_ptr<analog_input_t>> m_I;
std::vector<double> m_vals; std::vector<double> m_vals;
plib::pfunction m_precompiled; plib::pfunction m_compiled;
}; };
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------

View File

@ -37,7 +37,6 @@ void pfunction::compile_postfix(const std::vector<pstring> &inputs,
for (const pstring &cmd : cmds) for (const pstring &cmd : cmds)
{ {
printf("%s %d\n", cmd.c_str(), stk);
rpn_inst rc; rpn_inst rc;
if (cmd == "+") if (cmd == "+")
{ rc.m_cmd = ADD; stk -= 1; } { rc.m_cmd = ADD; stk -= 1; }

View File

@ -9,6 +9,7 @@
#define PFUNCTION_H_ #define PFUNCTION_H_
#include "pstring.h" #include "pstring.h"
#include "pstate.h"
#include <vector> #include <vector>
@ -43,6 +44,22 @@ namespace plib {
double m_param; double m_param;
}; };
public: public:
/*! Constructor with state saving support
*
* @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)
{
state_manager.save_item(owner, m_lfsr, name + ".lfsr");
}
/*! Constructor without state saving support
*
*/
pfunction() pfunction()
: m_lfsr(0xACE1u) : m_lfsr(0xACE1u)
{ {