add notes on FunctionUnit API
[soc.git] / src / soc / fu / compunits.py
1 """
2 * see https://libre-soc.org/3d_gpu/architecture/regfile/ section on regspecs
3
4 """
5
6 from nmigen.cli import rtlil
7 from soc.experiment.compalu_multi import MultiCompUnit
8
9 from soc.fu.alu.pipeline import ALUBasePipe
10 from soc.fu.alu.pipe_data import ALUPipeSpec
11
12 from soc.fu.cr.pipeline import CRBasePipe
13 from soc.fu.cr.pipe_data import CRPipeSpec
14
15
16 class FunctionUnitBaseSingle(MultiCompUnit):
17 """FunctionUnitBaseSingle
18
19 main "glue" class that brings everything together.
20 ONLY use this class for single-stage pipelines.
21
22 * :speckls: - the specification. contains regspec and op subset info,
23 and contains common "stuff" like the pipeline ctx,
24 what type of nmutil pipeline base is to be used (etc)
25 * :pipekls: - the type of pipeline. actually connects things together
26
27 note that it is through MultiCompUnit.get_in/out that we *actually*
28 connect up the association between regspec variable names (defined
29 in the pipe_data).
30 """
31 def __init__(self, speckls, pipekls):
32 pspec = speckls(id_wid=2) # spec (NNNPipeSpec instance)
33 opsubset = pspec.opsubsetkls # get the operand subset class
34 regspec = pspec.regspec # get the regspec
35 alu = pipekls(pspec) # create actual NNNBasePipe
36 super().__init__(regspec, alu, opsubset) # pass to MultiCompUnit
37
38
39 ######################################################################
40 ###### actual Function Units: these are "single" stage pipelines #####
41
42 class ALUFunctionUnit(FunctionUnitBaseSingle):
43 def __init__(self): super().__init__(ALUPipeSpec, ALUBasePipe)
44
45 class CRFunctionUnit(FunctionUnitBaseSingle):
46 def __init__(self): super().__init__(CRPipeSpec, CRBasePipe)
47
48 #####################################################################
49 ###### actual Function Units: these are "multi" stage pipelines #####
50
51 # TODO: ReservationStations-based.
52
53
54 def tst_single_fus_il():
55 for (name, kls) in (('alu', ALUFunctionUnit),
56 ('cr', CRFunctionUnit)):
57 fu = kls()
58 vl = rtlil.convert(fu, ports=fu.ports())
59 with open("fu_%s.il" % name, "w") as f:
60 f.write(vl)
61
62 if __name__ == '__main__':
63 tst_single_fus_il()