2019-04-29 06:02:05 -05:00
|
|
|
pattern ice40_dsp
|
|
|
|
|
2019-01-13 03:57:11 -06:00
|
|
|
state <SigBit> clock
|
|
|
|
state <bool> clock_pol clock_vld
|
2019-01-13 10:03:58 -06:00
|
|
|
state <SigSpec> sigA sigB sigY sigS
|
|
|
|
state <Cell*> addAB muxAB
|
2019-01-11 07:02:16 -06:00
|
|
|
|
|
|
|
match mul
|
|
|
|
select mul->type.in($mul)
|
|
|
|
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-01-13 05:53:13 -06:00
|
|
|
// select nusers(port(ffA, \Q)) == 2
|
2019-01-13 10:03:58 -06:00
|
|
|
index <SigSpec> port(ffA, \Q) === port(mul, \A)
|
2019-01-11 07:02:16 -06:00
|
|
|
optional
|
|
|
|
endmatch
|
|
|
|
|
|
|
|
code sigA clock clock_pol clock_vld
|
|
|
|
sigA = port(mul, \A);
|
|
|
|
|
2019-01-13 10:03:58 -06:00
|
|
|
if (ffA) {
|
2019-01-11 07:02:16 -06:00
|
|
|
sigA = port(ffA, \D);
|
|
|
|
|
|
|
|
clock = port(ffA, \CLK).as_bit();
|
|
|
|
clock_pol = param(ffA, \CLK_POLARITY).as_bool();
|
|
|
|
clock_vld = true;
|
|
|
|
}
|
|
|
|
endcode
|
|
|
|
|
|
|
|
match ffB
|
|
|
|
select ffB->type.in($dff)
|
2019-01-13 05:53:13 -06:00
|
|
|
// select nusers(port(ffB, \Q)) == 2
|
2019-01-13 10:03:58 -06:00
|
|
|
index <SigSpec> port(ffB, \Q) === port(mul, \B)
|
2019-01-11 07:02:16 -06:00
|
|
|
optional
|
|
|
|
endmatch
|
|
|
|
|
2019-01-13 03:57:11 -06:00
|
|
|
code sigB clock clock_pol clock_vld
|
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
|
|
|
sigB = port(ffB, \D);
|
|
|
|
SigBit c = port(ffB, \CLK).as_bit();
|
|
|
|
bool cp = param(ffB, \CLK_POLARITY).as_bool();
|
|
|
|
|
|
|
|
if (clock_vld && (c != clock || cp != clock_pol))
|
|
|
|
reject;
|
|
|
|
|
|
|
|
clock = c;
|
|
|
|
clock_pol = cp;
|
|
|
|
clock_vld = true;
|
|
|
|
}
|
|
|
|
endcode
|
|
|
|
|
|
|
|
match ffY
|
|
|
|
select ffY->type.in($dff)
|
2019-01-13 03:57:11 -06:00
|
|
|
select nusers(port(ffY, \D)) == 2
|
2019-01-13 10:03:58 -06:00
|
|
|
index <SigSpec> port(ffY, \D) === port(mul, \Y)
|
2019-01-11 07:02:16 -06:00
|
|
|
optional
|
|
|
|
endmatch
|
|
|
|
|
2019-01-13 03:57:11 -06:00
|
|
|
code sigY clock clock_pol clock_vld
|
2019-01-11 07:02:16 -06:00
|
|
|
sigY = port(mul, \Y);
|
|
|
|
|
2019-01-13 10:03:58 -06:00
|
|
|
if (ffY) {
|
2019-02-17 08:35:48 -06:00
|
|
|
sigY = port(ffY, \Q);
|
2019-01-11 07:02:16 -06:00
|
|
|
SigBit c = port(ffY, \CLK).as_bit();
|
|
|
|
bool cp = param(ffY, \CLK_POLARITY).as_bool();
|
|
|
|
|
|
|
|
if (clock_vld && (c != clock || cp != clock_pol))
|
|
|
|
reject;
|
|
|
|
|
|
|
|
clock = c;
|
|
|
|
clock_pol = cp;
|
|
|
|
clock_vld = true;
|
|
|
|
}
|
|
|
|
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
|
|
|
|
index <SigSpec> port(addA, \A) === sigY
|
|
|
|
optional
|
|
|
|
endmatch
|
|
|
|
|
|
|
|
match addB
|
|
|
|
if !addA
|
|
|
|
select addB->type.in($add, $sub)
|
|
|
|
select nusers(port(addB, \B)) == 2
|
|
|
|
index <SigSpec> port(addB, \B) === sigY
|
|
|
|
optional
|
|
|
|
endmatch
|
|
|
|
|
|
|
|
code addAB sigS
|
|
|
|
if (addA) {
|
|
|
|
addAB = addA;
|
|
|
|
sigS = port(addA, \B);
|
|
|
|
}
|
|
|
|
if (addB) {
|
|
|
|
addAB = addB;
|
|
|
|
sigS = port(addB, \A);
|
|
|
|
}
|
2019-02-20 04:18:19 -06:00
|
|
|
if (addAB) {
|
|
|
|
int natural_mul_width = GetSize(sigA) + GetSize(sigB);
|
|
|
|
int actual_mul_width = GetSize(sigY);
|
|
|
|
int actual_acc_width = GetSize(sigS);
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
match ffS
|
|
|
|
if muxAB
|
|
|
|
select ffS->type.in($dff)
|
|
|
|
select nusers(port(ffS, \D)) == 2
|
|
|
|
index <SigSpec> port(ffS, \D) === port(muxAB, \Y)
|
|
|
|
index <SigSpec> port(ffS, \Q) === sigS
|
|
|
|
endmatch
|
2019-02-17 08:35:48 -06:00
|
|
|
|
|
|
|
code clock clock_pol clock_vld
|
|
|
|
if (ffS) {
|
|
|
|
SigBit c = port(ffS, \CLK).as_bit();
|
|
|
|
bool cp = param(ffS, \CLK_POLARITY).as_bool();
|
|
|
|
|
|
|
|
if (clock_vld && (c != clock || cp != clock_pol))
|
|
|
|
reject;
|
|
|
|
|
|
|
|
clock = c;
|
|
|
|
clock_pol = cp;
|
|
|
|
clock_vld = true;
|
|
|
|
}
|
2019-08-15 15:47:59 -05:00
|
|
|
accept;
|
2019-02-17 08:35:48 -06:00
|
|
|
endcode
|