2019-07-15 16:46:31 -05:00
|
|
|
pattern xilinx_dsp
|
|
|
|
|
2019-09-11 15:06:49 -05:00
|
|
|
udata <std::function<SigSpec(const SigSpec&)>> unextend
|
2019-07-15 16:46:31 -05:00
|
|
|
state <SigBit> clock
|
2019-09-11 12:15:19 -05:00
|
|
|
state <SigSpec> sigA sigffAcemuxY sigB sigffBcemuxY sigC sigffCcemuxY sigD sigffDcemuxY sigM sigP
|
2019-09-05 23:38:35 -05:00
|
|
|
state <IdString> postAddAB postAddMuxAB
|
2019-09-11 18:21:24 -05:00
|
|
|
state <bool> ffA1cepol ffA2cepol ffADcepol ffB1cepol ffB2cepol ffCcepol ffDcepol ffMcepol ffPcepol
|
2019-09-11 12:15:19 -05:00
|
|
|
state <bool> ffArstpol ffADrstpol ffBrstpol ffCrstpol ffDrstpol ffMrstpol ffPrstpol
|
2019-07-15 16:46:31 -05:00
|
|
|
|
2019-09-11 18:21:24 -05:00
|
|
|
state <Cell*> ffAD ffADcemux ffADrstmux ffA1 ffA1cemux ffA1rstmux ffA2 ffA2cemux ffA2rstmux
|
|
|
|
state <Cell*> ffB1 ffB1cemux ffB1rstmux ffB2 ffB2cemux ffB2rstmux ffC ffCcemux ffCrstmux
|
2019-09-11 12:15:19 -05:00
|
|
|
state <Cell*> ffD ffDcemux ffDrstmux ffM ffMcemux ffMrstmux ffP ffPcemux ffPrstmux
|
2019-09-09 17:51:14 -05:00
|
|
|
|
|
|
|
// subpattern
|
2019-09-10 20:27:05 -05:00
|
|
|
state <SigSpec> argQ argD
|
2019-09-10 22:51:48 -05:00
|
|
|
state <bool> ffcepol ffrstpol
|
2019-09-11 09:34:14 -05:00
|
|
|
state <int> ffoffset
|
2019-09-10 20:27:05 -05:00
|
|
|
udata <SigSpec> dffD dffQ
|
2019-09-09 17:51:14 -05:00
|
|
|
udata <SigBit> dffclock
|
2019-09-10 22:51:48 -05:00
|
|
|
udata <Cell*> dff dffcemux dffrstmux
|
|
|
|
udata <bool> dffcepol dffrstpol
|
2019-09-09 17:51:14 -05:00
|
|
|
|
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-11 15:06:49 -05:00
|
|
|
code sigA sigB sigC sigD sigM
|
2019-09-06 23:01:36 -05:00
|
|
|
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-06 20:40:11 -05:00
|
|
|
sigC = dsp->connections_.at(\C, SigSpec());
|
2019-09-06 16:06:57 -05:00
|
|
|
sigD = dsp->connections_.at(\D, SigSpec());
|
|
|
|
|
2019-09-04 19:06:17 -05:00
|
|
|
SigSpec P = port(dsp, \P);
|
2019-09-09 22:57:03 -05:00
|
|
|
if (dsp->parameters.at(\USE_MULT, Const("MULTIPLY")).decode_string() == "MULTIPLY") {
|
|
|
|
// Only care about those bits that are used
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < GetSize(P); i++) {
|
|
|
|
if (nusers(P[i]) <= 1)
|
|
|
|
break;
|
|
|
|
sigM.append(P[i]);
|
|
|
|
}
|
|
|
|
log_assert(nusers(P.extract_end(i)) <= 1);
|
2019-09-04 19:06:17 -05:00
|
|
|
}
|
2019-09-09 22:57:03 -05:00
|
|
|
else
|
|
|
|
sigM = P;
|
2019-08-30 17:00:56 -05:00
|
|
|
endcode
|
|
|
|
|
2019-09-11 12:15:19 -05:00
|
|
|
code argQ ffAD ffADcemux ffADrstmux ffADcepol ffADrstpol sigA clock
|
2019-09-09 17:51:14 -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;
|
2019-09-10 20:52:54 -05:00
|
|
|
if (dffcemux) {
|
2019-09-11 12:15:19 -05:00
|
|
|
ffADcemux = dffcemux;
|
|
|
|
ffADrstmux = dffrstmux;
|
2019-09-10 20:59:03 -05:00
|
|
|
ffADcepol = dffcepol;
|
2019-09-11 12:15:19 -05:00
|
|
|
ffADrstpol = dffrstpol;
|
2019-09-09 17:51:14 -05:00
|
|
|
}
|
|
|
|
sigA = dffD;
|
|
|
|
}
|
2019-09-06 16:06:57 -05:00
|
|
|
}
|
|
|
|
endcode
|
|
|
|
|
|
|
|
match preAdd
|
|
|
|
if sigD.empty() || sigD.is_fully_zero()
|
|
|
|
// Ensure that preAdder not already used
|
|
|
|
if dsp->parameters.at(\USE_DPORT, Const("FALSE")).decode_string() == "FALSE"
|
|
|
|
if dsp->connections_.at(\INMODE, Const(0, 5)).is_fully_zero()
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
code sigA sigD
|
|
|
|
if (preAdd) {
|
|
|
|
sigA = port(preAdd, \A);
|
|
|
|
sigD = port(preAdd, \B);
|
|
|
|
if (GetSize(sigA) < GetSize(sigD))
|
|
|
|
std::swap(sigA, sigD);
|
|
|
|
}
|
|
|
|
endcode
|
|
|
|
|
2019-09-11 19:16:46 -05:00
|
|
|
code argQ ffAD ffADcemux ffADrstmux ffADcepol ffADrstpol sigA clock ffA2 ffA2cemux ffA2rstmux ffA2cepol ffArstpol ffA1 ffA1cemux ffA1rstmux ffA1cepol
|
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) {
|
|
|
|
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;
|
2019-09-11 19:16:46 -05:00
|
|
|
if (dffrstmux) {
|
|
|
|
ffA2cepol = dffcepol;
|
|
|
|
ffArstpol = dffrstpol;
|
|
|
|
}
|
2019-09-10 20:52:54 -05:00
|
|
|
if (dffcemux) {
|
2019-09-11 18:21:24 -05:00
|
|
|
ffA2cemux = dffcemux;
|
|
|
|
ffA2rstmux = dffrstmux;
|
2019-09-09 17:51:14 -05:00
|
|
|
}
|
|
|
|
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) {
|
2019-09-11 18:21:24 -05:00
|
|
|
log_assert(!ffA2 && !ffA2cemux && !ffA2rstmux);
|
|
|
|
std::swap(ffA2, ffAD);
|
|
|
|
std::swap(ffA2cemux, ffADcemux);
|
|
|
|
std::swap(ffA2rstmux, ffADrstmux);
|
|
|
|
ffA2cepol = ffADcepol;
|
2019-09-11 12:15:19 -05:00
|
|
|
ffArstpol = ffADrstpol;
|
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) {
|
|
|
|
if ((ffA2rstmux != nullptr) ^ (dffrstmux != nullptr))
|
|
|
|
goto ffA1_end;
|
|
|
|
if (dffrstmux) {
|
|
|
|
if (ffArstpol != dffrstpol)
|
|
|
|
goto ffA1_end;
|
|
|
|
if (port(ffA2rstmux, \S) != port(dffrstmux, \S))
|
|
|
|
goto ffA1_end;
|
|
|
|
ffA1rstmux = dffrstmux;
|
|
|
|
}
|
|
|
|
|
|
|
|
ffA1 = dff;
|
|
|
|
clock = dffclock;
|
|
|
|
|
|
|
|
if (dffcemux) {
|
|
|
|
ffA1cemux = dffcemux;
|
|
|
|
ffA1cepol = dffcepol;
|
|
|
|
}
|
|
|
|
sigA = dffD;
|
|
|
|
|
|
|
|
ffA1_end: ;
|
|
|
|
}
|
|
|
|
}
|
2019-09-06 16:06:57 -05:00
|
|
|
endcode
|
|
|
|
|
2019-09-11 19:16:46 -05:00
|
|
|
code argQ ffB2 ffB2cemux ffB2rstmux ffB2cepol ffBrstpol sigB clock ffB1 ffB1cemux ffB1rstmux ffB1cepol
|
2019-09-09 17:51:14 -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;
|
2019-09-10 20:52:54 -05:00
|
|
|
if (dffcemux) {
|
2019-09-11 18:21:24 -05:00
|
|
|
ffB2cemux = dffcemux;
|
|
|
|
ffB2rstmux = dffrstmux;
|
|
|
|
ffB2cepol = dffcepol;
|
2019-09-11 12:15:19 -05:00
|
|
|
ffBrstpol = dffrstpol;
|
2019-09-09 17:51:14 -05:00
|
|
|
}
|
|
|
|
sigB = dffD;
|
2019-09-11 19:16:46 -05:00
|
|
|
|
|
|
|
// Now attempt to match B1
|
|
|
|
if (ffB2) {
|
|
|
|
argQ = sigB;
|
|
|
|
subpattern(in_dffe);
|
|
|
|
if (dff) {
|
|
|
|
if ((ffB2rstmux != nullptr) ^ (dffrstmux != nullptr))
|
|
|
|
goto ffB1_end;
|
|
|
|
if (dffrstmux) {
|
|
|
|
if (ffBrstpol != dffrstpol)
|
|
|
|
goto ffB1_end;
|
|
|
|
if (port(ffB2rstmux, \S) != port(dffrstmux, \S))
|
|
|
|
goto ffB1_end;
|
|
|
|
ffB1rstmux = dffrstmux;
|
|
|
|
}
|
|
|
|
|
|
|
|
ffB1 = dff;
|
|
|
|
clock = dffclock;
|
|
|
|
|
|
|
|
if (dffcemux) {
|
|
|
|
ffB1cemux = dffcemux;
|
|
|
|
ffB1cepol = dffcepol;
|
|
|
|
}
|
|
|
|
sigB = dffD;
|
|
|
|
|
|
|
|
ffB1_end: ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-09 17:51:14 -05:00
|
|
|
}
|
2019-07-15 16:46:31 -05:00
|
|
|
}
|
|
|
|
endcode
|
|
|
|
|
2019-09-11 12:15:19 -05:00
|
|
|
code argQ ffD ffDcemux ffDrstmux ffDcepol ffDrstpol sigD clock
|
2019-09-09 17:51:14 -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;
|
2019-09-10 20:52:54 -05:00
|
|
|
if (dffcemux) {
|
2019-09-11 12:15:19 -05:00
|
|
|
ffDcemux = dffcemux;
|
|
|
|
ffDrstmux = dffrstmux;
|
2019-09-10 20:59:03 -05:00
|
|
|
ffDcepol = dffcepol;
|
2019-09-11 12:15:19 -05:00
|
|
|
ffDrstpol = dffrstpol;
|
2019-09-09 17:51:14 -05:00
|
|
|
}
|
|
|
|
sigD = dffD;
|
|
|
|
}
|
2019-09-06 17:32:26 -05:00
|
|
|
}
|
|
|
|
endcode
|
|
|
|
|
2019-09-11 09:34:14 -05:00
|
|
|
code argD ffM ffMcemux ffMrstmux ffMcepol ffMrstpol sigM sigP clock
|
2019-09-10 20:27:05 -05:00
|
|
|
if (param(dsp, \MREG).as_int() == 0 && nusers(sigM) == 2) {
|
|
|
|
argD = sigM;
|
|
|
|
subpattern(out_dffe);
|
|
|
|
if (dff) {
|
|
|
|
ffM = dff;
|
|
|
|
clock = dffclock;
|
2019-09-10 20:52:54 -05:00
|
|
|
if (dffcemux) {
|
2019-09-11 09:34:14 -05:00
|
|
|
ffMcemux = dffcemux;
|
|
|
|
ffMrstmux = dffrstmux;
|
2019-09-10 20:59:03 -05:00
|
|
|
ffMcepol = dffcepol;
|
2019-09-11 09:34:14 -05:00
|
|
|
ffMrstpol = dffrstpol;
|
2019-09-10 20:27:05 -05:00
|
|
|
}
|
|
|
|
sigM = dffQ;
|
|
|
|
}
|
2019-08-30 17:00:56 -05:00
|
|
|
}
|
|
|
|
sigP = sigM;
|
2019-08-09 17:19:33 -05:00
|
|
|
endcode
|
|
|
|
|
2019-09-03 18:10:16 -05:00
|
|
|
match postAdd
|
|
|
|
// Ensure that Z mux is not already used
|
|
|
|
if port(dsp, \OPMODE).extract(4,3).is_fully_zero()
|
|
|
|
|
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
|
|
|
|
select nusers(port(postAdd, \Y)) == 2
|
2019-09-03 18:10:16 -05:00
|
|
|
choice <IdString> AB {\A, \B}
|
2019-09-04 12:52:51 -05:00
|
|
|
select nusers(port(postAdd, AB)) <= 3
|
2019-09-11 09:34:14 -05:00
|
|
|
filter ffMcemux || nusers(port(postAdd, AB)) == 2
|
|
|
|
filter !ffMcemux || nusers(port(postAdd, AB)) == 3
|
2019-09-06 23:01:36 -05:00
|
|
|
filter GetSize(unextend(port(postAdd, AB))) <= GetSize(sigP)
|
|
|
|
filter unextend(port(postAdd, AB)) == sigP.extract(0, GetSize(unextend(port(postAdd, AB))))
|
|
|
|
filter nusers(sigP.extract_end(GetSize(unextend(port(postAdd, AB))))) <= 1
|
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);
|
2019-08-09 17:19:33 -05:00
|
|
|
|
2019-08-30 18:18:58 -05:00
|
|
|
// TODO for DSP48E1, which will have sign extended inputs/outputs
|
|
|
|
//int natural_mul_width = GetSize(port(dsp, \A)) + GetSize(port(dsp, \B));
|
|
|
|
//int actual_mul_width = GetSize(sigP);
|
|
|
|
//int actual_acc_width = GetSize(sigC);
|
2019-08-09 17:19:33 -05:00
|
|
|
|
2019-08-30 18:18:58 -05:00
|
|
|
//if ((actual_acc_width > actual_mul_width) && (natural_mul_width > actual_mul_width))
|
|
|
|
// reject;
|
2019-09-03 18:10:16 -05:00
|
|
|
//if ((actual_acc_width != actual_mul_width) && (param(dsp, \A_SIGNED).as_bool() != param(postAdd, \A_SIGNED).as_bool()))
|
2019-08-09 17:19:33 -05:00
|
|
|
// reject;
|
|
|
|
|
2019-09-03 18:10:16 -05:00
|
|
|
sigP = port(postAdd, \Y);
|
2019-08-09 17:19:33 -05:00
|
|
|
}
|
|
|
|
endcode
|
|
|
|
|
2019-09-10 22:51:48 -05:00
|
|
|
code argD ffP ffPcemux ffPrstmux ffPcepol ffPrstpol sigP clock
|
2019-09-10 20:27:05 -05:00
|
|
|
if (param(dsp, \PREG).as_int() == 0) {
|
2019-09-11 09:34:14 -05:00
|
|
|
// If ffMcemux and no postAdd new-value net must have exactly three users: ffMcemux, ffM and ffPcemux
|
|
|
|
if ((ffMcemux && !postAdd && nusers(sigP) == 3) ||
|
2019-09-10 22:51:48 -05:00
|
|
|
// Otherwise new-value net must have exactly two users: dsp and ffPcemux
|
2019-09-11 09:34:14 -05:00
|
|
|
((!ffMcemux || postAdd) && nusers(sigP) == 2)) {
|
2019-09-10 20:27:05 -05:00
|
|
|
argD = sigP;
|
|
|
|
subpattern(out_dffe);
|
|
|
|
if (dff) {
|
|
|
|
ffP = dff;
|
|
|
|
clock = dffclock;
|
2019-09-10 20:52:54 -05:00
|
|
|
if (dffcemux) {
|
2019-09-10 22:51:48 -05:00
|
|
|
ffPcemux = dffcemux;
|
2019-09-10 20:59:03 -05:00
|
|
|
ffPcepol = dffcepol;
|
2019-09-10 22:51:48 -05:00
|
|
|
ffPrstmux = dffrstmux;
|
|
|
|
ffPrstpol = dffrstpol;
|
2019-09-10 20:27:05 -05:00
|
|
|
}
|
|
|
|
sigP = dffQ;
|
|
|
|
}
|
|
|
|
}
|
2019-09-03 17:53:10 -05:00
|
|
|
}
|
|
|
|
endcode
|
|
|
|
|
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-09-11 12:15:19 -05:00
|
|
|
code argQ ffC ffCcemux ffCrstmux ffCcepol ffCrstpol sigC clock
|
|
|
|
if (param(dsp, \CREG).as_int() == 0 && sigC != sigP) {
|
2019-09-09 18:45:38 -05:00
|
|
|
argQ = sigC;
|
2019-09-09 17:51:14 -05:00
|
|
|
subpattern(in_dffe);
|
|
|
|
if (dff) {
|
|
|
|
ffC = dff;
|
|
|
|
clock = dffclock;
|
2019-09-10 20:52:54 -05:00
|
|
|
if (dffcemux) {
|
2019-09-11 12:15:19 -05:00
|
|
|
ffCcemux = dffcemux;
|
|
|
|
ffCrstmux = dffrstmux;
|
2019-09-10 20:59:03 -05:00
|
|
|
ffCcepol = dffcepol;
|
2019-09-11 12:15:19 -05:00
|
|
|
ffCrstpol = dffrstpol;
|
2019-09-09 17:51:14 -05:00
|
|
|
}
|
|
|
|
sigC = dffD;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
endcode
|
|
|
|
|
|
|
|
code
|
|
|
|
accept;
|
|
|
|
endcode
|
|
|
|
|
2019-09-10 20:27:05 -05:00
|
|
|
// #######################
|
|
|
|
|
2019-09-09 17:51:14 -05:00
|
|
|
subpattern in_dffe
|
2019-09-11 12:15:19 -05:00
|
|
|
arg argD argQ clock
|
|
|
|
|
|
|
|
code
|
|
|
|
dff = nullptr;
|
|
|
|
for (auto c : argQ.chunks()) {
|
|
|
|
if (!c.wire)
|
|
|
|
reject;
|
|
|
|
if (c.wire->get_bool_attribute(\keep))
|
|
|
|
reject;
|
|
|
|
}
|
|
|
|
endcode
|
2019-09-09 17:51:14 -05:00
|
|
|
|
|
|
|
match ff
|
|
|
|
select ff->type.in($dff)
|
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
|
|
|
|
|
|
|
slice offset GetSize(port(ff, \D))
|
|
|
|
index <SigBit> port(ff, \Q)[offset] === argQ[0]
|
|
|
|
set ffoffset offset
|
2019-09-06 23:01:36 -05:00
|
|
|
endmatch
|
|
|
|
|
2019-09-11 12:15:19 -05:00
|
|
|
code argQ argD
|
|
|
|
{
|
|
|
|
if (clock != SigBit()) {
|
|
|
|
if (port(ff, \CLK) != clock)
|
|
|
|
reject;
|
|
|
|
}
|
2019-09-06 23:01:36 -05:00
|
|
|
|
2019-09-11 12:15:19 -05:00
|
|
|
SigSpec Q = port(ff, \Q);
|
|
|
|
if (ffoffset + GetSize(argQ) > GetSize(Q))
|
|
|
|
reject;
|
|
|
|
for (int i = 1; i < GetSize(argQ); i++)
|
|
|
|
if (Q[ffoffset+i] != argQ[i])
|
|
|
|
reject;
|
2019-09-09 17:51:14 -05:00
|
|
|
|
2019-09-11 12:15:19 -05:00
|
|
|
dff = ff;
|
|
|
|
dffclock = port(ff, \CLK);
|
|
|
|
dffD = argQ;
|
|
|
|
argD = port(ff, \D);
|
|
|
|
argQ = Q;
|
|
|
|
dffD.replace(argQ, argD);
|
|
|
|
// Only search for ffrstmux if dffD only
|
|
|
|
// has two (ff, ffrstmux) users
|
|
|
|
if (nusers(dffD) > 2)
|
|
|
|
argD = SigSpec();
|
|
|
|
}
|
|
|
|
endcode
|
|
|
|
|
|
|
|
match ffrstmux
|
|
|
|
if !argD.empty()
|
|
|
|
select ffrstmux->type.in($mux)
|
|
|
|
index <SigSpec> port(ffrstmux, \Y) === argD
|
|
|
|
|
|
|
|
choice <IdString> BA {\B, \A}
|
|
|
|
// DSP48E1 only supports reset to zero
|
|
|
|
select port(ffrstmux, BA).is_fully_zero()
|
|
|
|
|
|
|
|
define <bool> pol (BA == \B)
|
|
|
|
set ffrstpol pol
|
|
|
|
semioptional
|
|
|
|
endmatch
|
|
|
|
|
|
|
|
code argD
|
|
|
|
if (ffrstmux) {
|
|
|
|
dffrstmux = ffrstmux;
|
|
|
|
dffrstpol = ffrstpol;
|
|
|
|
argD = port(ffrstmux, ffrstpol ? \A : \B);
|
|
|
|
dffD.replace(port(ffrstmux, \Y), argD);
|
|
|
|
|
|
|
|
// Only search for ffrstmux if argQ has at
|
|
|
|
// least 3 users (ff, <upstream>, ffrstmux) and
|
|
|
|
// dffD only has two (ff, ffrstmux)
|
2019-09-09 18:45:38 -05:00
|
|
|
if (!(nusers(argQ) >= 3 && nusers(dffD) == 2))
|
2019-09-11 12:15:19 -05:00
|
|
|
argD = SigSpec();
|
2019-09-09 17:59:10 -05:00
|
|
|
}
|
2019-09-11 12:15:19 -05:00
|
|
|
else
|
|
|
|
dffrstmux = nullptr;
|
2019-09-06 23:01:36 -05:00
|
|
|
endcode
|
|
|
|
|
2019-09-10 20:52:54 -05:00
|
|
|
match ffcemux
|
2019-09-11 12:15:19 -05:00
|
|
|
if !argD.empty()
|
2019-09-10 20:52:54 -05:00
|
|
|
select ffcemux->type.in($mux)
|
2019-09-11 12:15:19 -05:00
|
|
|
index <SigSpec> port(ffcemux, \Y) === argD
|
2019-09-06 23:01:36 -05:00
|
|
|
choice <IdString> AB {\A, \B}
|
2019-09-11 12:15:19 -05:00
|
|
|
index <SigSpec> port(ffcemux, AB) === argQ
|
2019-09-06 23:01:36 -05:00
|
|
|
define <bool> pol (AB == \A)
|
2019-09-10 20:59:03 -05:00
|
|
|
set ffcepol pol
|
2019-09-09 17:51:14 -05:00
|
|
|
semioptional
|
2019-09-06 23:01:36 -05:00
|
|
|
endmatch
|
|
|
|
|
2019-09-11 12:15:19 -05:00
|
|
|
code argD
|
2019-09-10 20:52:54 -05:00
|
|
|
if (ffcemux) {
|
|
|
|
dffcemux = ffcemux;
|
2019-09-10 20:59:03 -05:00
|
|
|
dffcepol = ffcepol;
|
2019-09-11 19:16:46 -05:00
|
|
|
argD = port(ffcemux, ffcepol ? \B : \A);
|
2019-09-11 12:15:19 -05:00
|
|
|
dffD.replace(port(ffcemux, \Y), argD);
|
2019-09-09 17:51:14 -05:00
|
|
|
}
|
2019-09-09 17:59:10 -05:00
|
|
|
else
|
2019-09-10 20:52:54 -05:00
|
|
|
dffcemux = nullptr;
|
2019-07-15 16:46:31 -05:00
|
|
|
endcode
|
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;
|
|
|
|
endcode
|
|
|
|
|
2019-09-10 20:59:03 -05:00
|
|
|
match ffcemux
|
|
|
|
select ffcemux->type.in($mux)
|
|
|
|
// ffcemux output must have two users: ffcemux and ff.D
|
|
|
|
select nusers(port(ffcemux, \Y)) == 2
|
2019-09-10 20:27:05 -05:00
|
|
|
|
2019-09-11 09:34:14 -05:00
|
|
|
choice <IdString> AB {\A, \B}
|
2019-09-10 20:59:03 -05:00
|
|
|
// keep-last-value net must have at least three users: ffcemux, ff, downstream sink(s)
|
|
|
|
select nusers(port(ffcemux, AB)) >= 3
|
2019-09-10 20:27:05 -05:00
|
|
|
|
2019-09-10 22:51:48 -05:00
|
|
|
slice offset GetSize(port(ffcemux, \Y))
|
2019-09-11 09:34:14 -05:00
|
|
|
define <IdString> BA (AB == \A ? \B : \A)
|
|
|
|
index <SigBit> port(ffcemux, BA)[offset] === argD[0]
|
|
|
|
set ffoffset offset
|
|
|
|
define <bool> pol (BA == \B)
|
2019-09-10 20:59:03 -05:00
|
|
|
set ffcepol pol
|
2019-09-11 09:34:14 -05:00
|
|
|
|
2019-09-10 20:27:05 -05:00
|
|
|
semioptional
|
|
|
|
endmatch
|
|
|
|
|
2019-09-10 22:51:48 -05:00
|
|
|
code argD argQ
|
2019-09-11 09:34:14 -05:00
|
|
|
dffcemux = ffcemux;
|
2019-09-10 20:59:03 -05:00
|
|
|
if (ffcemux) {
|
2019-09-11 09:34:14 -05:00
|
|
|
SigSpec BA = port(ffcemux, ffcepol ? \B : \A);
|
|
|
|
if (ffoffset + GetSize(argD) > GetSize(BA))
|
|
|
|
reject;
|
|
|
|
for (int i = 1; i < GetSize(argD); i++)
|
|
|
|
if (BA[ffoffset+i] != argD[i])
|
|
|
|
reject;
|
|
|
|
|
|
|
|
SigSpec Y = port(ffcemux, \Y);
|
|
|
|
argQ = argD;
|
|
|
|
argD.replace(BA, Y);
|
|
|
|
argQ.replace(BA, port(ffcemux, ffcepol ? \A : \B));
|
|
|
|
|
2019-09-10 20:59:03 -05:00
|
|
|
dffcemux = ffcemux;
|
|
|
|
dffcepol = ffcepol;
|
2019-09-10 20:27:05 -05:00
|
|
|
}
|
|
|
|
endcode
|
|
|
|
|
2019-09-10 22:51:48 -05:00
|
|
|
match ffrstmux
|
|
|
|
select ffrstmux->type.in($mux)
|
|
|
|
// ffrstmux output must have two users: ffrstmux and ff.D
|
|
|
|
select nusers(port(ffrstmux, \Y)) == 2
|
|
|
|
|
|
|
|
choice <IdString> BA {\B, \A}
|
|
|
|
// DSP48E1 only supports reset to zero
|
|
|
|
select port(ffrstmux, BA).is_fully_zero()
|
|
|
|
|
|
|
|
slice offset GetSize(port(ffrstmux, \Y))
|
2019-09-11 09:34:14 -05:00
|
|
|
define <IdString> AB (BA == \B ? \A : \B)
|
|
|
|
index <SigBit> port(ffrstmux, AB)[offset] === argD[0]
|
2019-09-10 22:51:48 -05:00
|
|
|
|
2019-09-11 09:34:14 -05:00
|
|
|
filter !ffcemux || ffoffset == offset
|
|
|
|
set ffoffset offset
|
2019-09-10 22:51:48 -05:00
|
|
|
define <bool> pol (AB == \A)
|
|
|
|
set ffrstpol pol
|
2019-09-11 09:34:14 -05:00
|
|
|
|
2019-09-10 22:51:48 -05:00
|
|
|
semioptional
|
|
|
|
endmatch
|
|
|
|
|
|
|
|
code argD argQ
|
2019-09-11 09:34:14 -05:00
|
|
|
dffrstmux = ffrstmux;
|
2019-09-10 22:51:48 -05:00
|
|
|
if (ffrstmux) {
|
2019-09-11 09:34:14 -05:00
|
|
|
SigSpec AB = port(ffrstmux, ffcepol ? \A : \B);
|
|
|
|
if (ffoffset + GetSize(argD) > GetSize(AB))
|
|
|
|
reject;
|
|
|
|
|
|
|
|
for (int i = 1; i < GetSize(argD); i++)
|
|
|
|
if (AB[ffoffset+i] != argD[i])
|
|
|
|
reject;
|
|
|
|
|
|
|
|
SigSpec Y = port(ffrstmux, \Y);
|
|
|
|
argD.replace(AB, Y);
|
|
|
|
|
2019-09-10 22:51:48 -05:00
|
|
|
dffrstmux = ffrstmux;
|
|
|
|
dffrstpol = ffrstpol;
|
|
|
|
}
|
|
|
|
endcode
|
|
|
|
|
2019-09-10 20:27:05 -05:00
|
|
|
match ff
|
|
|
|
select ff->type.in($dff)
|
|
|
|
// 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
|
|
|
|
|
|
|
filter (!ffcemux && !ffrstmux) || ffoffset == offset
|
|
|
|
set ffoffset offset
|
|
|
|
|
2019-09-10 20:27:05 -05:00
|
|
|
semioptional
|
|
|
|
endmatch
|
|
|
|
|
2019-09-11 09:34:14 -05:00
|
|
|
code argQ
|
|
|
|
if (ff) {
|
|
|
|
if (clock != SigBit()) {
|
|
|
|
if (port(ff, \CLK) != clock)
|
|
|
|
reject;
|
|
|
|
}
|
2019-09-10 20:27:05 -05:00
|
|
|
|
2019-09-11 09:34:14 -05:00
|
|
|
SigSpec D = port(ff, \D);
|
|
|
|
if (ffoffset + GetSize(argD) > GetSize(D))
|
|
|
|
reject;
|
|
|
|
for (int i = 1; i < GetSize(argD); i++)
|
|
|
|
if (D[ffoffset+i] != argD[i])
|
|
|
|
reject;
|
|
|
|
|
|
|
|
SigSpec Q = port(ff, \Q);
|
|
|
|
if (ffcemux) {
|
|
|
|
for (int i = 0; i < GetSize(argQ); i++)
|
|
|
|
if (Q[ffoffset+i] != argQ[i])
|
|
|
|
reject;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
argQ = argD;
|
|
|
|
argQ.replace(D, Q);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto c : argQ.chunks()) {
|
2019-09-10 23:33:14 -05:00
|
|
|
if (c.wire->get_bool_attribute(\keep))
|
2019-09-10 20:27:05 -05:00
|
|
|
reject;
|
2019-09-10 23:33:14 -05:00
|
|
|
Const init = c.wire->attributes.at(\init, State::Sx);
|
|
|
|
if (!init.is_fully_undef() && !init.is_fully_zero())
|
|
|
|
reject;
|
|
|
|
}
|
2019-09-10 20:27:05 -05:00
|
|
|
|
2019-09-11 09:34:14 -05:00
|
|
|
dff = ff;
|
|
|
|
dffQ = argQ;
|
2019-09-10 20:27:05 -05:00
|
|
|
dffclock = port(dff, \CLK);
|
|
|
|
}
|
2019-09-10 22:51:48 -05:00
|
|
|
// No enable/reset mux possible without flop
|
2019-09-11 09:34:14 -05:00
|
|
|
else if (dffcemux || dffrstmux)
|
2019-09-10 20:27:05 -05:00
|
|
|
reject;
|
|
|
|
endcode
|