mirror of https://github.com/YosysHQ/yosys.git
317 lines
8.7 KiB
Plaintext
317 lines
8.7 KiB
Plaintext
pattern xilinx_dsp
|
|
|
|
state <SigBit> clock
|
|
state <SigSpec> sigA sigffAmuxY sigB sigffBmuxY sigC sigM sigP
|
|
state <IdString> postAddAB postAddMuxAB
|
|
state <bool> ffAenpol ffBenpol ffMenpol ffPenpol
|
|
|
|
match dsp
|
|
select dsp->type.in(\DSP48E1)
|
|
endmatch
|
|
|
|
code sigA sigffAmuxY sigB sigffBmuxY sigM
|
|
sigA = port(dsp, \A);
|
|
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(dsp, \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);
|
|
|
|
SigSpec P = port(dsp, \P);
|
|
// Only care about those bits that are used
|
|
for (i = 0; i < GetSize(P); i++) {
|
|
if (nusers(P[i]) <= 1)
|
|
break;
|
|
sigM.append(P[i]);
|
|
}
|
|
log_assert(nusers(P.extract_end(i)) <= 1);
|
|
//if (GetSize(sigM) <= 10)
|
|
// reject;
|
|
|
|
sigffAmuxY = SigSpec();
|
|
sigffBmuxY = SigSpec();
|
|
endcode
|
|
|
|
match ffA
|
|
if param(dsp, \AREG).as_int() == 0
|
|
select ffA->type.in($dff)
|
|
// DSP48E1 does not support clock inversion
|
|
select param(ffA, \CLK_POLARITY).as_bool()
|
|
filter GetSize(port(ffA, \Q)) >= GetSize(sigA)
|
|
slice offset GetSize(port(ffA, \Q))
|
|
filter offset+GetSize(sigA) <= GetSize(port(ffA, \Q))
|
|
filter port(ffA, \Q).extract(offset, GetSize(sigA)) == sigA
|
|
optional
|
|
endmatch
|
|
|
|
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);
|
|
}
|
|
endcode
|
|
|
|
match ffAmux
|
|
if !sigffAmuxY.empty()
|
|
select ffAmux->type.in($mux)
|
|
filter GetSize(port(ffAmux, \Y)) >= GetSize(sigA)
|
|
slice offset GetSize(port(ffAmux, \Y))
|
|
filter offset+GetSize(sigA) <= GetSize(port(ffAmux, \Y))
|
|
filter port(ffAmux, \Y).extract(offset, GetSize(sigA)) == sigA
|
|
choice <IdString> BA {\B, \A}
|
|
filter offset+GetSize(sigffAmuxY) <= GetSize(port(ffAmux, \Y))
|
|
filter port(ffAmux, BA).extract(offset, GetSize(sigffAmuxY)) == sigffAmuxY
|
|
define <bool> pol (BA == \B)
|
|
set ffAenpol pol
|
|
optional
|
|
endmatch
|
|
|
|
match ffB
|
|
if param(dsp, \BREG).as_int() == 0
|
|
select ffB->type.in($dff)
|
|
// DSP48E1 does not support clock inversion
|
|
select param(ffB, \CLK_POLARITY).as_bool()
|
|
filter GetSize(port(ffB, \Q)) >= GetSize(sigB)
|
|
slice offset GetSize(port(ffB, \Q))
|
|
filter offset+GetSize(sigB) <= GetSize(port(ffB, \Q))
|
|
filter port(ffB, \Q).extract(offset, GetSize(sigB)) == sigB
|
|
optional
|
|
endmatch
|
|
|
|
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
|
|
|
|
match ffBmux
|
|
if !sigffBmuxY.empty()
|
|
select ffBmux->type.in($mux)
|
|
filter GetSize(port(ffBmux, \Y)) >= GetSize(sigB)
|
|
slice offset GetSize(port(ffBmux, \Y))
|
|
filter offset+GetSize(sigB) <= GetSize(port(ffBmux, \Y))
|
|
filter port(ffBmux, \Y).extract(offset, GetSize(sigB)) == sigB
|
|
choice <IdString> BA {\B, \A}
|
|
filter offset+GetSize(sigffBmuxY) <= GetSize(port(ffBmux, \Y))
|
|
filter port(ffBmux, BA).extract(offset, GetSize(sigffBmuxY)) == sigffBmuxY
|
|
define <bool> pol (BA == \B)
|
|
set ffBenpol pol
|
|
optional
|
|
endmatch
|
|
|
|
match ffMmux
|
|
select ffMmux->type.in($mux)
|
|
choice <IdString> BA {\B, \A}
|
|
// new-value net must have exactly two users: dsp and ffM
|
|
select nusers(port(ffMmux, BA)) == 2
|
|
define <IdString> AB (BA == \B ? \A : \B)
|
|
// keep-last-value net must have at least three users: ffMmux, ffM, downstream sink(s)
|
|
select nusers(port(ffMmux, AB)) >= 3
|
|
// ffMmux output must have two users: ffMmux and ffM.D
|
|
select nusers(port(ffMmux, \Y)) == 2
|
|
filter GetSize(port(ffMmux, \Y)) <= GetSize(sigM)
|
|
filter port(ffMmux, BA) == sigM.extract(0, GetSize(port(ffMmux, \Y)))
|
|
// Remaining bits on sigM must not have any other users
|
|
filter nusers(sigM.extract_end(GetSize(port(ffMmux, BA)))) <= 1
|
|
define <bool> pol (BA == \B)
|
|
set ffMenpol pol
|
|
optional
|
|
endmatch
|
|
|
|
code sigM
|
|
if (ffMmux)
|
|
sigM = port(ffMmux, \Y);
|
|
endcode
|
|
|
|
match ffM
|
|
if param(dsp, \MREG).as_int() == 0
|
|
select ffM->type.in($dff)
|
|
// DSP48E1 does not support clock inversion
|
|
select param(ffM, \CLK_POLARITY).as_bool()
|
|
select nusers(port(ffM, \D)) == 2
|
|
filter GetSize(port(ffM, \D)) <= GetSize(sigM)
|
|
filter port(ffM, \D) == sigM.extract(0, GetSize(port(ffM, \D)))
|
|
// Remaining bits on sigM must not have any other users
|
|
filter nusers(sigM.extract_end(GetSize(port(ffM, \D)))) <= 1
|
|
// Check ffMmux (when present) is a $dff enable mux
|
|
filter !ffMmux || port(ffM, \Q) == port(ffMmux, ffMenpol ? \A : \B)
|
|
optional
|
|
endmatch
|
|
|
|
code clock sigM sigP
|
|
if (ffM) {
|
|
sigM = port(ffM, \Q);
|
|
|
|
for (auto b : sigM)
|
|
if (b.wire->get_bool_attribute(\keep))
|
|
reject;
|
|
|
|
SigBit c = port(ffM, \CLK).as_bit();
|
|
if (clock != SigBit() && c != clock)
|
|
reject;
|
|
clock = c;
|
|
}
|
|
// Cannot have ffMmux enable mux without ffM
|
|
else if (ffMmux)
|
|
reject;
|
|
|
|
sigP = sigM;
|
|
endcode
|
|
|
|
match postAdd
|
|
// Ensure that Z mux is not already used
|
|
if port(dsp, \OPMODE).extract(4,3).is_fully_zero()
|
|
|
|
select postAdd->type.in($add)
|
|
select GetSize(port(postAdd, \Y)) <= 48
|
|
select nusers(port(postAdd, \Y)) == 2
|
|
choice <IdString> AB {\A, \B}
|
|
select nusers(port(postAdd, AB)) <= 3
|
|
filter ffMmux || nusers(port(postAdd, AB)) == 2
|
|
filter !ffMmux || nusers(port(postAdd, AB)) == 3
|
|
filter GetSize(port(postAdd, AB)) <= GetSize(sigP)
|
|
filter port(postAdd, AB) == sigP.extract(0, GetSize(port(postAdd, AB)))
|
|
filter nusers(sigP.extract_end(GetSize(port(postAdd, AB)))) <= 1
|
|
set postAddAB AB
|
|
optional
|
|
endmatch
|
|
|
|
code sigC sigP
|
|
if (postAdd) {
|
|
sigC = port(postAdd, postAddAB == \A ? \B : \A);
|
|
|
|
// TODO for DSP48E1, which will have sign extended inputs/outputs
|
|
//int natural_mul_width = GetSize(port(dsp, \A)) + GetSize(port(dsp, \B));
|
|
//int actual_mul_width = GetSize(sigP);
|
|
//int actual_acc_width = GetSize(sigC);
|
|
|
|
//if ((actual_acc_width > actual_mul_width) && (natural_mul_width > actual_mul_width))
|
|
// reject;
|
|
//if ((actual_acc_width != actual_mul_width) && (param(dsp, \A_SIGNED).as_bool() != param(postAdd, \A_SIGNED).as_bool()))
|
|
// reject;
|
|
|
|
sigP = port(postAdd, \Y);
|
|
}
|
|
endcode
|
|
|
|
match ffPmux
|
|
if param(dsp, \PREG).as_int() == 0
|
|
if nusers(sigP) == 2
|
|
select ffPmux->type.in($mux)
|
|
choice <IdString> BA {\B, \A}
|
|
// new-value net must have exactly two users: dsp and ffP
|
|
select nusers(port(ffPmux, BA)) == 2
|
|
define <IdString> AB (BA == \B ? \A : \B)
|
|
// keep-last-value net must have at least three users: ffPmux, ffP, downstream sink(s)
|
|
select nusers(port(ffPmux, AB)) >= 3
|
|
// ffPmux output must have two users: ffPmux and ffP.D
|
|
select nusers(port(ffPmux, \Y)) == 2
|
|
filter GetSize(port(ffPmux, \Y)) <= GetSize(sigP)
|
|
filter port(ffPmux, BA) == sigP.extract(0, GetSize(port(ffPmux, \Y)))
|
|
// Remaining bits on sigP must not have any other users
|
|
filter nusers(sigP.extract_end(GetSize(port(ffPmux, BA)))) <= 1
|
|
define <bool> pol (BA == \B)
|
|
set ffPenpol pol
|
|
optional
|
|
endmatch
|
|
|
|
code sigP
|
|
if (ffPmux)
|
|
sigP.replace(port(ffPmux, ffPenpol ? \A : \B), port(ffPmux, \Y));
|
|
endcode
|
|
|
|
match ffP
|
|
if param(dsp, \PREG).as_int() == 0
|
|
if nusers(sigP) == 2
|
|
select ffP->type.in($dff)
|
|
// DSP48E1 does not support clock inversion
|
|
select param(ffP, \CLK_POLARITY).as_bool()
|
|
filter GetSize(port(ffP, \D)) >= GetSize(sigP)
|
|
slice offset GetSize(port(ffP, \D))
|
|
filter offset+GetSize(sigP) <= GetSize(port(ffP, \D))
|
|
filter port(ffP, \D).extract(offset, GetSize(sigP)) == sigP
|
|
// Check ffPmux (when present) is a $dff enable mux
|
|
filter !ffPmux || port(ffP, \Q) == port(ffPmux, ffPenpol ? \A : \B)
|
|
optional
|
|
endmatch
|
|
|
|
code ffP sigP clock
|
|
if (ffP) {
|
|
for (auto b : port(ffP, \Q))
|
|
if (b.wire->get_bool_attribute(\keep))
|
|
reject;
|
|
|
|
SigBit c = port(ffP, \CLK).as_bit();
|
|
|
|
if (clock != SigBit() && c != clock)
|
|
reject;
|
|
|
|
clock = c;
|
|
|
|
sigP.replace(port(ffP, \D), port(ffP, \Q));
|
|
}
|
|
// Cannot have ffPmux enable mux without ffP
|
|
else if (ffPmux)
|
|
reject;
|
|
endcode
|
|
|
|
match postAddMux
|
|
if postAdd
|
|
if ffP
|
|
select postAddMux->type.in($mux)
|
|
select nusers(port(postAddMux, \Y)) == 2
|
|
choice <IdString> AB {\A, \B}
|
|
index <SigSpec> port(postAddMux, AB) === sigP
|
|
index <SigSpec> port(postAddMux, \Y) === sigC
|
|
set postAddMuxAB AB
|
|
optional
|
|
endmatch
|
|
|
|
code sigC
|
|
if (postAddMux)
|
|
sigC = port(postAddMux, postAddMuxAB == \A ? \B : \A);
|
|
endcode
|
|
|
|
code
|
|
accept;
|
|
endcode
|