xref: /XiangShan/src/main/scala/xiangshan/Bundle.scala (revision 2a4985ebca2f8bacfeb39c1a7b4fb30295f1052b)
1package xiangshan
2
3import chisel3._
4import chisel3.util._
5import bus.simplebus._
6import xiangshan.backend.brq.BrqPtr
7import xiangshan.backend.rename.FreeListPtr
8
9// Fetch FetchWidth x 32-bit insts from Icache
10class FetchPacket extends XSBundle {
11  val instrs = Vec(FetchWidth, UInt(32.W))
12  val mask = UInt((FetchWidth*2).W)
13  val pc = UInt(VAddrBits.W) // the pc of first inst in the fetch group
14  val pnpc = Vec(FetchWidth*2, UInt(VAddrBits.W))
15  val hist = Vec(FetchWidth*2, UInt(HistoryLength.W))
16  // val btbVictimWay = UInt(log2Up(BtbWays).W)
17  val predCtr = Vec(FetchWidth*2, UInt(2.W))
18  val btbHit = Vec(FetchWidth*2, Bool())
19  val tageMeta = Vec(FetchWidth*2, (new TageMeta))
20  val rasSp = UInt(log2Up(RasSize).W)
21  val rasTopCtr = UInt(8.W)
22}
23
24
25class ValidUndirectioned[T <: Data](gen: T) extends Bundle {
26  val valid = Bool()
27  val bits = gen.asInstanceOf[T]
28  override def cloneType = new ValidUndirectioned(gen).asInstanceOf[this.type]
29}
30
31object ValidUndirectioned {
32  def apply[T <: Data](gen: T) = {
33    new ValidUndirectioned[T](gen)
34  }
35}
36
37class TageMeta extends XSBundle {
38//  val provider = ValidUndirectioned(UInt(log2Ceil(TageNTables).W))
39  val altDiffers = Bool()
40  val providerU = UInt(2.W)
41  val providerCtr = UInt(3.W)
42//  val allocate = ValidUndirectioned(UInt(log2Ceil(TageNTables).W))
43}
44
45// Branch prediction result from BPU Stage1 & 3
46class BranchPrediction extends XSBundle {
47  val redirect = Bool()
48
49  // mask off all the instrs after the first redirect instr
50  val instrValid = Vec(FetchWidth*2, Bool())
51  // target of the first redirect instr in a fetch package
52  val target = UInt(VAddrBits.W)
53  val lateJump = Bool()
54  // save these info in brq!
55  // global history of each valid(or uncancelled) instruction, excluding branch's own prediction result
56  val hist = Vec(FetchWidth*2, UInt(HistoryLength.W))
57  // victim way when updating btb
58  // val btbVictimWay = UInt(log2Up(BtbWays).W)
59  // 2-bit saturated counter
60  val predCtr = Vec(FetchWidth*2, UInt(2.W))
61  val btbHit = Vec(FetchWidth*2, Bool())
62  // tage meta info
63  val tageMeta = Vec(FetchWidth*2, (new TageMeta))
64  // ras checkpoint, only used in Stage3
65  val rasSp = UInt(log2Up(RasSize).W)
66  val rasTopCtr = UInt(8.W)
67}
68
69// Save predecode info in icache
70class Predecode extends XSBundle {
71  val mask = UInt((FetchWidth*2).W)
72  val isRVC = Vec(FetchWidth*2, Bool())
73  val fuTypes = Vec(FetchWidth*2, FuType())
74  val fuOpTypes = Vec(FetchWidth*2, FuOpType())
75}
76
77
78class BranchUpdateInfo extends XSBundle {
79  val fetchOffset = UInt(log2Up(FetchWidth * 4).W)
80  val pnpc = UInt(VAddrBits.W)
81  val brTarget = UInt(VAddrBits.W)
82  val hist = UInt(HistoryLength.W)
83  val btbPredCtr = UInt(2.W)
84  val btbHit = Bool()
85  val tageMeta = new TageMeta
86  val rasSp = UInt(log2Up(RasSize).W)
87  val rasTopCtr = UInt(8.W)
88  val taken = Bool()
89  val fetchIdx = UInt(log2Up(FetchWidth*2).W)
90  val btbType = UInt(2.W)
91  val isRVC = Bool()
92  val isBr = Bool()
93  val isMisPred = Bool()
94}
95
96// Dequeue DecodeWidth insts from Ibuffer
97class CtrlFlow extends XSBundle {
98  val instr = UInt(32.W)
99  val pc = UInt(VAddrBits.W)
100  val exceptionVec = Vec(16, Bool())
101  val intrVec = Vec(12, Bool())
102  val brUpdate = new BranchUpdateInfo
103  val crossPageIPFFix = Bool()
104}
105
106// Decode DecodeWidth insts at Decode Stage
107class CtrlSignals extends XSBundle {
108  val src1Type, src2Type, src3Type = SrcType()
109  val lsrc1, lsrc2, lsrc3 = UInt(5.W)
110  val ldest = UInt(5.W)
111  val fuType = FuType()
112  val fuOpType = FuOpType()
113  val rfWen = Bool()
114  val fpWen = Bool()
115  val isXSTrap = Bool()
116  val noSpecExec = Bool()  // This inst can not be speculated
117  val isBlocked  = Bool()  // This inst requires pipeline to be blocked
118  val isRVF = Bool()
119  val imm = UInt(XLEN.W)
120  val dpqType = DPQType()
121}
122
123class CfCtrl extends XSBundle {
124  val cf = new CtrlFlow
125  val ctrl = new CtrlSignals
126  val brTag = new BrqPtr
127}
128
129trait HasRoqIdx { this: HasXSParameter =>
130  val roqIdx = UInt(RoqIdxWidth.W)
131
132  def isAfter(thatIdx: UInt): Bool = {
133    Mux(
134      this.roqIdx.head(1) === thatIdx.head(1),
135      this.roqIdx.tail(1) > thatIdx.tail(1),
136      this.roqIdx.tail(1) < thatIdx.tail(1)
137    )
138  }
139
140  def needFlush(redirect: Valid[Redirect]): Bool = {
141    redirect.valid && this.isAfter(redirect.bits.roqIdx)
142  }
143}
144
145// CfCtrl -> MicroOp at Rename Stage
146class MicroOp extends CfCtrl with HasRoqIdx {
147  val psrc1, psrc2, psrc3, pdest, old_pdest = UInt(PhyRegIdxWidth.W)
148  val src1State, src2State, src3State = SrcState()
149  val moqIdx = UInt(MoqIdxWidth.W)
150}
151
152class Redirect extends XSBundle with HasRoqIdx {
153  val isException = Bool()
154  val isMisPred = Bool()
155  val isReplay = Bool()
156  val pc = UInt(VAddrBits.W)
157  val target = UInt(VAddrBits.W)
158  val brTag = new BrqPtr
159}
160
161class Dp1ToDp2IO extends XSBundle {
162  val intDqToDp2 = Vec(dpParams.IntDqDeqWidth, DecoupledIO(new MicroOp))
163  val fpDqToDp2 = Vec(dpParams.FpDqDeqWidth, DecoupledIO(new MicroOp))
164  val lsDqToDp2 = Vec(dpParams.LsDqDeqWidth, DecoupledIO(new MicroOp))
165}
166
167class DebugBundle extends XSBundle{
168  val isMMIO = Bool()
169}
170
171class ExuInput extends XSBundle {
172  val uop = new MicroOp
173  val src1, src2, src3 = UInt(XLEN.W)
174}
175
176class ExuOutput extends XSBundle {
177  val uop = new MicroOp
178  val data = UInt(XLEN.W)
179  val redirectValid = Bool()
180  val redirect = new Redirect
181  val brUpdate = new BranchUpdateInfo
182  val debug = new DebugBundle
183}
184
185class ExuIO extends XSBundle {
186  val in = Flipped(DecoupledIO(new ExuInput))
187  val redirect = Flipped(ValidIO(new Redirect))
188  val out = DecoupledIO(new ExuOutput)
189  // for csr
190  val exception = Flipped(ValidIO(new MicroOp))
191  // for Lsu
192  val dmem = new SimpleBusUC
193  val mcommit = Input(UInt(3.W))
194}
195
196class RoqCommit extends XSBundle {
197  val uop = new MicroOp
198  val isWalk = Bool()
199}
200
201class TlbFeedback extends XSBundle with HasRoqIdx{
202  val hit = Bool()
203}
204
205class FrontendToBackendIO extends XSBundle {
206  // to backend end
207  val cfVec = Vec(DecodeWidth, DecoupledIO(new CtrlFlow))
208  // from backend
209  val redirect = Flipped(ValidIO(new Redirect))
210  val outOfOrderBrInfo = Flipped(ValidIO(new BranchUpdateInfo))
211  val inOrderBrInfo = Flipped(ValidIO(new BranchUpdateInfo))
212}
213