xref: /XiangShan/src/main/scala/xiangshan/mem/lsqueue/LoadQueueReplay.scala (revision 0466583513e4c1ddbbb566b866b8963635acb20f)
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***************************************************************************************/
16package xiangshan.mem
17
18import chisel3._
19import chisel3.util._
20import chipsalliance.rocketchip.config._
21import xiangshan._
22import xiangshan.backend.rob.{RobPtr, RobLsqIO}
23import xiangshan.cache._
24import xiangshan.backend.fu.fpu.FPU
25import xiangshan.cache._
26import xiangshan.frontend.FtqPtr
27import xiangshan.ExceptionNO._
28import xiangshan.cache.wpu.ReplayCarry
29import xiangshan.mem.mdp._
30import utils._
31import utility._
32
33object LoadReplayCauses {
34  // these causes have priority, lower coding has higher priority.
35  // when load replay happens, load unit will select highest priority
36  // from replay causes vector
37
38  /*
39   * Warning:
40   * ************************************************************
41   * * Don't change the priority. If the priority is changed,   *
42   * * deadlock may occur. If you really need to change or      *
43   * * add priority, please ensure that no deadlock will occur. *
44   * ************************************************************
45   *
46   */
47  // tlb miss check
48  val C_TM  = 0
49  // st-ld violation
50  val C_NK  = 1
51  // st-ld violation re-execute check
52  val C_MA  = 2
53  // store-to-load-forwarding check
54  val C_FF  = 3
55  // dcache replay check
56  val C_DR  = 4
57  // dcache miss check
58  val C_DM  = 5
59  // dcache bank conflict check
60  val C_BC  = 6
61  // RAR queue accept check
62  val C_RAR = 7
63  // RAW queue accept check
64  val C_RAW = 8
65  // total causes
66  val allCauses         = 9
67}
68
69class AgeDetector(numEntries: Int, numEnq: Int, regOut: Boolean = true)(implicit p: Parameters) extends XSModule {
70  val io = IO(new Bundle {
71    // NOTE: deq and enq may come at the same cycle.
72    val enq = Vec(numEnq, Input(UInt(numEntries.W)))
73    val deq = Input(UInt(numEntries.W))
74    val ready = Input(UInt(numEntries.W))
75    val out = Output(UInt(numEntries.W))
76  })
77
78  // age(i)(j): entry i enters queue before entry j
79  val age = Seq.fill(numEntries)(Seq.fill(numEntries)(RegInit(false.B)))
80  val nextAge = Seq.fill(numEntries)(Seq.fill(numEntries)(Wire(Bool())))
81
82  // to reduce reg usage, only use upper matrix
83  def get_age(row: Int, col: Int): Bool = if (row <= col) age(row)(col) else !age(col)(row)
84  def get_next_age(row: Int, col: Int): Bool = if (row <= col) nextAge(row)(col) else !nextAge(col)(row)
85  def isFlushed(i: Int): Bool = io.deq(i)
86  def isEnqueued(i: Int, numPorts: Int = -1): Bool = {
87    val takePorts = if (numPorts == -1) io.enq.length else numPorts
88    takePorts match {
89      case 0 => false.B
90      case 1 => io.enq.head(i) && !isFlushed(i)
91      case n => VecInit(io.enq.take(n).map(_(i))).asUInt.orR && !isFlushed(i)
92    }
93  }
94
95  for ((row, i) <- nextAge.zipWithIndex) {
96    val thisValid = get_age(i, i) || isEnqueued(i)
97    for ((elem, j) <- row.zipWithIndex) {
98      when (isFlushed(i)) {
99        // (1) when entry i is flushed or dequeues, set row(i) to false.B
100        elem := false.B
101      }.elsewhen (isFlushed(j)) {
102        // (2) when entry j is flushed or dequeues, set column(j) to validVec
103        elem := thisValid
104      }.elsewhen (isEnqueued(i)) {
105        // (3) when entry i enqueues from port k,
106        // (3.1) if entry j enqueues from previous ports, set to false
107        // (3.2) otherwise, set to true if and only of entry j is invalid
108        // overall: !jEnqFromPreviousPorts && !jIsValid
109        val sel = io.enq.map(_(i))
110        val result = (0 until numEnq).map(k => isEnqueued(j, k))
111        // why ParallelMux: sel must be one-hot since enq is one-hot
112        elem := !get_age(j, j) && !ParallelMux(sel, result)
113      }.otherwise {
114        // default: unchanged
115        elem := get_age(i, j)
116      }
117      age(i)(j) := elem
118    }
119  }
120
121  def getOldest(get: (Int, Int) => Bool): UInt = {
122    VecInit((0 until numEntries).map(i => {
123      io.ready(i) & VecInit((0 until numEntries).map(j => if (i != j) !io.ready(j) || get(i, j) else true.B)).asUInt.andR
124    })).asUInt
125  }
126  val best = getOldest(get_age)
127  val nextBest = getOldest(get_next_age)
128
129  io.out := (if (regOut) best else nextBest)
130}
131
132object AgeDetector {
133  def apply(numEntries: Int, enq: Vec[UInt], deq: UInt, ready: UInt)(implicit p: Parameters): Valid[UInt] = {
134    val age = Module(new AgeDetector(numEntries, enq.length, regOut = true))
135    age.io.enq := enq
136    age.io.deq := deq
137    age.io.ready:= ready
138    val out = Wire(Valid(UInt(deq.getWidth.W)))
139    out.valid := age.io.out.orR
140    out.bits := age.io.out
141    out
142  }
143}
144
145
146class LoadQueueReplay(implicit p: Parameters) extends XSModule
147  with HasDCacheParameters
148  with HasCircularQueuePtrHelper
149  with HasLoadHelper
150  with HasPerfEvents
151{
152  val io = IO(new Bundle() {
153    // control
154    val redirect = Flipped(ValidIO(new Redirect))
155
156    // from load unit s3
157    val enq = Vec(LoadPipelineWidth, Flipped(Decoupled(new LqWriteBundle)))
158
159    // from sta s1
160    val storeAddrIn = Vec(StorePipelineWidth, Flipped(Valid(new LsPipelineBundle)))
161
162    // from std s1
163    val storeDataIn = Vec(StorePipelineWidth, Flipped(Valid(new ExuOutput)))
164
165    // queue-based replay
166    val replay = Vec(LoadPipelineWidth, Decoupled(new LsPipelineBundle))
167    val refill = Flipped(ValidIO(new Refill))
168
169    // from StoreQueue
170    val stAddrReadySqPtr = Input(new SqPtr)
171    val stAddrReadyVec   = Input(Vec(StoreQueueSize, Bool()))
172    val stDataReadySqPtr = Input(new SqPtr)
173    val stDataReadyVec   = Input(Vec(StoreQueueSize, Bool()))
174
175    //
176    val sqEmpty = Input(Bool())
177    val lqFull  = Output(Bool())
178    val ldWbPtr = Input(new LqPtr)
179    val rarFull = Input(Bool())
180    val rawFull = Input(Bool())
181    val l2_hint  = Input(Valid(new L2ToL1Hint()))
182    val tlbReplayDelayCycleCtrl = Vec(4, Input(UInt(ReSelectLen.W)))
183  })
184
185  println("LoadQueueReplay size: " + LoadQueueReplaySize)
186  //  LoadQueueReplay field:
187  //  +-----------+---------+-------+-------------+--------+
188  //  | Allocated | MicroOp | VAddr |    Cause    |  Flags |
189  //  +-----------+---------+-------+-------------+--------+
190  //  Allocated   : entry has been allocated already
191  //  MicroOp     : inst's microOp
192  //  VAddr       : virtual address
193  //  Cause       : replay cause
194  //  Flags       : rar/raw queue allocate flags
195  val allocated = RegInit(VecInit(List.fill(LoadQueueReplaySize)(false.B))) // The control signals need to explicitly indicate the initial value
196  val scheduled = RegInit(VecInit(List.fill(LoadQueueReplaySize)(false.B)))
197  val uop = Reg(Vec(LoadQueueReplaySize, new MicroOp))
198  val vaddrModule = Module(new LqVAddrModule(
199    gen = UInt(VAddrBits.W),
200    numEntries = LoadQueueReplaySize,
201    numRead = LoadPipelineWidth,
202    numWrite = LoadPipelineWidth,
203    numWBank = LoadQueueNWriteBanks,
204    numWDelay = 2,
205    numCamPort = 0))
206  vaddrModule.io := DontCare
207  val debug_vaddr = RegInit(VecInit(List.fill(LoadQueueReplaySize)(0.U(VAddrBits.W))))
208  val cause = RegInit(VecInit(List.fill(LoadQueueReplaySize)(0.U(LoadReplayCauses.allCauses.W))))
209
210  // freeliset: store valid entries index.
211  // +---+---+--------------+-----+-----+
212  // | 0 | 1 |      ......  | n-2 | n-1 |
213  // +---+---+--------------+-----+-----+
214  val freeList = Module(new FreeList(
215    size = LoadQueueReplaySize,
216    allocWidth = LoadPipelineWidth,
217    freeWidth = 4,
218    moduleName = "LoadQueueReplay freelist"
219  ))
220  freeList.io := DontCare
221  /**
222   * used for re-select control
223   */
224  val credit = RegInit(VecInit(List.fill(LoadQueueReplaySize)(0.U(ReSelectLen.W))))
225  val selBlocked = RegInit(VecInit(List.fill(LoadQueueReplaySize)(false.B)))
226  //  Ptrs to control which cycle to choose
227  val blockPtrTlb = RegInit(VecInit(List.fill(LoadQueueReplaySize)(0.U(2.W))))
228  val blockPtrCache = RegInit(VecInit(List.fill(LoadQueueReplaySize)(0.U(2.W))))
229  val blockPtrOthers = RegInit(VecInit(List.fill(LoadQueueReplaySize)(0.U(2.W))))
230  //  Specific cycles to block
231  val blockCyclesTlb = Reg(Vec(4, UInt(ReSelectLen.W)))
232  blockCyclesTlb := io.tlbReplayDelayCycleCtrl
233  val blockCyclesCache = RegInit(VecInit(Seq(0.U(ReSelectLen.W), 0.U(ReSelectLen.W), 0.U(ReSelectLen.W), 0.U(ReSelectLen.W))))
234  val blockCyclesOthers = RegInit(VecInit(Seq(0.U(ReSelectLen.W), 0.U(ReSelectLen.W), 0.U(ReSelectLen.W), 0.U(ReSelectLen.W))))
235  val blockSqIdx = Reg(Vec(LoadQueueReplaySize, new SqPtr))
236  // block causes
237  val blockByTlbMiss = RegInit(VecInit(List.fill(LoadQueueReplaySize)(false.B)))
238  val blockByForwardFail = RegInit(VecInit(List.fill(LoadQueueReplaySize)(false.B)))
239  val blockByMemAmb = RegInit(VecInit(List.fill(LoadQueueReplaySize)(false.B)))
240  val blockByCacheMiss = RegInit(VecInit(List.fill(LoadQueueReplaySize)(false.B)))
241  val blockByRARReject = RegInit(VecInit(List.fill(LoadQueueReplaySize)(false.B)))
242  val blockByRAWReject = RegInit(VecInit(List.fill(LoadQueueReplaySize)(false.B)))
243  val blockByOthers = RegInit(VecInit(List.fill(LoadQueueReplaySize)(false.B)))
244  // DCache miss block
245  val missMSHRId = RegInit(VecInit(List.fill(LoadQueueReplaySize)(0.U((log2Up(cfg.nMissEntries).W)))))
246  // Has this load already updated dcache replacement?
247  val replacementUpdated = RegInit(VecInit(List.fill(LoadQueueReplaySize)(false.B)))
248  val trueCacheMissReplay = WireInit(VecInit(cause.map(_(LoadReplayCauses.C_DM))))
249  val creditUpdate = WireInit(VecInit(List.fill(LoadQueueReplaySize)(0.U(ReSelectLen.W))))
250  (0 until LoadQueueReplaySize).map(i => {
251    creditUpdate(i) := Mux(credit(i) > 0.U(ReSelectLen.W), credit(i)-1.U(ReSelectLen.W), credit(i))
252    selBlocked(i) := creditUpdate(i) =/= 0.U(ReSelectLen.W) || credit(i) =/= 0.U(ReSelectLen.W)
253  })
254  val replayCarryReg = RegInit(VecInit(List.fill(LoadQueueReplaySize)(ReplayCarry(nWays, 0.U, false.B))))
255  val dataInLastBeatReg = RegInit(VecInit(List.fill(LoadQueueReplaySize)(false.B)))
256
257  /**
258   * Enqueue
259   */
260  val canEnqueue = io.enq.map(_.valid)
261  val cancelEnq = io.enq.map(enq => enq.bits.uop.robIdx.needFlush(io.redirect))
262  val needReplay = io.enq.map(enq => enq.bits.rep_info.need_rep)
263  val hasExceptions = io.enq.map(enq => ExceptionNO.selectByFu(enq.bits.uop.cf.exceptionVec, lduCfg).asUInt.orR && !enq.bits.tlbMiss)
264  val loadReplay = io.enq.map(enq => enq.bits.isLoadReplay)
265  val needEnqueue = VecInit((0 until LoadPipelineWidth).map(w => {
266    canEnqueue(w) && !cancelEnq(w) && needReplay(w) && !hasExceptions(w)
267  }))
268  val canFreeVec = VecInit((0 until LoadPipelineWidth).map(w => {
269    canEnqueue(w) && loadReplay(w) && (!needReplay(w) || hasExceptions(w))
270  }))
271
272  // select LoadPipelineWidth valid index.
273  val lqFull = freeList.io.empty
274  val lqFreeNums = freeList.io.validCount
275
276  // replay logic
277  // release logic generation
278  val storeAddrInSameCycleVec = Wire(Vec(LoadQueueReplaySize, Bool()))
279  val storeDataInSameCycleVec = Wire(Vec(LoadQueueReplaySize, Bool()))
280  val addrNotBlockVec = Wire(Vec(LoadQueueReplaySize, Bool()))
281  val dataNotBlockVec = Wire(Vec(LoadQueueReplaySize, Bool()))
282  val storeAddrValidVec = addrNotBlockVec.asUInt | storeAddrInSameCycleVec.asUInt
283  val storeDataValidVec = dataNotBlockVec.asUInt | storeDataInSameCycleVec.asUInt
284
285  // store data valid check
286  val stAddrReadyVec = io.stAddrReadyVec
287  val stDataReadyVec = io.stDataReadyVec
288
289  for (i <- 0 until LoadQueueReplaySize) {
290    // dequeue
291    //  FIXME: store*Ptr is not accurate
292    dataNotBlockVec(i) := !isBefore(io.stDataReadySqPtr, blockSqIdx(i)) || stDataReadyVec(blockSqIdx(i).value) || io.sqEmpty // for better timing
293    addrNotBlockVec(i) := !isBefore(io.stAddrReadySqPtr, blockSqIdx(i)) || stAddrReadyVec(blockSqIdx(i).value) || io.sqEmpty // for better timing
294
295    // store address execute
296    storeAddrInSameCycleVec(i) := VecInit((0 until StorePipelineWidth).map(w => {
297      io.storeAddrIn(w).valid &&
298      !io.storeAddrIn(w).bits.miss &&
299      blockSqIdx(i) === io.storeAddrIn(w).bits.uop.sqIdx
300    })).asUInt.orR // for better timing
301
302    // store data execute
303    storeDataInSameCycleVec(i) := VecInit((0 until StorePipelineWidth).map(w => {
304      io.storeDataIn(w).valid &&
305      blockSqIdx(i) === io.storeDataIn(w).bits.uop.sqIdx
306    })).asUInt.orR // for better timing
307
308  }
309
310  // store addr issue check
311  val stAddrDeqVec = Wire(Vec(LoadQueueReplaySize, Bool()))
312  (0 until LoadQueueReplaySize).map(i => {
313    stAddrDeqVec(i) := allocated(i) && storeAddrValidVec(i)
314  })
315
316  // store data issue check
317  val stDataDeqVec = Wire(Vec(LoadQueueReplaySize, Bool()))
318  (0 until LoadQueueReplaySize).map(i => {
319    stDataDeqVec(i) := allocated(i) && storeDataValidVec(i)
320  })
321
322  // update block condition
323  (0 until LoadQueueReplaySize).map(i => {
324    blockByForwardFail(i) := Mux(blockByForwardFail(i) && stDataDeqVec(i), false.B, blockByForwardFail(i))
325    blockByMemAmb(i) := Mux(blockByMemAmb(i) && stAddrDeqVec(i), false.B, blockByMemAmb(i))
326    blockByCacheMiss(i) := Mux(blockByCacheMiss(i) && io.refill.valid && io.refill.bits.id === missMSHRId(i), false.B, blockByCacheMiss(i))
327
328    when (blockByCacheMiss(i) && io.refill.valid && io.refill.bits.id === missMSHRId(i)) { creditUpdate(i) := 0.U }
329    when (blockByRARReject(i) && (!io.rarFull || !isAfter(uop(i).lqIdx, io.ldWbPtr))) { blockByRARReject(i) := false.B }
330    when (blockByRAWReject(i) && (!io.rawFull || !isAfter(uop(i).sqIdx, io.stAddrReadySqPtr))) { blockByRAWReject(i) := false.B }
331    when (blockByTlbMiss(i) && creditUpdate(i) === 0.U) { blockByTlbMiss(i) := false.B }
332    when (blockByOthers(i) && creditUpdate(i) === 0.U) { blockByOthers(i) := false.B }
333  })
334
335  //  Replay is splitted into 3 stages
336  require((LoadQueueReplaySize % LoadPipelineWidth) == 0)
337  def getRemBits(input: UInt)(rem: Int): UInt = {
338    VecInit((0 until LoadQueueReplaySize / LoadPipelineWidth).map(i => { input(LoadPipelineWidth * i + rem) })).asUInt
339  }
340
341  def getRemSeq(input: Seq[Seq[Bool]])(rem: Int) = {
342    (0 until LoadQueueReplaySize / LoadPipelineWidth).map(i => { input(LoadPipelineWidth * i + rem) })
343  }
344
345  // stage1: select 2 entries and read their vaddr
346  val s0_oldestSel = Wire(Vec(LoadPipelineWidth, Valid(UInt(log2Up(LoadQueueReplaySize + 1).W))))
347  val s1_can_go = Wire(Vec(LoadPipelineWidth, Bool()))
348  val s1_oldestSel = Wire(Vec(LoadPipelineWidth, Valid(UInt(log2Up(LoadQueueReplaySize + 1).W))))
349  val s2_can_go = Wire(Vec(LoadPipelineWidth, Bool()))
350  val s2_oldestSel = Wire(Vec(LoadPipelineWidth, Valid(UInt(log2Up(LoadQueueReplaySize + 1).W))))
351
352  // generate mask
353  val needCancel = Wire(Vec(LoadQueueReplaySize, Bool()))
354  // generate enq mask
355  val selectIndexOH = Wire(Vec(LoadPipelineWidth, UInt(LoadQueueReplaySize.W)))
356  val s0_loadEnqFireMask = io.enq.map(x => x.fire && !x.bits.isLoadReplay).zip(selectIndexOH).map(x => Mux(x._1, x._2, 0.U))
357  val s0_remLoadEnqFireVec = s0_loadEnqFireMask.map(x => VecInit((0 until LoadPipelineWidth).map(rem => getRemBits(x)(rem))))
358  val s0_remEnqSelVec = Seq.tabulate(LoadPipelineWidth)(w => VecInit(s0_remLoadEnqFireVec.map(x => x(w))))
359
360  // generate free mask
361  val s0_loadFreeSelMask = needCancel.asUInt
362  val s0_remFreeSelVec = VecInit(Seq.tabulate(LoadPipelineWidth)(rem => getRemBits(s0_loadFreeSelMask)(rem)))
363
364  // l2 hint wakes up cache missed load
365  // l2 will send GrantData in next 2/3 cycle, wake up the missed load early and sent them to load pipe, so them will hit the data in D channel or mshr in load S1
366  val s0_loadHintWakeMask = VecInit((0 until LoadQueueReplaySize).map(i => {
367    allocated(i) && !scheduled(i) && blockByCacheMiss(i) && missMSHRId(i) === io.l2_hint.bits.sourceId && io.l2_hint.valid
368  })).asUInt()
369  // l2 will send 2 beats data in 2 cycles, so if data needed by this load is in first beat, select it this cycle, otherwise next cycle
370  val s0_loadHintSelMask = s0_loadHintWakeMask & VecInit(dataInLastBeatReg.map(!_)).asUInt
371  val s0_remLoadHintSelMask = VecInit((0 until LoadPipelineWidth).map(rem => getRemBits(s0_loadHintSelMask)(rem)))
372  val s0_hintSelValid = s0_loadHintSelMask.orR
373
374  // wake up cache missed load
375  (0 until LoadQueueReplaySize).foreach(i => {
376    when(s0_loadHintWakeMask(i)) {
377      blockByCacheMiss(i) := false.B
378      creditUpdate(i) := 0.U
379    }
380  })
381
382  // generate replay mask
383  // replay select priority is given as follow
384  // 1. hint wake up load
385  // 2. higher priority load
386  // 3. lower priority load
387  val s0_loadHigherPriorityReplaySelMask = VecInit((0 until LoadQueueReplaySize).map(i => {
388    val blocked = selBlocked(i) || blockByMemAmb(i) || blockByRARReject(i) || blockByRAWReject(i) || blockByOthers(i) || blockByForwardFail(i) || blockByCacheMiss(i) || blockByTlbMiss(i)
389    val hasHigherPriority = cause(i)(LoadReplayCauses.C_DM) || cause(i)(LoadReplayCauses.C_FF)
390    allocated(i) && !scheduled(i) && !blocked && hasHigherPriority
391  })).asUInt // use uint instead vec to reduce verilog lines
392  val s0_loadLowerPriorityReplaySelMask = VecInit((0 until LoadQueueReplaySize).map(i => {
393    val blocked = selBlocked(i) || blockByMemAmb(i) || blockByRARReject(i) || blockByRAWReject(i) || blockByOthers(i) || blockByForwardFail(i) || blockByCacheMiss(i) || blockByTlbMiss(i)
394    val hasLowerPriority = !cause(i)(LoadReplayCauses.C_DM) && !cause(i)(LoadReplayCauses.C_FF)
395    allocated(i) && !scheduled(i) && !blocked && hasLowerPriority
396  })).asUInt // use uint instead vec to reduce verilog lines
397  val s0_loadNormalReplaySelMask = s0_loadLowerPriorityReplaySelMask | s0_loadHigherPriorityReplaySelMask | s0_loadHintSelMask
398  val s0_remNormalReplaySelVec = VecInit((0 until LoadPipelineWidth).map(rem => getRemBits(s0_loadNormalReplaySelMask)(rem)))
399  val s0_loadPriorityReplaySelMask = Mux(s0_hintSelValid, s0_loadHintSelMask, Mux(s0_loadHigherPriorityReplaySelMask.orR, s0_loadHigherPriorityReplaySelMask, s0_loadLowerPriorityReplaySelMask))
400  val s0_remPriorityReplaySelVec = VecInit((0 until LoadPipelineWidth).map(rem => getRemBits(s0_loadPriorityReplaySelMask)(rem)))
401
402  /******************************************************************************************************
403   * WARNING: Make sure that OldestSelectStride must less than or equal stages of load pipeline.        *
404   ******************************************************************************************************
405   */
406  val OldestSelectStride = 4
407  val oldestPtrExt = (0 until OldestSelectStride).map(i => io.ldWbPtr + i.U)
408  val s0_oldestMatchMaskVec = (0 until LoadQueueReplaySize).map(i => (0 until OldestSelectStride).map(j => s0_loadNormalReplaySelMask(i) && uop(i).lqIdx === oldestPtrExt(j)))
409  val s0_remOldsetMatchMaskVec = (0 until LoadPipelineWidth).map(rem => getRemSeq(s0_oldestMatchMaskVec.map(_.take(1)))(rem))
410  val s0_remOlderMatchMaskVec = (0 until LoadPipelineWidth).map(rem => getRemSeq(s0_oldestMatchMaskVec.map(_.drop(1)))(rem))
411  val s0_remOldestSelVec = VecInit(Seq.tabulate(LoadPipelineWidth)(rem => {
412    VecInit((0 until LoadQueueReplaySize / LoadPipelineWidth).map(i => {
413      Mux(VecInit(s0_remOldsetMatchMaskVec(rem).map(_(0))).asUInt.orR, s0_remOldsetMatchMaskVec(rem)(i)(0), s0_remOlderMatchMaskVec(rem)(i).reduce(_|_))
414    })).asUInt
415  }))
416  val s0_remOldestHintSelVec = s0_remOldestSelVec.zip(s0_remLoadHintSelMask).map {
417    case(oldestVec, hintVec) => oldestVec & hintVec
418  }
419
420  // select oldest logic
421  s0_oldestSel := VecInit((0 until LoadPipelineWidth).map(rport => {
422    // select enqueue earlest inst
423    val ageOldest = AgeDetector(LoadQueueReplaySize / LoadPipelineWidth, s0_remEnqSelVec(rport), s0_remFreeSelVec(rport), s0_remPriorityReplaySelVec(rport))
424    assert(!(ageOldest.valid && PopCount(ageOldest.bits) > 1.U), "oldest index must be one-hot!")
425    val ageOldestValid = ageOldest.valid
426    val ageOldestIndexOH = ageOldest.bits
427
428    // select program order oldest
429    val l2HintFirst = io.l2_hint.valid && s0_remOldestHintSelVec(rport).orR
430    val issOldestValid = l2HintFirst || s0_remOldestSelVec(rport).orR
431    val issOldestIndexOH = Mux(l2HintFirst, PriorityEncoderOH(s0_remOldestHintSelVec(rport)), PriorityEncoderOH(s0_remOldestSelVec(rport)))
432
433    val oldest = Wire(Valid(UInt()))
434    val oldestSel = Mux(issOldestValid, issOldestIndexOH, ageOldestIndexOH)
435    val oldestBitsVec = Wire(Vec(LoadQueueReplaySize, Bool()))
436
437    require((LoadQueueReplaySize % LoadPipelineWidth) == 0)
438    oldestBitsVec.foreach(e => e := false.B)
439    for (i <- 0 until LoadQueueReplaySize / LoadPipelineWidth) {
440      oldestBitsVec(i * LoadPipelineWidth + rport) := oldestSel(i)
441    }
442
443    oldest.valid := ageOldest.valid || issOldestValid
444    oldest.bits := OHToUInt(oldestBitsVec.asUInt)
445    oldest
446  }))
447
448
449  // Replay port reorder
450  class BalanceEntry extends XSBundle {
451    val balance = Bool()
452    val index   = UInt(log2Up(LoadQueueReplaySize).W)
453    val port    = UInt(log2Up(LoadPipelineWidth).W)
454  }
455
456  def balanceReOrder(sel: Seq[ValidIO[BalanceEntry]]): Seq[ValidIO[BalanceEntry]] = {
457    require(sel.length > 0)
458    val balancePick = ParallelPriorityMux(sel.map(x => (x.valid && x.bits.balance) -> x))
459    val reorderSel = Wire(Vec(sel.length, ValidIO(new BalanceEntry)))
460    (0 until sel.length).map(i =>
461      if (i == 0) {
462        when (balancePick.valid && balancePick.bits.balance) {
463          reorderSel(i) := balancePick
464        } .otherwise {
465          reorderSel(i) := sel(i)
466        }
467      } else {
468        when (balancePick.valid && balancePick.bits.balance && i.U === balancePick.bits.port) {
469          reorderSel(i) := sel(0)
470        } .otherwise {
471          reorderSel(i) := sel(i)
472        }
473      }
474    )
475    reorderSel
476  }
477
478  // stage2: send replay request to load unit
479  // replay cold down
480  val ColdDownCycles = 16
481  val coldCounter = RegInit(VecInit(List.fill(LoadPipelineWidth)(0.U(log2Up(ColdDownCycles).W))))
482  val ColdDownThreshold = Wire(UInt(log2Up(ColdDownCycles).W))
483  ColdDownThreshold := Constantin.createRecord("ColdDownThreshold_"+p(XSCoreParamsKey).HartId.toString(), initValue = 12.U)
484  assert(ColdDownCycles.U > ColdDownThreshold, "ColdDownCycles must great than ColdDownThreshold!")
485
486  def replayCanFire(i: Int) = coldCounter(i) >= 0.U && coldCounter(i) < ColdDownThreshold
487  def coldDownNow(i: Int) = coldCounter(i) >= ColdDownThreshold
488
489  val s1_balanceOldestSelExt = (0 until LoadPipelineWidth).map(i => {
490    val wrapper = Wire(Valid(new BalanceEntry))
491    wrapper.valid        := s1_oldestSel(i).valid
492    wrapper.bits.balance := cause(s1_oldestSel(i).bits)(LoadReplayCauses.C_BC)
493    wrapper.bits.index   := s1_oldestSel(i).bits
494    wrapper.bits.port    := i.U
495    wrapper
496  })
497
498  val s1_balanceOldestSel = VecInit(balanceReOrder(s1_balanceOldestSelExt))
499  for (i <- 0 until LoadPipelineWidth) {
500    val s0_can_go = s1_can_go(s1_balanceOldestSel(i).bits.port) || uop(s1_oldestSel(i).bits).robIdx.needFlush(io.redirect)
501    val s0_cancel = uop(s0_oldestSel(i).bits).robIdx.needFlush(io.redirect)
502    val s0_oldestSelV = s0_oldestSel(i).valid && !s0_cancel
503    s1_oldestSel(i).valid := RegEnable(s0_oldestSelV, s0_can_go)
504    s1_oldestSel(i).bits := RegEnable(s0_oldestSel(i).bits, s0_can_go)
505
506    when (s0_can_go && s0_oldestSelV) {
507      scheduled(s0_oldestSel(i).bits) := true.B
508    }
509  }
510  val s2_cancelReplay = Wire(Vec(LoadPipelineWidth, Bool()))
511  for (i <- 0 until LoadPipelineWidth) {
512    val s1_cancel = uop(s1_balanceOldestSel(i).bits.index).robIdx.needFlush(io.redirect)
513    val s1_oldestSelV = s1_balanceOldestSel(i).valid && !s1_cancel
514    s1_can_go(i)          := Mux(s2_oldestSel(i).valid && !s2_cancelReplay(i), io.replay(i).ready && replayCanFire(i), true.B)
515    s2_oldestSel(i).valid := RegEnable(s1_oldestSelV, s1_can_go(i))
516    s2_oldestSel(i).bits  := RegEnable(s1_balanceOldestSel(i).bits.index, s1_can_go(i))
517
518    vaddrModule.io.ren(i) := s1_balanceOldestSel(i).valid && s1_can_go(i)
519    vaddrModule.io.raddr(i) := s1_balanceOldestSel(i).bits.index
520  }
521
522  for (i <- 0 until LoadPipelineWidth) {
523    val s1_replayIdx = s1_balanceOldestSel(i).bits.index
524    val s2_replayUop = RegEnable(uop(s1_replayIdx), s1_can_go(i))
525    val s2_replayMSHRId = RegEnable(missMSHRId(s1_replayIdx), s1_can_go(i))
526    val s2_replacementUpdated = RegEnable(replacementUpdated(s1_replayIdx), s1_can_go(i))
527    val s2_replayCauses = RegEnable(cause(s1_replayIdx), s1_can_go(i))
528    val s2_replayCarry = RegEnable(replayCarryReg(s1_replayIdx), s1_can_go(i))
529    val s2_replayCacheMissReplay = RegEnable(trueCacheMissReplay(s1_replayIdx), s1_can_go(i))
530    s2_cancelReplay(i) := s2_replayUop.robIdx.needFlush(io.redirect)
531
532    s2_can_go(i) := DontCare
533    io.replay(i).valid             := s2_oldestSel(i).valid && !s2_cancelReplay(i) && replayCanFire(i)
534    io.replay(i).bits              := DontCare
535    io.replay(i).bits.uop          := s2_replayUop
536    io.replay(i).bits.vaddr        := vaddrModule.io.rdata(i)
537    io.replay(i).bits.isFirstIssue := false.B
538    io.replay(i).bits.isLoadReplay := true.B
539    io.replay(i).bits.replayCarry  := s2_replayCarry
540    io.replay(i).bits.mshrid       := s2_replayMSHRId
541    io.replay(i).bits.replacementUpdated := s2_replacementUpdated
542    io.replay(i).bits.forward_tlDchannel := s2_replayCauses(LoadReplayCauses.C_DM)
543    io.replay(i).bits.schedIndex   := s2_oldestSel(i).bits
544
545    when (io.replay(i).fire) {
546      XSError(!allocated(s2_oldestSel(i).bits), p"LoadQueueReplay: why replay an invalid entry ${s2_oldestSel(i).bits} ?")
547    }
548  }
549
550  // update cold counter
551  val lastReplay = RegNext(VecInit(io.replay.map(_.fire)))
552  for (i <- 0 until LoadPipelineWidth) {
553    when (lastReplay(i) && io.replay(i).fire) {
554      coldCounter(i) := coldCounter(i) + 1.U
555    } .elsewhen (coldDownNow(i)) {
556      coldCounter(i) := coldCounter(i) + 1.U
557    } .otherwise {
558      coldCounter(i) := 0.U
559    }
560  }
561
562  when(io.refill.valid) {
563    XSDebug("miss resp: paddr:0x%x data %x\n", io.refill.bits.addr, io.refill.bits.data)
564  }
565
566  //  LoadQueueReplay deallocate
567  val freeMaskVec = Wire(Vec(LoadQueueReplaySize, Bool()))
568
569  // init
570  freeMaskVec.map(e => e := false.B)
571
572  // Allocate logic
573  val enqValidVec = Wire(Vec(LoadPipelineWidth, Bool()))
574  val enqIndexVec = Wire(Vec(LoadPipelineWidth, UInt()))
575
576  val newEnqueue = (0 until LoadPipelineWidth).map(i => {
577    needEnqueue(i) && !io.enq(i).bits.isLoadReplay
578  })
579
580  for ((enq, w) <- io.enq.zipWithIndex) {
581    vaddrModule.io.wen(w) := false.B
582    freeList.io.doAllocate(w) := false.B
583
584    freeList.io.allocateReq(w) := newEnqueue(w)
585
586    //  Allocated ready
587    enqValidVec(w) := freeList.io.canAllocate(w)
588    enqIndexVec(w) := Mux(enq.bits.isLoadReplay, enq.bits.schedIndex, freeList.io.allocateSlot(w))
589    selectIndexOH(w) := UIntToOH(enqIndexVec(w))
590    enq.ready := Mux(enq.bits.isLoadReplay, true.B, enqValidVec(w))
591
592    val enqIndex = enqIndexVec(w)
593    when (needEnqueue(w) && enq.ready) {
594
595      val debug_robIdx = enq.bits.uop.robIdx.asUInt
596      XSError(allocated(enqIndex) && !enq.bits.isLoadReplay, p"LoadQueueReplay: can not accept more load, check: ldu $w, robIdx $debug_robIdx!")
597      XSError(hasExceptions(w), p"LoadQueueReplay: The instruction has exception, it can not be replay, check: ldu $w, robIdx $debug_robIdx!")
598
599      freeList.io.doAllocate(w) := !enq.bits.isLoadReplay
600
601      //  Allocate new entry
602      allocated(enqIndex) := true.B
603      scheduled(enqIndex) := false.B
604      uop(enqIndex)       := enq.bits.uop
605
606      vaddrModule.io.wen(w)   := true.B
607      vaddrModule.io.waddr(w) := enqIndex
608      vaddrModule.io.wdata(w) := enq.bits.vaddr
609      debug_vaddr(enqIndex)   := enq.bits.vaddr
610
611      /**
612       * used for feedback and replay
613       */
614      // set flags
615      val replayInfo = enq.bits.rep_info
616      val dataInLastBeat = replayInfo.last_beat
617      cause(enqIndex) := replayInfo.cause.asUInt
618
619      // update credit
620      val blockCyclesTlbPtr = blockPtrTlb(enqIndex)
621      val blockCyclesCachePtr = blockPtrCache(enqIndex)
622      val blockCyclesOtherPtr = blockPtrOthers(enqIndex)
623      creditUpdate(enqIndex) := Mux(replayInfo.cause(LoadReplayCauses.C_TM), blockCyclesTlb(blockCyclesTlbPtr),
624                                Mux(replayInfo.cause(LoadReplayCauses.C_DM), blockCyclesCache(blockCyclesCachePtr) + dataInLastBeat, blockCyclesOthers(blockCyclesOtherPtr)))
625
626      // init
627      blockByTlbMiss(enqIndex)     := false.B
628      blockByMemAmb(enqIndex)   := false.B
629      blockByForwardFail(enqIndex) := false.B
630      blockByCacheMiss(enqIndex)   := false.B
631      blockByRARReject(enqIndex)   := false.B
632      blockByRAWReject(enqIndex)   := false.B
633      blockByOthers(enqIndex)      := false.B
634
635      // update block pointer
636      when (replayInfo.cause(LoadReplayCauses.C_DR)) {
637        // normal case: dcache replay
638        blockByOthers(enqIndex) := true.B
639        blockPtrOthers(enqIndex) :=  Mux(blockPtrOthers(enqIndex) === 3.U(2.W), blockPtrOthers(enqIndex), blockPtrOthers(enqIndex) + 1.U(2.W))
640      } .elsewhen (replayInfo.cause(LoadReplayCauses.C_BC) || replayInfo.cause(LoadReplayCauses.C_NK)) {
641        // normal case: bank conflict or schedule error
642        // can replay next cycle
643        creditUpdate(enqIndex) := 0.U
644        blockByOthers(enqIndex) := false.B
645      }
646
647      // special case: tlb miss
648      when (replayInfo.cause(LoadReplayCauses.C_TM)) {
649        blockByTlbMiss(enqIndex) := true.B
650        blockPtrTlb(enqIndex) := Mux(blockPtrTlb(enqIndex) === 3.U(2.W), blockPtrTlb(enqIndex), blockPtrTlb(enqIndex) + 1.U(2.W))
651      }
652
653      // special case: dcache miss
654      when (replayInfo.cause(LoadReplayCauses.C_DM) && enq.bits.handledByMSHR) {
655        blockByCacheMiss(enqIndex) := !replayInfo.full_fwd && //  dcache miss
656                                  !(io.refill.valid && io.refill.bits.id === replayInfo.mshr_id) // no refill in this cycle
657
658        blockPtrCache(enqIndex) := Mux(blockPtrCache(enqIndex) === 3.U(2.W), blockPtrCache(enqIndex), blockPtrCache(enqIndex) + 1.U(2.W))
659      }
660
661      // special case: st-ld violation
662      when (replayInfo.cause(LoadReplayCauses.C_MA)) {
663        blockByMemAmb(enqIndex) := true.B
664        blockSqIdx(enqIndex) := replayInfo.addr_inv_sq_idx
665        blockPtrOthers(enqIndex) :=  Mux(blockPtrOthers(enqIndex) === 3.U(2.W), blockPtrOthers(enqIndex), blockPtrOthers(enqIndex) + 1.U(2.W))
666      }
667
668      // special case: data forward fail
669      when (replayInfo.cause(LoadReplayCauses.C_FF)) {
670        blockByForwardFail(enqIndex) := true.B
671        blockSqIdx(enqIndex) := replayInfo.data_inv_sq_idx
672        blockPtrOthers(enqIndex) :=  Mux(blockPtrOthers(enqIndex) === 3.U(2.W), blockPtrOthers(enqIndex), blockPtrOthers(enqIndex) + 1.U(2.W))
673      }
674
675      // special case: rar reject
676      when (replayInfo.cause(LoadReplayCauses.C_RAR)) {
677        blockByRARReject(enqIndex) := true.B
678        blockPtrOthers(enqIndex) :=  Mux(blockPtrOthers(enqIndex) === 3.U(2.W), blockPtrOthers(enqIndex), blockPtrOthers(enqIndex) + 1.U(2.W))
679      }
680
681      // special case: raw reject
682      when (replayInfo.cause(LoadReplayCauses.C_RAW)) {
683        blockByRAWReject(enqIndex) := true.B
684        blockPtrOthers(enqIndex) :=  Mux(blockPtrOthers(enqIndex) === 3.U(2.W), blockPtrOthers(enqIndex), blockPtrOthers(enqIndex) + 1.U(2.W))
685      }
686
687      // extra info
688      replayCarryReg(enqIndex) := replayInfo.rep_carry
689      replacementUpdated(enqIndex) := enq.bits.replacementUpdated
690      // update mshr_id only when the load has already been handled by mshr
691      when(enq.bits.handledByMSHR) {
692        missMSHRId(enqIndex) := replayInfo.mshr_id
693      }
694      dataInLastBeatReg(enqIndex) := dataInLastBeat
695    }
696
697    //
698    val schedIndex = enq.bits.schedIndex
699    when (enq.valid && enq.bits.isLoadReplay) {
700      when (!needReplay(w) || hasExceptions(w)) {
701        allocated(schedIndex) := false.B
702        freeMaskVec(schedIndex) := true.B
703      } .otherwise {
704        scheduled(schedIndex) := false.B
705      }
706    }
707  }
708
709  // misprediction recovery / exception redirect
710  for (i <- 0 until LoadQueueReplaySize) {
711    needCancel(i) := uop(i).robIdx.needFlush(io.redirect) && allocated(i)
712    when (needCancel(i)) {
713      allocated(i) := false.B
714      freeMaskVec(i) := true.B
715    }
716  }
717
718  freeList.io.free := freeMaskVec.asUInt
719
720  io.lqFull := lqFull
721
722  // Topdown
723  val sourceVaddr = WireInit(0.U.asTypeOf(new Valid(UInt(VAddrBits.W))))
724
725  ExcitingUtils.addSink(sourceVaddr, s"rob_head_vaddr_${coreParams.HartId}", ExcitingUtils.Perf)
726
727  val uop_wrapper = Wire(Vec(LoadQueueReplaySize, new XSBundleWithMicroOp))
728  (uop_wrapper.zipWithIndex).foreach {
729    case (u, i) => {
730      u.uop := uop(i)
731    }
732  }
733  val lq_match_vec = (debug_vaddr.zip(allocated)).map{case(va, alloc) => alloc && (va === sourceVaddr.bits)}
734  val rob_head_lq_match = ParallelOperation(lq_match_vec.zip(uop_wrapper), (a: Tuple2[Bool, XSBundleWithMicroOp], b: Tuple2[Bool, XSBundleWithMicroOp]) => {
735    val (a_v, a_uop) = (a._1, a._2)
736    val (b_v, b_uop) = (b._1, b._2)
737
738    val res = Mux(a_v && b_v, Mux(isAfter(a_uop.uop.robIdx, b_uop.uop.robIdx), b_uop, a_uop),
739                  Mux(a_v, a_uop,
740                      Mux(b_v, b_uop,
741                                a_uop)))
742    (a_v || b_v, res)
743  })
744
745  val lq_match_bits = rob_head_lq_match._2.uop
746  val lq_match      = rob_head_lq_match._1 && sourceVaddr.valid
747  val lq_match_idx  = lq_match_bits.lqIdx.value
748
749  val rob_head_tlb_miss        = lq_match && cause(lq_match_idx)(LoadReplayCauses.C_TM)
750  val rob_head_nuke            = lq_match && cause(lq_match_idx)(LoadReplayCauses.C_NK)
751  val rob_head_mem_amb         = lq_match && cause(lq_match_idx)(LoadReplayCauses.C_MA)
752  val rob_head_confilct_replay = lq_match && cause(lq_match_idx)(LoadReplayCauses.C_BC)
753  val rob_head_forward_fail    = lq_match && cause(lq_match_idx)(LoadReplayCauses.C_FF)
754  val rob_head_mshrfull_replay = lq_match && cause(lq_match_idx)(LoadReplayCauses.C_DR)
755  val rob_head_dcache_miss     = lq_match && cause(lq_match_idx)(LoadReplayCauses.C_DM)
756  val rob_head_rar_nack        = lq_match && cause(lq_match_idx)(LoadReplayCauses.C_RAR)
757  val rob_head_raw_nack        = lq_match && cause(lq_match_idx)(LoadReplayCauses.C_RAW)
758  val rob_head_other_replay    = lq_match && (rob_head_rar_nack || rob_head_raw_nack || rob_head_forward_fail)
759
760  val rob_head_vio_replay = rob_head_nuke || rob_head_mem_amb
761
762  val rob_head_miss_in_dtlb = WireInit(false.B)
763  ExcitingUtils.addSink(rob_head_miss_in_dtlb, s"miss_in_dtlb_${coreParams.HartId}", ExcitingUtils.Perf)
764  ExcitingUtils.addSource(rob_head_tlb_miss && !rob_head_miss_in_dtlb, s"load_tlb_replay_stall_${coreParams.HartId}", ExcitingUtils.Perf, true)
765  ExcitingUtils.addSource(rob_head_tlb_miss &&  rob_head_miss_in_dtlb, s"load_tlb_miss_stall_${coreParams.HartId}", ExcitingUtils.Perf, true)
766  ExcitingUtils.addSource(rob_head_vio_replay, s"load_vio_replay_stall_${coreParams.HartId}", ExcitingUtils.Perf, true)
767  ExcitingUtils.addSource(rob_head_mshrfull_replay, s"load_mshr_replay_stall_${coreParams.HartId}", ExcitingUtils.Perf, true)
768  // ExcitingUtils.addSource(rob_head_confilct_replay, s"load_l1_cache_stall_with_bank_conflict_${coreParams.HartId}", ExcitingUtils.Perf, true)
769  ExcitingUtils.addSource(rob_head_other_replay, s"rob_head_other_replay_${coreParams.HartId}", ExcitingUtils.Perf, true)
770  val perfValidCount = RegNext(PopCount(allocated))
771
772  //  perf cnt
773  val enqNumber               = PopCount(io.enq.map(enq => enq.fire && !enq.bits.isLoadReplay))
774  val deqNumber               = PopCount(io.replay.map(_.fire))
775  val deqBlockCount           = PopCount(io.replay.map(r => r.valid && !r.ready))
776  val replayTlbMissCount      = PopCount(io.enq.map(enq => enq.fire && !enq.bits.isLoadReplay && enq.bits.rep_info.cause(LoadReplayCauses.C_TM)))
777  val replayMemAmbCount    = PopCount(io.enq.map(enq => enq.fire && !enq.bits.isLoadReplay && enq.bits.rep_info.cause(LoadReplayCauses.C_NK)))
778  val replayNukeCount         = PopCount(io.enq.map(enq => enq.fire && !enq.bits.isLoadReplay && enq.bits.rep_info.cause(LoadReplayCauses.C_MA)))
779  val replayRARRejectCount    = PopCount(io.enq.map(enq => enq.fire && !enq.bits.isLoadReplay && enq.bits.rep_info.cause(LoadReplayCauses.C_RAR)))
780  val replayRAWRejectCount    = PopCount(io.enq.map(enq => enq.fire && !enq.bits.isLoadReplay && enq.bits.rep_info.cause(LoadReplayCauses.C_RAW)))
781  val replayBankConflictCount = PopCount(io.enq.map(enq => enq.fire && !enq.bits.isLoadReplay && enq.bits.rep_info.cause(LoadReplayCauses.C_BC)))
782  val replayDCacheReplayCount = PopCount(io.enq.map(enq => enq.fire && !enq.bits.isLoadReplay && enq.bits.rep_info.cause(LoadReplayCauses.C_DR)))
783  val replayForwardFailCount  = PopCount(io.enq.map(enq => enq.fire && !enq.bits.isLoadReplay && enq.bits.rep_info.cause(LoadReplayCauses.C_FF)))
784  val replayDCacheMissCount   = PopCount(io.enq.map(enq => enq.fire && !enq.bits.isLoadReplay && enq.bits.rep_info.cause(LoadReplayCauses.C_DM)))
785  XSPerfAccumulate("enq", enqNumber)
786  XSPerfAccumulate("deq", deqNumber)
787  XSPerfAccumulate("deq_block", deqBlockCount)
788  XSPerfAccumulate("replay_full", io.lqFull)
789  XSPerfAccumulate("replay_rar_nack", replayRARRejectCount)
790  XSPerfAccumulate("replay_raw_nack", replayRAWRejectCount)
791  XSPerfAccumulate("replay_nuke", replayNukeCount)
792  XSPerfAccumulate("replay_mem_amb", replayMemAmbCount)
793  XSPerfAccumulate("replay_tlb_miss", replayTlbMissCount)
794  XSPerfAccumulate("replay_bank_conflict", replayBankConflictCount)
795  XSPerfAccumulate("replay_dcache_replay", replayDCacheReplayCount)
796  XSPerfAccumulate("replay_forward_fail", replayForwardFailCount)
797  XSPerfAccumulate("replay_dcache_miss", replayDCacheMissCount)
798  XSPerfAccumulate("replay_hint_wakeup", s0_hintSelValid)
799
800  val perfEvents: Seq[(String, UInt)] = Seq(
801    ("enq", enqNumber),
802    ("deq", deqNumber),
803    ("deq_block", deqBlockCount),
804    ("replay_full", io.lqFull),
805    ("replay_rar_nack", replayRARRejectCount),
806    ("replay_raw_nack", replayRAWRejectCount),
807    ("replay_nuke", replayNukeCount),
808    ("replay_mem_amb", replayMemAmbCount),
809    ("replay_tlb_miss", replayTlbMissCount),
810    ("replay_bank_conflict", replayBankConflictCount),
811    ("replay_dcache_replay", replayDCacheReplayCount),
812    ("replay_forward_fail", replayForwardFailCount),
813    ("replay_dcache_miss", replayDCacheMissCount),
814  )
815  generatePerfEvent()
816  // end
817}
818