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