mirror of https://github.com/YosysHQ/yosys.git
Refactor using subpattern in_dffe
This commit is contained in:
parent
e68507a716
commit
04bc287271
|
@ -7,11 +7,21 @@ state <IdString> postAddAB postAddMuxAB
|
||||||
state <bool> ffAenpol ffADenpol ffBenpol ffCenpol ffDenpol ffMenpol ffPenpol
|
state <bool> ffAenpol ffADenpol ffBenpol ffCenpol ffDenpol ffMenpol ffPenpol
|
||||||
state <int> ffPoffset
|
state <int> ffPoffset
|
||||||
|
|
||||||
|
state <Cell*> ffAD ffADmux ffA ffAmux ffB ffBmux ffC ffCmux ffD ffDmux
|
||||||
|
|
||||||
|
// subpattern
|
||||||
|
state <SigSpec> dffQ
|
||||||
|
state <bool> dffenpol_
|
||||||
|
udata <SigSpec> dffD
|
||||||
|
udata <SigBit> dffclock
|
||||||
|
udata <Cell*> dff dffmux
|
||||||
|
udata <bool> dffenpol
|
||||||
|
|
||||||
match dsp
|
match dsp
|
||||||
select dsp->type.in(\DSP48E1)
|
select dsp->type.in(\DSP48E1)
|
||||||
endmatch
|
endmatch
|
||||||
|
|
||||||
code unextend sigA sigffAmuxY sigB sigffBmuxY sigC sigffCmuxY sigD sigffDmuxY sigM
|
code unextend sigA sigB sigC sigD sigM
|
||||||
unextend = [](const SigSpec &sig) {
|
unextend = [](const SigSpec &sig) {
|
||||||
int i;
|
int i;
|
||||||
for (i = GetSize(sig)-1; i > 0; i--)
|
for (i = GetSize(sig)-1; i > 0; i--)
|
||||||
|
@ -39,60 +49,24 @@ code unextend sigA sigffAmuxY sigB sigffBmuxY sigC sigffCmuxY sigD sigffDmuxY si
|
||||||
log_assert(nusers(P.extract_end(i)) <= 1);
|
log_assert(nusers(P.extract_end(i)) <= 1);
|
||||||
//if (GetSize(sigM) <= 10)
|
//if (GetSize(sigM) <= 10)
|
||||||
// reject;
|
// reject;
|
||||||
|
|
||||||
sigffAmuxY = SigSpec();
|
|
||||||
sigffBmuxY = SigSpec();
|
|
||||||
sigffCmuxY = SigSpec();
|
|
||||||
sigffDmuxY = SigSpec();
|
|
||||||
endcode
|
endcode
|
||||||
|
|
||||||
match ffAD
|
code dffQ ffAD ffADmux ffADenpol sigA clock
|
||||||
if param(dsp, \ADREG).as_int() == 0
|
if (param(dsp, \ADREG).as_int() == 0) {
|
||||||
select ffAD->type.in($dff)
|
dffQ = sigA;
|
||||||
// DSP48E1 does not support clock inversion
|
subpattern(in_dffe);
|
||||||
select param(ffAD, \CLK_POLARITY).as_bool()
|
if (dff) {
|
||||||
filter GetSize(port(ffAD, \Q)) >= GetSize(sigA)
|
ffAD = dff;
|
||||||
slice offset GetSize(port(ffAD, \Q))
|
clock = dffclock;
|
||||||
filter offset+GetSize(sigA) <= GetSize(port(ffAD, \Q))
|
if (dffmux) {
|
||||||
filter port(ffAD, \Q).extract(offset, GetSize(sigA)) == sigA
|
ffADmux = dffmux;
|
||||||
optional
|
ffADenpol = dffenpol;
|
||||||
endmatch
|
}
|
||||||
|
sigA = dffD;
|
||||||
code sigA sigffAmuxY clock
|
}
|
||||||
if (ffAD) {
|
|
||||||
for (auto b : port(ffAD, \Q))
|
|
||||||
if (b.wire->get_bool_attribute(\keep))
|
|
||||||
reject;
|
|
||||||
|
|
||||||
clock = port(ffAD, \CLK).as_bit();
|
|
||||||
|
|
||||||
SigSpec A = sigA;
|
|
||||||
A.replace(port(ffAD, \Q), port(ffAD, \D));
|
|
||||||
// Only search for ffAmux if ffA.Q has at
|
|
||||||
// least 3 users (ffA, dsp, ffAmux) and
|
|
||||||
// its ffA.D only has two (ffA, ffAmux)
|
|
||||||
if (nusers(sigA) >= 3 && nusers(A) == 2)
|
|
||||||
sigffAmuxY = sigA;
|
|
||||||
sigA = std::move(A);
|
|
||||||
}
|
}
|
||||||
endcode
|
endcode
|
||||||
|
|
||||||
match ffADmux
|
|
||||||
if !sigffAmuxY.empty()
|
|
||||||
select ffADmux->type.in($mux)
|
|
||||||
index <SigSpec> port(ffADmux, \Y) === port(ffAD, \D)
|
|
||||||
filter GetSize(port(ffADmux, \Y)) >= GetSize(sigA)
|
|
||||||
slice offset GetSize(port(ffADmux, \Y))
|
|
||||||
filter offset+GetSize(sigA) <= GetSize(port(ffADmux, \Y))
|
|
||||||
filter port(ffADmux, \Y).extract(offset, GetSize(sigA)) == sigA
|
|
||||||
choice <IdString> AB {\A, \B}
|
|
||||||
filter offset+GetSize(sigffAmuxY) <= GetSize(port(ffADmux, \Y))
|
|
||||||
filter port(ffADmux, AB).extract(offset, GetSize(sigffAmuxY)) == sigffAmuxY
|
|
||||||
define <bool> pol (AB == \A)
|
|
||||||
set ffADenpol pol
|
|
||||||
optional
|
|
||||||
endmatch
|
|
||||||
|
|
||||||
match preAdd
|
match preAdd
|
||||||
if sigD.empty() || sigD.is_fully_zero()
|
if sigD.empty() || sigD.is_fully_zero()
|
||||||
// Ensure that preAdder not already used
|
// Ensure that preAdder not already used
|
||||||
|
@ -123,169 +97,66 @@ code sigA sigD
|
||||||
}
|
}
|
||||||
endcode
|
endcode
|
||||||
|
|
||||||
match ffA
|
code dffQ ffA ffAmux ffAenpol sigA clock ffAD ffADmux ffADenpol
|
||||||
if !preAdd
|
// Only search for ffA if there was a pre-adder
|
||||||
if param(dsp, \AREG).as_int() == 0
|
// (otherwise ffA would have been matched as ffAD)
|
||||||
select ffA->type.in($dff)
|
if (preAdd) {
|
||||||
// DSP48E1 does not support clock inversion
|
if (param(dsp, \AREG).as_int() == 0) {
|
||||||
select param(ffA, \CLK_POLARITY).as_bool()
|
dffQ = sigA;
|
||||||
filter GetSize(port(ffA, \Q)) >= GetSize(sigA)
|
subpattern(in_dffe);
|
||||||
slice offset GetSize(port(ffA, \Q))
|
if (dff) {
|
||||||
filter offset+GetSize(sigA) <= GetSize(port(ffA, \Q))
|
ffA = dff;
|
||||||
filter port(ffA, \Q).extract(offset, GetSize(sigA)) == sigA
|
clock = dffclock;
|
||||||
optional
|
if (dffmux) {
|
||||||
endmatch
|
ffAmux = dffmux;
|
||||||
|
ffAenpol = dffenpol;
|
||||||
code sigA sigffAmuxY clock
|
|
||||||
if (ffA) {
|
|
||||||
for (auto b : port(ffA, \Q))
|
|
||||||
if (b.wire->get_bool_attribute(\keep))
|
|
||||||
reject;
|
|
||||||
|
|
||||||
clock = port(ffA, \CLK).as_bit();
|
|
||||||
|
|
||||||
SigSpec A = sigA;
|
|
||||||
A.replace(port(ffA, \Q), port(ffA, \D));
|
|
||||||
// Only search for ffAmux if ffA.Q has at
|
|
||||||
// least 3 users (ffA, dsp, ffAmux) and
|
|
||||||
// its ffA.D only has two (ffA, ffAmux)
|
|
||||||
if (nusers(sigA) >= 3 && nusers(A) == 2)
|
|
||||||
sigffAmuxY = sigA;
|
|
||||||
sigA = std::move(A);
|
|
||||||
}
|
}
|
||||||
else if (!preAdd) {
|
sigA = dffD;
|
||||||
sigffAmuxY = SigSpec();
|
|
||||||
}
|
}
|
||||||
endcode
|
}
|
||||||
|
}
|
||||||
match ffAmux
|
// And if there wasn't a pre-adder,
|
||||||
if !sigffAmuxY.empty()
|
// move AD register to A
|
||||||
select ffAmux->type.in($mux)
|
else if (ffAD) {
|
||||||
index <SigSpec> port(ffAmux, \Y) === port(ffA, \D)
|
log_assert(!ffA && !ffAmux);
|
||||||
filter GetSize(port(ffAmux, \Y)) >= GetSize(sigA)
|
std::swap(ffA, ffAD);
|
||||||
slice offset GetSize(port(ffAmux, \Y))
|
std::swap(ffAmux, ffADmux);
|
||||||
filter offset+GetSize(sigA) <= GetSize(port(ffAmux, \Y))
|
|
||||||
filter port(ffAmux, \Y).extract(offset, GetSize(sigA)) == sigA
|
|
||||||
choice <IdString> AB {\A, \B}
|
|
||||||
filter offset+GetSize(sigffAmuxY) <= GetSize(port(ffAmux, \Y))
|
|
||||||
filter port(ffAmux, AB).extract(offset, GetSize(sigffAmuxY)) == sigffAmuxY
|
|
||||||
define <bool> pol (AB == \A)
|
|
||||||
set ffAenpol pol
|
|
||||||
optional
|
|
||||||
endmatch
|
|
||||||
|
|
||||||
code ffA ffAmux ffAenpol ffAD ffADmux
|
|
||||||
// Move AD register to A if no pre-adder
|
|
||||||
if (!ffA && !preAdd && ffAD) {
|
|
||||||
ffA = ffAD;
|
|
||||||
ffAmux = ffADmux;
|
|
||||||
ffAenpol = ffADenpol;
|
ffAenpol = ffADenpol;
|
||||||
|
|
||||||
ffAD = nullptr;
|
|
||||||
ffADmux = nullptr;
|
|
||||||
}
|
}
|
||||||
endcode
|
endcode
|
||||||
|
|
||||||
match ffB
|
code dffQ ffB ffBmux ffBenpol sigB clock
|
||||||
if param(dsp, \BREG).as_int() == 0
|
if (param(dsp, \BREG).as_int() == 0) {
|
||||||
select ffB->type.in($dff)
|
dffQ = sigB;
|
||||||
// DSP48E1 does not support clock inversion
|
subpattern(in_dffe);
|
||||||
select param(ffB, \CLK_POLARITY).as_bool()
|
if (dff) {
|
||||||
filter GetSize(port(ffB, \Q)) >= GetSize(sigB)
|
ffB = dff;
|
||||||
slice offset GetSize(port(ffB, \Q))
|
clock = dffclock;
|
||||||
filter offset+GetSize(sigB) <= GetSize(port(ffB, \Q))
|
if (dffmux) {
|
||||||
filter port(ffB, \Q).extract(offset, GetSize(sigB)) == sigB
|
ffBmux = dffmux;
|
||||||
optional
|
ffBenpol = dffenpol;
|
||||||
endmatch
|
}
|
||||||
|
sigB = dffD;
|
||||||
code sigB sigffBmuxY clock
|
}
|
||||||
if (ffB) {
|
|
||||||
for (auto b : port(ffB, \Q))
|
|
||||||
if (b.wire->get_bool_attribute(\keep))
|
|
||||||
reject;
|
|
||||||
|
|
||||||
SigBit c = port(ffB, \CLK).as_bit();
|
|
||||||
if (clock != SigBit() && c != clock)
|
|
||||||
reject;
|
|
||||||
clock = c;
|
|
||||||
|
|
||||||
SigSpec B = sigB;
|
|
||||||
B.replace(port(ffB, \Q), port(ffB, \D));
|
|
||||||
// Only search for ffBmux if ffB.Q has at
|
|
||||||
// least 3 users (ffB, dsp, ffBmux) and
|
|
||||||
// its ffB.D only has two (ffB, ffBmux)
|
|
||||||
if (nusers(sigB) >= 3 && nusers(B) == 2)
|
|
||||||
sigffBmuxY = sigB;
|
|
||||||
sigB = std::move(B);
|
|
||||||
}
|
}
|
||||||
endcode
|
endcode
|
||||||
|
|
||||||
match ffBmux
|
code dffQ ffD ffDmux ffDenpol sigD clock
|
||||||
if !sigffBmuxY.empty()
|
if (param(dsp, \DREG).as_int() == 0) {
|
||||||
select ffBmux->type.in($mux)
|
dffQ = sigD;
|
||||||
index <SigSpec> port(ffBmux, \Y) === port(ffB, \D)
|
subpattern(in_dffe);
|
||||||
filter GetSize(port(ffBmux, \Y)) >= GetSize(sigB)
|
if (dff) {
|
||||||
slice offset GetSize(port(ffBmux, \Y))
|
ffD = dff;
|
||||||
filter offset+GetSize(sigB) <= GetSize(port(ffBmux, \Y))
|
clock = dffclock;
|
||||||
filter port(ffBmux, \Y).extract(offset, GetSize(sigB)) == sigB
|
if (dffmux) {
|
||||||
choice <IdString> AB {\A, \B}
|
ffDmux = dffmux;
|
||||||
filter offset+GetSize(sigffBmuxY) <= GetSize(port(ffBmux, \Y))
|
ffDenpol = dffenpol;
|
||||||
filter port(ffBmux, AB).extract(offset, GetSize(sigffBmuxY)) == sigffBmuxY
|
}
|
||||||
define <bool> pol (AB == \A)
|
sigD = dffD;
|
||||||
set ffBenpol pol
|
}
|
||||||
optional
|
|
||||||
endmatch
|
|
||||||
|
|
||||||
match ffD
|
|
||||||
if param(dsp, \DREG).as_int() == 0
|
|
||||||
select ffD->type.in($dff)
|
|
||||||
// DSP48E1 does not support clock inversion
|
|
||||||
select param(ffD, \CLK_POLARITY).as_bool()
|
|
||||||
filter GetSize(port(ffD, \Q)) >= GetSize(sigD)
|
|
||||||
slice offset GetSize(port(ffD, \Q))
|
|
||||||
filter offset+GetSize(sigD) <= GetSize(port(ffD, \Q))
|
|
||||||
filter port(ffD, \Q).extract(offset, GetSize(sigD)) == sigD
|
|
||||||
optional
|
|
||||||
endmatch
|
|
||||||
|
|
||||||
code sigD sigffDmuxY clock
|
|
||||||
if (ffD) {
|
|
||||||
for (auto b : port(ffD, \Q))
|
|
||||||
if (b.wire->get_bool_attribute(\keep))
|
|
||||||
reject;
|
|
||||||
|
|
||||||
SigBit c = port(ffD, \CLK).as_bit();
|
|
||||||
if (clock != SigBit() && c != clock)
|
|
||||||
reject;
|
|
||||||
clock = c;
|
|
||||||
|
|
||||||
SigSpec D = sigD;
|
|
||||||
D.replace(port(ffD, \Q), port(ffD, \D));
|
|
||||||
// Only search for ffDmux if ffD.Q has at
|
|
||||||
// least 3 users (ffD, dsp, ffDmux) and
|
|
||||||
// its ffD.D only has two (ffD, ffDmux)
|
|
||||||
if (nusers(sigD) >= 3 && nusers(D) == 2)
|
|
||||||
sigffDmuxY = sigD;
|
|
||||||
sigD = std::move(D);
|
|
||||||
}
|
}
|
||||||
endcode
|
endcode
|
||||||
|
|
||||||
match ffDmux
|
|
||||||
if !sigffDmuxY.empty()
|
|
||||||
select ffDmux->type.in($mux)
|
|
||||||
index <SigSpec> port(ffDmux, \Y) === port(ffD, \D)
|
|
||||||
filter GetSize(port(ffDmux, \Y)) >= GetSize(sigD)
|
|
||||||
slice offset GetSize(port(ffDmux, \Y))
|
|
||||||
filter offset+GetSize(sigD) <= GetSize(port(ffDmux, \Y))
|
|
||||||
filter port(ffDmux, \Y).extract(offset, GetSize(sigD)) == sigD
|
|
||||||
choice <IdString> AB {\A, \B}
|
|
||||||
filter offset+GetSize(sigffDmuxY) <= GetSize(port(ffDmux, \Y))
|
|
||||||
filter port(ffDmux, AB).extract(offset, GetSize(sigffDmuxY)) == sigffDmuxY
|
|
||||||
define <bool> pol (AB == \A)
|
|
||||||
set ffDenpol pol
|
|
||||||
optional
|
|
||||||
endmatch
|
|
||||||
|
|
||||||
match ffMmux
|
match ffMmux
|
||||||
if param(dsp, \MREG).as_int() == 0
|
if param(dsp, \MREG).as_int() == 0
|
||||||
if nusers(sigM) == 2
|
if nusers(sigM) == 2
|
||||||
|
@ -496,56 +367,91 @@ code sigC
|
||||||
sigC = port(postAddMux, postAddMuxAB == \A ? \B : \A);
|
sigC = port(postAddMux, postAddMuxAB == \A ? \B : \A);
|
||||||
endcode
|
endcode
|
||||||
|
|
||||||
match ffC
|
code dffQ ffC ffCmux ffCenpol sigC clock
|
||||||
if param(dsp, \CREG).as_int() == 0
|
if (param(dsp, \CREG).as_int() == 0) {
|
||||||
select ffC->type.in($dff)
|
dffQ = sigC;
|
||||||
// DSP48E1 does not support clock inversion
|
subpattern(in_dffe);
|
||||||
select param(ffC, \CLK_POLARITY).as_bool()
|
if (dff) {
|
||||||
filter GetSize(port(ffC, \Q)) >= GetSize(sigD)
|
ffC = dff;
|
||||||
slice offset GetSize(port(ffC, \Q))
|
clock = dffclock;
|
||||||
filter offset+GetSize(sigC) <= GetSize(port(ffC, \Q))
|
if (dffmux) {
|
||||||
filter port(ffC, \Q).extract(offset, GetSize(sigC)) == sigC
|
ffCmux = dffmux;
|
||||||
optional
|
ffCenpol = dffenpol;
|
||||||
endmatch
|
}
|
||||||
|
sigC = dffD;
|
||||||
code sigC sigffCmuxY clock
|
}
|
||||||
if (ffC) {
|
|
||||||
for (auto b : port(ffC, \Q))
|
|
||||||
if (b.wire->get_bool_attribute(\keep))
|
|
||||||
reject;
|
|
||||||
|
|
||||||
SigBit c = port(ffC, \CLK).as_bit();
|
|
||||||
if (clock != SigBit() && c != clock)
|
|
||||||
reject;
|
|
||||||
clock = c;
|
|
||||||
|
|
||||||
SigSpec C = sigC;
|
|
||||||
C.replace(port(ffC, \Q), port(ffC, \D));
|
|
||||||
// Only search for ffCmux if ffC.Q has at
|
|
||||||
// least 3 users (ffC, dsp, ffCmux) and
|
|
||||||
// its ffC.D only has two (ffC, ffCmux)
|
|
||||||
if (nusers(sigC) >= 3 && nusers(C) == 2)
|
|
||||||
sigffCmuxY = sigC;
|
|
||||||
sigC = std::move(C);
|
|
||||||
}
|
}
|
||||||
endcode
|
endcode
|
||||||
|
|
||||||
match ffCmux
|
|
||||||
if !sigffCmuxY.empty()
|
|
||||||
select ffCmux->type.in($mux)
|
|
||||||
index <SigSpec> port(ffCmux, \Y) === port(ffC, \D)
|
|
||||||
filter GetSize(port(ffCmux, \Y)) >= GetSize(sigC)
|
|
||||||
slice offset GetSize(port(ffCmux, \Y))
|
|
||||||
filter offset+GetSize(sigC) <= GetSize(port(ffCmux, \Y))
|
|
||||||
filter port(ffCmux, \Y).extract(offset, GetSize(sigC)) == sigC
|
|
||||||
choice <IdString> AB {\A, \B}
|
|
||||||
filter offset+GetSize(sigffCmuxY) <= GetSize(port(ffCmux, \Y))
|
|
||||||
filter port(ffCmux, AB).extract(offset, GetSize(sigffCmuxY)) == sigffCmuxY
|
|
||||||
define <bool> pol (AB == \A)
|
|
||||||
set ffCenpol pol
|
|
||||||
optional
|
|
||||||
endmatch
|
|
||||||
|
|
||||||
code
|
code
|
||||||
accept;
|
accept;
|
||||||
endcode
|
endcode
|
||||||
|
|
||||||
|
subpattern in_dffe
|
||||||
|
arg dffQ clock dffenpol_
|
||||||
|
|
||||||
|
code
|
||||||
|
dff = nullptr;
|
||||||
|
dffmux = nullptr;
|
||||||
|
endcode
|
||||||
|
|
||||||
|
match ff
|
||||||
|
select ff->type.in($dff)
|
||||||
|
// DSP48E1 does not support clock inversion
|
||||||
|
select param(ff, \CLK_POLARITY).as_bool()
|
||||||
|
filter GetSize(port(ff, \Q)) >= GetSize(dffQ)
|
||||||
|
slice offset GetSize(port(ff, \Q))
|
||||||
|
filter offset+GetSize(dffQ) <= GetSize(port(ff, \Q))
|
||||||
|
filter port(ff, \Q).extract(offset, GetSize(dffQ)) == dffQ
|
||||||
|
semioptional
|
||||||
|
endmatch
|
||||||
|
|
||||||
|
code dffQ
|
||||||
|
if (ff) {
|
||||||
|
for (auto b : dffQ)
|
||||||
|
if (b.wire->get_bool_attribute(\keep))
|
||||||
|
reject;
|
||||||
|
|
||||||
|
if (clock != SigBit()) {
|
||||||
|
if (port(ff, \CLK) != clock)
|
||||||
|
reject;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
dffclock = port(ff, \CLK);
|
||||||
|
|
||||||
|
dff = ff;
|
||||||
|
dffD = dffQ;
|
||||||
|
dffD.replace(port(ff, \Q), port(ff, \D));
|
||||||
|
// Only search for ffmux if ff.Q has at
|
||||||
|
// least 3 users (ff, dsp, ffmux) and
|
||||||
|
// its ff.D only has two (ff, ffmux)
|
||||||
|
if (!(nusers(dffQ) >= 3 && nusers(dffD) == 2))
|
||||||
|
dffQ = SigSpec();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
dffQ = SigSpec();
|
||||||
|
endcode
|
||||||
|
|
||||||
|
match ffmux
|
||||||
|
if !dffQ.empty()
|
||||||
|
select ffmux->type.in($mux)
|
||||||
|
index <SigSpec> port(ffmux, \Y) === port(ff, \D)
|
||||||
|
filter GetSize(port(ffmux, \Y)) >= GetSize(dffD)
|
||||||
|
slice offset GetSize(port(ffmux, \Y))
|
||||||
|
filter offset+GetSize(dffD) <= GetSize(port(ffmux, \Y))
|
||||||
|
filter port(ffmux, \Y).extract(offset, GetSize(dffD)) == dffD
|
||||||
|
choice <IdString> AB {\A, \B}
|
||||||
|
filter offset+GetSize(dffQ) <= GetSize(port(ffmux, \Y))
|
||||||
|
filter port(ffmux, AB).extract(offset, GetSize(dffQ)) == dffQ
|
||||||
|
define <bool> pol (AB == \A)
|
||||||
|
set dffenpol_ pol
|
||||||
|
semioptional
|
||||||
|
endmatch
|
||||||
|
|
||||||
|
code
|
||||||
|
if (ffmux) {
|
||||||
|
dffmux = ffmux;
|
||||||
|
dffenpol = dffenpol_;
|
||||||
|
dffD = port(ffmux, dffenpol ? \B : \A);
|
||||||
|
}
|
||||||
|
endcode
|
||||||
|
|
Loading…
Reference in New Issue