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