-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
coreblocks/fu/unsigned_multiplication/iterative_sequence.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from amaranth import * | ||
import math | ||
# from coreblocks.fu.unsigned_multiplication.common import DSPMulUnit, MulBaseUnsigned | ||
# from coreblocks.params import GenParams | ||
# from transactron import * | ||
# from transactron.core import def_method | ||
|
||
__all__ = ["IterativeSequenceMul"] | ||
|
||
|
||
class IterativeSequenceMul(Elaboratable): | ||
def __init__(self, dsp_width: int, n: int): | ||
self.n = n | ||
self.dsp_width = dsp_width | ||
|
||
self.i1 = Signal(unsigned(n)) | ||
self.i2 = Signal(unsigned(n)) | ||
self.result = Signal(unsigned(n * 2)) | ||
|
||
self.pipline_array = [[[Signal(unsigned(n*2)) for _ in range(n)] for _ in range(n)] for _ in range(n)] | ||
|
||
def elaborate(self): | ||
m = Module() | ||
|
||
number_of_chunks = self.n // self.dsp_width | ||
|
||
for j in range(number_of_chunks): | ||
chunk_i1 = self.i1[j*self.dsp_width : (j+1)*self.dsp_width] | ||
for i in range(number_of_chunks): | ||
chunk_i2 = self.i2[i*self.dsp_width:(i+1)*self.dsp_width] | ||
m.d.sync += self.pipline_array[0][j][i].eq(chunk_i1*chunk_i2) | ||
|
||
for i in range(1, n): | ||
for j in range(n-1): | ||
for k in range(n-1): | ||
ll = pipline_array[i-1][j][k] | ||
lu = pipline_array[i-1][j][k+1] | ||
ul = pipline_array[i-1][j+1][k] | ||
uu = pipline_array[i-1][j+1][k+1] | ||
m.d.sync += self.pipline_array[i][j][k].eq(ll+((ul+lu) << self.n // 2) + (uu << self.n)) | ||
result_lvl = math.log(self.n - self.dps_width, 2) | ||
m.d.sync += self.result.eq(self.pipline_array[result_lvl][0][0]) | ||
return m |