xref: /XiangShan/src/main/scala/xiangshan/frontend/IBuffer.scala (revision bb2f3f51dd67f6e16e0cc1ffe43368c9fc7e4aef)
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.frontend
18
19import org.chipsalliance.cde.config.Parameters
20import chisel3._
21import chisel3.util._
22import xiangshan._
23import utils._
24import utility._
25import xiangshan.ExceptionNO._
26
27class IBufPtr(implicit p: Parameters) extends CircularQueuePtr[IBufPtr](
28  p => p(XSCoreParamsKey).IBufSize
29) {
30}
31
32class IBufInBankPtr(implicit p: Parameters) extends CircularQueuePtr[IBufInBankPtr](
33  p => p(XSCoreParamsKey).IBufSize / p(XSCoreParamsKey).IBufNBank
34) {
35}
36
37class IBufBankPtr(implicit p: Parameters) extends CircularQueuePtr[IBufBankPtr](
38  p => p(XSCoreParamsKey).IBufNBank
39) {
40}
41
42class IBufferIO(implicit p: Parameters) extends XSBundle {
43  val flush = Input(Bool())
44  val ControlRedirect = Input(Bool())
45  val ControlBTBMissBubble = Input(Bool())
46  val TAGEMissBubble = Input(Bool())
47  val SCMissBubble = Input(Bool())
48  val ITTAGEMissBubble = Input(Bool())
49  val RASMissBubble = Input(Bool())
50  val MemVioRedirect = Input(Bool())
51  val in = Flipped(DecoupledIO(new FetchToIBuffer))
52  val out = Vec(DecodeWidth, DecoupledIO(new CtrlFlow))
53  val full = Output(Bool())
54  val decodeCanAccept = Input(Bool())
55  val stallReason = new StallReasonIO(DecodeWidth)
56}
57
58class IBufEntry(implicit p: Parameters) extends XSBundle {
59  val inst = UInt(32.W)
60  val pc = UInt(VAddrBits.W)
61  val foldpc = UInt(MemPredPCWidth.W)
62  val pd = new PreDecodeInfo
63  val pred_taken = Bool()
64  val ftqPtr = new FtqPtr
65  val ftqOffset = UInt(log2Ceil(PredictWidth).W)
66  val exceptionType = UInt(ExceptionType.width.W)
67  val crossPageIPFFix = Bool()
68  val triggered = new TriggerCf
69
70  def fromFetch(fetch: FetchToIBuffer, i: Int): IBufEntry = {
71    inst   := fetch.instrs(i)
72    pc     := fetch.pc(i)
73    foldpc := fetch.foldpc(i)
74    pd     := fetch.pd(i)
75    pred_taken := fetch.ftqOffset(i).valid
76    ftqPtr := fetch.ftqPtr
77    ftqOffset := fetch.ftqOffset(i).bits
78    exceptionType := fetch.exceptionType(i)
79    crossPageIPFFix := fetch.crossPageIPFFix(i)
80    triggered := fetch.triggered(i)
81    this
82  }
83
84  def toCtrlFlow: CtrlFlow = {
85    val cf = Wire(new CtrlFlow)
86    cf.instr := inst
87    cf.pc := pc
88    cf.foldpc := foldpc
89    cf.exceptionVec := 0.U.asTypeOf(ExceptionVec())
90    cf.exceptionVec(instrPageFault) := exceptionType === ExceptionType.ipf
91    cf.exceptionVec(instrGuestPageFault) := exceptionType === ExceptionType.igpf
92    cf.exceptionVec(instrAccessFault) := exceptionType === ExceptionType.acf
93    cf.trigger := triggered
94    cf.pd := pd
95    cf.pred_taken := pred_taken
96    cf.crossPageIPFFix := crossPageIPFFix
97    cf.storeSetHit := DontCare
98    cf.waitForRobIdx := DontCare
99    cf.loadWaitBit := DontCare
100    cf.loadWaitStrict := DontCare
101    cf.ssid := DontCare
102    cf.ftqPtr := ftqPtr
103    cf.ftqOffset := ftqOffset
104    cf
105  }
106}
107
108class IBuffer(implicit p: Parameters) extends XSModule with HasCircularQueuePtrHelper with HasPerfEvents {
109  val io = IO(new IBufferIO)
110
111  // io alias
112  private val decodeCanAccept = io.decodeCanAccept
113
114  // Parameter Check
115  private val bankSize = IBufSize / IBufNBank
116  require(IBufSize % IBufNBank == 0, s"IBufNBank should divide IBufSize, IBufNBank: $IBufNBank, IBufSize: $IBufSize")
117  require(IBufNBank >= DecodeWidth,
118    s"IBufNBank should be equal or larger than DecodeWidth, IBufNBank: $IBufNBank, DecodeWidth: $DecodeWidth")
119
120  // IBuffer is organized as raw registers
121  // This is due to IBuffer is a huge queue, read & write port logic should be precisely controlled
122  //                             . + + E E E - .
123  //                             . + + E E E - .
124  //                             . . + E E E - .
125  //                             . . + E E E E -
126  // As shown above, + means enqueue, - means dequeue, E is current content
127  // When dequeue, read port is organized like a banked FIFO
128  // Dequeue reads no more than 1 entry from each bank sequentially, this can be exploit to reduce area
129  // Enqueue writes cannot benefit from this characteristic unless use a SRAM
130  // For detail see Enqueue and Dequeue below
131  private val ibuf: Vec[IBufEntry] = RegInit(VecInit.fill(IBufSize)(0.U.asTypeOf(new IBufEntry)))
132  private val bankedIBufView: Vec[Vec[IBufEntry]] = VecInit.tabulate(IBufNBank)(
133    bankID => VecInit.tabulate(bankSize)(
134      inBankOffset => ibuf(bankID + inBankOffset * IBufNBank)
135    )
136  )
137
138
139  // Bypass wire
140  private val bypassEntries = WireDefault(VecInit.fill(DecodeWidth)(0.U.asTypeOf(Valid(new IBufEntry))))
141  // Normal read wire
142  private val deqEntries = WireDefault(VecInit.fill(DecodeWidth)(0.U.asTypeOf(Valid(new IBufEntry))))
143  // Output register
144  private val outputEntries = RegInit(VecInit.fill(DecodeWidth)(0.U.asTypeOf(Valid(new IBufEntry))))
145
146  // Between Bank
147  private val deqBankPtrVec: Vec[IBufBankPtr] = RegInit(VecInit.tabulate(DecodeWidth)(_.U.asTypeOf(new IBufBankPtr)))
148  private val deqBankPtr: IBufBankPtr = deqBankPtrVec(0)
149  private val deqBankPtrVecNext = Wire(deqBankPtrVec.cloneType)
150  // Inside Bank
151  private val deqInBankPtr: Vec[IBufInBankPtr] = RegInit(VecInit.fill(IBufNBank)(0.U.asTypeOf(new IBufInBankPtr)))
152  private val deqInBankPtrNext = Wire(deqInBankPtr.cloneType)
153
154  val deqPtr = RegInit(0.U.asTypeOf(new IBufPtr))
155  val deqPtrNext = Wire(deqPtr.cloneType)
156
157  val enqPtrVec = RegInit(VecInit.tabulate(PredictWidth)(_.U.asTypeOf(new IBufPtr)))
158  val enqPtr = enqPtrVec(0)
159
160  val numTryEnq = WireDefault(0.U)
161  val numEnq = Mux(io.in.fire, numTryEnq, 0.U)
162
163  // Record the insts in output entries are from bypass or deq.
164  // Update deqPtr if they are from deq
165  val currentOutUseBypass = RegInit(false.B)
166  val numBypassRemain = RegInit(0.U(log2Up(DecodeWidth).W))
167  val numBypassRemainNext = Wire(numBypassRemain.cloneType)
168
169  // empty and decode can accept insts and previous bypass insts are all out
170  val useBypass = enqPtr === deqPtr && decodeCanAccept && (numBypassRemain === 0.U || currentOutUseBypass && numBypassRemainNext === 0.U)
171
172  // The number of decode accepted insts.
173  // Since decode promises accepting insts in order, use priority encoder to simplify the accumulation.
174  private val numOut: UInt = PriorityMuxDefault(io.out.map(x => !x.ready) zip (0 until DecodeWidth).map(_.U), DecodeWidth.U)
175  private val numDeq = Mux(currentOutUseBypass, 0.U, numOut)
176
177  // counter current number of valid
178  val numValid = distanceBetween(enqPtr, deqPtr)
179  val numValidAfterDeq = numValid - numDeq
180  // counter next number of valid
181  val numValidNext = numValid + numEnq - numDeq
182  val allowEnq = RegInit(true.B)
183  val numFromFetch = Mux(io.in.valid, PopCount(io.in.bits.enqEnable), 0.U)
184  val numBypass = PopCount(bypassEntries.map(_.valid))
185
186  allowEnq := (IBufSize - PredictWidth).U >= numValidNext // Disable when almost full
187
188  val enqOffset = VecInit.tabulate(PredictWidth)(i => PopCount(io.in.bits.valid.asBools.take(i)))
189  val enqData = VecInit.tabulate(PredictWidth)(i => Wire(new IBufEntry).fromFetch(io.in.bits, i))
190
191  // when using bypass, bypassed entries do not enqueue
192  when(useBypass) {
193    when(numFromFetch >= DecodeWidth.U) {
194      numTryEnq := numFromFetch - DecodeWidth.U
195    } .otherwise {
196      numTryEnq := 0.U
197    }
198  } .otherwise {
199    numTryEnq := numFromFetch
200  }
201
202  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
203  // Bypass
204  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
205  bypassEntries.zipWithIndex.foreach {
206    case (entry, idx) =>
207      // Select
208      val validOH = Range(0, PredictWidth).map {
209        i =>
210          io.in.bits.valid(i) &&
211            io.in.bits.enqEnable(i) &&
212            enqOffset(i) === idx.asUInt
213      } // Should be OneHot
214      entry.valid := validOH.reduce(_ || _) && io.in.fire && !io.flush
215      entry.bits := Mux1H(validOH, enqData)
216
217      // Debug Assertion
218      XSError(io.in.valid && PopCount(validOH) > 1.asUInt, "validOH is not OneHot")
219  }
220
221  // => Decode Output
222  // clean register output
223  io.out zip outputEntries foreach {
224    case (io, reg) =>
225      io.valid := reg.valid
226      io.bits := reg.bits.toCtrlFlow
227  }
228  (outputEntries zip bypassEntries zip deqEntries).zipWithIndex.foreach {
229    case (((out, bypass), deq), i) =>
230      when(decodeCanAccept) {
231        when(useBypass && io.in.valid) {
232          out := bypass
233          currentOutUseBypass := true.B
234        }.elsewhen(currentOutUseBypass && numBypassRemainNext =/= 0.U) {
235          out := Mux(i.U < numBypassRemainNext, outputEntries(i.U + numOut), 0.U.asTypeOf(out))
236          currentOutUseBypass := true.B
237        }.otherwise {
238          out := deq
239          currentOutUseBypass := false.B
240        }
241      }
242  }
243
244  when(useBypass && io.in.valid) {
245    numBypassRemain := numBypass
246  }.elsewhen(currentOutUseBypass) {
247    numBypassRemain := numBypassRemainNext
248  }.otherwise {
249    assert(numBypassRemain === 0.U, "numBypassRemain should keep 0 when not in currentOutUseBypass")
250  }
251  numBypassRemainNext := numBypassRemain - numOut
252
253  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
254  // Enqueue
255  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
256  io.in.ready := allowEnq
257  // Data
258  ibuf.zipWithIndex.foreach {
259    case (entry, idx) => {
260      // Select
261      val validOH = Range(0, PredictWidth).map {
262        i =>
263          val useBypassMatch = enqOffset(i) >= DecodeWidth.U &&
264            enqPtrVec(enqOffset(i) - DecodeWidth.U).value === idx.asUInt
265          val normalMatch = enqPtrVec(enqOffset(i)).value === idx.asUInt
266          val m = Mux(useBypass, useBypassMatch, normalMatch) // when using bypass, bypassed entries do not enqueue
267
268          io.in.bits.valid(i) && io.in.bits.enqEnable(i) && m
269      } // Should be OneHot
270      val wen = validOH.reduce(_ || _) && io.in.fire && !io.flush
271
272      // Write port
273      // Each IBuffer entry has a PredictWidth -> 1 Mux
274      val writeEntry = Mux1H(validOH, enqData)
275      entry := Mux(wen, writeEntry, entry)
276
277      // Debug Assertion
278      XSError(io.in.valid && PopCount(validOH) > 1.asUInt, "validOH is not OneHot")
279    }
280  }
281  // Pointer maintenance
282  when (io.in.fire && !io.flush) {
283    enqPtrVec := VecInit(enqPtrVec.map(_ + numTryEnq))
284  }
285
286  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
287  // Dequeue
288  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
289  val validVec = Mux(numValidAfterDeq >= DecodeWidth.U,
290    ((1 << DecodeWidth) - 1).U,
291    UIntToMask(numValidAfterDeq(log2Ceil(DecodeWidth) - 1, 0), DecodeWidth)
292  )
293  // Data
294  // Read port
295  // 2-stage, IBufNBank * (bankSize -> 1) + IBufNBank -> 1
296  // Should be better than IBufSize -> 1 in area, with no significant latency increase
297  private val readStage1: Vec[IBufEntry] = VecInit.tabulate(IBufNBank)(
298    bankID => Mux1H(UIntToOH(deqInBankPtrNext(bankID).value), bankedIBufView(bankID))
299  )
300  for (i <- 0 until DecodeWidth) {
301    deqEntries(i).valid := validVec(i)
302    deqEntries(i).bits := Mux1H(UIntToOH(deqBankPtrVecNext(i).value), readStage1)
303  }
304  // Pointer maintenance
305  deqBankPtrVecNext := VecInit(deqBankPtrVec.map(_ + numDeq))
306  deqPtrNext := deqPtr + numDeq
307  deqInBankPtrNext.zip(deqInBankPtr).zipWithIndex.foreach {
308    case ((ptrNext, ptr), idx) => {
309      // validVec[k] == bankValid[deqBankPtr + k]
310      // So bankValid[n] == validVec[n - deqBankPtr]
311      val validIdx = Mux(idx.asUInt >= deqBankPtr.value,
312        idx.asUInt - deqBankPtr.value,
313        ((idx + IBufNBank).asUInt - deqBankPtr.value)(log2Ceil(IBufNBank) - 1, 0)
314      )(log2Ceil(DecodeWidth) - 1, 0)
315      val bankAdvance = Mux(validIdx >= DecodeWidth.U,
316        false.B,
317        io.out(validIdx).ready // `ready` depends on `valid`, so we need only `ready`, not fire
318      ) && !currentOutUseBypass
319      ptrNext := Mux(bankAdvance , ptr + 1.U, ptr)
320    }
321  }
322
323  // Flush
324  when (io.flush) {
325    allowEnq := true.B
326    enqPtrVec := enqPtrVec.indices.map(_.U.asTypeOf(new IBufPtr))
327    deqBankPtrVec := deqBankPtrVec.indices.map(_.U.asTypeOf(new IBufBankPtr))
328    deqInBankPtr := VecInit.fill(IBufNBank)(0.U.asTypeOf(new IBufInBankPtr))
329    deqPtr := 0.U.asTypeOf(new IBufPtr())
330    outputEntries.foreach(_.valid := false.B)
331    currentOutUseBypass := false.B
332    numBypassRemain := 0.U
333  }.otherwise {
334    deqPtr := deqPtrNext
335    deqInBankPtr := deqInBankPtrNext
336    deqBankPtrVec := deqBankPtrVecNext
337  }
338  io.full := !allowEnq
339
340  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
341  // TopDown
342  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
343  val topdown_stage = RegInit(0.U.asTypeOf(new FrontendTopDownBundle))
344  topdown_stage := io.in.bits.topdown_info
345  when(io.flush) {
346    when(io.ControlRedirect) {
347      when(io.ControlBTBMissBubble) {
348        topdown_stage.reasons(TopDownCounters.BTBMissBubble.id) := true.B
349      }.elsewhen(io.TAGEMissBubble) {
350        topdown_stage.reasons(TopDownCounters.TAGEMissBubble.id) := true.B
351      }.elsewhen(io.SCMissBubble) {
352        topdown_stage.reasons(TopDownCounters.SCMissBubble.id) := true.B
353      }.elsewhen(io.ITTAGEMissBubble) {
354        topdown_stage.reasons(TopDownCounters.ITTAGEMissBubble.id) := true.B
355      }.elsewhen(io.RASMissBubble) {
356        topdown_stage.reasons(TopDownCounters.RASMissBubble.id) := true.B
357      }
358    }.elsewhen(io.MemVioRedirect) {
359      topdown_stage.reasons(TopDownCounters.MemVioRedirectBubble.id) := true.B
360    }.otherwise {
361      topdown_stage.reasons(TopDownCounters.OtherRedirectBubble.id) := true.B
362    }
363  }
364
365
366  val dequeueInsufficient = Wire(Bool())
367  val matchBubble = Wire(UInt(log2Up(TopDownCounters.NumStallReasons.id).W))
368  val deqValidCount = PopCount(validVec.asBools)
369  val deqWasteCount = DecodeWidth.U - deqValidCount
370  dequeueInsufficient := deqValidCount < DecodeWidth.U
371  matchBubble := (TopDownCounters.NumStallReasons.id - 1).U - PriorityEncoder(topdown_stage.reasons.reverse)
372
373  io.stallReason.reason.map(_ := 0.U)
374  for (i <- 0 until DecodeWidth) {
375    when(i.U < deqWasteCount) {
376      io.stallReason.reason(DecodeWidth - i - 1) := matchBubble
377    }
378  }
379
380  when(!(deqWasteCount === DecodeWidth.U || topdown_stage.reasons.asUInt.orR)) {
381    // should set reason for FetchFragmentationStall
382    // topdown_stage.reasons(TopDownCounters.FetchFragmentationStall.id) := true.B
383    for (i <- 0 until DecodeWidth) {
384      when(i.U < deqWasteCount) {
385        io.stallReason.reason(DecodeWidth - i - 1) := TopDownCounters.FetchFragBubble.id.U
386      }
387    }
388  }
389
390  when(io.stallReason.backReason.valid) {
391    io.stallReason.reason.map(_ := io.stallReason.backReason.bits)
392  }
393
394  // Debug info
395  XSError(
396    deqPtr.value =/= deqBankPtr.value + deqInBankPtr(deqBankPtr.value).value * IBufNBank.asUInt,
397    "Dequeue PTR mismatch"
398  )
399  XSError(isBefore(enqPtr, deqPtr) && !isFull(enqPtr, deqPtr), "\ndeqPtr is older than enqPtr!\n")
400
401  XSDebug(io.flush, "IBuffer Flushed\n")
402
403  when(io.in.fire) {
404    XSDebug("Enque:\n")
405    XSDebug(p"MASK=${Binary(io.in.bits.valid)}\n")
406    for(i <- 0 until PredictWidth){
407      XSDebug(p"PC=${Hexadecimal(io.in.bits.pc(i))} ${Hexadecimal(io.in.bits.instrs(i))}\n")
408    }
409  }
410
411  for (i <- 0 until DecodeWidth) {
412    XSDebug(io.out(i).fire,
413      p"deq: ${Hexadecimal(io.out(i).bits.instr)} PC=${Hexadecimal(io.out(i).bits.pc)}" +
414      p"v=${io.out(i).valid} r=${io.out(i).ready} " +
415      p"excpVec=${Binary(io.out(i).bits.exceptionVec.asUInt)} crossPageIPF=${io.out(i).bits.crossPageIPFFix}\n")
416  }
417
418  XSDebug(p"numValid: ${numValid}\n")
419  XSDebug(p"EnqNum: ${numEnq}\n")
420  XSDebug(p"DeqNum: ${numDeq}\n")
421
422  val afterInit = RegInit(false.B)
423  val headBubble = RegInit(false.B)
424  when (io.in.fire) { afterInit := true.B }
425  when (io.flush) {
426    headBubble := true.B
427  } .elsewhen(numValid =/= 0.U) {
428    headBubble := false.B
429  }
430  val instrHungry = afterInit && (numValid === 0.U) && !headBubble
431
432  QueuePerf(IBufSize, numValid, !allowEnq)
433  XSPerfAccumulate("flush", io.flush)
434  XSPerfAccumulate("hungry", instrHungry)
435
436  val ibuffer_IDWidth_hvButNotFull = afterInit && (numValid =/= 0.U) && (numValid < DecodeWidth.U) && !headBubble
437  XSPerfAccumulate("ibuffer_IDWidth_hvButNotFull", ibuffer_IDWidth_hvButNotFull)
438  /*
439  XSPerfAccumulate("ICacheMissBubble", Mux(matchBubbleVec(TopDownCounters.ICacheMissBubble.id), deqWasteCount, 0.U))
440  XSPerfAccumulate("ITLBMissBubble", Mux(matchBubbleVec(TopDownCounters.ITLBMissBubble.id), deqWasteCount, 0.U))
441  XSPerfAccumulate("ControlRedirectBubble", Mux(matchBubbleVec(TopDownCounters.ControlRedirectBubble.id), deqWasteCount, 0.U))
442  XSPerfAccumulate("MemVioRedirectBubble", Mux(matchBubbleVec(TopDownCounters.MemVioRedirectBubble.id), deqWasteCount, 0.U))
443  XSPerfAccumulate("OtherRedirectBubble", Mux(matchBubbleVec(TopDownCounters.OtherRedirectBubble.id), deqWasteCount, 0.U))
444  XSPerfAccumulate("BTBMissBubble", Mux(matchBubbleVec(TopDownCounters.BTBMissBubble.id), deqWasteCount, 0.U))
445  XSPerfAccumulate("OverrideBubble", Mux(matchBubbleVec(TopDownCounters.OverrideBubble.id), deqWasteCount, 0.U))
446  XSPerfAccumulate("FtqUpdateBubble", Mux(matchBubbleVec(TopDownCounters.FtqUpdateBubble.id), deqWasteCount, 0.U))
447  XSPerfAccumulate("FtqFullStall", Mux(matchBubbleVec(TopDownCounters.FtqFullStall.id), deqWasteCount, 0.U))
448  XSPerfAccumulate("FetchFragmentBubble",
449  Mux(deqWasteCount === DecodeWidth.U || topdown_stage.reasons.asUInt.orR, 0.U, deqWasteCount))
450  XSPerfAccumulate("TAGEMissBubble", Mux(matchBubbleVec(TopDownCounters.TAGEMissBubble.id), deqWasteCount, 0.U))
451  XSPerfAccumulate("SCMissBubble", Mux(matchBubbleVec(TopDownCounters.SCMissBubble.id), deqWasteCount, 0.U))
452  XSPerfAccumulate("ITTAGEMissBubble", Mux(matchBubbleVec(TopDownCounters.ITTAGEMissBubble.id), deqWasteCount, 0.U))
453  XSPerfAccumulate("RASMissBubble", Mux(matchBubbleVec(TopDownCounters.RASMissBubble.id), deqWasteCount, 0.U))
454  */
455
456  val perfEvents = Seq(
457    ("IBuffer_Flushed  ", io.flush                                                                     ),
458    ("IBuffer_hungry   ", instrHungry                                                                  ),
459    ("IBuffer_1_4_valid", (numValid >  (0*(IBufSize/4)).U) & (numValid < (1*(IBufSize/4)).U)   ),
460    ("IBuffer_2_4_valid", (numValid >= (1*(IBufSize/4)).U) & (numValid < (2*(IBufSize/4)).U)   ),
461    ("IBuffer_3_4_valid", (numValid >= (2*(IBufSize/4)).U) & (numValid < (3*(IBufSize/4)).U)   ),
462    ("IBuffer_4_4_valid", (numValid >= (3*(IBufSize/4)).U) & (numValid < (4*(IBufSize/4)).U)   ),
463    ("IBuffer_full     ",  numValid.andR                                                           ),
464    ("Front_Bubble     ", PopCount((0 until DecodeWidth).map(i => io.out(i).ready && !io.out(i).valid)))
465  )
466  generatePerfEvent()
467}
468