xref: /XiangShan/src/main/scala/xiangshan/Bundle.scala (revision 249ba4707f41e45288faa494f3ce8483e4611aa7)
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 btbHitJal = Bool()
56  val bimCtr = UInt(2.W)
57  val histPtr = UInt(log2Up(ExtHistoryLength).W)
58  val tageMeta = new TageMeta
59  val rasSp = UInt(log2Up(RasSize).W)
60  val rasTopCtr = UInt(8.W)
61
62  def apply(histPtr: UInt, tageMeta: TageMeta, rasSp: UInt, rasTopCtr: UInt) = {
63    this.histPtr := histPtr
64    this.tageMeta := tageMeta
65    this.rasSp := rasSp
66    this.rasTopCtr := rasTopCtr
67    this.asUInt
68  }
69  def size = 0.U.asTypeOf(this).getWidth
70  def fromUInt(x: UInt) = x.asTypeOf(this)
71}
72
73class Predecode extends XSBundle {
74  val isFetchpcEqualFirstpc = Bool()
75  val mask = UInt((FetchWidth*2).W)
76  val pd = Vec(FetchWidth*2, (new PreDecodeInfo))
77}
78
79class BranchUpdateInfo extends XSBundle {
80  // from backend
81  val pc = UInt(VAddrBits.W)
82  val pnpc = UInt(VAddrBits.W)
83  val target = UInt(VAddrBits.W)
84  val brTarget = UInt(VAddrBits.W)
85  val taken = Bool()
86  val fetchIdx = UInt(log2Up(FetchWidth*2).W)
87  val isMisPred = Bool()
88
89  // frontend -> backend -> frontend
90  val pd = new PreDecodeInfo
91  val brInfo = new BranchInfo
92}
93
94// Dequeue DecodeWidth insts from Ibuffer
95class CtrlFlow extends XSBundle {
96  val instr = UInt(32.W)
97  val pc = UInt(VAddrBits.W)
98  val exceptionVec = Vec(16, Bool())
99  val intrVec = Vec(12, Bool())
100  val brUpdate = new BranchUpdateInfo
101  val crossPageIPFFix = Bool()
102}
103
104// Decode DecodeWidth insts at Decode Stage
105class CtrlSignals extends XSBundle {
106  val src1Type, src2Type, src3Type = SrcType()
107  val lsrc1, lsrc2, lsrc3 = UInt(5.W)
108  val ldest = UInt(5.W)
109  val fuType = FuType()
110  val fuOpType = FuOpType()
111  val rfWen = Bool()
112  val fpWen = Bool()
113  val isXSTrap = Bool()
114  val noSpecExec = Bool()  // This inst can not be speculated
115  val isBlocked  = Bool()  // This inst requires pipeline to be blocked
116  val isRVF = Bool()
117  val imm = UInt(XLEN.W)
118  val commitType = CommitType()
119}
120
121class CfCtrl extends XSBundle {
122  val cf = new CtrlFlow
123  val ctrl = new CtrlSignals
124  val brTag = new BrqPtr
125}
126
127trait HasRoqIdx { this: HasXSParameter =>
128  val roqIdx = UInt(RoqIdxWidth.W)
129
130  def isAfter(thatIdx: UInt): Bool = {
131    Mux(
132      this.roqIdx.head(1) === thatIdx.head(1),
133      this.roqIdx.tail(1) > thatIdx.tail(1),
134      this.roqIdx.tail(1) < thatIdx.tail(1)
135    )
136  }
137
138  def isAfter[ T<: HasRoqIdx ](that: T): Bool = {
139    isAfter(that.roqIdx)
140  }
141
142  def needFlush(redirect: Valid[Redirect]): Bool = {
143    redirect.valid && this.isAfter(redirect.bits.roqIdx)
144  }
145}
146
147// CfCtrl -> MicroOp at Rename Stage
148class MicroOp extends CfCtrl with HasRoqIdx {
149  val psrc1, psrc2, psrc3, pdest, old_pdest = UInt(PhyRegIdxWidth.W)
150  val src1State, src2State, src3State = SrcState()
151  val lsroqIdx = UInt(LsroqIdxWidth.W)
152}
153
154class Redirect extends XSBundle with HasRoqIdx {
155  val isException = Bool()
156  val isMisPred = Bool()
157  val isReplay = Bool()
158  val pc = UInt(VAddrBits.W)
159  val target = UInt(VAddrBits.W)
160  val brTag = new BrqPtr
161}
162
163class Dp1ToDp2IO extends XSBundle {
164  val intDqToDp2 = Vec(dpParams.IntDqDeqWidth, DecoupledIO(new MicroOp))
165  val fpDqToDp2 = Vec(dpParams.FpDqDeqWidth, DecoupledIO(new MicroOp))
166  val lsDqToDp2 = Vec(dpParams.LsDqDeqWidth, DecoupledIO(new MicroOp))
167}
168
169class ReplayPregReq extends XSBundle {
170  // NOTE: set isInt and isFp both to 'false' when invalid
171  val isInt = Bool()
172  val isFp = Bool()
173  val preg = UInt(PhyRegIdxWidth.W)
174}
175
176class DebugBundle extends XSBundle{
177  val isMMIO = Bool()
178}
179
180class ExuInput extends XSBundle {
181  val uop = new MicroOp
182  val src1, src2, src3 = UInt(XLEN.W)
183}
184
185class ExuOutput extends XSBundle {
186  val uop = new MicroOp
187  val data = UInt(XLEN.W)
188  val redirectValid = Bool()
189  val redirect = new Redirect
190  val brUpdate = new BranchUpdateInfo
191  val debug = new DebugBundle
192}
193
194class ExuIO extends XSBundle {
195  val in = Flipped(DecoupledIO(new ExuInput))
196  val redirect = Flipped(ValidIO(new Redirect))
197  val out = DecoupledIO(new ExuOutput)
198  // for csr
199  val exception = Flipped(ValidIO(new MicroOp))
200  // for Lsu
201  val dmem = new SimpleBusUC
202  val mcommit = Input(UInt(3.W))
203}
204
205class RoqCommit extends XSBundle {
206  val uop = new MicroOp
207  val isWalk = Bool()
208}
209
210class TlbFeedback extends XSBundle with HasRoqIdx{
211  val hit = Bool()
212}
213
214class FrontendToBackendIO extends XSBundle {
215  // to backend end
216  val cfVec = Vec(DecodeWidth, DecoupledIO(new CtrlFlow))
217  // from backend
218  val redirect = Flipped(ValidIO(new Redirect))
219  val outOfOrderBrInfo = Flipped(ValidIO(new BranchUpdateInfo))
220  val inOrderBrInfo = Flipped(ValidIO(new BranchUpdateInfo))
221}
222