xref: /XiangShan/src/main/scala/xiangshan/backend/Bundles.scala (revision 5d2b9cad647cd0cbcbbe806f2f733d2b9ec0863a)
1package xiangshan.backend
2
3import chipsalliance.rocketchip.config.Parameters
4import chisel3._
5import chisel3.util.BitPat.bitPatToUInt
6import chisel3.util._
7import utils.OptionWrapper
8import xiangshan._
9import xiangshan.backend.datapath.DataConfig._
10import xiangshan.backend.datapath.WbConfig.WbConfig
11import xiangshan.backend.decode.{ImmUnion, XDecode}
12import xiangshan.backend.exu.ExeUnitParams
13import xiangshan.backend.fu.FuType
14import xiangshan.backend.fu.fpu.Bundles.Frm
15import xiangshan.backend.fu.vector.Bundles.{Category, Nf, VConfig, VLmul, VSew, VType, Vl, Vxrm}
16import xiangshan.backend.issue.{IssueBlockParams, IssueQueueDeqRespBundle, IssueQueueJumpBundle, SchedulerType, StatusArrayDeqRespBundle}
17import xiangshan.backend.regfile.{RfReadPortWithConfig, RfWritePortWithConfig}
18import xiangshan.backend.rob.RobPtr
19import xiangshan.frontend._
20import xiangshan.mem.{LqPtr, SqPtr}
21
22object Bundles {
23
24  // frontend -> backend
25  class StaticInst(implicit p: Parameters) extends XSBundle {
26    val instr           = UInt(32.W)
27    val pc              = UInt(VAddrBits.W)
28    val foldpc          = UInt(MemPredPCWidth.W)
29    val exceptionVec    = ExceptionVec()
30    val trigger         = new TriggerCf
31    val preDecodeInfo   = new PreDecodeInfo
32    val pred_taken      = Bool()
33    val crossPageIPFFix = Bool()
34    val ftqPtr          = new FtqPtr
35    val ftqOffset       = UInt(log2Up(PredictWidth).W)
36
37    def connectCtrlFlow(source: CtrlFlow): Unit = {
38      this.instr            := source.instr
39      this.pc               := source.pc
40      this.foldpc           := source.foldpc
41      this.exceptionVec     := source.exceptionVec
42      this.trigger          := source.trigger
43      this.preDecodeInfo    := source.pd
44      this.pred_taken       := source.pred_taken
45      this.crossPageIPFFix  := source.crossPageIPFFix
46      this.ftqPtr           := source.ftqPtr
47      this.ftqOffset        := source.ftqOffset
48    }
49  }
50
51  // StaticInst --[Decode]--> DecodedInst
52  class DecodedInst(implicit p: Parameters) extends XSBundle {
53    def numSrc = backendParams.numSrc
54    // passed from StaticInst
55    val instr           = UInt(32.W)
56    val pc              = UInt(VAddrBits.W)
57    val foldpc          = UInt(MemPredPCWidth.W)
58    val exceptionVec    = ExceptionVec()
59    val trigger         = new TriggerCf
60    val preDecodeInfo   = new PreDecodeInfo
61    val pred_taken      = Bool()
62    val crossPageIPFFix = Bool()
63    val ftqPtr          = new FtqPtr
64    val ftqOffset       = UInt(log2Up(PredictWidth).W)
65    // decoded
66    val srcType       = Vec(numSrc, SrcType())
67    val lsrc          = Vec(numSrc, UInt(6.W))
68    val ldest         = UInt(6.W)
69    val fuType        = FuType()
70    val fuOpType      = FuOpType()
71    val rfWen         = Bool()
72    val fpWen         = Bool()
73    val vecWen        = Bool()
74    val isXSTrap      = Bool()
75    val waitForward   = Bool() // no speculate execution
76    val blockBackward = Bool()
77    val flushPipe     = Bool() // This inst will flush all the pipe when commit, like exception but can commit
78    val selImm        = SelImm()
79    val imm           = UInt(ImmUnion.maxLen.W)
80    val fpu           = new FPUCtrlSignals
81    val vpu           = new VPUCtrlSignals
82    val isMove        = Bool()
83    val uopIdx        = UInt(5.W)
84    val uopSplitType  = UopSplitType()
85    val isVset        = Bool()
86    val firstUop      = Bool()
87    val lastUop       = Bool()
88    val numUops       = UInt(log2Up(MaxUopSize).W) // rob need this
89    val commitType    = CommitType() // Todo: remove it
90
91    private def allSignals = srcType.take(3) ++ Seq(fuType, fuOpType, rfWen, fpWen, vecWen,
92      isXSTrap, waitForward, blockBackward, flushPipe, uopSplitType, selImm)
93
94    def decode(inst: UInt, table: Iterable[(BitPat, List[BitPat])]): DecodedInst = {
95      val decoder: Seq[UInt] = ListLookup(
96        inst, XDecode.decodeDefault.map(bitPatToUInt),
97        table.map{ case (pat, pats) => (pat, pats.map(bitPatToUInt)) }.toArray
98      )
99      allSignals zip decoder foreach { case (s, d) => s := d }
100      this
101    }
102
103    def isSoftPrefetch: Bool = {
104      fuType === FuType.alu.U && fuOpType === ALUOpType.or && selImm === SelImm.IMM_I && ldest === 0.U
105    }
106
107    def connectStaticInst(source: StaticInst): Unit = {
108      for ((name, data) <- this.elements) {
109        if (source.elements.contains(name)) {
110          data := source.elements(name)
111        }
112      }
113    }
114  }
115
116  // DecodedInst --[Rename]--> DynInst
117  class DynInst(implicit p: Parameters) extends XSBundle {
118    def numSrc          = backendParams.numSrc
119    // passed from StaticInst
120    val instr           = UInt(32.W)
121    val pc              = UInt(VAddrBits.W)
122    val foldpc          = UInt(MemPredPCWidth.W)
123    val exceptionVec    = ExceptionVec()
124    val trigger         = new TriggerCf
125    val preDecodeInfo   = new PreDecodeInfo
126    val pred_taken      = Bool()
127    val crossPageIPFFix = Bool()
128    val ftqPtr          = new FtqPtr
129    val ftqOffset       = UInt(log2Up(PredictWidth).W)
130    // passed from DecodedInst
131    val srcType         = Vec(numSrc, SrcType())
132    val lsrc            = Vec(numSrc, UInt(6.W))
133    val ldest           = UInt(6.W)
134    val fuType          = FuType()
135    val fuOpType        = FuOpType()
136    val rfWen           = Bool()
137    val fpWen           = Bool()
138    val vecWen          = Bool()
139    val isXSTrap        = Bool()
140    val waitForward     = Bool() // no speculate execution
141    val blockBackward   = Bool()
142    val flushPipe       = Bool() // This inst will flush all the pipe when commit, like exception but can commit
143    val selImm          = SelImm()
144    val imm             = UInt(XLEN.W) // Todo: check if it need minimized
145    val fpu             = new FPUCtrlSignals
146    val vpu             = new VPUCtrlSignals
147    val isMove          = Bool()
148    val uopIdx          = UInt(5.W)
149    val isVset          = Bool()
150    val firstUop        = Bool()
151    val lastUop         = Bool()
152    val numUops         = UInt(log2Up(MaxUopSize).W) // rob need this
153    val commitType      = CommitType()
154    // rename
155    val srcState        = Vec(numSrc, SrcState())
156    val psrc            = Vec(numSrc, UInt(PhyRegIdxWidth.W))
157    val pdest           = UInt(PhyRegIdxWidth.W)
158    val oldPdest        = UInt(PhyRegIdxWidth.W)
159    val robIdx          = new RobPtr
160
161    val eliminatedMove  = Bool()
162    val debugInfo       = new PerfDebugInfo
163    val storeSetHit     = Bool() // inst has been allocated an store set
164    val waitForRobIdx   = new RobPtr // store set predicted previous store robIdx
165    // Load wait is needed
166    // load inst will not be executed until former store (predicted by mdp) addr calcuated
167    val loadWaitBit     = Bool()
168    // If (loadWaitBit && loadWaitStrict), strict load wait is needed
169    // load inst will not be executed until ALL former store addr calcuated
170    val loadWaitStrict  = Bool()
171    val ssid            = UInt(SSIDWidth.W)
172    // Todo
173    val lqIdx = new LqPtr
174    val sqIdx = new SqPtr
175    // debug module
176    val singleStep      = Bool()
177    // schedule
178    val replayInst      = Bool()
179
180    def isLUI: Bool = this.fuType === FuType.alu.U && this.selImm === SelImm.IMM_U
181    def isWFI: Bool = this.fuType === FuType.csr.U && fuOpType === CSROpType.wfi
182
183    def isSvinvalBegin(flush: Bool) = FuType.isFence(fuType) && fuOpType === FenceOpType.nofence && !flush
184    def isSvinval(flush: Bool) = FuType.isFence(fuType) && fuOpType === FenceOpType.sfence && !flush
185    def isSvinvalEnd(flush: Bool) = FuType.isFence(fuType) && fuOpType === FenceOpType.nofence && flush
186
187    def srcIsReady: Vec[Bool] = {
188      VecInit(this.srcType.zip(this.srcState).map {
189        case (t, s) => SrcType.isNotReg(t) || SrcState.isReady(s)
190      })
191    }
192
193    def clearExceptions(
194      exceptionBits: Seq[Int] = Seq(),
195      flushPipe    : Boolean = false,
196      replayInst   : Boolean = false
197    ): DynInst = {
198      this.exceptionVec.zipWithIndex.filterNot(x => exceptionBits.contains(x._2)).foreach(_._1 := false.B)
199      if (!flushPipe) { this.flushPipe := false.B }
200      if (!replayInst) { this.replayInst := false.B }
201      this
202    }
203
204    def needWriteRf: Bool = (rfWen && ldest =/= 0.U) || fpWen || vecWen
205  }
206
207  trait BundleSource {
208    var wakeupSource = "undefined"
209    var idx = 0
210  }
211
212  class IssueQueueWakeUpBundle(pregIdxWidth: Int, wakeupSourceStr: String, val exuIdx: Int) extends Bundle with BundleSource {
213    val rfWen = Bool()
214    val fpWen = Bool()
215    val vecWen = Bool()
216    val pdest = UInt(pregIdxWidth.W)
217
218    this.wakeupSource = wakeupSourceStr
219
220    def this(pregIdxWidth: Int) = {
221      this(pregIdxWidth, "undefined", -1)
222    }
223
224    def this(wakeupSource: String, backendParam: BackendParams) = {
225      this(backendParam.pregParams.map(_.addrWidth).max, wakeupSource, backendParam.getExuIdx(wakeupSource))
226    }
227
228    /**
229      * @param successor Seq[(psrc, srcType)]
230      * @return Seq[if wakeup psrc]
231      */
232    def wakeUp(successor: Seq[(UInt, UInt)], valid: Bool): Seq[Bool]= {
233      successor.map { case (thatPsrc, srcType) =>
234        val pdestMatch = pdest === thatPsrc
235        pdestMatch && (
236          SrcType.isFp(srcType) && this.fpWen ||
237          SrcType.isXp(srcType) && this.rfWen ||
238          SrcType.isVp(srcType) && this.vecWen
239        ) && valid
240      }
241    }
242
243    def fromExuInput(exuInput: ExuInput): Unit = {
244      this.rfWen := exuInput.rfWen.getOrElse(false.B)
245      this.fpWen := exuInput.fpWen.getOrElse(false.B)
246      this.vecWen := exuInput.vecWen.getOrElse(false.B)
247      this.pdest := exuInput.pdest
248
249      this.wakeupSource = exuInput.params.name
250    }
251  }
252
253  class VPUCtrlSignals(implicit p: Parameters) extends XSBundle {
254    // vtype
255    val vill      = Bool()
256    val vma       = Bool()    // 1: agnostic, 0: undisturbed
257    val vta       = Bool()    // 1: agnostic, 0: undisturbed
258    val vsew      = VSew()
259    val vlmul     = VLmul()   // 1/8~8      --> -3~3
260
261    val vm        = Bool()    // 0: need v0.t
262    val vstart    = Vl()
263
264    // float rounding mode
265    val frm       = Frm()
266    // vector fix int rounding mode
267    val vxrm      = Vxrm()
268    // vector uop index, exclude other non-vector uop
269    val vuopIdx   = UopIdx()
270    // maybe used if data dependancy
271    val vmask     = UInt(MaskSrcData().dataWidth.W)
272    val vl        = Vl()
273
274    // vector load/store
275    val nf        = Nf()
276
277    val needScalaSrc       = Bool()
278    val permImmTruncate    = Bool() // opivi
279
280    val isReverse = Bool() // vrsub, vrdiv
281    val isExt     = Bool()
282    val isNarrow  = Bool()
283    val isDstMask = Bool() // vvm, vvvm, mmm
284    val isMove    = Bool() // vmv.s.x, vmv.v.v, vmv.v.x, vmv.v.i
285
286    def vtype: VType = {
287      val res = Wire(VType())
288      res.illegal := this.vill
289      res.vma     := this.vma
290      res.vta     := this.vta
291      res.vsew    := this.vsew
292      res.vlmul   := this.vlmul
293      res
294    }
295
296    def vconfig: VConfig = {
297      val res = Wire(VConfig())
298      res.vtype := this.vtype
299      res.vl    := this.vl
300      res
301    }
302  }
303
304  // DynInst --[IssueQueue]--> DataPath
305  class IssueQueueIssueBundle(
306    iqParams: IssueBlockParams,
307    exuParams: ExeUnitParams,
308    addrWidth: Int,
309    vaddrBits: Int
310  )(implicit
311    p: Parameters
312  ) extends Bundle {
313    private val rfReadDataCfgSet: Seq[Set[DataConfig]] = exuParams.getRfReadDataCfgSet
314
315    val rf: MixedVec[MixedVec[RfReadPortWithConfig]] = Flipped(MixedVec(
316      rfReadDataCfgSet.map((set: Set[DataConfig]) =>
317        MixedVec(set.map((x: DataConfig) => new RfReadPortWithConfig(x, addrWidth)).toSeq)
318      )
319    ))
320
321    val bypass = new Bundle {
322      val exuOH = Vec(exuParams.numRegSrc, ExuOH())
323    }
324
325    val srcType = Vec(exuParams.numRegSrc, SrcType()) // used to select imm or reg data
326    val immType = SelImm()                         // used to select imm extractor
327    val common = new ExuInput(exuParams)
328    val jmp = if (exuParams.needPc) Some(Flipped(new IssueQueueJumpBundle)) else None
329    val addrOH = UInt(iqParams.numEntries.W)
330
331    def getSource: SchedulerType = exuParams.getWBSource
332    def getIntWbBusyBundle = common.rfWen.toSeq
333    def getVfWbBusyBundle = common.getVfWen.toSeq
334    def getIntRfReadBundle: Seq[RfReadPortWithConfig] = rf.flatten.filter(_.readInt)
335    def getVfRfReadBundle: Seq[RfReadPortWithConfig] = rf.flatten.filter(_.readVf)
336  }
337
338  class OGRespBundle(implicit p:Parameters, params: IssueBlockParams) extends XSBundle {
339    val issueQueueParams = this.params
340    val og0resp = Valid(new StatusArrayDeqRespBundle)
341    val og1resp = Valid(new StatusArrayDeqRespBundle)
342  }
343
344  class fuBusyRespBundle(implicit p: Parameters, params: IssueBlockParams) extends Bundle {
345    val respType = RSFeedbackType() // update credit if needs replay
346    val rfWen = Bool() // TODO: use params to identify IntWB/VfWB
347    val fuType = FuType()
348  }
349
350  class WbFuBusyTableWriteBundle(val params: ExeUnitParams)(implicit p: Parameters) extends XSBundle {
351    private val intCertainLat = params.intLatencyCertain
352    private val vfCertainLat = params.vfLatencyCertain
353    private val intLat = params.intLatencyValMax
354    private val vfLat = params.vfLatencyValMax
355
356    val intWbBusyTable = OptionWrapper(intCertainLat, UInt((intLat + 1).W))
357    val vfWbBusyTable = OptionWrapper(vfCertainLat, UInt((vfLat + 1).W))
358    val intDeqRespSet = OptionWrapper(intCertainLat, UInt((intLat + 1).W))
359    val vfDeqRespSet = OptionWrapper(vfCertainLat, UInt((vfLat + 1).W))
360  }
361
362  class WbFuBusyTableReadBundle(val params: ExeUnitParams)(implicit p: Parameters) extends XSBundle {
363    private val intCertainLat = params.intLatencyCertain
364    private val vfCertainLat = params.vfLatencyCertain
365    private val intLat = params.intLatencyValMax
366    private val vfLat = params.vfLatencyValMax
367
368    val intWbBusyTable = OptionWrapper(intCertainLat, UInt((intLat + 1).W))
369    val vfWbBusyTable = OptionWrapper(vfCertainLat, UInt((vfLat + 1).W))
370  }
371
372  class WbConflictBundle(val params: ExeUnitParams)(implicit p: Parameters) extends XSBundle {
373    private val intCertainLat = params.intLatencyCertain
374    private val vfCertainLat = params.vfLatencyCertain
375
376    val intConflict = OptionWrapper(intCertainLat, Bool())
377    val vfConflict = OptionWrapper(vfCertainLat, Bool())
378  }
379
380  // DataPath --[ExuInput]--> Exu
381  class ExuInput(val params: ExeUnitParams)(implicit p: Parameters) extends XSBundle {
382    val fuType        = FuType()
383    val fuOpType      = FuOpType()
384    val src           = Vec(params.numRegSrc, UInt(params.dataBitsMax.W))
385    val imm           = UInt(XLEN.W)
386    val robIdx        = new RobPtr
387    val iqIdx         = UInt(log2Up(MemIQSizeMax).W)// Only used by store yet
388    val isFirstIssue  = Bool()                      // Only used by store yet
389    val pdest         = UInt(params.wbPregIdxWidth.W)
390    val rfWen         = if (params.writeIntRf)    Some(Bool())                        else None
391    val fpWen         = if (params.writeFpRf)     Some(Bool())                        else None
392    val vecWen        = if (params.writeVecRf)    Some(Bool())                        else None
393    val fpu           = if (params.needFPUCtrl)   Some(new FPUCtrlSignals)            else None
394    val vpu           = if (params.needVPUCtrl)   Some(new VPUCtrlSignals)            else None
395    val flushPipe     = if (params.flushPipe)     Some(Bool())                        else None
396    val pc            = if (params.needPc)        Some(UInt(VAddrData().dataWidth.W)) else None
397    val jalrTarget    = if (params.hasJmpFu)      Some(UInt(VAddrData().dataWidth.W)) else None
398    val preDecode     = if (params.hasPredecode)  Some(new PreDecodeInfo)             else None
399    val ftqIdx        = if (params.needPc || params.replayInst)
400                                                  Some(new FtqPtr)                    else None
401    val ftqOffset     = if (params.needPc || params.replayInst)
402                                                  Some(UInt(log2Up(PredictWidth).W))  else None
403    val predictInfo   = if (params.hasPredecode)  Some(new Bundle {
404      val target = UInt(VAddrData().dataWidth.W)
405      val taken = Bool()
406    }) else None
407    val sqIdx = if (params.hasMemAddrFu || params.hasStdFu) Some(new SqPtr) else None
408    val lqIdx = if (params.hasMemAddrFu) Some(new LqPtr) else None
409    val exuOH = OptionWrapper(params.isIQWakeUpSink, Vec(params.numRegSrc, ExuOH()))
410
411    def getVfWen = {
412      if (params.writeFpRf) this.fpWen
413      else if(params.writeVecRf) this.vecWen
414      else None
415    }
416
417    def fromIssueBundle(source: IssueQueueIssueBundle): Unit = {
418      // src is assigned to rfReadData
419      this.fuType       := source.common.fuType
420      this.fuOpType     := source.common.fuOpType
421      this.imm          := source.common.imm
422      this.robIdx       := source.common.robIdx
423      this.pdest        := source.common.pdest
424      this.isFirstIssue := source.common.isFirstIssue // Only used by mem debug log
425      this.iqIdx        := source.common.iqIdx        // Only used by mem feedback
426      this.rfWen        .foreach(_ := source.common.rfWen.get)
427      this.fpWen        .foreach(_ := source.common.fpWen.get)
428      this.vecWen       .foreach(_ := source.common.vecWen.get)
429      this.fpu          .foreach(_ := source.common.fpu.get)
430      this.vpu          .foreach(_ := source.common.vpu.get)
431      this.flushPipe    .foreach(_ := source.common.flushPipe.get)
432      this.pc           .foreach(_ := source.jmp.get.pc)
433      this.jalrTarget   .foreach(_ := source.jmp.get.target)
434      this.preDecode    .foreach(_ := source.common.preDecode.get)
435      this.ftqIdx       .foreach(_ := source.common.ftqIdx.get)
436      this.ftqOffset    .foreach(_ := source.common.ftqOffset.get)
437      this.predictInfo  .foreach(_ := source.common.predictInfo.get)
438      this.lqIdx        .foreach(_ := source.common.lqIdx.get)
439      this.sqIdx        .foreach(_ := source.common.sqIdx.get)
440      this.exuOH        .foreach(_ := source.common.exuOH.get)
441    }
442  }
443
444  // ExuInput --[FuncUnit]--> ExuOutput
445  class ExuOutput(
446    val params: ExeUnitParams,
447  )(implicit
448    val p: Parameters
449  ) extends Bundle with BundleSource with HasXSParameter {
450    val data         = UInt(params.dataBitsMax.W)
451    val pdest        = UInt(params.wbPregIdxWidth.W)
452    val robIdx       = new RobPtr
453    val intWen       = if (params.writeIntRf)   Some(Bool())                  else None
454    val fpWen        = if (params.writeFpRf)    Some(Bool())                  else None
455    val vecWen       = if (params.writeVecRf)   Some(Bool())                  else None
456    val redirect     = if (params.hasRedirect)  Some(ValidIO(new Redirect))   else None
457    val fflags       = if (params.writeFflags)  Some(UInt(5.W))               else None
458    val vxsat        = if (params.writeVxsat)   Some(Bool())                  else None
459    val exceptionVec = if (params.exceptionOut.nonEmpty) Some(ExceptionVec()) else None
460    val flushPipe    = if (params.flushPipe)    Some(Bool())                  else None
461    val replay       = if (params.replayInst)   Some(Bool())                  else None
462    val lqIdx        = if (params.hasLoadFu)    Some(new LqPtr())             else None
463    val sqIdx        = if (params.hasStoreAddrFu || params.hasStdFu)
464                                                Some(new SqPtr())             else None
465    val ftqIdx       = if (params.needPc || params.replayInst)
466                                                Some(new FtqPtr)                    else None
467    val ftqOffset    = if (params.needPc || params.replayInst)
468                                                Some(UInt(log2Up(PredictWidth).W))  else None
469    // uop info
470    val predecodeInfo = if(params.hasPredecode) Some(new PreDecodeInfo) else None
471    val debug = new DebugBundle
472    val debugInfo = new PerfDebugInfo
473  }
474
475  // ExuOutput + DynInst --> WriteBackBundle
476  class WriteBackBundle(val params: WbConfig)(implicit p: Parameters) extends Bundle with BundleSource {
477    val rfWen = Bool()
478    val fpWen = Bool()
479    val vecWen = Bool()
480    val pdest = UInt(params.pregIdxWidth.W)
481    val data = UInt(params.dataWidth.W)
482    val robIdx = new RobPtr()(p)
483    val flushPipe = Bool()
484    val replayInst = Bool()
485    val redirect = ValidIO(new Redirect)
486    val fflags = UInt(5.W)
487    val vxsat = Bool()
488    val exceptionVec = ExceptionVec()
489    val debug = new DebugBundle
490    val debugInfo = new PerfDebugInfo
491
492    this.wakeupSource = s"WB(${params.toString})"
493
494    def fromExuOutput(source: ExuOutput) = {
495      this.rfWen  := source.intWen.getOrElse(false.B)
496      this.fpWen  := source.fpWen.getOrElse(false.B)
497      this.vecWen := source.vecWen.getOrElse(false.B)
498      this.pdest  := source.pdest
499      this.data   := source.data
500      this.robIdx := source.robIdx
501      this.flushPipe := source.flushPipe.getOrElse(false.B)
502      this.replayInst := source.replay.getOrElse(false.B)
503      this.redirect := source.redirect.getOrElse(0.U.asTypeOf(this.redirect))
504      this.fflags := source.fflags.getOrElse(0.U.asTypeOf(this.fflags))
505      this.vxsat := source.vxsat.getOrElse(0.U.asTypeOf(this.vxsat))
506      this.exceptionVec := source.exceptionVec.getOrElse(0.U.asTypeOf(this.exceptionVec))
507      this.debug := source.debug
508      this.debugInfo := source.debugInfo
509    }
510
511    def asIntRfWriteBundle(fire: Bool): RfWritePortWithConfig = {
512      val rfWrite = Wire(Output(new RfWritePortWithConfig(this.params.dataCfg, this.params.pregIdxWidth)))
513      rfWrite.wen := this.rfWen && fire
514      rfWrite.addr := this.pdest
515      rfWrite.data := this.data
516      rfWrite.intWen := this.rfWen
517      rfWrite.fpWen := false.B
518      rfWrite.vecWen := false.B
519      rfWrite
520    }
521
522    def asVfRfWriteBundle(fire: Bool): RfWritePortWithConfig = {
523      val rfWrite = Wire(Output(new RfWritePortWithConfig(this.params.dataCfg, this.params.pregIdxWidth)))
524      rfWrite.wen := (this.fpWen || this.vecWen) && fire
525      rfWrite.addr := this.pdest
526      rfWrite.data := this.data
527      rfWrite.intWen := false.B
528      rfWrite.fpWen := this.fpWen
529      rfWrite.vecWen := this.vecWen
530      rfWrite
531    }
532  }
533
534  // ExuOutput --> ExuBypassBundle --[DataPath]-->ExuInput
535  //                                /
536  //     [IssueQueue]--> ExuInput --
537  class ExuBypassBundle(
538    val params: ExeUnitParams,
539  )(implicit
540    val p: Parameters
541  ) extends Bundle {
542    val data  = UInt(params.dataBitsMax.W)
543    val pdest = UInt(params.wbPregIdxWidth.W)
544  }
545
546  class ExceptionInfo extends Bundle {
547    val pc = UInt(VAddrData().dataWidth.W)
548    val instr = UInt(32.W)
549    val commitType = CommitType()
550    val exceptionVec = ExceptionVec()
551    val singleStep = Bool()
552    val crossPageIPFFix = Bool()
553    val isInterrupt = Bool()
554  }
555
556  object UopIdx {
557    def apply()(implicit p: Parameters): UInt = UInt(log2Up(p(XSCoreParamsKey).MaxUopSize + 1).W)
558  }
559
560  object FuLatency {
561    def apply(): UInt = UInt(width.W)
562
563    def width = 4 // 0~15 // Todo: assosiate it with FuConfig
564  }
565
566  object ExuOH {
567    def apply(exuNum: Int): Vec[Bool] = Vec(exuNum, Bool())
568
569    def apply()(implicit p: Parameters): Vec[Bool] = Vec(width, Bool())
570
571    def width(implicit p: Parameters): Int = p(XSCoreParamsKey).backendParams.numExu
572  }
573
574  class MemExuInput(isVector: Boolean = false)(implicit p: Parameters) extends XSBundle {
575    val uop = new DynInst
576    val src = if (isVector) Vec(5, UInt(VLEN.W)) else Vec(3, UInt(XLEN.W))
577    val iqIdx = UInt(log2Up(MemIQSizeMax).W)
578    val isFirstIssue = Bool()
579  }
580
581  class MemExuOutput(isVector: Boolean = false)(implicit p: Parameters) extends XSBundle {
582    val uop = new DynInst
583    val data = if (isVector) UInt(VLEN.W) else UInt(XLEN.W)
584    val debug = new DebugBundle
585  }
586
587  class MemMicroOpRbExt(implicit p: Parameters) extends XSBundle {
588    val uop = new DynInst
589    val flag = UInt(1.W)
590  }
591}
592