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
|
|
|
|
|
|
|
|
#include "passes/pmgen/xilinx_dsp_pm.h"
|
|
|
|
|
2019-08-13 19:11:35 -05:00
|
|
|
void pack_xilinx_dsp(dict<SigBit, Cell*> &bit_to_driver, 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");
|
2019-09-03 18:24:59 -05:00
|
|
|
log("ffA: %s\n", log_id(st.ffA, "--"));
|
2019-09-05 12:07:26 -05:00
|
|
|
log("ffAmux: %s\n", log_id(st.ffAmux, "--"));
|
2019-09-03 18:24:59 -05:00
|
|
|
log("ffB: %s\n", log_id(st.ffB, "--"));
|
2019-09-05 12:46:33 -05:00
|
|
|
log("ffBmux: %s\n", log_id(st.ffBmux, "--"));
|
2019-09-03 18:24:59 -05:00
|
|
|
log("dsp: %s\n", log_id(st.dsp, "--"));
|
|
|
|
log("ffM: %s\n", log_id(st.ffM, "--"));
|
2019-09-04 12:52:51 -05:00
|
|
|
log("ffMmux: %s\n", log_id(st.ffMmux, "--"));
|
2019-09-03 18:24:59 -05:00
|
|
|
log("postAdd: %s\n", log_id(st.postAdd, "--"));
|
|
|
|
log("postAddMux: %s\n", log_id(st.postAddMux, "--"));
|
|
|
|
log("ffP: %s\n", log_id(st.ffP, "--"));
|
2019-09-05 13:00:27 -05:00
|
|
|
log("ffPmux: %s\n", log_id(st.ffPmux, "--"));
|
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-13 19:11:35 -05:00
|
|
|
bit_to_driver.insert(std::make_pair(cell->getPort("\\P")[17], cell));
|
2019-09-03 16:57:59 -05:00
|
|
|
SigSpec C = st.sigC;
|
2019-08-09 17:19:33 -05:00
|
|
|
SigSpec P = st.sigP;
|
|
|
|
|
2019-09-03 18:10:16 -05:00
|
|
|
if (st.postAdd) {
|
|
|
|
log(" adder %s (%s)\n", log_id(st.postAdd), log_id(st.postAdd->type));
|
2019-09-03 16:57:59 -05:00
|
|
|
|
|
|
|
SigSpec &opmode = cell->connections_.at("\\OPMODE");
|
2019-09-03 18:37:59 -05:00
|
|
|
if (st.postAddMux) {
|
|
|
|
log_assert(st.ffP);
|
2019-09-03 18:24:59 -05:00
|
|
|
opmode[4] = st.postAddMux->getPort("\\S");
|
|
|
|
pm.autoremove(st.postAddMux);
|
2019-09-03 17:53:10 -05:00
|
|
|
}
|
|
|
|
else if (st.ffP && C == P) {
|
2019-09-03 16:57:59 -05:00
|
|
|
C = SigSpec();
|
|
|
|
opmode[4] = State::S0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
opmode[4] = State::S1;
|
|
|
|
opmode[6] = State::S0;
|
|
|
|
opmode[5] = State::S1;
|
|
|
|
|
2019-09-03 18:10:16 -05:00
|
|
|
pm.autoremove(st.postAdd);
|
2019-09-03 16:57:59 -05:00
|
|
|
}
|
|
|
|
|
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-09-05 12:07:26 -05:00
|
|
|
SigSpec Q = pm.sigmap(st.ffA->getPort("\\Q"));
|
2019-07-17 14:45:25 -05:00
|
|
|
A.replace(Q, D);
|
2019-09-05 12:07:26 -05:00
|
|
|
if (st.ffAmux) {
|
|
|
|
SigSpec Y = st.ffAmux->getPort("\\Y");
|
2019-09-05 23:28:28 -05:00
|
|
|
SigSpec AB = st.ffAmux->getPort(st.ffAenpol ? "\\A" : "\\B");
|
|
|
|
SigSpec S = st.ffAmux->getPort("\\S");
|
2019-09-05 23:38:35 -05:00
|
|
|
A.replace(Y, AB);
|
2019-09-05 23:28:28 -05:00
|
|
|
cell->setPort("\\CEA2", st.ffAenpol ? S : pm.module->Not(NEW_ID, S));
|
2019-09-05 12:07:26 -05:00
|
|
|
}
|
|
|
|
else
|
2019-07-16 16:06:32 -05:00
|
|
|
cell->setPort("\\CEA2", State::S1);
|
2019-09-05 12:07:26 -05:00
|
|
|
cell->setPort("\\A", A);
|
2019-09-05 12:46:33 -05:00
|
|
|
|
|
|
|
cell->setParam("\\AREG", 1);
|
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);
|
2019-09-05 12:46:33 -05:00
|
|
|
if (st.ffBmux) {
|
|
|
|
SigSpec Y = st.ffBmux->getPort("\\Y");
|
2019-09-05 23:38:35 -05:00
|
|
|
SigSpec AB = st.ffBmux->getPort(st.ffBenpol ? "\\A" : "\\B");
|
|
|
|
SigSpec S = st.ffBmux->getPort("\\S");
|
2019-09-05 12:46:33 -05:00
|
|
|
B.replace(Y, AB);
|
2019-09-05 23:38:35 -05:00
|
|
|
cell->setPort("\\CEB2", st.ffBenpol ? S : pm.module->Not(NEW_ID, S));
|
2019-09-05 12:46:33 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
cell->setPort("\\CEB2", State::S1);
|
2019-07-17 14:45:25 -05:00
|
|
|
cell->setPort("\\B", B);
|
2019-09-05 12:46:33 -05:00
|
|
|
|
2019-08-08 12:44:49 -05:00
|
|
|
cell->setParam("\\BREG", 1);
|
2019-07-15 16:46:31 -05:00
|
|
|
}
|
2019-08-30 17:00:56 -05:00
|
|
|
if (st.ffM) {
|
2019-09-04 12:52:51 -05:00
|
|
|
if (st.ffMmux) {
|
2019-09-05 23:38:35 -05:00
|
|
|
SigSpec S = st.ffMmux->getPort("\\S");
|
|
|
|
cell->setPort("\\CEM", st.ffMenpol ? S : pm.module->Not(NEW_ID, S));
|
2019-09-04 12:52:51 -05:00
|
|
|
pm.autoremove(st.ffMmux);
|
|
|
|
}
|
|
|
|
else
|
2019-08-30 17:00:56 -05:00
|
|
|
cell->setPort("\\CEM", State::S1);
|
2019-09-05 13:00:27 -05:00
|
|
|
SigSpec D = st.ffM->getPort("\\D");
|
|
|
|
SigSpec Q = st.ffM->getPort("\\Q");
|
2019-09-05 13:46:38 -05:00
|
|
|
P.replace(pm.sigmap(D), Q);
|
2019-09-05 13:00:27 -05:00
|
|
|
|
|
|
|
cell->setParam("\\MREG", State::S1);
|
2019-08-30 17:30:04 -05:00
|
|
|
pm.autoremove(st.ffM);
|
2019-08-30 17:00:56 -05:00
|
|
|
}
|
2019-07-16 16:06:32 -05:00
|
|
|
if (st.ffP) {
|
2019-09-05 13:00:27 -05:00
|
|
|
if (st.ffPmux) {
|
2019-09-05 23:38:35 -05:00
|
|
|
SigSpec S = st.ffPmux->getPort("\\S");
|
|
|
|
cell->setPort("\\CEP", st.ffPenpol ? S : pm.module->Not(NEW_ID, S));
|
2019-09-05 13:00:27 -05:00
|
|
|
st.ffPmux->connections_.at("\\Y").replace(P, pm.module->addWire(NEW_ID, GetSize(P)));
|
|
|
|
}
|
|
|
|
else
|
2019-07-16 16:06:32 -05:00
|
|
|
cell->setPort("\\CEP", State::S1);
|
2019-09-05 13:00:27 -05:00
|
|
|
SigSpec D = st.ffP->getPort("\\D");
|
|
|
|
SigSpec Q = st.ffP->getPort("\\Q");
|
2019-09-05 13:46:38 -05:00
|
|
|
P.replace(pm.sigmap(D), Q);
|
2019-08-01 17:10:43 -05:00
|
|
|
st.ffP->connections_.at("\\Q").replace(P, pm.module->addWire(NEW_ID, GetSize(P)));
|
2019-09-05 13:00:27 -05:00
|
|
|
|
|
|
|
cell->setParam("\\PREG", State::S1);
|
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-09-05 13:46:38 -05:00
|
|
|
if (st.ffM)
|
|
|
|
log(" ffM:%s", log_id(st.ffM));
|
|
|
|
|
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-09-03 16:57:59 -05:00
|
|
|
if (!C.empty()) {
|
|
|
|
if (GetSize(C) < 48)
|
2019-09-03 16:37:32 -05:00
|
|
|
C.extend_u0(48, true);
|
2019-09-03 16:57:59 -05:00
|
|
|
cell->setPort("\\C", C);
|
2019-09-03 16:37:32 -05:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-08-13 12:23:07 -05:00
|
|
|
struct XilinxDspPass : public Pass {
|
|
|
|
XilinxDspPass() : Pass("xilinx_dsp", "Xilinx: pack DSP registers") { }
|
2019-07-15 16:46:31 -05:00
|
|
|
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);
|
|
|
|
|
2019-08-13 19:11:35 -05:00
|
|
|
for (auto module : design->selected_modules()) {
|
|
|
|
xilinx_dsp_pm pm(module, module->selected_cells());
|
|
|
|
dict<SigBit, Cell*> bit_to_driver;
|
|
|
|
auto f = [&bit_to_driver](xilinx_dsp_pm &pm){ pack_xilinx_dsp(bit_to_driver, pm); };
|
|
|
|
pm.run_xilinx_dsp(f);
|
|
|
|
|
|
|
|
// Look for ability to convert C input from another DSP into PCIN
|
|
|
|
// NB: Needs to be done after pattern matcher has folded all
|
|
|
|
// $add cells into the DSP
|
|
|
|
for (auto cell : module->cells()) {
|
|
|
|
if (cell->type != "\\DSP48E1")
|
|
|
|
continue;
|
|
|
|
SigSpec &opmode = cell->connections_.at("\\OPMODE");
|
|
|
|
if (opmode.extract(4,3) != Const::from_string("011"))
|
|
|
|
continue;
|
|
|
|
SigSpec C = pm.sigmap(cell->getPort("\\C"));
|
|
|
|
if (C.has_const())
|
|
|
|
continue;
|
|
|
|
auto it = bit_to_driver.find(C[0]);
|
|
|
|
if (it == bit_to_driver.end())
|
|
|
|
continue;
|
|
|
|
auto driver = it->second;
|
|
|
|
|
|
|
|
// Unextend C
|
|
|
|
int i;
|
|
|
|
for (i = GetSize(C)-1; i > 0; i--)
|
|
|
|
if (C[i] != C[i-1])
|
|
|
|
break;
|
|
|
|
if (i > 48-17)
|
|
|
|
continue;
|
|
|
|
if (driver->getPort("\\P").extract(17, i) == C.extract(0, i)) {
|
|
|
|
cell->setPort("\\C", Const(0, 48));
|
|
|
|
Wire *cascade = module->addWire(NEW_ID, 48);
|
|
|
|
driver->setPort("\\PCOUT", cascade);
|
|
|
|
cell->setPort("\\PCIN", cascade);
|
|
|
|
opmode[6] = State::S1;
|
|
|
|
opmode[5] = State::S0;
|
|
|
|
opmode[4] = State::S1;
|
|
|
|
bit_to_driver.erase(it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-15 16:46:31 -05:00
|
|
|
}
|
2019-08-13 12:23:07 -05:00
|
|
|
} XilinxDspPass;
|
2019-07-15 16:46:31 -05:00
|
|
|
|
|
|
|
PRIVATE_NAMESPACE_END
|