2772236eb61403fef7f64c894d29031d4b12b4e1
[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 SPR1 SPR2
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
27 from ieee754.fpcommon.getop import FPPipeContext
28 from soc.decoder.power_decoder2 import Data
29 from soc.fu.alu.pipe_data import IntegerData
30
31
32 class BranchInputData(IntegerData):
33 def __init__(self, pspec):
34 super().__init__(pspec)
35 # Note: for OP_BCREG, SPR1 will either be CTR, LR, or TAR
36 # this involves the *decode* unit selecting the register, based
37 # on detecting the operand being bcctr, bclr or bctar
38
39 self.spr1 = Signal(64, reset_less=True) # see table above, SPR1
40 self.spr2 = Signal(64, reset_less=True) # see table above, SPR2
41 self.cr = Signal(32, reset_less=True) # Condition Register(s) CR0-7
42 self.cia = Signal(64, reset_less=True) # Current Instruction Address
43
44 # convenience variables. not all of these are used at once
45 self.ctr = self.srr0 = self.hsrr0 = self.spr2
46 self.lr = self.tar = self.srr1 = self.hsrr1 = self.spr1
47
48 def __iter__(self):
49 yield from super().__iter__()
50 yield self.spr1
51 yield self.spr2
52 yield self.cr
53 yield self.cia
54
55 def eq(self, i):
56 lst = super().eq(i)
57 return lst + [self.spr1.eq(i.spr1), self.spr2.eq(i.spr2),
58 self.cr.eq(i.cr), self.cia.eq(i.cia)]
59
60
61 class BranchOutputData(IntegerData):
62 def __init__(self, pspec):
63 super().__init__(pspec)
64 self.spr1 = Data(64, name="spr1")
65 self.spr2 = Data(64, name="spr2")
66 self.nia = Data(64, name="nia")
67
68 # convenience variables.
69 self.lr = self.tar = self.spr1
70 self.ctr = self.spr2
71
72 def __iter__(self):
73 yield from super().__iter__()
74 yield from self.spr1
75 yield from self.spr2
76 yield from self.nia
77
78 def eq(self, i):
79 lst = super().eq(i)
80 return lst + [self.spr1.eq(i.spr1), self.spr2.eq(i.spr2),
81 self.nia.eq(i.nia)]