From 07645b6670074249817c208a561883bed10eb898 Mon Sep 17 00:00:00 2001 From: couriersud Date: Fri, 8 Apr 2016 17:02:33 +0200 Subject: [PATCH] Minor changes, mostly signed comparisons and adding includes for dependency documentation. --- src/lib/netlist/build/makefile | 9 ++++---- src/lib/netlist/macro/nlm_ttl74xx.cpp | 4 ++-- src/lib/netlist/macro/nlm_ttl74xx.h | 4 ++-- src/lib/netlist/plib/plists.h | 2 +- src/lib/netlist/solver/mat_cr.h | 14 +++++++------ src/lib/netlist/solver/nld_ms_direct.h | 5 +++-- src/lib/netlist/solver/nld_ms_direct_lu.h | 1 + src/lib/netlist/solver/nld_ms_sm.h | 25 ++++++++++++----------- src/lib/netlist/solver/nld_ms_w.h | 16 +++++++-------- 9 files changed, 42 insertions(+), 38 deletions(-) diff --git a/src/lib/netlist/build/makefile b/src/lib/netlist/build/makefile index 19742fc9b31..be49d098a0d 100644 --- a/src/lib/netlist/build/makefile +++ b/src/lib/netlist/build/makefile @@ -18,10 +18,10 @@ SRC = .. CDEFS = -DPSTANDALONE=1 -DPTR64=1 #-Werror -CFLAGS = $(LTO) -g -O3 -std=c++98 -Doverride="" -march=native -msse4.2 -Wall -Wpedantic -Wsign-compare -Wextra -Wno-long-long -Wno-unused-parameter -Wno-unused-result -Wno-variadic-macros -I.. -LDFLAGS = $(LTO) -g -O3 -std=c++98 -#CFLAGS = $(LTO) -g -O3 -std=c++11 -Wall -Wpedantic -Wsign-compare -Wextra -Isrc -#LDFLAGS = $(LTO) -g -O3 -std=c++11 +#CFLAGS = $(LTO) -g -O3 -std=c++98 -Doverride="" -march=native -msse4.2 -Wall -Wpedantic -Wsign-compare -Wextra -Wno-long-long -Wno-unused-parameter -Wno-unused-result -Wno-variadic-macros -I.. +#LDFLAGS = $(LTO) -g -O3 -std=c++98 +CFLAGS = $(LTO) -g -O3 -std=c++11 -I.. -Wall -Wpedantic -Wsign-compare -Wextra -Wno-unused-parameter +LDFLAGS = $(LTO) -g -O3 -std=c++11 CC = @g++-5 LD = @g++-5 @@ -66,7 +66,6 @@ NLOBJS := \ $(NLOBJ)/analog/nld_opamps.o \ $(NLOBJ)/devices/nld_4020.o \ $(NLOBJ)/devices/nld_4066.o \ - $(NLOBJ)/devices/nld_7400.o \ $(NLOBJ)/devices/nld_7402.o \ $(NLOBJ)/devices/nld_7404.o \ $(NLOBJ)/devices/nld_7408.o \ diff --git a/src/lib/netlist/macro/nlm_ttl74xx.cpp b/src/lib/netlist/macro/nlm_ttl74xx.cpp index ed74a8e305c..96038049473 100644 --- a/src/lib/netlist/macro/nlm_ttl74xx.cpp +++ b/src/lib/netlist/macro/nlm_ttl74xx.cpp @@ -30,7 +30,7 @@ NETLIST_START(TTL_7416_DIP) s3.A, /* A3 |5 10| Y5 */ s5.Q, s3.Q, /* Y3 |6 9| A4 */ s4.A, GND.I, /* GND |7 8| Y4 */ s4.Q - /* +--------------+ */ + /* +--------------+ */ ) NETLIST_END() @@ -69,7 +69,7 @@ NETLIST_START(TTL_7400_DIP) s2.B, /* B2 |5 10| B3 */ s3.B, s2.Q, /* Y2 |6 9| A3 */ s3.A, GND.I, /* GND |7 8| Y3 */ s3.Q - /* +--------------+ */ + /* +--------------+ */ ) NETLIST_END() diff --git a/src/lib/netlist/macro/nlm_ttl74xx.h b/src/lib/netlist/macro/nlm_ttl74xx.h index cd502aa4782..763ee5620ca 100644 --- a/src/lib/netlist/macro/nlm_ttl74xx.h +++ b/src/lib/netlist/macro/nlm_ttl74xx.h @@ -14,8 +14,8 @@ #define TTL_7400_GATE(_name) \ NET_REGISTER_DEV(TTL_7400_GATE, _name) #define TTL_7400_NAND(_name, _A, _B) \ - NET_REGISTER_DEV(TTL_7400_NAND, _name) \ - NET_CONNECT(_name, A, _A) \ + NET_REGISTER_DEV(TTL_7400_NAND, _name) \ + NET_CONNECT(_name, A, _A) \ NET_CONNECT(_name, B, _B) #define TTL_7400_DIP(_name) \ diff --git a/src/lib/netlist/plib/plists.h b/src/lib/netlist/plib/plists.h index f5d395f4628..43aa28a229a 100644 --- a/src/lib/netlist/plib/plists.h +++ b/src/lib/netlist/plib/plists.h @@ -126,7 +126,7 @@ public: int indexof(const _ListClass &elem) const { - for (int i = 0; i < this->size(); i++) + for (unsigned i = 0; i < this->size(); i++) { if (this->at(i) == elem) return i; diff --git a/src/lib/netlist/solver/mat_cr.h b/src/lib/netlist/solver/mat_cr.h index ea72884c1de..d259fa40df1 100644 --- a/src/lib/netlist/solver/mat_cr.h +++ b/src/lib/netlist/solver/mat_cr.h @@ -34,7 +34,7 @@ struct mat_cr_t while (k < oe) { - double tmp = 0.0; + T tmp = 0.0; const unsigned e = ia[i+1]; for (; k < e; k++) tmp += A[k] * x[ja[k]]; @@ -42,7 +42,8 @@ struct mat_cr_t } } - void incomplete_LU_factorization(const nl_double * RESTRICT A, nl_double * RESTRICT LU) + template + void incomplete_LU_factorization(const T * RESTRICT A, T * RESTRICT LU) { /* * incomplete LU Factorization according to http://de.wikipedia.org/wiki/ILU-Zerlegung @@ -64,7 +65,7 @@ struct mat_cr_t // pk == (i, k) const unsigned k = ja[pk]; const unsigned iak1 = ia[k + 1]; - const double LUpk = LU[pk] = LU[pk] / LU[diag[k]]; + const T LUpk = LU[pk] = LU[pk] / LU[diag[k]]; unsigned pt = ia[k]; @@ -81,7 +82,8 @@ struct mat_cr_t } } - void solveLUx (const nl_double * RESTRICT LU, nl_double * RESTRICT r) + template + void solveLUx (const T * RESTRICT LU, T * RESTRICT r) { /* * Solve a linear equation Ax = r @@ -109,7 +111,7 @@ struct mat_cr_t for (i = 1; ia[i] < nz_num; i++ ) { - double tmp = 0.0; + T tmp = 0.0; const unsigned j1 = ia[i]; const unsigned j2 = diag[i]; @@ -122,7 +124,7 @@ struct mat_cr_t for (; 0 < i; i-- ) { const unsigned im1 = i - 1; - double tmp = 0.0; + T tmp = 0.0; const unsigned j1 = diag[im1] + 1; const unsigned j2 = ia[im1+1]; for (unsigned j = j1; j < j2; j++ ) diff --git a/src/lib/netlist/solver/nld_ms_direct.h b/src/lib/netlist/solver/nld_ms_direct.h index dbd8929a725..f0c892ab698 100644 --- a/src/lib/netlist/solver/nld_ms_direct.h +++ b/src/lib/netlist/solver/nld_ms_direct.h @@ -11,6 +11,7 @@ #include #include "solver/nld_solver.h" +#include "solver/nld_matrix_solver.h" #include "solver/vector_base.h" /* Disabling dynamic allocation gives a ~10% boost in performance @@ -133,7 +134,7 @@ protected: virtual int vsolve_non_dynamic(const bool newton_raphson) override; int solve_non_dynamic(const bool newton_raphson); - inline const unsigned N() const { if (m_N == 0) return m_dim; else return m_N; } + inline unsigned N() const { if (m_N == 0) return m_dim; else return m_N; } void build_LE_A(); void build_LE_RHS(); @@ -574,7 +575,7 @@ void matrix_solver_direct_t::LE_solve() #else vec_add_mult_scalar(kN-i-1,pj,f1,pi); //for (unsigned k = i+1; k < kN; k++) - // pj[k] = pj[k] + pi[k] * f1; + // pj[k] = pj[k] + pi[k] * f1; //for (unsigned k = i+1; k < kN; k++) //A(j,k) += A(i,k) * f1; RHS(j) += RHS(i) * f1; diff --git a/src/lib/netlist/solver/nld_ms_direct_lu.h b/src/lib/netlist/solver/nld_ms_direct_lu.h index 2109b0f3e41..757970e5c07 100644 --- a/src/lib/netlist/solver/nld_ms_direct_lu.h +++ b/src/lib/netlist/solver/nld_ms_direct_lu.h @@ -11,6 +11,7 @@ #include #include "solver/nld_solver.h" +#include "solver/nld_matrix_solver.h" //#define A(_r, _c) m_A[_r][_c] diff --git a/src/lib/netlist/solver/nld_ms_sm.h b/src/lib/netlist/solver/nld_ms_sm.h index efac84b51da..5204d744ddf 100644 --- a/src/lib/netlist/solver/nld_ms_sm.h +++ b/src/lib/netlist/solver/nld_ms_sm.h @@ -13,9 +13,9 @@ * In this specific implementation, u is a unit vector specifying the row which * changed. Thus v contains the changed column. * - * Than z = A????? u , w = transpose(A?????) v , lambda = v z + * Than z = A⁻¹ u , w = transpose(A⁻¹) v , lambda = v z * - * A????? <- 1.0 / (1.0 + lambda) * (z x w) + * A⁻¹ <- 1.0 / (1.0 + lambda) * (z x w) * * The approach is iterative and applied for each row changed. * @@ -36,6 +36,7 @@ #include #include "solver/nld_solver.h" +#include "solver/nld_matrix_solver.h" #include "solver/vector_base.h" NETLIB_NAMESPACE_DEVICES_START() @@ -62,7 +63,7 @@ protected: virtual int vsolve_non_dynamic(const bool newton_raphson) override; int solve_non_dynamic(const bool newton_raphson); - inline const unsigned N() const { if (m_N == 0) return m_dim; else return m_N; } + inline unsigned N() const { if (m_N == 0) return m_dim; else return m_N; } void build_LE_A(); void build_LE_RHS(); @@ -454,14 +455,14 @@ void matrix_solver_sm_t::LE_compute_x( { const unsigned kN = N(); - for (int i=0; i::solve_non_dynamic(ATTR_UNUSED const boo } else { - if (!incremental) + if (not incremental) { - for (int row = 0; row < iN; row ++) - for (int k = 0; k < iN; k++) + for (unsigned row = 0; row < iN; row ++) + for (unsigned k = 0; k < iN; k++) Ainv(row,k) = lAinv(row, k); } - for (int row = 0; row < iN; row ++) + for (unsigned row = 0; row < iN; row ++) { nl_double v[m_pitch] = {0}; unsigned cols[m_pitch]; @@ -555,11 +556,11 @@ int matrix_solver_sm_t::solve_non_dynamic(ATTR_UNUSED const boo } lamba = -1.0 / (1.0 + lamba); - for (int i=0; i #include "solver/nld_solver.h" +#include "solver/nld_matrix_solver.h" #include "solver/vector_base.h" NETLIB_NAMESPACE_DEVICES_START() @@ -69,7 +70,7 @@ protected: virtual int vsolve_non_dynamic(const bool newton_raphson) override; int solve_non_dynamic(const bool newton_raphson); - inline const unsigned N() const { if (m_N == 0) return m_dim; else return m_N; } + inline unsigned N() const { if (m_N == 0) return m_dim; else return m_N; } void build_LE_A(); void build_LE_RHS(); @@ -467,14 +468,14 @@ void matrix_solver_w_t::LE_compute_x( { const unsigned kN = N(); - for (int i=0; i::solve_non_dynamic(ATTR_UNUSED const bool unsigned rowcount=0; #define VT(r,c) (A(r,c) - lA(r,c)) - for (int row = 0; row < iN; row ++) + for (unsigned row = 0; row < iN; row ++) { unsigned cc=0; auto &nz = m_terms[row]->m_nz; @@ -596,7 +597,7 @@ int matrix_solver_w_t::solve_non_dynamic(ATTR_UNUSED const bool } /* Back substitution */ //inv(H) w = t w = H t - nl_double *t = new nl_double[rowcount]; + nl_double t[_storage_N]; // FIXME: convert to member for (int j = rowcount - 1; j >= 0; j--) { nl_double tmp = 0; @@ -619,7 +620,6 @@ int matrix_solver_w_t::solve_non_dynamic(ATTR_UNUSED const bool } new_V[i] -= tmp; } - delete[] t; } } m_cnt++;