xref: /XiangShan/src/main/scala/xiangshan/backend/rename/Rename.scala (revision 8891a219bbc84f568e1d134854d8d5ed86d6d560)
1/***************************************************************************************
2* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences
3* Copyright (c) 2020-2021 Peng Cheng Laboratory
4*
5* XiangShan is licensed under Mulan PSL v2.
6* You can use this software according to the terms and conditions of the Mulan PSL v2.
7* You may obtain a copy of Mulan PSL v2 at:
8*          http://license.coscl.org.cn/MulanPSL2
9*
10* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13*
14* See the Mulan PSL v2 for more details.
15***************************************************************************************/
16
17package xiangshan.backend.rename
18
19import org.chipsalliance.cde.config.Parameters
20import chisel3._
21import chisel3.util._
22import xiangshan._
23import utils._
24import utility._
25import xiangshan.backend.decode.{FusionDecodeInfo, Imm_I, Imm_LUI_LOAD, Imm_U}
26import xiangshan.backend.rob.RobPtr
27import xiangshan.backend.rename.freelist._
28import xiangshan.mem.mdp._
29
30class Rename(implicit p: Parameters) extends XSModule with HasCircularQueuePtrHelper with HasPerfEvents {
31  val io = IO(new Bundle() {
32    val redirect = Flipped(ValidIO(new Redirect))
33    val robCommits = Input(new RobCommitIO)
34    // from decode
35    val in = Vec(RenameWidth, Flipped(DecoupledIO(new CfCtrl)))
36    val fusionInfo = Vec(DecodeWidth - 1, Flipped(new FusionDecodeInfo))
37    // ssit read result
38    val ssit = Flipped(Vec(RenameWidth, Output(new SSITEntry)))
39    // waittable read result
40    val waittable = Flipped(Vec(RenameWidth, Output(Bool())))
41    // to rename table
42    val intReadPorts = Vec(RenameWidth, Vec(3, Input(UInt(PhyRegIdxWidth.W))))
43    val fpReadPorts = Vec(RenameWidth, Vec(4, Input(UInt(PhyRegIdxWidth.W))))
44    val intRenamePorts = Vec(RenameWidth, Output(new RatWritePort))
45    val fpRenamePorts = Vec(RenameWidth, Output(new RatWritePort))
46    // from rename table
47    val int_old_pdest = Vec(CommitWidth, Input(UInt(PhyRegIdxWidth.W)))
48    val fp_old_pdest = Vec(CommitWidth, Input(UInt(PhyRegIdxWidth.W)))
49    val int_need_free = Vec(CommitWidth, Input(Bool()))
50    // to dispatch1
51    val out = Vec(RenameWidth, DecoupledIO(new MicroOp))
52    // for snapshots
53    val snpt = Input(new SnapshotPort)
54    // debug arch ports
55    val debug_int_rat = Vec(32, Input(UInt(PhyRegIdxWidth.W)))
56    val debug_fp_rat = Vec(32, Input(UInt(PhyRegIdxWidth.W)))
57    // perf only
58    val stallReason = new Bundle {
59      val in = Flipped(new StallReasonIO(RenameWidth))
60      val out = new StallReasonIO(RenameWidth)
61    }
62  })
63
64  // create free list and rat
65  val intFreeList = Module(new MEFreeList(NRPhyRegs))
66  val fpFreeList = Module(new StdFreeList(NRPhyRegs - 32))
67
68  intFreeList.io.commit    <> io.robCommits
69  intFreeList.io.debug_rat <> io.debug_int_rat
70  fpFreeList.io.commit     <> io.robCommits
71  fpFreeList.io.debug_rat  <> io.debug_fp_rat
72
73  // decide if given instruction needs allocating a new physical register (CfCtrl: from decode; RobCommitInfo: from rob)
74  def needDestReg[T <: CfCtrl](fp: Boolean, x: T): Bool = {
75    {if(fp) x.ctrl.fpWen else x.ctrl.rfWen && (x.ctrl.ldest =/= 0.U)}
76  }
77  def needDestRegCommit[T <: RobCommitInfo](fp: Boolean, x: T): Bool = {
78    if(fp) x.fpWen else x.rfWen
79  }
80  def needDestRegWalk[T <: RobCommitInfo](fp: Boolean, x: T): Bool = {
81    if(fp) x.fpWen else x.rfWen && x.ldest =/= 0.U
82  }
83
84  // connect [redirect + walk] ports for __float point__ & __integer__ free list
85  Seq((fpFreeList, true), (intFreeList, false)).foreach{ case (fl, isFp) =>
86    fl.io.redirect := io.redirect.valid
87    fl.io.walk := io.robCommits.isWalk
88  }
89  // only when both fp and int free list and dispatch1 has enough space can we do allocation
90  // when isWalk, freelist can definitely allocate
91  intFreeList.io.doAllocate := fpFreeList.io.canAllocate && io.out(0).ready || io.robCommits.isWalk
92  fpFreeList.io.doAllocate := intFreeList.io.canAllocate && io.out(0).ready || io.robCommits.isWalk
93
94  //           dispatch1 ready ++ float point free list ready ++ int free list ready      ++ not walk
95  val canOut = io.out(0).ready && fpFreeList.io.canAllocate && intFreeList.io.canAllocate && !io.robCommits.isWalk
96
97
98  // speculatively assign the instruction with an robIdx
99  val validCount = PopCount(io.in.map(_.valid)) // number of instructions waiting to enter rob (from decode)
100  val robIdxHead = RegInit(0.U.asTypeOf(new RobPtr))
101  val lastCycleMisprediction = RegNext(io.redirect.valid && !io.redirect.bits.flushItself())
102  val robIdxHeadNext = Mux(io.redirect.valid, io.redirect.bits.robIdx, // redirect: move ptr to given rob index
103         Mux(lastCycleMisprediction, robIdxHead + 1.U, // mis-predict: not flush robIdx itself
104                         Mux(canOut, robIdxHead + validCount, // instructions successfully entered next stage: increase robIdx
105                      /* default */  robIdxHead))) // no instructions passed by this cycle: stick to old value
106  robIdxHead := robIdxHeadNext
107
108  /**
109    * Rename: allocate free physical register and update rename table
110    */
111  val uops = Wire(Vec(RenameWidth, new MicroOp))
112  uops.foreach( uop => {
113    uop.srcState(0) := DontCare
114    uop.srcState(1) := DontCare
115    uop.srcState(2) := DontCare
116    uop.robIdx := DontCare
117    uop.debugInfo := DontCare
118    uop.lqIdx := DontCare
119    uop.sqIdx := DontCare
120    uop.snapshot := DontCare
121  })
122
123  require(RenameWidth >= CommitWidth)
124
125  val needFpDest = Wire(Vec(RenameWidth, Bool()))
126  val needIntDest = Wire(Vec(RenameWidth, Bool()))
127  val hasValid = Cat(io.in.map(_.valid)).orR
128
129  val isMove = io.in.map(_.bits.ctrl.isMove)
130
131  val walkNeedFpDest = WireDefault(VecInit(Seq.fill(RenameWidth)(false.B)))
132  val walkNeedIntDest = WireDefault(VecInit(Seq.fill(RenameWidth)(false.B)))
133  val walkIsMove = WireDefault(VecInit(Seq.fill(RenameWidth)(false.B)))
134
135  val intSpecWen = Wire(Vec(RenameWidth, Bool()))
136  val fpSpecWen = Wire(Vec(RenameWidth, Bool()))
137
138  val walkIntSpecWen = WireDefault(VecInit(Seq.fill(RenameWidth)(false.B)))
139
140  val walkPdest = Wire(Vec(RenameWidth, UInt(PhyRegIdxWidth.W)))
141
142  // uop calculation
143  for (i <- 0 until RenameWidth) {
144    uops(i).cf := io.in(i).bits.cf
145    uops(i).ctrl := io.in(i).bits.ctrl
146
147    // update cf according to ssit result
148    uops(i).cf.storeSetHit := io.ssit(i).valid
149    uops(i).cf.loadWaitStrict := io.ssit(i).strict && io.ssit(i).valid
150    uops(i).cf.ssid := io.ssit(i).ssid
151
152    // update cf according to waittable result
153    uops(i).cf.loadWaitBit := io.waittable(i)
154
155    // alloc a new phy reg
156    needFpDest(i) := io.in(i).valid && needDestReg(fp = true, io.in(i).bits)
157    needIntDest(i) := io.in(i).valid && needDestReg(fp = false, io.in(i).bits)
158    if (i < CommitWidth) {
159      walkNeedFpDest(i) := io.robCommits.walkValid(i) && needDestRegWalk(fp = true, io.robCommits.info(i))
160      walkNeedIntDest(i) := io.robCommits.walkValid(i) && needDestRegWalk(fp = false, io.robCommits.info(i))
161      walkIsMove(i) := io.robCommits.info(i).isMove
162    }
163    fpFreeList.io.allocateReq(i) := needFpDest(i)
164    fpFreeList.io.walkReq(i) := walkNeedFpDest(i)
165    intFreeList.io.allocateReq(i) := needIntDest(i) && !isMove(i)
166    intFreeList.io.walkReq(i) := walkNeedIntDest(i) && !walkIsMove(i)
167
168    // no valid instruction from decode stage || all resources (dispatch1 + both free lists) ready
169    io.in(i).ready := !hasValid || canOut
170
171    uops(i).robIdx := robIdxHead + PopCount(io.in.take(i).map(_.valid))
172
173    uops(i).psrc(0) := Mux(uops(i).ctrl.srcType(0) === SrcType.reg, io.intReadPorts(i)(0), io.fpReadPorts(i)(0))
174    uops(i).psrc(1) := Mux(uops(i).ctrl.srcType(1) === SrcType.reg, io.intReadPorts(i)(1), io.fpReadPorts(i)(1))
175    // int psrc2 should be bypassed from next instruction if it is fused
176    if (i < RenameWidth - 1) {
177      when (io.fusionInfo(i).rs2FromRs2 || io.fusionInfo(i).rs2FromRs1) {
178        uops(i).psrc(1) := Mux(io.fusionInfo(i).rs2FromRs2, io.intReadPorts(i + 1)(1), io.intReadPorts(i + 1)(0))
179      }.elsewhen(io.fusionInfo(i).rs2FromZero) {
180        uops(i).psrc(1) := 0.U
181      }
182    }
183    uops(i).psrc(2) := io.fpReadPorts(i)(2)
184    uops(i).eliminatedMove := isMove(i)
185
186    // update pdest
187    uops(i).pdest := Mux(needIntDest(i), intFreeList.io.allocatePhyReg(i), // normal int inst
188      // normal fp inst
189      Mux(needFpDest(i), fpFreeList.io.allocatePhyReg(i),
190        /* default */0.U))
191
192    // Assign performance counters
193    uops(i).debugInfo.renameTime := GTimer()
194
195    io.out(i).valid := io.in(i).valid && intFreeList.io.canAllocate && fpFreeList.io.canAllocate && !io.robCommits.isWalk
196    io.out(i).bits := uops(i)
197    // dirty code for fence. The lsrc is passed by imm.
198    when (io.out(i).bits.ctrl.fuType === FuType.fence) {
199      io.out(i).bits.ctrl.imm := Cat(io.in(i).bits.ctrl.lsrc(1), io.in(i).bits.ctrl.lsrc(0))
200    }
201    // dirty code for SoftPrefetch (prefetch.r/prefetch.w)
202    when (io.in(i).bits.ctrl.isSoftPrefetch) {
203      io.out(i).bits.ctrl.fuType := FuType.ldu
204      io.out(i).bits.ctrl.fuOpType := Mux(io.in(i).bits.ctrl.lsrc(1) === 1.U, LSUOpType.prefetch_r, LSUOpType.prefetch_w)
205      io.out(i).bits.ctrl.selImm := SelImm.IMM_S
206      io.out(i).bits.ctrl.imm := Cat(io.in(i).bits.ctrl.imm(io.in(i).bits.ctrl.imm.getWidth - 1, 5), 0.U(5.W))
207    }
208
209    // write speculative rename table
210    // we update rat later inside commit code
211    intSpecWen(i) := needIntDest(i) && intFreeList.io.canAllocate && intFreeList.io.doAllocate && !io.robCommits.isWalk && !io.redirect.valid
212    fpSpecWen(i) := needFpDest(i) && fpFreeList.io.canAllocate && fpFreeList.io.doAllocate && !io.robCommits.isWalk && !io.redirect.valid
213
214    if (i < CommitWidth) {
215      walkIntSpecWen(i) := walkNeedIntDest(i) && !io.redirect.valid
216      walkPdest(i) := io.robCommits.info(i).pdest
217    } else {
218      walkPdest(i) := io.out(i).bits.pdest
219    }
220  }
221
222  /**
223    * How to set psrc:
224    * - bypass the pdest to psrc if previous instructions write to the same ldest as lsrc
225    * - default: psrc from RAT
226    * How to set pdest:
227    * - Mux(isMove, psrc, pdest_from_freelist).
228    *
229    * The critical path of rename lies here:
230    * When move elimination is enabled, we need to update the rat with psrc.
231    * However, psrc maybe comes from previous instructions' pdest, which comes from freelist.
232    *
233    * If we expand these logic for pdest(N):
234    * pdest(N) = Mux(isMove(N), psrc(N), freelist_out(N))
235    *          = Mux(isMove(N), Mux(bypass(N, N - 1), pdest(N - 1),
236    *                           Mux(bypass(N, N - 2), pdest(N - 2),
237    *                           ...
238    *                           Mux(bypass(N, 0),     pdest(0),
239    *                                                 rat_out(N))...)),
240    *                           freelist_out(N))
241    */
242  // a simple functional model for now
243  io.out(0).bits.pdest := Mux(isMove(0), uops(0).psrc.head, uops(0).pdest)
244  val bypassCond = Wire(Vec(4, MixedVec(List.tabulate(RenameWidth-1)(i => UInt((i+1).W)))))
245  for (i <- 1 until RenameWidth) {
246    val fpCond = io.in(i).bits.ctrl.srcType.map(_ === SrcType.fp) :+ needFpDest(i)
247    val intCond = io.in(i).bits.ctrl.srcType.map(_ === SrcType.reg) :+ needIntDest(i)
248    val target = io.in(i).bits.ctrl.lsrc :+ io.in(i).bits.ctrl.ldest
249    for ((((cond1, cond2), t), j) <- fpCond.zip(intCond).zip(target).zipWithIndex) {
250      val destToSrc = io.in.take(i).zipWithIndex.map { case (in, j) =>
251        val indexMatch = in.bits.ctrl.ldest === t
252        val writeMatch =  cond2 && needIntDest(j) || cond1 && needFpDest(j)
253        indexMatch && writeMatch
254      }
255      bypassCond(j)(i - 1) := VecInit(destToSrc).asUInt
256    }
257    io.out(i).bits.psrc(0) := io.out.take(i).map(_.bits.pdest).zip(bypassCond(0)(i-1).asBools).foldLeft(uops(i).psrc(0)) {
258      (z, next) => Mux(next._2, next._1, z)
259    }
260    io.out(i).bits.psrc(1) := io.out.take(i).map(_.bits.pdest).zip(bypassCond(1)(i-1).asBools).foldLeft(uops(i).psrc(1)) {
261      (z, next) => Mux(next._2, next._1, z)
262    }
263    io.out(i).bits.psrc(2) := io.out.take(i).map(_.bits.pdest).zip(bypassCond(2)(i-1).asBools).foldLeft(uops(i).psrc(2)) {
264      (z, next) => Mux(next._2, next._1, z)
265    }
266    io.out(i).bits.pdest := Mux(isMove(i), io.out(i).bits.psrc(0), uops(i).pdest)
267
268    // For fused-lui-load, load.src(0) is replaced by the imm.
269    val last_is_lui = io.in(i - 1).bits.ctrl.selImm === SelImm.IMM_U && io.in(i - 1).bits.ctrl.srcType(0) =/= SrcType.pc
270    val this_is_load = io.in(i).bits.ctrl.fuType === FuType.ldu
271    val lui_to_load = io.in(i - 1).valid && io.in(i - 1).bits.ctrl.ldest === io.in(i).bits.ctrl.lsrc(0)
272    val fused_lui_load = last_is_lui && this_is_load && lui_to_load
273    when (fused_lui_load) {
274      // The first LOAD operand (base address) is replaced by LUI-imm and stored in {psrc, imm}
275      val lui_imm = io.in(i - 1).bits.ctrl.imm
276      val ld_imm = io.in(i).bits.ctrl.imm
277      io.out(i).bits.ctrl.srcType(0) := SrcType.imm
278      io.out(i).bits.ctrl.imm := Imm_LUI_LOAD().immFromLuiLoad(lui_imm, ld_imm)
279      val psrcWidth = uops(i).psrc.head.getWidth
280      val lui_imm_in_imm = uops(i).ctrl.imm.getWidth - Imm_I().len
281      val left_lui_imm = Imm_U().len - lui_imm_in_imm
282      require(2 * psrcWidth >= left_lui_imm, "cannot fused lui and load with psrc")
283      io.out(i).bits.psrc(0) := lui_imm(lui_imm_in_imm + psrcWidth - 1, lui_imm_in_imm)
284      io.out(i).bits.psrc(1) := lui_imm(lui_imm.getWidth - 1, lui_imm_in_imm + psrcWidth)
285    }
286
287  }
288
289  val hasCFI = VecInit(io.in.map(in => (!in.bits.cf.pd.notCFI || FuType.isJumpExu(in.bits.ctrl.fuType)) && in.fire)).asUInt.orR
290  val snapshotCtr = RegInit((4 * CommitWidth).U)
291  val allowSnpt = if (EnableRenameSnapshot) !snapshotCtr.orR else false.B
292  io.out.head.bits.snapshot := hasCFI && allowSnpt
293  when(io.out.head.fire && io.out.head.bits.snapshot) {
294    snapshotCtr := (4 * CommitWidth).U - PopCount(io.out.map(_.fire))
295  }.elsewhen(io.out.head.fire) {
296    snapshotCtr := Mux(snapshotCtr < PopCount(io.out.map(_.fire)), 0.U, snapshotCtr - PopCount(io.out.map(_.fire)))
297  }
298
299  intFreeList.io.snpt := io.snpt
300  fpFreeList.io.snpt := io.snpt
301  intFreeList.io.snpt.snptEnq := io.out.head.fire && io.out.head.bits.snapshot
302  fpFreeList.io.snpt.snptEnq := io.out.head.fire && io.out.head.bits.snapshot
303
304  /**
305    * Instructions commit: update freelist and rename table
306    */
307  for (i <- 0 until CommitWidth) {
308    val commitValid = io.robCommits.isCommit && io.robCommits.commitValid(i)
309    val walkValid = io.robCommits.isWalk && io.robCommits.walkValid(i)
310
311    Seq((io.intRenamePorts, false), (io.fpRenamePorts, true)) foreach { case (rat, fp) =>
312      /*
313      I. RAT Update
314       */
315
316      // walk back write - restore spec state : ldest => old_pdest
317      if (fp && i < RenameWidth) {
318        // When redirect happens (mis-prediction), don't update the rename table
319        rat(i).wen := fpSpecWen(i)
320        rat(i).addr := uops(i).ctrl.ldest
321        rat(i).data := fpFreeList.io.allocatePhyReg(i)
322      } else if (!fp && i < RenameWidth) {
323        rat(i).wen := intSpecWen(i)
324        rat(i).addr := uops(i).ctrl.ldest
325        rat(i).data := io.out(i).bits.pdest
326      }
327
328      /*
329      II. Free List Update
330       */
331      if (fp) { // Float Point free list
332        fpFreeList.io.freeReq(i)  := RegNext(commitValid && needDestRegCommit(fp, io.robCommits.info(i)), false.B)
333        fpFreeList.io.freePhyReg(i) := io.fp_old_pdest(i)
334      } else { // Integer free list
335        intFreeList.io.freeReq(i) := io.int_need_free(i)
336        intFreeList.io.freePhyReg(i) := RegNext(io.int_old_pdest(i))
337      }
338    }
339  }
340
341  /*
342  Debug and performance counters
343   */
344  def printRenameInfo(in: DecoupledIO[CfCtrl], out: DecoupledIO[MicroOp]) = {
345    XSInfo(out.fire, p"pc:${Hexadecimal(in.bits.cf.pc)} in(${in.valid},${in.ready}) " +
346      p"lsrc(0):${in.bits.ctrl.lsrc(0)} -> psrc(0):${out.bits.psrc(0)} " +
347      p"lsrc(1):${in.bits.ctrl.lsrc(1)} -> psrc(1):${out.bits.psrc(1)} " +
348      p"lsrc(2):${in.bits.ctrl.lsrc(2)} -> psrc(2):${out.bits.psrc(2)} " +
349      p"ldest:${in.bits.ctrl.ldest} -> pdest:${out.bits.pdest} "
350    )
351  }
352
353  for((x,y) <- io.in.zip(io.out)){
354    printRenameInfo(x, y)
355  }
356
357  val debugRedirect = RegEnable(io.redirect.bits, io.redirect.valid)
358  // bad speculation
359  val recStall = io.redirect.valid || io.robCommits.isWalk
360  val ctrlRecStall = Mux(io.redirect.valid, io.redirect.bits.debugIsCtrl, io.robCommits.isWalk && debugRedirect.debugIsCtrl)
361  val mvioRecStall = Mux(io.redirect.valid, io.redirect.bits.debugIsMemVio, io.robCommits.isWalk && debugRedirect.debugIsMemVio)
362  val otherRecStall = recStall && !(ctrlRecStall || mvioRecStall)
363  XSPerfAccumulate("recovery_stall", recStall)
364  XSPerfAccumulate("control_recovery_stall", ctrlRecStall)
365  XSPerfAccumulate("mem_violation_recovery_stall", mvioRecStall)
366  XSPerfAccumulate("other_recovery_stall", otherRecStall)
367  // freelist stall
368  val notRecStall = !io.out.head.valid && !recStall
369  val intFlStall = notRecStall && hasValid && !intFreeList.io.canAllocate
370  val fpFlStall = notRecStall && hasValid && !fpFreeList.io.canAllocate
371  // other stall
372  val otherStall = notRecStall && !intFlStall && !fpFlStall
373
374  io.stallReason.in.backReason.valid := io.stallReason.out.backReason.valid || !io.in.head.ready
375  io.stallReason.in.backReason.bits := Mux(io.stallReason.out.backReason.valid, io.stallReason.out.backReason.bits,
376    MuxCase(TopDownCounters.OtherCoreStall.id.U, Seq(
377      ctrlRecStall  -> TopDownCounters.ControlRecoveryStall.id.U,
378      mvioRecStall  -> TopDownCounters.MemVioRecoveryStall.id.U,
379      otherRecStall -> TopDownCounters.OtherRecoveryStall.id.U,
380      intFlStall    -> TopDownCounters.IntFlStall.id.U,
381      fpFlStall     -> TopDownCounters.FpFlStall.id.U
382    )
383  ))
384  io.stallReason.out.reason.zip(io.stallReason.in.reason).zip(io.in.map(_.valid)).foreach { case ((out, in), valid) =>
385    out := Mux(io.stallReason.in.backReason.valid,
386               io.stallReason.in.backReason.bits,
387               Mux(valid, TopDownCounters.NoStall.id.U, in))
388  }
389
390  XSDebug(io.robCommits.isWalk, p"Walk Recovery Enabled\n")
391  XSDebug(io.robCommits.isWalk, p"validVec:${Binary(io.robCommits.walkValid.asUInt)}\n")
392  for (i <- 0 until CommitWidth) {
393    val info = io.robCommits.info(i)
394    XSDebug(io.robCommits.isWalk && io.robCommits.walkValid(i), p"[#$i walk info] pc:${Hexadecimal(info.pc)} " +
395      p"ldest:${info.ldest} rfWen:${info.rfWen} fpWen:${info.fpWen} ")
396  }
397
398  XSDebug(p"inValidVec: ${Binary(Cat(io.in.map(_.valid)))}\n")
399
400  XSPerfAccumulate("in", Mux(RegNext(io.in(0).ready), PopCount(io.in.map(_.valid)), 0.U))
401  XSPerfAccumulate("utilization", PopCount(io.in.map(_.valid)))
402  XSPerfAccumulate("waitInstr", PopCount((0 until RenameWidth).map(i => io.in(i).valid && !io.in(i).ready)))
403  XSPerfAccumulate("stall_cycle_dispatch", hasValid && !io.out(0).ready && fpFreeList.io.canAllocate && intFreeList.io.canAllocate && !io.robCommits.isWalk)
404  XSPerfAccumulate("stall_cycle_fp", hasValid && io.out(0).ready && !fpFreeList.io.canAllocate && intFreeList.io.canAllocate && !io.robCommits.isWalk)
405  XSPerfAccumulate("stall_cycle_int", hasValid && io.out(0).ready && fpFreeList.io.canAllocate && !intFreeList.io.canAllocate && !io.robCommits.isWalk)
406  XSPerfAccumulate("stall_cycle_walk", hasValid && io.out(0).ready && fpFreeList.io.canAllocate && intFreeList.io.canAllocate && io.robCommits.isWalk)
407
408  XSPerfHistogram("slots_fire", PopCount(io.out.map(_.fire)), true.B, 0, RenameWidth+1, 1)
409  // Explaination: when out(0) not fire, PopCount(valid) is not meaningfull
410  XSPerfHistogram("slots_valid_pure", PopCount(io.in.map(_.valid)), io.out(0).fire, 0, RenameWidth+1, 1)
411  XSPerfHistogram("slots_valid_rough", PopCount(io.in.map(_.valid)), true.B, 0, RenameWidth+1, 1)
412
413  XSPerfAccumulate("move_instr_count", PopCount(io.out.map(out => out.fire && out.bits.ctrl.isMove)))
414  val is_fused_lui_load = io.out.map(o => o.fire && o.bits.ctrl.fuType === FuType.ldu && o.bits.ctrl.srcType(0) === SrcType.imm)
415  XSPerfAccumulate("fused_lui_load_instr_count", PopCount(is_fused_lui_load))
416
417
418  val renamePerf = Seq(
419    ("rename_in                  ", PopCount(io.in.map(_.valid & io.in(0).ready ))                                                               ),
420    ("rename_waitinstr           ", PopCount((0 until RenameWidth).map(i => io.in(i).valid && !io.in(i).ready))                                  ),
421    ("rename_stall_cycle_dispatch", hasValid && !io.out(0).ready &&  fpFreeList.io.canAllocate &&  intFreeList.io.canAllocate && !io.robCommits.isWalk),
422    ("rename_stall_cycle_fp      ", hasValid &&  io.out(0).ready && !fpFreeList.io.canAllocate &&  intFreeList.io.canAllocate && !io.robCommits.isWalk),
423    ("rename_stall_cycle_int     ", hasValid &&  io.out(0).ready &&  fpFreeList.io.canAllocate && !intFreeList.io.canAllocate && !io.robCommits.isWalk),
424    ("rename_stall_cycle_walk    ", hasValid &&  io.out(0).ready &&  fpFreeList.io.canAllocate &&  intFreeList.io.canAllocate &&  io.robCommits.isWalk)
425  )
426  val intFlPerf = intFreeList.getPerfEvents
427  val fpFlPerf = fpFreeList.getPerfEvents
428  val perfEvents = renamePerf ++ intFlPerf ++ fpFlPerf
429  generatePerfEvent()
430}
431