xref: /XiangShan/src/main/scala/xiangshan/Bundle.scala (revision 7695ca79d0e41b29295cf96154f3d9987ea22cfc)
1package xiangshan
2
3import chisel3._
4import chisel3.util._
5import bus.simplebus._
6import xiangshan.backend.brq.BrqPtr
7import xiangshan.backend.rename.FreeListPtr
8import xiangshan.frontend.PreDecodeInfo
9
10// Fetch FetchWidth x 32-bit insts from Icache
11class FetchPacket extends XSBundle {
12  val instrs = Vec(PredictWidth, UInt(32.W))
13  val mask = UInt(PredictWidth.W)
14  // val pc = UInt(VAddrBits.W)
15  val pc = Vec(PredictWidth, UInt(VAddrBits.W))
16  val pnpc = Vec(PredictWidth, UInt(VAddrBits.W))
17  val brInfo = Vec(PredictWidth, new BranchInfo)
18  val pd = Vec(PredictWidth, new PreDecodeInfo)
19}
20
21class ValidUndirectioned[T <: Data](gen: T) extends Bundle {
22  val valid = Bool()
23  val bits = gen.cloneType.asInstanceOf[T]
24  override def cloneType = new ValidUndirectioned(gen).asInstanceOf[this.type]
25}
26
27object ValidUndirectioned {
28  def apply[T <: Data](gen: T) = {
29    new ValidUndirectioned[T](gen)
30  }
31}
32
33class TageMeta extends XSBundle {
34  def TageNTables = 6
35  val provider = ValidUndirectioned(UInt(log2Ceil(TageNTables).W))
36  val altDiffers = Bool()
37  val providerU = UInt(2.W)
38  val providerCtr = UInt(3.W)
39  val allocate = ValidUndirectioned(UInt(log2Ceil(TageNTables).W))
40}
41
42class BranchPrediction extends XSBundle {
43  val redirect = Bool()
44  val taken = Bool()
45  val jmpIdx = UInt(log2Up(PredictWidth).W)
46  val hasNotTakenBrs = Bool()
47  val target = UInt(VAddrBits.W)
48  val saveHalfRVI = Bool()
49}
50
51class BranchInfo extends XSBundle {
52  val ubtbWriteWay = UInt(log2Up(UBtbWays).W)
53  val ubtbHits = Bool()
54  val btbWriteWay = UInt(log2Up(BtbWays).W)
55  val bimCtr = UInt(2.W)
56  val histPtr = UInt(log2Up(ExtHistoryLength).W)
57  val tageMeta = new TageMeta
58  val rasSp = UInt(log2Up(RasSize).W)
59  val rasTopCtr = UInt(8.W)
60
61  def apply(histPtr: UInt, tageMeta: TageMeta, rasSp: UInt, rasTopCtr: UInt) = {
62    this.histPtr := histPtr
63    this.tageMeta := tageMeta
64    this.rasSp := rasSp
65    this.rasTopCtr := rasTopCtr
66    this.asUInt
67  }
68  def size = 0.U.asTypeOf(this).getWidth
69  def fromUInt(x: UInt) = x.asTypeOf(this)
70}
71
72class Predecode extends XSBundle {
73  val mask = UInt((FetchWidth*2).W)
74  val pd = Vec(FetchWidth*2, (new PreDecodeInfo))
75}
76
77class BranchUpdateInfo extends XSBundle {
78  // from backend
79  val pc = UInt(VAddrBits.W)
80  val pnpc = UInt(VAddrBits.W)
81  val target = UInt(VAddrBits.W)
82  val brTarget = UInt(VAddrBits.W)
83  val taken = Bool()
84  val fetchIdx = UInt(log2Up(FetchWidth*2).W)
85  val isMisPred = Bool()
86
87  // frontend -> backend -> frontend
88  val pd = new PreDecodeInfo
89  val brInfo = new BranchInfo
90}
91
92// Dequeue DecodeWidth insts from Ibuffer
93class CtrlFlow extends XSBundle {
94  val instr = UInt(32.W)
95  val pc = UInt(VAddrBits.W)
96  val exceptionVec = Vec(16, Bool())
97  val intrVec = Vec(12, Bool())
98  val brUpdate = new BranchUpdateInfo
99  val crossPageIPFFix = Bool()
100}
101
102// Decode DecodeWidth insts at Decode Stage
103class CtrlSignals extends XSBundle {
104  val src1Type, src2Type, src3Type = SrcType()
105  val lsrc1, lsrc2, lsrc3 = UInt(5.W)
106  val ldest = UInt(5.W)
107  val fuType = FuType()
108  val fuOpType = FuOpType()
109  val rfWen = Bool()
110  val fpWen = Bool()
111  val isXSTrap = Bool()
112  val noSpecExec = Bool()  // This inst can not be speculated
113  val isBlocked  = Bool()  // This inst requires pipeline to be blocked
114  val isRVF = Bool()
115  val imm = UInt(XLEN.W)
116  val commitType = CommitType()
117}
118
119class CfCtrl extends XSBundle {
120  val cf = new CtrlFlow
121  val ctrl = new CtrlSignals
122  val brTag = new BrqPtr
123}
124
125trait HasRoqIdx { this: HasXSParameter =>
126  val roqIdx = UInt(RoqIdxWidth.W)
127
128  def isAfter(thatIdx: UInt): Bool = {
129    Mux(
130      this.roqIdx.head(1) === thatIdx.head(1),
131      this.roqIdx.tail(1) > thatIdx.tail(1),
132      this.roqIdx.tail(1) < thatIdx.tail(1)
133    )
134  }
135
136  def isAfter[ T<: HasRoqIdx ](that: T): Bool = {
137    isAfter(that.roqIdx)
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 lsroqIdx = UInt(LsroqIdxWidth.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 ReplayPregReq extends XSBundle {
168  // NOTE: set isInt and isFp both to 'false' when invalid
169  val isInt = Bool()
170  val isFp = Bool()
171  val preg = UInt(PhyRegIdxWidth.W)
172}
173
174class DebugBundle extends XSBundle{
175  val isMMIO = Bool()
176}
177
178class ExuInput extends XSBundle {
179  val uop = new MicroOp
180  val src1, src2, src3 = UInt(XLEN.W)
181}
182
183class ExuOutput extends XSBundle {
184  val uop = new MicroOp
185  val data = UInt(XLEN.W)
186  val redirectValid = Bool()
187  val redirect = new Redirect
188  val brUpdate = new BranchUpdateInfo
189  val debug = new DebugBundle
190}
191
192class ExuIO extends XSBundle {
193  val in = Flipped(DecoupledIO(new ExuInput))
194  val redirect = Flipped(ValidIO(new Redirect))
195  val out = DecoupledIO(new ExuOutput)
196  // for csr
197  val exception = Flipped(ValidIO(new MicroOp))
198  // for Lsu
199  val dmem = new SimpleBusUC
200  val mcommit = Input(UInt(3.W))
201}
202
203class RoqCommit extends XSBundle {
204  val uop = new MicroOp
205  val isWalk = Bool()
206}
207
208class TlbFeedback extends XSBundle with HasRoqIdx{
209  val hit = Bool()
210}
211
212class FrontendToBackendIO extends XSBundle {
213  // to backend end
214  val cfVec = Vec(DecodeWidth, DecoupledIO(new CtrlFlow))
215  // from backend
216  val redirect = Flipped(ValidIO(new Redirect))
217  val outOfOrderBrInfo = Flipped(ValidIO(new BranchUpdateInfo))
218  val inOrderBrInfo = Flipped(ValidIO(new BranchUpdateInfo))
219}
220