xref: /XiangShan/src/main/scala/xiangshan/backend/rename/Rename.scala (revision 49162c9ab67070931573c1d4a372e2c858a72716)
1c6d43980SLemover/***************************************************************************************
2c6d43980SLemover* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences
3f320e0f0SYinan Xu* Copyright (c) 2020-2021 Peng Cheng Laboratory
4c6d43980SLemover*
5c6d43980SLemover* XiangShan is licensed under Mulan PSL v2.
6c6d43980SLemover* You can use this software according to the terms and conditions of the Mulan PSL v2.
7c6d43980SLemover* You may obtain a copy of Mulan PSL v2 at:
8c6d43980SLemover*          http://license.coscl.org.cn/MulanPSL2
9c6d43980SLemover*
10c6d43980SLemover* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11c6d43980SLemover* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12c6d43980SLemover* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13c6d43980SLemover*
14c6d43980SLemover* See the Mulan PSL v2 for more details.
15c6d43980SLemover***************************************************************************************/
16c6d43980SLemover
175844fcf0SLinJiaweipackage xiangshan.backend.rename
185844fcf0SLinJiawei
198891a219SYinan Xuimport org.chipsalliance.cde.config.Parameters
205844fcf0SLinJiaweiimport chisel3._
215844fcf0SLinJiaweiimport chisel3.util._
223c02ee8fSwakafaimport utility._
233b739f49SXuan Huimport utils._
243b739f49SXuan Huimport xiangshan._
2589cc69c1STang Haojinimport xiangshan.backend.Bundles.{DecodedInst, DynInst}
26765e58c6Ssinsanctionimport xiangshan.backend.decode.{FusionDecodeInfo, ImmUnion, Imm_I, Imm_LUI_LOAD, Imm_U}
27730cfbc0SXuan Huimport xiangshan.backend.fu.FuType
2870224bf6SYinan Xuimport xiangshan.backend.rename.freelist._
29c3f16425Sxiaofeibao-xjtuimport xiangshan.backend.rob.{RobEnqIO, RobPtr}
30980c1bc3SWilliam Wangimport xiangshan.mem.mdp._
318daac0bfSxiaofeibao-xjtuimport xiangshan.ExceptionNO._
32d77cf63cSxiaofeibao-xjtuimport xiangshan.backend.fu.FuType._
33d77cf63cSxiaofeibao-xjtuimport xiangshan.mem.{EewLog2, GenUSWholeEmul}
34d77cf63cSxiaofeibao-xjtuimport xiangshan.mem.GenRealFlowNum
35*49162c9aSGuanghui Chengimport xiangshan.backend.trace._
3699b8dc2cSYinan Xu
37ccfddc82SHaojin Tangclass Rename(implicit p: Parameters) extends XSModule with HasCircularQueuePtrHelper with HasPerfEvents {
38d6f9198fSXuan Hu
39d6f9198fSXuan Hu  // params alias
4098639abbSXuan Hu  private val numRegSrc = backendParams.numRegSrc
41d6f9198fSXuan Hu  private val numVecRegSrc = backendParams.numVecRegSrc
425718c384SHaojin Tang  private val numVecRatPorts = numVecRegSrc
4398639abbSXuan Hu
4498639abbSXuan Hu  println(s"[Rename] numRegSrc: $numRegSrc")
4598639abbSXuan Hu
465844fcf0SLinJiawei  val io = IO(new Bundle() {
475844fcf0SLinJiawei    val redirect = Flipped(ValidIO(new Redirect))
486b102a39SHaojin Tang    val rabCommits = Input(new RabCommitIO)
49a3fe955fSGuanghui Cheng    // from csr
50a3fe955fSGuanghui Cheng    val singleStep = Input(Bool())
517fa2c198SYinan Xu    // from decode
523b739f49SXuan Hu    val in = Vec(RenameWidth, Flipped(DecoupledIO(new DecodedInst)))
53a0db5a4bSYinan Xu    val fusionInfo = Vec(DecodeWidth - 1, Flipped(new FusionDecodeInfo))
54980c1bc3SWilliam Wang    // ssit read result
55980c1bc3SWilliam Wang    val ssit = Flipped(Vec(RenameWidth, Output(new SSITEntry)))
56980c1bc3SWilliam Wang    // waittable read result
57980c1bc3SWilliam Wang    val waittable = Flipped(Vec(RenameWidth, Output(Bool())))
587fa2c198SYinan Xu    // to rename table
595718c384SHaojin Tang    val intReadPorts = Vec(RenameWidth, Vec(2, Input(UInt(PhyRegIdxWidth.W))))
605718c384SHaojin Tang    val fpReadPorts = Vec(RenameWidth, Vec(3, Input(UInt(PhyRegIdxWidth.W))))
61d6f9198fSXuan Hu    val vecReadPorts = Vec(RenameWidth, Vec(numVecRatPorts, Input(UInt(PhyRegIdxWidth.W))))
62368cbcecSxiaofeibao    val v0ReadPorts = Vec(RenameWidth, Vec(1, Input(UInt(PhyRegIdxWidth.W))))
63368cbcecSxiaofeibao    val vlReadPorts = Vec(RenameWidth, Vec(1, Input(UInt(PhyRegIdxWidth.W))))
64ad5c9e6eSJunxiong Ji    val intRenamePorts = Vec(RenameWidth, Output(new RatWritePort(log2Ceil(IntLogicRegs))))
65ad5c9e6eSJunxiong Ji    val fpRenamePorts = Vec(RenameWidth, Output(new RatWritePort(log2Ceil(FpLogicRegs))))
66ad5c9e6eSJunxiong Ji    val vecRenamePorts = Vec(RenameWidth, Output(new RatWritePort(log2Ceil(VecLogicRegs))))
67ad5c9e6eSJunxiong Ji    val v0RenamePorts = Vec(RenameWidth, Output(new RatWritePort(log2Ceil(V0LogicRegs))))
68ad5c9e6eSJunxiong Ji    val vlRenamePorts = Vec(RenameWidth, Output(new RatWritePort(log2Ceil(VlLogicRegs))))
69dcf3a679STang Haojin    // from rename table
70780712aaSxiaofeibao-xjtu    val int_old_pdest = Vec(RabCommitWidth, Input(UInt(PhyRegIdxWidth.W)))
71780712aaSxiaofeibao-xjtu    val fp_old_pdest = Vec(RabCommitWidth, Input(UInt(PhyRegIdxWidth.W)))
72780712aaSxiaofeibao-xjtu    val vec_old_pdest = Vec(RabCommitWidth, Input(UInt(PhyRegIdxWidth.W)))
73368cbcecSxiaofeibao    val v0_old_pdest = Vec(RabCommitWidth, Input(UInt(PhyRegIdxWidth.W)))
74368cbcecSxiaofeibao    val vl_old_pdest = Vec(RabCommitWidth, Input(UInt(PhyRegIdxWidth.W)))
75780712aaSxiaofeibao-xjtu    val int_need_free = Vec(RabCommitWidth, Input(Bool()))
7657c4f8d6SLinJiawei    // to dispatch1
773b739f49SXuan Hu    val out = Vec(RenameWidth, DecoupledIO(new DynInst))
78fa7f2c26STang Haojin    // for snapshots
79fa7f2c26STang Haojin    val snpt = Input(new SnapshotPort)
80c4b56310SHaojin Tang    val snptLastEnq = Flipped(ValidIO(new RobPtr))
81bb7e6e3aSxiaofeibao-xjtu    val snptIsFull= Input(Bool())
82ccfddc82SHaojin Tang    // debug arch ports
83b7d9e8d5Sxiaofeibao-xjtu    val debug_int_rat = if (backendParams.debugEn) Some(Vec(32, Input(UInt(PhyRegIdxWidth.W)))) else None
84b7d9e8d5Sxiaofeibao-xjtu    val debug_fp_rat = if (backendParams.debugEn) Some(Vec(32, Input(UInt(PhyRegIdxWidth.W)))) else None
85368cbcecSxiaofeibao    val debug_vec_rat = if (backendParams.debugEn) Some(Vec(31, Input(UInt(PhyRegIdxWidth.W)))) else None
86d1e473c9Sxiaofeibao    val debug_v0_rat = if (backendParams.debugEn) Some(Vec(1, Input(UInt(PhyRegIdxWidth.W)))) else None
87d1e473c9Sxiaofeibao    val debug_vl_rat = if (backendParams.debugEn) Some(Vec(1, Input(UInt(PhyRegIdxWidth.W)))) else None
88d2b20d1aSTang Haojin    // perf only
89d2b20d1aSTang Haojin    val stallReason = new Bundle {
90d2b20d1aSTang Haojin      val in = Flipped(new StallReasonIO(RenameWidth))
91d2b20d1aSTang Haojin      val out = new StallReasonIO(RenameWidth)
92d2b20d1aSTang Haojin    }
935844fcf0SLinJiawei  })
94b034d3b9SLinJiawei
956374b1d6SXuan Hu  // io alias
966374b1d6SXuan Hu  private val dispatchCanAcc = io.out.head.ready
976374b1d6SXuan Hu
9889cc69c1STang Haojin  val compressUnit = Module(new CompressUnit())
998b8e745dSYikeZhou  // create free list and rat
10039c59369SXuan Hu  val intFreeList = Module(new MEFreeList(IntPhyRegs))
1014eebf274Ssinsanction  val fpFreeList = Module(new StdFreeList(FpPhyRegs - FpLogicRegs, FpLogicRegs, Reg_F))
102d1e473c9Sxiaofeibao  val vecFreeList = Module(new StdFreeList(VfPhyRegs - VecLogicRegs, VecLogicRegs, Reg_V, 31))
103d1e473c9Sxiaofeibao  val v0FreeList = Module(new StdFreeList(V0PhyRegs - V0LogicRegs, V0LogicRegs, Reg_V0, 1))
104d1e473c9Sxiaofeibao  val vlFreeList = Module(new StdFreeList(VlPhyRegs - VlLogicRegs, VlLogicRegs, Reg_Vl, 1))
105368cbcecSxiaofeibao
1068b8e745dSYikeZhou
1076b102a39SHaojin Tang  intFreeList.io.commit    <> io.rabCommits
108b7d9e8d5Sxiaofeibao-xjtu  intFreeList.io.debug_rat.foreach(_ <> io.debug_int_rat.get)
1096b102a39SHaojin Tang  fpFreeList.io.commit     <> io.rabCommits
110b7d9e8d5Sxiaofeibao-xjtu  fpFreeList.io.debug_rat.foreach(_ <> io.debug_fp_rat.get)
1114eebf274Ssinsanction  vecFreeList.io.commit    <> io.rabCommits
1124eebf274Ssinsanction  vecFreeList.io.debug_rat.foreach(_ <> io.debug_vec_rat.get)
113368cbcecSxiaofeibao  v0FreeList.io.commit <> io.rabCommits
114368cbcecSxiaofeibao  v0FreeList.io.debug_rat.foreach(_ <> io.debug_v0_rat.get)
115368cbcecSxiaofeibao  vlFreeList.io.commit <> io.rabCommits
116368cbcecSxiaofeibao  vlFreeList.io.debug_rat.foreach(_ <> io.debug_vl_rat.get)
117ccfddc82SHaojin Tang
1189aca92b9SYinan Xu  // decide if given instruction needs allocating a new physical register (CfCtrl: from decode; RobCommitInfo: from rob)
1193b739f49SXuan Hu  def needDestReg[T <: DecodedInst](reg_t: RegType, x: T): Bool = reg_t match {
1203b739f49SXuan Hu    case Reg_I => x.rfWen && x.ldest =/= 0.U
1213b739f49SXuan Hu    case Reg_F => x.fpWen
1223b739f49SXuan Hu    case Reg_V => x.vecWen
123368cbcecSxiaofeibao    case Reg_V0 => x.v0Wen
124368cbcecSxiaofeibao    case Reg_Vl => x.vlWen
125b034d3b9SLinJiawei  }
1266b102a39SHaojin Tang  def needDestRegCommit[T <: RabCommitInfo](reg_t: RegType, x: T): Bool = {
1273b739f49SXuan Hu    reg_t match {
1283b739f49SXuan Hu      case Reg_I => x.rfWen
1293b739f49SXuan Hu      case Reg_F => x.fpWen
1303b739f49SXuan Hu      case Reg_V => x.vecWen
131368cbcecSxiaofeibao      case Reg_V0 => x.v0Wen
132368cbcecSxiaofeibao      case Reg_Vl => x.vlWen
133fe6452fcSYinan Xu    }
134deb6421eSHaojin Tang  }
1356b102a39SHaojin Tang  def needDestRegWalk[T <: RabCommitInfo](reg_t: RegType, x: T): Bool = {
1363b739f49SXuan Hu    reg_t match {
1373b739f49SXuan Hu      case Reg_I => x.rfWen && x.ldest =/= 0.U
1383b739f49SXuan Hu      case Reg_F => x.fpWen
1393b739f49SXuan Hu      case Reg_V => x.vecWen
140368cbcecSxiaofeibao      case Reg_V0 => x.v0Wen
141368cbcecSxiaofeibao      case Reg_Vl => x.vlWen
1423b739f49SXuan Hu    }
143ccfddc82SHaojin Tang  }
1448b8e745dSYikeZhou
1454eebf274Ssinsanction  // connect [redirect + walk] ports for fp & vec & int free list
146368cbcecSxiaofeibao  Seq(fpFreeList, vecFreeList, intFreeList, v0FreeList, vlFreeList).foreach { case fl =>
14770224bf6SYinan Xu    fl.io.redirect := io.redirect.valid
1486b102a39SHaojin Tang    fl.io.walk := io.rabCommits.isWalk
1494efb89cbSYikeZhou  }
1504eebf274Ssinsanction  // only when all free list and dispatch1 has enough space can we do allocation
151ccfddc82SHaojin Tang  // when isWalk, freelist can definitely allocate
152368cbcecSxiaofeibao  intFreeList.io.doAllocate := fpFreeList.io.canAllocate && vecFreeList.io.canAllocate && v0FreeList.io.canAllocate && vlFreeList.io.canAllocate && dispatchCanAcc || io.rabCommits.isWalk
153368cbcecSxiaofeibao  fpFreeList.io.doAllocate := intFreeList.io.canAllocate && vecFreeList.io.canAllocate && v0FreeList.io.canAllocate && vlFreeList.io.canAllocate && dispatchCanAcc || io.rabCommits.isWalk
154368cbcecSxiaofeibao  vecFreeList.io.doAllocate := intFreeList.io.canAllocate && fpFreeList.io.canAllocate && v0FreeList.io.canAllocate && vlFreeList.io.canAllocate && dispatchCanAcc || io.rabCommits.isWalk
155368cbcecSxiaofeibao  v0FreeList.io.doAllocate := intFreeList.io.canAllocate && fpFreeList.io.canAllocate && vecFreeList.io.canAllocate && vlFreeList.io.canAllocate && dispatchCanAcc || io.rabCommits.isWalk
156368cbcecSxiaofeibao  vlFreeList.io.doAllocate := intFreeList.io.canAllocate && fpFreeList.io.canAllocate && vecFreeList.io.canAllocate && v0FreeList.io.canAllocate && dispatchCanAcc || io.rabCommits.isWalk
1575eb4af5bSYikeZhou
1584eebf274Ssinsanction  //           dispatch1 ready ++ float point free list ready ++ int free list ready ++ vec free list ready     ++ not walk
159368cbcecSxiaofeibao  val canOut = dispatchCanAcc && fpFreeList.io.canAllocate && intFreeList.io.canAllocate && vecFreeList.io.canAllocate && v0FreeList.io.canAllocate && vlFreeList.io.canAllocate && !io.rabCommits.isWalk
1605eb4af5bSYikeZhou
16189cc69c1STang Haojin  compressUnit.io.in.zip(io.in).foreach{ case(sink, source) =>
162a3fe955fSGuanghui Cheng    sink.valid := source.valid && !io.singleStep
16389cc69c1STang Haojin    sink.bits := source.bits
16489cc69c1STang Haojin  }
16589cc69c1STang Haojin  val needRobFlags = compressUnit.io.out.needRobFlags
16689cc69c1STang Haojin  val instrSizesVec = compressUnit.io.out.instrSizes
16789cc69c1STang Haojin  val compressMasksVec = compressUnit.io.out.masks
168b034d3b9SLinJiawei
1699aca92b9SYinan Xu  // speculatively assign the instruction with an robIdx
17089cc69c1STang Haojin  val validCount = PopCount(io.in.zip(needRobFlags).map{ case(in, needRobFlag) => in.valid && in.bits.lastUop && needRobFlag}) // number of instructions waiting to enter rob (from decode)
1719aca92b9SYinan Xu  val robIdxHead = RegInit(0.U.asTypeOf(new RobPtr))
1725f8b6c9eSsinceforYy  val lastCycleMisprediction = GatedValidRegNext(io.redirect.valid && !io.redirect.bits.flushItself())
173f4b2089aSYinan Xu  val robIdxHeadNext = Mux(io.redirect.valid, io.redirect.bits.robIdx, // redirect: move ptr to given rob index
1749aca92b9SYinan Xu         Mux(lastCycleMisprediction, robIdxHead + 1.U, // mis-predict: not flush robIdx itself
175ac78003fSzhanglyGit           Mux(canOut, robIdxHead + validCount, // instructions successfully entered next stage: increase robIdx
176f4b2089aSYinan Xu                      /* default */  robIdxHead))) // no instructions passed by this cycle: stick to old value
1779aca92b9SYinan Xu  robIdxHead := robIdxHeadNext
178588ceab5SYinan Xu
17900ad41d0SYinan Xu  /**
18000ad41d0SYinan Xu    * Rename: allocate free physical register and update rename table
18100ad41d0SYinan Xu    */
1823b739f49SXuan Hu  val uops = Wire(Vec(RenameWidth, new DynInst))
183b034d3b9SLinJiawei  uops.foreach( uop => {
184a7a8a6ccSHaojin Tang    uop.srcState      := DontCare
1857cef916fSYinan Xu    uop.debugInfo     := DontCare
186bc86598fSWilliam Wang    uop.lqIdx         := DontCare
187bc86598fSWilliam Wang    uop.sqIdx         := DontCare
1883b739f49SXuan Hu    uop.waitForRobIdx := DontCare
1893b739f49SXuan Hu    uop.singleStep    := DontCare
190fa7f2c26STang Haojin    uop.snapshot      := DontCare
19113551487SzhanglyGit    uop.srcLoadDependency := DontCare
192f3a9fb05SAnzo    uop.numLsElem       :=  DontCare
1938daac0bfSxiaofeibao-xjtu    uop.hasException  :=  DontCare
194955b4beaSsinsanction    uop.useRegCache   := DontCare
195955b4beaSsinsanction    uop.regCacheIdx   := DontCare
196*49162c9aSGuanghui Cheng    uop.traceBlockInPipe := DontCare
197b034d3b9SLinJiawei  })
198d77cf63cSxiaofeibao-xjtu  private val fuType       = uops.map(_.fuType)
199d77cf63cSxiaofeibao-xjtu  private val fuOpType     = uops.map(_.fuOpType)
200d77cf63cSxiaofeibao-xjtu  private val vtype        = uops.map(_.vpu.vtype)
201d77cf63cSxiaofeibao-xjtu  private val sew          = vtype.map(_.vsew)
202d77cf63cSxiaofeibao-xjtu  private val lmul         = vtype.map(_.vlmul)
203d77cf63cSxiaofeibao-xjtu  private val eew          = uops.map(_.vpu.veew)
204d77cf63cSxiaofeibao-xjtu  private val mop          = fuOpType.map(fuOpTypeItem => LSUOpType.getVecLSMop(fuOpTypeItem))
205d77cf63cSxiaofeibao-xjtu  private val isVlsType    = fuType.map(fuTypeItem => isVls(fuTypeItem))
206d77cf63cSxiaofeibao-xjtu  private val isSegment    = fuType.map(fuTypeItem => isVsegls(fuTypeItem))
207d77cf63cSxiaofeibao-xjtu  private val isUnitStride = fuOpType.map(fuOpTypeItem => LSUOpType.isAllUS(fuOpTypeItem))
208d77cf63cSxiaofeibao-xjtu  private val nf           = fuOpType.zip(uops.map(_.vpu.nf)).map { case (fuOpTypeItem, nfItem) => Mux(LSUOpType.isWhole(fuOpTypeItem), 0.U, nfItem) }
209d77cf63cSxiaofeibao-xjtu  private val mulBits      = 3 // dirty code
210d77cf63cSxiaofeibao-xjtu  private val emul         = fuOpType.zipWithIndex.map { case (fuOpTypeItem, index) =>
211d77cf63cSxiaofeibao-xjtu    Mux(
212d77cf63cSxiaofeibao-xjtu      LSUOpType.isWhole(fuOpTypeItem),
213d77cf63cSxiaofeibao-xjtu      GenUSWholeEmul(nf(index)),
214d77cf63cSxiaofeibao-xjtu      Mux(
215d77cf63cSxiaofeibao-xjtu        LSUOpType.isMasked(fuOpTypeItem),
216d77cf63cSxiaofeibao-xjtu        0.U(mulBits.W),
217d77cf63cSxiaofeibao-xjtu        EewLog2(eew(index)) - sew(index) + lmul(index)
218d77cf63cSxiaofeibao-xjtu      )
219d77cf63cSxiaofeibao-xjtu    )
220d77cf63cSxiaofeibao-xjtu  }
221d77cf63cSxiaofeibao-xjtu  private val isVecUnitType = isVlsType.zip(isUnitStride).map { case (isVlsTypeItme, isUnitStrideItem) =>
222d77cf63cSxiaofeibao-xjtu    isVlsTypeItme && isUnitStrideItem
223d77cf63cSxiaofeibao-xjtu  }
224d77cf63cSxiaofeibao-xjtu  private val instType = isSegment.zip(mop).map { case (isSegementItem, mopItem) => Cat(isSegementItem, mopItem) }
225d77cf63cSxiaofeibao-xjtu  // There is no way to calculate the 'flow' for 'unit-stride' exactly:
226d77cf63cSxiaofeibao-xjtu  //  Whether 'unit-stride' needs to be split can only be known after obtaining the address.
227d77cf63cSxiaofeibao-xjtu  // For scalar instructions, this is not handled here, and different assignments are done later according to the situation.
228d77cf63cSxiaofeibao-xjtu  private val numLsElem = instType.zipWithIndex.map { case (instTypeItem, index) =>
229d77cf63cSxiaofeibao-xjtu    Mux(
230d77cf63cSxiaofeibao-xjtu      isVecUnitType(index),
231d77cf63cSxiaofeibao-xjtu      VecMemUnitStrideMaxFlowNum.U,
232d77cf63cSxiaofeibao-xjtu      GenRealFlowNum(instTypeItem, emul(index), lmul(index), eew(index), sew(index))
233d77cf63cSxiaofeibao-xjtu    )
234d77cf63cSxiaofeibao-xjtu  }
235d77cf63cSxiaofeibao-xjtu  uops.zipWithIndex.map { case(u, i) =>
236d77cf63cSxiaofeibao-xjtu    u.numLsElem := Mux(io.in(i).valid & isVlsType(i), numLsElem(i), 0.U)
237d77cf63cSxiaofeibao-xjtu  }
238b034d3b9SLinJiawei
239deb6421eSHaojin Tang  val needVecDest    = Wire(Vec(RenameWidth, Bool()))
24099b8dc2cSYinan Xu  val needFpDest     = Wire(Vec(RenameWidth, Bool()))
24199b8dc2cSYinan Xu  val needIntDest    = Wire(Vec(RenameWidth, Bool()))
242368cbcecSxiaofeibao  val needV0Dest     = Wire(Vec(RenameWidth, Bool()))
243368cbcecSxiaofeibao  val needVlDest     = Wire(Vec(RenameWidth, Bool()))
244a63155a6SXuan Hu  private val inHeadValid = io.in.head.valid
2458b8e745dSYikeZhou
246c58c2872STang Haojin  val isMove = Wire(Vec(RenameWidth, Bool()))
247c58c2872STang Haojin  isMove zip io.in.map(_.bits) foreach {
248c58c2872STang Haojin    case (move, in) => move := Mux(in.exceptionVec.asUInt.orR, false.B, in.isMove)
249c58c2872STang Haojin  }
2508b8e745dSYikeZhou
251ccfddc82SHaojin Tang  val walkNeedIntDest = WireDefault(VecInit(Seq.fill(RenameWidth)(false.B)))
2523b739f49SXuan Hu  val walkNeedFpDest = WireDefault(VecInit(Seq.fill(RenameWidth)(false.B)))
2533b739f49SXuan Hu  val walkNeedVecDest = WireDefault(VecInit(Seq.fill(RenameWidth)(false.B)))
254368cbcecSxiaofeibao  val walkNeedV0Dest = WireDefault(VecInit(Seq.fill(RenameWidth)(false.B)))
255368cbcecSxiaofeibao  val walkNeedVlDest = WireDefault(VecInit(Seq.fill(RenameWidth)(false.B)))
256ccfddc82SHaojin Tang  val walkIsMove = WireDefault(VecInit(Seq.fill(RenameWidth)(false.B)))
257ccfddc82SHaojin Tang
2588b8e745dSYikeZhou  val intSpecWen = Wire(Vec(RenameWidth, Bool()))
2598b8e745dSYikeZhou  val fpSpecWen  = Wire(Vec(RenameWidth, Bool()))
260deb6421eSHaojin Tang  val vecSpecWen = Wire(Vec(RenameWidth, Bool()))
261368cbcecSxiaofeibao  val v0SpecWen = Wire(Vec(RenameWidth, Bool()))
262368cbcecSxiaofeibao  val vlSpecWen = Wire(Vec(RenameWidth, Bool()))
2638b8e745dSYikeZhou
264ccfddc82SHaojin Tang  val walkIntSpecWen = WireDefault(VecInit(Seq.fill(RenameWidth)(false.B)))
265ccfddc82SHaojin Tang
266ccfddc82SHaojin Tang  val walkPdest = Wire(Vec(RenameWidth, UInt(PhyRegIdxWidth.W)))
267ccfddc82SHaojin Tang
2688b8e745dSYikeZhou  // uop calculation
269b034d3b9SLinJiawei  for (i <- 0 until RenameWidth) {
2700c01a27aSHaojin Tang    (uops(i): Data).waiveAll :<= (io.in(i).bits: Data).waiveAll
271b034d3b9SLinJiawei
272980c1bc3SWilliam Wang    // update cf according to ssit result
2733b739f49SXuan Hu    uops(i).storeSetHit := io.ssit(i).valid
2743b739f49SXuan Hu    uops(i).loadWaitStrict := io.ssit(i).strict && io.ssit(i).valid
2753b739f49SXuan Hu    uops(i).ssid := io.ssit(i).ssid
276980c1bc3SWilliam Wang
277980c1bc3SWilliam Wang    // update cf according to waittable result
2783b739f49SXuan Hu    uops(i).loadWaitBit := io.waittable(i)
279980c1bc3SWilliam Wang
2803b739f49SXuan Hu    uops(i).replayInst := false.B // set by IQ or MemQ
2814eebf274Ssinsanction    // alloc a new phy reg
282368cbcecSxiaofeibao    needV0Dest(i) := io.in(i).valid && needDestReg(Reg_V0, io.in(i).bits)
283368cbcecSxiaofeibao    needVlDest(i) := io.in(i).valid && needDestReg(Reg_Vl, io.in(i).bits)
284ac78003fSzhanglyGit    needVecDest(i) := io.in(i).valid && needDestReg(Reg_V, io.in(i).bits)
285ac78003fSzhanglyGit    needFpDest(i) := io.in(i).valid && needDestReg(Reg_F, io.in(i).bits)
286ac78003fSzhanglyGit    needIntDest(i) := io.in(i).valid && needDestReg(Reg_I, io.in(i).bits)
287780712aaSxiaofeibao-xjtu    if (i < RabCommitWidth) {
2886b102a39SHaojin Tang      walkNeedIntDest(i) := io.rabCommits.walkValid(i) && needDestRegWalk(Reg_I, io.rabCommits.info(i))
2896b102a39SHaojin Tang      walkNeedFpDest(i) := io.rabCommits.walkValid(i) && needDestRegWalk(Reg_F, io.rabCommits.info(i))
2906b102a39SHaojin Tang      walkNeedVecDest(i) := io.rabCommits.walkValid(i) && needDestRegWalk(Reg_V, io.rabCommits.info(i))
291368cbcecSxiaofeibao      walkNeedV0Dest(i) := io.rabCommits.walkValid(i) && needDestRegWalk(Reg_V0, io.rabCommits.info(i))
292368cbcecSxiaofeibao      walkNeedVlDest(i) := io.rabCommits.walkValid(i) && needDestRegWalk(Reg_Vl, io.rabCommits.info(i))
2936b102a39SHaojin Tang      walkIsMove(i) := io.rabCommits.info(i).isMove
294ccfddc82SHaojin Tang    }
2954eebf274Ssinsanction    fpFreeList.io.allocateReq(i) := needFpDest(i)
2964eebf274Ssinsanction    fpFreeList.io.walkReq(i) := walkNeedFpDest(i)
2974eebf274Ssinsanction    vecFreeList.io.allocateReq(i) := needVecDest(i)
2984eebf274Ssinsanction    vecFreeList.io.walkReq(i) := walkNeedVecDest(i)
299368cbcecSxiaofeibao    v0FreeList.io.allocateReq(i) := needV0Dest(i)
300368cbcecSxiaofeibao    v0FreeList.io.walkReq(i) := walkNeedV0Dest(i)
301368cbcecSxiaofeibao    vlFreeList.io.allocateReq(i) := needVlDest(i)
302368cbcecSxiaofeibao    vlFreeList.io.walkReq(i) := walkNeedVlDest(i)
303dcf3a679STang Haojin    intFreeList.io.allocateReq(i) := needIntDest(i) && !isMove(i)
304dcf3a679STang Haojin    intFreeList.io.walkReq(i) := walkNeedIntDest(i) && !walkIsMove(i)
3052438f9ebSYinan Xu
3068b8e745dSYikeZhou    // no valid instruction from decode stage || all resources (dispatch1 + both free lists) ready
3071c6572a6Sxiaofeibao    io.in(i).ready := !io.in(0).valid || canOut
30858e06390SLinJiawei
30989cc69c1STang Haojin    uops(i).robIdx := robIdxHead + PopCount(io.in.zip(needRobFlags).take(i).map{ case(in, needRobFlag) => in.valid && in.bits.lastUop && needRobFlag})
31089cc69c1STang Haojin    uops(i).instrSize := instrSizesVec(i)
3117e0f64b0SGuanghui Cheng    val hasExceptionExceptFlushPipe = Cat(selectFrontend(uops(i).exceptionVec) :+ uops(i).exceptionVec(illegalInstr) :+ uops(i).exceptionVec(virtualInstr)).orR || TriggerAction.isDmode(uops(i).trigger)
312571677c9Sxiaofeibao-xjtu    when(isMove(i) || hasExceptionExceptFlushPipe) {
31389cc69c1STang Haojin      uops(i).numUops := 0.U
3143235a9d8SZiyue-Zhang      uops(i).numWB := 0.U
31589cc69c1STang Haojin    }
31689cc69c1STang Haojin    if (i > 0) {
31789cc69c1STang Haojin      when(!needRobFlags(i - 1)) {
31889cc69c1STang Haojin        uops(i).firstUop := false.B
31989cc69c1STang Haojin        uops(i).ftqPtr := uops(i - 1).ftqPtr
32089cc69c1STang Haojin        uops(i).ftqOffset := uops(i - 1).ftqOffset
32189cc69c1STang Haojin        uops(i).numUops := instrSizesVec(i) - PopCount(compressMasksVec(i) & Cat(isMove.reverse))
3223235a9d8SZiyue-Zhang        uops(i).numWB := instrSizesVec(i) - PopCount(compressMasksVec(i) & Cat(isMove.reverse))
32389cc69c1STang Haojin      }
32489cc69c1STang Haojin    }
32589cc69c1STang Haojin    when(!needRobFlags(i)) {
32689cc69c1STang Haojin      uops(i).lastUop := false.B
32789cc69c1STang Haojin      uops(i).numUops := instrSizesVec(i) - PopCount(compressMasksVec(i) & Cat(isMove.reverse))
3283235a9d8SZiyue-Zhang      uops(i).numWB := instrSizesVec(i) - PopCount(compressMasksVec(i) & Cat(isMove.reverse))
32989cc69c1STang Haojin    }
330f1ba628bSHaojin Tang    uops(i).wfflags := (compressMasksVec(i) & Cat(io.in.map(_.bits.wfflags).reverse)).orR
331f1ba628bSHaojin Tang    uops(i).dirtyFs := (compressMasksVec(i) & Cat(io.in.map(_.bits.fpWen).reverse)).orR
3323af3539fSZiyue Zhang    // vector instructions' uopSplitType cannot be UopSplitType.SCA_SIM
3333af3539fSZiyue Zhang    uops(i).dirtyVs := (compressMasksVec(i) & Cat(io.in.map(_.bits.uopSplitType =/= UopSplitType.SCA_SIM).reverse)).orR
334368cbcecSxiaofeibao    // psrc0,psrc1,psrc2 don't require v0ReadPorts because their srcType can distinguish whether they are V0 or not
335368cbcecSxiaofeibao    uops(i).psrc(0) := Mux1H(uops(i).srcType(0)(2, 0), Seq(io.intReadPorts(i)(0), io.fpReadPorts(i)(0), io.vecReadPorts(i)(0)))
336368cbcecSxiaofeibao    uops(i).psrc(1) := Mux1H(uops(i).srcType(1)(2, 0), Seq(io.intReadPorts(i)(1), io.fpReadPorts(i)(1), io.vecReadPorts(i)(1)))
3373b739f49SXuan Hu    uops(i).psrc(2) := Mux1H(uops(i).srcType(2)(2, 1), Seq(io.fpReadPorts(i)(2), io.vecReadPorts(i)(2)))
338368cbcecSxiaofeibao    uops(i).psrc(3) := io.v0ReadPorts(i)(0)
339368cbcecSxiaofeibao    uops(i).psrc(4) := io.vlReadPorts(i)(0)
340f5710817SXuan Hu
341a0db5a4bSYinan Xu    // int psrc2 should be bypassed from next instruction if it is fused
342a0db5a4bSYinan Xu    if (i < RenameWidth - 1) {
343a0db5a4bSYinan Xu      when (io.fusionInfo(i).rs2FromRs2 || io.fusionInfo(i).rs2FromRs1) {
344a0db5a4bSYinan Xu        uops(i).psrc(1) := Mux(io.fusionInfo(i).rs2FromRs2, io.intReadPorts(i + 1)(1), io.intReadPorts(i + 1)(0))
345a0db5a4bSYinan Xu      }.elsewhen(io.fusionInfo(i).rs2FromZero) {
346a0db5a4bSYinan Xu        uops(i).psrc(1) := 0.U
347a0db5a4bSYinan Xu      }
348a0db5a4bSYinan Xu    }
34970224bf6SYinan Xu    uops(i).eliminatedMove := isMove(i)
3508b8e745dSYikeZhou
3518b8e745dSYikeZhou    // update pdest
352ac78003fSzhanglyGit    uops(i).pdest := MuxCase(0.U, Seq(
353ac78003fSzhanglyGit      needIntDest(i)    ->  intFreeList.io.allocatePhyReg(i),
3544eebf274Ssinsanction      needFpDest(i)     ->  fpFreeList.io.allocatePhyReg(i),
3554eebf274Ssinsanction      needVecDest(i)    ->  vecFreeList.io.allocatePhyReg(i),
356368cbcecSxiaofeibao      needV0Dest(i)    ->  v0FreeList.io.allocatePhyReg(i),
357368cbcecSxiaofeibao      needVlDest(i)    ->  vlFreeList.io.allocatePhyReg(i),
3583b739f49SXuan Hu    ))
3598b8e745dSYikeZhou
360ebb8ebf8SYinan Xu    // Assign performance counters
361ebb8ebf8SYinan Xu    uops(i).debugInfo.renameTime := GTimer()
362ebb8ebf8SYinan Xu
363368cbcecSxiaofeibao    io.out(i).valid := io.in(i).valid && intFreeList.io.canAllocate && fpFreeList.io.canAllocate && vecFreeList.io.canAllocate && v0FreeList.io.canAllocate && vlFreeList.io.canAllocate && !io.rabCommits.isWalk
364ebb8ebf8SYinan Xu    io.out(i).bits := uops(i)
3653b739f49SXuan Hu    // Todo: move these shit in decode stage
366f025d715SYinan Xu    // dirty code for fence. The lsrc is passed by imm.
3673b739f49SXuan Hu    when (io.out(i).bits.fuType === FuType.fence.U) {
3683b739f49SXuan Hu      io.out(i).bits.imm := Cat(io.in(i).bits.lsrc(1), io.in(i).bits.lsrc(0))
369a020ce37SYinan Xu    }
370d91483a6Sfdy
371f025d715SYinan Xu    // dirty code for SoftPrefetch (prefetch.r/prefetch.w)
372621007d9SXuan Hu//    when (io.in(i).bits.isSoftPrefetch) {
373621007d9SXuan Hu//      io.out(i).bits.fuType := FuType.ldu.U
374621007d9SXuan Hu//      io.out(i).bits.fuOpType := Mux(io.in(i).bits.lsrc(1) === 1.U, LSUOpType.prefetch_r, LSUOpType.prefetch_w)
375621007d9SXuan Hu//      io.out(i).bits.selImm := SelImm.IMM_S
376621007d9SXuan Hu//      io.out(i).bits.imm := Cat(io.in(i).bits.imm(io.in(i).bits.imm.getWidth - 1, 5), 0.U(5.W))
377621007d9SXuan Hu//    }
378ebb8ebf8SYinan Xu
379765e58c6Ssinsanction    // dirty code for lui+addi(w) fusion
380765e58c6Ssinsanction    if (i < RenameWidth - 1) {
381765e58c6Ssinsanction      val fused_lui32 = io.in(i).bits.selImm === SelImm.IMM_LUI32 && io.in(i).bits.fuType === FuType.alu.U
382765e58c6Ssinsanction      when (fused_lui32) {
383765e58c6Ssinsanction        val lui_imm = io.in(i).bits.imm(19, 0)
384765e58c6Ssinsanction        val add_imm = io.in(i + 1).bits.imm(11, 0)
38549f433deSXuan Hu        require(io.out(i).bits.imm.getWidth >= lui_imm.getWidth + add_imm.getWidth)
38649f433deSXuan Hu        io.out(i).bits.imm := Cat(lui_imm, add_imm)
387765e58c6Ssinsanction      }
388765e58c6Ssinsanction    }
389765e58c6Ssinsanction
3908b8e745dSYikeZhou    // write speculative rename table
39139d3280eSYikeZhou    // we update rat later inside commit code
3926b102a39SHaojin Tang    intSpecWen(i) := needIntDest(i) && intFreeList.io.canAllocate && intFreeList.io.doAllocate && !io.rabCommits.isWalk && !io.redirect.valid
3936b102a39SHaojin Tang    fpSpecWen(i)  := needFpDest(i)  && fpFreeList.io.canAllocate  && fpFreeList.io.doAllocate  && !io.rabCommits.isWalk && !io.redirect.valid
3944eebf274Ssinsanction    vecSpecWen(i) := needVecDest(i) && vecFreeList.io.canAllocate && vecFreeList.io.doAllocate && !io.rabCommits.isWalk && !io.redirect.valid
395368cbcecSxiaofeibao    v0SpecWen(i) := needV0Dest(i) && v0FreeList.io.canAllocate && v0FreeList.io.doAllocate && !io.rabCommits.isWalk && !io.redirect.valid
396368cbcecSxiaofeibao    vlSpecWen(i) := needVlDest(i) && vlFreeList.io.canAllocate && vlFreeList.io.doAllocate && !io.rabCommits.isWalk && !io.redirect.valid
397ac78003fSzhanglyGit
39870224bf6SYinan Xu
399780712aaSxiaofeibao-xjtu    if (i < RabCommitWidth) {
400ccfddc82SHaojin Tang      walkIntSpecWen(i) := walkNeedIntDest(i) && !io.redirect.valid
4016b102a39SHaojin Tang      walkPdest(i) := io.rabCommits.info(i).pdest
402ccfddc82SHaojin Tang    } else {
403ccfddc82SHaojin Tang      walkPdest(i) := io.out(i).bits.pdest
404ccfddc82SHaojin Tang    }
405b034d3b9SLinJiawei  }
406b034d3b9SLinJiawei
40770224bf6SYinan Xu  /**
408*49162c9aSGuanghui Cheng   * trace begin
409*49162c9aSGuanghui Cheng   */
410*49162c9aSGuanghui Cheng  val inVec = io.in.map(_.bits)
411*49162c9aSGuanghui Cheng  val canRobCompressVec = inVec.map(_.canRobCompress)
412*49162c9aSGuanghui Cheng  val isRVCVec = inVec.map(_.preDecodeInfo.isRVC)
413*49162c9aSGuanghui Cheng  val halfWordNumVec = (0 until RenameWidth).map{
414*49162c9aSGuanghui Cheng    i => compressMasksVec(i).asBools.zip(isRVCVec).map{
415*49162c9aSGuanghui Cheng      case (mask, isRVC) => Mux(mask, Mux(isRVC, 1.U, 2.U), 0.U)
416*49162c9aSGuanghui Cheng    }
417*49162c9aSGuanghui Cheng  }
418*49162c9aSGuanghui Cheng
419*49162c9aSGuanghui Cheng  for (i <- 0 until RenameWidth) {
420*49162c9aSGuanghui Cheng    // iretire
421*49162c9aSGuanghui Cheng    uops(i).traceBlockInPipe.iretire := Mux(canRobCompressVec(i),
422*49162c9aSGuanghui Cheng      halfWordNumVec(i).reduce(_ +& _),
423*49162c9aSGuanghui Cheng      Mux(isRVCVec(i), 1.U, 2.U)
424*49162c9aSGuanghui Cheng    )
425*49162c9aSGuanghui Cheng
426*49162c9aSGuanghui Cheng    // ilastsize
427*49162c9aSGuanghui Cheng    val j = i
428*49162c9aSGuanghui Cheng    val lastIsRVC = WireInit(false.B)
429*49162c9aSGuanghui Cheng    (j until RenameWidth).map { j =>
430*49162c9aSGuanghui Cheng      when(compressMasksVec(i)(j)) {
431*49162c9aSGuanghui Cheng        lastIsRVC := io.in(j).bits.preDecodeInfo.isRVC
432*49162c9aSGuanghui Cheng      }
433*49162c9aSGuanghui Cheng    }
434*49162c9aSGuanghui Cheng
435*49162c9aSGuanghui Cheng    uops(i).traceBlockInPipe.ilastsize := Mux(canRobCompressVec(i),
436*49162c9aSGuanghui Cheng      Mux(lastIsRVC, Ilastsize.HalfWord, Ilastsize.Word),
437*49162c9aSGuanghui Cheng      Mux(isRVCVec(i), Ilastsize.HalfWord, Ilastsize.Word)
438*49162c9aSGuanghui Cheng    )
439*49162c9aSGuanghui Cheng
440*49162c9aSGuanghui Cheng    // itype
441*49162c9aSGuanghui Cheng    uops(i).traceBlockInPipe.itype := Itype.jumpTypeGen(inVec(i).preDecodeInfo.brType, inVec(i).ldest.asTypeOf(new OpRegType), inVec(i).lsrc(0).asTypeOf((new OpRegType)))
442*49162c9aSGuanghui Cheng  }
443*49162c9aSGuanghui Cheng  /**
444*49162c9aSGuanghui Cheng   * trace end
445*49162c9aSGuanghui Cheng   */
446*49162c9aSGuanghui Cheng
447*49162c9aSGuanghui Cheng  /**
44870224bf6SYinan Xu    * How to set psrc:
44970224bf6SYinan Xu    * - bypass the pdest to psrc if previous instructions write to the same ldest as lsrc
45070224bf6SYinan Xu    * - default: psrc from RAT
45170224bf6SYinan Xu    * How to set pdest:
45270224bf6SYinan Xu    * - Mux(isMove, psrc, pdest_from_freelist).
45370224bf6SYinan Xu    *
45470224bf6SYinan Xu    * The critical path of rename lies here:
45570224bf6SYinan Xu    * When move elimination is enabled, we need to update the rat with psrc.
45670224bf6SYinan Xu    * However, psrc maybe comes from previous instructions' pdest, which comes from freelist.
45770224bf6SYinan Xu    *
45870224bf6SYinan Xu    * If we expand these logic for pdest(N):
45970224bf6SYinan Xu    * pdest(N) = Mux(isMove(N), psrc(N), freelist_out(N))
46070224bf6SYinan Xu    *          = Mux(isMove(N), Mux(bypass(N, N - 1), pdest(N - 1),
46170224bf6SYinan Xu    *                           Mux(bypass(N, N - 2), pdest(N - 2),
46270224bf6SYinan Xu    *                           ...
46370224bf6SYinan Xu    *                           Mux(bypass(N, 0),     pdest(0),
46470224bf6SYinan Xu    *                                                 rat_out(N))...)),
46570224bf6SYinan Xu    *                           freelist_out(N))
46670224bf6SYinan Xu    */
46770224bf6SYinan Xu  // a simple functional model for now
46870224bf6SYinan Xu  io.out(0).bits.pdest := Mux(isMove(0), uops(0).psrc.head, uops(0).pdest)
4693b739f49SXuan Hu
4703b739f49SXuan Hu  // psrc(n) + pdest(1)
47198639abbSXuan Hu  val bypassCond: Vec[MixedVec[UInt]] = Wire(Vec(numRegSrc + 1, MixedVec(List.tabulate(RenameWidth-1)(i => UInt((i+1).W)))))
47298639abbSXuan Hu  require(io.in(0).bits.srcType.size == io.in(0).bits.numSrc)
47398639abbSXuan Hu  private val pdestLoc = io.in.head.bits.srcType.size // 2 vector src: v0, vl&vtype
4743b739f49SXuan Hu  println(s"[Rename] idx of pdest in bypassCond $pdestLoc")
47599b8dc2cSYinan Xu  for (i <- 1 until RenameWidth) {
476368cbcecSxiaofeibao    val v0Cond = io.in(i).bits.srcType.zipWithIndex.map{ case (s, i) =>
477368cbcecSxiaofeibao      if (i == 3) (s === SrcType.vp) || (s === SrcType.v0)
478368cbcecSxiaofeibao      else false.B
479368cbcecSxiaofeibao    } :+ needV0Dest(i)
480368cbcecSxiaofeibao    val vlCond = io.in(i).bits.srcType.zipWithIndex.map{ case (s, i) =>
481368cbcecSxiaofeibao      if (i == 4) s === SrcType.vp
482368cbcecSxiaofeibao      else false.B
483368cbcecSxiaofeibao    } :+ needVlDest(i)
48498639abbSXuan Hu    val vecCond = io.in(i).bits.srcType.map(_ === SrcType.vp) :+ needVecDest(i)
48598639abbSXuan Hu    val fpCond  = io.in(i).bits.srcType.map(_ === SrcType.fp) :+ needFpDest(i)
48698639abbSXuan Hu    val intCond = io.in(i).bits.srcType.map(_ === SrcType.xp) :+ needIntDest(i)
48798639abbSXuan Hu    val target = io.in(i).bits.lsrc :+ io.in(i).bits.ldest
488368cbcecSxiaofeibao    for ((((((cond1, (condV0, condVl)), cond2), cond3), t), j) <- vecCond.zip(v0Cond.zip(vlCond)).zip(fpCond).zip(intCond).zip(target).zipWithIndex) {
48970224bf6SYinan Xu      val destToSrc = io.in.take(i).zipWithIndex.map { case (in, j) =>
4903b739f49SXuan Hu        val indexMatch = in.bits.ldest === t
491deb6421eSHaojin Tang        val writeMatch =  cond3 && needIntDest(j) || cond2 && needFpDest(j) || cond1 && needVecDest(j)
492368cbcecSxiaofeibao        val v0vlMatch = condV0 && needV0Dest(j) || condVl && needVlDest(j)
493368cbcecSxiaofeibao        indexMatch && writeMatch || v0vlMatch
49470224bf6SYinan Xu      }
49570224bf6SYinan Xu      bypassCond(j)(i - 1) := VecInit(destToSrc).asUInt
49670224bf6SYinan Xu    }
49770224bf6SYinan Xu    io.out(i).bits.psrc(0) := io.out.take(i).map(_.bits.pdest).zip(bypassCond(0)(i-1).asBools).foldLeft(uops(i).psrc(0)) {
49870224bf6SYinan Xu      (z, next) => Mux(next._2, next._1, z)
49970224bf6SYinan Xu    }
50070224bf6SYinan Xu    io.out(i).bits.psrc(1) := io.out.take(i).map(_.bits.pdest).zip(bypassCond(1)(i-1).asBools).foldLeft(uops(i).psrc(1)) {
50170224bf6SYinan Xu      (z, next) => Mux(next._2, next._1, z)
50270224bf6SYinan Xu    }
50370224bf6SYinan Xu    io.out(i).bits.psrc(2) := io.out.take(i).map(_.bits.pdest).zip(bypassCond(2)(i-1).asBools).foldLeft(uops(i).psrc(2)) {
50470224bf6SYinan Xu      (z, next) => Mux(next._2, next._1, z)
50570224bf6SYinan Xu    }
506a7a8a6ccSHaojin Tang    io.out(i).bits.psrc(3) := io.out.take(i).map(_.bits.pdest).zip(bypassCond(3)(i-1).asBools).foldLeft(uops(i).psrc(3)) {
507a7a8a6ccSHaojin Tang      (z, next) => Mux(next._2, next._1, z)
508a7a8a6ccSHaojin Tang    }
509996aacc9SXuan Hu    io.out(i).bits.psrc(4) := io.out.take(i).map(_.bits.pdest).zip(bypassCond(4)(i-1).asBools).foldLeft(uops(i).psrc(4)) {
5103b739f49SXuan Hu      (z, next) => Mux(next._2, next._1, z)
5113b739f49SXuan Hu    }
51270224bf6SYinan Xu    io.out(i).bits.pdest := Mux(isMove(i), io.out(i).bits.psrc(0), uops(i).pdest)
513fd7603d9SYinan Xu
5143b739f49SXuan Hu    // Todo: better implementation for fields reuse
515fd7603d9SYinan Xu    // For fused-lui-load, load.src(0) is replaced by the imm.
5163b739f49SXuan Hu    val last_is_lui = io.in(i - 1).bits.selImm === SelImm.IMM_U && io.in(i - 1).bits.srcType(0) =/= SrcType.pc
5173b739f49SXuan Hu    val this_is_load = io.in(i).bits.fuType === FuType.ldu.U
5183b739f49SXuan Hu    val lui_to_load = io.in(i - 1).valid && io.in(i - 1).bits.ldest === io.in(i).bits.lsrc(0)
519f4dcd9fcSsinsanction    val fused_lui_load = last_is_lui && this_is_load && lui_to_load
520fd7603d9SYinan Xu    when (fused_lui_load) {
52149f433deSXuan Hu      // The first LOAD operand (base address) is replaced by LUI-imm and stored in imm
52249f433deSXuan Hu      val lui_imm = io.in(i - 1).bits.imm(ImmUnion.U.len - 1, 0)
52349f433deSXuan Hu      val ld_imm = io.in(i).bits.imm(ImmUnion.I.len - 1, 0)
52449f433deSXuan Hu      require(io.out(i).bits.imm.getWidth >= lui_imm.getWidth + ld_imm.getWidth)
5253b739f49SXuan Hu      io.out(i).bits.srcType(0) := SrcType.imm
52649f433deSXuan Hu      io.out(i).bits.imm := Cat(lui_imm, ld_imm)
527fd7603d9SYinan Xu    }
528fd7603d9SYinan Xu
529b034d3b9SLinJiawei  }
53000ad41d0SYinan Xu
531c4b56310SHaojin Tang  val genSnapshot = Cat(io.out.map(out => out.fire && out.bits.snapshot)).orR
532bb7e6e3aSxiaofeibao-xjtu  val lastCycleCreateSnpt = RegInit(false.B)
533bb7e6e3aSxiaofeibao-xjtu  lastCycleCreateSnpt := genSnapshot && !io.snptIsFull
534bb7e6e3aSxiaofeibao-xjtu  val sameSnptDistance = (RobCommitWidth * 4).U
535bb7e6e3aSxiaofeibao-xjtu  // notInSameSnpt: 1.robidxHead - snapLastEnq >= sameSnptDistance 2.no snap
536bb7e6e3aSxiaofeibao-xjtu  val notInSameSnpt = GatedValidRegNext(distanceBetween(robIdxHeadNext, io.snptLastEnq.bits) >= sameSnptDistance || !io.snptLastEnq.valid)
537bb7e6e3aSxiaofeibao-xjtu  val allowSnpt = if (EnableRenameSnapshot) notInSameSnpt && !lastCycleCreateSnpt && io.in.head.bits.firstUop else false.B
538c4b56310SHaojin Tang  io.out.zip(io.in).foreach{ case (out, in) => out.bits.snapshot := allowSnpt && (!in.bits.preDecodeInfo.notCFI || FuType.isJump(in.bits.fuType)) && in.fire }
5398daac0bfSxiaofeibao-xjtu  io.out.map{ x =>
5407e0f64b0SGuanghui Cheng    x.bits.hasException := Cat(selectFrontend(x.bits.exceptionVec) :+ x.bits.exceptionVec(illegalInstr) :+ x.bits.exceptionVec(virtualInstr)).orR || TriggerAction.isDmode(x.bits.trigger)
5418daac0bfSxiaofeibao-xjtu  }
542780712aaSxiaofeibao-xjtu  if(backendParams.debugEn){
543780712aaSxiaofeibao-xjtu    dontTouch(robIdxHeadNext)
544780712aaSxiaofeibao-xjtu    dontTouch(notInSameSnpt)
545780712aaSxiaofeibao-xjtu    dontTouch(genSnapshot)
546fa7f2c26STang Haojin  }
547fa7f2c26STang Haojin  intFreeList.io.snpt := io.snpt
548fa7f2c26STang Haojin  fpFreeList.io.snpt := io.snpt
5494eebf274Ssinsanction  vecFreeList.io.snpt := io.snpt
550368cbcecSxiaofeibao  v0FreeList.io.snpt := io.snpt
551368cbcecSxiaofeibao  vlFreeList.io.snpt := io.snpt
552c4b56310SHaojin Tang  intFreeList.io.snpt.snptEnq := genSnapshot
553c4b56310SHaojin Tang  fpFreeList.io.snpt.snptEnq := genSnapshot
5544eebf274Ssinsanction  vecFreeList.io.snpt.snptEnq := genSnapshot
555368cbcecSxiaofeibao  v0FreeList.io.snpt.snptEnq := genSnapshot
556368cbcecSxiaofeibao  vlFreeList.io.snpt.snptEnq := genSnapshot
557fa7f2c26STang Haojin
55800ad41d0SYinan Xu  /**
55900ad41d0SYinan Xu    * Instructions commit: update freelist and rename table
56000ad41d0SYinan Xu    */
561780712aaSxiaofeibao-xjtu  for (i <- 0 until RabCommitWidth) {
5626b102a39SHaojin Tang    val commitValid = io.rabCommits.isCommit && io.rabCommits.commitValid(i)
5636b102a39SHaojin Tang    val walkValid = io.rabCommits.isWalk && io.rabCommits.walkValid(i)
56400ad41d0SYinan Xu
565deb6421eSHaojin Tang    // I. RAT Update
5667fa2c198SYinan Xu    // When redirect happens (mis-prediction), don't update the rename table
567deb6421eSHaojin Tang    io.intRenamePorts(i).wen  := intSpecWen(i)
568ad5c9e6eSJunxiong Ji    io.intRenamePorts(i).addr := uops(i).ldest(log2Ceil(IntLogicRegs) - 1, 0)
569deb6421eSHaojin Tang    io.intRenamePorts(i).data := io.out(i).bits.pdest
5708b8e745dSYikeZhou
571deb6421eSHaojin Tang    io.fpRenamePorts(i).wen  := fpSpecWen(i)
572ad5c9e6eSJunxiong Ji    io.fpRenamePorts(i).addr := uops(i).ldest(log2Ceil(FpLogicRegs) - 1, 0)
573deb6421eSHaojin Tang    io.fpRenamePorts(i).data := fpFreeList.io.allocatePhyReg(i)
574deb6421eSHaojin Tang
575deb6421eSHaojin Tang    io.vecRenamePorts(i).wen := vecSpecWen(i)
576ad5c9e6eSJunxiong Ji    io.vecRenamePorts(i).addr := uops(i).ldest(log2Ceil(VecLogicRegs) - 1, 0)
5774eebf274Ssinsanction    io.vecRenamePorts(i).data := vecFreeList.io.allocatePhyReg(i)
578deb6421eSHaojin Tang
579368cbcecSxiaofeibao    io.v0RenamePorts(i).wen := v0SpecWen(i)
580ad5c9e6eSJunxiong Ji    io.v0RenamePorts(i).addr := uops(i).ldest(log2Ceil(V0LogicRegs) - 1, 0)
581368cbcecSxiaofeibao    io.v0RenamePorts(i).data := v0FreeList.io.allocatePhyReg(i)
582368cbcecSxiaofeibao
583368cbcecSxiaofeibao    io.vlRenamePorts(i).wen := vlSpecWen(i)
584ad5c9e6eSJunxiong Ji    io.vlRenamePorts(i).addr := uops(i).ldest(log2Ceil(VlLogicRegs) - 1, 0)
585368cbcecSxiaofeibao    io.vlRenamePorts(i).data := vlFreeList.io.allocatePhyReg(i)
586368cbcecSxiaofeibao
587deb6421eSHaojin Tang    // II. Free List Update
588dcf3a679STang Haojin    intFreeList.io.freeReq(i) := io.int_need_free(i)
589dcf3a679STang Haojin    intFreeList.io.freePhyReg(i) := RegNext(io.int_old_pdest(i))
5904eebf274Ssinsanction    fpFreeList.io.freeReq(i)  := GatedValidRegNext(commitValid && needDestRegCommit(Reg_F, io.rabCommits.info(i)))
5917042bac3Ssinsanction    fpFreeList.io.freePhyReg(i) := io.fp_old_pdest(i)
5924eebf274Ssinsanction    vecFreeList.io.freeReq(i)  := GatedValidRegNext(commitValid && needDestRegCommit(Reg_V, io.rabCommits.info(i)))
5937042bac3Ssinsanction    vecFreeList.io.freePhyReg(i) := io.vec_old_pdest(i)
594368cbcecSxiaofeibao    v0FreeList.io.freeReq(i) := GatedValidRegNext(commitValid && needDestRegCommit(Reg_V0, io.rabCommits.info(i)))
595f6e3bebeSxiaofeibao    v0FreeList.io.freePhyReg(i) := io.v0_old_pdest(i)
596368cbcecSxiaofeibao    vlFreeList.io.freeReq(i) := GatedValidRegNext(commitValid && needDestRegCommit(Reg_Vl, io.rabCommits.info(i)))
597f6e3bebeSxiaofeibao    vlFreeList.io.freePhyReg(i) := io.vl_old_pdest(i)
5988b8e745dSYikeZhou  }
5998b8e745dSYikeZhou
6008b8e745dSYikeZhou  /*
60170224bf6SYinan Xu  Debug and performance counters
6028b8e745dSYikeZhou   */
6033b739f49SXuan Hu  def printRenameInfo(in: DecoupledIO[DecodedInst], out: DecoupledIO[DynInst]) = {
6043b739f49SXuan Hu    XSInfo(out.fire, p"pc:${Hexadecimal(in.bits.pc)} in(${in.valid},${in.ready}) " +
6053b739f49SXuan Hu      p"lsrc(0):${in.bits.lsrc(0)} -> psrc(0):${out.bits.psrc(0)} " +
6063b739f49SXuan Hu      p"lsrc(1):${in.bits.lsrc(1)} -> psrc(1):${out.bits.psrc(1)} " +
6073b739f49SXuan Hu      p"lsrc(2):${in.bits.lsrc(2)} -> psrc(2):${out.bits.psrc(2)} " +
608c61abc0cSXuan Hu      p"ldest:${in.bits.ldest} -> pdest:${out.bits.pdest}\n"
6098b8e745dSYikeZhou    )
6108b8e745dSYikeZhou  }
6118b8e745dSYikeZhou
6128b8e745dSYikeZhou  for ((x,y) <- io.in.zip(io.out)) {
6138b8e745dSYikeZhou    printRenameInfo(x, y)
6148b8e745dSYikeZhou  }
6158b8e745dSYikeZhou
61642bcc716Sxiaofeibao-xjtu  io.out.map { case x =>
61742bcc716Sxiaofeibao-xjtu    when(x.valid && x.bits.rfWen){
61842bcc716Sxiaofeibao-xjtu      assert(x.bits.ldest =/= 0.U, "rfWen cannot be 1 when Int regfile ldest is 0")
61942bcc716Sxiaofeibao-xjtu    }
62042bcc716Sxiaofeibao-xjtu  }
621d2b20d1aSTang Haojin  val debugRedirect = RegEnable(io.redirect.bits, io.redirect.valid)
622d2b20d1aSTang Haojin  // bad speculation
6236b102a39SHaojin Tang  val recStall = io.redirect.valid || io.rabCommits.isWalk
6246b102a39SHaojin Tang  val ctrlRecStall = Mux(io.redirect.valid, io.redirect.bits.debugIsCtrl, io.rabCommits.isWalk && debugRedirect.debugIsCtrl)
6256b102a39SHaojin Tang  val mvioRecStall = Mux(io.redirect.valid, io.redirect.bits.debugIsMemVio, io.rabCommits.isWalk && debugRedirect.debugIsMemVio)
626d2b20d1aSTang Haojin  val otherRecStall = recStall && !(ctrlRecStall || mvioRecStall)
627d2b20d1aSTang Haojin  XSPerfAccumulate("recovery_stall", recStall)
628d2b20d1aSTang Haojin  XSPerfAccumulate("control_recovery_stall", ctrlRecStall)
629d2b20d1aSTang Haojin  XSPerfAccumulate("mem_violation_recovery_stall", mvioRecStall)
630d2b20d1aSTang Haojin  XSPerfAccumulate("other_recovery_stall", otherRecStall)
631d2b20d1aSTang Haojin  // freelist stall
632d2b20d1aSTang Haojin  val notRecStall = !io.out.head.valid && !recStall
633368cbcecSxiaofeibao  val intFlStall = notRecStall && inHeadValid && fpFreeList.io.canAllocate && vecFreeList.io.canAllocate && v0FreeList.io.canAllocate && vlFreeList.io.canAllocate && !intFreeList.io.canAllocate
634368cbcecSxiaofeibao  val fpFlStall = notRecStall && inHeadValid && intFreeList.io.canAllocate && vecFreeList.io.canAllocate && v0FreeList.io.canAllocate && vlFreeList.io.canAllocate && !fpFreeList.io.canAllocate
635368cbcecSxiaofeibao  val vecFlStall = notRecStall && inHeadValid && intFreeList.io.canAllocate && fpFreeList.io.canAllocate && v0FreeList.io.canAllocate && vlFreeList.io.canAllocate && !vecFreeList.io.canAllocate
636368cbcecSxiaofeibao  val v0FlStall = notRecStall && inHeadValid && intFreeList.io.canAllocate && fpFreeList.io.canAllocate && vecFreeList.io.canAllocate && vlFreeList.io.canAllocate && !v0FreeList.io.canAllocate
637368cbcecSxiaofeibao  val vlFlStall = notRecStall && inHeadValid && intFreeList.io.canAllocate && fpFreeList.io.canAllocate && vecFreeList.io.canAllocate && v0FreeList.io.canAllocate && !vlFreeList.io.canAllocate
638368cbcecSxiaofeibao  val multiFlStall = notRecStall && inHeadValid && (PopCount(Cat(
639368cbcecSxiaofeibao    !intFreeList.io.canAllocate,
640368cbcecSxiaofeibao    !fpFreeList.io.canAllocate,
641368cbcecSxiaofeibao    !vecFreeList.io.canAllocate,
642368cbcecSxiaofeibao    !v0FreeList.io.canAllocate,
643368cbcecSxiaofeibao    !vlFreeList.io.canAllocate,
644368cbcecSxiaofeibao  )) > 1.U)
645d2b20d1aSTang Haojin  // other stall
646368cbcecSxiaofeibao  val otherStall = notRecStall && !intFlStall && !fpFlStall && !vecFlStall && !v0FlStall && !vlFlStall && !multiFlStall
647d2b20d1aSTang Haojin
648d2b20d1aSTang Haojin  io.stallReason.in.backReason.valid := io.stallReason.out.backReason.valid || !io.in.head.ready
649d2b20d1aSTang Haojin  io.stallReason.in.backReason.bits := Mux(io.stallReason.out.backReason.valid, io.stallReason.out.backReason.bits,
650d2b20d1aSTang Haojin    MuxCase(TopDownCounters.OtherCoreStall.id.U, Seq(
651d2b20d1aSTang Haojin      ctrlRecStall  -> TopDownCounters.ControlRecoveryStall.id.U,
652d2b20d1aSTang Haojin      mvioRecStall  -> TopDownCounters.MemVioRecoveryStall.id.U,
653d2b20d1aSTang Haojin      otherRecStall -> TopDownCounters.OtherRecoveryStall.id.U,
654d2b20d1aSTang Haojin      intFlStall    -> TopDownCounters.IntFlStall.id.U,
6554eebf274Ssinsanction      fpFlStall     -> TopDownCounters.FpFlStall.id.U,
6564eebf274Ssinsanction      vecFlStall    -> TopDownCounters.VecFlStall.id.U,
657368cbcecSxiaofeibao      v0FlStall     -> TopDownCounters.V0FlStall.id.U,
658368cbcecSxiaofeibao      vlFlStall     -> TopDownCounters.VlFlStall.id.U,
659368cbcecSxiaofeibao      multiFlStall  -> TopDownCounters.MultiFlStall.id.U,
660d2b20d1aSTang Haojin    )
661d2b20d1aSTang Haojin  ))
662d2b20d1aSTang Haojin  io.stallReason.out.reason.zip(io.stallReason.in.reason).zip(io.in.map(_.valid)).foreach { case ((out, in), valid) =>
6630adf86dcSHaojin Tang    out := Mux(io.stallReason.in.backReason.valid, io.stallReason.in.backReason.bits, in)
664d2b20d1aSTang Haojin  }
665d2b20d1aSTang Haojin
6666b102a39SHaojin Tang  XSDebug(io.rabCommits.isWalk, p"Walk Recovery Enabled\n")
6676b102a39SHaojin Tang  XSDebug(io.rabCommits.isWalk, p"validVec:${Binary(io.rabCommits.walkValid.asUInt)}\n")
668780712aaSxiaofeibao-xjtu  for (i <- 0 until RabCommitWidth) {
6696b102a39SHaojin Tang    val info = io.rabCommits.info(i)
6706b102a39SHaojin Tang    XSDebug(io.rabCommits.isWalk && io.rabCommits.walkValid(i), p"[#$i walk info] " +
671368cbcecSxiaofeibao      p"ldest:${info.ldest} rfWen:${info.rfWen} fpWen:${info.fpWen} vecWen:${info.vecWen} v0Wen:${info.v0Wen} vlWen:${info.vlWen}")
6728b8e745dSYikeZhou  }
6738b8e745dSYikeZhou
6748b8e745dSYikeZhou  XSDebug(p"inValidVec: ${Binary(Cat(io.in.map(_.valid)))}\n")
6758b8e745dSYikeZhou
676a63155a6SXuan Hu  XSPerfAccumulate("in_valid_count", PopCount(io.in.map(_.valid)))
677a63155a6SXuan Hu  XSPerfAccumulate("in_fire_count", PopCount(io.in.map(_.fire)))
678a63155a6SXuan Hu  XSPerfAccumulate("in_valid_not_ready_count", PopCount(io.in.map(x => x.valid && !x.ready)))
6796374b1d6SXuan Hu  XSPerfAccumulate("wait_cycle", !io.in.head.valid && dispatchCanAcc)
6805eb4af5bSYikeZhou
681a63155a6SXuan Hu  // These stall reasons could overlap each other, but we configure the priority as fellows.
682a63155a6SXuan Hu  // walk stall > dispatch stall > int freelist stall > fp freelist stall
683a63155a6SXuan Hu  private val inHeadStall = io.in.head match { case x => x.valid && !x.ready }
6846b102a39SHaojin Tang  private val stallForWalk      = inHeadValid &&  io.rabCommits.isWalk
6856374b1d6SXuan Hu  private val stallForDispatch  = inHeadValid && !io.rabCommits.isWalk && !dispatchCanAcc
686368cbcecSxiaofeibao  private val stallForIntFL     = inHeadValid && !io.rabCommits.isWalk && dispatchCanAcc && fpFreeList.io.canAllocate && vecFreeList.io.canAllocate && v0FreeList.io.canAllocate && vlFreeList.io.canAllocate && !intFreeList.io.canAllocate
687368cbcecSxiaofeibao  private val stallForFpFL      = inHeadValid && !io.rabCommits.isWalk && dispatchCanAcc && intFreeList.io.canAllocate && vecFreeList.io.canAllocate && v0FreeList.io.canAllocate && vlFreeList.io.canAllocate && !fpFreeList.io.canAllocate
688368cbcecSxiaofeibao  private val stallForVecFL     = inHeadValid && !io.rabCommits.isWalk && dispatchCanAcc && intFreeList.io.canAllocate && fpFreeList.io.canAllocate && v0FreeList.io.canAllocate && vlFreeList.io.canAllocate && !vecFreeList.io.canAllocate
689368cbcecSxiaofeibao  private val stallForV0FL      = inHeadValid && !io.rabCommits.isWalk && dispatchCanAcc && intFreeList.io.canAllocate && fpFreeList.io.canAllocate && vecFreeList.io.canAllocate && vlFreeList.io.canAllocate && !v0FreeList.io.canAllocate
690368cbcecSxiaofeibao  private val stallForVlFL      = inHeadValid && !io.rabCommits.isWalk && dispatchCanAcc && intFreeList.io.canAllocate && fpFreeList.io.canAllocate && vecFreeList.io.canAllocate && v0FreeList.io.canAllocate && !vlFreeList.io.canAllocate
691a63155a6SXuan Hu  XSPerfAccumulate("stall_cycle",          inHeadStall)
692a63155a6SXuan Hu  XSPerfAccumulate("stall_cycle_walk",     stallForWalk)
693a63155a6SXuan Hu  XSPerfAccumulate("stall_cycle_dispatch", stallForDispatch)
694a63155a6SXuan Hu  XSPerfAccumulate("stall_cycle_int",      stallForIntFL)
695a63155a6SXuan Hu  XSPerfAccumulate("stall_cycle_fp",       stallForFpFL)
6964eebf274Ssinsanction  XSPerfAccumulate("stall_cycle_vec",      stallForVecFL)
697368cbcecSxiaofeibao  XSPerfAccumulate("stall_cycle_vec",      stallForV0FL)
698368cbcecSxiaofeibao  XSPerfAccumulate("stall_cycle_vec",      stallForVlFL)
699a63155a6SXuan Hu
700a63155a6SXuan Hu  XSPerfHistogram("in_valid_range",  PopCount(io.in.map(_.valid)),  true.B, 0, DecodeWidth + 1, 1)
701a63155a6SXuan Hu  XSPerfHistogram("in_fire_range",   PopCount(io.in.map(_.fire)),   true.B, 0, DecodeWidth + 1, 1)
702a63155a6SXuan Hu  XSPerfHistogram("out_valid_range", PopCount(io.out.map(_.valid)), true.B, 0, DecodeWidth + 1, 1)
703a63155a6SXuan Hu  XSPerfHistogram("out_fire_range",  PopCount(io.out.map(_.fire)),  true.B, 0, DecodeWidth + 1, 1)
704d8aa3d57SbugGenerator
7053b739f49SXuan Hu  XSPerfAccumulate("move_instr_count", PopCount(io.out.map(out => out.fire && out.bits.isMove)))
7063b739f49SXuan Hu  val is_fused_lui_load = io.out.map(o => o.fire && o.bits.fuType === FuType.ldu.U && o.bits.srcType(0) === SrcType.imm)
707fd7603d9SYinan Xu  XSPerfAccumulate("fused_lui_load_instr_count", PopCount(is_fused_lui_load))
708cd365d4cSrvcoresjw
7091ca0e4f3SYinan Xu  val renamePerf = Seq(
710cd365d4cSrvcoresjw    ("rename_in                  ", PopCount(io.in.map(_.valid & io.in(0).ready ))                                                               ),
711cd365d4cSrvcoresjw    ("rename_waitinstr           ", PopCount((0 until RenameWidth).map(i => io.in(i).valid && !io.in(i).ready))                                  ),
712a63155a6SXuan Hu    ("rename_stall               ", inHeadStall),
7136b102a39SHaojin Tang    ("rename_stall_cycle_walk    ", inHeadValid &&  io.rabCommits.isWalk),
7146374b1d6SXuan Hu    ("rename_stall_cycle_dispatch", inHeadValid && !io.rabCommits.isWalk && !dispatchCanAcc),
715368cbcecSxiaofeibao    ("rename_stall_cycle_int     ", inHeadValid && !io.rabCommits.isWalk && dispatchCanAcc && fpFreeList.io.canAllocate && vecFreeList.io.canAllocate && v0FreeList.io.canAllocate && vlFreeList.io.canAllocate && !intFreeList.io.canAllocate),
716368cbcecSxiaofeibao    ("rename_stall_cycle_fp      ", inHeadValid && !io.rabCommits.isWalk && dispatchCanAcc && intFreeList.io.canAllocate && vecFreeList.io.canAllocate && v0FreeList.io.canAllocate && vlFreeList.io.canAllocate && !fpFreeList.io.canAllocate),
717368cbcecSxiaofeibao    ("rename_stall_cycle_vec     ", inHeadValid && !io.rabCommits.isWalk && dispatchCanAcc && intFreeList.io.canAllocate && fpFreeList.io.canAllocate && v0FreeList.io.canAllocate && vlFreeList.io.canAllocate && !vecFreeList.io.canAllocate),
718368cbcecSxiaofeibao    ("rename_stall_cycle_v0      ", inHeadValid && !io.rabCommits.isWalk && dispatchCanAcc && intFreeList.io.canAllocate && fpFreeList.io.canAllocate && vecFreeList.io.canAllocate && vlFreeList.io.canAllocate && !v0FreeList.io.canAllocate),
719368cbcecSxiaofeibao    ("rename_stall_cycle_vl      ", inHeadValid && !io.rabCommits.isWalk && dispatchCanAcc && intFreeList.io.canAllocate && fpFreeList.io.canAllocate && vecFreeList.io.canAllocate && v0FreeList.io.canAllocate && !vlFreeList.io.canAllocate),
720cd365d4cSrvcoresjw  )
7211ca0e4f3SYinan Xu  val intFlPerf = intFreeList.getPerfEvents
7221ca0e4f3SYinan Xu  val fpFlPerf = fpFreeList.getPerfEvents
7234eebf274Ssinsanction  val vecFlPerf = vecFreeList.getPerfEvents
724368cbcecSxiaofeibao  val v0FlPerf = v0FreeList.getPerfEvents
725368cbcecSxiaofeibao  val vlFlPerf = vlFreeList.getPerfEvents
726368cbcecSxiaofeibao  val perfEvents = renamePerf ++ intFlPerf ++ fpFlPerf ++ vecFlPerf ++ v0FlPerf ++ vlFlPerf
7271ca0e4f3SYinan Xu  generatePerfEvent()
7285eb4af5bSYikeZhou}
729