mirror of
https://github.com/YosysHQ/yosys
synced 2025-04-28 11:25:53 +00:00
ql_dsp_*: Clean up
Clean up the code up to Yosys standards. Drop detection of QL_DSP2_MULTADD in io_regs since those cells can't be inferred with the current flow anyway.
This commit is contained in:
parent
6d7dafe5e5
commit
306e688406
2 changed files with 148 additions and 319 deletions
|
@ -30,26 +30,24 @@ PRIVATE_NAMESPACE_BEGIN
|
|||
// ============================================================================
|
||||
|
||||
struct QlDspIORegs : public Pass {
|
||||
|
||||
const std::vector<std::string> ports2del_mult = {"load_acc", "subtract", "acc_fir", "dly_b"};
|
||||
const std::vector<std::string> ports2del_mult = {"load_acc", "subtract", "acc_fir", "dly_b",
|
||||
"saturate_enable", "shift_right", "round"};
|
||||
const std::vector<std::string> ports2del_mult_acc = {"acc_fir", "dly_b"};
|
||||
const std::vector<std::string> ports2del_mult_add = {"dly_b"};
|
||||
const std::vector<std::string> ports2del_extension = {"saturate_enable", "shift_right", "round"};
|
||||
|
||||
/// Temporary SigBit to SigBit helper map.
|
||||
SigMap m_SigMap;
|
||||
SigMap sigmap;
|
||||
|
||||
// ..........................................
|
||||
|
||||
QlDspIORegs() : Pass("ql_dsp_io_regs", "Changes types of QL_DSP2/QL_DSP3 depending on their configuration.") {}
|
||||
QlDspIORegs() : Pass("ql_dsp_io_regs", "change types of QL_DSP2 depending on configuration") {}
|
||||
|
||||
void help() override
|
||||
{
|
||||
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
||||
log("\n");
|
||||
log(" ql_dsp_io_regs [options] [selection]\n");
|
||||
log("\n");
|
||||
log("Looks for QL_DSP2/QL_DSP3 cells and changes their types depending\n");
|
||||
log("on their configuration.\n");
|
||||
log("This pass looks for QL_DSP2 cells and changes their cell type depending on their\n");
|
||||
log("configuration.\n");
|
||||
}
|
||||
|
||||
void execute(std::vector<std::string> a_Args, RTLIL::Design *a_Design) override
|
||||
|
@ -67,178 +65,92 @@ struct QlDspIORegs : public Pass {
|
|||
}
|
||||
}
|
||||
|
||||
// Returns a pair of mask and value describing constant bit connections of
|
||||
// a SigSpec
|
||||
std::pair<uint32_t, uint32_t> get_constant_mask_value(const RTLIL::SigSpec *sigspec)
|
||||
{
|
||||
uint32_t mask = 0L;
|
||||
uint32_t value = 0L;
|
||||
|
||||
auto sigbits = sigspec->bits();
|
||||
for (ssize_t i = (sigbits.size() - 1); i >= 0; --i) {
|
||||
auto other = m_SigMap(sigbits[i]);
|
||||
|
||||
mask <<= 1;
|
||||
value <<= 1;
|
||||
|
||||
// A known constant
|
||||
if (!other.is_wire() && other.data != RTLIL::Sx) {
|
||||
mask |= 0x1;
|
||||
value |= (other.data == RTLIL::S1);
|
||||
}
|
||||
}
|
||||
|
||||
return std::make_pair(mask, value);
|
||||
}
|
||||
|
||||
void ql_dsp_io_regs_pass(RTLIL::Module *module)
|
||||
{
|
||||
// Setup the SigMap
|
||||
m_SigMap.clear();
|
||||
m_SigMap.set(module);
|
||||
sigmap.set(module);
|
||||
|
||||
for (auto cell : module->cells_) {
|
||||
std::string cell_type = cell.second->type.str();
|
||||
if (cell_type == RTLIL::escape_id("QL_DSP2") || cell_type == RTLIL::escape_id("QL_DSP3")) {
|
||||
auto dsp = cell.second;
|
||||
for (auto cell : module->cells()) {
|
||||
if (cell->type != ID(QL_DSP2))
|
||||
continue;
|
||||
|
||||
// If the cell does not have the "is_inferred" attribute set
|
||||
// then don't touch it.
|
||||
if (!dsp->has_attribute(RTLIL::escape_id("is_inferred")) || dsp->get_bool_attribute(RTLIL::escape_id("is_inferred")) == false) {
|
||||
continue;
|
||||
}
|
||||
// If the cell does not have the "is_inferred" attribute set
|
||||
// then don't touch it.
|
||||
if (!cell->get_bool_attribute(ID(is_inferred)))
|
||||
continue;
|
||||
|
||||
bool del_clk = true;
|
||||
bool use_dsp_cfg_params = (cell_type == RTLIL::escape_id("QL_DSP3"));
|
||||
// Get DSP configuration
|
||||
for (auto cfg_port : {ID(register_inputs), ID(output_select)})
|
||||
if (!cell->hasPort(cfg_port) || sigmap(cell->getPort(cfg_port)).is_fully_const())
|
||||
log_error("Missing or non-constant '%s' port on DSP cell %s\n",
|
||||
log_id(cfg_port), log_id(cell));
|
||||
int reg_in_i = sigmap(cell->getPort(ID(register_inputs))).as_int();
|
||||
int out_sel_i = sigmap(cell->getPort(ID(output_select))).as_int();
|
||||
|
||||
int reg_in_i;
|
||||
int out_sel_i;
|
||||
// Get the feedback port
|
||||
if (!cell->hasPort(ID(feedback)))
|
||||
log_error("Missing 'feedback' port on %s", log_id(cell));
|
||||
SigSpec feedback = sigmap(cell->getPort(ID(feedback)));
|
||||
|
||||
// Get DSP configuration
|
||||
if (use_dsp_cfg_params) {
|
||||
// Read MODE_BITS at correct indexes
|
||||
auto mode_bits = &dsp->getParam(RTLIL::escape_id("MODE_BITS"));
|
||||
RTLIL::Const register_inputs;
|
||||
register_inputs = mode_bits->bits.at(MODE_BITS_REGISTER_INPUTS_ID);
|
||||
reg_in_i = register_inputs.as_int();
|
||||
// Check the top two bits on 'feedback' to be constant zero.
|
||||
// That's what we are expecting from inference.
|
||||
if (feedback.extract(1, 2) != SigSpec(0, 2))
|
||||
log_error("Unexpected feedback configuration on %s\n", log_id(cell));
|
||||
|
||||
RTLIL::Const output_select;
|
||||
output_select = mode_bits->extract(MODE_BITS_OUTPUT_SELECT_START_ID, MODE_BITS_OUTPUT_SELECT_WIDTH);
|
||||
out_sel_i = output_select.as_int();
|
||||
} else {
|
||||
// Read dedicated configuration ports
|
||||
const RTLIL::SigSpec *register_inputs;
|
||||
register_inputs = &dsp->getPort(RTLIL::escape_id("register_inputs"));
|
||||
if (!register_inputs)
|
||||
log_error("register_inputs port not found!");
|
||||
auto reg_in_c = register_inputs->as_const();
|
||||
reg_in_i = reg_in_c.as_int();
|
||||
// Build new type name
|
||||
std::string new_type = "QL_DSP2_MULT";
|
||||
|
||||
const RTLIL::SigSpec *output_select;
|
||||
output_select = &dsp->getPort(RTLIL::escape_id("output_select"));
|
||||
if (!output_select)
|
||||
log_error("output_select port not found!");
|
||||
auto out_sel_c = output_select->as_const();
|
||||
out_sel_i = out_sel_c.as_int();
|
||||
}
|
||||
// Decide if we should be deleting the clock port
|
||||
bool del_clk = true;
|
||||
|
||||
// Get the feedback port
|
||||
const RTLIL::SigSpec *feedback;
|
||||
feedback = &dsp->getPort(RTLIL::escape_id("feedback"));
|
||||
if (!feedback)
|
||||
log_error("feedback port not found!");
|
||||
|
||||
// Check if feedback is or can be set to 0 which implies MACC
|
||||
auto feedback_con = get_constant_mask_value(feedback);
|
||||
bool have_macc = (feedback_con.second == 0x0);
|
||||
// log("mask=0x%08X value=0x%08X\n", consts.first, consts.second);
|
||||
// log_error("=== END HERE ===\n");
|
||||
|
||||
// Build new type name
|
||||
std::string new_type = cell_type;
|
||||
new_type += "_MULT";
|
||||
|
||||
if (have_macc) {
|
||||
switch (out_sel_i) {
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 5:
|
||||
case 7:
|
||||
del_clk = false;
|
||||
new_type += "ACC";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (out_sel_i) {
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 5:
|
||||
case 7:
|
||||
new_type += "ADD";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (reg_in_i) {
|
||||
del_clk = false;
|
||||
new_type += "_REGIN";
|
||||
}
|
||||
|
||||
if (out_sel_i > 3) {
|
||||
del_clk = false;
|
||||
new_type += "_REGOUT";
|
||||
}
|
||||
|
||||
// Set new type name
|
||||
dsp->type = RTLIL::IdString(new_type);
|
||||
|
||||
std::vector<std::string> ports2del;
|
||||
|
||||
if (del_clk)
|
||||
ports2del.push_back("clk");
|
||||
|
||||
switch (out_sel_i) {
|
||||
case 0:
|
||||
case 4:
|
||||
case 6:
|
||||
ports2del.insert(ports2del.end(), ports2del_mult.begin(), ports2del_mult.end());
|
||||
// Mark for deleton additional configuration ports
|
||||
if (!use_dsp_cfg_params) {
|
||||
ports2del.insert(ports2del.end(), ports2del_extension.begin(), ports2del_extension.end());
|
||||
}
|
||||
break;
|
||||
switch (out_sel_i) {
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 5:
|
||||
case 7:
|
||||
if (have_macc) {
|
||||
ports2del.insert(ports2del.end(), ports2del_mult_acc.begin(), ports2del_mult_acc.end());
|
||||
} else {
|
||||
ports2del.insert(ports2del.end(), ports2del_mult_add.begin(), ports2del_mult_add.end());
|
||||
}
|
||||
del_clk = false;
|
||||
new_type += "ACC";
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
for (auto portname : ports2del) {
|
||||
const RTLIL::SigSpec *port = &dsp->getPort(RTLIL::escape_id(portname));
|
||||
if (!port)
|
||||
log_error("%s port not found!", portname.c_str());
|
||||
dsp->connections_.erase(RTLIL::escape_id(portname));
|
||||
}
|
||||
if (reg_in_i) {
|
||||
del_clk = false;
|
||||
new_type += "_REGIN";
|
||||
}
|
||||
|
||||
if (out_sel_i > 3) {
|
||||
del_clk = false;
|
||||
new_type += "_REGOUT";
|
||||
}
|
||||
|
||||
// Set new type name
|
||||
cell->type = RTLIL::IdString(new_type);
|
||||
|
||||
std::vector<std::string> ports2del;
|
||||
|
||||
if (del_clk)
|
||||
cell->unsetPort(ID(clk));
|
||||
|
||||
switch (out_sel_i) {
|
||||
case 0:
|
||||
case 4:
|
||||
case 6:
|
||||
for (auto port : ports2del_mult)
|
||||
cell->unsetPort(port);
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 5:
|
||||
case 7:
|
||||
for (auto port : ports2del_mult_acc)
|
||||
cell->unsetPort(port);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Clear the sigmap
|
||||
m_SigMap.clear();
|
||||
}
|
||||
|
||||
} QlDspIORegs;
|
||||
|
||||
PRIVATE_NAMESPACE_END
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue