xref: /XiangShan/src/main/scala/xiangshan/backend/rename/Rename.scala (revision 708ceed4afe43fb0ea3a52407e46b2794c573634)
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 chipsalliance.rocketchip.config.Parameters
20import chisel3._
21import chisel3.util._
22import xiangshan._
23import utils._
24import xiangshan.backend.roq.RoqPtr
25import xiangshan.backend.dispatch.PreDispatchInfo
26
27class RenameBypassInfo(implicit p: Parameters) extends XSBundle {
28  val lsrc1_bypass = MixedVec(List.tabulate(RenameWidth-1)(i => UInt((i+1).W)))
29  val lsrc2_bypass = MixedVec(List.tabulate(RenameWidth-1)(i => UInt((i+1).W)))
30  val lsrc3_bypass = MixedVec(List.tabulate(RenameWidth-1)(i => UInt((i+1).W)))
31  val ldest_bypass = MixedVec(List.tabulate(RenameWidth-1)(i => UInt((i+1).W)))
32}
33
34class Rename(implicit p: Parameters) extends XSModule {
35  val io = IO(new Bundle() {
36    val redirect = Flipped(ValidIO(new Redirect))
37    val flush = Input(Bool())
38    val roqCommits = Flipped(new RoqCommitIO)
39    // from decode buffer
40    val in = Vec(RenameWidth, Flipped(DecoupledIO(new CfCtrl)))
41    // to dispatch1
42    val out = Vec(RenameWidth, DecoupledIO(new MicroOp))
43    val renameBypass = Output(new RenameBypassInfo)
44    val dispatchInfo = Output(new PreDispatchInfo)
45    // for debug printing
46    val debug_int_rat = Vec(32, Output(UInt(PhyRegIdxWidth.W)))
47    val debug_fp_rat = Vec(32, Output(UInt(PhyRegIdxWidth.W)))
48  })
49
50  // create free list and rat
51  val intFreeList = Module(if (EnableIntMoveElim) new freelist.MEFreeList else new freelist.StdFreeList)
52  val fpFreeList = Module(new freelist.StdFreeList)
53
54  val intRat = Module(new RenameTable(float = false))
55  val fpRat = Module(new RenameTable(float = true))
56
57  // connect flush and redirect ports for rat
58  Seq(intRat, fpRat) foreach { case rat =>
59    rat.io.redirect := io.redirect.valid
60    rat.io.flush := io.flush
61    rat.io.walkWen := io.roqCommits.isWalk
62  }
63
64  // decide if given instruction needs allocating a new physical register (CfCtrl: from decode; RoqCommitInfo: from roq)
65  def needDestReg[T <: CfCtrl](fp: Boolean, x: T): Bool = {
66    {if(fp) x.ctrl.fpWen else x.ctrl.rfWen && (x.ctrl.ldest =/= 0.U)}
67  }
68  def needDestRegCommit[T <: RoqCommitInfo](fp: Boolean, x: T): Bool = {
69    {if(fp) x.fpWen else x.rfWen && (x.ldest =/= 0.U)}
70  }
71
72  // connect [flush + redirect + walk] ports for __float point__ & __integer__ free list
73  Seq((fpFreeList, true), (intFreeList, false)).foreach{ case (fl, isFp) =>
74    fl.flush := io.flush
75    fl.redirect := io.redirect.valid
76    fl.walk := io.roqCommits.isWalk
77    // when isWalk, use stepBack to restore head pointer of free list
78    // (if ME enabled, stepBack of intFreeList should be useless thus optimized out)
79    fl.stepBack := PopCount(io.roqCommits.valid.zip(io.roqCommits.info).map{case (v, i) => v && needDestRegCommit(isFp, i)})
80  }
81  // walk has higher priority than allocation and thus we don't use isWalk here
82  // only when both fp and int free list and dispatch1 has enough space can we do allocation
83  intFreeList.doAllocate := fpFreeList.canAllocate && io.out(0).ready
84  fpFreeList.doAllocate := intFreeList.canAllocate && io.out(0).ready
85
86  //           dispatch1 ready ++ float point free list ready ++ int free list ready      ++ not walk
87  val canOut = io.out(0).ready && fpFreeList.canAllocate && intFreeList.canAllocate && !io.roqCommits.isWalk
88
89
90  // speculatively assign the instruction with an roqIdx
91  val validCount = PopCount(io.in.map(_.valid)) // number of instructions waiting to enter roq (from decode)
92  val roqIdxHead = RegInit(0.U.asTypeOf(new RoqPtr))
93  val lastCycleMisprediction = RegNext(io.redirect.valid && !io.redirect.bits.flushItself())
94  val roqIdxHeadNext = Mux(io.flush, 0.U.asTypeOf(new RoqPtr), // flush: clear roq
95              Mux(io.redirect.valid, io.redirect.bits.roqIdx, // redirect: move ptr to given roq index (flush itself)
96         Mux(lastCycleMisprediction, roqIdxHead + 1.U, // mis-predict: not flush roqIdx itself
97                         Mux(canOut, roqIdxHead + validCount, // instructions successfully entered next stage: increase roqIdx
98                      /* default */  roqIdxHead)))) // no instructions passed by this cycle: stick to old value
99  roqIdxHead := roqIdxHeadNext
100
101
102  /**
103    * Rename: allocate free physical register and update rename table
104    */
105  val uops = Wire(Vec(RenameWidth, new MicroOp))
106  uops.foreach( uop => {
107    uop.srcState(0) := DontCare
108    uop.srcState(1) := DontCare
109    uop.srcState(2) := DontCare
110    uop.roqIdx := DontCare
111    uop.diffTestDebugLrScValid := DontCare
112    uop.debugInfo := DontCare
113    uop.lqIdx := DontCare
114    uop.sqIdx := DontCare
115  })
116
117  val needFpDest = Wire(Vec(RenameWidth, Bool()))
118  val needIntDest = Wire(Vec(RenameWidth, Bool()))
119  val hasValid = Cat(io.in.map(_.valid)).orR
120
121  val isMove = io.in.map(_.bits.ctrl.isMove)
122  val isMax = if (EnableIntMoveElim) Some(intFreeList.asInstanceOf[freelist.MEFreeList].maxVec) else None
123  val meEnable = WireInit(VecInit(Seq.fill(RenameWidth)(false.B)))
124  val psrc_cmp = Wire(MixedVec(List.tabulate(RenameWidth-1)(i => UInt((i+1).W))))
125  val intPsrc = Wire(Vec(RenameWidth, UInt()))
126
127  val intSpecWen = Wire(Vec(RenameWidth, Bool()))
128  val fpSpecWen = Wire(Vec(RenameWidth, Bool()))
129
130  // uop calculation
131  for (i <- 0 until RenameWidth) {
132    uops(i).cf := io.in(i).bits.cf
133    uops(i).ctrl := io.in(i).bits.ctrl
134
135    val inValid = io.in(i).valid
136
137    // alloc a new phy reg
138    needFpDest(i) := inValid && needDestReg(fp = true, io.in(i).bits)
139    needIntDest(i) := inValid && needDestReg(fp = false, io.in(i).bits)
140    fpFreeList.allocateReq(i) := needFpDest(i)
141    intFreeList.allocateReq(i) := needIntDest(i)
142
143    // no valid instruction from decode stage || all resources (dispatch1 + both free lists) ready
144    io.in(i).ready := !hasValid || canOut
145
146    // do checkpoints when a branch inst come
147    // for(fl <- Seq(fpFreeList, intFreeList)){
148    //   fl.cpReqs(i).valid := inValid
149    //   fl.cpReqs(i).bits := io.in(i).bits.brTag
150    // }
151
152    uops(i).roqIdx := roqIdxHead + PopCount(io.in.take(i).map(_.valid))
153
154    // read rename table
155    def readRat(lsrcList: List[UInt], ldest: UInt, fp: Boolean) = {
156      val rat = if(fp) fpRat else intRat
157      val srcCnt = lsrcList.size
158      val psrcVec = Wire(Vec(srcCnt, UInt(PhyRegIdxWidth.W)))
159      val old_pdest = Wire(UInt(PhyRegIdxWidth.W))
160      for(k <- 0 until srcCnt+1){
161        val rportIdx = i * (srcCnt+1) + k
162        if(k != srcCnt){
163          rat.io.readPorts(rportIdx).addr := lsrcList(k)
164          psrcVec(k) := rat.io.readPorts(rportIdx).rdata
165        } else {
166          rat.io.readPorts(rportIdx).addr := ldest
167          old_pdest := rat.io.readPorts(rportIdx).rdata
168        }
169      }
170      (psrcVec, old_pdest)
171    }
172    val lsrcList = List(uops(i).ctrl.lsrc(0), uops(i).ctrl.lsrc(1), uops(i).ctrl.lsrc(2))
173    val ldest = uops(i).ctrl.ldest
174    val (intPhySrcVec, intOldPdest) = readRat(lsrcList.take(2), ldest, fp = false)
175    intPsrc(i) := intPhySrcVec(0)
176    val (fpPhySrcVec, fpOldPdest) = readRat(lsrcList, ldest, fp = true)
177    uops(i).psrc(0) := Mux(uops(i).ctrl.srcType(0) === SrcType.reg, intPhySrcVec(0), fpPhySrcVec(0))
178    uops(i).psrc(1) := Mux(uops(i).ctrl.srcType(1) === SrcType.reg, intPhySrcVec(1), fpPhySrcVec(1))
179    uops(i).psrc(2) := fpPhySrcVec(2)
180    uops(i).old_pdest := Mux(uops(i).ctrl.rfWen, intOldPdest, fpOldPdest)
181
182    if (EnableIntMoveElim) {
183
184      if (i == 0) {
185        // calculate meEnable
186        meEnable(i) := isMove(i) && (!isMax.get(intPsrc(i)) || uops(i).ctrl.lsrc(0) === 0.U)
187      } else {
188        // compare psrc0
189        psrc_cmp(i-1) := Cat((0 until i).map(j => {
190          intPsrc(i) === intPsrc(j) && io.in(i).bits.ctrl.isMove && io.in(j).bits.ctrl.isMove
191        }) /* reverse is not necessary here */)
192
193        // calculate meEnable
194        meEnable(i) := isMove(i) && (!(io.renameBypass.lsrc1_bypass(i-1).orR | psrc_cmp(i-1).orR | isMax.get(intPsrc(i))) || uops(i).ctrl.lsrc(0) === 0.U)
195      }
196      uops(i).eliminatedMove := meEnable(i) || (uops(i).ctrl.isMove && uops(i).ctrl.ldest === 0.U)
197
198      // send psrc of eliminated move instructions to free list and label them as eliminated
199      intFreeList.asInstanceOf[freelist.MEFreeList].psrcOfMove(i).valid := meEnable(i)
200      intFreeList.asInstanceOf[freelist.MEFreeList].psrcOfMove(i).bits := intPsrc(i)
201      // when (meEnable(i)) {
202      //   XSInfo(io.in(i).valid && io.out(i).valid, p"Move instruction ${Hexadecimal(io.in(i).bits.cf.pc)} eliminated successfully! psrc:${uops(i).psrc(0)}\n")
203      // } .otherwise {
204      //   XSInfo(io.in(i).valid && io.out(i).valid && isMove(i), p"Move instruction ${Hexadecimal(io.in(i).bits.cf.pc)} failed to be eliminated! psrc:${uops(i).psrc(0)}\n")
205      // }
206
207      // update pdest
208      uops(i).pdest := Mux(meEnable(i), intPsrc(i), // move eliminated
209                       Mux(needIntDest(i), intFreeList.allocatePhyReg(i), // normal int inst
210                       Mux(uops(i).ctrl.ldest===0.U && uops(i).ctrl.rfWen, 0.U // int inst with dst=r0
211                       /* default */, fpFreeList.allocatePhyReg(i)))) // normal fp inst
212    } else {
213      uops(i).eliminatedMove := DontCare
214      psrc_cmp.foreach(_ := DontCare)
215      // update pdest
216      uops(i).pdest := Mux(needIntDest(i), intFreeList.allocatePhyReg(i), // normal int inst
217                       Mux(uops(i).ctrl.ldest===0.U && uops(i).ctrl.rfWen, 0.U // int inst with dst=r0
218                       /* default */, fpFreeList.allocatePhyReg(i))) // normal fp inst
219    }
220
221    // Assign performance counters
222    uops(i).debugInfo.renameTime := GTimer()
223
224    io.out(i).valid := io.in(i).valid && intFreeList.canAllocate && fpFreeList.canAllocate && !io.roqCommits.isWalk
225    io.out(i).bits := uops(i)
226
227    // write speculative rename table
228    // we update rat later inside commit code
229    intSpecWen(i) := intFreeList.allocateReq(i) && intFreeList.canAllocate && intFreeList.doAllocate && !io.roqCommits.isWalk
230    fpSpecWen(i) := fpFreeList.allocateReq(i) && fpFreeList.canAllocate && fpFreeList.doAllocate && !io.roqCommits.isWalk
231  }
232
233  // We don't bypass the old_pdest from valid instructions with the same ldest currently in rename stage.
234  // Instead, we determine whether there're some dependencies between the valid instructions.
235  for (i <- 1 until RenameWidth) {
236    io.renameBypass.lsrc1_bypass(i-1) := Cat((0 until i).map(j => {
237      val fpMatch  = needFpDest(j) && io.in(i).bits.ctrl.srcType(0) === SrcType.fp
238      val intMatch = needIntDest(j) && io.in(i).bits.ctrl.srcType(0) === SrcType.reg
239      (fpMatch || intMatch) && io.in(j).bits.ctrl.ldest === io.in(i).bits.ctrl.lsrc(0)
240    }).reverse)
241    io.renameBypass.lsrc2_bypass(i-1) := Cat((0 until i).map(j => {
242      val fpMatch  = needFpDest(j) && io.in(i).bits.ctrl.srcType(1) === SrcType.fp
243      val intMatch = needIntDest(j) && io.in(i).bits.ctrl.srcType(1) === SrcType.reg
244      (fpMatch || intMatch) && io.in(j).bits.ctrl.ldest === io.in(i).bits.ctrl.lsrc(1)
245    }).reverse)
246    io.renameBypass.lsrc3_bypass(i-1) := Cat((0 until i).map(j => {
247      val fpMatch  = needFpDest(j) && io.in(i).bits.ctrl.srcType(2) === SrcType.fp
248      val intMatch = needIntDest(j) && io.in(i).bits.ctrl.srcType(2) === SrcType.reg
249      (fpMatch || intMatch) && io.in(j).bits.ctrl.ldest === io.in(i).bits.ctrl.lsrc(2)
250    }).reverse)
251    io.renameBypass.ldest_bypass(i-1) := Cat((0 until i).map(j => {
252      val fpMatch  = needFpDest(j) && needFpDest(i)
253      val intMatch = needIntDest(j) && needIntDest(i)
254      (fpMatch || intMatch) && io.in(j).bits.ctrl.ldest === io.in(i).bits.ctrl.ldest
255    }).reverse)
256  }
257
258  // calculate lsq space requirement
259  val isLs    = VecInit(uops.map(uop => FuType.isLoadStore(uop.ctrl.fuType)))
260  val isStore = VecInit(uops.map(uop => FuType.isStoreExu(uop.ctrl.fuType)))
261  val isAMO   = VecInit(uops.map(uop => FuType.isAMO(uop.ctrl.fuType)))
262  io.dispatchInfo.lsqNeedAlloc := VecInit((0 until RenameWidth).map(i =>
263    Mux(isLs(i), Mux(isStore(i) && !isAMO(i), 2.U, 1.U), 0.U)))
264
265  /**
266    * Instructions commit: update freelist and rename table
267    */
268  for (i <- 0 until CommitWidth) {
269
270    Seq((intRat, false), (fpRat, true)) foreach { case (rat, fp) =>
271      // is valid commit req and given instruction has destination register
272      val commitDestValid = io.roqCommits.valid(i) && needDestRegCommit(fp, io.roqCommits.info(i))
273      XSDebug(p"isFp[${fp}]index[$i]-commitDestValid:$commitDestValid,isWalk:${io.roqCommits.isWalk}\n")
274
275      /*
276      I. RAT Update
277       */
278
279      // walk back write - restore spec state : ldest => old_pdest
280      if (fp && i < RenameWidth) {
281        rat.io.specWritePorts(i).wen := (commitDestValid && io.roqCommits.isWalk) || fpSpecWen(i)
282        rat.io.specWritePorts(i).addr := Mux(fpSpecWen(i), uops(i).ctrl.ldest, io.roqCommits.info(i).ldest)
283        rat.io.specWritePorts(i).wdata := Mux(fpSpecWen(i), fpFreeList.allocatePhyReg(i), io.roqCommits.info(i).old_pdest)
284      } else if (!fp && i < RenameWidth) {
285        rat.io.specWritePorts(i).wen := (commitDestValid && io.roqCommits.isWalk) || intSpecWen(i)
286        rat.io.specWritePorts(i).addr := Mux(intSpecWen(i), uops(i).ctrl.ldest, io.roqCommits.info(i).ldest)
287        if (EnableIntMoveElim) {
288          rat.io.specWritePorts(i).wdata :=
289            Mux(intSpecWen(i), Mux(meEnable(i), intPsrc(i), intFreeList.allocatePhyReg(i)), io.roqCommits.info(i).old_pdest)
290        } else {
291          rat.io.specWritePorts(i).wdata :=
292            Mux(intSpecWen(i), intFreeList.allocatePhyReg(i), io.roqCommits.info(i).old_pdest)
293        }
294      // when i >= RenameWidth, this write must happens during WALK process
295      } else if (i >= RenameWidth) {
296        rat.io.specWritePorts(i).wen := commitDestValid && io.roqCommits.isWalk
297        rat.io.specWritePorts(i).addr := io.roqCommits.info(i).ldest
298        rat.io.specWritePorts(i).wdata := io.roqCommits.info(i).old_pdest
299      }
300
301      when (commitDestValid && io.roqCommits.isWalk) {
302        XSInfo({if(fp) p"[fp" else p"[int"} + p" walk] " +
303          p"ldest:${rat.io.specWritePorts(i).addr} -> old_pdest:${rat.io.specWritePorts(i).wdata}\n")
304      }
305
306      // normal write - update arch state (serve as initialization)
307      rat.io.archWritePorts(i).wen := commitDestValid && !io.roqCommits.isWalk
308      rat.io.archWritePorts(i).addr := io.roqCommits.info(i).ldest
309      rat.io.archWritePorts(i).wdata := io.roqCommits.info(i).pdest
310
311      XSInfo(rat.io.archWritePorts(i).wen,
312        {if(fp) p"[fp" else p"[int"} + p" arch rat update] ldest:${rat.io.archWritePorts(i).addr} ->" +
313        p" pdest:${rat.io.archWritePorts(i).wdata}\n"
314      )
315
316
317      /*
318      II. Free List Update
319       */
320
321      if (fp) { // Float Point free list
322        fpFreeList.freeReq(i)  := commitDestValid && !io.roqCommits.isWalk
323        fpFreeList.freePhyReg(i) := io.roqCommits.info(i).old_pdest
324      } else if (EnableIntMoveElim) { // Integer free list
325
326        // during walk process:
327        // 1. for normal inst, free pdest + revert rat from ldest->pdest to ldest->old_pdest
328        // 2. for ME inst, free pdest(commit counter++) + revert rat
329
330        // conclusion:
331        // a. rat recovery has nothing to do with ME or not
332        // b. treat walk as normal commit except replace old_pdests with pdests and set io.walk to true
333        // c. ignore pdests port when walking
334
335        intFreeList.freeReq(i) := commitDestValid // walk or not walk
336        intFreeList.freePhyReg(i)  := Mux(io.roqCommits.isWalk, io.roqCommits.info(i).pdest, io.roqCommits.info(i).old_pdest)
337        intFreeList.asInstanceOf[freelist.MEFreeList].eliminatedMove(i) := io.roqCommits.info(i).eliminatedMove
338        intFreeList.asInstanceOf[freelist.MEFreeList].multiRefPhyReg(i) := io.roqCommits.info(i).pdest
339      } else {
340        intFreeList.freeReq(i) := commitDestValid && !io.roqCommits.isWalk
341        intFreeList.freePhyReg(i)  := io.roqCommits.info(i).old_pdest
342      }
343    }
344  }
345
346
347  /*
348  Debug and performance counter
349   */
350
351  def printRenameInfo(in: DecoupledIO[CfCtrl], out: DecoupledIO[MicroOp]) = {
352    XSInfo(
353      in.valid && in.ready,
354      p"pc:${Hexadecimal(in.bits.cf.pc)} in v:${in.valid} in rdy:${in.ready} " +
355        p"lsrc(0):${in.bits.ctrl.lsrc(0)} -> psrc(0):${out.bits.psrc(0)} " +
356        p"lsrc(1):${in.bits.ctrl.lsrc(1)} -> psrc(1):${out.bits.psrc(1)} " +
357        p"lsrc(2):${in.bits.ctrl.lsrc(2)} -> psrc(2):${out.bits.psrc(2)} " +
358        p"ldest:${in.bits.ctrl.ldest} -> pdest:${out.bits.pdest} " +
359        p"old_pdest:${out.bits.old_pdest} " +
360        p"out v:${out.valid} r:${out.ready}\n"
361    )
362  }
363
364  for((x,y) <- io.in.zip(io.out)){
365    printRenameInfo(x, y)
366  }
367
368  XSDebug(io.roqCommits.isWalk, p"Walk Recovery Enabled\n")
369  XSDebug(io.roqCommits.isWalk, p"validVec:${Binary(io.roqCommits.valid.asUInt)}\n")
370  for (i <- 0 until CommitWidth) {
371    val info = io.roqCommits.info(i)
372    XSDebug(io.roqCommits.isWalk && io.roqCommits.valid(i), p"[#$i walk info] pc:${Hexadecimal(info.pc)} " +
373      p"ldest:${info.ldest} rfWen:${info.rfWen} fpWen:${info.fpWen} " + { if (EnableIntMoveElim) p"eliminatedMove:${info.eliminatedMove} " else p"" } +
374      p"pdest:${info.pdest} old_pdest:${info.old_pdest}\n")
375  }
376
377  XSDebug(p"inValidVec: ${Binary(Cat(io.in.map(_.valid)))}\n")
378  XSInfo(!canOut, p"stall at rename, hasValid:${hasValid}, fpCanAlloc:${fpFreeList.canAllocate}, intCanAlloc:${intFreeList.canAllocate} dispatch1ready:${io.out(0).ready}, isWalk:${io.roqCommits.isWalk}\n")
379
380  intRat.io.debug_rdata <> io.debug_int_rat
381  fpRat.io.debug_rdata <> io.debug_fp_rat
382
383  XSDebug(p"Arch Int RAT:" + io.debug_int_rat.zipWithIndex.map{ case (r, i) => p"#$i:$r " }.reduceLeft(_ + _) + p"\n")
384
385  XSPerfAccumulate("in", Mux(RegNext(io.in(0).ready), PopCount(io.in.map(_.valid)), 0.U))
386  XSPerfAccumulate("utilization", PopCount(io.in.map(_.valid)))
387  XSPerfAccumulate("waitInstr", PopCount((0 until RenameWidth).map(i => io.in(i).valid && !io.in(i).ready)))
388  XSPerfAccumulate("stall_cycle_dispatch", hasValid && !io.out(0).ready && fpFreeList.canAllocate && intFreeList.canAllocate && !io.roqCommits.isWalk)
389  XSPerfAccumulate("stall_cycle_fp", hasValid && io.out(0).ready && !fpFreeList.canAllocate && intFreeList.canAllocate && !io.roqCommits.isWalk)
390  XSPerfAccumulate("stall_cycle_int", hasValid && io.out(0).ready && fpFreeList.canAllocate && !intFreeList.canAllocate && !io.roqCommits.isWalk)
391  XSPerfAccumulate("stall_cycle_walk", hasValid && io.out(0).ready && fpFreeList.canAllocate && intFreeList.canAllocate && io.roqCommits.isWalk)
392  if (!env.FPGAPlatform) {
393    ExcitingUtils.addSource(io.roqCommits.isWalk, "TMA_backendiswalk")
394  }
395
396  if (EnableIntMoveElim) {
397    XSPerfAccumulate("move_instr_count", PopCount(Seq.tabulate(RenameWidth)(i => io.out(i).fire() && io.in(i).bits.ctrl.isMove)))
398    XSPerfAccumulate("move_elim_enabled", PopCount(Seq.tabulate(RenameWidth)(i => io.out(i).fire() && meEnable(i))))
399    XSPerfAccumulate("move_elim_cancelled", PopCount(Seq.tabulate(RenameWidth)(i => io.out(i).fire() && io.in(i).bits.ctrl.isMove && !meEnable(i))))
400    XSPerfAccumulate("move_elim_cancelled_psrc_bypass", PopCount(Seq.tabulate(RenameWidth)(i => io.out(i).fire() && io.in(i).bits.ctrl.isMove && !meEnable(i) && { if (i == 0) false.B else io.renameBypass.lsrc1_bypass(i-1).orR })))
401    XSPerfAccumulate("move_elim_cancelled_cnt_limit", PopCount(Seq.tabulate(RenameWidth)(i => io.out(i).fire() && io.in(i).bits.ctrl.isMove && !meEnable(i) && isMax.get(io.out(i).bits.psrc(0)))))
402    XSPerfAccumulate("move_elim_cancelled_inc_more_than_one", PopCount(Seq.tabulate(RenameWidth)(i => io.out(i).fire() && io.in(i).bits.ctrl.isMove && !meEnable(i) && { if (i == 0) false.B else psrc_cmp(i-1).orR })))
403
404    // to make sure meEnable functions as expected
405    for (i <- 0 until RenameWidth) {
406      XSDebug(io.out(i).fire() && io.in(i).bits.ctrl.isMove && !meEnable(i) && isMax.get(io.out(i).bits.psrc(0)),
407        p"ME_CANCELLED: ref counter hits max value (pc:0x${Hexadecimal(io.in(i).bits.cf.pc)})\n")
408      XSDebug(io.out(i).fire() && io.in(i).bits.ctrl.isMove && !meEnable(i) && { if (i == 0) false.B else io.renameBypass.lsrc1_bypass(i-1).orR },
409        p"ME_CANCELLED: RAW dependency (pc:0x${Hexadecimal(io.in(i).bits.cf.pc)})\n")
410      XSDebug(io.out(i).fire() && io.in(i).bits.ctrl.isMove && !meEnable(i) && { if (i == 0) false.B else psrc_cmp(i-1).orR },
411        p"ME_CANCELLED: psrc duplicates with former instruction (pc:0x${Hexadecimal(io.in(i).bits.cf.pc)})\n")
412    }
413    XSDebug(VecInit(Seq.tabulate(RenameWidth)(i => io.out(i).fire() && io.in(i).bits.ctrl.isMove && !meEnable(i))).asUInt().orR,
414      p"ME_CANCELLED: pc group [ " + (0 until RenameWidth).map(i => p"fire:${io.out(i).fire()},pc:0x${Hexadecimal(io.in(i).bits.cf.pc)} ").reduceLeft(_ + _) + p"]\n")
415    XSInfo(meEnable.asUInt().orR(), p"meEnableVec:${Binary(meEnable.asUInt)}\n")
416  }
417}
418