whoops forgot that the mul pipeline is actually a pipeline (3 stage, first one)
[soc.git] / src / soc / fu / pipe_data.py
1 from ieee754.fpcommon.getop import FPPipeContext
2 from nmutil.dynamicpipe import SimpleHandshakeRedir
3 from nmigen import Signal
4 from soc.decoder.power_decoder2 import Data
5 from soc.fu.regspec import get_regspec_bitwidth
6
7 class IntegerData:
8
9 def __init__(self, pspec, output):
10 self.ctx = FPPipeContext(pspec)
11 self.muxid = self.ctx.muxid
12 self.data = []
13 self.is_output = output
14 for i, (regfile, regname, widspec) in enumerate(self.regspec):
15 wid = get_regspec_bitwidth([self.regspec], 0, i)
16 if output:
17 sig = Data(wid, name=regname)
18 else:
19 sig = Signal(wid, name=regname, reset_less=True)
20 setattr(self, regname, sig)
21 self.data.append(sig)
22
23 def __iter__(self):
24 yield from self.ctx
25 yield from self.data
26
27 def eq(self, i):
28 eqs = [self.ctx.eq(i.ctx)]
29 for j in range(len(self.data)):
30 assert type(self.data[j]) == type(i.data[j])
31 eqs.append(self.data[j].eq(i.data[j]))
32 return eqs
33
34 def ports(self):
35 return self.ctx.ports() # TODO: include self.data
36
37
38 # hmmm there has to be a better way than this
39 def get_rec_width(rec):
40 recwidth = 0
41 # Setup random inputs for dut.op
42 for p in rec.ports():
43 width = p.width
44 recwidth += width
45 return recwidth
46
47
48 class CommonPipeSpec:
49 def __init__(self, id_wid):
50 self.pipekls = SimpleHandshakeRedir
51 self.id_wid = id_wid
52 self.opkls = lambda _: self.opsubsetkls(name="op")
53 self.op_wid = get_rec_width(self.opkls(None)) # hmm..
54 self.stage = None