Skip to content

Commit 097c987

Browse files
committed
mcm: programmatically generated multiplications
1 parent 528f696 commit 097c987

File tree

1 file changed

+5
-32
lines changed

1 file changed

+5
-32
lines changed

misoc/cores/duc.py

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -215,38 +215,11 @@ def __init__(self, width, constants):
215215

216216
# manually generated multiplication for small numbers,
217217
# if you use "x*y" Vivado will use a DSP48E1 instead
218-
if n > 0:
219-
ctx += o[0].eq(0)
220-
if n > 1:
221-
ctx += o[1].eq(i)
222-
if n > 2:
223-
ctx += o[2].eq(i << 1)
224-
if n > 3:
225-
ctx += o[3].eq(i + (i << 1))
226-
if n > 4:
227-
ctx += o[4].eq(i << 2)
228-
if n > 5:
229-
ctx += o[5].eq(i + (i << 2))
230-
if n > 6:
231-
ctx += o[6].eq((i << 2) + (i << 1))
232-
if n > 7:
233-
ctx += o[7].eq((i << 3) - i)
234-
if n > 8:
235-
ctx += o[8].eq(i << 3)
236-
if n > 9:
237-
ctx += o[9].eq(i + (i << 3))
238-
if n > 10:
239-
ctx += o[10].eq((i << 3) + (i << 1))
240-
if n > 11:
241-
ctx += o[11].eq(i + (i << 3) + (i << 1))
242-
if n > 12:
243-
ctx += o[12].eq((i << 3) + (i << 2))
244-
if n > 13:
245-
ctx += o[13].eq(i + (i << 3) + (i << 2))
246-
if n > 14:
247-
ctx += o[14].eq((i << 3) + (i << 2) + (i << 1))
248-
if n > 15:
249-
ctx += o[15].eq(i + (i << 3) + (i << 2) + (i << 1))
218+
for x in range(n):
219+
ctx += o[x].eq((x & 0x1) * i +
220+
((x & 0x2) >> 1) * (i << 1) +
221+
((x & 0x4) >> 2) * (i << 2) +
222+
((x & 0x8) >> 3) * (i << 3))
250223

251224

252225
class PhasedAccu(Module):

0 commit comments

Comments
 (0)