blif code generator support for arbitrary MUX devices.

This commit is contained in:
Stephen Williams 2013-08-16 20:54:51 -07:00
parent ec99faff05
commit a6fb6be8b5
1 changed files with 72 additions and 1 deletions

View File

@ -20,9 +20,17 @@
# include "priv.h"
# include "nex_data.h"
# include <vector>
# include <cassert>
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<blif_nex_data_t*> 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<<idx))
fputc('1', fd);
else
fputc('0', fd);
}
for (size_t idx = 0 ; idx < ned_d.size() ; idx += 1) {
if (didx == idx)
fputc('1', fd);
else
fputc('-', fd);
}
fprintf(fd, " 1\n");
}
}
return 0;
}
int print_lpm_mux(FILE*fd, ivl_lpm_t net)
{
if (ivl_lpm_selects(net) == 1)
return print_lpm_mux_s1(fd, net);
else
return print_lpm_mux_sN(fd, net);
}