rename FPADDBaseData to FPBaseData and move to separate module
[ieee754fpu.git] / src / ieee754 / fpcommon / basedata.py
1 # IEEE Floating Point Adder (Single Precision)
2 # Copyright (C) 2019 Luke Kenneth Casson Leighton <lkcl@lkcl.net>
3
4 from nmigen import Signal
5 from ieee754.fpcommon.getop import FPPipeContext
6
7
8 class FPBaseData:
9
10 def __init__(self, pspec, n_ops=2):
11 width = pspec.width
12 self.ctx = FPPipeContext(pspec)
13 ops = []
14 for i in range(n_ops):
15 name = chr(ord("a")+i)
16 operand = Signal(width, name=name)
17 setattr(self, name, operand)
18 ops.append(operand)
19 self.muxid = self.ctx.muxid # make muxid available here: complicated
20 self.ops = ops
21
22 def eq(self, i):
23 ret = []
24 for op1, op2 in zip(self.ops, i.ops):
25 ret.append(op1.eq(op2))
26 ret.append(self.ctx.eq(i.ctx))
27 return ret
28
29 def __iter__(self):
30 if self.ops:
31 yield from self.ops
32 yield from self.ctx
33
34 def ports(self):
35 return list(self)
36
37