split out adder code (PartitionedAdder) into module, PartitionPoints too
[ieee754fpu.git] / src / ieee754 / fclass / pipeline.py
1 # IEEE754 FCLASS Module
2 # Copyright (C) 2019 Luke Kenneth Casson Leighon <lkcl@lkcl.net>
3
4 from nmutil.singlepipe import ControlBase
5 from nmutil.concurrentunit import ReservationStations, num_bits
6 from ieee754.fpcommon.fpbase import FPNumBase
7 from ieee754.fclass.fclass import FPClassMod
8 from ieee754.pipeline import PipelineSpec, DynamicPipe
9
10
11 class FPFClassPipe(DynamicPipe):
12 """ FPConversion: turns its argument (modkls) from a stage into a pipe
13 """
14
15 def __init__(self, in_pspec, out_pspec, modkls):
16 in_pspec.stage = modkls(in_pspec, out_pspec)
17 super().__init__(in_pspec)
18
19
20 # XXX not used because there isn't anything to "join" (no pipe chain)
21 # keeping this code around just in case FPClass has to be split into
22 # two [unlikely but hey]
23 class FPClassBasePipe(ControlBase):
24 def __init__(self, modkls, in_pspec, out_pspec):
25 ControlBase.__init__(self)
26 # redundant because there's only one "thing" here.
27 self.pipe1 = FPFClassPipe(in_pspec, out_pspec, modkls)
28 self._eqs = self.connect([self.pipe1, ])
29
30 def elaborate(self, platform):
31 m = ControlBase.elaborate(self, platform)
32 m.submodules.fclass = self.pipe1
33 m.d.comb += self._eqs
34 return m
35
36
37 class FPClassMuxInOutBase(ReservationStations):
38 """ Reservation-Station version of FPClass pipeline.
39
40 * fan-in on inputs (an array of FPBaseData: a,b,mid)
41 * 2-stage multiplier pipeline
42 * fan-out on outputs (an array of FPPackData: z,mid)
43
44 Fan-in and Fan-out are combinatorial.
45 """
46
47 def __init__(self, modkls, in_width, out_width,
48 num_rows, op_wid=0, pkls=FPClassBasePipe):
49 self.op_wid = op_wid
50 self.id_wid = num_bits(num_rows)
51
52 self.in_pspec = PipelineSpec(in_width, self.id_wid, op_wid)
53 self.out_pspec = PipelineSpec(out_width, self.id_wid, op_wid)
54
55 self.alu = pkls(self.in_pspec, self.out_pspec, modkls)
56 ReservationStations.__init__(self, num_rows)
57
58
59 class FPClassMuxInOut(FPClassMuxInOutBase):
60 """ Reservation-Station version of FPClass pipeline.
61
62 * fan-in on inputs (an array of FPBaseData: a,b,mid)
63 * 2-stage multiplier pipeline
64 * fan-out on outputs (an array of FPPackData: z,mid)
65
66 Fan-in and Fan-out are combinatorial.
67 """
68
69 def __init__(self, in_width, out_width, num_rows, op_wid=0):
70 FPClassMuxInOutBase.__init__(self, FPClassMod,
71 in_width, out_width,
72 num_rows, op_wid,
73 pkls=FPFClassPipe)
74 #pkls=FPClassBasePipe)
75