rename regspecs to give a consistent naming scheme
[soc.git] / src / soc / fu / branch / pipe_data.py
1 """
2 Optional Register allocation listed below. mandatory input
3 (CompBROpSubset, CIA) not included.
4
5 * CR is Condition Register (not an SPR)
6 * SPR1 and SPR2 are all from the SPR regfile. 2 ports are needed
7
8 insn CR SPR2 SPR1
9 ---- -- ---- ----
10 op_b xx xx xx
11 op_ba xx xx xx
12 op_bl xx xx xx
13 op_bla xx xx xx
14 op_bc CR, xx, CTR
15 op_bca CR, xx, CTR
16 op_bcl CR, xx, CTR
17 op_bcla CR, xx, CTR
18 op_bclr CR, LR, CTR
19 op_bclrl CR, LR, CTR
20 op_bcctr CR, xx, CTR
21 op_bcctrl CR, xx, CTR
22 op_bctar CR, TAR, CTR
23 op_bctarl CR, TAR, CTR
24 """
25
26 from nmigen import Signal, Const, Cat
27 from ieee754.fpcommon.getop import FPPipeContext
28 from soc.decoder.power_decoder2 import Data
29 from soc.fu.pipe_data import IntegerData, CommonPipeSpec
30 from soc.fu.branch.br_input_record import CompBROpSubset # TODO: replace
31
32
33 class BranchInputData(IntegerData):
34 regspec = [('SPR', 'spr1', '0:63'),
35 ('SPR', 'spr2', '0:63'),
36 ('CR', 'cr_a', '0:3'),
37 ('FAST', 'cia', '0:63')]
38 def __init__(self, pspec):
39 super().__init__(pspec)
40 # Note: for OP_BCREG, SPR1 will either be CTR, LR, or TAR
41 # this involves the *decode* unit selecting the register, based
42 # on detecting the operand being bcctr, bclr or bctar
43
44 self.spr1 = Signal(64, reset_less=True) # see table above, SPR1
45 self.spr2 = Signal(64, reset_less=True) # see table above, SPR2
46 self.cr_a = Signal(4, reset_less=True) # Condition Register(s) CR0-7
47 self.cia = Signal(64, reset_less=True) # Current Instruction Address
48
49 # convenience variables. not all of these are used at once
50 self.ctr = self.srr0 = self.hsrr0 = self.spr1
51 self.lr = self.tar = self.srr1 = self.hsrr1 = self.spr2
52 self.cr = self.cr_a
53
54 def __iter__(self):
55 yield from super().__iter__()
56 yield self.spr1
57 yield self.spr2
58 yield self.cr_a
59 yield self.cia
60
61 def eq(self, i):
62 lst = super().eq(i)
63 return lst + [self.spr1.eq(i.spr1), self.spr2.eq(i.spr2),
64 self.cr_a.eq(i.cr_a), self.cia.eq(i.cia)]
65
66
67 class BranchOutputData(IntegerData):
68 regspec = [('SPR', 'spr1', '0:63'),
69 ('SPR', 'spr2', '0:63'),
70 ('FAST', 'nia', '0:63')]
71 def __init__(self, pspec):
72 super().__init__(pspec)
73 self.spr1 = Data(64, name="spr1")
74 self.spr2 = Data(64, name="spr2")
75 self.nia = Data(64, name="nia")
76
77 # convenience variables.
78 self.ctr = self.spr1
79 self.lr = self.tar = self.spr2
80
81 def __iter__(self):
82 yield from super().__iter__()
83 yield from self.spr1
84 yield from self.spr2
85 yield from self.nia
86
87 def eq(self, i):
88 lst = super().eq(i)
89 return lst + [self.spr1.eq(i.spr1), self.spr2.eq(i.spr2),
90 self.nia.eq(i.nia)]
91
92
93 class BranchPipeSpec(CommonPipeSpec):
94 regspec = (BranchInputData.regspec, BranchOutputData.regspec)
95 opsubsetkls = CompBROpSubset
96 def rdflags(self, e): # in order of regspec
97 cr1_en = e.read_cr1.ok # CR A
98 spr1_ok = e.read_spr1.ok # SPR1
99 spr2_ok = e.read_spr2.ok # SPR2
100 return Cat(spr1_ok, spr2_ok, cr1_en, 1) # CIA CR SPR1 SPR2