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