mirror of
https://github.com/YosysHQ/yosys
synced 2025-06-20 04:43:40 +00:00
Refactor ice40_dsp
This commit is contained in:
parent
888ae1d05e
commit
5a2fc6fcb5
2 changed files with 29 additions and 27 deletions
|
@ -74,9 +74,11 @@ void create_ice40_dsp(ice40_dsp_pm &pm)
|
||||||
|
|
||||||
// SB_MAC16 Input Interface
|
// SB_MAC16 Input Interface
|
||||||
SigSpec A = st.sigA;
|
SigSpec A = st.sigA;
|
||||||
|
A.extend_u0(16, st.mul->getParam("\\A_SIGNED").as_bool());
|
||||||
log_assert(GetSize(A) == 16);
|
log_assert(GetSize(A) == 16);
|
||||||
|
|
||||||
SigSpec B = st.sigB;
|
SigSpec B = st.sigB;
|
||||||
|
B.extend_u0(16, st.mul->getParam("\\B_SIGNED").as_bool());
|
||||||
log_assert(GetSize(B) == 16);
|
log_assert(GetSize(B) == 16);
|
||||||
|
|
||||||
SigSpec CD = st.sigCD;
|
SigSpec CD = st.sigCD;
|
||||||
|
|
|
@ -2,8 +2,7 @@ pattern ice40_dsp
|
||||||
|
|
||||||
state <SigBit> clock
|
state <SigBit> clock
|
||||||
state <bool> clock_pol cd_signed
|
state <bool> clock_pol cd_signed
|
||||||
state <std::set<SigBit>> sigAset sigBset
|
state <SigSpec> sigA sigB sigCD sigH sigO
|
||||||
state <SigSpec> sigA sigB sigCD sigH sigO sigOused
|
|
||||||
state <Cell*> addAB muxAB
|
state <Cell*> addAB muxAB
|
||||||
|
|
||||||
match mul
|
match mul
|
||||||
|
@ -11,16 +10,7 @@ match mul
|
||||||
select GetSize(mul->getPort(\A)) + GetSize(mul->getPort(\B)) > 10
|
select GetSize(mul->getPort(\A)) + GetSize(mul->getPort(\B)) > 10
|
||||||
endmatch
|
endmatch
|
||||||
|
|
||||||
code sigAset sigBset
|
code sigA sigB sigH
|
||||||
SigSpec A = port(mul, \A);
|
|
||||||
A.remove_const();
|
|
||||||
sigAset = A.to_sigbit_set();
|
|
||||||
SigSpec B = port(mul, \B);
|
|
||||||
B.remove_const();
|
|
||||||
sigBset = B.to_sigbit_set();
|
|
||||||
endcode
|
|
||||||
|
|
||||||
code sigH
|
|
||||||
SigSpec O;
|
SigSpec O;
|
||||||
if (mul->type == $mul)
|
if (mul->type == $mul)
|
||||||
O = mul->getPort(\Y);
|
O = mul->getPort(\Y);
|
||||||
|
@ -29,8 +19,26 @@ code sigH
|
||||||
else log_abort();
|
else log_abort();
|
||||||
if (GetSize(O) <= 10)
|
if (GetSize(O) <= 10)
|
||||||
reject;
|
reject;
|
||||||
// Only care about those bits that are used
|
|
||||||
|
sigA = port(mul, \A);
|
||||||
int i;
|
int i;
|
||||||
|
for (i = GetSize(sigA)-1; i > 0; i--)
|
||||||
|
if (sigA[i] != sigA[i-1])
|
||||||
|
break;
|
||||||
|
// Do not remove non-const sign bit
|
||||||
|
if (sigA[i].wire)
|
||||||
|
++i;
|
||||||
|
sigA.remove(i, GetSize(sigA)-i);
|
||||||
|
sigB = port(mul, \B);
|
||||||
|
for (i = GetSize(sigB)-1; i > 0; i--)
|
||||||
|
if (sigB[i] != sigB[i-1])
|
||||||
|
break;
|
||||||
|
// Do not remove non-const sign bit
|
||||||
|
if (sigB[i].wire)
|
||||||
|
++i;
|
||||||
|
sigB.remove(i, GetSize(sigB)-i);
|
||||||
|
|
||||||
|
// Only care about those bits that are used
|
||||||
for (i = 0; i < GetSize(O); i++) {
|
for (i = 0; i < GetSize(O); i++) {
|
||||||
if (nusers(O[i]) <= 1)
|
if (nusers(O[i]) <= 1)
|
||||||
break;
|
break;
|
||||||
|
@ -41,19 +49,15 @@ endcode
|
||||||
|
|
||||||
match ffA
|
match ffA
|
||||||
if mul->type != \SB_MAC16 || !param(mul, \A_REG).as_bool()
|
if mul->type != \SB_MAC16 || !param(mul, \A_REG).as_bool()
|
||||||
if !sigAset.empty()
|
|
||||||
select ffA->type.in($dff)
|
select ffA->type.in($dff)
|
||||||
|
filter GetSize(port(ffA, \Q)) >= GetSize(sigA)
|
||||||
|
slice offset GetSize(port(ffA, \Q))
|
||||||
|
filter offset+GetSize(sigA) <= GetSize(port(ffA, \Q)) && port(ffA, \Q).extract(offset, GetSize(sigA)) == sigA
|
||||||
optional
|
optional
|
||||||
endmatch
|
endmatch
|
||||||
|
|
||||||
code sigA clock clock_pol
|
code sigA clock clock_pol
|
||||||
sigA = port(mul, \A);
|
|
||||||
|
|
||||||
if (ffA) {
|
if (ffA) {
|
||||||
auto ffAset = port(ffA, \Q).to_sigbit_set();
|
|
||||||
if (!std::includes(ffAset.begin(), ffAset.end(), sigAset.begin(), sigAset.end()))
|
|
||||||
reject;
|
|
||||||
|
|
||||||
for (auto b : port(ffA, \Q))
|
for (auto b : port(ffA, \Q))
|
||||||
if (b.wire->get_bool_attribute(\keep))
|
if (b.wire->get_bool_attribute(\keep))
|
||||||
reject;
|
reject;
|
||||||
|
@ -67,19 +71,15 @@ endcode
|
||||||
|
|
||||||
match ffB
|
match ffB
|
||||||
if mul->type != \SB_MAC16 || !param(mul, \B_REG).as_bool()
|
if mul->type != \SB_MAC16 || !param(mul, \B_REG).as_bool()
|
||||||
if !sigBset.empty()
|
|
||||||
select ffB->type.in($dff)
|
select ffB->type.in($dff)
|
||||||
|
filter GetSize(port(ffB, \Q)) >= GetSize(sigB)
|
||||||
|
slice offset GetSize(port(ffB, \Q))
|
||||||
|
filter offset+GetSize(sigB) <= GetSize(port(ffB, \Q)) && port(ffB, \Q).extract(offset, GetSize(sigB)) == sigB
|
||||||
optional
|
optional
|
||||||
endmatch
|
endmatch
|
||||||
|
|
||||||
code sigB clock clock_pol
|
code sigB clock clock_pol
|
||||||
sigB = port(mul, \B);
|
|
||||||
|
|
||||||
if (ffB) {
|
if (ffB) {
|
||||||
auto ffBset = port(ffB, \Q).to_sigbit_set();
|
|
||||||
if (!std::includes(ffBset.begin(), ffBset.end(), sigBset.begin(), sigBset.end()))
|
|
||||||
reject;
|
|
||||||
|
|
||||||
for (auto b : port(ffB, \Q))
|
for (auto b : port(ffB, \Q))
|
||||||
if (b.wire->get_bool_attribute(\keep))
|
if (b.wire->get_bool_attribute(\keep))
|
||||||
reject;
|
reject;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue