Previous 199869 Revisions Next

r35320 Sunday 18th January, 2015 at 10:48:39 UTC by Couriersud
Introduced an nl_double type. This will be followed by an nl_float type
for certain components (mostly matrix and vector). (nw)
[/branches/kale/src/emu/machine]netlist.c
[/branches/kale/src/emu/netlist]nl_base.c nl_base.h nl_config.h nl_dice_compat.h nl_parser.c nl_parser.h pstate.c pstate.h pstring.c pstring.h
[/branches/kale/src/emu/netlist/analog]nld_bjt.c nld_bjt.h nld_fourterm.c nld_fourterm.h nld_ms_direct.h nld_ms_direct1.h nld_ms_direct2.h nld_ms_gauss_seidel.h nld_solver.c nld_solver.h nld_twoterm.c nld_twoterm.h
[/branches/kale/src/emu/netlist/devices]nld_4066.c nld_74123.c nld_74ls629.c nld_cmos.h nld_ne555.c nld_ne555.h nld_r2r_dac.c nld_system.c
[/branches/kale/src/mame/includes]mario.h

branches/kale/src/emu/machine/netlist.c
r243831r243832
443443               if (td != NULL) save_pointer(td, s->m_name, s->m_count);
444444            }
445445            break;
446            case DT_FLOAT:
447                {
448                    float *td = s->resolved<float>();
449                    if (td != NULL) save_pointer(td, s->m_name, s->m_count);
450                }
451                break;
446452         case DT_INT64:
447453            save_pointer((INT64 *) s->m_ptr, s->m_name, s->m_count);
448454            break;
branches/kale/src/emu/netlist/analog/nld_bjt.c
r243831r243832
1111{
1212public:
1313   diode() : m_Is(1e-15), m_VT(0.0258), m_VT_inv(1.0 / m_VT) {}
14   diode(const double Is, const double n)
14   diode(const nl_double Is, const nl_double n)
1515   {
1616      m_Is = Is;
1717      m_VT = 0.0258 * n;
1818      m_VT_inv = 1.0 / m_VT;
1919   }
20   void set(const double Is, const double n)
20   void set(const nl_double Is, const nl_double n)
2121   {
2222      m_Is = Is;
2323      m_VT = 0.0258 * n;
2424      m_VT_inv = 1.0 / m_VT;
2525   }
26   double I(const double V) const { return m_Is * exp(V * m_VT_inv) - m_Is; }
27   double g(const double V) const { return m_Is * m_VT_inv * exp(V * m_VT_inv); }
28   double V(const double I) const { return log(1.0 + I / m_Is) * m_VT; }
29   double gI(const double I) const { return m_VT_inv * (I + m_Is); }
26   nl_double I(const nl_double V) const { return m_Is * exp(V * m_VT_inv) - m_Is; }
27   nl_double g(const nl_double V) const { return m_Is * m_VT_inv * exp(V * m_VT_inv); }
28   nl_double V(const nl_double I) const { return log(1.0 + I / m_Is) * m_VT; }
29   nl_double gI(const nl_double I) const { return m_VT_inv * (I + m_Is); }
3030
3131private:
32   double m_Is;
33   double m_VT;
34   double m_VT_inv;
32   nl_double m_Is;
33   nl_double m_VT;
34   nl_double m_VT_inv;
3535};
3636
3737
r243831r243832
8585   m_state_on = 0;
8686
8787   {
88      double IS = m_model.model_value("IS", 1e-15);
89      double BF = m_model.model_value("BF", 100);
90      double NF = m_model.model_value("NF", 1);
91      //double VJE = m_model.dValue("VJE", 0.75);
88      nl_double IS = m_model.model_value("IS", 1e-15);
89      nl_double BF = m_model.model_value("BF", 100);
90      nl_double NF = m_model.model_value("NF", 1);
91      //nl_double VJE = m_model.dValue("VJE", 0.75);
9292
9393      set_qtype((m_model.model_type() == "NPN") ? BJT_NPN : BJT_PNP);
9494
95      double alpha = BF / (1.0 + BF);
95      nl_double alpha = BF / (1.0 + BF);
9696
9797      diode d(IS, NF);
9898
r243831r243832
155155   m_gD_BC.save("m_D_BC", *this);
156156
157157   {
158      double IS = m_model.model_value("IS", 1e-15);
159      double BF = m_model.model_value("BF", 100);
160      double NF = m_model.model_value("NF", 1);
161      double BR = m_model.model_value("BR", 1);
162      double NR = m_model.model_value("NR", 1);
163      //double VJE = m_model.dValue("VJE", 0.75);
158      nl_double IS = m_model.model_value("IS", 1e-15);
159      nl_double BF = m_model.model_value("BF", 100);
160      nl_double NF = m_model.model_value("NF", 1);
161      nl_double BR = m_model.model_value("BR", 1);
162      nl_double NR = m_model.model_value("NR", 1);
163      //nl_double VJE = m_model.dValue("VJE", 0.75);
164164
165165      set_qtype((m_model.model_type() == "NPN") ? BJT_NPN : BJT_PNP);
166166      //printf("type %s\n", m_model.model_type().cstr());
branches/kale/src/emu/netlist/analog/nld_bjt.h
r243831r243832
9898
9999   NETLIB_UPDATE_TERMINALS()
100100   {
101      const double m = (is_qtype( BJT_NPN) ? 1 : -1);
101      const nl_double m = (is_qtype( BJT_NPN) ? 1 : -1);
102102
103103      const int new_state = (m_RB.deltaV() * m > m_V ) ? 1 : 0;
104104      if (m_state_on ^ new_state)
105105      {
106106#if 0
107         double gb = m_gB;
108         double gc = m_gC;
109         double v  = m_V * m;
107         nl_double gb = m_gB;
108         nl_double gc = m_gC;
109         nl_double v  = m_V * m;
110110         if (!new_state )
111111         {
112112            // not conducting
r243831r243832
115115            gc = netlist().gmin();
116116         }
117117#else
118         const double gb = new_state ? m_gB : netlist().gmin();
119         const double gc = new_state ? m_gC : netlist().gmin();
120         const double v  = new_state ? m_V * m : 0;
118         const nl_double gb = new_state ? m_gB : netlist().gmin();
119         const nl_double gc = new_state ? m_gC : netlist().gmin();
120         const nl_double v  = new_state ? m_V * m : 0;
121121#endif
122122         m_RB.set(gb, v,   0.0);
123123         m_RC.set(gc, 0.0, 0.0);
r243831r243832
142142   ATTR_COLD virtual void start();
143143   ATTR_HOT void update_param();
144144
145   double m_gB; // base conductance / switch on
146   double m_gC; // collector conductance / switch on
147   double m_V; // internal voltage source
145   nl_double m_gB; // base conductance / switch on
146   nl_double m_gC; // collector conductance / switch on
147   nl_double m_V; // internal voltage source
148148   UINT8 m_state_on;
149149
150150private:
r243831r243832
169169
170170   NETLIB_UPDATE_TERMINALS()
171171   {
172      const double polarity = (qtype() == BJT_NPN ? 1.0 : -1.0);
172      const nl_double polarity = (qtype() == BJT_NPN ? 1.0 : -1.0);
173173
174174      m_gD_BE.update_diode(-m_D_EB.deltaV() * polarity);
175175      m_gD_BC.update_diode(-m_D_CB.deltaV() * polarity);
176176
177      const double gee = m_gD_BE.G();
178      const double gcc = m_gD_BC.G();
179      const double gec =  m_alpha_r * gcc;
180      const double gce =  m_alpha_f * gee;
181      const double sIe = -m_gD_BE.I() + m_alpha_r * m_gD_BC.I();
182      const double sIc = m_alpha_f * m_gD_BE.I() - m_gD_BC.I();
183      const double Ie = (sIe + gee * m_gD_BE.Vd() - gec * m_gD_BC.Vd()) * polarity;
184      const double Ic = (sIc - gce * m_gD_BE.Vd() + gcc * m_gD_BC.Vd()) * polarity;
177      const nl_double gee = m_gD_BE.G();
178      const nl_double gcc = m_gD_BC.G();
179      const nl_double gec =  m_alpha_r * gcc;
180      const nl_double gce =  m_alpha_f * gee;
181      const nl_double sIe = -m_gD_BE.I() + m_alpha_r * m_gD_BC.I();
182      const nl_double sIc = m_alpha_f * m_gD_BE.I() - m_gD_BC.I();
183      const nl_double Ie = (sIe + gee * m_gD_BE.Vd() - gec * m_gD_BC.Vd()) * polarity;
184      const nl_double Ic = (sIc - gce * m_gD_BE.Vd() + gcc * m_gD_BC.Vd()) * polarity;
185185
186186      m_D_EB.set_mat(gee, gec - gee, gce - gee, gee - gec, Ie, -Ie);
187187      m_D_CB.set_mat(gcc, gce - gcc, gec - gcc, gcc - gce, Ic, -Ic);
r243831r243832
202202   nld_twoterm m_D_EB;  // gee, gec - gee, gce - gee, gee - gec | Ie
203203   nld_twoterm m_D_EC;  // 0, -gec, -gcc, 0 | 0
204204
205   double m_alpha_f;
206   double m_alpha_r;
205   nl_double m_alpha_f;
206   nl_double m_alpha_r;
207207
208208private:
209209};
branches/kale/src/emu/netlist/analog/nld_fourterm.c
r243831r243832
1717   m_gfac = 1.0;
1818}
1919
20void NETLIB_NAME(VCCS)::start_internal(const double def_RI)
20void NETLIB_NAME(VCCS)::start_internal(const nl_double def_RI)
2121{
2222   register_param("G", m_G, 1.0);
2323   register_param("RI", m_RI, def_RI);
r243831r243832
4545
4646NETLIB_RESET(VCCS)
4747{
48   const double m_mult = m_G.Value() * m_gfac; // 1.0 ==> 1V ==> 1A
49   const double GI = 1.0 / m_RI.Value();
48   const nl_double m_mult = m_G.Value() * m_gfac; // 1.0 ==> 1V ==> 1A
49   const nl_double GI = 1.0 / m_RI.Value();
5050
5151   m_IP.set(GI);
5252   m_IN.set(GI);
branches/kale/src/emu/netlist/analog/nld_fourterm.h
r243831r243832
5959   ATTR_COLD virtual void update_param();
6060   ATTR_HOT ATTR_ALIGN void update();
6161
62   ATTR_COLD void start_internal(const double def_RI);
62   ATTR_COLD void start_internal(const nl_double def_RI);
6363
6464   netlist_terminal_t m_OP;
6565   netlist_terminal_t m_ON;
r243831r243832
7373   netlist_param_double_t m_G;
7474   netlist_param_double_t m_RI;
7575
76   double m_gfac;
76   nl_double m_gfac;
7777};
7878
7979// ----------------------------------------------------------------------------------------
r243831r243832
115115   ATTR_COLD virtual void update_param();
116116   ATTR_HOT ATTR_ALIGN void update();
117117
118   double m_gfac;
118   nl_double m_gfac;
119119};
120120
121121
branches/kale/src/emu/netlist/analog/nld_ms_direct.h
r243831r243832
2828protected:
2929   ATTR_COLD virtual void add_term(int net_idx, netlist_terminal_t *term);
3030
31   ATTR_HOT virtual double vsolve();
31   ATTR_HOT virtual nl_double vsolve();
3232
3333   ATTR_HOT int solve_non_dynamic();
3434   ATTR_HOT void build_LE();
35   ATTR_HOT void gauss_LE(double (* RESTRICT x));
36   ATTR_HOT double delta(const double (* RESTRICT V));
37   ATTR_HOT void store(const double (* RESTRICT V), const bool store_RHS);
35   ATTR_HOT void gauss_LE(nl_double (* RESTRICT x));
36   ATTR_HOT nl_double delta(const nl_double (* RESTRICT V));
37   ATTR_HOT void store(const nl_double (* RESTRICT V), const bool store_RHS);
3838
3939   /* bring the whole system to the current time
4040    * Don't schedule a new calculation time. The recalculation has to be
4141    * triggered by the caller after the netlist element was changed.
4242    */
43   ATTR_HOT double compute_next_timestep();
43   ATTR_HOT nl_double compute_next_timestep();
4444
45   double m_A[_storage_N][((_storage_N + 7) / 8) * 8];
46   double m_RHS[_storage_N];
47   double m_last_RHS[_storage_N]; // right hand side - contains currents
48   double m_Vdelta[_storage_N];
49   double m_last_V[_storage_N];
45   nl_double m_A[_storage_N][((_storage_N + 7) / 8) * 8];
46   nl_double m_RHS[_storage_N];
47   nl_double m_last_RHS[_storage_N]; // right hand side - contains currents
48   nl_double m_Vdelta[_storage_N];
49   nl_double m_last_V[_storage_N];
5050
5151   terms_t **m_terms;
5252   terms_t *m_rails_temp;
r243831r243832
5555   vector_ops_t *m_row_ops[_storage_N + 1];
5656
5757   int m_dim;
58   double m_lp_fact;
58   nl_double m_lp_fact;
5959};
6060
6161// ----------------------------------------------------------------------------------------
r243831r243832
8484}
8585
8686template <int m_N, int _storage_N>
87ATTR_HOT double netlist_matrix_solver_direct_t<m_N, _storage_N>::compute_next_timestep()
87ATTR_HOT nl_double netlist_matrix_solver_direct_t<m_N, _storage_N>::compute_next_timestep()
8888{
89   double new_solver_timestep = m_params.m_max_timestep;
89   nl_double new_solver_timestep = m_params.m_max_timestep;
9090
9191   if (m_params.m_dynamic)
9292   {
r243831r243832
103103      {
104104         netlist_analog_net_t *n = m_nets[k];
105105#endif
106         const double DD_n = (n->m_cur_Analog - m_last_V[k]);
107         const double hn = current_timestep();
106         const nl_double DD_n = (n->m_cur_Analog - m_last_V[k]);
107         const nl_double hn = current_timestep();
108108
109         double DD2 = (DD_n / hn - n->m_DD_n_m_1 / n->m_h_n_m_1) / (hn + n->m_h_n_m_1);
110         double new_net_timestep;
109         nl_double DD2 = (DD_n / hn - n->m_DD_n_m_1 / n->m_h_n_m_1) / (hn + n->m_h_n_m_1);
110         nl_double new_net_timestep;
111111
112112         n->m_h_n_m_1 = hn;
113113         n->m_DD_n_m_1 = DD_n;
r243831r243832
236236      for (int i=0; i < N(); i++)
237237         m_A[k][i] = 0.0;
238238
239      double rhsk = 0.0;
240      double akk  = 0.0;
239      nl_double rhsk = 0.0;
240      nl_double akk  = 0.0;
241241      {
242242         const int terms_count = m_terms[k]->count();
243         const double * RESTRICT gt = m_terms[k]->gt();
244         const double * RESTRICT go = m_terms[k]->go();
245         const double * RESTRICT Idr = m_terms[k]->Idr();
243         const nl_double * RESTRICT gt = m_terms[k]->gt();
244         const nl_double * RESTRICT go = m_terms[k]->go();
245         const nl_double * RESTRICT Idr = m_terms[k]->Idr();
246246#if VECTALT
247247
248248         for (int i = 0; i < terms_count; i++)
r243831r243832
253253#else
254254         m_terms[k]->ops()->sum2(Idr, gt, rhsk, akk);
255255#endif
256         double * const * RESTRICT other_cur_analog = m_terms[k]->other_curanalog();
256         nl_double * const * RESTRICT other_cur_analog = m_terms[k]->other_curanalog();
257257         for (int i = m_terms[k]->m_railstart; i < terms_count; i++)
258258         {
259259            //rhsk = rhsk + go[i] * terms[i]->m_otherterm->net().as_analog().Q_Analog();
r243831r243832
272272      m_A[k][k] += 1.0;
273273      {
274274         const int *net_other = m_terms[k]->net_other();
275         const double *go = m_terms[k]->go();
275         const nl_double *go = m_terms[k]->go();
276276         const int railstart =  m_terms[k]->m_railstart;
277277
278278         for (int i = 0; i < railstart; i++)
r243831r243832
285285      m_A[k][k] += akk;
286286      {
287287         const int * RESTRICT net_other = m_terms[k]->net_other();
288         const double * RESTRICT go = m_terms[k]->go();
288         const nl_double * RESTRICT go = m_terms[k]->go();
289289         const int railstart =  m_terms[k]->m_railstart;
290290
291291         for (int i = 0; i < railstart; i++)
r243831r243832
299299
300300template <int m_N, int _storage_N>
301301ATTR_HOT void netlist_matrix_solver_direct_t<m_N, _storage_N>::gauss_LE(
302      double (* RESTRICT x))
302      nl_double (* RESTRICT x))
303303{
304304#if 0
305305   for (int i = 0; i < N(); i++)
r243831r243832
336336      }
337337
338338      /* FIXME: Singular matrix? */
339      const double f = 1.0 / m_A[i][i];
339      const nl_double f = 1.0 / m_A[i][i];
340340
341341      /* Eliminate column i from row j */
342342
343343      for (int j = i + 1; j < kN; j++)
344344      {
345         const double f1 = - m_A[j][i] * f;
345         const nl_double f1 = - m_A[j][i] * f;
346346         if (f1 != 0.0)
347347         {
348348#if 0 && VECTALT
r243831r243832
359359   /* back substitution */
360360   for (int j = kN - 1; j >= 0; j--)
361361   {
362      double tmp = 0;
362      nl_double tmp = 0;
363363
364364      for (int k = j + 1; k < kN; k++)
365365         tmp += m_A[j][k] * x[k];
r243831r243832
380380}
381381
382382template <int m_N, int _storage_N>
383ATTR_HOT double netlist_matrix_solver_direct_t<m_N, _storage_N>::delta(
384      const double (* RESTRICT V))
383ATTR_HOT nl_double netlist_matrix_solver_direct_t<m_N, _storage_N>::delta(
384      const nl_double (* RESTRICT V))
385385{
386   double cerr = 0;
387   double cerr2 = 0;
386   nl_double cerr = 0;
387   nl_double cerr2 = 0;
388388   for (int i = 0; i < this->N(); i++)
389389   {
390      const double e = (V[i] - this->m_nets[i]->m_cur_Analog);
391      const double e2 = (m_RHS[i] - this->m_last_RHS[i]);
390      const nl_double e = (V[i] - this->m_nets[i]->m_cur_Analog);
391      const nl_double e2 = (m_RHS[i] - this->m_last_RHS[i]);
392392      cerr = (fabs(e) > cerr ? fabs(e) : cerr);
393393      cerr2 = (fabs(e2) > cerr2 ? fabs(e2) : cerr2);
394394   }
r243831r243832
398398
399399template <int m_N, int _storage_N>
400400ATTR_HOT void netlist_matrix_solver_direct_t<m_N, _storage_N>::store(
401      const double (* RESTRICT V), const bool store_RHS)
401      const nl_double (* RESTRICT V), const bool store_RHS)
402402{
403403   for (int i = 0; i < this->N(); i++)
404404   {
r243831r243832
414414}
415415
416416template <int m_N, int _storage_N>
417ATTR_HOT double netlist_matrix_solver_direct_t<m_N, _storage_N>::vsolve()
417ATTR_HOT nl_double netlist_matrix_solver_direct_t<m_N, _storage_N>::vsolve()
418418{
419419   solve_base<netlist_matrix_solver_direct_t>(this);
420420   return this->compute_next_timestep();
r243831r243832
424424template <int m_N, int _storage_N>
425425ATTR_HOT int netlist_matrix_solver_direct_t<m_N, _storage_N>::solve_non_dynamic()
426426{
427   double new_v[_storage_N] = { 0.0 };
427   nl_double new_v[_storage_N] = { 0.0 };
428428
429429   this->gauss_LE(new_v);
430430
431431   if (this->is_dynamic())
432432   {
433      double err = delta(new_v);
433      nl_double err = delta(new_v);
434434
435435      store(new_v, true);
436436
branches/kale/src/emu/netlist/analog/nld_ms_direct1.h
r243831r243832
1818      {}
1919   ATTR_HOT inline int vsolve_non_dynamic();
2020protected:
21   ATTR_HOT virtual double vsolve();
21   ATTR_HOT virtual nl_double vsolve();
2222private:
2323};
2424
r243831r243832
2626// netlist_matrix_solver - Direct1
2727// ----------------------------------------------------------------------------------------
2828
29ATTR_HOT double netlist_matrix_solver_direct1_t::vsolve()
29ATTR_HOT nl_double netlist_matrix_solver_direct1_t::vsolve()
3030{
3131   solve_base<netlist_matrix_solver_direct1_t>(this);
3232   return this->compute_next_timestep();
r243831r243832
3838   this->build_LE();
3939   //NL_VERBOSE_OUT(("%f %f\n", new_val, m_RHS[0] / m_A[0][0]);
4040
41   double new_val =  m_RHS[0] / m_A[0][0];
41   nl_double new_val =  m_RHS[0] / m_A[0][0];
4242
43   double e = (new_val - net->m_cur_Analog);
44   double cerr = fabs(e);
43   nl_double e = (new_val - net->m_cur_Analog);
44   nl_double cerr = fabs(e);
4545
4646   net->m_cur_Analog = new_val;
4747
branches/kale/src/emu/netlist/analog/nld_ms_direct2.h
r243831r243832
2020      {}
2121   ATTR_HOT inline int vsolve_non_dynamic();
2222protected:
23   ATTR_HOT virtual double vsolve();
23   ATTR_HOT virtual nl_double vsolve();
2424private:
2525};
2626
r243831r243832
2828// netlist_matrix_solver - Direct2
2929// ----------------------------------------------------------------------------------------
3030
31ATTR_HOT double netlist_matrix_solver_direct2_t::vsolve()
31ATTR_HOT nl_double netlist_matrix_solver_direct2_t::vsolve()
3232{
3333   solve_base<netlist_matrix_solver_direct2_t>(this);
3434   return this->compute_next_timestep();
r243831r243832
3838{
3939   build_LE();
4040
41   const double a = m_A[0][0];
42   const double b = m_A[0][1];
43   const double c = m_A[1][0];
44   const double d = m_A[1][1];
41   const nl_double a = m_A[0][0];
42   const nl_double b = m_A[0][1];
43   const nl_double c = m_A[1][0];
44   const nl_double d = m_A[1][1];
4545
46   double new_val[2];
46   nl_double new_val[2];
4747   new_val[1] = (a * m_RHS[1] - c * m_RHS[0]) / (a * d - b * c);
4848   new_val[0] = (m_RHS[0] - b * new_val[1]) / a;
4949
5050   if (is_dynamic())
5151   {
52      double err = this->delta(new_val);
52      nl_double err = this->delta(new_val);
5353      store(new_val, true);
5454      if (err > m_params.m_accuracy )
5555         return 2;
branches/kale/src/emu/netlist/analog/nld_ms_gauss_seidel.h
r243831r243832
2929
3030   ATTR_HOT inline int vsolve_non_dynamic();
3131protected:
32   ATTR_HOT virtual double vsolve();
32   ATTR_HOT virtual nl_double vsolve();
3333
3434private:
35   double m_lp_fact;
35   nl_double m_lp_fact;
3636   int m_gs_fail;
3737   int m_gs_total;
3838
r243831r243832
6464}
6565
6666template <int m_N, int _storage_N>
67ATTR_HOT double netlist_matrix_solver_gauss_seidel_t<m_N, _storage_N>::vsolve()
67ATTR_HOT nl_double netlist_matrix_solver_gauss_seidel_t<m_N, _storage_N>::vsolve()
6868{
6969   /*
7070    * enable linear prediction on first newton pass
r243831r243832
8686
8787   if (USE_LINEAR_PREDICTION)
8888   {
89      double sq = 0;
90      double sqo = 0;
91      const double rez_cts = 1.0 / this->current_timestep();
89      nl_double sq = 0;
90      nl_double sqo = 0;
91      const nl_double rez_cts = 1.0 / this->current_timestep();
9292      for (int k = 0; k < this->N(); k++)
9393      {
9494         const netlist_analog_net_t *n = this->m_nets[k];
95         const double nv = (n->m_cur_Analog - this->m_last_V[k]) * rez_cts ;
95         const nl_double nv = (n->m_cur_Analog - this->m_last_V[k]) * rez_cts ;
9696         sq += nv * nv;
9797         sqo += this->m_Vdelta[k] * this->m_Vdelta[k];
9898         this->m_Vdelta[k] = nv;
r243831r243832
116116    */
117117
118118#if 0 || USE_MATRIX_GS
119   static double ws = 1.0;
120   ATTR_ALIGN double new_v[_storage_N] = { 0.0 };
119   static nl_double ws = 1.0;
120   ATTR_ALIGN nl_double new_v[_storage_N] = { 0.0 };
121121   const int iN = this->N();
122122
123123   bool resched = false;
r243831r243832
127127   this->build_LE();
128128
129129   {
130      double frob;
130      nl_double frob;
131131      frob = 0;
132      double rmin = 1e99, rmax = -1e99;
132      nl_double rmin = 1e99, rmax = -1e99;
133133      for (int k = 0; k < iN; k++)
134134      {
135135         new_v[k] = this->m_nets[k]->m_cur_Analog;
136         double s=0.0;
136         nl_double s=0.0;
137137         for (int i = 0; i < iN; i++)
138138         {
139139            frob += this->m_A[k][i] * this->m_A[k][i];
r243831r243832
146146            rmax = s;
147147      }
148148#if 0
149      double frobA = sqrt(frob /(iN));
149      nl_double frobA = sqrt(frob /(iN));
150150      if (1 &&frobA < 1.0)
151151         //ws = 2.0 / (1.0 + sqrt(1.0-frobA));
152152         ws = 2.0 / (2.0 - frobA);
r243831r243832
161161      // overhead is bigger than the gain. Consequently the fast GS below
162162      // uses a fixed GS. One can however use this here to determine a
163163      // suitable parameter.
164      double rm = (rmax + rmin) * 0.5;
164      nl_double rm = (rmax + rmin) * 0.5;
165165      if (rm < 1.0)
166166         ws = 2.0 / (1.0 + sqrt(1.0-rm));
167167      else
r243831r243832
172172   }
173173
174174   // Frobenius norm for (D-L)^(-1)U
175   //double frobU;
176   //double frobL;
177   //double norm;
175   //nl_double frobU;
176   //nl_double frobL;
177   //nl_double norm;
178178   do {
179179      resched = false;
180      double cerr = 0.0;
180      nl_double cerr = 0.0;
181181      //frobU = 0;
182182      //frobL = 0;
183183      //norm = 0;
184184
185185      for (int k = 0; k < iN; k++)
186186      {
187         double Idrive = 0;
188         //double norm_t = 0;
187         nl_double Idrive = 0;
188         //nl_double norm_t = 0;
189189         // Reduction loops need -ffast-math
190190         for (int i = 0; i < iN; i++)
191191            Idrive += this->m_A[k][i] * new_v[i];
r243831r243832
198198         }
199199
200200         //if (norm_t > norm) norm = norm_t;
201         const double new_val = (1.0-ws) * new_v[k] + ws * (this->m_RHS[k] - Idrive + this->m_A[k][k] * new_v[k]) / this->m_A[k][k];
201         const nl_double new_val = (1.0-ws) * new_v[k] + ws * (this->m_RHS[k] - Idrive + this->m_A[k][k] * new_v[k]) / this->m_A[k][k];
202202
203         const double e = fabs(new_val - new_v[k]);
203         const nl_double e = fabs(new_val - new_v[k]);
204204         cerr = (e > cerr ? e : cerr);
205205         new_v[k] = new_val;
206206      }
r243831r243832
210210         resched = true;
211211      }
212212      resched_cnt++;
213      //ATTR_UNUSED double frobUL = sqrt((frobU + frobL) / (double) (iN) / (double) (iN));
213      //ATTR_UNUSED nl_double frobUL = sqrt((frobU + frobL) / (double) (iN) / (double) (iN));
214214   } while (resched && (resched_cnt < this->m_params.m_gs_loops));
215215   //printf("Frobenius %f %f %f %f %f\n", sqrt(frobU), sqrt(frobL), frobUL, frobA, norm);
216216   //printf("Omega Estimate1 %f %f\n", 2.0 / (1.0 + sqrt(1-frobUL)), 2.0 / (1.0 + sqrt(1-frobA)) ); //        printf("Frobenius %f\n", sqrt(frob / (double) (iN * iN) ));
r243831r243832
247247    * omega = 2.0 / (1.0 + sqrt(1-rho))
248248    */
249249
250   const double ws = this->m_params.m_sor; //1.045; //2.0 / (1.0 + /*sin*/(3.14159 * 5.5 / (double) (m_nets.count()+1)));
251   //const double ws = 2.0 / (1.0 + sin(3.14159 * 4 / (double) (this->N())));
250   const nl_double ws = this->m_params.m_sor; //1.045; //2.0 / (1.0 + /*sin*/(3.14159 * 5.5 / (double) (m_nets.count()+1)));
251   //const nl_double ws = 2.0 / (1.0 + sin(3.14159 * 4 / (double) (this->N())));
252252
253   ATTR_ALIGN double w[_storage_N];
254   ATTR_ALIGN double one_m_w[_storage_N];
255   ATTR_ALIGN double RHS[_storage_N];
256   ATTR_ALIGN double new_V[_storage_N];
253   ATTR_ALIGN nl_double w[_storage_N];
254   ATTR_ALIGN nl_double one_m_w[_storage_N];
255   ATTR_ALIGN nl_double RHS[_storage_N];
256   ATTR_ALIGN nl_double new_V[_storage_N];
257257
258258   for (int k = 0; k < iN; k++)
259259   {
260      double gtot_t = 0.0;
261      double gabs_t = 0.0;
262      double RHS_t = 0.0;
260      nl_double gtot_t = 0.0;
261      nl_double gabs_t = 0.0;
262      nl_double RHS_t = 0.0;
263263
264264      new_V[k] = this->m_nets[k]->m_cur_Analog;
265265
266266      {
267267         const int term_count = this->m_terms[k]->count();
268         const double * const RESTRICT gt = this->m_terms[k]->gt();
269         const double * const RESTRICT go = this->m_terms[k]->go();
270         const double * const RESTRICT Idr = this->m_terms[k]->Idr();
271         const double * const *other_cur_analog = this->m_terms[k]->other_curanalog();
268         const nl_double * const RESTRICT gt = this->m_terms[k]->gt();
269         const nl_double * const RESTRICT go = this->m_terms[k]->go();
270         const nl_double * const RESTRICT Idr = this->m_terms[k]->Idr();
271         const nl_double * const *other_cur_analog = this->m_terms[k]->other_curanalog();
272272#if VECTALT
273273         for (int i = 0; i < term_count; i++)
274274         {
r243831r243832
308308
309309   }
310310
311   const double accuracy = this->m_params.m_accuracy;
311   const nl_double accuracy = this->m_params.m_accuracy;
312312
313313   do {
314314      resched = false;
r243831r243832
317317      {
318318         const int * RESTRICT net_other = this->m_terms[k]->net_other();
319319         const int railstart = this->m_terms[k]->m_railstart;
320         const double * RESTRICT go = this->m_terms[k]->go();
320         const nl_double * RESTRICT go = this->m_terms[k]->go();
321321
322         double Idrive = 0.0;
322         nl_double Idrive = 0.0;
323323         for (int i = 0; i < railstart; i++)
324324            Idrive = Idrive + go[i] * new_V[net_other[i]];
325325
326         //double new_val = (net->m_cur_Analog * gabs[k] + iIdr) / (gtot[k]);
327         const double new_val = new_V[k] * one_m_w[k] + (Idrive + RHS[k]) * w[k];
326         //nl_double new_val = (net->m_cur_Analog * gabs[k] + iIdr) / (gtot[k]);
327         const nl_double new_val = new_V[k] * one_m_w[k] + (Idrive + RHS[k]) * w[k];
328328
329329         resched = resched || (std::abs(new_val - new_V[k]) > accuracy);
330330         new_V[k] = new_val;
branches/kale/src/emu/netlist/analog/nld_solver.c
r243831r243832
233233
234234ATTR_COLD void netlist_matrix_solver_t::update()
235235{
236   const double new_timestep = solve();
236   const nl_double new_timestep = solve();
237237
238238   if (m_params.m_dynamic && is_timestep() && new_timestep > 0)
239239      m_Q_sync.net().reschedule_in_queue(netlist_time::from_double(new_timestep));
r243831r243832
241241
242242ATTR_COLD void netlist_matrix_solver_t::update_forced()
243243{
244   ATTR_UNUSED const double new_timestep = solve();
244   ATTR_UNUSED const nl_double new_timestep = solve();
245245
246246   if (m_params.m_dynamic && is_timestep())
247247      m_Q_sync.net().reschedule_in_queue(netlist_time::from_double(m_params.m_min_timestep));
r243831r243832
249249
250250ATTR_HOT void netlist_matrix_solver_t::step(const netlist_time delta)
251251{
252   const double dd = delta.as_double();
252   const nl_double dd = delta.as_double();
253253   for (int k=0; k < m_step_devices.count(); k++)
254254      m_step_devices[k]->step_time(dd);
255255}
r243831r243832
284284   }
285285}
286286
287ATTR_HOT double netlist_matrix_solver_t::solve()
287ATTR_HOT nl_double netlist_matrix_solver_t::solve()
288288{
289289   netlist_time now = netlist().time();
290290   netlist_time delta = now - m_last_step;
r243831r243832
300300
301301   step(delta);
302302
303   const double next_time_step = vsolve();
303   const nl_double next_time_step = vsolve();
304304
305305   update_inputs();
306306   return next_time_step;
r243831r243832
348348   register_param("GMIN", m_gmin, NETLIST_GMIN_DEFAULT);
349349   register_param("DYNAMIC_TS", m_dynamic, 0);
350350   register_param("LTE", m_lte, 5e-5);                     // diff/timestep
351   register_param("MIN_TIMESTEP", m_min_timestep, 1e-6);   // double timestep resolution
351   register_param("MIN_TIMESTEP", m_min_timestep, 1e-6);   // nl_double timestep resolution
352352
353353   // internal staff
354354
r243831r243832
417417      if (m_mat_solvers[i]->is_timestep())
418418         {
419419            // Ignore return value
420            ATTR_UNUSED const double ts = m_mat_solvers[i]->solve();
420            ATTR_UNUSED const nl_double ts = m_mat_solvers[i]->solve();
421421         }
422422   }
423423#endif
branches/kale/src/emu/netlist/analog/nld_solver.h
r243831r243832
3737
3838struct netlist_solver_parameters_t
3939{
40   double m_accuracy;
41   double m_lte;
42   double m_min_timestep;
43   double m_max_timestep;
44   double m_sor;
40   nl_double m_accuracy;
41   nl_double m_lte;
42   nl_double m_min_timestep;
43   nl_double m_max_timestep;
44   nl_double m_sor;
4545   bool m_dynamic;
4646   int m_gs_loops;
4747   int m_nr_loops;
r243831r243832
5959
6060   virtual ~vector_ops_t() {}
6161
62   virtual const double sum(const double * v) = 0;
63   virtual void sum2(const double * RESTRICT v1, const double * RESTRICT v2, double & RESTRICT  s1, double & RESTRICT s2) = 0;
64   virtual void addmult(double * RESTRICT v1, const double * RESTRICT v2, const double &mult) = 0;
65   virtual void sum2a(const double * RESTRICT v1, const double * RESTRICT v2, const double * RESTRICT v3abs, double & RESTRICT s1, double & RESTRICT s2, double & RESTRICT s3abs) = 0;
62   virtual const nl_double sum(const nl_double * v) = 0;
63   virtual void sum2(const nl_double * RESTRICT v1, const nl_double * RESTRICT v2, nl_double & RESTRICT  s1, nl_double & RESTRICT s2) = 0;
64   virtual void addmult(nl_double * RESTRICT v1, const nl_double * RESTRICT v2, const nl_double &mult) = 0;
65   virtual void sum2a(const nl_double * RESTRICT v1, const nl_double * RESTRICT v2, const nl_double * RESTRICT v3abs, nl_double & RESTRICT s1, nl_double & RESTRICT s2, nl_double & RESTRICT s3abs) = 0;
6666
67   virtual const double sumabs(const double * v) = 0;
67   virtual const nl_double sumabs(const nl_double * v) = 0;
6868
6969   static vector_ops_t *create_ops(const int size);
7070
r243831r243832
9595
9696   ATTR_HOT inline const int N() const { if (m_N == 0) return m_dim; else return m_N; }
9797
98   const double sum(const double * v)
98   const nl_double sum(const nl_double * v)
9999   {
100      const double *  RESTRICT vl = v;
101      double tmp = 0.0;
100      const nl_double *  RESTRICT vl = v;
101      nl_double tmp = 0.0;
102102      for (int i=0; i < N(); i++)
103103         tmp += vl[i];
104104      return tmp;
105105   }
106106
107   void sum2(const double * RESTRICT v1, const double * RESTRICT v2, double & RESTRICT s1, double & RESTRICT s2)
107   void sum2(const nl_double * RESTRICT v1, const nl_double * RESTRICT v2, nl_double & RESTRICT s1, nl_double & RESTRICT s2)
108108   {
109      const double * RESTRICT v1l = v1;
110      const double * RESTRICT v2l = v2;
109      const nl_double * RESTRICT v1l = v1;
110      const nl_double * RESTRICT v2l = v2;
111111      for (int i=0; i < N(); i++)
112112      {
113113         s1 += v1l[i];
r243831r243832
115115      }
116116   }
117117
118   void addmult(double * RESTRICT v1, const double * RESTRICT v2, const double &mult)
118   void addmult(nl_double * RESTRICT v1, const nl_double * RESTRICT v2, const nl_double &mult)
119119   {
120      double * RESTRICT v1l = v1;
121      const double * RESTRICT v2l = v2;
120      nl_double * RESTRICT v1l = v1;
121      const nl_double * RESTRICT v2l = v2;
122122      for (int i=0; i < N(); i++)
123123      {
124124         v1l[i] += v2l[i] * mult;
125125      }
126126   }
127127
128   void sum2a(const double * RESTRICT v1, const double * RESTRICT v2, const double * RESTRICT v3abs, double & RESTRICT s1, double & RESTRICT s2, double & RESTRICT s3abs)
128   void sum2a(const nl_double * RESTRICT v1, const nl_double * RESTRICT v2, const nl_double * RESTRICT v3abs, nl_double & RESTRICT s1, nl_double & RESTRICT s2, nl_double & RESTRICT s3abs)
129129   {
130      const double * RESTRICT v1l = v1;
131      const double * RESTRICT v2l = v2;
132      const double * RESTRICT v3l = v3abs;
130      const nl_double * RESTRICT v1l = v1;
131      const nl_double * RESTRICT v2l = v2;
132      const nl_double * RESTRICT v3l = v3abs;
133133      for (int i=0; i < N(); i++)
134134      {
135135         s1 += v1l[i];
r243831r243832
138138      }
139139   }
140140
141   const double sumabs(const double * v)
141   const nl_double sumabs(const nl_double * v)
142142   {
143      const double * RESTRICT vl = v;
144      double tmp = 0.0;
143      const nl_double * RESTRICT vl = v;
144      nl_double tmp = 0.0;
145145      for (int i=0; i < N(); i++)
146146         tmp += fabs(vl[i]);
147147      return tmp;
r243831r243832
171171
172172   ATTR_HOT inline netlist_terminal_t **terms() { return m_term; }
173173   ATTR_HOT inline int *net_other() { return m_net_other; }
174   ATTR_HOT inline double *gt() { return m_gt; }
175   ATTR_HOT inline double *go() { return m_go; }
176   ATTR_HOT inline double *Idr() { return m_Idr; }
177   ATTR_HOT inline double **other_curanalog() { return m_other_curanalog; }
174   ATTR_HOT inline nl_double *gt() { return m_gt; }
175   ATTR_HOT inline nl_double *go() { return m_go; }
176   ATTR_HOT inline nl_double *Idr() { return m_Idr; }
177   ATTR_HOT inline nl_double **other_curanalog() { return m_other_curanalog; }
178178
179179   ATTR_COLD void set_pointers();
180180
r243831r243832
183183private:
184184   plinearlist_t<netlist_terminal_t *> m_term;
185185   plinearlist_t<int> m_net_other;
186   plinearlist_t<double> m_go;
187   plinearlist_t<double> m_gt;
188   plinearlist_t<double> m_Idr;
189   plinearlist_t<double *> m_other_curanalog;
186   plinearlist_t<nl_double> m_go;
187   plinearlist_t<nl_double> m_gt;
188   plinearlist_t<nl_double> m_Idr;
189   plinearlist_t<nl_double *> m_other_curanalog;
190190};
191191
192192class netlist_matrix_solver_t : public netlist_device_t
r243831r243832
209209   template<class C>
210210   void solve_base(C *p);
211211
212   ATTR_HOT double solve();
212   ATTR_HOT nl_double solve();
213213
214214   ATTR_HOT inline bool is_dynamic() { return m_dynamic_devices.count() > 0; }
215215   ATTR_HOT inline bool is_timestep() { return m_step_devices.count() > 0; }
r243831r243832
236236   ATTR_HOT void update_dynamic();
237237
238238   // should return next time step
239   ATTR_HOT virtual double vsolve() = 0;
239   ATTR_HOT virtual nl_double vsolve() = 0;
240240
241241   ATTR_COLD virtual void  add_term(int net_idx, netlist_terminal_t *term) = 0;
242242
r243831r243832
249249
250250   const netlist_solver_parameters_t &m_params;
251251
252   ATTR_HOT inline const double current_timestep() { return m_cur_ts; }
252   ATTR_HOT inline const nl_double current_timestep() { return m_cur_ts; }
253253private:
254254
255255   netlist_time m_last_step;
256   double m_cur_ts;
256   nl_double m_cur_ts;
257257   dev_list_t m_step_devices;
258258   dev_list_t m_dynamic_devices;
259259
r243831r243832
279279
280280   ATTR_COLD void post_start();
281281
282   ATTR_HOT inline double gmin() { return m_gmin.Value(); }
282   ATTR_HOT inline nl_double gmin() { return m_gmin.Value(); }
283283
284284protected:
285285   ATTR_HOT void update();
branches/kale/src/emu/netlist/analog/nld_twoterm.c
r243831r243832
1616   set_param(1e-15, 1, 1e-15);
1717}
1818
19ATTR_COLD void netlist_generic_diode::set_param(const double Is, const double n, double gmin)
19ATTR_COLD void netlist_generic_diode::set_param(const nl_double Is, const nl_double n, nl_double gmin)
2020{
2121   m_Is = Is;
2222   m_n = n;
r243831r243832
157157
158158NETLIB_UPDATE_PARAM(POT)
159159{
160   double v = m_Dial.Value();
160   nl_double v = m_Dial.Value();
161161   if (m_DialIsLog.Value())
162162      v = (exp(v) - 1.0) / (exp(1.0) - 1.0);
163163
r243831r243832
221221
222222NETLIB_UPDATE_PARAM(D)
223223{
224   double Is = m_model.model_value("Is", 1e-15);
225   double n = m_model.model_value("N", 1);
224   nl_double Is = m_model.model_value("Is", 1e-15);
225   nl_double n = m_model.model_value("N", 1);
226226
227227   m_D.set_param(Is, n, netlist().gmin());
228228}
branches/kale/src/emu/netlist/analog/nld_twoterm.h
r243831r243832
9797   {
9898   }
9999
100   ATTR_HOT inline void set(const double G, const double V, const double I)
100   ATTR_HOT inline void set(const nl_double G, const nl_double V, const nl_double I)
101101   {
102102      /*      GO, GT, I                */
103103      m_P.set( G,  G, (  V) * G - I);
104104      m_N.set( G,  G, ( -V) * G + I);
105105   }
106106
107   ATTR_HOT inline double deltaV() const
107   ATTR_HOT inline nl_double deltaV() const
108108   {
109109      return m_P.net().as_analog().Q_Analog() - m_N.net().as_analog().Q_Analog();
110110   }
111111
112   ATTR_HOT void set_mat(double a11, double a12, double a21, double a22, double r1, double r2)
112   ATTR_HOT void set_mat(nl_double a11, nl_double a12, nl_double a21, nl_double a22, nl_double r1, nl_double r2)
113113   {
114114      /*      GO, GT, I                */
115115      m_P.set(-a12, a11, -r1);
r243831r243832
133133public:
134134   ATTR_COLD NETLIB_NAME(R_base)() : NETLIB_NAME(twoterm)(RESISTOR) { }
135135
136   inline void set_R(const double R)
136   inline void set_R(const nl_double R)
137137   {
138138      set(1.0 / R, 0.0, 0.0);
139139   }
r243831r243832
171171public:
172172   ATTR_COLD NETLIB_NAME(C)() : NETLIB_NAME(twoterm)(CAPACITOR) { }
173173
174   ATTR_HOT void step_time(const double st)
174   ATTR_HOT void step_time(const nl_double st)
175175   {
176      const double G = m_C.Value() / st;
177      const double I = -G * deltaV();
176      const nl_double G = m_C.Value() / st;
177      const nl_double I = -G * deltaV();
178178      set(G, 0.0, I);
179179   }
180180
r243831r243832
198198public:
199199   ATTR_COLD netlist_generic_diode();
200200
201   ATTR_HOT inline void update_diode(const double nVd)
201   ATTR_HOT inline void update_diode(const nl_double nVd)
202202   {
203203      //FIXME: Optimize cutoff case
204204
r243831r243832
212212      {
213213         m_Vd = nVd;
214214
215         const double eVDVt = exp(m_Vd * m_VtInv);
215         const nl_double eVDVt = exp(m_Vd * m_VtInv);
216216         m_Id = m_Is * (eVDVt - 1.0);
217217         m_G = m_Is * m_VtInv * eVDVt + m_gmin;
218218      }
r243831r243832
221221#if defined(_MSC_VER) && _MSC_VER < 1800
222222         m_Vd = m_Vd + log((nVd - m_Vd) * m_VtInv + 1.0) * m_Vt;
223223#else
224         double a = (nVd - m_Vd) * m_VtInv;
224         nl_double a = (nVd - m_Vd) * m_VtInv;
225225         if (a<1e-12 - 1.0) a = 1e-12 - 1.0;
226226         m_Vd = m_Vd + log1p(a) * m_Vt;
227227#endif
228         const double eVDVt = exp(m_Vd * m_VtInv);
228         const nl_double eVDVt = exp(m_Vd * m_VtInv);
229229         m_Id = m_Is * (eVDVt - 1.0);
230230
231231         m_G = m_Is * m_VtInv * eVDVt + m_gmin;
r243831r243832
234234      //printf("nVd %f m_Vd %f Vcrit %f\n", nVd, m_Vd, m_Vcrit);
235235   }
236236
237   ATTR_COLD void set_param(const double Is, const double n, double gmin);
237   ATTR_COLD void set_param(const nl_double Is, const nl_double n, nl_double gmin);
238238
239   ATTR_HOT inline double I() const { return m_Id; }
240   ATTR_HOT inline double G() const { return m_G; }
241   ATTR_HOT inline double Ieq() const { return (m_Id - m_Vd * m_G); }
242   ATTR_HOT inline double Vd() const { return m_Vd; }
239   ATTR_HOT inline nl_double I() const { return m_Id; }
240   ATTR_HOT inline nl_double G() const { return m_G; }
241   ATTR_HOT inline nl_double Ieq() const { return (m_Id - m_Vd * m_G); }
242   ATTR_HOT inline nl_double Vd() const { return m_Vd; }
243243
244244   /* owning object must save those ... */
245245
246246   ATTR_COLD void save(pstring name, netlist_object_t &parent);
247247
248248private:
249   double m_Vd;
250   double m_Id;
251   double m_G;
249   nl_double m_Vd;
250   nl_double m_Id;
251   nl_double m_G;
252252
253   double m_Vt;
254   double m_Is;
255   double m_n;
256   double m_gmin;
253   nl_double m_Vt;
254   nl_double m_Is;
255   nl_double m_n;
256   nl_double m_gmin;
257257
258   double m_VtInv;
259   double m_Vcrit;
258   nl_double m_VtInv;
259   nl_double m_Vcrit;
260260};
261261
262262// ----------------------------------------------------------------------------------------
r243831r243832
268268// add c3 and it'll be better than 1%
269269
270270#if 0
271inline double fastexp_h(const double x)
271inline nl_double fastexp_h(const nl_double x)
272272{
273   static const double ln2r = 1.442695040888963387;
274   static const double ln2  = 0.693147180559945286;
275   //static const double c3   = 0.166666666666666667;
273   static const nl_double ln2r = 1.442695040888963387;
274   static const nl_double ln2  = 0.693147180559945286;
275   //static const nl_double c3   = 0.166666666666666667;
276276
277   const double y = x * ln2r;
277   const nl_double y = x * ln2r;
278278   const unsigned int t = y;
279   const double z = (x - ln2 * (double) t);
280   const double zz = z * z;
281   //const double zzz = zz * z;
279   const nl_double z = (x - ln2 * (double) t);
280   const nl_double zz = z * z;
281   //const nl_double zzz = zz * z;
282282
283283   return (double)(1 << t)*(1.0 + z + 0.5 * zz); // + c3*zzz;
284284}
285285
286inline double fastexp(const double x)
286inline nl_double fastexp(const nl_double x)
287287{
288288   if (x<0)
289289      return 1.0 / fastexp_h(-x);
branches/kale/src/emu/netlist/devices/nld_4066.c
r243831r243832
1919
2020NETLIB_UPDATE(4066)
2121{
22   double sup = (m_supply.get()->vdd() - m_supply.get()->vss());
23   double low = 0.45 * sup;
24   double high = 0.55 * sup;
25   double in = INPANALOG(m_control) - m_supply.get()->vss();
26   double rON = 270.0 * 5.0 / sup;
22   nl_double sup = (m_supply.get()->vdd() - m_supply.get()->vss());
23   nl_double low = 0.45 * sup;
24   nl_double high = 0.55 * sup;
25   nl_double in = INPANALOG(m_control) - m_supply.get()->vss();
26   nl_double rON = 270.0 * 5.0 / sup;
2727
2828   if (in < low)
2929   {
branches/kale/src/emu/netlist/devices/nld_74123.c
r243831r243832
6969
7070   if (m_state == 1)
7171   {
72      const double vLow = m_KP * TERMANALOG(m_RP.m_P);
72      const nl_double vLow = m_KP * TERMANALOG(m_RP.m_P);
7373      if (INPANALOG(m_CV) < vLow)
7474      {
7575         m_RN.set_R(R_OFF);
r243831r243832
7878   }
7979   else if (m_state == 2)
8080   {
81      const double vHigh = TERMANALOG(m_RP.m_P) * (1.0 - m_KP);
81      const nl_double vHigh = TERMANALOG(m_RP.m_P) * (1.0 - m_KP);
8282      if (INPANALOG(m_CV) > vHigh)
8383      {
8484         m_RP.set_R(R_OFF);
branches/kale/src/emu/netlist/devices/nld_74ls629.c
r243831r243832
104104{
105105   {
106106      // recompute
107      double  freq;
108      double  v_freq_2, v_freq_3, v_freq_4;
109      double  v_freq = INPANALOG(m_FC);
110      double  v_rng = INPANALOG(m_RNG);
107      nl_double  freq;
108      nl_double  v_freq_2, v_freq_3, v_freq_4;
109      nl_double  v_freq = INPANALOG(m_FC);
110      nl_double  v_rng = INPANALOG(m_RNG);
111111
112112      /* coefficients */
113      const double k1 = 1.9904769024796283E+03;
114      const double k2 = 1.2070059213983407E+03;
115      const double k3 = 1.3266985579561108E+03;
116      const double k4 = -1.5500979825922698E+02;
117      const double k5 = 2.8184536266938172E+00;
118      const double k6 = -2.3503421582744556E+02;
119      const double k7 = -3.3836786704527788E+02;
120      const double k8 = -1.3569136703258670E+02;
121      const double k9 = 2.9914575453819188E+00;
122      const double k10 = 1.6855569086173170E+00;
113      const nl_double k1 = 1.9904769024796283E+03;
114      const nl_double k2 = 1.2070059213983407E+03;
115      const nl_double k3 = 1.3266985579561108E+03;
116      const nl_double k4 = -1.5500979825922698E+02;
117      const nl_double k5 = 2.8184536266938172E+00;
118      const nl_double k6 = -2.3503421582744556E+02;
119      const nl_double k7 = -3.3836786704527788E+02;
120      const nl_double k8 = -1.3569136703258670E+02;
121      const nl_double k9 = 2.9914575453819188E+00;
122      const nl_double k10 = 1.6855569086173170E+00;
123123
124124      /* scale due to input resistance */
125125
branches/kale/src/emu/netlist/devices/nld_cmos.h
r243831r243832
2929      ATTR_HOT void reset()  {};
3030
3131public:
32   ATTR_HOT inline double vdd() { return INPANALOG(m_vdd); }
33   ATTR_HOT inline double vss() { return INPANALOG(m_vss); }
32   ATTR_HOT inline nl_double vdd() { return INPANALOG(m_vdd); }
33   ATTR_HOT inline nl_double vss() { return INPANALOG(m_vss); }
3434};
3535
3636#endif /* NLD_CMOS_H_ */
branches/kale/src/emu/netlist/devices/nld_ne555.c
r243831r243832
1010#define R_OFF (1E20)
1111#define R_ON (25)   // Datasheet states a maximum discharge of 200mA, R = 5V / 0.2
1212
13inline double NETLIB_NAME(NE555)::clamp(const double v, const double a, const double b)
13inline nl_double NETLIB_NAME(NE555)::clamp(const nl_double v, const nl_double a, const nl_double b)
1414{
15   double ret = v;
16   double vcc = TERMANALOG(m_R1.m_P);
15   nl_double ret = v;
16   nl_double vcc = TERMANALOG(m_R1.m_P);
1717
1818   if (ret >  vcc - a)
1919      ret = vcc - a;
r243831r243832
6464{
6565   // FIXME: assumes GND is connected to 0V.
6666
67   double vt = clamp(TERMANALOG(m_R2.m_P), 0.7, 1.4);
67   nl_double vt = clamp(TERMANALOG(m_R2.m_P), 0.7, 1.4);
6868   bool bthresh = (INPANALOG(m_THRES) > vt);
6969   bool btrig = (INPANALOG(m_TRIG) > clamp(TERMANALOG(m_R2.m_N), 0.7, 1.4));
7070   bool out = m_last_out;
branches/kale/src/emu/netlist/devices/nld_ne555.h
r243831r243832
3939
4040   netlist_state_t<bool> m_last_out;
4141
42   inline double clamp(const double v, const double a, const double b);
42   inline nl_double clamp(const nl_double v, const nl_double a, const nl_double b);
4343
4444);
4545
branches/kale/src/emu/netlist/devices/nld_r2r_dac.c
r243831r243832
3232
3333   update_dev();
3434
35   double V = m_VIN.Value() / (double) (1 << m_num.Value()) * (double) m_val.Value();
35   nl_double V = m_VIN.Value() / (double) (1 << m_num.Value()) * (double) m_val.Value();
3636
3737   this->set(1.0 / m_R.Value(), V, 0.0);
3838}
branches/kale/src/emu/netlist/devices/nld_system.c
r243831r243832
118118   if (state != m_last_state)
119119   {
120120      m_last_state = state;
121      const double R = state ? m_logic_family->m_R_high : m_logic_family->m_R_low;
122      const double V = state ? m_logic_family->m_high_V : m_logic_family->m_low_V;
121      const nl_double R = state ? m_logic_family->m_R_high : m_logic_family->m_R_low;
122      const nl_double V = state ? m_logic_family->m_high_V : m_logic_family->m_low_V;
123123
124124      // We only need to update the net first if this is a time stepping net
125125      if (m_RV.m_P.net().as_analog().solver()->is_timestep())
branches/kale/src/emu/netlist/nl_base.c
r243831r243832
170170   netlist_object_t::save_register();
171171}
172172
173ATTR_HOT const double netlist_base_t::gmin() const
173ATTR_HOT const nl_double netlist_base_t::gmin() const
174174{
175175   return solver()->gmin();
176176}
r243831r243832
452452}
453453
454454template ATTR_COLD void netlist_device_t::register_param(const pstring &sname, netlist_param_double_t &param, const double initialVal);
455template ATTR_COLD void netlist_device_t::register_param(const pstring &sname, netlist_param_double_t &param, const float initialVal);
455456template ATTR_COLD void netlist_device_t::register_param(const pstring &sname, netlist_param_int_t &param, const int initialVal);
456457template ATTR_COLD void netlist_device_t::register_param(const pstring &sname, netlist_param_logic_t &param, const int initialVal);
457458template ATTR_COLD void netlist_device_t::register_param(const pstring &sname, netlist_param_str_t &param, const char * const initialVal);
r243831r243832
874875   net().as_analog().m_cur_Analog = 0.98;
875876}
876877
877ATTR_COLD void netlist_analog_output_t::initial(const double val)
878ATTR_COLD void netlist_analog_output_t::initial(const nl_double val)
878879{
879880   net().as_analog().m_cur_Analog = val * 0.99;
880881}
r243831r243832
931932}
932933
933934
934ATTR_COLD double netlist_param_model_t::model_value(const pstring &entity, const double defval) const
935ATTR_COLD nl_double netlist_param_model_t::model_value(const pstring &entity, const nl_double defval) const
935936{
936937   pstring tmp = this->Value();
937938   // .model 1N914 D(Is=2.52n Rs=.568 N=1.752 Cjo=4p M=.4 tt=20n Iave=200m Vpk=75 mfg=OnSemi type=silicon)
r243831r243832
945946      if (pequal < 0)
946947         netlist().error("parameter %s misformat in model %s temp %s\n", entity.cstr(), Value().cstr(), tmp.cstr());
947948      tmp = tmp.substr(pequal+1);
948      double factor = 1.0;
949      nl_double factor = 1.0;
949950      switch (*(tmp.right(1).cstr()))
950951      {
951952         case 'm': factor = 1e-3; break;
branches/kale/src/emu/netlist/nl_base.h
r243831r243832
272272
273273struct netlist_logic_family_desc_t
274274{
275   double m_low_thresh_V;
276   double m_high_thresh_V;
277   double m_low_V;
278   double m_high_V;
279   double m_R_low;
280   double m_R_high;
275   nl_double m_low_thresh_V;
276   nl_double m_high_thresh_V;
277   nl_double m_low_V;
278   nl_double m_high_V;
279   nl_double m_R_low;
280   nl_double m_R_high;
281281};
282282
283283/* Terminals inherit the family description from the netlist_device
r243831r243832
474474
475475   ATTR_COLD netlist_terminal_t();
476476
477   double *m_Idr1; // drive current
478   double *m_go1;  // conductance for Voltage from other term
479   double *m_gt1;  // conductance for total conductance
477   nl_double *m_Idr1; // drive current
478   nl_double *m_go1;  // conductance for Voltage from other term
479   nl_double *m_gt1;  // conductance for total conductance
480480
481   ATTR_HOT inline void set(const double G)
481   ATTR_HOT inline void set(const nl_double G)
482482   {
483483      set_ptr(m_Idr1, 0);
484484      set_ptr(m_go1, G);
485485      set_ptr(m_gt1, G);
486486   }
487487
488   ATTR_HOT inline void set(const double GO, const double GT)
488   ATTR_HOT inline void set(const nl_double GO, const nl_double GT)
489489   {
490490      set_ptr(m_Idr1, 0);
491491      set_ptr(m_go1, GO);
492492      set_ptr(m_gt1, GT);
493493   }
494494
495   ATTR_HOT inline void set(const double GO, const double GT, const double I)
495   ATTR_HOT inline void set(const nl_double GO, const nl_double GT, const nl_double I)
496496   {
497497      set_ptr(m_Idr1, I);
498498      set_ptr(m_go1, GO);
r243831r243832
509509
510510   ATTR_COLD virtual void reset();
511511private:
512   inline void set_ptr(double *ptr, const double val)
512   inline void set_ptr(nl_double *ptr, const nl_double val)
513513   {
514514      if (ptr != NULL)
515515         *ptr = val;
r243831r243832
586586   ATTR_COLD netlist_analog_input_t()
587587      : netlist_input_t(INPUT, ANALOG) { }
588588
589   ATTR_HOT inline const double Q_Analog() const;
589   ATTR_HOT inline const nl_double Q_Analog() const;
590590};
591591
592592//#define INPVAL(_x) (_x).Q()
r243831r243832
661661   // We have to have those on one object. Dividing those does lead
662662   // to a significant performance hit
663663   // FIXME: Have to fix the public at some time
664   double m_cur_Analog;
664   nl_double m_cur_Analog;
665665
666666};
667667
r243831r243832
736736   ATTR_COLD netlist_analog_net_t();
737737   ATTR_COLD virtual ~netlist_analog_net_t() { };
738738
739   ATTR_HOT inline const double Q_Analog() const
739   ATTR_HOT inline const nl_double Q_Analog() const
740740   {
741741      //nl_assert(object_type(SIGNAL_MASK) == SIGNAL_ANALOG);
742742      nl_assert(family() == ANALOG);
743743      return m_cur_Analog;
744744   }
745745
746   ATTR_COLD inline double &Q_Analog_state_ptr()
746   ATTR_COLD inline nl_double &Q_Analog_state_ptr()
747747   {
748748      //nl_assert(object_type(SIGNAL_MASK) == SIGNAL_ANALOG);
749749      nl_assert(family() == ANALOG);
r243831r243832
764764private:
765765
766766public:
767   double m_DD_n_m_1;
768   double m_h_n_m_1;
767   nl_double m_DD_n_m_1;
768   nl_double m_h_n_m_1;
769769
770770   //FIXME: needed by current solver code
771771   netlist_matrix_solver_t *m_solver;
r243831r243832
831831
832832   ATTR_COLD netlist_analog_output_t();
833833
834   ATTR_COLD void initial(const double val);
834   ATTR_COLD void initial(const nl_double val);
835835
836   ATTR_HOT inline void set_Q(const double newQ);
836   ATTR_HOT inline void set_Q(const nl_double newQ);
837837
838838   netlist_analog_net_t *m_proxied_net; // only for proxy nets in analog input logic
839839
r243831r243832
876876public:
877877   ATTR_COLD netlist_param_double_t();
878878
879   ATTR_HOT inline void setTo(const double param);
880   ATTR_COLD inline void initial(const double val) { m_param = val; }
881   ATTR_HOT inline const double Value() const        { return m_param;   }
879   ATTR_HOT inline void setTo(const nl_double param);
880   ATTR_COLD inline void initial(const nl_double val) { m_param = val; }
881   ATTR_HOT inline const nl_double Value() const        { return m_param;   }
882882
883883protected:
884884   ATTR_COLD virtual void save_register()
r243831r243832
888888   }
889889
890890private:
891   double m_param;
891   nl_double m_param;
892892};
893893
894894class netlist_param_int_t : public netlist_param_t
r243831r243832
946946   ATTR_HOT inline const pstring &Value() const     { return m_param;     }
947947
948948   /* these should be cached! */
949   ATTR_COLD double model_value(const pstring &entity, const double defval = 0.0) const;
949   ATTR_COLD nl_double model_value(const pstring &entity, const nl_double defval = 0.0) const;
950950   ATTR_COLD const pstring model_type() const;
951951
952952private:
r243831r243832
997997      out.set_Q(val, delay);
998998   }
999999
1000   ATTR_HOT inline const double INPANALOG(const netlist_analog_input_t &inp) const { return inp.Q_Analog(); }
1000   ATTR_HOT inline const nl_double INPANALOG(const netlist_analog_input_t &inp) const { return inp.Q_Analog(); }
10011001
1002   ATTR_HOT inline const double TERMANALOG(const netlist_terminal_t &term) const { return term.net().as_analog().Q_Analog(); }
1002   ATTR_HOT inline const nl_double TERMANALOG(const netlist_terminal_t &term) const { return term.net().as_analog().Q_Analog(); }
10031003
1004   ATTR_HOT inline void OUTANALOG(netlist_analog_output_t &out, const double val)
1004   ATTR_HOT inline void OUTANALOG(netlist_analog_output_t &out, const nl_double val)
10051005   {
10061006      out.set_Q(val);
10071007   }
r243831r243832
10101010
10111011   ATTR_HOT virtual void dec_active() {  }
10121012
1013   ATTR_HOT virtual void step_time(const double st) { }
1013   ATTR_HOT virtual void step_time(const nl_double st) { }
10141014   ATTR_HOT virtual void update_terminals() { }
10151015
10161016
r243831r243832
11201120   ATTR_HOT inline const netlist_time time() const { return m_time; }
11211121   ATTR_HOT inline NETLIB_NAME(solver) *solver() const { return m_solver; }
11221122   ATTR_HOT inline NETLIB_NAME(gnd) *gnd() const { return m_gnd; }
1123   ATTR_HOT const double gmin() const;
1123   ATTR_HOT const nl_double gmin() const;
11241124
11251125   ATTR_HOT inline void push_to_queue(netlist_net_t *out, const netlist_time attime)
11261126   {
r243831r243832
12511251   }
12521252}
12531253
1254ATTR_HOT inline void netlist_param_double_t::setTo(const double param)
1254ATTR_HOT inline void netlist_param_double_t::setTo(const nl_double param)
12551255{
12561256   if (m_param != param)
12571257   {
r243831r243832
13561356   return net().as_logic().Q();
13571357}
13581358
1359ATTR_HOT inline const double netlist_analog_input_t::Q_Analog() const
1359ATTR_HOT inline const nl_double netlist_analog_input_t::Q_Analog() const
13601360{
13611361   return net().as_analog().Q_Analog();
13621362}
13631363
1364ATTR_HOT inline void netlist_analog_output_t::set_Q(const double newQ)
1364ATTR_HOT inline void netlist_analog_output_t::set_Q(const nl_double newQ)
13651365{
13661366   if (newQ != net().as_analog().m_cur_Analog)
13671367   {
branches/kale/src/emu/netlist/nl_config.h
r243831r243832
4949
5050#define NETLIST_GMIN_DEFAULT    (1e-9)
5151
52//typedef double   nl_double;
53
54#define nl_double double
55
5256//============================================================
5357//  DEBUGGING
5458//============================================================
branches/kale/src/emu/netlist/nl_dice_compat.h
r243831r243832
3030struct Mono555Desc
3131{
3232public:
33      double r, c;
33      nl_double r, c;
3434
35      Mono555Desc(double res, double cap) : r(res), c(cap) { }
35      Mono555Desc(nl_double res, nl_double cap) : r(res), c(cap) { }
3636};
3737
3838struct SeriesRCDesc
3939{
4040public:
41      double r, c;
41      nl_double r, c;
4242
43      SeriesRCDesc(double res, double cap) : r(res), c(cap) { }
43      SeriesRCDesc(nl_double res, nl_double cap) : r(res), c(cap) { }
4444};
4545
4646#define CHIP_555_Mono(_name,  _pdesc)   \
branches/kale/src/emu/netlist/nl_parser.c
r243831r243832
399399void netlist_parser::netdev_param()
400400{
401401   pstring param;
402   double val;
402   nl_double val;
403403   param = get_identifier();
404404   require_token(m_tok_comma);
405405   val = eval_param(get_token());
r243831r243832
439439      }
440440      else
441441      {
442         double val = eval_param(tok);
442         nl_double val = eval_param(tok);
443443         m_setup.register_param(paramfq, val);
444444      }
445445      cnt++;
r243831r243832
467467// ----------------------------------------------------------------------------------------
468468
469469
470double netlist_parser::eval_param(const token_t tok)
470nl_double netlist_parser::eval_param(const token_t tok)
471471{
472472   static const char *macs[6] = {"", "RES_K", "RES_M", "CAP_U", "CAP_N", "CAP_P"};
473   static double facs[6] = {1, 1e3, 1e6, 1e-6, 1e-9, 1e-12};
473   static nl_double facs[6] = {1, 1e3, 1e6, 1e-6, 1e-9, 1e-12};
474474   int i;
475475   int f=0;
476476   bool e;
477   double ret;
477   nl_double ret;
478478   pstring val;
479479
480480   //printf("param %s\n", tok.m_token.cstr());
branches/kale/src/emu/netlist/nl_parser.h
r243831r243832
160160   virtual void verror(pstring msg, int line_num, pstring line);
161161private:
162162
163   double eval_param(const token_t tok);
163   nl_double eval_param(const token_t tok);
164164
165165   token_id_t m_tok_param_left;
166166   token_id_t m_tok_param_right;
branches/kale/src/emu/netlist/pstate.c
r243831r243832
2323         "DT_INT16",
2424         "DT_INT8",
2525         "DT_INT",
26         "DT_BOOLEAN"
26         "DT_BOOLEAN",
27            "DT_FLOAT"
2728   };
2829
2930   NL_VERBOSE_OUT(("SAVE: <%s> %s(%d) %p\n", fullname.cstr(), ts[dt].cstr(), size, ptr));
branches/kale/src/emu/netlist/pstate.h
r243831r243832
3232   DT_INT16,
3333   DT_INT8,
3434   DT_INT,
35   DT_BOOLEAN
35   DT_BOOLEAN,
36   DT_FLOAT
3637};
3738
3839template<typename _ItemType> struct nl_datatype
r243831r243832
5556
5657NETLIST_SAVE_TYPE(char, DT_INT8);
5758NETLIST_SAVE_TYPE(double, DT_DOUBLE);
59NETLIST_SAVE_TYPE(float, DT_FLOAT);
5860NETLIST_SAVE_TYPE(INT8, DT_INT8);
5961NETLIST_SAVE_TYPE(UINT8, DT_INT8);
6062NETLIST_SAVE_TYPE(INT64, DT_INT64);
branches/kale/src/emu/netlist/pstring.c
r243831r243832
108108   return 1;
109109}
110110
111double pstring::as_double(bool *error) const
111nl_double pstring::as_double(bool *error) const
112112{
113   double ret;
113   nl_double ret;
114114   char *e = NULL;
115115
116116   if (error != NULL)
r243831r243832
124124
125125long pstring::as_long(bool *error) const
126126{
127   double ret;
127   nl_double ret;
128128   char *e = NULL;
129129
130130   if (error != NULL)
branches/kale/src/emu/netlist/pstring.h
r243831r243832
159159
160160   // conversions
161161
162   double as_double(bool *error = NULL) const;
162   nl_double as_double(bool *error = NULL) const;
163163
164164   long as_long(bool *error = NULL) const;
165165
branches/kale/src/mame/includes/mario.h
r243831r243832
33
44#include "machine/z80dma.h"
55
6#define OLD_SOUND   (1)
6#define OLD_SOUND   (0)
77
88#if !OLD_SOUND
99#include "machine/netlist.h"


Previous 199869 Revisions Next


© 1997-2024 The MAME Team