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-08-09 17:19:33 -05:00
|
|
|
state <SigSpec> sigC sigP sigPused
|
|
|
|
state <Cell*> addAB
|
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-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-08-09 17:19:33 -05:00
|
|
|
code sigP
|
|
|
|
sigP = port(dsp, \P);
|
|
|
|
endcode
|
|
|
|
|
|
|
|
match addA
|
|
|
|
select addA->type.in($add)
|
|
|
|
select param(addA, \A_SIGNED).as_bool() && param(addA, \B_SIGNED).as_bool()
|
2019-08-09 17:47:40 -05:00
|
|
|
index <int> nusers(port(addA, \A)) === 2
|
2019-08-09 17:19:33 -05:00
|
|
|
//index <SigSpec> port(addA, \A) === sigP.extract(0, param(addA, \A_WIDTH).as_int())
|
2019-08-09 17:47:40 -05:00
|
|
|
filter param(addA, \A_WIDTH).as_int() <= GetSize(sigP)
|
2019-08-09 17:19:33 -05:00
|
|
|
filter port(addA, \A) == sigP.extract(0, param(addA, \A_WIDTH).as_int())
|
|
|
|
optional
|
|
|
|
endmatch
|
|
|
|
|
|
|
|
match addB
|
|
|
|
if !addA
|
|
|
|
select addB->type.in($add, $sub)
|
|
|
|
select param(addB, \A_SIGNED).as_bool() && param(addB, \B_SIGNED).as_bool()
|
2019-08-09 17:47:40 -05:00
|
|
|
index <int> nusers(port(addB, \B)) === 2
|
2019-08-09 17:19:33 -05:00
|
|
|
//index <SigSpec> port(addB, \B) === sigP.extract(0, param(addB, \B_WIDTH).as_int())
|
2019-08-09 17:47:40 -05:00
|
|
|
filter param(addB, \B_WIDTH).as_int() <= GetSize(sigP)
|
2019-08-13 19:11:35 -05:00
|
|
|
filter port(addB, \B) == sigP.extract(0, param(addB, \B_WIDTH).as_int())
|
2019-08-09 17:19:33 -05:00
|
|
|
optional
|
|
|
|
endmatch
|
|
|
|
|
|
|
|
code addAB sigC sigP
|
|
|
|
if (addA) {
|
|
|
|
addAB = addA;
|
|
|
|
sigC = port(addAB, \B);
|
|
|
|
}
|
|
|
|
if (addB) {
|
|
|
|
addAB = addB;
|
|
|
|
sigC = port(addAB, \A);
|
|
|
|
}
|
|
|
|
if (addAB) {
|
|
|
|
// Ensure that adder is not used
|
|
|
|
SigSpec opmodeZ = port(dsp, \OPMODE).extract(4,3);
|
|
|
|
if (!opmodeZ.is_fully_zero())
|
|
|
|
reject;
|
|
|
|
|
|
|
|
int natural_mul_width = GetSize(port(dsp, \A)) + GetSize(port(dsp, \B));
|
|
|
|
int actual_mul_width = GetSize(sigP);
|
|
|
|
int actual_acc_width = GetSize(sigC);
|
|
|
|
|
|
|
|
if ((actual_acc_width > actual_mul_width) && (natural_mul_width > actual_mul_width))
|
|
|
|
reject;
|
|
|
|
//if ((actual_acc_width != actual_mul_width) && (param(dsp, \A_SIGNED).as_bool() != param(addAB, \A_SIGNED).as_bool()))
|
|
|
|
// reject;
|
|
|
|
|
|
|
|
sigP = port(addAB, \Y);
|
|
|
|
}
|
|
|
|
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-08-08 18:33:37 -05:00
|
|
|
//// $mux cell left behind by dff2dffe
|
|
|
|
//// would prefer not to run 'opt_expr -mux_undef'
|
|
|
|
//// since that would lose information helpful for
|
|
|
|
//// efficient wide-mux inference
|
|
|
|
//match muxP
|
|
|
|
// if !sigPused.empty() && !ffP
|
|
|
|
// select muxP->type.in($mux)
|
|
|
|
// select nusers(port(muxP, \B)) == 2
|
|
|
|
// select port(muxP, \A).is_fully_undef()
|
|
|
|
// filter param(muxP, \WIDTH).as_int() >= GetSize(sigPused)
|
|
|
|
// filter includes(port(muxP, \B).to_sigbit_set(), sigPused.to_sigbit_set())
|
|
|
|
// optional
|
|
|
|
//endmatch
|
|
|
|
//
|
|
|
|
//match ffY
|
|
|
|
// if muxP
|
|
|
|
// select ffY->type.in($dff, $dffe)
|
|
|
|
// select nusers(port(ffY, \D)) == 2
|
|
|
|
// // DSP48E1 does not support clock inversion
|
|
|
|
// select param(ffY, \CLK_POLARITY).as_bool()
|
|
|
|
// filter param(ffY, \WIDTH).as_int() >= GetSize(sigPused)
|
|
|
|
// filter includes(port(ffY, \D).to_sigbit_set(), port(muxP, \Y).to_sigbit_set())
|
|
|
|
//endmatch
|
2019-07-15 16:46:31 -05:00
|
|
|
|
2019-07-16 16:06:32 -05:00
|
|
|
code ffP clock
|
2019-08-08 18:33:37 -05:00
|
|
|
// if (ffY)
|
|
|
|
// ffP = ffY;
|
2019-07-15 16:46:31 -05:00
|
|
|
|
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-08-30 13:02:10 -05:00
|
|
|
|
|
|
|
accept;
|
2019-07-15 16:46:31 -05:00
|
|
|
endcode
|