2019-07-15 16:46:31 -05:00
|
|
|
pattern xilinx_dsp
|
|
|
|
|
|
|
|
state <SigBit> clock
|
2019-08-13 19:11:35 -05:00
|
|
|
state <std::set<SigBit>> sigAset sigBset
|
2019-09-04 12:52:51 -05:00
|
|
|
state <SigSpec> sigC sigM sigP sigPused
|
|
|
|
state <IdString> ffMmuxAB postAddAB postAddMuxAB
|
2019-07-15 16:46:31 -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-08-13 19:11:35 -05:00
|
|
|
code sigAset sigBset
|
|
|
|
SigSpec A = port(dsp, \A);
|
|
|
|
A.remove_const();
|
|
|
|
sigAset = A.to_sigbit_set();
|
|
|
|
SigSpec B = port(dsp, \B);
|
|
|
|
B.remove_const();
|
|
|
|
sigBset = B.to_sigbit_set();
|
|
|
|
endcode
|
|
|
|
|
2019-08-30 17:00:56 -05:00
|
|
|
code sigM
|
|
|
|
sigM = port(dsp, \P);
|
|
|
|
//if (GetSize(sigH) <= 10)
|
|
|
|
// reject;
|
|
|
|
endcode
|
|
|
|
|
2019-07-15 16:46:31 -05:00
|
|
|
match ffA
|
2019-08-09 17:47:40 -05:00
|
|
|
if param(dsp, \AREG).as_int() == 0
|
2019-08-13 19:11:35 -05:00
|
|
|
if !sigAset.empty()
|
2019-08-08 12:51:19 -05:00
|
|
|
select ffA->type.in($dff)
|
2019-07-15 16:46:31 -05:00
|
|
|
// DSP48E1 does not support clock inversion
|
2019-07-18 15:30:35 -05:00
|
|
|
select param(ffA, \CLK_POLARITY).as_bool()
|
2019-08-13 19:11:35 -05:00
|
|
|
filter includes(port(ffA, \Q).to_sigbit_set(), sigAset)
|
2019-07-15 16:46:31 -05:00
|
|
|
optional
|
|
|
|
endmatch
|
|
|
|
|
2019-07-16 16:06:32 -05:00
|
|
|
code clock
|
2019-08-15 14:34:11 -05:00
|
|
|
if (ffA) {
|
2019-07-15 16:46:31 -05:00
|
|
|
clock = port(ffA, \CLK).as_bit();
|
2019-08-15 14:34:11 -05:00
|
|
|
|
|
|
|
for (auto b : port(ffA, \Q))
|
|
|
|
if (b.wire->get_bool_attribute(\keep))
|
|
|
|
reject;
|
|
|
|
}
|
2019-07-15 16:46:31 -05:00
|
|
|
endcode
|
|
|
|
|
|
|
|
match ffB
|
2019-08-09 17:47:40 -05:00
|
|
|
if param(dsp, \BREG).as_int() == 0
|
2019-08-13 19:11:35 -05:00
|
|
|
if !sigBset.empty()
|
2019-08-08 12:51:19 -05:00
|
|
|
select ffB->type.in($dff)
|
2019-07-18 15:30:35 -05:00
|
|
|
// DSP48E1 does not support clock inversion
|
2019-07-16 17:54:07 -05:00
|
|
|
select param(ffB, \CLK_POLARITY).as_bool()
|
2019-08-13 19:11:35 -05:00
|
|
|
filter includes(port(ffB, \Q).to_sigbit_set(), sigBset)
|
2019-07-15 16:46:31 -05:00
|
|
|
optional
|
|
|
|
endmatch
|
|
|
|
|
2019-07-16 16:06:32 -05:00
|
|
|
code clock
|
2019-07-15 16:46:31 -05:00
|
|
|
if (ffB) {
|
2019-08-15 14:34:11 -05:00
|
|
|
for (auto b : port(ffB, \Q))
|
|
|
|
if (b.wire->get_bool_attribute(\keep))
|
|
|
|
reject;
|
|
|
|
|
2019-07-15 16:46:31 -05:00
|
|
|
SigBit c = port(ffB, \CLK).as_bit();
|
|
|
|
|
|
|
|
if (clock != SigBit() && c != clock)
|
|
|
|
reject;
|
|
|
|
|
|
|
|
clock = c;
|
|
|
|
}
|
|
|
|
endcode
|
|
|
|
|
2019-09-04 12:52:51 -05:00
|
|
|
match ffMmux
|
|
|
|
select ffMmux->type.in($mux)
|
|
|
|
select nusers(port(ffMmux, \Y)) == 2
|
|
|
|
filter GetSize(port(ffMmux, \Y)) <= GetSize(sigM)
|
|
|
|
choice <IdString> AB {\A, \B}
|
|
|
|
filter port(ffMmux, AB) == sigM.extract(0, GetSize(port(ffMmux, \Y)))
|
|
|
|
filter nusers(sigM.extract_end(GetSize(port(ffMmux, AB)))) <= 1
|
|
|
|
set ffMmuxAB AB
|
|
|
|
optional
|
|
|
|
endmatch
|
|
|
|
|
|
|
|
code sigM
|
|
|
|
if (ffMmux)
|
|
|
|
sigM = port(ffMmux, \Y);
|
|
|
|
endcode
|
|
|
|
|
2019-08-30 17:00:56 -05:00
|
|
|
match ffM
|
|
|
|
if param(dsp, \MREG).as_int() == 0
|
|
|
|
select ffM->type.in($dff)
|
|
|
|
// DSP48E1 does not support clock inversion
|
|
|
|
select param(ffM, \CLK_POLARITY).as_bool()
|
|
|
|
select nusers(port(ffM, \D)) == 2
|
2019-08-30 18:18:58 -05:00
|
|
|
filter GetSize(port(ffM, \D)) <= GetSize(sigM)
|
2019-08-30 17:00:56 -05:00
|
|
|
filter port(ffM, \D) == sigM.extract(0, GetSize(port(ffM, \D)))
|
2019-08-30 18:18:58 -05:00
|
|
|
filter nusers(sigM.extract_end(GetSize(port(ffM, \D)))) <= 1
|
2019-09-04 12:52:51 -05:00
|
|
|
// Check ffMmux (when present) is a $dff enable mux
|
|
|
|
filter !ffMmux || port(ffM, \Q) == port(ffMmux, ffMmuxAB == \A ? \B : \A)
|
2019-08-30 17:00:56 -05:00
|
|
|
optional
|
|
|
|
endmatch
|
|
|
|
|
|
|
|
code clock sigM sigP
|
|
|
|
if (ffM) {
|
|
|
|
sigM = port(ffM, \Q);
|
2019-09-04 12:52:51 -05:00
|
|
|
|
2019-08-30 17:00:56 -05:00
|
|
|
for (auto b : sigM)
|
|
|
|
if (b.wire->get_bool_attribute(\keep))
|
|
|
|
reject;
|
|
|
|
|
2019-08-30 18:18:58 -05:00
|
|
|
SigBit c = port(ffM, \CLK).as_bit();
|
2019-08-30 17:00:56 -05:00
|
|
|
|
|
|
|
if (clock != SigBit() && c != clock)
|
|
|
|
reject;
|
|
|
|
|
|
|
|
clock = c;
|
|
|
|
}
|
2019-09-04 12:52:51 -05:00
|
|
|
// Cannot have ffMmux enable mux without ffM
|
|
|
|
else if (ffMmux)
|
|
|
|
reject;
|
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-03 18:10:16 -05:00
|
|
|
select param(postAdd, \A_SIGNED).as_bool() && param(postAdd, \B_SIGNED).as_bool()
|
|
|
|
choice <IdString> AB {\A, \B}
|
2019-09-04 12:52:51 -05:00
|
|
|
select nusers(port(postAdd, AB)) <= 3
|
|
|
|
filter ffMmux || nusers(port(postAdd, AB)) == 2
|
|
|
|
filter !ffMmux || nusers(port(postAdd, AB)) == 3
|
2019-09-03 18:10:16 -05:00
|
|
|
filter GetSize(port(postAdd, AB)) <= GetSize(sigP)
|
|
|
|
filter port(postAdd, AB) == sigP.extract(0, GetSize(port(postAdd, AB)))
|
|
|
|
filter nusers(sigP.extract_end(GetSize(port(postAdd, AB)))) <= 1
|
|
|
|
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-07-18 16:08:18 -05:00
|
|
|
// Extract the bits of P that actually have a consumer
|
2019-08-08 14:56:05 -05:00
|
|
|
// (as opposed to being a dummy)
|
2019-07-19 12:57:32 -05:00
|
|
|
code sigPused
|
2019-08-09 17:19:33 -05:00
|
|
|
for (int i = 0; i < GetSize(sigP); i++)
|
|
|
|
if (sigP[i].wire && nusers(sigP[i]) > 1)
|
|
|
|
sigPused.append(sigP[i]);
|
2019-07-16 16:06:32 -05:00
|
|
|
endcode
|
|
|
|
|
|
|
|
match ffP
|
2019-08-09 17:47:40 -05:00
|
|
|
if param(dsp, \PREG).as_int() == 0
|
2019-07-19 12:57:32 -05:00
|
|
|
if !sigPused.empty()
|
2019-08-09 19:35:13 -05:00
|
|
|
if nusers(sigPused) == 2
|
2019-08-08 12:51:19 -05:00
|
|
|
select ffP->type.in($dff)
|
2019-07-18 15:30:35 -05:00
|
|
|
// DSP48E1 does not support clock inversion
|
|
|
|
select param(ffP, \CLK_POLARITY).as_bool()
|
2019-07-19 12:57:32 -05:00
|
|
|
filter param(ffP, \WIDTH).as_int() >= GetSize(sigPused)
|
|
|
|
filter includes(port(ffP, \D).to_sigbit_set(), sigPused.to_sigbit_set())
|
2019-07-16 16:06:32 -05:00
|
|
|
optional
|
|
|
|
endmatch
|
|
|
|
|
2019-09-03 17:53:10 -05:00
|
|
|
code ffP sigP clock
|
2019-07-16 16:06:32 -05:00
|
|
|
if (ffP) {
|
2019-08-15 14:34:11 -05:00
|
|
|
for (auto b : port(ffP, \Q))
|
|
|
|
if (b.wire->get_bool_attribute(\keep))
|
|
|
|
reject;
|
|
|
|
|
2019-07-16 16:06:32 -05:00
|
|
|
SigBit c = port(ffP, \CLK).as_bit();
|
2019-07-15 16:46:31 -05:00
|
|
|
|
|
|
|
if (clock != SigBit() && c != clock)
|
|
|
|
reject;
|
|
|
|
|
|
|
|
clock = c;
|
2019-09-03 17:53:10 -05:00
|
|
|
|
|
|
|
sigP = port(ffP, \Q);
|
|
|
|
}
|
|
|
|
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-03 17:53:10 -05:00
|
|
|
code
|
2019-08-30 13:02:10 -05:00
|
|
|
accept;
|
2019-07-15 16:46:31 -05:00
|
|
|
endcode
|