diff --git a/tgt-blif/lpm_mux.cc b/tgt-blif/lpm_mux.cc index d0b5b6c2c..944e87099 100644 --- a/tgt-blif/lpm_mux.cc +++ b/tgt-blif/lpm_mux.cc @@ -20,9 +20,17 @@ # include "priv.h" # include "nex_data.h" +# include # include -int print_lpm_mux(FILE*fd, ivl_lpm_t net) +using namespace std; + +/* + * This handles the special case that the select port to the MUX is a + * single bit. In other words, a binary mux. This may have an + * arbitrary data width, but it selects from input A or input B. + */ +static int print_lpm_mux_s1(FILE*fd, ivl_lpm_t net) { ivl_nexus_t nex_out = ivl_lpm_q(net); blif_nex_data_t*ned_out = blif_nex_data_t::get_nex_data(nex_out); @@ -55,3 +63,66 @@ int print_lpm_mux(FILE*fd, ivl_lpm_t net) return 0; } + +static int print_lpm_mux_sN(FILE*fd, ivl_lpm_t net) +{ + ivl_nexus_t nex_out = ivl_lpm_q(net); + blif_nex_data_t*ned_out = blif_nex_data_t::get_nex_data(nex_out); + + ivl_nexus_t nex_sel = ivl_lpm_select(net); + blif_nex_data_t*ned_sel = blif_nex_data_t::get_nex_data(nex_sel); + + vector ned_d (ivl_lpm_size(net)); + for (size_t idx = 0 ; idx < ned_d.size() ; idx += 1) { + ivl_nexus_t tmp = ivl_lpm_data(net,idx); + ned_d[idx] = blif_nex_data_t::get_nex_data(tmp); + } + + for (unsigned wid = 0 ; wid < ivl_lpm_width(net) ; wid += 1) { + // First, print the names record with all the ports... + fprintf(fd, ".names"); + for (size_t idx = 0 ; idx < ned_sel->get_width() ; idx += 1) { + fprintf(fd, " %s%s", ned_sel->get_name(), ned_sel->get_name_index(idx)); + } + + for (size_t idx = 0 ; idx < ned_d.size() ; idx += 1) { + fprintf(fd, " %s%s", ned_d[idx]->get_name(), + ned_d[idx]->get_name_index(wid)); + } + + fprintf(fd, " %s%s\n", ned_out->get_name(), ned_out->get_name_index(wid)); + + // Print the logic table. We need one line for each + // select address. The select pins must exactly match + // the select address. The output depends only on the + // select D input. + for (size_t didx = 0 ; didx < ned_d.size() ; didx += 1) { + + for (size_t idx = 0 ; idx < ned_sel->get_width() ; idx += 1) { + if (didx & (1<