diff options
author | 2020-06-13 15:58:27 +0200 | |
---|---|---|
committer | 2020-06-13 15:58:27 +0200 | |
commit | 284f196df1c65a91eb38a5a9f31a2da7fb86a1ac (patch) | |
tree | d29473e4024dce305d0ee3bb957a663420417312 /src/lib/netlist/solver/nld_ms_gcr.h | |
parent | 52b8d5fd2b656c317e589da93467c33be74e76ea (diff) | |
parent | e949e9c29de82ee7c32692e7b65da05dd22bdc9d (diff) |
Merge branch 'master' of https://github.com/mamedev/mame
Diffstat (limited to 'src/lib/netlist/solver/nld_ms_gcr.h')
-rw-r--r-- | src/lib/netlist/solver/nld_ms_gcr.h | 66 |
1 files changed, 52 insertions, 14 deletions
diff --git a/src/lib/netlist/solver/nld_ms_gcr.h b/src/lib/netlist/solver/nld_ms_gcr.h index 72e5c45f525..3de955627ee 100644 --- a/src/lib/netlist/solver/nld_ms_gcr.h +++ b/src/lib/netlist/solver/nld_ms_gcr.h @@ -12,7 +12,8 @@ #include "plib/mat_cr.h" -#include "nld_ms_direct.h" +//#include "nld_ms_direct.h" +#include "nld_matrix_solver_ext.h" #include "nld_solver.h" #include "plib/pdynlib.h" #include "plib/pstream.h" @@ -31,6 +32,8 @@ namespace solver public: using mat_type = plib::pGEmatrix_cr_t<plib::pmatrix_cr_t<FT, SIZE>>; + using base_type = matrix_solver_ext_t<FT, SIZE>; + using fptype = typename base_type::fptype; matrix_solver_GCR_t(netlist_state_t &anetlist, const pstring &name, const analog_net_t::list_t &nets, @@ -85,9 +88,9 @@ namespace solver anetlist.log().verbose("maximum fill: {1}", gr.first); anetlist.log().verbose("Post elimination occupancy ratio: {2} Ops: {1}", gr.second, - static_cast<nl_fptype>(mat.nz_num) / static_cast<nl_fptype>(iN * iN)); + static_cast<fptype>(mat.nz_num) / static_cast<fptype>(iN * iN)); anetlist.log().verbose(" Pre elimination occupancy ratio: {2}", - static_cast<nl_fptype>(raw_elements) / static_cast<nl_fptype>(iN * iN)); + static_cast<fptype>(raw_elements) / static_cast<fptype>(iN * iN)); // FIXME: Move me // @@ -123,7 +126,7 @@ namespace solver pstring static_compile_name(); mat_type mat; - plib::dynproc<void, FT *, nl_fptype *, nl_fptype *, nl_fptype *, nl_fptype ** > m_proc; + plib::dynproc<void, FT *, fptype *, fptype *, fptype *, fptype ** > m_proc; }; @@ -139,7 +142,7 @@ namespace solver pstring fpsuffix(fp_constants<FT>::suffix()); for (std::size_t i = 0; i < mat.nz_num; i++) - strm("{1} m_A{2}(0.0);\n", fptype, i, i); + strm("\t{1} m_A{2}(0.0);\n", fptype, i, i); for (std::size_t k = 0; k < iN; k++) { @@ -150,23 +153,27 @@ namespace solver //auto gtot_t = std::accumulate(gt, gt + term_count, plib::constants<FT>::zero()); //*tcr_r[railstart] = static_cast<FT>(gtot_t); //mat.A[mat.diag[k]] += gtot_t; auto pd = this->m_mat_ptr[k][net.railstart()] - &this->mat.A[0]; +#if 0 pstring terms = plib::pfmt("m_A{1} = gt[{2}]")(pd, this->m_gtn.didx(k,0)); for (std::size_t i=1; i < net.count(); i++) terms += plib::pfmt(" + gt[{1}]")(this->m_gtn.didx(k,i)); strm("\t{1};\n", terms); - +#else + for (std::size_t i=0; i < net.count(); i++) + strm("\tm_A{1} += gt[{2}];\n", pd, this->m_gtn.didx(k,i)); +#endif //for (std::size_t i = 0; i < railstart; i++) // *tcr_r[i] += static_cast<FT>(go[i]); for (std::size_t i = 0; i < net.railstart(); i++) { auto p = this->m_mat_ptr[k][i] - &this->mat.A[0]; - strm("\tm_A{1} = m_A{1} + go[{2}];\n", p, this->m_gonn.didx(k,i)); + strm("\tm_A{1} += go[{2}];\n", p, this->m_gonn.didx(k,i)); } +#if 0 //auto RHS_t(std::accumulate(Idr, Idr + term_count, plib::constants<FT>::zero())); - terms = plib::pfmt("{1} RHS{2} = Idr[{3}]")(fptype, k, this->m_Idrn.didx(k,0)); for (std::size_t i=1; i < net.count(); i++) terms += plib::pfmt(" + Idr[{1}]")(this->m_Idrn.didx(k,i)); @@ -174,9 +181,21 @@ namespace solver // RHS_t += (- go[i]) * *cnV[i]; for (std::size_t i = net.railstart(); i < net.count(); i++) - terms += plib::pfmt(" - go[{1}] * *cnV[{1}]")(this->m_gonn.didx(k,i), this->m_connected_net_Vn.didx(k,i)); + terms += plib::pfmt(" - go[{1}] * *cnV[{2}]")(this->m_gonn.didx(k,i), this->m_connected_net_Vn.didx(k,i)); strm("\t{1};\n", terms); +#else + //auto RHS_t(std::accumulate(Idr, Idr + term_count, plib::constants<FT>::zero())); + strm("\t{1} RHS{2} = Idr[{3}];\n", fptype, k, this->m_Idrn.didx(k,0)); + for (std::size_t i=1; i < net.count(); i++) + strm("\tRHS{1} += Idr[{2}];\n", k, this->m_Idrn.didx(k,i)); + //for (std::size_t i = railstart; i < term_count; i++) + // RHS_t += (- go[i]) * *cnV[i]; + + for (std::size_t i = net.railstart(); i < net.count(); i++) + strm("\tRHS{1} -= go[{2}] * *cnV[{3}];\n", k, this->m_gonn.didx(k,i), this->m_connected_net_Vn.didx(k,i)); + +#endif } for (std::size_t i = 0; i < iN - 1; i++) @@ -188,7 +207,7 @@ namespace solver std::size_t pi = mat.diag[i]; //const FT f = 1.0 / m_A[pi++]; - strm("const {1} f{2} = 1.0{3} / m_A{4};\n", fptype, i, fpsuffix, pi); + strm("\tconst {1} f{2} = 1.0{3} / m_A{4};\n", fptype, i, fpsuffix, pi); pi++; const std::size_t piie = mat.row_idx[i+1]; @@ -224,6 +243,7 @@ namespace solver strm("\tV[{1}] = RHS{2} / m_A{3};\n", iN - 1, iN - 1, mat.diag[iN - 1]); for (std::size_t j = iN - 1; j-- > 0;) { +#if 1 strm("\t{1} tmp{2} = 0.0{3};\n", fptype, j, fpsuffix); const std::size_t e = mat.row_idx[j+1]; for (std::size_t pk = mat.diag[j] + 1; pk < e; pk++) @@ -231,6 +251,24 @@ namespace solver strm("\ttmp{1} += m_A{2} * V[{3}];\n", j, pk, mat.col_idx[pk]); } strm("\tV[{1}] = (RHS{1} - tmp{1}) / m_A{4};\n", j, j, j, mat.diag[j]); +#else + pstring tmp; + const std::size_t e = mat.row_idx[j+1]; + for (std::size_t pk = mat.diag[j] + 1; pk < e; pk++) + { + tmp = tmp + plib::pfmt(" + m_A{2} * V[{3}]")(j, pk, mat.col_idx[pk]); + } + if (tmp.empty()) + { + strm("\tV[{1}] = RHS{1} / m_A{2};\n", j, mat.diag[j]); + } + else + { + //strm("\tconst {1} tmp{2} = {3};\n", fptype, j, tmp.substr(3)); + //strm("\tV[{1}] = (RHS{1} - tmp{1}) / m_A{2};\n", j, mat.diag[j]); + strm("\tV[{1}] = (RHS{1} - ({2})) / m_A{3};\n", j, tmp.substr(3), mat.diag[j]); + } +#endif } } @@ -238,7 +276,7 @@ namespace solver pstring matrix_solver_GCR_t<FT, SIZE>::static_compile_name() { pstring str_floattype(fp_constants<FT>::name()); - pstring str_fptype(fp_constants<nl_fptype>::name()); + pstring str_fptype(fp_constants<fptype>::name()); std::stringstream t; t.imbue(std::locale::classic()); plib::putf8_fmt_writer w(&t); @@ -255,7 +293,7 @@ namespace solver plib::putf8_fmt_writer strm(&t); pstring name = static_compile_name(); pstring str_floattype(fp_constants<FT>::name()); - pstring str_fptype(fp_constants<nl_fptype>::name()); + pstring str_fptype(fp_constants<fptype>::name()); pstring extqual; if (target == CXX_EXTERNAL_C) @@ -263,8 +301,8 @@ namespace solver else if (target == CXX_STATIC) extqual = "static"; strm.writeline(plib::pfmt("{1} void {2}({3} * __restrict V, " - "{4} * __restrict go, {4} * __restrict gt, " - "{4} * __restrict Idr, {4} ** __restrict cnV)\n")(extqual, name, str_floattype, str_fptype)); + "const {4} * __restrict go, const {4} * __restrict gt, " + "const {4} * __restrict Idr, const {4} * const * __restrict cnV)\n")(extqual, name, str_floattype, str_fptype)); strm.writeline("{\n"); generate_code(strm); strm.writeline("}\n"); |