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