2019-10-04 14:40:34 -05:00
|
|
|
// This file describes the second of three pattern matcher setups that
|
|
|
|
// forms the `xilinx_dsp` pass described in xilinx_dsp.cc
|
|
|
|
// At a high level, it works as follows:
|
2019-12-22 13:43:39 -06:00
|
|
|
// (1) Starting from a DSP48* cell that (a) doesn't have a CREG already,
|
2019-10-04 14:40:34 -05:00
|
|
|
// and (b) uses the 'C' port
|
|
|
|
// (2) Match the driver of the 'C' input to a possible $dff cell (CREG)
|
|
|
|
// (attached to at most two $mux cells that implement clock-enable or
|
|
|
|
// reset functionality, using a subpattern discussed below)
|
|
|
|
// Notes:
|
2019-10-05 00:24:15 -05:00
|
|
|
// - Running CREG packing after xilinx_dsp_pack is necessary since there is no
|
|
|
|
// guarantee that the cell ordering corresponds to the "expected" case (i.e.
|
|
|
|
// the order in which they appear in the source) thus the possiblity existed
|
|
|
|
// that a register got packed as a CREG into a downstream DSP that should
|
|
|
|
// have otherwise been a PREG of an upstream DSP that had not been visited
|
|
|
|
// yet
|
2019-10-04 14:40:34 -05:00
|
|
|
// - The reason this is separated out from the xilinx_dsp.pmg file is
|
|
|
|
// for efficiency --- each *.pmg file creates a class of the same basename,
|
|
|
|
// which when constructed, creates a custom database tailored to the
|
|
|
|
// pattern(s) contained within. Since the pattern in this file must be
|
|
|
|
// executed after the pattern contained in xilinx_dsp.pmg, it is necessary
|
|
|
|
// to reconstruct this database. Separating the two patterns into
|
|
|
|
// independent files causes two smaller, more specific, databases.
|
|
|
|
|
2019-09-23 15:27:10 -05:00
|
|
|
pattern xilinx_dsp_packC
|
|
|
|
|
|
|
|
udata <std::function<SigSpec(const SigSpec&)>> unextend
|
|
|
|
state <SigBit> clock
|
|
|
|
state <SigSpec> sigC sigP
|
2020-07-22 05:27:15 -05:00
|
|
|
state <Cell*> ffC
|
2019-09-23 15:27:10 -05:00
|
|
|
|
2019-10-05 00:24:15 -05:00
|
|
|
// Variables used for subpatterns
|
2019-09-23 15:27:10 -05:00
|
|
|
state <SigSpec> argQ argD
|
|
|
|
state <int> ffoffset
|
|
|
|
udata <SigSpec> dffD dffQ
|
|
|
|
udata <SigBit> dffclock
|
2020-07-22 05:27:15 -05:00
|
|
|
udata <Cell*> dff
|
2019-09-23 15:27:10 -05:00
|
|
|
|
2019-12-22 13:43:39 -06:00
|
|
|
// (1) Starting from a DSP48* cell that (a) doesn't have a CREG already,
|
2019-10-04 14:40:34 -05:00
|
|
|
// and (b) uses the 'C' port
|
2019-09-23 15:27:10 -05:00
|
|
|
match dsp
|
2019-12-22 13:43:39 -06:00
|
|
|
select dsp->type.in(\DSP48A, \DSP48A1, \DSP48E1)
|
2020-04-22 14:02:30 -05:00
|
|
|
select param(dsp, \CREG).as_int() == 0
|
2019-09-23 15:27:10 -05:00
|
|
|
select nusers(port(dsp, \C, SigSpec())) > 1
|
|
|
|
endmatch
|
|
|
|
|
2019-10-04 14:43:19 -05:00
|
|
|
code sigC sigP clock
|
2019-09-23 15:27:10 -05:00
|
|
|
unextend = [](const SigSpec &sig) {
|
|
|
|
int i;
|
|
|
|
for (i = GetSize(sig)-1; i > 0; i--)
|
|
|
|
if (sig[i] != sig[i-1])
|
|
|
|
break;
|
|
|
|
// Do not remove non-const sign bit
|
|
|
|
if (sig[i].wire)
|
|
|
|
++i;
|
|
|
|
return sig.extract(0, i);
|
|
|
|
};
|
|
|
|
sigC = unextend(port(dsp, \C, SigSpec()));
|
|
|
|
|
|
|
|
SigSpec P = port(dsp, \P);
|
2019-12-22 13:43:39 -06:00
|
|
|
if (!dsp->type.in(\DSP48E1) ||
|
2020-04-22 14:02:30 -05:00
|
|
|
param(dsp, \USE_MULT).decode_string() == "MULTIPLY") {
|
2019-09-23 15:27:10 -05:00
|
|
|
// Only care about those bits that are used
|
|
|
|
int i;
|
2019-11-18 01:19:53 -06:00
|
|
|
for (i = GetSize(P)-1; i >= 0; i--)
|
|
|
|
if (nusers(P[i]) > 1)
|
2019-09-23 15:27:10 -05:00
|
|
|
break;
|
2019-11-18 01:19:53 -06:00
|
|
|
i++;
|
2019-09-23 15:27:10 -05:00
|
|
|
log_assert(nusers(P.extract_end(i)) <= 1);
|
2019-11-18 01:19:53 -06:00
|
|
|
sigP = P.extract(0, i);
|
2019-09-23 15:27:10 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
sigP = P;
|
2019-10-04 14:43:19 -05:00
|
|
|
|
|
|
|
clock = port(dsp, \CLK, SigBit());
|
2019-10-04 14:40:34 -05:00
|
|
|
endcode
|
2019-09-23 15:27:10 -05:00
|
|
|
|
2019-10-04 14:40:34 -05:00
|
|
|
// (2) Match the driver of the 'C' input to a possible $dff cell (CREG)
|
|
|
|
// (attached to at most two $mux cells that implement clock-enable or
|
2019-10-04 15:31:44 -05:00
|
|
|
// reset functionality, using the in_dffe subpattern)
|
2020-07-22 05:27:15 -05:00
|
|
|
code argQ ffC sigC clock
|
2019-09-23 15:27:10 -05:00
|
|
|
argQ = sigC;
|
|
|
|
subpattern(in_dffe);
|
|
|
|
if (dff) {
|
|
|
|
ffC = dff;
|
|
|
|
clock = dffclock;
|
|
|
|
sigC = dffD;
|
|
|
|
}
|
|
|
|
endcode
|
|
|
|
|
|
|
|
code
|
|
|
|
if (ffC)
|
|
|
|
accept;
|
|
|
|
endcode
|
|
|
|
|
|
|
|
// #######################
|
|
|
|
|
2019-10-04 15:31:44 -05:00
|
|
|
// Subpattern for matching against input registers, based on knowledge of the
|
2020-07-22 05:27:15 -05:00
|
|
|
// 'Q' input.
|
2019-09-23 15:27:10 -05:00
|
|
|
subpattern in_dffe
|
2020-07-22 05:27:15 -05:00
|
|
|
arg argQ clock
|
2019-09-23 15:27:10 -05:00
|
|
|
|
|
|
|
code
|
|
|
|
dff = nullptr;
|
2020-07-22 05:27:15 -05:00
|
|
|
if (argQ.empty())
|
|
|
|
reject;
|
2019-10-04 15:31:44 -05:00
|
|
|
for (const auto &c : argQ.chunks()) {
|
|
|
|
// Abandon matches when 'Q' is a constant
|
2019-09-23 15:27:10 -05:00
|
|
|
if (!c.wire)
|
|
|
|
reject;
|
2019-10-04 15:31:44 -05:00
|
|
|
// Abandon matches when 'Q' has the keep attribute set
|
2019-09-23 15:27:10 -05:00
|
|
|
if (c.wire->get_bool_attribute(\keep))
|
|
|
|
reject;
|
2019-10-04 15:31:44 -05:00
|
|
|
// Abandon matches when 'Q' has a non-zero init attribute set
|
|
|
|
// (not supported by DSP48E1)
|
|
|
|
Const init = c.wire->attributes.at(\init, Const());
|
2020-07-22 05:27:15 -05:00
|
|
|
if (!init.empty())
|
|
|
|
for (auto b : init.extract(c.offset, c.width))
|
|
|
|
if (b != State::Sx && b != State::S0)
|
|
|
|
reject;
|
2019-09-23 15:27:10 -05:00
|
|
|
}
|
|
|
|
endcode
|
|
|
|
|
|
|
|
match ff
|
2020-07-22 05:27:15 -05:00
|
|
|
select ff->type.in($dff, $dffe, $sdff, $sdffe)
|
2019-09-23 15:27:10 -05:00
|
|
|
// DSP48E1 does not support clock inversion
|
|
|
|
select param(ff, \CLK_POLARITY).as_bool()
|
|
|
|
|
2020-07-22 05:27:15 -05:00
|
|
|
// Check that reset value, if present, is fully 0.
|
|
|
|
filter ff->type.in($dff, $dffe) || param(ff, \SRST_VALUE).is_fully_zero()
|
|
|
|
|
2019-09-23 15:27:10 -05:00
|
|
|
slice offset GetSize(port(ff, \D))
|
|
|
|
index <SigBit> port(ff, \Q)[offset] === argQ[0]
|
|
|
|
|
|
|
|
// Check that the rest of argQ is present
|
|
|
|
filter GetSize(port(ff, \Q)) >= offset + GetSize(argQ)
|
|
|
|
filter port(ff, \Q).extract(offset, GetSize(argQ)) == argQ
|
|
|
|
|
2024-02-08 10:46:00 -06:00
|
|
|
filter clock == SigBit() || port(ff, \CLK)[0] == clock
|
2019-09-23 15:27:10 -05:00
|
|
|
endmatch
|
|
|
|
|
2020-07-22 05:27:15 -05:00
|
|
|
code argQ
|
2019-09-23 15:27:10 -05:00
|
|
|
SigSpec Q = port(ff, \Q);
|
|
|
|
dff = ff;
|
|
|
|
dffclock = port(ff, \CLK);
|
|
|
|
dffD = argQ;
|
2020-07-22 05:27:15 -05:00
|
|
|
SigSpec D = port(ff, \D);
|
2019-09-23 15:27:10 -05:00
|
|
|
argQ = Q;
|
2020-07-22 05:27:15 -05:00
|
|
|
dffD.replace(argQ, D);
|
2019-09-23 15:27:10 -05:00
|
|
|
endcode
|