yosys/passes/pmgen/ice40_dsp.pmg

200 lines
4.3 KiB
Plaintext
Raw Normal View History

pattern ice40_dsp
state <SigBit> clock
2019-07-23 15:58:56 -05:00
state <bool> clock_pol sigCD_signed
state <SigSpec> sigA sigB sigCD sigH sigO
state <Cell*> addAB muxAB
match mul
2019-07-18 17:38:28 -05:00
select mul->type.in($mul, $__MUL16X16)
select GetSize(mul->getPort(\A)) + GetSize(mul->getPort(\B)) > 10
select GetSize(mul->getPort(\Y)) > 10
endmatch
match ffA
select ffA->type.in($dff)
filter !port(mul, \A).remove_const().empty()
filter includes(port(ffA, \Q).to_sigbit_set(), port(mul, \A).remove_const().to_sigbit_set())
optional
endmatch
code sigA clock clock_pol
sigA = port(mul, \A);
if (ffA) {
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));
}
endcode
match ffB
select ffB->type.in($dff)
filter !port(mul, \B).remove_const().empty()
filter includes(port(ffB, \Q).to_sigbit_set(), port(mul, \B).remove_const().to_sigbit_set())
optional
endmatch
code sigB clock clock_pol
sigB = port(mul, \B);
if (ffB) {
SigBit c = port(ffB, \CLK).as_bit();
bool cp = param(ffB, \CLK_POLARITY).as_bool();
if (clock != SigBit() && (c != clock || cp != clock_pol))
reject;
clock = c;
clock_pol = cp;
2019-07-19 22:25:28 -05:00
sigB.replace(port(ffB, \Q), port(ffB, \D));
}
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)
optional
endmatch
2019-07-22 18:12:57 -05:00
code sigH sigO clock clock_pol
2019-07-22 17:08:26 -05:00
sigH = port(mul, \Y);
2019-07-22 18:12:57 -05:00
sigO = sigH;
2019-07-20 00:47:08 -05:00
2019-07-22 17:08:26 -05:00
if (ffH) {
sigH = port(ffH, \Q);
2019-07-22 18:12:57 -05:00
sigO = sigH;
2019-07-22 17:08:26 -05:00
SigBit c = port(ffH, \CLK).as_bit();
bool cp = param(ffH, \CLK_POLARITY).as_bool();
if (clock != SigBit() && (c != clock || cp != clock_pol))
reject;
clock = c;
clock_pol = cp;
}
endcode
match addA
select addA->type.in($add)
select nusers(port(addA, \A)) == 2
2019-07-22 17:08:26 -05:00
index <SigSpec> port(addA, \A) === sigH
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
optional
endmatch
2019-07-23 15:58:56 -05:00
code addAB sigCD sigCD_signed sigO
if (addA) {
addAB = addA;
2019-07-23 15:58:56 -05:00
sigCD = port(addAB, \B);
sigCD_signed = param(addAB, \B_SIGNED).as_bool();
}
if (addB) {
addAB = addB;
2019-07-23 15:58:56 -05:00
sigCD = port(addAB, \A);
sigCD_signed = param(addAB, \A_SIGNED).as_bool();
}
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);
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-07-22 18:12:57 -05:00
sigO = port(addAB, \Y);
}
endcode
match muxA
2019-07-23 15:58:56 -05:00
if sigCD.empty()
select muxA->type.in($mux)
select nusers(port(muxA, \A)) == 2
2019-07-23 15:58:56 -05:00
index <SigSpec> port(muxA, \A) === sigO
optional
endmatch
match muxB
2019-07-23 15:58:56 -05:00
if sigCD.empty()
if !muxA
select muxB->type.in($mux)
select nusers(port(muxB, \B)) == 2
2019-07-23 15:58:56 -05:00
index <SigSpec> port(muxB, \B) === sigO
optional
endmatch
2019-07-23 15:58:56 -05:00
code muxAB sigCD sigCD_signed sigO
muxAB = addAB;
2019-07-23 15:58:56 -05:00
if (muxA) {
muxAB = muxA;
2019-07-23 15:58:56 -05:00
sigCD = port(muxAB, \B);
}
if (muxB) {
muxAB = muxB;
2019-07-23 15:58:56 -05:00
sigCD = port(muxAB, \A);
}
if (muxA || muxB) {
2019-07-22 18:12:57 -05:00
sigO = port(muxAB, \Y);
2019-07-23 15:58:56 -05:00
sigCD_signed = addAB && param(addAB, \A_SIGNED).as_bool() && param(addAB, \B_SIGNED).as_bool();
}
endcode
2019-07-22 18:12:57 -05:00
match ffO_lo
select ffO_lo->type.in($dff)
filter nusers(sigO.extract(0,16)) == 2
filter includes(port(ffO_lo, \D).to_sigbit_set(), sigO.extract(0,16).to_sigbit_set())
optional
endmatch
match ffO_hi
select ffO_hi->type.in($dff)
filter nusers(sigO.extract(16,16)) == 2
filter includes(port(ffO_hi, \D).to_sigbit_set(), sigO.extract(16,16).to_sigbit_set())
2019-07-22 15:01:49 -05:00
optional
endmatch
2019-07-22 17:08:26 -05:00
code clock clock_pol sigO
2019-07-22 18:12:57 -05:00
if (ffO_lo || ffO_hi) {
if (ffO_lo) {
SigBit c = port(ffO_lo, \CLK).as_bit();
bool cp = param(ffO_lo, \CLK_POLARITY).as_bool();
2019-07-22 18:12:57 -05:00
if (clock != SigBit() && (c != clock || cp != clock_pol))
reject;
clock = c;
clock_pol = cp;
if (port(ffO_lo, \Q) != sigO.extract(0,16))
sigO.replace(port(ffO_lo, \D), port(ffO_lo, \Q));
2019-07-22 17:05:16 -05:00
}
2019-07-22 18:12:57 -05:00
if (ffO_hi) {
SigBit c = port(ffO_hi, \CLK).as_bit();
bool cp = param(ffO_hi, \CLK_POLARITY).as_bool();
2019-07-22 18:12:57 -05:00
if (clock != SigBit() && (c != clock || cp != clock_pol))
reject;
clock = c;
clock_pol = cp;
if (port(ffO_hi, \Q) != sigO.extract(16,16))
sigO.replace(port(ffO_hi, \D), port(ffO_hi, \Q));
}
}
endcode