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