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