2019-04-29 06:02:05 -05:00
|
|
|
pattern ice40_dsp
|
|
|
|
|
2019-01-13 03:57:11 -06:00
|
|
|
state <SigBit> clock
|
2019-07-22 17:08:26 -05:00
|
|
|
state <bool> clock_pol sigO_signed
|
|
|
|
state <SigSpec> sigA sigB sigH sigO
|
2019-01-13 10:03:58 -06:00
|
|
|
state <Cell*> addAB muxAB
|
2019-01-11 07:02:16 -06:00
|
|
|
|
|
|
|
match mul
|
2019-07-18 17:38:28 -05:00
|
|
|
select mul->type.in($mul, $__MUL16X16)
|
2019-01-11 07:02:16 -06:00
|
|
|
select GetSize(mul->getPort(\A)) + GetSize(mul->getPort(\B)) > 10
|
|
|
|
select GetSize(mul->getPort(\Y)) > 10
|
|
|
|
endmatch
|
|
|
|
|
|
|
|
match ffA
|
|
|
|
select ffA->type.in($dff)
|
2019-07-19 12:57:32 -05:00
|
|
|
filter !port(mul, \A).remove_const().empty()
|
|
|
|
filter includes(port(ffA, \Q).to_sigbit_set(), port(mul, \A).remove_const().to_sigbit_set())
|
2019-01-11 07:02:16 -06:00
|
|
|
optional
|
|
|
|
endmatch
|
|
|
|
|
2019-07-19 12:57:32 -05:00
|
|
|
code sigA clock clock_pol
|
2019-01-11 07:02:16 -06:00
|
|
|
sigA = port(mul, \A);
|
|
|
|
|
2019-01-13 10:03:58 -06:00
|
|
|
if (ffA) {
|
2019-01-11 07:02:16 -06:00
|
|
|
clock = port(ffA, \CLK).as_bit();
|
|
|
|
clock_pol = param(ffA, \CLK_POLARITY).as_bool();
|
2019-07-19 22:25:28 -05:00
|
|
|
|
|
|
|
sigA.replace(port(ffA, \Q), port(ffA, \D));
|
2019-01-11 07:02:16 -06:00
|
|
|
}
|
|
|
|
endcode
|
|
|
|
|
|
|
|
match ffB
|
|
|
|
select ffB->type.in($dff)
|
2019-07-19 12:57:32 -05:00
|
|
|
filter !port(mul, \B).remove_const().empty()
|
|
|
|
filter includes(port(ffB, \Q).to_sigbit_set(), port(mul, \B).remove_const().to_sigbit_set())
|
2019-01-11 07:02:16 -06:00
|
|
|
optional
|
|
|
|
endmatch
|
|
|
|
|
2019-07-19 12:57:32 -05:00
|
|
|
code sigB clock clock_pol
|
2019-01-11 07:02:16 -06:00
|
|
|
sigB = port(mul, \B);
|
|
|
|
|
2019-01-13 10:03:58 -06:00
|
|
|
if (ffB) {
|
2019-01-11 07:02:16 -06:00
|
|
|
SigBit c = port(ffB, \CLK).as_bit();
|
|
|
|
bool cp = param(ffB, \CLK_POLARITY).as_bool();
|
|
|
|
|
2019-07-19 12:57:32 -05:00
|
|
|
if (clock != SigBit() && (c != clock || cp != clock_pol))
|
2019-01-11 07:02:16 -06:00
|
|
|
reject;
|
|
|
|
|
|
|
|
clock = c;
|
|
|
|
clock_pol = cp;
|
2019-07-19 22:25:28 -05:00
|
|
|
|
|
|
|
sigB.replace(port(ffB, \Q), port(ffB, \D));
|
2019-01-11 07:02:16 -06:00
|
|
|
}
|
|
|
|
endcode
|
|
|
|
|
2019-07-22 17:08:26 -05:00
|
|
|
match ffH
|
|
|
|
select ffH->type.in($dff)
|
|
|
|
select nusers(port(ffH, \D)) == 2
|
|
|
|
index <SigSpec> port(ffH, \D) === port(mul, \Y)
|
2019-01-11 07:02:16 -06:00
|
|
|
optional
|
|
|
|
endmatch
|
|
|
|
|
2019-07-22 17:08:26 -05:00
|
|
|
code sigH clock clock_pol
|
|
|
|
sigH = port(mul, \Y);
|
2019-07-20 00:47:08 -05:00
|
|
|
|
2019-07-22 17:08:26 -05:00
|
|
|
if (ffH) {
|
|
|
|
sigH = port(ffH, \Q);
|
2019-07-19 12:57:32 -05:00
|
|
|
|
2019-07-22 17:08:26 -05:00
|
|
|
SigBit c = port(ffH, \CLK).as_bit();
|
|
|
|
bool cp = param(ffH, \CLK_POLARITY).as_bool();
|
2019-01-11 07:02:16 -06:00
|
|
|
|
2019-07-19 12:57:32 -05:00
|
|
|
if (clock != SigBit() && (c != clock || cp != clock_pol))
|
2019-01-11 07:02:16 -06:00
|
|
|
reject;
|
|
|
|
|
|
|
|
clock = c;
|
|
|
|
clock_pol = cp;
|
|
|
|
}
|
|
|
|
endcode
|
2019-01-13 10:03:58 -06:00
|
|
|
|
|
|
|
match addA
|
2019-02-17 08:35:48 -06:00
|
|
|
select addA->type.in($add)
|
2019-01-13 10:03:58 -06:00
|
|
|
select nusers(port(addA, \A)) == 2
|
2019-07-22 17:08:26 -05:00
|
|
|
index <SigSpec> port(addA, \A) === sigH
|
2019-01-13 10:03:58 -06:00
|
|
|
optional
|
|
|
|
endmatch
|
|
|
|
|
|
|
|
match addB
|
|
|
|
if !addA
|
|
|
|
select addB->type.in($add, $sub)
|
|
|
|
select nusers(port(addB, \B)) == 2
|
2019-07-22 17:08:26 -05:00
|
|
|
index <SigSpec> port(addB, \B) === sigH
|
2019-01-13 10:03:58 -06:00
|
|
|
optional
|
|
|
|
endmatch
|
|
|
|
|
2019-07-22 17:08:26 -05:00
|
|
|
code addAB sigO sigO_signed
|
2019-01-13 10:03:58 -06:00
|
|
|
if (addA) {
|
|
|
|
addAB = addA;
|
2019-07-22 17:08:26 -05:00
|
|
|
sigO = port(addAB, \B);
|
|
|
|
sigO_signed = param(addAB, \B_SIGNED).as_bool();
|
2019-01-13 10:03:58 -06:00
|
|
|
}
|
|
|
|
if (addB) {
|
|
|
|
addAB = addB;
|
2019-07-22 17:08:26 -05:00
|
|
|
sigO = port(addAB, \A);
|
|
|
|
sigO_signed = param(addAB, \A_SIGNED).as_bool();
|
2019-01-13 10:03:58 -06:00
|
|
|
}
|
2019-02-20 04:18:19 -06:00
|
|
|
if (addAB) {
|
|
|
|
int natural_mul_width = GetSize(sigA) + GetSize(sigB);
|
2019-07-22 17:08:26 -05:00
|
|
|
int actual_mul_width = GetSize(sigH);
|
|
|
|
int actual_acc_width = GetSize(sigO);
|
2019-02-20 04:18:19 -06:00
|
|
|
|
|
|
|
if ((actual_acc_width > actual_mul_width) && (natural_mul_width > actual_mul_width))
|
|
|
|
reject;
|
|
|
|
if ((actual_acc_width != actual_mul_width) && (param(mul, \A_SIGNED).as_bool() != param(addAB, \A_SIGNED).as_bool()))
|
|
|
|
reject;
|
|
|
|
}
|
2019-01-13 10:03:58 -06:00
|
|
|
endcode
|
|
|
|
|
|
|
|
match muxA
|
|
|
|
if addAB
|
|
|
|
select muxA->type.in($mux)
|
|
|
|
select nusers(port(muxA, \A)) == 2
|
|
|
|
index <SigSpec> port(muxA, \A) === port(addAB, \Y)
|
|
|
|
optional
|
|
|
|
endmatch
|
|
|
|
|
|
|
|
match muxB
|
|
|
|
if addAB
|
|
|
|
if !muxA
|
|
|
|
select muxB->type.in($mux)
|
|
|
|
select nusers(port(muxB, \B)) == 2
|
|
|
|
index <SigSpec> port(muxB, \B) === port(addAB, \Y)
|
|
|
|
optional
|
|
|
|
endmatch
|
|
|
|
|
|
|
|
code muxAB
|
|
|
|
muxAB = addAB;
|
|
|
|
if (muxA)
|
|
|
|
muxAB = muxA;
|
|
|
|
if (muxB)
|
|
|
|
muxAB = muxB;
|
|
|
|
endcode
|
|
|
|
|
2019-07-22 17:08:26 -05:00
|
|
|
match ffO
|
2019-01-13 10:03:58 -06:00
|
|
|
if muxAB
|
2019-07-22 17:08:26 -05:00
|
|
|
select ffO->type.in($dff)
|
2019-07-22 17:05:16 -05:00
|
|
|
filter nusers(port(muxAB, \Y)) == 2
|
2019-07-22 17:08:26 -05:00
|
|
|
filter includes(port(ffO, \D).to_sigbit_set(), port(muxAB, \Y).to_sigbit_set())
|
2019-07-22 15:01:49 -05:00
|
|
|
optional
|
2019-01-13 10:03:58 -06:00
|
|
|
endmatch
|
2019-02-17 08:35:48 -06:00
|
|
|
|
2019-07-22 17:08:26 -05:00
|
|
|
code clock clock_pol sigO
|
|
|
|
if (ffO) {
|
|
|
|
SigBit c = port(ffO, \CLK).as_bit();
|
|
|
|
bool cp = param(ffO, \CLK_POLARITY).as_bool();
|
2019-02-17 08:35:48 -06:00
|
|
|
|
2019-07-22 17:08:26 -05:00
|
|
|
if (port(ffO, \Q) != sigO) {
|
|
|
|
sigO = port(muxAB, \Y);
|
|
|
|
sigO.replace(port(ffO, \D), port(ffO, \Q));
|
2019-07-22 17:05:16 -05:00
|
|
|
}
|
|
|
|
|
2019-07-19 12:57:32 -05:00
|
|
|
if (clock != SigBit() && (c != clock || cp != clock_pol))
|
2019-02-17 08:35:48 -06:00
|
|
|
reject;
|
|
|
|
|
|
|
|
clock = c;
|
|
|
|
clock_pol = cp;
|
|
|
|
}
|
|
|
|
endcode
|