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