From db0dbeaea506a44c3acfaf64b0160c3cb397edb9 Mon Sep 17 00:00:00 2001 From: couriersud Date: Sat, 2 Nov 2019 23:39:24 +0100 Subject: netlist: improve readability. (nw) Renamed cast member of the constants struct to magic to clearly identify magic numbers. Introduced nlconst struct inheriting from plib::constants to make code better understandable. --- src/lib/netlist/analog/nld_bjt.cpp | 40 ++++---- src/lib/netlist/analog/nld_generic_models.h | 62 ++++++------ src/lib/netlist/analog/nld_mosfet.cpp | 146 +++++++++++++-------------- src/lib/netlist/analog/nld_opamps.cpp | 14 +-- src/lib/netlist/analog/nld_switches.cpp | 2 +- src/lib/netlist/analog/nlid_fourterm.cpp | 30 +++--- src/lib/netlist/analog/nlid_fourterm.h | 16 +-- src/lib/netlist/analog/nlid_twoterm.cpp | 26 ++--- src/lib/netlist/analog/nlid_twoterm.h | 48 ++++----- src/lib/netlist/devices/nld_4066.cpp | 16 +-- src/lib/netlist/devices/nld_4316.cpp | 6 +- src/lib/netlist/devices/nld_74123.cpp | 8 +- src/lib/netlist/devices/nld_74ls629.cpp | 30 +++--- src/lib/netlist/devices/nld_mm5837.cpp | 14 +-- src/lib/netlist/devices/nld_ne555.cpp | 18 ++-- src/lib/netlist/devices/nld_r2r_dac.cpp | 6 +- src/lib/netlist/devices/nld_schmitt.cpp | 8 +- src/lib/netlist/devices/nlid_proxy.cpp | 36 +++---- src/lib/netlist/devices/nlid_proxy.h | 2 +- src/lib/netlist/devices/nlid_system.h | 38 +++---- src/lib/netlist/nl_base.cpp | 32 +++--- src/lib/netlist/nl_base.h | 4 +- src/lib/netlist/nl_config.h | 2 +- src/lib/netlist/nl_parser.cpp | 14 +-- src/lib/netlist/nl_setup.cpp | 28 ++--- src/lib/netlist/nltypes.h | 6 +- src/lib/netlist/plib/pfmtlog.h | 1 - src/lib/netlist/plib/putil.h | 10 +- src/lib/netlist/prg/nltool.cpp | 4 +- src/lib/netlist/solver/nld_matrix_solver.cpp | 4 +- src/lib/netlist/solver/nld_matrix_solver.h | 28 ++--- src/lib/netlist/solver/nld_ms_sor.h | 8 +- 32 files changed, 355 insertions(+), 352 deletions(-) (limited to 'src/lib') diff --git a/src/lib/netlist/analog/nld_bjt.cpp b/src/lib/netlist/analog/nld_bjt.cpp index 2eed4711322..d96754daede 100644 --- a/src/lib/netlist/analog/nld_bjt.cpp +++ b/src/lib/netlist/analog/nld_bjt.cpp @@ -16,27 +16,25 @@ namespace netlist { namespace analog { - using constants = plib::constants; - class diode { public: diode() - : m_Is(plib::constants::cast(1e-15)) - , m_VT(plib::constants::cast(0.0258)) + : m_Is(nlconst::magic(1e-15)) + , m_VT(nlconst::magic(0.0258)) , m_VT_inv(plib::reciprocal(m_VT)) {} diode(const nl_fptype Is, const nl_fptype n) { m_Is = Is; - m_VT = plib::constants::cast(0.0258) * n; + m_VT = nlconst::magic(0.0258) * n; m_VT_inv = plib::reciprocal(m_VT); } void set(const nl_fptype Is, const nl_fptype n) { m_Is = Is; - m_VT = plib::constants::cast(0.0258) * n; + m_VT = nlconst::magic(0.0258) * n; m_VT_inv = plib::reciprocal(m_VT); } nl_fptype I(const nl_fptype V) const { return m_Is * std::exp(V * m_VT_inv) - m_Is; } @@ -184,9 +182,9 @@ namespace analog , m_RB(*this, "m_RB", true) , m_RC(*this, "m_RC", true) , m_BC(*this, "m_BC", true) - , m_gB(plib::constants::cast(1e-9)) - , m_gC(plib::constants::cast(1e-9)) - , m_V(plib::constants::zero()) + , m_gB(nlconst::magic(1e-9)) + , m_gC(nlconst::magic(1e-9)) + , m_V(nlconst::zero()) , m_state_on(*this, "m_state_on", 0) { register_subalias("B", m_RB.m_P); @@ -242,13 +240,13 @@ namespace analog connect(m_D_EB.m_N, m_D_CB.m_N); connect(m_D_CB.m_P, m_D_EC.m_N); - if (m_model.m_CJE > plib::constants::zero()) + if (m_model.m_CJE > nlconst::zero()) { create_and_register_subdevice("m_CJE", m_CJE); connect("B", "m_CJE.1"); connect("E", "m_CJE.2"); } - if (m_model.m_CJC > plib::constants::zero()) + if (m_model.m_CJC > nlconst::zero()) { create_and_register_subdevice("m_CJC", m_CJC); connect("B", "m_CJC.1"); @@ -297,14 +295,14 @@ namespace analog NETLIB_RESET(QBJT_switch) { NETLIB_NAME(QBJT)::reset(); - const auto zero(plib::constants::zero()); + const auto zero(nlconst::zero()); m_state_on = 0; m_RB.set_G_V_I(exec().gmin(), zero, zero); m_RC.set_G_V_I(exec().gmin(), zero, zero); - m_BC.set_G_V_I(exec().gmin() / plib::constants::cast(10.0), zero, zero); + m_BC.set_G_V_I(exec().gmin() / nlconst::magic(10.0), zero, zero); } @@ -329,13 +327,13 @@ namespace analog set_qtype((m_model.type() == "NPN") ? BJT_NPN : BJT_PNP); - nl_fptype alpha = BF / (plib::constants::one() + BF); + nl_fptype alpha = BF / (nlconst::one() + BF); diode d(IS, NF); // Assume 5mA Collector current for switch operation - const auto cc(plib::constants::cast(0.005)); + const auto cc(nlconst::magic(0.005)); m_V = d.V(cc / alpha); /* Base current is 0.005 / beta @@ -357,7 +355,7 @@ namespace analog const unsigned new_state = (m_RB.deltaV() * m > m_V ) ? 1 : 0; if (m_state_on ^ new_state) { - const auto zero(plib::constants::zero()); + const auto zero(nlconst::zero()); const nl_fptype gb = new_state ? m_gB : exec().gmin(); const nl_fptype gc = new_state ? m_gC : exec().gmin(); const nl_fptype v = new_state ? m_V * m : zero; @@ -403,7 +401,7 @@ namespace analog NETLIB_UPDATE_TERMINALS(QBJT_EB) { - const nl_fptype polarity = plib::constants::cast(qtype() == BJT_NPN ? 1.0 : -1.0); + const nl_fptype polarity = nlconst::magic(qtype() == BJT_NPN ? 1.0 : -1.0); m_gD_BE.update_diode(-m_D_EB.deltaV() * polarity); m_gD_BC.update_diode(-m_D_CB.deltaV() * polarity); @@ -439,11 +437,11 @@ namespace analog set_qtype((m_model.type() == "NPN") ? BJT_NPN : BJT_PNP); - m_alpha_f = BF / (plib::constants::one() + BF); - m_alpha_r = BR / (plib::constants::one() + BR); + m_alpha_f = BF / (nlconst::one() + BF); + m_alpha_r = BR / (nlconst::one() + BR); - m_gD_BE.set_param(IS / m_alpha_f, NF, exec().gmin(), constants::T0()); - m_gD_BC.set_param(IS / m_alpha_r, NR, exec().gmin(), constants::T0()); + m_gD_BE.set_param(IS / m_alpha_f, NF, exec().gmin(), nlconst::T0()); + m_gD_BC.set_param(IS / m_alpha_r, NR, exec().gmin(), nlconst::T0()); } } // namespace analog diff --git a/src/lib/netlist/analog/nld_generic_models.h b/src/lib/netlist/analog/nld_generic_models.h index 6a5285b94f6..b7412641d5e 100644 --- a/src/lib/netlist/analog/nld_generic_models.h +++ b/src/lib/netlist/analog/nld_generic_models.h @@ -38,10 +38,10 @@ namespace analog { public: generic_capacitor(device_t &dev, const pstring &name) - : m_h(dev, name + ".m_h", plib::constants::zero()) - , m_c(dev, name + ".m_c", plib::constants::zero()) - , m_v(dev, name + ".m_v", plib::constants::zero()) - , m_gmin(plib::constants::zero()) + : m_h(dev, name + ".m_h", nlconst::zero()) + , m_c(dev, name + ".m_c", nlconst::zero()) + , m_v(dev, name + ".m_v", nlconst::zero()) + , m_gmin(nlconst::zero()) { } @@ -57,7 +57,7 @@ namespace analog nl_fptype G(nl_fptype cap) const { //return m_h * cap + m_gmin; - return m_h * plib::constants::half() * (cap + m_c) + m_gmin; + return m_h * nlconst::half() * (cap + m_c) + m_gmin; //return m_h * cap + m_gmin; } @@ -65,7 +65,7 @@ namespace analog { plib::unused_var(v); //return -m_h * 0.5 * ((cap + m_c) * m_v + (cap - m_c) * v) ; - return -m_h * plib::constants::half() * (cap + m_c) * m_v; + return -m_h * nlconst::half() * (cap + m_c) * m_v; //return -m_h * cap * m_v; } @@ -91,9 +91,9 @@ namespace analog { public: generic_capacitor(device_t &dev, const pstring &name) - : m_h(dev, name + ".m_h", plib::constants::zero()) - , m_v(dev, name + ".m_v", plib::constants::zero()) - , m_gmin(plib::constants::zero()) + : m_h(dev, name + ".m_h", nlconst::zero()) + , m_v(dev, name + ".m_v", nlconst::zero()) + , m_gmin(nlconst::zero()) { } @@ -133,29 +133,29 @@ namespace analog { public: generic_diode(device_t &dev, const pstring &name) - : m_Vd(dev, name + ".m_Vd", plib::constants::cast(0.7)) - , m_Id(dev, name + ".m_Id", plib::constants::zero()) - , m_G(dev, name + ".m_G", plib::constants::cast(1e-15)) - , m_Vt(plib::constants::zero()) - , m_Vmin(plib::constants::zero()) // not used in MOS model - , m_Is(plib::constants::zero()) - , m_logIs(plib::constants::zero()) - , m_n(plib::constants::zero()) - , m_gmin(plib::constants::cast(1e-15)) - , m_VtInv(plib::constants::zero()) - , m_Vcrit(plib::constants::zero()) + : m_Vd(dev, name + ".m_Vd", nlconst::magic(0.7)) + , m_Id(dev, name + ".m_Id", nlconst::zero()) + , m_G(dev, name + ".m_G", nlconst::magic(1e-15)) + , m_Vt(nlconst::zero()) + , m_Vmin(nlconst::zero()) // not used in MOS model + , m_Is(nlconst::zero()) + , m_logIs(nlconst::zero()) + , m_n(nlconst::zero()) + , m_gmin(nlconst::magic(1e-15)) + , m_VtInv(nlconst::zero()) + , m_Vcrit(nlconst::zero()) , m_name(name) { set_param( - plib::constants::cast(1e-15) - , plib::constants::cast(1) - , plib::constants::cast(1e-15) - , plib::constants::cast(300.0)); + nlconst::magic(1e-15) + , nlconst::magic(1) + , nlconst::magic(1e-15) + , nlconst::magic(300.0)); } void update_diode(const nl_fptype nVd) { - nl_fptype IseVDVt(plib::constants::zero()); + nl_fptype IseVDVt(nlconst::zero()); if (TYPE == diode_e::BIPOLAR) { @@ -164,7 +164,7 @@ namespace analog { const nl_fptype d = std::min(+fp_constants::DIODE_MAXDIFF(), nVd - m_Vd); const nl_fptype a = std::abs(d) * m_VtInv; - m_Vd = m_Vd + plib::constants::cast(d < 0 ? -1.0 : 1.0) * std::log1p(a) * m_Vt; + m_Vd = m_Vd + nlconst::magic(d < 0 ? -1.0 : 1.0) * std::log1p(a) * m_Vt; } else m_Vd = std::max(-fp_constants::DIODE_MAXDIFF(), nVd); @@ -184,7 +184,7 @@ namespace analog } else if (TYPE == diode_e::MOS) { - if (nVd < constants::zero()) + if (nVd < nlconst::zero()) { m_Vd = nVd; m_G = m_Is * m_VtInv + m_gmin; @@ -207,12 +207,12 @@ namespace analog m_n = n; m_gmin = gmin; - m_Vt = m_n * temp * constants::k_b() / constants::Q_e(); + m_Vt = m_n * temp * nlconst::k_b() / nlconst::Q_e(); - m_Vmin = plib::constants::cast(-5.0) * m_Vt; + m_Vmin = nlconst::magic(-5.0) * m_Vt; - m_Vcrit = m_Vt * std::log(m_Vt / m_Is / constants::sqrt2()); - m_VtInv = constants::one() / m_Vt; + m_Vcrit = m_Vt * std::log(m_Vt / m_Is / nlconst::sqrt2()); + m_VtInv = nlconst::one() / m_Vt; //printf("%g %g\n", m_Vmin, m_Vcrit); } diff --git a/src/lib/netlist/analog/nld_mosfet.cpp b/src/lib/netlist/analog/nld_mosfet.cpp index 172f8cd75f0..da73b129e88 100644 --- a/src/lib/netlist/analog/nld_mosfet.cpp +++ b/src/lib/netlist/analog/nld_mosfet.cpp @@ -195,20 +195,20 @@ namespace analog , m_cap_gb(*this, "m_cap_gb") , m_cap_gs(*this, "m_cap_gs") , m_cap_gd(*this, "m_cap_gd") - , m_phi(plib::constants::zero()) - , m_gamma(plib::constants::zero()) - , m_vto(plib::constants::zero()) - , m_beta(plib::constants::zero()) - , m_lambda(plib::constants::zero()) - , m_Leff(plib::constants::zero()) - , m_CoxWL(plib::constants::zero()) - , m_polarity(plib::constants::cast(qtype() == FET_NMOS ? 1.0 : -1.0)) - , m_Cgb(plib::constants::zero()) - , m_Cgs(plib::constants::zero()) - , m_Cgd(plib::constants::zero()) + , m_phi(nlconst::zero()) + , m_gamma(nlconst::zero()) + , m_vto(nlconst::zero()) + , m_beta(nlconst::zero()) + , m_lambda(nlconst::zero()) + , m_Leff(nlconst::zero()) + , m_CoxWL(nlconst::zero()) + , m_polarity(nlconst::magic(qtype() == FET_NMOS ? 1.0 : -1.0)) + , m_Cgb(nlconst::zero()) + , m_Cgs(nlconst::zero()) + , m_Cgd(nlconst::zero()) , m_capmod(2) - , m_Vgs(*this, "m_Vgs", plib::constants::zero()) - , m_Vgd(*this, "m_Vgd", plib::constants::zero()) + , m_Vgs(*this, "m_Vgs", nlconst::zero()) + , m_Vgd(*this, "m_Vgd", nlconst::zero()) { register_subalias("S", m_SG.m_P); // Source register_subalias("G", m_SG.m_N); // Gate @@ -220,7 +220,7 @@ namespace analog connect(m_DG.m_P, m_SD.m_N); set_qtype((m_model.type() == "NMOS_DEFAULT") ? FET_NMOS : FET_PMOS); - m_polarity = qtype() == plib::constants::cast(FET_NMOS ? 1.0 : -1.0); + m_polarity = qtype() == nlconst::magic(FET_NMOS ? 1.0 : -1.0); m_capmod = m_model.m_CAPMOD; // printf("capmod %d %g %g\n", m_capmod, (nl_fptype)m_model.m_VTO, m_polarity); @@ -241,49 +241,49 @@ namespace analog // calculate effective channel length m_Leff = m_model.m_L - 2 * m_model.m_LD; - nl_assert_always(m_Leff > plib::constants::zero(), "Effective Lateral diffusion would be negative for model " + m_model.name()); + nl_assert_always(m_Leff > nlconst::zero(), "Effective Lateral diffusion would be negative for model " + m_model.name()); - nl_fptype Cox = (m_model.m_TOX > plib::constants::zero()) ? (constants::eps_SiO2() * constants::eps_0() / m_model.m_TOX) : plib::constants::zero(); + nl_fptype Cox = (m_model.m_TOX > nlconst::zero()) ? (constants::eps_SiO2() * constants::eps_0() / m_model.m_TOX) : nlconst::zero(); // calculate DC transconductance coefficient - if (m_model.m_KP > plib::constants::zero()) + if (m_model.m_KP > nlconst::zero()) m_beta = m_model.m_KP * m_model.m_W / m_Leff; - else if (Cox > plib::constants::zero() && m_model.m_UO > plib::constants::zero()) - m_beta = m_model.m_UO * plib::constants::cast(1e-4) * Cox * m_model.m_W / m_Leff; + else if (Cox > nlconst::zero() && m_model.m_UO > nlconst::zero()) + m_beta = m_model.m_UO * nlconst::magic(1e-4) * Cox * m_model.m_W / m_Leff; else - m_beta = plib::constants::cast(2e-5) * m_model.m_W / m_Leff; + m_beta = nlconst::magic(2e-5) * m_model.m_W / m_Leff; //FIXME::UT can disappear const nl_fptype Vt = constants::T0() * constants::k_b() / constants::Q_e(); // calculate surface potential if not given - if (m_model.m_PHI > plib::constants::zero()) + if (m_model.m_PHI > nlconst::zero()) m_phi = m_model.m_PHI; - else if (m_model.m_NSUB > plib::constants::zero()) + else if (m_model.m_NSUB > nlconst::zero()) { - nl_assert_always(m_model.m_NSUB * plib::constants::cast(1e6) >= constants::NiSi(), "Error calculating phi for model " + m_model.name()); - m_phi = plib::constants::two() * Vt * std::log (m_model.m_NSUB * plib::constants::cast(1e6) / constants::NiSi()); + nl_assert_always(m_model.m_NSUB * nlconst::magic(1e6) >= constants::NiSi(), "Error calculating phi for model " + m_model.name()); + m_phi = nlconst::two() * Vt * std::log (m_model.m_NSUB * nlconst::magic(1e6) / constants::NiSi()); } else - m_phi = plib::constants::cast(0.6); + m_phi = nlconst::magic(0.6); // calculate bulk threshold if not given - if (m_model.m_GAMMA > plib::constants::zero()) + if (m_model.m_GAMMA > nlconst::zero()) m_gamma = m_model.m_GAMMA; else { - if (Cox > plib::constants::zero() && m_model.m_NSUB > plib::constants::zero()) - m_gamma = std::sqrt (plib::constants::two() + if (Cox > nlconst::zero() && m_model.m_NSUB > nlconst::zero()) + m_gamma = std::sqrt (nlconst::two() * constants::Q_e() * constants::eps_Si() * constants::eps_0() - * m_model.m_NSUB * plib::constants::cast(1e6)) / Cox; + * m_model.m_NSUB * nlconst::magic(1e6)) / Cox; else - m_gamma = plib::constants::zero(); + m_gamma = nlconst::zero(); } m_vto = m_model.m_VTO; // FIXME zero conversion - if(m_vto != plib::constants::zero()) + if(m_vto != nlconst::zero()) log().warning(MW_MOSFET_THRESHOLD_VOLTAGE(m_model.name())); /* FIXME: VTO if missing may be calculated from TPG, NSS and temperature. Usually models @@ -305,7 +305,7 @@ namespace analog //const nl_nl_fptype Ugs = -m_SG.deltaV() * m_polarity; // Gate - Source const nl_fptype Ugd = m_Vgd; // Gate - Drain const nl_fptype Ugs = m_Vgs; // Gate - Source - const nl_fptype Ubs = plib::constants::zero(); // Bulk - Source == 0 if connected + const nl_fptype Ubs = nlconst::zero(); // Bulk - Source == 0 if connected const nl_fptype Ugb = Ugs - Ubs; m_cap_gb.timestep(m_Cgb, Ugb, step); @@ -388,21 +388,21 @@ namespace analog if (Vctrl <= -m_phi) { Cgb = m_CoxWL; - Cgs = plib::constants::zero(); - Cgd = plib::constants::zero(); + Cgs = nlconst::zero(); + Cgd = nlconst::zero(); } - else if (Vctrl <= -m_phi / plib::constants::two()) + else if (Vctrl <= -m_phi / nlconst::two()) { Cgb = -Vctrl * m_CoxWL / m_phi; - Cgs = plib::constants::zero(); - Cgd = plib::constants::zero(); + Cgs = nlconst::zero(); + Cgd = nlconst::zero(); } // Depletion else if (Vctrl <= 0) { Cgb = -Vctrl * m_CoxWL / m_phi; - Cgs = Vctrl * m_CoxWL * plib::constants::cast(4.0 / 3.0) / m_phi + plib::constants::cast(2.0 / 3.0) * m_CoxWL; - Cgd = plib::constants::zero(); + Cgs = Vctrl * m_CoxWL * nlconst::magic(4.0 / 3.0) / m_phi + nlconst::magic(2.0 / 3.0) * m_CoxWL; + Cgd = nlconst::zero(); } else { @@ -411,18 +411,18 @@ namespace analog // saturation if (Vdsat <= Vds) { - Cgb = plib::constants::zero(); - Cgs = plib::constants::cast(2.0 / 3.0) * m_CoxWL; - Cgd = plib::constants::zero(); + Cgb = nlconst::zero(); + Cgs = nlconst::magic(2.0 / 3.0) * m_CoxWL; + Cgd = nlconst::zero(); } else { // linear const nl_fptype Sqr1 = static_cast(std::pow(Vdsat - Vds, 2)); - const nl_fptype Sqr2 = static_cast(std::pow(plib::constants::two() * Vdsat - Vds, 2)); + const nl_fptype Sqr2 = static_cast(std::pow(nlconst::two() * Vdsat - Vds, 2)); Cgb = 0; - Cgs = m_CoxWL * (plib::constants::one() - Sqr1 / Sqr2) * plib::constants::cast(2.0 / 3.0); - Cgd = m_CoxWL * (plib::constants::one() - Vdsat * Vdsat / Sqr2) * plib::constants::cast(2.0 / 3.0); + Cgs = m_CoxWL * (nlconst::one() - Sqr1 / Sqr2) * nlconst::magic(2.0 / 3.0); + Cgd = m_CoxWL * (nlconst::one() - Vdsat * Vdsat / Sqr2) * nlconst::magic(2.0 / 3.0); } } } @@ -450,16 +450,16 @@ namespace analog // limit step sizes - const nl_fptype k = plib::constants::cast(3.5); // see "Circuit Simulation", page 185 + const nl_fptype k = nlconst::magic(3.5); // see "Circuit Simulation", page 185 nl_fptype d = (Vgs - m_Vgs); - Vgs = m_Vgs + plib::reciprocal(k) * plib::constants::cast(d < 0 ? -1.0 : 1.0) * std::log1p(k * std::abs(d)); + Vgs = m_Vgs + plib::reciprocal(k) * nlconst::magic(d < 0 ? -1.0 : 1.0) * std::log1p(k * std::abs(d)); d = (Vgd - m_Vgd); - Vgd = m_Vgd + plib::reciprocal(k) * plib::constants::cast(d < 0 ? -1.0 : 1.0) * std::log1p(k * std::abs(d)); + Vgd = m_Vgd + plib::reciprocal(k) * nlconst::magic(d < 0 ? -1.0 : 1.0) * std::log1p(k * std::abs(d)); m_Vgs = Vgs; m_Vgd = Vgd; - const nl_fptype Vbs = plib::constants::zero(); // Bulk - Source == 0 if connected + const nl_fptype Vbs = nlconst::zero(); // Bulk - Source == 0 if connected //const nl_nl_fptype Vbd = m_SD.deltaV() * m_polarity; // Bulk - Drain = Source - Drain const nl_fptype Vds = Vgs - Vgd; const nl_fptype Vbd = -Vds; // Bulk - Drain = Source - Drain @@ -471,11 +471,11 @@ namespace analog // Are we in forward mode ? // in backward mode, just swap source and drain - const bool is_forward = Vds >= plib::constants::zero(); + const bool is_forward = Vds >= nlconst::zero(); // calculate Vth const nl_fptype Vbulk = is_forward ? Vbs : Vbd; - const nl_fptype phi_m_Vbulk = (m_phi > Vbulk) ? std::sqrt(m_phi - Vbulk) : plib::constants::zero(); + const nl_fptype phi_m_Vbulk = (m_phi > Vbulk) ? std::sqrt(m_phi - Vbulk) : nlconst::zero(); const nl_fptype Vth = m_vto * m_polarity + m_gamma * (phi_m_Vbulk - std::sqrt(m_phi)); const nl_fptype Vctrl = (is_forward ? Vgs : Vgd) - Vth; @@ -483,34 +483,34 @@ namespace analog nl_fptype Ids(0), gm(0), gds(0), gmb(0); const nl_fptype absVds = std::abs(Vds); - if (Vctrl <= plib::constants::zero()) + if (Vctrl <= nlconst::zero()) { // cutoff region - Ids = plib::constants::zero(); - gm = plib::constants::zero(); - gds = plib::constants::zero(); - gmb = plib::constants::zero(); + Ids = nlconst::zero(); + gm = nlconst::zero(); + gds = nlconst::zero(); + gmb = nlconst::zero(); } else { - const nl_fptype beta = m_beta * (plib::constants::one() + m_lambda * absVds); + const nl_fptype beta = m_beta * (nlconst::one() + m_lambda * absVds); if (Vctrl <= absVds) { // saturation region - Ids = beta * Vctrl * Vctrl / plib::constants::two(); + Ids = beta * Vctrl * Vctrl / nlconst::two(); gm = beta * Vctrl; - gds = m_lambda * m_beta * Vctrl * Vctrl / plib::constants::two(); + gds = m_lambda * m_beta * Vctrl * Vctrl / nlconst::two(); } else { // linear region - Ids = beta * absVds * (Vctrl - absVds / plib::constants::two()); + Ids = beta * absVds * (Vctrl - absVds / nlconst::two()); gm = beta * absVds; - gds = beta * (Vctrl - absVds) + m_lambda * m_beta * absVds * (Vctrl - absVds / plib::constants::two()); + gds = beta * (Vctrl - absVds) + m_lambda * m_beta * absVds * (Vctrl - absVds / nlconst::two()); } // backgate transconductance - const nl_fptype bgtc = (phi_m_Vbulk != plib::constants::zero()) ? (m_gamma / phi_m_Vbulk / plib::constants::two()) : plib::constants::zero(); + const nl_fptype bgtc = (phi_m_Vbulk != nlconst::zero()) ? (m_gamma / phi_m_Vbulk / nlconst::two()) : nlconst::zero(); gmb = gm * bgtc; } @@ -527,27 +527,27 @@ namespace analog const nl_fptype IeqBS = m_D_BS.Ieq(); const nl_fptype gbs = m_D_BS.G(); #else - const nl_fptype IeqBS = plib::constants::zero(); - const nl_fptype gbs = plib::constants::zero(); + const nl_fptype IeqBS = nlconst::zero(); + const nl_fptype gbs = nlconst::zero(); #endif // exchange controlling nodes if necessary - const nl_fptype gsource = is_forward ? (gm + gmb) : plib::constants::zero(); - const nl_fptype gdrain = is_forward ? plib::constants::zero() : (gm + gmb); + const nl_fptype gsource = is_forward ? (gm + gmb) : nlconst::zero(); + const nl_fptype gdrain = is_forward ? nlconst::zero() : (gm + gmb); const nl_fptype IeqDS = (is_forward) ? Ids - gm * Vgs - gmb * Vbs - gds * Vds : -Ids - gm * Vgd - gmb * Vbd - gds * Vds; // IG = 0 - nl_fptype IG = plib::constants::zero(); + nl_fptype IG = nlconst::zero(); nl_fptype ID = (+IeqBD - IeqDS) * m_polarity; nl_fptype IS = (+IeqBS + IeqDS) * m_polarity; nl_fptype IB = (-IeqBD - IeqBS) * m_polarity; - nl_fptype gGG = plib::constants::zero(); - nl_fptype gGD = plib::constants::zero(); - nl_fptype gGS = plib::constants::zero(); - nl_fptype gGB = plib::constants::zero(); + nl_fptype gGG = nlconst::zero(); + nl_fptype gGD = nlconst::zero(); + nl_fptype gGS = nlconst::zero(); + nl_fptype gGB = nlconst::zero(); nl_fptype gDG = gm; nl_fptype gDD = gds + gbd - gdrain; @@ -559,7 +559,7 @@ namespace analog nl_fptype gSS = gbs + gds + gsource; const nl_fptype gSB = -gbs - gmb; - nl_fptype gBG = plib::constants::zero(); + nl_fptype gBG = nlconst::zero(); const nl_fptype gBD = -gbd; const nl_fptype gBS = -gbs; nl_fptype gBB = gbs + gbd; @@ -580,7 +580,7 @@ namespace analog // Source connected to body, Diode S-B shorted! const nl_fptype gSSBB = gSS + gBB + gBS + gSB; - const auto zero(plib::constants::zero()); + const auto zero(nlconst::zero()); // S G m_SG.set_mat( gSSBB, gSG + gBG, +(IS + IB), // S gGS + gGB, gGG, IG ); // G diff --git a/src/lib/netlist/analog/nld_opamps.cpp b/src/lib/netlist/analog/nld_opamps.cpp index dfd1e06b139..2756262cc4a 100644 --- a/src/lib/netlist/analog/nld_opamps.cpp +++ b/src/lib/netlist/analog/nld_opamps.cpp @@ -197,13 +197,13 @@ namespace netlist NETLIB_UPDATE(opamp) { - const nl_fptype cVt = plib::constants::cast(0.0258 * 1.0); // * m_n; + const nl_fptype cVt = nlconst::magic(0.0258 * 1.0); // * m_n; const nl_fptype cId = m_model.m_DAB; // 3 mA - const nl_fptype cVd = cVt * std::log(cId / plib::constants::cast(1e-15) + plib::constants::one()); + const nl_fptype cVd = cVt * std::log(cId / nlconst::magic(1e-15) + nlconst::one()); m_VH.push(m_VCC() - m_model.m_VLH - cVd); m_VL.push(m_GND() + m_model.m_VLL + cVd); - m_VREF.push((m_VCC() + m_GND()) / plib::constants::two()); + m_VREF.push((m_VCC() + m_GND()) / nlconst::two()); } NETLIB_UPDATE_PARAM(opamp) @@ -220,11 +220,11 @@ namespace netlist if (m_type == 3 || m_type == 2) { nl_fptype CP = m_model.m_DAB / m_model.m_SLEW; - nl_fptype RP = plib::constants::half() / constants::pi() / CP / m_model.m_FPF; + nl_fptype RP = nlconst::half() / nlconst::pi() / CP / m_model.m_FPF; nl_fptype G = m_model.m_UGF / m_model.m_FPF / RP; //printf("OPAMP %s: %g %g %g\n", name().c_str(), CP, RP, G); - if (m_model.m_SLEW / (plib::constants::four() * constants::pi() * plib::constants::cast(0.0258)) < m_model.m_UGF) + if (m_model.m_SLEW / (nlconst::four() * nlconst::pi() * nlconst::magic(0.0258)) < m_model.m_UGF) log().warning(MW_OPAMP_FAIL_CONVERGENCE(this->name())); m_CP->m_C.setTo(CP); @@ -234,12 +234,12 @@ namespace netlist } if (m_type == 2) { - m_EBUF->m_G.setTo(plib::constants::one()); + m_EBUF->m_G.setTo(nlconst::one()); m_EBUF->m_RO.setTo(m_model.m_RO); } if (m_type == 3) { - m_EBUF->m_G.setTo(plib::constants::one()); + m_EBUF->m_G.setTo(nlconst::one()); m_EBUF->m_RO.setTo(m_model.m_RO); } } diff --git a/src/lib/netlist/analog/nld_switches.cpp b/src/lib/netlist/analog/nld_switches.cpp index 8f0647da04c..09bf62d29de 100644 --- a/src/lib/netlist/analog/nld_switches.cpp +++ b/src/lib/netlist/analog/nld_switches.cpp @@ -13,7 +13,7 @@ /* FIXME : convert to parameters */ #define R_OFF (plib::reciprocal(exec().gmin())) -#define R_ON plib::constants::cast(0.01) +#define R_ON nlconst::magic(0.01) namespace netlist { diff --git a/src/lib/netlist/analog/nlid_fourterm.cpp b/src/lib/netlist/analog/nlid_fourterm.cpp index ea5687c4f80..c4fdedbe1a9 100644 --- a/src/lib/netlist/analog/nlid_fourterm.cpp +++ b/src/lib/netlist/analog/nlid_fourterm.cpp @@ -24,16 +24,16 @@ namespace netlist NETLIB_RESET(VCCS) { const nl_fptype m_mult = m_G() * m_gfac; // 1.0 ==> 1V ==> 1A - const nl_fptype GI = plib::constants::one() / m_RI(); + const nl_fptype GI = nlconst::one() / m_RI(); m_IP.set_conductivity(GI); m_IN.set_conductivity(GI); - m_OP.set_go_gt(-m_mult, plib::constants::zero()); - m_OP1.set_go_gt(m_mult, plib::constants::zero()); + m_OP.set_go_gt(-m_mult, nlconst::zero()); + m_OP1.set_go_gt(m_mult, nlconst::zero()); - m_ON.set_go_gt(m_mult, plib::constants::zero()); - m_ON1.set_go_gt(-m_mult, plib::constants::zero()); + m_ON.set_go_gt(m_mult, nlconst::zero()); + m_ON1.set_go_gt(-m_mult, nlconst::zero()); } NETLIB_UPDATE(VCCS) @@ -67,9 +67,9 @@ NETLIB_UPDATE_TERMINALS(LVCCS) { const nl_fptype m_mult = m_G() * m_gfac; // 1.0 ==> 1V ==> 1A const nl_fptype vi = m_IP.net().Q_Analog() - m_IN.net().Q_Analog(); - const auto c1(plib::constants::cast(0.2)); + const auto c1(nlconst::magic(0.2)); - if (std::abs(m_mult / m_cur_limit() * vi) > plib::constants::half()) + if (std::abs(m_mult / m_cur_limit() * vi) > nlconst::half()) m_vi = m_vi + c1 * std::tanh((vi - m_vi) / c1); else m_vi = vi; @@ -77,14 +77,14 @@ NETLIB_UPDATE_TERMINALS(LVCCS) const nl_fptype x = m_mult / m_cur_limit() * m_vi; const nl_fptype X = std::tanh(x); - const nl_fptype beta = m_mult * (plib::constants::one() - X*X); + const nl_fptype beta = m_mult * (nlconst::one() - X*X); const nl_fptype I = m_cur_limit() * X - beta * m_vi; - m_OP.set_go_gt_I(-beta, plib::constants::zero(), I); - m_OP1.set_go_gt(beta, plib::constants::zero()); + m_OP.set_go_gt_I(-beta, nlconst::zero(), I); + m_OP1.set_go_gt(beta, nlconst::zero()); - m_ON.set_go_gt_I(beta, plib::constants::zero(), -I); - m_ON1.set_go_gt(-beta, plib::constants::zero()); + m_ON.set_go_gt_I(beta, nlconst::zero(), -I); + m_ON1.set_go_gt(-beta, nlconst::zero()); } // ---------------------------------------------------------------------------------------- @@ -107,11 +107,11 @@ NETLIB_UPDATE_PARAM(CCCS) NETLIB_RESET(VCVS) { - m_gfac = plib::constants::one() / m_RO(); + m_gfac = nlconst::one() / m_RO(); NETLIB_NAME(VCCS)::reset(); - m_OP2.set_conductivity(plib::constants::one() / m_RO()); - m_ON2.set_conductivity(plib::constants::one() / m_RO()); + m_OP2.set_conductivity(nlconst::one() / m_RO()); + m_ON2.set_conductivity(nlconst::one() / m_RO()); } } //namespace analog diff --git a/src/lib/netlist/analog/nlid_fourterm.h b/src/lib/netlist/analog/nlid_fourterm.h index 4900b55fda6..a977bdd5260 100644 --- a/src/lib/netlist/analog/nlid_fourterm.h +++ b/src/lib/netlist/analog/nlid_fourterm.h @@ -39,19 +39,19 @@ namespace netlist { { public: NETLIB_CONSTRUCTOR(VCCS) - , m_G(*this, "G", plib::constants::one()) - , m_RI(*this, "RI", plib::constants::cast(1e9)) + , m_G(*this, "G", nlconst::one()) + , m_RI(*this, "RI", nlconst::magic(1e9)) , m_OP(*this, "OP", &m_IP) , m_ON(*this, "ON", &m_IP) , m_IP(*this, "IP", &m_IN) // <= this should be NULL and terminal be filtered out prior to solving... , m_IN(*this, "IN", &m_IP) // <= this should be NULL and terminal be filtered out prior to solving... , m_OP1(*this, "_OP1", &m_IN) , m_ON1(*this, "_ON1", &m_IN) - , m_gfac(plib::constants::one()) + , m_gfac(nlconst::one()) { connect(m_OP, m_OP1); connect(m_ON, m_ON1); - m_gfac = plib::constants::one(); + m_gfac = nlconst::one(); } NETLIB_RESETI(); @@ -85,8 +85,8 @@ namespace netlist { { public: NETLIB_CONSTRUCTOR_DERIVED(LVCCS, VCCS) - , m_cur_limit(*this, "CURLIM", plib::constants::cast(1000.0)) - , m_vi(plib::constants::zero()) + , m_cur_limit(*this, "CURLIM", nlconst::magic(1000.0)) + , m_vi(nlconst::zero()) { } @@ -131,7 +131,7 @@ namespace netlist { public: NETLIB_CONSTRUCTOR_DERIVED(CCCS, VCCS) { - m_gfac = plib::constants::one() / m_RI(); + m_gfac = nlconst::one() / m_RI(); } NETLIB_RESETI(); @@ -174,7 +174,7 @@ namespace netlist { { public: NETLIB_CONSTRUCTOR_DERIVED(VCVS, VCCS) - , m_RO(*this, "RO", plib::constants::one()) + , m_RO(*this, "RO", nlconst::one()) , m_OP2(*this, "_OP2", &m_ON2) , m_ON2(*this, "_ON2", &m_OP2) { diff --git a/src/lib/netlist/analog/nlid_twoterm.cpp b/src/lib/netlist/analog/nlid_twoterm.cpp index c9d94c98f51..2234afd5cd6 100644 --- a/src/lib/netlist/analog/nlid_twoterm.cpp +++ b/src/lib/netlist/analog/nlid_twoterm.cpp @@ -64,10 +64,10 @@ NETLIB_RESET(POT) { nl_fptype v = m_Dial(); if (m_DialIsLog()) - v = (std::exp(v) - plib::constants::one()) / (std::exp(plib::constants::one()) - plib::constants::one()); + v = (std::exp(v) - nlconst::one()) / (std::exp(nlconst::one()) - nlconst::one()); m_R1.set_R(std::max(m_R() * v, exec().gmin())); - m_R2.set_R(std::max(m_R() * (plib::constants::one() - v), exec().gmin())); + m_R2.set_R(std::max(m_R() * (nlconst::one() - v), exec().gmin())); } NETLIB_UPDATE_PARAM(POT) @@ -77,11 +77,11 @@ NETLIB_UPDATE_PARAM(POT) nl_fptype v = m_Dial(); if (m_DialIsLog()) - v = (std::exp(v) - plib::constants::one()) / (std::exp(plib::constants::one()) - plib::constants::one()); + v = (std::exp(v) - nlconst::one()) / (std::exp(nlconst::one()) - nlconst::one()); if (m_Reverse()) - v = plib::constants::one() - v; + v = nlconst::one() - v; m_R1.set_R(std::max(m_R() * v, exec().gmin())); - m_R2.set_R(std::max(m_R() * (plib::constants::one() - v), exec().gmin())); + m_R2.set_R(std::max(m_R() * (nlconst::one() - v), exec().gmin())); } @@ -94,9 +94,9 @@ NETLIB_RESET(POT2) nl_fptype v = m_Dial(); if (m_DialIsLog()) - v = (std::exp(v) - plib::constants::one()) / (std::exp(plib::constants::one()) - plib::constants::one()); + v = (std::exp(v) - nlconst::one()) / (std::exp(nlconst::one()) - nlconst::one()); if (m_Reverse()) - v = plib::constants::one() - v; + v = nlconst::one() - v; m_R1.set_R(std::max(m_R() * v, exec().gmin())); } @@ -108,9 +108,9 @@ NETLIB_UPDATE_PARAM(POT2) nl_fptype v = m_Dial(); if (m_DialIsLog()) - v = (std::exp(v) - plib::constants::one()) / (std::exp(plib::constants::one()) - plib::constants::one()); + v = (std::exp(v) - nlconst::one()) / (std::exp(nlconst::one()) - nlconst::one()); if (m_Reverse()) - v = plib::constants::one() - v; + v = nlconst::one() - v; m_R1.set_R(std::max(m_R() * v, exec().gmin())); } @@ -121,7 +121,7 @@ NETLIB_UPDATE_PARAM(POT2) NETLIB_RESET(L) { m_gmin = exec().gmin(); - m_I = plib::constants::zero(); + m_I = nlconst::zero(); m_G = m_gmin; set_mat( m_G, -m_G, -m_I, -m_G, m_G, m_I); @@ -151,8 +151,8 @@ NETLIB_RESET(D) nl_fptype Is = m_model.m_IS; nl_fptype n = m_model.m_N; - m_D.set_param(Is, n, exec().gmin(), constants::T0()); - set_G_V_I(m_D.G(), plib::constants::zero(), m_D.Ieq()); + m_D.set_param(Is, n, exec().gmin(), nlconst::T0()); + set_G_V_I(m_D.G(), nlconst::zero(), m_D.Ieq()); } NETLIB_UPDATE_PARAM(D) @@ -160,7 +160,7 @@ NETLIB_UPDATE_PARAM(D) nl_fptype Is = m_model.m_IS; nl_fptype n = m_model.m_N; - m_D.set_param(Is, n, exec().gmin(), constants::T0()); + m_D.set_param(Is, n, exec().gmin(), nlconst::T0()); } NETLIB_UPDATE_TERMINALS(D) diff --git a/src/lib/netlist/analog/nlid_twoterm.h b/src/lib/netlist/analog/nlid_twoterm.h index 72de24181e0..d9c1b8e8050 100644 --- a/src/lib/netlist/analog/nlid_twoterm.h +++ b/src/lib/netlist/analog/nlid_twoterm.h @@ -127,9 +127,9 @@ namespace analog void set_R(const nl_fptype R) { - const nl_fptype G = plib::constants::one() / R; - set_mat( G, -G, plib::constants::zero(), - -G, G, plib::constants::zero()); + const nl_fptype G = nlconst::one() / R; + set_mat( G, -G, nlconst::zero(), + -G, G, nlconst::zero()); } NETLIB_RESETI(); @@ -142,7 +142,7 @@ namespace analog NETLIB_OBJECT_DERIVED(R, R_base) { NETLIB_CONSTRUCTOR_DERIVED(R, R_base) - , m_R(*this, "R", plib::constants::cast(1e9)) + , m_R(*this, "R", nlconst::magic(1e9)) { } @@ -178,7 +178,7 @@ namespace analog , m_R1(*this, "_R1") , m_R2(*this, "_R2") , m_R(*this, "R", 10000) - , m_Dial(*this, "DIAL", plib::constants::half()) + , m_Dial(*this, "DIAL", nlconst::half()) , m_DialIsLog(*this, "DIALLOG", false) , m_Reverse(*this, "REVERSE", false) { @@ -208,8 +208,8 @@ namespace analog { NETLIB_CONSTRUCTOR(POT2) , m_R1(*this, "_R1") - , m_R(*this, "R", plib::constants::cast(10000.0)) - , m_Dial(*this, "DIAL", plib::constants::half()) + , m_R(*this, "R", nlconst::magic(10000.0)) + , m_Dial(*this, "DIAL", nlconst::half()) , m_DialIsLog(*this, "DIALLOG", false) , m_Reverse(*this, "REVERSE", false) { @@ -239,7 +239,7 @@ namespace analog { public: NETLIB_CONSTRUCTOR_DERIVED(C, twoterm) - , m_C(*this, "C", plib::constants::cast(1e-6)) + , m_C(*this, "C", nlconst::magic(1e-6)) , m_cap(*this, "m_cap") { } @@ -289,10 +289,10 @@ namespace analog { public: NETLIB_CONSTRUCTOR_DERIVED(L, twoterm) - , m_L(*this, "L", plib::constants::cast(1e-6)) - , m_gmin(plib::constants::zero()) - , m_G(plib::constants::zero()) - , m_I(plib::constants::zero()) + , m_L(*this, "L", nlconst::magic(1e-6)) + , m_gmin(nlconst::zero()) + , m_G(nlconst::zero()) + , m_I(nlconst::zero()) { //register_term("1", m_P); //register_term("2", m_N); @@ -392,12 +392,12 @@ namespace analog { public: NETLIB_CONSTRUCTOR_DERIVED(VS, twoterm) - , m_t(*this, "m_t", plib::constants::zero()) - , m_R(*this, "R", plib::constants::cast(0.1)) - , m_V(*this, "V", plib::constants::zero()) + , m_t(*this, "m_t", nlconst::zero()) + , m_R(*this, "R", nlconst::magic(0.1)) + , m_V(*this, "V", nlconst::zero()) , m_func(*this,"FUNC", "") , m_compiled(this->name() + ".FUNCC", this, this->state().run_state_manager()) - , m_funcparam({plib::constants::zero()}) + , m_funcparam({nlconst::zero()}) { register_subalias("P", m_P); register_subalias("N", m_N); @@ -413,7 +413,7 @@ namespace analog m_funcparam[0] = m_t; this->set_G_V_I(plib::reciprocal(m_R()), m_compiled.evaluate(m_funcparam), - plib::constants::zero()); + nlconst::zero()); } protected: @@ -422,7 +422,7 @@ namespace analog NETLIB_RESETI() { NETLIB_NAME(twoterm)::reset(); - this->set_G_V_I(plib::reciprocal(m_R()), m_V(), plib::constants::zero()); + this->set_G_V_I(plib::reciprocal(m_R()), m_V(), nlconst::zero()); } private: @@ -442,11 +442,11 @@ namespace analog { public: NETLIB_CONSTRUCTOR_DERIVED(CS, twoterm) - , m_t(*this, "m_t", plib::constants::zero()) - , m_I(*this, "I", plib::constants::one()) + , m_t(*this, "m_t", nlconst::zero()) + , m_I(*this, "I", nlconst::one()) , m_func(*this,"FUNC", "") , m_compiled(this->name() + ".FUNCC", this, this->state().run_state_manager()) - , m_funcparam({plib::constants::zero()}) + , m_funcparam({nlconst::zero()}) { register_subalias("P", m_P); register_subalias("N", m_N); @@ -460,7 +460,7 @@ namespace analog m_t += step; m_funcparam[0] = m_t; const nl_fptype I = m_compiled.evaluate(m_funcparam); - const auto zero(plib::constants::zero()); + const auto zero(nlconst::zero()); set_mat(zero, zero, -I, zero, zero, I); } @@ -471,7 +471,7 @@ namespace analog NETLIB_RESETI() { NETLIB_NAME(twoterm)::reset(); - const auto zero(plib::constants::zero()); + const auto zero(nlconst::zero()); set_mat(zero, zero, -m_I(), zero, zero, m_I()); } @@ -479,7 +479,7 @@ namespace analog NETLIB_UPDATE_PARAMI() { solve_now(); - const auto zero(plib::constants::zero()); + const auto zero(nlconst::zero()); set_mat(zero, zero, -m_I(), zero, zero, m_I()); } diff --git a/src/lib/netlist/devices/nld_4066.cpp b/src/lib/netlist/devices/nld_4066.cpp index ed14748975a..d067ce14cd4 100644 --- a/src/lib/netlist/devices/nld_4066.cpp +++ b/src/lib/netlist/devices/nld_4066.cpp @@ -22,7 +22,7 @@ namespace netlist , m_supply(*this, "VDD", "VSS", true) , m_R(*this, "R") , m_control(*this, "CTL") - , m_base_r(*this, "BASER", plib::constants::cast(270.0)) + , m_base_r(*this, "BASER", nlconst::magic(270.0)) { } @@ -41,28 +41,28 @@ namespace netlist { // Start in off condition // FIXME: is ROFF correct? - m_R.set_R(plib::constants::one() / exec().gmin()); + m_R.set_R(nlconst::one() / exec().gmin()); } NETLIB_UPDATE(CD4066_GATE) { nl_fptype sup = (m_supply.VCC() - m_supply.GND()); - nl_fptype low = plib::constants::cast(0.45) * sup; - nl_fptype high = plib::constants::cast(0.55) * sup; + nl_fptype low = nlconst::magic(0.45) * sup; + nl_fptype high = nlconst::magic(0.55) * sup; nl_fptype in = m_control() - m_supply.GND(); - nl_fptype rON = m_base_r() * plib::constants::cast(5.0) / sup; - nl_fptype R = -plib::constants::one(); + nl_fptype rON = m_base_r() * nlconst::magic(5.0) / sup; + nl_fptype R = -nlconst::one(); if (in < low) { - R = plib::constants::one() / exec().gmin(); + R = nlconst::one() / exec().gmin(); } else if (in > high) { R = rON; } - if (R > plib::constants::zero()) + if (R > nlconst::zero()) { m_R.update(); m_R.set_R(R); diff --git a/src/lib/netlist/devices/nld_4316.cpp b/src/lib/netlist/devices/nld_4316.cpp index 206dffc821d..367a29b331c 100644 --- a/src/lib/netlist/devices/nld_4316.cpp +++ b/src/lib/netlist/devices/nld_4316.cpp @@ -20,7 +20,7 @@ namespace netlist { namespace devices { , m_R(*this, "_R") , m_S(*this, "S") , m_E(*this, "E") - , m_base_r(*this, "BASER", plib::constants::cast(45.0)) + , m_base_r(*this, "BASER", nlconst::magic(45.0)) { } @@ -38,7 +38,7 @@ namespace netlist { namespace devices { NETLIB_RESET(CD4316_GATE) { - m_R.set_R(plib::constants::one() / exec().gmin()); + m_R.set_R(nlconst::one() / exec().gmin()); } NETLIB_UPDATE(CD4316_GATE) @@ -47,7 +47,7 @@ namespace netlist { namespace devices { if (m_S() && !m_E()) m_R.set_R(m_base_r()); else - m_R.set_R(plib::constants::one() / exec().gmin()); + m_R.set_R(nlconst::one() / exec().gmin()); m_R.solve_later(NLTIME_FROM_NS(1)); } diff --git a/src/lib/netlist/devices/nld_74123.cpp b/src/lib/netlist/devices/nld_74123.cpp index a7d654a83d2..e601a792a8c 100644 --- a/src/lib/netlist/devices/nld_74123.cpp +++ b/src/lib/netlist/devices/nld_74123.cpp @@ -31,8 +31,8 @@ namespace netlist , m_last_trig(*this, "m_last_trig", 0) , m_state(*this, "m_state", 0) , m_KP(*this, "m_KP", 0) - , m_K(*this, "K", plib::constants::cast((m_dev_type == 4538) ? 1.0 : 0.4)) // CD4538 datasheet states PW=RC - , m_RI(*this, "RI", plib::constants::cast(400.0)) // around 250 for HC series, 400 on LS/TTL, estimated from datasheets + , m_K(*this, "K", nlconst::magic((m_dev_type == 4538) ? 1.0 : 0.4)) // CD4538 datasheet states PW=RC + , m_RI(*this, "RI", nlconst::magic(400.0)) // around 250 for HC series, 400 on LS/TTL, estimated from datasheets { if ((m_dev_type != 9602) && (m_dev_type != 4538) ) m_dev_type = 74123; @@ -241,7 +241,7 @@ namespace netlist } if (m_state == 2) { - const nl_fptype vHigh = m_RP.m_R.m_P() * (plib::constants::one() - m_KP); + const nl_fptype vHigh = m_RP.m_R.m_P() * (nlconst::one() - m_KP); if (m_CV() > vHigh) { m_RP_Q.push(0, NLTIME_FROM_NS(10)); // R_OFF @@ -255,7 +255,7 @@ namespace netlist NETLIB_RESET(74123) { - m_KP = plib::reciprocal(plib::constants::one() + std::exp(m_K())); + m_KP = plib::reciprocal(nlconst::one() + std::exp(m_K())); m_RP.reset(); m_RN.reset(); diff --git a/src/lib/netlist/devices/nld_74ls629.cpp b/src/lib/netlist/devices/nld_74ls629.cpp index f95da603e7e..d3e30395b64 100644 --- a/src/lib/netlist/devices/nld_74ls629.cpp +++ b/src/lib/netlist/devices/nld_74ls629.cpp @@ -85,7 +85,7 @@ namespace netlist , m_ENQ(*this, "ENQ") , m_RNG(*this, "RNG") , m_FC(*this, "FC") - , m_CAP(*this, "CAP", plib::constants::cast(1e-6)) + , m_CAP(*this, "CAP", nlconst::magic(1e-6)) { register_subalias("GND", m_R_FC.m_N); @@ -98,8 +98,8 @@ namespace netlist NETLIB_RESETI() { - m_R_FC.set_R( plib::constants::cast(90000.0)); - m_R_RNG.set_R(plib::constants::cast(90000.0)); + m_R_FC.set_R( nlconst::magic(90000.0)); + m_R_RNG.set_R(nlconst::magic(90000.0)); m_clock.reset(); } NETLIB_UPDATEI(); @@ -179,16 +179,16 @@ namespace netlist nl_fptype v_rng = m_RNG(); /* coefficients */ - const nl_fptype k1 = plib::constants::cast( 1.9904769024796283E+03); - const nl_fptype k2 = plib::constants::cast( 1.2070059213983407E+03); - const nl_fptype k3 = plib::constants::cast( 1.3266985579561108E+03); - const nl_fptype k4 = plib::constants::cast(-1.5500979825922698E+02); - const nl_fptype k5 = plib::constants::cast( 2.8184536266938172E+00); - const nl_fptype k6 = plib::constants::cast(-2.3503421582744556E+02); - const nl_fptype k7 = plib::constants::cast(-3.3836786704527788E+02); - const nl_fptype k8 = plib::constants::cast(-1.3569136703258670E+02); - const nl_fptype k9 = plib::constants::cast( 2.9914575453819188E+00); - const nl_fptype k10 = plib::constants::cast( 1.6855569086173170E+00); + const nl_fptype k1 = nlconst::magic( 1.9904769024796283E+03); + const nl_fptype k2 = nlconst::magic( 1.2070059213983407E+03); + const nl_fptype k3 = nlconst::magic( 1.3266985579561108E+03); + const nl_fptype k4 = nlconst::magic(-1.5500979825922698E+02); + const nl_fptype k5 = nlconst::magic( 2.8184536266938172E+00); + const nl_fptype k6 = nlconst::magic(-2.3503421582744556E+02); + const nl_fptype k7 = nlconst::magic(-3.3836786704527788E+02); + const nl_fptype k8 = nlconst::magic(-1.3569136703258670E+02); + const nl_fptype k9 = nlconst::magic( 2.9914575453819188E+00); + const nl_fptype k10 = nlconst::magic( 1.6855569086173170E+00); /* scale due to input resistance */ @@ -208,11 +208,11 @@ namespace netlist freq += k9 * v_rng * v_freq_3; freq += k10 * v_rng * v_freq_4; - freq *= plib::constants::cast(0.1e-6) / m_CAP(); + freq *= nlconst::magic(0.1e-6) / m_CAP(); // FIXME: we need a possibility to remove entries from queue ... // or an exact model ... - m_clock.m_inc = netlist_time::from_fp(plib::constants::half() / freq); + m_clock.m_inc = netlist_time::from_fp(nlconst::half() / freq); //m_clock.update(); //NL_VERBOSE_OUT(("{1} {2} {3} {4}\n", name(), v_freq, v_rng, freq)); diff --git a/src/lib/netlist/devices/nld_mm5837.cpp b/src/lib/netlist/devices/nld_mm5837.cpp index 21b7e7d17ab..acd009497f6 100644 --- a/src/lib/netlist/devices/nld_mm5837.cpp +++ b/src/lib/netlist/devices/nld_mm5837.cpp @@ -69,11 +69,11 @@ namespace netlist { //m_V0.initial(0.0); //m_RV.do_reset(); - m_RV.set_G_V_I(plib::constants::one() / plib::constants::cast(R_LOW), - plib::constants::zero(), - plib::constants::zero()); + m_RV.set_G_V_I(nlconst::one() / nlconst::magic(R_LOW), + nlconst::zero(), + nlconst::zero()); m_inc = netlist_time::from_fp(plib::reciprocal(m_FREQ())); - if (m_FREQ() < plib::constants::cast(24000) || m_FREQ() > plib::constants::cast(56000)) + if (m_FREQ() < nlconst::magic(24000) || m_FREQ() > nlconst::magic(56000)) log().warning(MW_FREQUENCY_OUTSIDE_OF_SPECS_1(m_FREQ())); m_shift = 0x1ffff; @@ -83,7 +83,7 @@ namespace netlist NETLIB_UPDATE_PARAM(MM5837_dip) { m_inc = netlist_time::from_fp(plib::reciprocal(m_FREQ())); - if (m_FREQ() < plib::constants::cast(24000) || m_FREQ() > plib::constants::cast(56000)) + if (m_FREQ() < nlconst::magic(24000) || m_FREQ() > nlconst::magic(56000)) log().warning(MW_FREQUENCY_OUTSIDE_OF_SPECS_1(m_FREQ())); } @@ -104,13 +104,13 @@ namespace netlist if (state != last_state) { - const nl_fptype R = plib::constants::cast(state ? R_HIGH : R_LOW); + const nl_fptype R = nlconst::magic(state ? R_HIGH : R_LOW); const nl_fptype V = state ? m_VDD() : m_VSS(); // We only need to update the net first if this is a time stepping net if (m_is_timestep) m_RV.update(); - m_RV.set_G_V_I(plib::constants::one() / R, V, plib::constants::zero()); + m_RV.set_G_V_I(nlconst::one() / R, V, nlconst::zero()); m_RV.solve_later(NLTIME_FROM_NS(1)); } diff --git a/src/lib/netlist/devices/nld_ne555.cpp b/src/lib/netlist/devices/nld_ne555.cpp index 5c28f8313c0..6a6834df5d5 100644 --- a/src/lib/netlist/devices/nld_ne555.cpp +++ b/src/lib/netlist/devices/nld_ne555.cpp @@ -140,11 +140,11 @@ namespace netlist m_RDIS.reset(); /* FIXME make resistances a parameter, properly model other variants */ - m_R1.set_R(plib::constants::cast(5000)); - m_R2.set_R(plib::constants::cast(5000)); - m_R3.set_R(plib::constants::cast(5000)); - m_ROUT.set_R(plib::constants::cast(20)); - m_RDIS.set_R(plib::constants::cast(R_OFF)); + m_R1.set_R(nlconst::magic(5000)); + m_R2.set_R(nlconst::magic(5000)); + m_R3.set_R(nlconst::magic(5000)); + m_ROUT.set_R(nlconst::magic(20)); + m_RDIS.set_R(nlconst::magic(R_OFF)); m_last_out = true; } @@ -161,9 +161,9 @@ namespace netlist } else { - const nl_fptype vt = clamp(m_R2.m_P(), plib::constants::cast(0.7), plib::constants::cast(1.4)); + const nl_fptype vt = clamp(m_R2.m_P(), nlconst::magic(0.7), nlconst::magic(1.4)); const bool bthresh = (m_THRES() > vt); - const bool btrig = (m_TRIG() > clamp(m_R2.m_N(), plib::constants::cast(0.7), plib::constants::cast(1.4))); + const bool btrig = (m_TRIG() > clamp(m_R2.m_N(), nlconst::magic(0.7), nlconst::magic(1.4))); if (!btrig) m_ff = true; @@ -177,14 +177,14 @@ namespace netlist { m_RDIS.update(); m_OUT.push(m_R3.m_N()); - m_RDIS.set_R(plib::constants::cast(R_ON)); + m_RDIS.set_R(nlconst::magic(R_ON)); } else if (!m_last_out && out) { m_RDIS.update(); // FIXME: Should be delayed by 100ns m_OUT.push(m_R1.m_P()); - m_RDIS.set_R(plib::constants::cast(R_OFF)); + m_RDIS.set_R(nlconst::magic(R_OFF)); } m_last_reset = reset; m_last_out = out; diff --git a/src/lib/netlist/devices/nld_r2r_dac.cpp b/src/lib/netlist/devices/nld_r2r_dac.cpp index 6d83d755791..8f2c62d2185 100644 --- a/src/lib/netlist/devices/nld_r2r_dac.cpp +++ b/src/lib/netlist/devices/nld_r2r_dac.cpp @@ -16,8 +16,8 @@ namespace netlist NETLIB_OBJECT_DERIVED(r2r_dac, twoterm) { NETLIB_CONSTRUCTOR_DERIVED(r2r_dac, twoterm) - , m_VIN(*this, "VIN", plib::constants::one()) - , m_R(*this, "R", plib::constants::one()) + , m_VIN(*this, "VIN", nlconst::one()) + , m_R(*this, "R", nlconst::one()) , m_num(*this, "N", 1) , m_val(*this, "VAL", 1) { @@ -44,7 +44,7 @@ namespace netlist nl_fptype V = m_VIN() / static_cast(1 << m_num()) * static_cast(m_val()); - this->set_G_V_I(plib::reciprocal(m_R()), V, plib::constants::zero()); + this->set_G_V_I(plib::reciprocal(m_R()), V, nlconst::zero()); } } //namespace analog diff --git a/src/lib/netlist/devices/nld_schmitt.cpp b/src/lib/netlist/devices/nld_schmitt.cpp index fafeaa9f2a8..29dbf8cf6b0 100644 --- a/src/lib/netlist/devices/nld_schmitt.cpp +++ b/src/lib/netlist/devices/nld_schmitt.cpp @@ -85,8 +85,8 @@ namespace netlist m_RVI.reset(); m_RVO.reset(); m_is_timestep = m_RVO.m_P.net().solver()->has_timestep_devices(); - m_RVI.set_G_V_I(plib::constants::one() / m_model.m_RI, m_model.m_VI, plib::constants::zero()); - m_RVO.set_G_V_I(plib::constants::one() / m_model.m_ROL, m_model.m_VOL, plib::constants::zero()); + m_RVI.set_G_V_I(nlconst::one() / m_model.m_RI, m_model.m_VI, nlconst::zero()); + m_RVO.set_G_V_I(nlconst::one() / m_model.m_ROL, m_model.m_VOL, nlconst::zero()); } NETLIB_UPDATEI() @@ -98,7 +98,7 @@ namespace netlist m_last_state = 0; if (m_is_timestep) m_RVO.update(); - m_RVO.set_G_V_I(plib::constants::one() / m_model.m_ROH, m_model.m_VOH, plib::constants::zero()); + m_RVO.set_G_V_I(nlconst::one() / m_model.m_ROH, m_model.m_VOH, nlconst::zero()); m_RVO.solve_later(); } } @@ -109,7 +109,7 @@ namespace netlist m_last_state = 1; if (m_is_timestep) m_RVO.update(); - m_RVO.set_G_V_I(plib::constants::one() / m_model.m_ROL, m_model.m_VOL, plib::constants::zero()); + m_RVO.set_G_V_I(nlconst::one() / m_model.m_ROL, m_model.m_VOL, nlconst::zero()); m_RVO.solve_later(); } } diff --git a/src/lib/netlist/devices/nlid_proxy.cpp b/src/lib/netlist/devices/nlid_proxy.cpp index 9f5be46a6cd..0e677de1f39 100644 --- a/src/lib/netlist/devices/nlid_proxy.cpp +++ b/src/lib/netlist/devices/nlid_proxy.cpp @@ -52,11 +52,11 @@ namespace netlist nl_assert(m_logic_family != nullptr); // FIXME: Variable supply voltage! nl_fptype supply_V = logic_family()->fixed_V(); - if (supply_V == plib::constants::zero()) supply_V = plib::constants::cast(5.0); + if (supply_V == nlconst::zero()) supply_V = nlconst::magic(5.0); - if (m_I.Q_Analog() > logic_family()->high_thresh_V(plib::constants::zero(), supply_V)) + if (m_I.Q_Analog() > logic_family()->high_thresh_V(nlconst::zero(), supply_V)) out().push(1, netlist_time::quantum()); - else if (m_I.Q_Analog() < logic_family()->low_thresh_V(plib::constants::zero(), supply_V)) + else if (m_I.Q_Analog() < logic_family()->low_thresh_V(nlconst::zero(), supply_V)) out().push(0, netlist_time::quantum()); else { @@ -112,7 +112,7 @@ namespace netlist //FIXME: Use power terminals and change info to warning or error if (!f) { - if (logic_family()->fixed_V() == plib::constants::zero()) + if (logic_family()->fixed_V() == nlconst::zero()) log().error(MI_NO_POWER_TERMINALS_ON_DEVICE_1(state().setup().de_alias(out_proxied->device().name()))); else log().info(MI_NO_POWER_TERMINALS_ON_DEVICE_1(state().setup().de_alias(out_proxied->device().name()))); @@ -149,8 +149,8 @@ namespace netlist // FIXME: Variable voltage nl_fptype supply_V = logic_family()->fixed_V(); // FIXME: comparison to zero - if (supply_V == plib::constants::zero()) - supply_V = plib::constants::cast(5.0); + if (supply_V == nlconst::zero()) + supply_V = nlconst::magic(5.0); //m_Q.initial(0.0); m_last_state = -1; @@ -161,11 +161,11 @@ namespace netlist if (m_VCCHack) m_VCCHack->initial(supply_V); m_is_timestep = m_RN.m_P.net().solver()->has_timestep_devices(); - m_RN.set_G_V_I(plib::constants::one() / logic_family()->R_low(), - logic_family()->low_offset_V(), plib::constants::zero()); + m_RN.set_G_V_I(nlconst::one() / logic_family()->R_low(), + logic_family()->low_offset_V(), nlconst::zero()); m_RP.set_G_V_I(G_OFF, - plib::constants::zero(), - plib::constants::zero()); + nlconst::zero(), + nlconst::zero()); } NETLIB_UPDATE(d_to_a_proxy) @@ -181,18 +181,18 @@ namespace netlist if (state) { m_RN.set_G_V_I(G_OFF, - plib::constants::zero(), - plib::constants::zero()); - m_RP.set_G_V_I(plib::constants::one() / logic_family()->R_high(), - logic_family()->high_offset_V(), plib::constants::zero()); + nlconst::zero(), + nlconst::zero()); + m_RP.set_G_V_I(nlconst::one() / logic_family()->R_high(), + logic_family()->high_offset_V(), nlconst::zero()); } else { - m_RN.set_G_V_I(plib::constants::one() / logic_family()->R_low(), - logic_family()->low_offset_V(), plib::constants::zero()); + m_RN.set_G_V_I(nlconst::one() / logic_family()->R_low(), + logic_family()->low_offset_V(), nlconst::zero()); m_RP.set_G_V_I(G_OFF, - plib::constants::zero(), - plib::constants::zero()); + nlconst::zero(), + nlconst::zero()); } m_RN.solve_later(); // RN, RP are connected ... m_last_state = state; diff --git a/src/lib/netlist/devices/nlid_proxy.h b/src/lib/netlist/devices/nlid_proxy.h index 30043580306..0badfd92006 100644 --- a/src/lib/netlist/devices/nlid_proxy.h +++ b/src/lib/netlist/devices/nlid_proxy.h @@ -104,7 +104,7 @@ namespace netlist private: - static constexpr const nl_fptype G_OFF = plib::constants::cast(1e-9); + static constexpr const nl_fptype G_OFF = nlconst::magic(1e-9); plib::unique_ptr m_GNDHack; // FIXME: Long term, we need to connect proxy gnd to device gnd plib::unique_ptr m_VCCHack; // FIXME: Long term, we need to connect proxy gnd to device gnd diff --git a/src/lib/netlist/devices/nlid_system.h b/src/lib/netlist/devices/nlid_system.h index c92c18b56e3..b69d7ee75c2 100644 --- a/src/lib/netlist/devices/nlid_system.h +++ b/src/lib/netlist/devices/nlid_system.h @@ -52,9 +52,9 @@ namespace devices { NETLIB_CONSTRUCTOR(mainclock) , m_Q(*this, "Q") - , m_freq(*this, "FREQ", plib::constants::cast(7159000.0 * 5)) + , m_freq(*this, "FREQ", nlconst::magic(7159000.0 * 5)) { - m_inc = netlist_time::from_fp(plib::reciprocal(m_freq()*plib::constants::two())); + m_inc = netlist_time::from_fp(plib::reciprocal(m_freq()*nlconst::two())); } NETLIB_RESETI() @@ -64,7 +64,7 @@ namespace devices NETLIB_UPDATE_PARAMI() { - m_inc = netlist_time::from_fp(plib::reciprocal(m_freq()*plib::constants::two())); + m_inc = netlist_time::from_fp(plib::reciprocal(m_freq()*nlconst::two())); } NETLIB_UPDATEI() @@ -91,9 +91,9 @@ namespace devices NETLIB_CONSTRUCTOR(clock) , m_feedback(*this, "FB") , m_Q(*this, "Q") - , m_freq(*this, "FREQ", plib::constants::cast(7159000.0 * 5.0)) + , m_freq(*this, "FREQ", nlconst::magic(7159000.0 * 5.0)) { - m_inc = netlist_time::from_fp(plib::reciprocal(m_freq()*plib::constants::two())); + m_inc = netlist_time::from_fp(plib::reciprocal(m_freq()*nlconst::two())); connect(m_feedback, m_Q); } @@ -101,7 +101,7 @@ namespace devices NETLIB_UPDATE_PARAMI() { - m_inc = netlist_time::from_fp(plib::reciprocal(m_freq()*plib::constants::two())); + m_inc = netlist_time::from_fp(plib::reciprocal(m_freq()*nlconst::two())); } NETLIB_UPDATEI() @@ -128,7 +128,7 @@ namespace devices , m_Q(*this, "Q") , m_func(*this,"FUNC", "") , m_compiled(this->name() + ".FUNCC", this, this->state().run_state_manager()) - , m_funcparam({plib::constants::zero()}) + , m_funcparam({nlconst::zero()}) { if (m_func() != "") m_compiled.compile(std::vector({{pstring("T")}}), m_func()); @@ -160,19 +160,19 @@ namespace devices NETLIB_OBJECT(extclock) { NETLIB_CONSTRUCTOR(extclock) - , m_freq(*this, "FREQ", plib::constants::cast(7159000.0 * 5.0)) + , m_freq(*this, "FREQ", nlconst::magic(7159000.0 * 5.0)) , m_pattern(*this, "PATTERN", "1,1") - , m_offset(*this, "OFFSET", plib::constants::zero()) + , m_offset(*this, "OFFSET", nlconst::zero()) , m_feedback(*this, "FB") , m_Q(*this, "Q") , m_cnt(*this, "m_cnt", 0) , m_off(*this, "m_off", netlist_time::zero()) { - m_inc[0] = netlist_time::from_fp(plib::reciprocal(m_freq()*plib::constants::two())); + m_inc[0] = netlist_time::from_fp(plib::reciprocal(m_freq()*nlconst::two())); connect(m_feedback, m_Q); - netlist_time base = netlist_time::from_fp(plib::reciprocal(m_freq()*plib::constants::two())); + netlist_time base = netlist_time::from_fp(plib::reciprocal(m_freq()*nlconst::two())); std::vector pat(plib::psplit(m_pattern(),",")); m_off = netlist_time::from_fp(m_offset()); @@ -250,12 +250,12 @@ namespace devices { NETLIB_CONSTRUCTOR(analog_input) , m_Q(*this, "Q") - , m_IN(*this, "IN", plib::constants::zero()) + , m_IN(*this, "IN", nlconst::zero()) { } NETLIB_UPDATEI() { } - NETLIB_RESETI() { m_Q.initial(plib::constants::zero()); } + NETLIB_RESETI() { m_Q.initial(nlconst::zero()); } NETLIB_UPDATE_PARAMI() { m_Q.push(m_IN()); } private: @@ -275,7 +275,7 @@ namespace devices } NETLIB_UPDATEI() { - m_Q.push(plib::constants::zero()); + m_Q.push(nlconst::zero()); } NETLIB_RESETI() { } protected: @@ -316,8 +316,8 @@ namespace devices , m_ROUT(*this, "m_ROUT", true) , m_I(*this, "_I") , m_Q(*this, "_Q") - , m_p_RIN(*this, "RIN", plib::constants::cast(1.0e6)) - , m_p_ROUT(*this, "ROUT", plib::constants::cast(50.0)) + , m_p_RIN(*this, "RIN", nlconst::magic(1.0e6)) + , m_p_ROUT(*this, "ROUT", nlconst::magic(50.0)) { register_subalias("I", m_RIN.m_P); @@ -371,7 +371,7 @@ namespace devices pstring n = plib::pfmt("A{1}")(i); m_I.push_back(pool().make_unique(*this, n)); inps.push_back(n); - m_vals.push_back(plib::constants::zero()); + m_vals.push_back(nlconst::zero()); } m_compiled.compile(inps, m_func()); } @@ -402,8 +402,8 @@ namespace devices NETLIB_CONSTRUCTOR(res_sw) , m_R(*this, "_R") , m_I(*this, "I") - , m_RON(*this, "RON", plib::constants::one()) - , m_ROFF(*this, "ROFF", plib::constants::cast(1.0E20)) + , m_RON(*this, "RON", nlconst::one()) + , m_ROFF(*this, "ROFF", nlconst::magic(1.0E20)) , m_last_state(*this, "m_last_state", 0) { register_subalias("1", m_R.m_P); diff --git a/src/lib/netlist/nl_base.cpp b/src/lib/netlist/nl_base.cpp index 02a341f5b7f..7206efca2f3 100644 --- a/src/lib/netlist/nl_base.cpp +++ b/src/lib/netlist/nl_base.cpp @@ -40,14 +40,14 @@ namespace netlist public: logic_family_ttl_t() : logic_family_desc_t() { - m_fixed_V = plib::constants::cast(5.0); - m_low_thresh_PCNT = plib::constants::cast(0.8 / 5.0); - m_high_thresh_PCNT = plib::constants::cast(2.0 / 5.0); + m_fixed_V = nlconst::magic(5.0); + m_low_thresh_PCNT = nlconst::magic(0.8 / 5.0); + m_high_thresh_PCNT = nlconst::magic(2.0 / 5.0); // m_low_V - these depend on sinked/sourced current. Values should be suitable for typical applications. - m_low_VO = plib::constants::cast(0.1); - m_high_VO = plib::constants::cast(1.0); // 4.0 - m_R_low = plib::constants::cast(1.0); - m_R_high = plib::constants::cast(130.0); + m_low_VO = nlconst::magic(0.1); + m_high_VO = nlconst::magic(1.0); // 4.0 + m_R_low = nlconst::magic(1.0); + m_R_high = nlconst::magic(130.0); } unique_pool_ptr create_d_a_proxy(netlist_state_t &anetlist, const pstring &name, logic_output_t *proxied) const override; unique_pool_ptr create_a_d_proxy(netlist_state_t &anetlist, const pstring &name, logic_input_t *proxied) const override; @@ -67,14 +67,14 @@ namespace netlist public: logic_family_cd4xxx_t() : logic_family_desc_t() { - m_fixed_V = plib::constants::cast(0.0); - m_low_thresh_PCNT = plib::constants::cast(1.5 / 5.0); - m_high_thresh_PCNT = plib::constants::cast(3.5 / 5.0); + m_fixed_V = nlconst::magic(0.0); + m_low_thresh_PCNT = nlconst::magic(1.5 / 5.0); + m_high_thresh_PCNT = nlconst::magic(3.5 / 5.0); // m_low_V - these depend on sinked/sourced current. Values should be suitable for typical applications. - m_low_VO = plib::constants::cast(0.05); - m_high_VO = plib::constants::cast(0.05); // 4.95 - m_R_low = plib::constants::cast(10.0); - m_R_high = plib::constants::cast(10.0); + m_low_VO = nlconst::magic(0.05); + m_high_VO = nlconst::magic(0.05); // 4.95 + m_R_low = nlconst::magic(10.0); + m_R_high = nlconst::magic(10.0); } unique_pool_ptr create_d_a_proxy(netlist_state_t &anetlist, const pstring &name, logic_output_t *proxied) const override; unique_pool_ptr create_a_d_proxy(netlist_state_t &anetlist, const pstring &name, logic_input_t *proxied) const override; @@ -669,7 +669,7 @@ namespace netlist auto *p = dynamic_cast(this); if (p != nullptr) - p->m_cur_Analog = plib::constants::zero(); + p->m_cur_Analog = nlconst::zero(); /* rebuild m_list and reset terminals to active or analog out state */ @@ -727,7 +727,7 @@ namespace netlist analog_net_t::analog_net_t(netlist_state_t &nl, const pstring &aname, detail::core_terminal_t *mr) : net_t(nl, aname, mr) - , m_cur_Analog(*this, "m_cur_Analog", plib::constants::zero()) + , m_cur_Analog(*this, "m_cur_Analog", nlconst::zero()) , m_solver(nullptr) { } diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index c1d42f22cb9..907c3f76829 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -764,12 +764,12 @@ namespace netlist void set_conductivity(const nl_fptype G) noexcept { - set_go_gt_I(-G, G, plib::constants::zero()); + set_go_gt_I(-G, G, nlconst::zero()); } void set_go_gt(const nl_fptype GO, const nl_fptype GT) noexcept { - set_go_gt_I(GO, GT, plib::constants::zero()); + set_go_gt_I(GO, GT, nlconst::zero()); } void set_go_gt_I(const nl_fptype GO, const nl_fptype GT, const nl_fptype I) noexcept diff --git a/src/lib/netlist/nl_config.h b/src/lib/netlist/nl_config.h index a0cbb687fec..8d1cfa898f5 100644 --- a/src/lib/netlist/nl_config.h +++ b/src/lib/netlist/nl_config.h @@ -104,7 +104,7 @@ static constexpr const auto NETLIST_CLOCK = NETLIST_INTERNAL_RES; // due to numeric issues //============================================================ -using nl_fptype = double; +using nl_fptype = float; namespace netlist { diff --git a/src/lib/netlist/nl_parser.cpp b/src/lib/netlist/nl_parser.cpp index 44c2a02ca0d..786365359b5 100644 --- a/src/lib/netlist/nl_parser.cpp +++ b/src/lib/netlist/nl_parser.cpp @@ -414,13 +414,13 @@ nl_fptype parser_t::eval_param(const token_t &tok) { static std::array macs = {"", "RES_R", "RES_K", "RES_M", "CAP_U", "CAP_N", "CAP_P"}; static std::array facs = { - plib::constants::cast(1.0), - plib::constants::cast(1.0), - plib::constants::cast(1e3), - plib::constants::cast(1e6), - plib::constants::cast(1e-6), - plib::constants::cast(1e-9), - plib::constants::cast(1e-12) + nlconst::magic(1.0), + nlconst::magic(1.0), + nlconst::magic(1e3), + nlconst::magic(1e6), + nlconst::magic(1e-6), + nlconst::magic(1e-9), + nlconst::magic(1e-12) }; std::size_t f=0; nl_fptype ret(0); diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index e6008595e3f..5c8936a9bca 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -121,8 +121,8 @@ namespace netlist void nlparse_t::register_param_x(const pstring ¶m, const nl_fptype value) { - if (std::abs(value - std::floor(value)) > plib::constants::cast(1e-30) - || std::abs(value) > plib::constants::cast(1e9)) + if (std::abs(value - std::floor(value)) > nlconst::magic(1e-30) + || std::abs(value) > nlconst::magic(1e9)) register_param(param, plib::pfmt("{1:.9}").e(value)); else register_param(param, plib::pfmt("{1}")(static_cast(value))); @@ -942,24 +942,24 @@ nl_fptype models_t::value(const pstring &model, const pstring &entity) pstring tmp = value_str(model, entity); - nl_fptype factor = plib::constants::one(); + nl_fptype factor = nlconst::one(); auto p = std::next(tmp.begin(), static_cast(tmp.size() - 1)); switch (*p) { - case 'M': factor = plib::constants::cast(1e6); break; + case 'M': factor = nlconst::magic(1e6); break; case 'k': - case 'K': factor = plib::constants::cast(1e3); break; - case 'm': factor = plib::constants::cast(1e-3); break; - case 'u': factor = plib::constants::cast(1e-6); break; - case 'n': factor = plib::constants::cast(1e-9); break; - case 'p': factor = plib::constants::cast(1e-12); break; - case 'f': factor = plib::constants::cast(1e-15); break; - case 'a': factor = plib::constants::cast(1e-18); break; + case 'K': factor = nlconst::magic(1e3); break; + case 'm': factor = nlconst::magic(1e-3); break; + case 'u': factor = nlconst::magic(1e-6); break; + case 'n': factor = nlconst::magic(1e-9); break; + case 'p': factor = nlconst::magic(1e-12); break; + case 'f': factor = nlconst::magic(1e-15); break; + case 'a': factor = nlconst::magic(1e-18); break; default: if (*p < '0' || *p > '9') throw nl_exception(MF_UNKNOWN_NUMBER_FACTOR_IN_1(entity)); } - if (factor != plib::constants::one()) + if (factor != nlconst::one()) tmp = plib::left(tmp, tmp.size() - 1); // FIXME: check for errors //printf("%s %s %e %e\n", entity.c_str(), tmp.c_str(), plib::pstonum(tmp), factor); @@ -1126,10 +1126,10 @@ void setup_t::prepare_to_run() //FIXME: check for errors ... bool err(false); auto v = plib::pstonum_ne(p->second, err); - if (err || std::abs(v - std::floor(v)) > plib::constants::cast(1e-6) ) + if (err || std::abs(v - std::floor(v)) > nlconst::magic(1e-6) ) log().fatal(MF_HND_VAL_NOT_SUPPORTED(p->second)); // FIXME comparison with zero - d.second->set_hint_deactivate(v == plib::constants::zero()); + d.second->set_hint_deactivate(v == nlconst::zero()); } } else diff --git a/src/lib/netlist/nltypes.h b/src/lib/netlist/nltypes.h index fe51be8c17d..236b6dc1519 100644 --- a/src/lib/netlist/nltypes.h +++ b/src/lib/netlist/nltypes.h @@ -29,10 +29,10 @@ namespace netlist { /*! @brief plib::constants struct specialized for nl_fptype * - * This may be any of bool, uint8_t, uint16_t, uin32_t and uint64_t. - * The choice has little to no impact on performance. */ - using constants = plib::constants; + struct nlconst : public plib::constants + { + }; /*! @brief netlist_sig_t is the type used for logic signals. * diff --git a/src/lib/netlist/plib/pfmtlog.h b/src/lib/netlist/plib/pfmtlog.h index 17ca3f1d7ad..53ed539078e 100644 --- a/src/lib/netlist/plib/pfmtlog.h +++ b/src/lib/netlist/plib/pfmtlog.h @@ -197,7 +197,6 @@ public: return *this; } - template pfmt &operator()(X&& x, Y && y, Args&&... args) { diff --git a/src/lib/netlist/plib/putil.h b/src/lib/netlist/plib/putil.h index 1fa3971f8a6..e72eccfe01f 100644 --- a/src/lib/netlist/plib/putil.h +++ b/src/lib/netlist/plib/putil.h @@ -257,9 +257,15 @@ namespace plib * \brief Intrinsic carrier concentration in 1/m^3 of Silicon */ static inline constexpr T NiSi() noexcept { return static_cast(1.45e16); } - + /*! + * \brief clearly identify magic numbers in code + * + * Magic numbers should be avoided. The magic member at least clearly + * identifies them and makes it easier to convert them to named constants + * later. + */ template - static inline constexpr const T cast(V &&v) noexcept { return static_cast(v); } + static inline constexpr const T magic(V &&v) noexcept { return static_cast(v); } }; /*! typesafe reciprocal function diff --git a/src/lib/netlist/prg/nltool.cpp b/src/lib/netlist/prg/nltool.cpp index ffadd002cda..d1d9ceb89e0 100644 --- a/src/lib/netlist/prg/nltool.cpp +++ b/src/lib/netlist/prg/nltool.cpp @@ -311,7 +311,7 @@ void netlist_tool_callbacks_t::vlog(const plib::plog_level &l, const pstring &ls struct input_t { input_t(const netlist::setup_t &setup, const pstring &line) - : m_value(plib::constants::zero()) + : m_value(netlist::nlconst::zero()) { std::array buf; // NOLINT(cppcoreguidelines-pro-type-member-init) double t(0); @@ -465,7 +465,7 @@ void tool_app_t::run() auto emutime(t.as_seconds()); pout("{1:f} seconds emulation took {2:f} real time ==> {3:5.2f}%\n", (ttr - nlt).as_fp(), emutime, - (ttr - nlt).as_fp() / emutime * plib::constants::cast(100.0)); + (ttr - nlt).as_fp() / emutime * netlist::nlconst::magic(100.0)); } void tool_app_t::validate() diff --git a/src/lib/netlist/solver/nld_matrix_solver.cpp b/src/lib/netlist/solver/nld_matrix_solver.cpp index d7b77baf1b9..e33421d08b8 100644 --- a/src/lib/netlist/solver/nld_matrix_solver.cpp +++ b/src/lib/netlist/solver/nld_matrix_solver.cpp @@ -501,7 +501,7 @@ namespace solver std::vector touched(1024, false); // FIXME! - nl_fptype weight = plib::constants::zero(); + nl_fptype weight = nlconst::zero(); auto &term = m_terms[row]; for (std::size_t i = 0; i < term.count(); i++) { @@ -560,7 +560,7 @@ namespace solver this->m_stat_calculations, static_cast(this->m_stat_calculations) / this->exec().time().as_fp(), this->m_iterative_fail, - plib::constants::cast(100.0) * static_cast(this->m_iterative_fail) + nlconst::magic(100.0) * static_cast(this->m_iterative_fail) / static_cast(this->m_stat_calculations), static_cast(this->m_iterative_total) / static_cast(this->m_stat_calculations)); } diff --git a/src/lib/netlist/solver/nld_matrix_solver.h b/src/lib/netlist/solver/nld_matrix_solver.h index 3a9c8386f69..09e650be1a3 100644 --- a/src/lib/netlist/solver/nld_matrix_solver.h +++ b/src/lib/netlist/solver/nld_matrix_solver.h @@ -49,20 +49,20 @@ namespace solver struct solver_parameters_t { solver_parameters_t(device_t &parent) - : m_freq(parent, "FREQ", plib::constants::cast(48000.0)) + : m_freq(parent, "FREQ", nlconst::magic(48000.0)) /* iteration parameters */ - , m_gs_sor(parent, "SOR_FACTOR", plib::constants::cast(1.059)) + , m_gs_sor(parent, "SOR_FACTOR", nlconst::magic(1.059)) , m_method(parent, "METHOD", matrix_type_e::MAT_CR) , m_fp_type(parent, "FPTYPE", matrix_fp_type_e::DOUBLE) - , m_reltol(parent, "RELTOL", plib::constants::cast(1e-3)) ///< SPICE RELTOL parameter - , m_vntol(parent, "VNTOL", plib::constants::cast(1e-6)) ///< SPICE VNTOL parameter - , m_accuracy(parent, "ACCURACY", plib::constants::cast(1e-7)) ///< Iterative solver accuracy + , m_reltol(parent, "RELTOL", nlconst::magic(1e-3)) ///< SPICE RELTOL parameter + , m_vntol(parent, "VNTOL", nlconst::magic(1e-6)) ///< SPICE VNTOL parameter + , m_accuracy(parent, "ACCURACY", nlconst::magic(1e-7)) ///< Iterative solver accuracy , m_nr_loops(parent, "NR_LOOPS", 250) ///< Maximum number of Newton-Raphson loops , m_gs_loops(parent, "GS_LOOPS", 9) ///< Maximum number of Gauss-Seidel loops /* general parameters */ - , m_gmin(parent, "GMIN", plib::constants::cast(1e-9)) + , m_gmin(parent, "GMIN", nlconst::magic(1e-9)) , m_pivot(parent, "PIVOT", false) ///< use pivoting on supported solvers , m_nr_recalc_delay(parent, "NR_RECALC_DELAY", netlist_time::quantum().as_fp()) ///< Delay to next solve attempt if nr loops exceeded @@ -70,8 +70,8 @@ namespace solver /* automatic time step */ , m_dynamic_ts(parent, "DYNAMIC_TS", false) ///< Use dynamic time stepping - , m_dynamic_lte(parent, "DYNAMIC_LTE", plib::constants::cast(1e-5)) ///< dynamic time stepping slope - , m_dynamic_min_ts(parent, "DYNAMIC_MIN_TIMESTEP", plib::constants::cast(1e-6)) ///< smallest time step allowed + , m_dynamic_lte(parent, "DYNAMIC_LTE", nlconst::magic(1e-5)) ///< dynamic time stepping slope + , m_dynamic_min_ts(parent, "DYNAMIC_MIN_TIMESTEP", nlconst::magic(1e-6)) ///< smallest time step allowed /* matrix sorting */ , m_sort_type(parent, "SORT_TYPE", matrix_sort_type_e::PREFER_IDENTITY_TOP_LEFT) @@ -375,9 +375,9 @@ namespace solver , m_new_V(size) , m_RHS(size) , m_mat_ptr(size, this->max_railstart() + 1) - , m_last_V(size, plib::constants::zero()) - , m_DD_n_m_1(size, plib::constants::zero()) - , m_h_n_m_1(size, plib::constants::zero()) + , m_last_V(size, nlconst::zero()) + , m_DD_n_m_1(size, nlconst::zero()) + , m_h_n_m_1(size, nlconst::zero()) { /* * save states @@ -468,7 +468,7 @@ namespace solver m_h_n_m_1[k] = hn; m_DD_n_m_1[k] = DD_n; if (std::fabs(DD2) > fp_constants::TIMESTEP_MINDIV()) // avoid div-by-zero - new_net_timestep = std::sqrt(m_params.m_dynamic_lte / std::fabs(plib::constants::cast(0.5)*DD2)); + new_net_timestep = std::sqrt(m_params.m_dynamic_lte / std::fabs(nlconst::magic(0.5)*DD2)); else new_net_timestep = m_params.m_max_timestep; @@ -549,8 +549,8 @@ namespace solver *tcr_r[i] += static_cast(go[i]); /* use native floattype for now */ - auto gtot_t(plib::constants::zero()); - auto RHS_t (plib::constants::zero()); + auto gtot_t(nlconst::zero()); + auto RHS_t (nlconst::zero()); for (std::size_t i = 0; i < term_count; i++) { diff --git a/src/lib/netlist/solver/nld_ms_sor.h b/src/lib/netlist/solver/nld_ms_sor.h index f2e8352279e..ee79599a2ff 100644 --- a/src/lib/netlist/solver/nld_ms_sor.h +++ b/src/lib/netlist/solver/nld_ms_sor.h @@ -70,9 +70,9 @@ namespace solver for (std::size_t k = 0; k < iN; k++) { - nl_fptype gtot_t = plib::constants::zero(); - nl_fptype gabs_t = plib::constants::zero(); - nl_fptype RHS_t = plib::constants::zero(); + nl_fptype gtot_t = nlconst::zero(); + nl_fptype gabs_t = nlconst::zero(); + nl_fptype RHS_t = nlconst::zero(); const std::size_t term_count = this->m_terms[k].count(); const nl_fptype * const gt = this->m_gtn[k]; @@ -98,7 +98,7 @@ namespace solver for (std::size_t i = 0; i < term_count; i++) gabs_t = gabs_t + std::abs(go[i]); - gabs_t *= plib::constants::cast(0.5); // derived by try and error + gabs_t *= nlconst::magic(0.5); // derived by try and error if (gabs_t <= gtot_t) { w[k] = ws / static_cast(gtot_t); -- cgit v1.2.3