xref: /XiangShan/src/main/scala/xiangshan/frontend/FTB.scala (revision 84e47f35db7c435223b222af2342463b2f92e059)
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 chipsalliance.rocketchip.config.Parameters
20import chisel3._
21import chisel3.stage.{ChiselGeneratorAnnotation, ChiselStage}
22import chisel3.util._
23import xiangshan._
24import utils._
25import chisel3.experimental.chiselName
26
27import scala.math.min
28import os.copy
29
30
31trait FTBParams extends HasXSParameter with HasBPUConst {
32  val numEntries = 4096
33  val numWays    = 4
34  val numSets    = numEntries/numWays // 512
35  val tagSize    = 20
36
37
38
39  val TAR_STAT_SZ = 2
40  def TAR_FIT = 0.U(TAR_STAT_SZ.W)
41  def TAR_OVF = 1.U(TAR_STAT_SZ.W)
42  def TAR_UDF = 2.U(TAR_STAT_SZ.W)
43
44  def BR_OFFSET_LEN = 12
45  def JMP_OFFSET_LEN = 20
46}
47
48class FtbSlot(val offsetLen: Int, val subOffsetLen: Int = 0)(implicit p: Parameters) extends XSBundle with FTBParams {
49  require(subOffsetLen <= offsetLen)
50  val offset  = UInt(log2Ceil(PredictWidth).W)
51  val lower   = UInt(offsetLen.W)
52  val tarStat = UInt(TAR_STAT_SZ.W)
53  val sharing = Bool()
54  val valid   = Bool()
55
56  def setLowerStatByTarget(pc: UInt, target: UInt, isShare: Boolean) = {
57    def getTargetStatByHigher(pc_higher: UInt, target_higher: UInt) =
58      Mux(target_higher > pc_higher, TAR_OVF,
59        Mux(target_higher < pc_higher, TAR_UDF, TAR_FIT))
60    def getLowerByTarget(target: UInt, offsetLen: Int) = target(offsetLen, 1)
61    val offLen = if (isShare) this.subOffsetLen else this.offsetLen
62    val pc_higher = pc(VAddrBits-1, offLen+1)
63    val target_higher = target(VAddrBits-1, offLen+1)
64    val stat = getTargetStatByHigher(pc_higher, target_higher)
65    val lower = ZeroExt(getLowerByTarget(target, offLen), this.offsetLen)
66    this.lower := lower
67    this.tarStat := stat
68    this.sharing := isShare.B
69  }
70
71  def getTarget(pc: UInt) = {
72    def getTarget(offLen: Int)(pc: UInt, lower: UInt, stat: UInt) = {
73      val higher = pc(VAddrBits-1, offLen+1)
74      val target =
75        Cat(
76          Mux(stat === TAR_OVF, higher+1.U,
77            Mux(stat === TAR_UDF, higher-1.U, higher)),
78          lower(offLen-1, 0), 0.U(1.W)
79        )
80      require(target.getWidth == VAddrBits)
81      require(offLen != 0)
82      target
83    }
84    if (subOffsetLen != 0)
85      Mux(sharing,
86        getTarget(subOffsetLen)(pc, lower, tarStat),
87        getTarget(offsetLen)(pc, lower, tarStat)
88      )
89    else
90      getTarget(offsetLen)(pc, lower, tarStat)
91  }
92  def fromAnotherSlot(that: FtbSlot) = {
93    require(
94      this.offsetLen > that.offsetLen && that.offsetLen == this.subOffsetLen ||
95      this.offsetLen == that.offsetLen
96    )
97    this.offset := that.offset
98    this.tarStat := that.tarStat
99    this.sharing := (this.offsetLen > that.offsetLen && that.offsetLen == this.subOffsetLen).B
100    this.valid := that.valid
101    this.lower := ZeroExt(that.lower, this.offsetLen)
102  }
103
104}
105
106class FTBEntry(implicit p: Parameters) extends XSBundle with FTBParams with BPUUtils {
107
108
109  val valid       = Bool()
110
111  val brSlots = Vec(numBrSlot, new FtbSlot(BR_OFFSET_LEN))
112
113  // if shareTailSlot is set, this slot can hold a branch or a jal/jalr
114  // else this slot holds only jal/jalr
115  val tailSlot = new FtbSlot(JMP_OFFSET_LEN, BR_OFFSET_LEN)
116
117  // Partial Fall-Through Address
118  val pftAddr     = UInt((log2Up(PredictWidth)+1).W)
119  val carry       = Bool()
120
121  val isCall      = Bool()
122  val isRet       = Bool()
123  val isJalr      = Bool()
124
125  //
126  val oversize    = Bool()
127
128  val last_is_rvc = Bool()
129
130  val always_taken = Vec(numBr, Bool())
131
132  def getSlotForBr(idx: Int): FtbSlot = {
133    require(
134      idx < numBr-1 || idx == numBr-1 && !shareTailSlot ||
135      idx == numBr-1 && shareTailSlot
136    )
137    (idx, numBr, shareTailSlot) match {
138      case (i, n, true) if i == n-1 => this.tailSlot
139      case _ => this.brSlots(idx)
140    }
141  }
142  def allSlotsForBr = {
143    (0 until numBr).map(getSlotForBr(_))
144  }
145  def setByBrTarget(brIdx: Int, pc: UInt, target: UInt) = {
146    val slot = getSlotForBr(brIdx)
147    slot.setLowerStatByTarget(pc, target, shareTailSlot && brIdx == numBr-1)
148  }
149  def setByJmpTarget(pc: UInt, target: UInt) = {
150    this.tailSlot.setLowerStatByTarget(pc, target, false)
151  }
152
153  def getTargetVec(pc: UInt) = {
154    VecInit((brSlots :+ tailSlot).map(_.getTarget(pc)))
155  }
156
157  def getOffsetVec = VecInit(brSlots.map(_.offset) :+ tailSlot.offset)
158  def isJal = !isJalr
159  def getFallThrough(pc: UInt) = getFallThroughAddr(pc, carry, pftAddr)
160  def hasBr(offset: UInt) =
161    brSlots.map{ s => s.valid && s.offset <= offset}.reduce(_||_) ||
162    (shareTailSlot.B && tailSlot.valid && tailSlot.offset <= offset && tailSlot.sharing)
163
164  def getBrMaskByOffset(offset: UInt) =
165    brSlots.map{ s => s.valid && s.offset <= offset } ++
166    (if (shareTailSlot) Seq(tailSlot.valid && tailSlot.offset <= offset && tailSlot.sharing) else Nil)
167
168  def getBrRecordedVec(offset: UInt) = {
169    VecInit(
170      brSlots.map(s => s.valid && s.offset === offset) ++
171      (if (shareTailSlot) Seq(tailSlot.valid && tailSlot.offset === offset && tailSlot.sharing) else Nil)
172    )
173  }
174
175  def brIsSaved(offset: UInt) = getBrRecordedVec(offset).reduce(_||_)
176
177  def brValids = {
178    VecInit(
179      brSlots.map(_.valid) ++
180      (if (shareTailSlot) Seq(tailSlot.valid && tailSlot.sharing) else Nil)
181    )
182  }
183
184  def noEmptySlotForNewBr = {
185    VecInit(
186      brSlots.map(_.valid) ++
187      (if (shareTailSlot) Seq(tailSlot.valid) else Nil)
188    ).reduce(_&&_)
189  }
190
191  def newBrCanNotInsert(offset: UInt) = {
192    val lastSlotForBr = if (shareTailSlot) tailSlot else brSlots.last
193    lastSlotForBr.valid && lastSlotForBr.offset < offset
194  }
195
196  def jmpValid = {
197    tailSlot.valid && (!shareTailSlot.B || !tailSlot.sharing)
198  }
199
200  def brOffset = {
201    VecInit(
202      brSlots.map(_.offset) ++
203      (if (shareTailSlot) Seq(tailSlot.offset) else Nil)
204    )
205  }
206
207
208  def display(cond: Bool): Unit = {
209    XSDebug(cond, p"-----------FTB entry----------- \n")
210    XSDebug(cond, p"v=${valid}\n")
211    for(i <- 0 until numBr) {
212      XSDebug(cond, p"[br$i]: v=${allSlotsForBr(i).valid}, offset=${allSlotsForBr(i).offset}," +
213        p"lower=${Hexadecimal(allSlotsForBr(i).lower)}\n")
214    }
215    XSDebug(cond, p"[tailSlot]: v=${tailSlot.valid}, offset=${tailSlot.offset}," +
216      p"lower=${Hexadecimal(tailSlot.lower)}, sharing=${tailSlot.sharing}}\n")
217    XSDebug(cond, p"pftAddr=${Hexadecimal(pftAddr)}, carry=$carry\n")
218    XSDebug(cond, p"isCall=$isCall, isRet=$isRet, isjalr=$isJalr\n")
219    XSDebug(cond, p"oversize=$oversize, last_is_rvc=$last_is_rvc\n")
220    XSDebug(cond, p"------------------------------- \n")
221  }
222
223}
224
225class FTBEntryWithTag(implicit p: Parameters) extends XSBundle with FTBParams with BPUUtils {
226  val entry = new FTBEntry
227  val tag = UInt(tagSize.W)
228  def display(cond: Bool): Unit = {
229    entry.display(cond)
230    XSDebug(cond, p"tag is ${Hexadecimal(tag)}\n------------------------------- \n")
231  }
232}
233
234class FTBMeta(implicit p: Parameters) extends XSBundle with FTBParams {
235  val writeWay = UInt(log2Ceil(numWays).W)
236  val hit = Bool()
237  val pred_cycle = UInt(64.W) // TODO: Use Option
238}
239
240object FTBMeta {
241  def apply(writeWay: UInt, hit: Bool, pred_cycle: UInt)(implicit p: Parameters): FTBMeta = {
242    val e = Wire(new FTBMeta)
243    e.writeWay := writeWay
244    e.hit := hit
245    e.pred_cycle := pred_cycle
246    e
247  }
248}
249
250// class UpdateQueueEntry(implicit p: Parameters) extends XSBundle with FTBParams {
251//   val pc = UInt(VAddrBits.W)
252//   val ftb_entry = new FTBEntry
253//   val hit = Bool()
254//   val hit_way = UInt(log2Ceil(numWays).W)
255// }
256//
257// object UpdateQueueEntry {
258//   def apply(pc: UInt, fe: FTBEntry, hit: Bool, hit_way: UInt)(implicit p: Parameters): UpdateQueueEntry = {
259//     val e = Wire(new UpdateQueueEntry)
260//     e.pc := pc
261//     e.ftb_entry := fe
262//     e.hit := hit
263//     e.hit_way := hit_way
264//     e
265//   }
266// }
267
268class FTB(implicit p: Parameters) extends BasePredictor with FTBParams with BPUUtils with HasCircularQueuePtrHelper {
269  override val meta_size = WireInit(0.U.asTypeOf(new FTBMeta)).getWidth
270
271  val ftbAddr = new TableAddr(log2Up(numSets), 1)
272
273  class FTBBank(val numSets: Int, val nWays: Int) extends XSModule with BPUUtils {
274    val io = IO(new Bundle {
275      val s1_fire = Input(Bool())
276
277      // when ftb hit, read_hits.valid is true, and read_hits.bits is OH of hit way
278      // when ftb not hit, read_hits.valid is false, and read_hits is OH of allocWay
279      // val read_hits = Valid(Vec(numWays, Bool()))
280      val req_pc = Flipped(DecoupledIO(UInt(VAddrBits.W)))
281      val read_resp = Output(new FTBEntry)
282      val read_hits = Valid(UInt(log2Ceil(numWays).W))
283
284      val u_req_pc = Flipped(DecoupledIO(UInt(VAddrBits.W)))
285      val update_hits = Valid(UInt(log2Ceil(numWays).W))
286      val update_access = Input(Bool())
287
288      val update_pc = Input(UInt(VAddrBits.W))
289      val update_write_data = Flipped(Valid(new FTBEntryWithTag))
290      val update_write_way = Input(UInt(log2Ceil(numWays).W))
291      val update_write_alloc = Input(Bool())
292    })
293
294    // Extract holdRead logic to fix bug that update read override predict read result
295    val ftb = Module(new SRAMTemplate(new FTBEntryWithTag, set = numSets, way = numWays, shouldReset = true, holdRead = false, singlePort = true))
296
297    val pred_rdata   = HoldUnless(ftb.io.r.resp.data, RegNext(io.req_pc.valid && !io.update_access))
298    ftb.io.r.req.valid := io.req_pc.valid || io.u_req_pc.valid // io.s0_fire
299    ftb.io.r.req.bits.setIdx := Mux(io.u_req_pc.valid, ftbAddr.getIdx(io.u_req_pc.bits), ftbAddr.getIdx(io.req_pc.bits)) // s0_idx
300
301    assert(!(io.req_pc.valid && io.u_req_pc.valid))
302
303    io.req_pc.ready := ftb.io.r.req.ready
304    io.u_req_pc.ready := ftb.io.r.req.ready
305
306    val req_tag = RegEnable(ftbAddr.getTag(io.req_pc.bits)(tagSize-1, 0), io.req_pc.valid)
307    val req_idx = RegEnable(ftbAddr.getIdx(io.req_pc.bits), io.req_pc.valid)
308
309    val u_req_tag = RegEnable(ftbAddr.getTag(io.u_req_pc.bits)(tagSize-1, 0), io.u_req_pc.valid)
310
311    val read_entries = pred_rdata.map(_.entry)
312    val read_tags    = pred_rdata.map(_.tag)
313
314    val total_hits = VecInit((0 until numWays).map(b => read_tags(b) === req_tag && read_entries(b).valid && io.s1_fire))
315    val hit = total_hits.reduce(_||_)
316    // val hit_way_1h = VecInit(PriorityEncoderOH(total_hits))
317    val hit_way = OHToUInt(total_hits)
318
319    val u_total_hits = VecInit((0 until numWays).map(b =>
320        ftb.io.r.resp.data(b).tag === u_req_tag && ftb.io.r.resp.data(b).entry.valid && RegNext(io.update_access)))
321    val u_hit = u_total_hits.reduce(_||_)
322    // val hit_way_1h = VecInit(PriorityEncoderOH(total_hits))
323    val u_hit_way = OHToUInt(u_total_hits)
324
325    assert(PopCount(total_hits) === 1.U || PopCount(total_hits) === 0.U)
326    assert(PopCount(u_total_hits) === 1.U || PopCount(u_total_hits) === 0.U)
327
328    val replacer = ReplacementPolicy.fromString(Some("setplru"), numWays, numSets)
329    // val allocWriteWay = replacer.way(req_idx)
330
331    val touch_set = Seq.fill(1)(Wire(UInt(log2Ceil(numSets).W)))
332    val touch_way = Seq.fill(1)(Wire(Valid(UInt(log2Ceil(numWays).W))))
333
334    touch_set(0) := req_idx
335
336    touch_way(0).valid := hit
337    touch_way(0).bits := hit_way
338
339    replacer.access(touch_set, touch_way)
340
341    // def allocWay(valids: UInt, meta_tags: UInt, req_tag: UInt) = {
342    //   val randomAlloc = false
343    //   if (numWays > 1) {
344    //     val w = Wire(UInt(log2Up(numWays).W))
345    //     val valid = WireInit(valids.andR)
346    //     val tags = Cat(meta_tags, req_tag)
347    //     val l = log2Up(numWays)
348    //     val nChunks = (tags.getWidth + l - 1) / l
349    //     val chunks = (0 until nChunks).map( i =>
350    //       tags(min((i+1)*l, tags.getWidth)-1, i*l)
351    //     )
352    //     w := Mux(valid, if (randomAlloc) {LFSR64()(log2Up(numWays)-1,0)} else {chunks.reduce(_^_)}, PriorityEncoder(~valids))
353    //     w
354    //   } else {
355    //     val w = WireInit(0.U)
356    //     w
357    //   }
358    // }
359
360    // val allocWriteWay = allocWay(
361    //   VecInit(read_entries.map(_.valid)).asUInt,
362    //   VecInit(read_tags).asUInt,
363    //   req_tag
364    // )
365
366    def allocWay(valids: UInt, idx: UInt) = {
367      if (numWays > 1) {
368        val w = Wire(UInt(log2Up(numWays).W))
369        val valid = WireInit(valids.andR)
370        w := Mux(valid, replacer.way(idx), PriorityEncoder(~valids))
371        w
372      }else {
373        val w = WireInit(0.U)
374        w
375      }
376    }
377
378    io.read_resp := Mux1H(total_hits, read_entries) // Mux1H
379    io.read_hits.valid := hit
380    // io.read_hits.bits := Mux(hit, hit_way_1h, VecInit(UIntToOH(allocWriteWay).asBools()))
381    io.read_hits.bits := hit_way
382
383    io.update_hits.valid := u_hit
384    io.update_hits.bits := u_hit_way
385
386    // XSDebug(!hit, "FTB not hit, alloc a way: %d\n", allocWriteWay)
387
388    // Update logic
389    val u_valid = io.update_write_data.valid
390    val u_data = io.update_write_data.bits
391    val u_idx = ftbAddr.getIdx(io.update_pc)
392    val allocWriteWay = allocWay(VecInit(read_entries.map(_.valid)).asUInt, u_idx)
393    val u_mask = UIntToOH(Mux(io.update_write_alloc, allocWriteWay, io.update_write_way))
394
395    for (i <- 0 until numWays) {
396      XSPerfAccumulate(f"ftb_replace_way$i", u_valid && io.update_write_alloc && OHToUInt(u_mask) === i.U)
397      XSPerfAccumulate(f"ftb_replace_way${i}_has_empty", u_valid && io.update_write_alloc && !read_entries.map(_.valid).reduce(_&&_) && OHToUInt(u_mask) === i.U)
398      XSPerfAccumulate(f"ftb_hit_way$i", hit && !io.update_access && hit_way === i.U)
399    }
400
401    ftb.io.w.apply(u_valid, u_data, u_idx, u_mask)
402
403    // print hit entry info
404    Mux1H(total_hits, ftb.io.r.resp.data).display(true.B)
405  } // FTBBank
406
407  val ftbBank = Module(new FTBBank(numSets, numWays))
408
409  ftbBank.io.req_pc.valid := io.s0_fire
410  ftbBank.io.req_pc.bits := s0_pc
411
412  val ftb_entry = RegEnable(ftbBank.io.read_resp, io.s1_fire)
413  val s1_hit = ftbBank.io.read_hits.valid
414  val s2_hit = RegEnable(s1_hit, io.s1_fire)
415  val writeWay = ftbBank.io.read_hits.bits
416
417  val fallThruAddr = getFallThroughAddr(s2_pc, ftb_entry.carry, ftb_entry.pftAddr)
418
419  // io.out.bits.resp := RegEnable(io.in.bits.resp_in(0), 0.U.asTypeOf(new BranchPredictionResp), io.s1_fire)
420  io.out.resp := io.in.bits.resp_in(0)
421
422  val s1_latch_call_is_rvc   = DontCare // TODO: modify when add RAS
423
424  io.out.resp.s2.preds.hit           := s2_hit
425  io.out.resp.s2.pc                  := s2_pc
426  io.out.resp.s2.ftb_entry           := ftb_entry
427  io.out.resp.s2.preds.fromFtbEntry(ftb_entry, s2_pc)
428
429  io.out.s3_meta := RegEnable(RegEnable(FTBMeta(writeWay.asUInt(), s1_hit, GTimer()).asUInt(), io.s1_fire), io.s2_fire)
430
431  // always taken logic
432  when (s2_hit) {
433    for (i <- 0 until numBr) {
434      when (ftb_entry.always_taken(i)) {
435        io.out.resp.s2.preds.br_taken_mask(i) := true.B
436      }
437    }
438  }
439
440  // Update logic
441  val update = RegNext(io.update.bits)
442
443  // val update_queue = Mem(64, new UpdateQueueEntry)
444  // val head, tail = RegInit(UpdateQueuePtr(false.B, 0.U))
445  // val u_queue = Module(new Queue(new UpdateQueueEntry, entries = 64, flow = true))
446  // assert(u_queue.io.count < 64.U)
447
448  val u_meta = update.meta.asTypeOf(new FTBMeta)
449  val u_valid = RegNext(io.update.valid && !io.update.bits.old_entry)
450
451  // io.s1_ready := ftbBank.io.req_pc.ready && u_queue.io.count === 0.U && !u_valid
452  io.s1_ready := ftbBank.io.req_pc.ready && !(u_valid && !u_meta.hit)
453
454  // val update_now = u_queue.io.deq.fire && u_queue.io.deq.bits.hit
455  val update_now = u_valid && u_meta.hit
456
457  ftbBank.io.u_req_pc.valid := u_valid && !u_meta.hit
458  ftbBank.io.u_req_pc.bits := update.pc
459
460  // assert(!(u_valid && RegNext(u_valid) && update.pc === RegNext(update.pc)))
461  // assert(!(u_valid && RegNext(u_valid)))
462
463  // val u_way = u_queue.io.deq.bits.hit_way
464
465  val ftb_write = Wire(new FTBEntryWithTag)
466  // ftb_write.entry := Mux(update_now, u_queue.io.deq.bits.ftb_entry, RegNext(u_queue.io.deq.bits.ftb_entry))
467  // ftb_write.tag   := ftbAddr.getTag(Mux(update_now, u_queue.io.deq.bits.pc, RegNext(u_queue.io.deq.bits.pc)))(tagSize-1, 0)
468  ftb_write.entry := Mux(update_now, update.ftb_entry, RegNext(update.ftb_entry))
469  ftb_write.tag   := ftbAddr.getTag(Mux(update_now, update.pc, RegNext(update.pc)))(tagSize-1, 0)
470
471  // val write_valid = update_now || RegNext(u_queue.io.deq.fire && !u_queue.io.deq.bits.hit)
472  val write_valid = update_now || RegNext(u_valid && !u_meta.hit)
473
474  // u_queue.io.enq.valid := u_valid
475  // u_queue.io.enq.bits := UpdateQueueEntry(update.pc, update.ftb_entry, u_meta.hit, u_meta.writeWay)
476  // u_queue.io.deq.ready := RegNext(!u_queue.io.deq.fire || update_now)
477
478  ftbBank.io.update_write_data.valid := write_valid
479  ftbBank.io.update_write_data.bits := ftb_write
480  // ftbBank.io.update_pc := Mux(update_now, u_queue.io.deq.bits.pc, RegNext(u_queue.io.deq.bits.pc))
481  ftbBank.io.update_pc := Mux(update_now, update.pc, RegNext(update.pc))
482  ftbBank.io.update_write_way := Mux(update_now, u_meta.writeWay, ftbBank.io.update_hits.bits)
483  // ftbBank.io.update_write_alloc := Mux(update_now, !u_queue.io.deq.bits.hit, !ftbBank.io.update_hits.valid)
484  ftbBank.io.update_write_alloc := Mux(update_now, false.B, !ftbBank.io.update_hits.valid)
485  ftbBank.io.update_access := u_valid && !u_meta.hit
486  ftbBank.io.s1_fire := io.s1_fire
487
488  XSDebug("req_v=%b, req_pc=%x, ready=%b (resp at next cycle)\n", io.s0_fire, s0_pc, ftbBank.io.req_pc.ready)
489  XSDebug("s2_hit=%b, hit_way=%b\n", s2_hit, writeWay.asUInt)
490  XSDebug("s2_br_taken_mask=%b, s2_real_taken_mask=%b\n",
491    io.in.bits.resp_in(0).s2.preds.br_taken_mask.asUInt, io.out.resp.s2.real_slot_taken_mask().asUInt)
492  XSDebug("s2_target=%x\n", io.out.resp.s2.target)
493
494  ftb_entry.display(true.B)
495
496  XSPerfAccumulate("ftb_read_hits", RegNext(io.s0_fire) && s1_hit)
497  XSPerfAccumulate("ftb_read_misses", RegNext(io.s0_fire) && !s1_hit)
498
499  XSPerfAccumulate("ftb_commit_hits", io.update.valid && io.update.bits.preds.hit)
500  XSPerfAccumulate("ftb_commit_misses", io.update.valid && !io.update.bits.preds.hit)
501
502  XSPerfAccumulate("ftb_update_req", io.update.valid)
503  XSPerfAccumulate("ftb_update_ignored", io.update.valid && io.update.bits.old_entry)
504  XSPerfAccumulate("ftb_updated", u_valid)
505
506  val perfinfo = IO(new Bundle(){
507    val perfEvents = Output(new PerfEventsBundle(2))
508  })
509  val perfEvents = Seq(
510    ("ftb_commit_hits            ", u_valid  &&  update.preds.hit),
511    ("ftb_commit_misses          ", u_valid  && !update.preds.hit),
512  )
513
514  for (((perf_out,(perf_name,perf)),i) <- perfinfo.perfEvents.perf_events.zip(perfEvents).zipWithIndex) {
515    perf_out.incr_step := RegNext(perf)
516  }
517}
518