2019-07-15 16:46:31 -05:00
|
|
|
/*
|
|
|
|
* yosys -- Yosys Open SYnthesis Suite
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "kernel/yosys.h"
|
|
|
|
#include "kernel/sigtools.h"
|
|
|
|
|
|
|
|
USING_YOSYS_NAMESPACE
|
|
|
|
PRIVATE_NAMESPACE_BEGIN
|
|
|
|
|
2019-07-18 15:30:35 -05:00
|
|
|
template<class T> bool includes(const T &lhs, const T &rhs) {
|
|
|
|
return std::includes(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
|
|
|
|
}
|
2019-07-15 16:46:31 -05:00
|
|
|
#include "passes/pmgen/xilinx_dsp_pm.h"
|
|
|
|
|
2019-07-16 16:06:32 -05:00
|
|
|
void pack_xilinx_dsp(xilinx_dsp_pm &pm)
|
2019-07-15 16:46:31 -05:00
|
|
|
{
|
|
|
|
auto &st = pm.st_xilinx_dsp;
|
|
|
|
|
2019-07-16 16:06:32 -05:00
|
|
|
#if 1
|
2019-07-15 16:46:31 -05:00
|
|
|
log("\n");
|
|
|
|
log("ffA: %s\n", log_id(st.ffA, "--"));
|
|
|
|
log("ffB: %s\n", log_id(st.ffB, "--"));
|
2019-07-16 16:06:32 -05:00
|
|
|
log("dsp: %s\n", log_id(st.dsp, "--"));
|
2019-08-09 17:19:33 -05:00
|
|
|
log("addAB: %s\n", log_id(st.addAB, "--"));
|
2019-07-16 16:06:32 -05:00
|
|
|
log("ffP: %s\n", log_id(st.ffP, "--"));
|
2019-08-08 18:33:37 -05:00
|
|
|
//log("muxP: %s\n", log_id(st.muxP, "--"));
|
2019-07-19 12:57:32 -05:00
|
|
|
log("sigPused: %s\n", log_signal(st.sigPused));
|
2019-07-15 16:46:31 -05:00
|
|
|
#endif
|
|
|
|
|
2019-08-09 17:19:33 -05:00
|
|
|
log("Analysing %s.%s for Xilinx DSP packing.\n", log_id(pm.module), log_id(st.dsp));
|
2019-07-15 16:46:31 -05:00
|
|
|
|
2019-07-16 16:06:32 -05:00
|
|
|
Cell *cell = st.dsp;
|
2019-08-09 17:19:33 -05:00
|
|
|
SigSpec P = st.sigP;
|
|
|
|
|
|
|
|
if (st.addAB) {
|
|
|
|
log(" adder %s (%s)\n", log_id(st.addAB), log_id(st.addAB->type));
|
|
|
|
cell->setPort("\\C", st.sigC.extend_u0(48, true));
|
|
|
|
SigSpec &opmode = cell->connections_.at("\\OPMODE");
|
|
|
|
opmode[6] = State::S0;
|
|
|
|
opmode[5] = State::S1;
|
|
|
|
opmode[4] = State::S1;
|
|
|
|
pm.autoremove(st.addAB);
|
|
|
|
}
|
2019-07-15 16:46:31 -05:00
|
|
|
|
|
|
|
if (st.clock != SigBit())
|
|
|
|
{
|
|
|
|
cell->setPort("\\CLK", st.clock);
|
|
|
|
|
|
|
|
if (st.ffA) {
|
2019-07-17 14:45:25 -05:00
|
|
|
SigSpec A = cell->getPort("\\A");
|
2019-07-16 16:06:32 -05:00
|
|
|
SigSpec D = st.ffA->getPort("\\D");
|
2019-07-17 14:45:25 -05:00
|
|
|
SigSpec Q = st.ffA->getPort("\\Q");
|
|
|
|
A.replace(Q, D);
|
|
|
|
cell->setPort("\\A", A);
|
2019-08-08 12:44:49 -05:00
|
|
|
cell->setParam("\\AREG", 1);
|
2019-07-16 16:06:32 -05:00
|
|
|
if (st.ffA->type == "$dff")
|
|
|
|
cell->setPort("\\CEA2", State::S1);
|
2019-08-08 12:44:49 -05:00
|
|
|
//else if (st.ffA->type == "$dffe")
|
|
|
|
// cell->setPort("\\CEA2", st.ffA->getPort("\\EN"));
|
2019-07-16 16:06:32 -05:00
|
|
|
else log_abort();
|
2019-07-15 16:46:31 -05:00
|
|
|
}
|
|
|
|
if (st.ffB) {
|
2019-07-17 14:45:25 -05:00
|
|
|
SigSpec B = cell->getPort("\\B");
|
2019-07-16 16:06:32 -05:00
|
|
|
SigSpec D = st.ffB->getPort("\\D");
|
2019-07-17 14:45:25 -05:00
|
|
|
SigSpec Q = st.ffB->getPort("\\Q");
|
|
|
|
B.replace(Q, D);
|
|
|
|
cell->setPort("\\B", B);
|
2019-08-08 12:44:49 -05:00
|
|
|
cell->setParam("\\BREG", 1);
|
2019-07-16 16:06:32 -05:00
|
|
|
if (st.ffB->type == "$dff")
|
|
|
|
cell->setPort("\\CEB2", State::S1);
|
2019-08-08 12:44:49 -05:00
|
|
|
//else if (st.ffB->type == "$dffe")
|
|
|
|
// cell->setPort("\\CEB2", st.ffB->getPort("\\EN"));
|
2019-07-16 16:06:32 -05:00
|
|
|
else log_abort();
|
2019-07-15 16:46:31 -05:00
|
|
|
}
|
2019-07-16 16:06:32 -05:00
|
|
|
if (st.ffP) {
|
2019-07-18 16:08:18 -05:00
|
|
|
SigSpec D;
|
2019-08-08 18:33:37 -05:00
|
|
|
//if (st.muxP)
|
|
|
|
// D = st.muxP->getPort("\\B");
|
|
|
|
//else
|
2019-07-18 16:08:18 -05:00
|
|
|
D = st.ffP->getPort("\\D");
|
2019-07-16 16:06:32 -05:00
|
|
|
SigSpec Q = st.ffP->getPort("\\Q");
|
2019-08-01 17:10:43 -05:00
|
|
|
P.replace(pm.sigmap(D), Q);
|
2019-07-16 16:06:32 -05:00
|
|
|
cell->setParam("\\PREG", State::S1);
|
|
|
|
if (st.ffP->type == "$dff")
|
|
|
|
cell->setPort("\\CEP", State::S1);
|
2019-08-08 12:44:49 -05:00
|
|
|
//else if (st.ffP->type == "$dffe")
|
|
|
|
// cell->setPort("\\CEP", st.ffP->getPort("\\EN"));
|
2019-07-16 16:06:32 -05:00
|
|
|
else log_abort();
|
2019-08-01 17:10:43 -05:00
|
|
|
|
|
|
|
st.ffP->connections_.at("\\Q").replace(P, pm.module->addWire(NEW_ID, GetSize(P)));
|
2019-07-15 16:46:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
log(" clock: %s (%s)", log_signal(st.clock), "posedge");
|
|
|
|
|
|
|
|
if (st.ffA)
|
|
|
|
log(" ffA:%s", log_id(st.ffA));
|
|
|
|
|
|
|
|
if (st.ffB)
|
|
|
|
log(" ffB:%s", log_id(st.ffB));
|
|
|
|
|
2019-07-16 16:06:32 -05:00
|
|
|
if (st.ffP)
|
2019-08-08 18:33:37 -05:00
|
|
|
log(" ffP:%s", log_id(st.ffP));
|
2019-07-15 16:46:31 -05:00
|
|
|
|
|
|
|
log("\n");
|
|
|
|
}
|
|
|
|
|
2019-08-09 17:19:33 -05:00
|
|
|
if (GetSize(P) < 48)
|
|
|
|
P.append(pm.module->addWire(NEW_ID, 48-GetSize(P)));
|
|
|
|
cell->setPort("\\P", P);
|
|
|
|
|
2019-07-16 16:06:32 -05:00
|
|
|
pm.blacklist(cell);
|
2019-07-15 16:46:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
struct Ice40DspPass : public Pass {
|
|
|
|
Ice40DspPass() : Pass("xilinx_dsp", "Xilinx: pack DSP registers") { }
|
|
|
|
void help() YS_OVERRIDE
|
|
|
|
{
|
|
|
|
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
|
|
|
log("\n");
|
|
|
|
log(" xilinx_dsp [options] [selection]\n");
|
|
|
|
log("\n");
|
|
|
|
log("Pack registers into Xilinx DSPs\n");
|
|
|
|
log("\n");
|
|
|
|
}
|
|
|
|
void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE
|
|
|
|
{
|
2019-07-16 16:06:32 -05:00
|
|
|
log_header(design, "Executing XILINX_DSP pass (pack DSPs).\n");
|
2019-07-15 16:46:31 -05:00
|
|
|
|
|
|
|
size_t argidx;
|
|
|
|
for (argidx = 1; argidx < args.size(); argidx++)
|
|
|
|
{
|
|
|
|
// if (args[argidx] == "-singleton") {
|
|
|
|
// singleton_mode = true;
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
extra_args(args, argidx, design);
|
|
|
|
|
|
|
|
for (auto module : design->selected_modules())
|
2019-07-16 16:06:32 -05:00
|
|
|
xilinx_dsp_pm(module, module->selected_cells()).run_xilinx_dsp(pack_xilinx_dsp);
|
2019-07-15 16:46:31 -05:00
|
|
|
}
|
|
|
|
} Ice40DspPass;
|
|
|
|
|
|
|
|
PRIVATE_NAMESPACE_END
|