2019-10-04 14:40:34 -05:00
|
|
|
// This file describes the main pattern matcher setup (of three total) that
|
|
|
|
// forms the `xilinx_dsp` pass described in xilinx_dsp.cc
|
|
|
|
// At a high level, it works as follows:
|
|
|
|
// ( 1) Starting from a DSP48E1 cell
|
2020-07-22 05:27:15 -05:00
|
|
|
// ( 2) Match the driver of the 'A' input to a possible $sdffe cell (ADREG)
|
2019-10-04 14:40:34 -05:00
|
|
|
// If ADREG matched, treat 'A' input as input of ADREG
|
|
|
|
// ( 3) Match the driver of the 'A' and 'D' inputs for a possible $add cell
|
|
|
|
// (pre-adder)
|
|
|
|
// ( 4) If pre-adder was present, find match 'A' input for A2REG
|
|
|
|
// If pre-adder was not present, move ADREG to A2REG
|
|
|
|
// If A2REG, then match 'A' input for A1REG
|
|
|
|
// ( 5) Match 'B' input for B2REG
|
|
|
|
// If B2REG, then match 'B' input for B1REG
|
|
|
|
// ( 6) Match 'D' input for DREG
|
|
|
|
// ( 7) Match 'P' output that exclusively drives an MREG
|
|
|
|
// ( 8) Match 'P' output that exclusively drives one of two inputs to an $add
|
|
|
|
// cell (post-adder).
|
|
|
|
// The other input to the adder is assumed to come in from the 'C' input
|
|
|
|
// (note: 'P' -> 'C' connections that exist for accumulators are
|
|
|
|
// recognised in xilinx_dsp.cc).
|
|
|
|
// ( 9) Match 'P' output that exclusively drives a PREG
|
|
|
|
// (10) If post-adder and PREG both present, match for a $mux cell driving
|
|
|
|
// the 'C' input, where one of the $mux's inputs is the PREG output.
|
|
|
|
// This indicates an accumulator situation, and one where a $mux exists
|
|
|
|
// to override the accumulated value:
|
|
|
|
// +--------------------------------+
|
|
|
|
// | ____ |
|
|
|
|
// +--| \ |
|
|
|
|
// |$mux|-+ |
|
|
|
|
// 'C' ---|____/ | |
|
|
|
|
// | /-------\ +----+ |
|
|
|
|
// +----+ +-| post- |___|PREG|---+ 'P'
|
|
|
|
// |MREG|------ | adder | +----+
|
|
|
|
// +----+ \-------/
|
|
|
|
// (11) If PREG present, match for a greater-than-or-equal $ge cell attached
|
|
|
|
// to the 'P' output where it is compared to a constant that is a
|
|
|
|
// power-of-2: e.g. `assign overflow = (PREG >= 2**40);`
|
|
|
|
// In this scenario, the pattern detector functionality of a DSP48E1 can
|
|
|
|
// to implement this function
|
|
|
|
// Notes:
|
|
|
|
// - The intention of this pattern matcher is for it to be compatible with
|
|
|
|
// DSP48E1 cells inferred from multiply operations by Yosys, as well as for
|
|
|
|
// user instantiations that may already contain the cells being packed...
|
|
|
|
// (though the latter is currently untested)
|
2020-07-22 05:27:15 -05:00
|
|
|
// - Since the $sdffe pattern is used
|
2019-10-05 10:53:01 -05:00
|
|
|
// for each *REG match, it has been factored out into two subpatterns:
|
|
|
|
// in_dffe and out_dffe located at the bottom of this file.
|
|
|
|
// - Matching for pattern detector features is currently incomplete. For
|
|
|
|
// example, matching for underflow as well as overflow detection is
|
|
|
|
// possible, as would auto-reset, enabling saturated arithmetic, detecting
|
|
|
|
// custom patterns, etc.
|
2019-10-04 14:40:34 -05:00
|
|
|
|
2019-09-20 12:00:09 -05:00
|
|
|
pattern xilinx_dsp_pack
|
2019-07-15 16:46:31 -05:00
|
|
|
|
|
|
|
state <SigBit> clock
|
2019-09-20 14:03:25 -05:00
|
|
|
state <SigSpec> sigA sigB sigC sigD sigM sigP
|
2019-09-05 23:38:35 -05:00
|
|
|
state <IdString> postAddAB postAddMuxAB
|
2020-07-22 05:27:15 -05:00
|
|
|
state <Cell*> ffAD ffA1 ffA2
|
|
|
|
state <Cell*> ffB1 ffB2
|
|
|
|
state <Cell*> ffD ffM ffP
|
2019-09-09 17:51:14 -05:00
|
|
|
|
2019-10-04 14:40:34 -05:00
|
|
|
// Variables used for subpatterns
|
2019-09-10 20:27:05 -05:00
|
|
|
state <SigSpec> argQ argD
|
|
|
|
udata <SigSpec> dffD dffQ
|
2019-09-09 17:51:14 -05:00
|
|
|
udata <SigBit> dffclock
|
2020-07-22 05:27:15 -05:00
|
|
|
udata <Cell*> dff
|
2019-09-09 17:51:14 -05:00
|
|
|
|
2019-10-04 14:40:34 -05:00
|
|
|
// (1) Starting from a DSP48E1 cell
|
2019-07-16 16:06:32 -05:00
|
|
|
match dsp
|
|
|
|
select dsp->type.in(\DSP48E1)
|
2019-07-15 16:46:31 -05:00
|
|
|
endmatch
|
|
|
|
|
2019-09-23 15:27:10 -05:00
|
|
|
code sigA sigB sigC sigD sigM clock
|
2019-09-25 16:04:36 -05:00
|
|
|
auto unextend = [](const SigSpec &sig) {
|
2019-09-06 20:40:11 -05:00
|
|
|
int i;
|
|
|
|
for (i = GetSize(sig)-1; i > 0; i--)
|
|
|
|
if (sig[i] != sig[i-1])
|
|
|
|
break;
|
|
|
|
// Do not remove non-const sign bit
|
2019-09-06 23:01:36 -05:00
|
|
|
if (sig[i].wire)
|
2019-09-06 20:40:11 -05:00
|
|
|
++i;
|
|
|
|
return sig.extract(0, i);
|
|
|
|
};
|
2019-09-06 23:01:36 -05:00
|
|
|
sigA = unextend(port(dsp, \A));
|
|
|
|
sigB = unextend(port(dsp, \B));
|
2019-08-13 19:11:35 -05:00
|
|
|
|
2019-09-23 15:00:44 -05:00
|
|
|
sigC = port(dsp, \C, SigSpec());
|
|
|
|
sigD = port(dsp, \D, SigSpec());
|
2019-09-06 16:06:57 -05:00
|
|
|
|
2019-09-04 19:06:17 -05:00
|
|
|
SigSpec P = port(dsp, \P);
|
2020-04-22 14:02:30 -05:00
|
|
|
if (param(dsp, \USE_MULT).decode_string() == "MULTIPLY") {
|
2019-09-09 22:57:03 -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-09 22:57:03 -05:00
|
|
|
break;
|
2019-11-18 01:19:53 -06:00
|
|
|
i++;
|
2019-09-09 22:57:03 -05:00
|
|
|
log_assert(nusers(P.extract_end(i)) <= 1);
|
2019-10-04 23:42:46 -05:00
|
|
|
// This sigM could have no users if downstream sinks (e.g. $add) is
|
|
|
|
// narrower than $mul result, for example
|
2019-11-18 01:19:53 -06:00
|
|
|
if (i == 0)
|
2019-10-04 23:42:46 -05:00
|
|
|
reject;
|
2019-11-18 01:19:53 -06:00
|
|
|
sigM = P.extract(0, i);
|
2019-09-04 19:06:17 -05:00
|
|
|
}
|
2019-09-09 22:57:03 -05:00
|
|
|
else
|
|
|
|
sigM = P;
|
2019-09-23 15:27:10 -05:00
|
|
|
|
|
|
|
clock = port(dsp, \CLK, SigBit());
|
2019-08-30 17:00:56 -05:00
|
|
|
endcode
|
|
|
|
|
2020-07-22 05:27:15 -05:00
|
|
|
// (2) Match the driver of the 'A' input to a possible $sdffe cell (ADREG)
|
2019-10-04 14:40:34 -05:00
|
|
|
// If matched, treat 'A' input as input of ADREG
|
2020-07-22 05:27:15 -05:00
|
|
|
code argQ ffAD sigA clock
|
2020-04-22 14:02:30 -05:00
|
|
|
if (param(dsp, \ADREG).as_int() == 0) {
|
2019-09-09 18:45:38 -05:00
|
|
|
argQ = sigA;
|
2019-09-09 17:51:14 -05:00
|
|
|
subpattern(in_dffe);
|
|
|
|
if (dff) {
|
|
|
|
ffAD = dff;
|
|
|
|
clock = dffclock;
|
|
|
|
sigA = dffD;
|
|
|
|
}
|
2019-09-06 16:06:57 -05:00
|
|
|
}
|
|
|
|
endcode
|
|
|
|
|
2019-10-04 14:40:34 -05:00
|
|
|
// (3) Match the driver of the 'A' and 'D' inputs for a possible $add cell
|
|
|
|
// (pre-adder)
|
2019-09-06 16:06:57 -05:00
|
|
|
match preAdd
|
|
|
|
if sigD.empty() || sigD.is_fully_zero()
|
|
|
|
// Ensure that preAdder not already used
|
2020-04-22 14:02:30 -05:00
|
|
|
if param(dsp, \USE_DPORT).decode_string() == "FALSE"
|
2019-09-20 16:21:22 -05:00
|
|
|
if port(dsp, \INMODE, Const(0, 5)).is_fully_zero()
|
2019-09-06 16:06:57 -05:00
|
|
|
|
|
|
|
select preAdd->type.in($add)
|
|
|
|
// Output has to be 25 bits or less
|
|
|
|
select GetSize(port(preAdd, \Y)) <= 25
|
|
|
|
select nusers(port(preAdd, \Y)) == 2
|
|
|
|
choice <IdString> AB {\A, \B}
|
|
|
|
// A port has to be 30 bits or less
|
|
|
|
select GetSize(port(preAdd, AB)) <= 30
|
|
|
|
define <IdString> BA (AB == \A ? \B : \A)
|
|
|
|
// D port has to be 25 bits or less
|
|
|
|
select GetSize(port(preAdd, BA)) <= 25
|
|
|
|
index <SigSpec> port(preAdd, \Y) === sigA
|
|
|
|
|
|
|
|
optional
|
|
|
|
endmatch
|
|
|
|
|
2019-10-04 15:33:27 -05:00
|
|
|
code sigA sigD
|
|
|
|
if (preAdd) {
|
|
|
|
sigA = port(preAdd, \A);
|
|
|
|
sigD = port(preAdd, \B);
|
|
|
|
}
|
|
|
|
endcode
|
|
|
|
|
2019-10-04 14:40:34 -05:00
|
|
|
// (4) If pre-adder was present, find match 'A' input for A2REG
|
|
|
|
// If pre-adder was not present, move ADREG to A2REG
|
|
|
|
// Then match 'A' input for A1REG
|
2020-07-22 05:27:15 -05:00
|
|
|
code argQ ffAD sigA clock ffA2 ffA1
|
2019-09-11 18:21:24 -05:00
|
|
|
// Only search for ffA2 if there was a pre-adder
|
2019-09-11 19:16:46 -05:00
|
|
|
// (otherwise ffA2 would have been matched as ffAD)
|
2019-09-09 17:51:14 -05:00
|
|
|
if (preAdd) {
|
2020-04-22 14:02:30 -05:00
|
|
|
if (param(dsp, \AREG).as_int() == 0) {
|
2019-09-09 18:45:38 -05:00
|
|
|
argQ = sigA;
|
2019-09-09 17:51:14 -05:00
|
|
|
subpattern(in_dffe);
|
|
|
|
if (dff) {
|
2019-09-11 18:21:24 -05:00
|
|
|
ffA2 = dff;
|
2019-09-09 17:51:14 -05:00
|
|
|
clock = dffclock;
|
|
|
|
sigA = dffD;
|
|
|
|
}
|
|
|
|
}
|
2019-09-06 16:06:57 -05:00
|
|
|
}
|
2019-09-09 17:51:14 -05:00
|
|
|
// And if there wasn't a pre-adder,
|
|
|
|
// move AD register to A
|
|
|
|
else if (ffAD) {
|
2020-07-22 05:27:15 -05:00
|
|
|
log_assert(!ffA2);
|
2019-09-11 18:21:24 -05:00
|
|
|
std::swap(ffA2, ffAD);
|
2019-09-06 16:06:57 -05:00
|
|
|
}
|
2019-09-11 19:16:46 -05:00
|
|
|
|
|
|
|
// Now attempt to match A1
|
|
|
|
if (ffA2) {
|
|
|
|
argQ = sigA;
|
|
|
|
subpattern(in_dffe);
|
|
|
|
if (dff) {
|
2020-07-22 05:27:15 -05:00
|
|
|
if (dff->type != ffA2->type)
|
2019-09-11 19:16:46 -05:00
|
|
|
goto ffA1_end;
|
2020-07-22 05:27:15 -05:00
|
|
|
if (dff->type.in($sdff, $sdffe, $sdffce)) {
|
|
|
|
if (param(dff, \SRST_POLARITY) != param(ffA2, \SRST_POLARITY))
|
2019-09-11 19:16:46 -05:00
|
|
|
goto ffA1_end;
|
2020-07-22 05:27:15 -05:00
|
|
|
if (port(dff, \SRST) != port(ffA2, \SRST))
|
|
|
|
goto ffA1_end;
|
|
|
|
}
|
|
|
|
if (dff->type.in($dffe, $sdffe, $sdffce)) {
|
|
|
|
if (param(dff, \EN_POLARITY) != param(ffA2, \EN_POLARITY))
|
|
|
|
goto ffA1_end;
|
|
|
|
if (port(dff, \EN) != port(ffA2, \EN))
|
2019-09-11 19:16:46 -05:00
|
|
|
goto ffA1_end;
|
|
|
|
}
|
|
|
|
|
|
|
|
ffA1 = dff;
|
|
|
|
clock = dffclock;
|
|
|
|
sigA = dffD;
|
|
|
|
|
|
|
|
ffA1_end: ;
|
|
|
|
}
|
|
|
|
}
|
2019-09-06 16:06:57 -05:00
|
|
|
endcode
|
|
|
|
|
2019-10-04 14:40:34 -05:00
|
|
|
// (5) Match 'B' input for B2REG
|
|
|
|
// If B2REG, then match 'B' input for B1REG
|
2020-07-22 05:27:15 -05:00
|
|
|
code argQ ffB2 sigB clock ffB1
|
2020-04-22 14:02:30 -05:00
|
|
|
if (param(dsp, \BREG).as_int() == 0) {
|
2019-09-09 18:45:38 -05:00
|
|
|
argQ = sigB;
|
2019-09-09 17:51:14 -05:00
|
|
|
subpattern(in_dffe);
|
|
|
|
if (dff) {
|
2019-09-11 18:21:24 -05:00
|
|
|
ffB2 = dff;
|
2019-09-09 17:51:14 -05:00
|
|
|
clock = dffclock;
|
|
|
|
sigB = dffD;
|
2019-09-11 19:16:46 -05:00
|
|
|
|
|
|
|
// Now attempt to match B1
|
|
|
|
if (ffB2) {
|
|
|
|
argQ = sigB;
|
|
|
|
subpattern(in_dffe);
|
|
|
|
if (dff) {
|
2020-07-22 05:27:15 -05:00
|
|
|
if (dff->type != ffB2->type)
|
2019-09-11 19:16:46 -05:00
|
|
|
goto ffB1_end;
|
2020-07-22 05:27:15 -05:00
|
|
|
if (dff->type.in($sdff, $sdffe, $sdffce)) {
|
|
|
|
if (param(dff, \SRST_POLARITY) != param(ffB2, \SRST_POLARITY))
|
|
|
|
goto ffB1_end;
|
|
|
|
if (port(dff, \SRST) != port(ffB2, \SRST))
|
|
|
|
goto ffB1_end;
|
|
|
|
}
|
|
|
|
if (dff->type.in($dffe, $sdffe, $sdffce)) {
|
|
|
|
if (param(dff, \EN_POLARITY) != param(ffB2, \EN_POLARITY))
|
2019-09-11 19:16:46 -05:00
|
|
|
goto ffB1_end;
|
2020-07-22 05:27:15 -05:00
|
|
|
if (port(dff, \EN) != port(ffB2, \EN))
|
2019-09-11 19:16:46 -05:00
|
|
|
goto ffB1_end;
|
|
|
|
}
|
|
|
|
|
|
|
|
ffB1 = dff;
|
|
|
|
clock = dffclock;
|
|
|
|
sigB = dffD;
|
|
|
|
|
|
|
|
ffB1_end: ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-09 17:51:14 -05:00
|
|
|
}
|
2019-07-15 16:46:31 -05:00
|
|
|
}
|
|
|
|
endcode
|
|
|
|
|
2019-10-04 14:40:34 -05:00
|
|
|
// (6) Match 'D' input for DREG
|
2020-07-22 05:27:15 -05:00
|
|
|
code argQ ffD sigD clock
|
2020-04-22 14:02:30 -05:00
|
|
|
if (param(dsp, \DREG).as_int() == 0) {
|
2019-09-09 18:45:38 -05:00
|
|
|
argQ = sigD;
|
2019-09-09 17:51:14 -05:00
|
|
|
subpattern(in_dffe);
|
|
|
|
if (dff) {
|
|
|
|
ffD = dff;
|
|
|
|
clock = dffclock;
|
|
|
|
sigD = dffD;
|
|
|
|
}
|
2019-09-06 17:32:26 -05:00
|
|
|
}
|
|
|
|
endcode
|
|
|
|
|
2019-10-04 14:40:34 -05:00
|
|
|
// (7) Match 'P' output that exclusively drives an MREG
|
2020-07-22 05:27:15 -05:00
|
|
|
code argD ffM sigM sigP clock
|
2020-04-22 14:02:30 -05:00
|
|
|
if (param(dsp, \MREG).as_int() == 0 && nusers(sigM) == 2) {
|
2019-09-10 20:27:05 -05:00
|
|
|
argD = sigM;
|
|
|
|
subpattern(out_dffe);
|
|
|
|
if (dff) {
|
|
|
|
ffM = dff;
|
|
|
|
clock = dffclock;
|
|
|
|
sigM = dffQ;
|
|
|
|
}
|
2019-08-30 17:00:56 -05:00
|
|
|
}
|
|
|
|
sigP = sigM;
|
2019-08-09 17:19:33 -05:00
|
|
|
endcode
|
|
|
|
|
2019-10-04 14:40:34 -05:00
|
|
|
// (8) Match 'P' output that exclusively drives one of two inputs to an $add
|
|
|
|
// cell (post-adder).
|
|
|
|
// The other input to the adder is assumed to come in from the 'C' input
|
|
|
|
// (note: 'P' -> 'C' connections that exist for accumulators are
|
|
|
|
// recognised in xilinx_dsp.cc).
|
2019-09-03 18:10:16 -05:00
|
|
|
match postAdd
|
|
|
|
// Ensure that Z mux is not already used
|
2020-01-17 18:05:10 -06:00
|
|
|
if port(dsp, \OPMODE, SigSpec(0, 7)).extract(4,3).is_fully_zero()
|
2019-09-03 18:10:16 -05:00
|
|
|
|
2019-09-03 18:24:59 -05:00
|
|
|
select postAdd->type.in($add)
|
2019-09-06 12:35:06 -05:00
|
|
|
select GetSize(port(postAdd, \Y)) <= 48
|
2019-09-03 18:10:16 -05:00
|
|
|
choice <IdString> AB {\A, \B}
|
2020-07-22 05:27:15 -05:00
|
|
|
select nusers(port(postAdd, AB)) == 2
|
2019-09-19 22:04:44 -05:00
|
|
|
|
|
|
|
index <SigBit> port(postAdd, AB)[0] === sigP[0]
|
2019-09-25 19:22:30 -05:00
|
|
|
filter GetSize(port(postAdd, AB)) >= GetSize(sigP)
|
|
|
|
filter port(postAdd, AB).extract(0, GetSize(sigP)) == sigP
|
2019-11-26 23:26:53 -06:00
|
|
|
// Check that remainder of AB is a sign- or zero-extension
|
|
|
|
filter port(postAdd, AB).extract_end(GetSize(sigP)) == SigSpec(sigP[GetSize(sigP)-1], GetSize(port(postAdd, AB))-GetSize(sigP)) || port(postAdd, AB).extract_end(GetSize(sigP)) == SigSpec(State::S0, GetSize(port(postAdd, AB))-GetSize(sigP))
|
|
|
|
|
2019-09-03 18:10:16 -05:00
|
|
|
set postAddAB AB
|
2019-08-09 17:19:33 -05:00
|
|
|
optional
|
|
|
|
endmatch
|
|
|
|
|
2019-09-03 18:10:16 -05:00
|
|
|
code sigC sigP
|
|
|
|
if (postAdd) {
|
|
|
|
sigC = port(postAdd, postAddAB == \A ? \B : \A);
|
|
|
|
sigP = port(postAdd, \Y);
|
2019-08-09 17:19:33 -05:00
|
|
|
}
|
|
|
|
endcode
|
|
|
|
|
2019-10-04 14:40:34 -05:00
|
|
|
// (9) Match 'P' output that exclusively drives a PREG
|
2020-07-22 05:27:15 -05:00
|
|
|
code argD ffP sigP clock
|
2020-04-22 14:02:30 -05:00
|
|
|
if (param(dsp, \PREG).as_int() == 0) {
|
2020-07-22 05:27:15 -05:00
|
|
|
if (nusers(sigP) == 2) {
|
2019-09-10 20:27:05 -05:00
|
|
|
argD = sigP;
|
|
|
|
subpattern(out_dffe);
|
|
|
|
if (dff) {
|
|
|
|
ffP = dff;
|
|
|
|
clock = dffclock;
|
|
|
|
sigP = dffQ;
|
|
|
|
}
|
|
|
|
}
|
2019-09-03 17:53:10 -05:00
|
|
|
}
|
|
|
|
endcode
|
|
|
|
|
2019-10-04 14:40:34 -05:00
|
|
|
// (10) If post-adder and PREG both present, match for a $mux cell driving
|
|
|
|
// the 'C' input, where one of the $mux's inputs is the PREG output.
|
|
|
|
// This indicates an accumulator situation, and one where a $mux exists
|
|
|
|
// to override the accumulated value:
|
|
|
|
// +--------------------------------+
|
|
|
|
// | ____ |
|
|
|
|
// +--| \ |
|
|
|
|
// |$mux|-+ |
|
|
|
|
// 'C' ---|____/ | |
|
|
|
|
// | /-------\ +----+ |
|
|
|
|
// +----+ +-| post- |___|PREG|---+ 'P'
|
|
|
|
// |MREG|------ | adder | +----+
|
|
|
|
// +----+ \-------/
|
2019-09-03 18:24:59 -05:00
|
|
|
match postAddMux
|
2019-09-03 18:10:16 -05:00
|
|
|
if postAdd
|
2019-09-03 18:24:59 -05:00
|
|
|
if ffP
|
|
|
|
select postAddMux->type.in($mux)
|
|
|
|
select nusers(port(postAddMux, \Y)) == 2
|
|
|
|
choice <IdString> AB {\A, \B}
|
|
|
|
index <SigSpec> port(postAddMux, AB) === sigP
|
|
|
|
index <SigSpec> port(postAddMux, \Y) === sigC
|
|
|
|
set postAddMuxAB AB
|
2019-09-03 17:53:10 -05:00
|
|
|
optional
|
|
|
|
endmatch
|
|
|
|
|
2019-09-03 18:24:59 -05:00
|
|
|
code sigC
|
|
|
|
if (postAddMux)
|
|
|
|
sigC = port(postAddMux, postAddMuxAB == \A ? \B : \A);
|
2019-09-03 17:53:10 -05:00
|
|
|
endcode
|
2019-08-30 13:02:10 -05:00
|
|
|
|
2019-10-04 14:40:34 -05:00
|
|
|
// (11) If PREG present, match for a greater-than-or-equal $ge cell attached to
|
|
|
|
// the 'P' output where it is compared to a constant that is a power-of-2:
|
|
|
|
// e.g. `assign overflow = (PREG >= 2**40);`
|
|
|
|
// In this scenario, the pattern detector functionality of a DSP48E1 can
|
|
|
|
// to implement this function
|
2019-09-18 11:39:59 -05:00
|
|
|
match overflow
|
|
|
|
if ffP
|
2020-04-22 14:02:30 -05:00
|
|
|
if param(dsp, \USE_PATTERN_DETECT).decode_string() == "NO_PATDET"
|
2019-09-18 11:39:59 -05:00
|
|
|
select overflow->type.in($ge)
|
|
|
|
select GetSize(port(overflow, \Y)) <= 48
|
|
|
|
select port(overflow, \B).is_fully_const()
|
2019-09-18 14:16:03 -05:00
|
|
|
define <Const> B port(overflow, \B).as_const()
|
2024-10-09 12:39:45 -05:00
|
|
|
select std::count(B.begin(), B.end(), State::S1) == 1
|
2019-09-18 11:39:59 -05:00
|
|
|
index <SigSpec> port(overflow, \A) === sigP
|
|
|
|
optional
|
|
|
|
endmatch
|
|
|
|
|
2019-09-09 17:51:14 -05:00
|
|
|
code
|
|
|
|
accept;
|
|
|
|
endcode
|
|
|
|
|
2019-09-10 20:27:05 -05:00
|
|
|
// #######################
|
|
|
|
|
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-09 17:51:14 -05:00
|
|
|
subpattern in_dffe
|
2020-07-22 05:27:15 -05:00
|
|
|
arg argQ clock
|
2019-09-11 12:15:19 -05:00
|
|
|
|
|
|
|
code
|
|
|
|
dff = nullptr;
|
2020-01-17 19:07:03 -06:00
|
|
|
if (argQ.empty())
|
2019-11-18 01:19:53 -06:00
|
|
|
reject;
|
2019-10-04 15:31:44 -05:00
|
|
|
for (const auto &c : argQ.chunks()) {
|
|
|
|
// Abandon matches when 'Q' is a constant
|
2019-09-11 12:15:19 -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-11 12:15:19 -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());
|
|
|
|
if (!init.empty())
|
|
|
|
for (auto b : init.extract(c.offset, c.width))
|
|
|
|
if (b != State::Sx && b != State::S0)
|
|
|
|
reject;
|
2019-09-11 12:15:19 -05:00
|
|
|
}
|
|
|
|
endcode
|
2019-09-09 17:51:14 -05:00
|
|
|
|
|
|
|
match ff
|
2020-07-22 05:27:15 -05:00
|
|
|
select ff->type.in($dff, $dffe, $sdff, $sdffe)
|
2019-09-06 23:01:36 -05:00
|
|
|
// DSP48E1 does not support clock inversion
|
2019-09-09 17:51:14 -05:00
|
|
|
select param(ff, \CLK_POLARITY).as_bool()
|
2019-09-11 12:15:19 -05:00
|
|
|
|
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-11 12:15:19 -05:00
|
|
|
slice offset GetSize(port(ff, \D))
|
|
|
|
index <SigBit> port(ff, \Q)[offset] === argQ[0]
|
2019-09-19 16:34:06 -05:00
|
|
|
|
|
|
|
// 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-06 23:01:36 -05:00
|
|
|
endmatch
|
|
|
|
|
2020-07-22 05:27:15 -05:00
|
|
|
code argQ
|
2019-09-11 12:15:19 -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-11 12:15:19 -05:00
|
|
|
argQ = Q;
|
2020-07-22 05:27:15 -05:00
|
|
|
dffD.replace(argQ, D);
|
2019-07-15 16:46:31 -05:00
|
|
|
endcode
|
2019-09-10 20:27:05 -05:00
|
|
|
|
|
|
|
// #######################
|
|
|
|
|
2019-10-04 15:31:44 -05:00
|
|
|
// Subpattern for matching against output registers, based on knowledge of the
|
|
|
|
// 'D' input.
|
|
|
|
// At a high level:
|
|
|
|
// (1) Starting from an optional $mux cell that implements clock enable
|
|
|
|
// semantics --- one where the given 'D' argument (partially or fully)
|
|
|
|
// drives one of its two inputs
|
|
|
|
// (2) Starting from, or continuing onto, another optional $mux cell that
|
|
|
|
// implements synchronous reset semantics --- one where the given 'D'
|
|
|
|
// argument (or the clock enable $mux output) drives one of its two inputs
|
|
|
|
// and where the other input is fully zero
|
|
|
|
// (3) Match for a $dff cell (whose 'D' input is the 'D' argument, or the
|
|
|
|
// output of the previous clock enable or reset $mux cells)
|
2019-09-10 20:27:05 -05:00
|
|
|
subpattern out_dffe
|
2019-09-10 22:51:48 -05:00
|
|
|
arg argD argQ clock
|
2019-09-10 20:27:05 -05:00
|
|
|
|
2019-09-11 09:34:14 -05:00
|
|
|
code
|
|
|
|
dff = nullptr;
|
2019-09-19 16:34:06 -05:00
|
|
|
for (auto c : argD.chunks())
|
2019-10-04 15:31:44 -05:00
|
|
|
// Abandon matches when 'D' has the keep attribute set
|
2019-09-19 16:34:06 -05:00
|
|
|
if (c.wire->get_bool_attribute(\keep))
|
|
|
|
reject;
|
2019-09-11 09:34:14 -05:00
|
|
|
endcode
|
|
|
|
|
2019-09-10 20:27:05 -05:00
|
|
|
match ff
|
2020-07-22 05:27:15 -05:00
|
|
|
select ff->type.in($dff, $dffe, $sdff, $sdffe)
|
2019-09-10 20:27:05 -05:00
|
|
|
// DSP48E1 does not support clock inversion
|
|
|
|
select param(ff, \CLK_POLARITY).as_bool()
|
2019-09-11 09:34:14 -05:00
|
|
|
|
|
|
|
slice offset GetSize(port(ff, \D))
|
2019-09-11 12:15:19 -05:00
|
|
|
index <SigBit> port(ff, \D)[offset] === argD[0]
|
2019-09-11 09:34:14 -05:00
|
|
|
|
2019-09-19 16:34:06 -05:00
|
|
|
// Check that the rest of argD is present
|
|
|
|
filter GetSize(port(ff, \D)) >= offset + GetSize(argD)
|
|
|
|
filter port(ff, \D).extract(offset, GetSize(argD)) == argD
|
2019-09-11 09:34:14 -05:00
|
|
|
|
2024-02-08 10:46:00 -06:00
|
|
|
filter clock == SigBit() || port(ff, \CLK)[0] == clock
|
2019-09-10 20:27:05 -05:00
|
|
|
endmatch
|
|
|
|
|
2019-09-11 09:34:14 -05:00
|
|
|
code argQ
|
2019-10-04 15:31:44 -05:00
|
|
|
SigSpec D = port(ff, \D);
|
|
|
|
SigSpec Q = port(ff, \Q);
|
2020-07-22 05:27:15 -05:00
|
|
|
argQ = argD;
|
|
|
|
argQ.replace(D, Q);
|
2019-09-10 20:27:05 -05:00
|
|
|
|
2019-10-04 15:31:44 -05:00
|
|
|
// Abandon matches when 'Q' has a non-zero init attribute set
|
|
|
|
// (not supported by DSP48E1)
|
|
|
|
for (auto c : argQ.chunks()) {
|
|
|
|
Const init = c.wire->attributes.at(\init, Const());
|
|
|
|
if (!init.empty())
|
|
|
|
for (auto b : init.extract(c.offset, c.width))
|
|
|
|
if (b != State::Sx && b != State::S0)
|
|
|
|
reject;
|
2019-09-10 20:27:05 -05:00
|
|
|
}
|
2019-10-04 15:31:44 -05:00
|
|
|
|
|
|
|
dff = ff;
|
|
|
|
dffQ = argQ;
|
|
|
|
dffclock = port(ff, \CLK);
|
2019-09-10 20:27:05 -05:00
|
|
|
endcode
|