xref: /XiangShan/src/main/scala/xiangshan/frontend/FrontendBundle.scala (revision b37e4b45da2333608f12413931aecdaef46443e4)
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.frontend
17
18import chipsalliance.rocketchip.config.Parameters
19import chisel3._
20import chisel3.util._
21import chisel3.experimental.chiselName
22import xiangshan._
23import xiangshan.frontend.icache.HasICacheParameters
24import utils._
25import scala.math._
26
27@chiselName
28class FetchRequestBundle(implicit p: Parameters) extends XSBundle with HasICacheParameters {
29  val startAddr       = UInt(VAddrBits.W)
30  val nextlineStart   = UInt(VAddrBits.W)
31  // val fallThruError   = Bool()
32  val ftqIdx          = new FtqPtr
33  val ftqOffset       = ValidUndirectioned(UInt(log2Ceil(PredictWidth).W))
34  val nextStartAddr   = UInt(VAddrBits.W)
35  val oversize        = Bool()
36
37  def crossCacheline = startAddr(blockOffBits - 1) === 1.U
38
39  def fromFtqPcBundle(b: Ftq_RF_Components) = {
40    this.startAddr := b.startAddr
41    this.nextlineStart := b.nextLineAddr
42    this.oversize := b.oversize
43    when (b.fallThruError) {
44      val nextBlockHigherTemp = Mux(startAddr(log2Ceil(PredictWidth)+instOffsetBits), b.startAddr, b.nextLineAddr)
45      val nextBlockHigher = nextBlockHigherTemp(VAddrBits-1, log2Ceil(PredictWidth)+instOffsetBits+1)
46      this.nextStartAddr :=
47        Cat(nextBlockHigher,
48          startAddr(log2Ceil(PredictWidth)+instOffsetBits) ^ 1.U(1.W),
49          startAddr(log2Ceil(PredictWidth)+instOffsetBits-1, instOffsetBits),
50          0.U(instOffsetBits.W)
51        )
52    }
53    this
54  }
55  override def toPrintable: Printable = {
56    p"[start] ${Hexadecimal(startAddr)} [next] ${Hexadecimal(nextlineStart)}" +
57      p"[tgt] ${Hexadecimal(nextStartAddr)} [ftqIdx] $ftqIdx [jmp] v:${ftqOffset.valid}" +
58      p" offset: ${ftqOffset.bits}\n"
59  }
60}
61
62class PredecodeWritebackBundle(implicit p:Parameters) extends XSBundle {
63  val pc           = Vec(PredictWidth, UInt(VAddrBits.W))
64  val pd           = Vec(PredictWidth, new PreDecodeInfo) // TODO: redefine Predecode
65  val ftqIdx       = new FtqPtr
66  val ftqOffset    = UInt(log2Ceil(PredictWidth).W)
67  val misOffset    = ValidUndirectioned(UInt(log2Ceil(PredictWidth).W))
68  val cfiOffset    = ValidUndirectioned(UInt(log2Ceil(PredictWidth).W))
69  val target       = UInt(VAddrBits.W)
70  val jalTarget    = UInt(VAddrBits.W)
71  val instrRange   = Vec(PredictWidth, Bool())
72}
73
74class Exception(implicit p: Parameters) extends XSBundle {
75
76}
77
78class FetchToIBuffer(implicit p: Parameters) extends XSBundle {
79  val instrs    = Vec(PredictWidth, UInt(32.W))
80  val valid     = UInt(PredictWidth.W)
81  val enqEnable = UInt(PredictWidth.W)
82  val pd        = Vec(PredictWidth, new PreDecodeInfo)
83  val pc        = Vec(PredictWidth, UInt(VAddrBits.W))
84  val foldpc    = Vec(PredictWidth, UInt(MemPredPCWidth.W))
85  val ftqPtr       = new FtqPtr
86  val ftqOffset    = Vec(PredictWidth, ValidUndirectioned(UInt(log2Ceil(PredictWidth).W)))
87  val ipf          = Vec(PredictWidth, Bool())
88  val acf          = Vec(PredictWidth, Bool())
89  val crossPageIPFFix = Vec(PredictWidth, Bool())
90  val triggered    = Vec(PredictWidth, new TriggerCf)
91}
92
93// class BitWiseUInt(val width: Int, val init: UInt) extends Module {
94//   val io = IO(new Bundle {
95//     val set
96//   })
97// }
98// Move from BPU
99abstract class GlobalHistory(implicit p: Parameters) extends XSBundle with HasBPUConst {
100  def update(br_valids: Vec[Bool], real_taken_mask: Vec[Bool]): GlobalHistory
101}
102
103class ShiftingGlobalHistory(implicit p: Parameters) extends GlobalHistory {
104  val predHist = UInt(HistoryLength.W)
105
106  def update(shift: UInt, taken: Bool, hist: UInt = this.predHist): ShiftingGlobalHistory = {
107    val g = Wire(new ShiftingGlobalHistory)
108    g.predHist := (hist << shift) | taken
109    g
110  }
111
112  def update(br_valids: Vec[Bool], real_taken_mask: Vec[Bool]): ShiftingGlobalHistory = {
113    require(br_valids.length == numBr)
114    require(real_taken_mask.length == numBr)
115    val last_valid_idx = PriorityMux(
116      br_valids.reverse :+ true.B,
117      (numBr to 0 by -1).map(_.U(log2Ceil(numBr+1).W))
118    )
119    val first_taken_idx = PriorityEncoder(false.B +: real_taken_mask)
120    val smaller = Mux(last_valid_idx < first_taken_idx,
121      last_valid_idx,
122      first_taken_idx
123    )
124    val shift = smaller
125    val taken = real_taken_mask.reduce(_||_)
126    update(shift, taken, this.predHist)
127  }
128
129  // static read
130  def read(n: Int): Bool = predHist.asBools()(n)
131
132  final def === (that: ShiftingGlobalHistory): Bool = {
133    predHist === that.predHist
134  }
135
136  final def =/= (that: ShiftingGlobalHistory): Bool = !(this === that)
137}
138
139// circular global history pointer
140class CGHPtr(implicit p: Parameters) extends CircularQueuePtr[CGHPtr](
141  p => p(XSCoreParamsKey).HistoryLength
142){
143  override def cloneType = (new CGHPtr).asInstanceOf[this.type]
144}
145class CircularGlobalHistory(implicit p: Parameters) extends GlobalHistory {
146  val buffer = Vec(HistoryLength, Bool())
147  type HistPtr = UInt
148  def update(br_valids: Vec[Bool], real_taken_mask: Vec[Bool]): CircularGlobalHistory = {
149    this
150  }
151}
152
153class FoldedHistory(val len: Int, val compLen: Int, val max_update_num: Int)(implicit p: Parameters)
154  extends XSBundle with HasBPUConst {
155  require(compLen >= 1)
156  require(len > 0)
157  // require(folded_len <= len)
158  require(compLen >= max_update_num)
159  val folded_hist = UInt(compLen.W)
160
161  def info = (len, compLen)
162  def oldest_bit_to_get_from_ghr = (0 until max_update_num).map(len - _ - 1)
163  def oldest_bit_pos_in_folded = oldest_bit_to_get_from_ghr map (_ % compLen)
164  def oldest_bit_wrap_around = oldest_bit_to_get_from_ghr map (_ / compLen > 0)
165  def oldest_bit_start = oldest_bit_pos_in_folded.head
166
167  def get_oldest_bits_from_ghr(ghr: Vec[Bool], histPtr: CGHPtr) = {
168    // TODO: wrap inc for histPtr value
169    oldest_bit_to_get_from_ghr.map(i => ghr((histPtr + (i+1).U).value))
170  }
171
172  def circular_shift_left(src: UInt, shamt: Int) = {
173    val srcLen = src.getWidth
174    val src_doubled = Cat(src, src)
175    val shifted = src_doubled(srcLen*2-1-shamt, srcLen-shamt)
176    shifted
177  }
178
179
180  def update(ghr: Vec[Bool], histPtr: CGHPtr, num: Int, taken: Bool): FoldedHistory = {
181    // do xors for several bitsets at specified bits
182    def bitsets_xor(len: Int, bitsets: Seq[Seq[Tuple2[Int, Bool]]]) = {
183      val res = Wire(Vec(len, Bool()))
184      // println(f"num bitsets: ${bitsets.length}")
185      // println(f"bitsets $bitsets")
186      val resArr = Array.fill(len)(List[Bool]())
187      for (bs <- bitsets) {
188        for ((n, b) <- bs) {
189          resArr(n) = b :: resArr(n)
190        }
191      }
192      // println(f"${resArr.mkString}")
193      // println(f"histLen: ${this.len}, foldedLen: $folded_len")
194      for (i <- 0 until len) {
195        // println(f"bit[$i], ${resArr(i).mkString}")
196        if (resArr(i).length > 2) {
197          println(f"[warning] update logic of foldest history has two or more levels of xor gates! " +
198            f"histlen:${this.len}, compLen:$compLen")
199        }
200        if (resArr(i).length == 0) {
201          println(f"[error] bits $i is not assigned in folded hist update logic! histlen:${this.len}, compLen:$compLen")
202        }
203        res(i) := resArr(i).foldLeft(false.B)(_^_)
204      }
205      res.asUInt
206    }
207    val oldest_bits = get_oldest_bits_from_ghr(ghr, histPtr)
208
209    // mask off bits that do not update
210    val oldest_bits_masked = oldest_bits.zipWithIndex.map{
211      case (ob, i) => ob && (i < num).B
212    }
213    // if a bit does not wrap around, it should not be xored when it exits
214    val oldest_bits_set = (0 until max_update_num).filter(oldest_bit_wrap_around).map(i => (oldest_bit_pos_in_folded(i), oldest_bits_masked(i)))
215
216    // println(f"old bits pos ${oldest_bits_set.map(_._1)}")
217
218    // only the last bit could be 1, as we have at most one taken branch at a time
219    val newest_bits_masked = VecInit((0 until max_update_num).map(i => taken && ((i+1) == num).B)).asUInt
220    // if a bit does not wrap around, newest bits should not be xored onto it either
221    val newest_bits_set = (0 until max_update_num).map(i => (compLen-1-i, newest_bits_masked(i)))
222
223    // println(f"new bits set ${newest_bits_set.map(_._1)}")
224    //
225    val original_bits_masked = VecInit(folded_hist.asBools.zipWithIndex.map{
226      case (fb, i) => fb && !(num >= (len-i)).B
227    })
228    val original_bits_set = (0 until compLen).map(i => (i, original_bits_masked(i)))
229
230
231    // histLen too short to wrap around
232    val new_folded_hist =
233      if (len <= compLen) {
234        ((folded_hist << num) | taken)(compLen-1,0)
235        // circular_shift_left(max_update_num)(Cat(Reverse(newest_bits_masked), folded_hist(compLen-max_update_num-1,0)), num)
236      } else {
237        // do xor then shift
238        val xored = bitsets_xor(compLen, Seq(original_bits_set, oldest_bits_set, newest_bits_set))
239        circular_shift_left(xored, num)
240      }
241    val fh = WireInit(this)
242    fh.folded_hist := new_folded_hist
243    fh
244  }
245}
246
247class TableAddr(val idxBits: Int, val banks: Int)(implicit p: Parameters) extends XSBundle{
248  def tagBits = VAddrBits - idxBits - instOffsetBits
249
250  val tag = UInt(tagBits.W)
251  val idx = UInt(idxBits.W)
252  val offset = UInt(instOffsetBits.W)
253
254  def fromUInt(x: UInt) = x.asTypeOf(UInt(VAddrBits.W)).asTypeOf(this)
255  def getTag(x: UInt) = fromUInt(x).tag
256  def getIdx(x: UInt) = fromUInt(x).idx
257  def getBank(x: UInt) = if (banks > 1) getIdx(x)(log2Up(banks) - 1, 0) else 0.U
258  def getBankIdx(x: UInt) = if (banks > 1) getIdx(x)(idxBits - 1, log2Up(banks)) else getIdx(x)
259}
260
261trait BasicPrediction extends HasXSParameter {
262  def cfiIndex: ValidUndirectioned[UInt]
263  def target(pc: UInt): UInt
264  def lastBrPosOH: Vec[Bool]
265  def brTaken: Bool
266  def shouldShiftVec: Vec[Bool]
267  def fallThruError: Bool
268  val oversize: Bool
269}
270class MinimalBranchPrediction(implicit p: Parameters) extends NewMicroBTBEntry with BasicPrediction {
271  val valid = Bool()
272  def cfiIndex = {
273    val res = Wire(ValidUndirectioned(UInt(log2Ceil(PredictWidth).W)))
274    res.valid := taken && valid
275    res.bits := cfiOffset | Fill(res.bits.getWidth, !valid)
276    res
277  }
278  def target(pc: UInt) = nextAddr
279  def lastBrPosOH: Vec[Bool] = VecInit(brNumOH.asBools())
280  def brTaken = takenOnBr
281  def shouldShiftVec: Vec[Bool] = VecInit((0 until numBr).map(i => lastBrPosOH.drop(i+1).reduce(_||_)))
282  def fallThruError: Bool = false.B
283
284  def fromMicroBTBEntry(valid: Bool, entry: NewMicroBTBEntry, pc: UInt) = {
285    this.valid := valid
286    this.nextAddr := Mux(valid, entry.nextAddr, pc + (FetchWidth*4).U)
287    this.cfiOffset := entry.cfiOffset | Fill(cfiOffset.getWidth, !valid)
288    this.taken := entry.taken && valid
289    this.takenOnBr := entry.takenOnBr && valid
290    this.brNumOH := Mux(valid, entry.brNumOH, 1.U(3.W))
291    this.oversize := entry.oversize && valid
292  }
293}
294@chiselName
295class FullBranchPrediction(implicit p: Parameters) extends XSBundle with HasBPUConst with BasicPrediction {
296  val br_taken_mask = Vec(numBr, Bool())
297
298  val slot_valids = Vec(totalSlot, Bool())
299
300  val targets = Vec(totalSlot, UInt(VAddrBits.W))
301  val jalr_target = UInt(VAddrBits.W) // special path for indirect predictors
302  val offsets = Vec(totalSlot, UInt(log2Ceil(PredictWidth).W))
303  val fallThroughAddr = UInt(VAddrBits.W)
304  val fallThroughErr = Bool()
305  val oversize = Bool()
306
307  val is_jal = Bool()
308  val is_jalr = Bool()
309  val is_call = Bool()
310  val is_ret = Bool()
311  val is_br_sharing = Bool()
312
313  // val call_is_rvc = Bool()
314  val hit = Bool()
315
316  def br_slot_valids = slot_valids.init
317  def tail_slot_valid = slot_valids.last
318
319  def br_valids = {
320    VecInit(br_slot_valids :+ (tail_slot_valid && is_br_sharing))
321  }
322
323  def taken_mask_on_slot = {
324    VecInit(
325      (br_slot_valids zip br_taken_mask.init).map{ case (t, v) => t && v } :+ (
326        tail_slot_valid && (
327          is_br_sharing && br_taken_mask.last || !is_br_sharing
328        )
329      )
330    )
331  }
332
333  def real_slot_taken_mask(): Vec[Bool] = {
334    VecInit(taken_mask_on_slot.map(_ && hit))
335  }
336
337  // len numBr
338  def real_br_taken_mask(): Vec[Bool] = {
339    VecInit(
340      taken_mask_on_slot.map(_ && hit).init :+
341      (br_taken_mask.last && tail_slot_valid && is_br_sharing && hit)
342    )
343  }
344
345  // the vec indicating if ghr should shift on each branch
346  def shouldShiftVec =
347    VecInit(br_valids.zipWithIndex.map{ case (v, i) =>
348      v && !real_br_taken_mask.take(i).reduceOption(_||_).getOrElse(false.B)})
349
350  def lastBrPosOH =
351    VecInit((!hit || !br_valids.reduce(_||_)) +: // not hit or no brs in entry
352      (0 until numBr).map(i =>
353        br_valids(i) &&
354        !real_br_taken_mask.take(i).reduceOption(_||_).getOrElse(false.B) && // no brs taken in front it
355        (real_br_taken_mask()(i) || !br_valids.drop(i+1).reduceOption(_||_).getOrElse(false.B)) && // no brs behind it
356        hit
357      )
358    )
359
360  def brTaken = (br_valids zip br_taken_mask).map{ case (a, b) => a && b }.reduce(_||_)
361
362  def target(pc: UInt): UInt = {
363    val targetVecOnHit = targets :+ fallThroughAddr
364    val targetOnNotHit = pc + (FetchWidth * 4).U
365    val taken_mask = taken_mask_on_slot
366    val selVecOHOnHit =
367      taken_mask.zipWithIndex.map{ case (t, i) => !taken_mask.take(i).fold(false.B)(_||_) && t} :+ !taken_mask.asUInt.orR
368    val targetOnHit = Mux1H(selVecOHOnHit, targetVecOnHit)
369    Mux(hit, targetOnHit, targetOnNotHit)
370  }
371
372  def fallThruError: Bool = hit && fallThroughErr
373
374  def hit_taken_on_jmp =
375    !real_slot_taken_mask().init.reduce(_||_) &&
376    real_slot_taken_mask().last && !is_br_sharing
377  def hit_taken_on_call = hit_taken_on_jmp && is_call
378  def hit_taken_on_ret  = hit_taken_on_jmp && is_ret
379  def hit_taken_on_jalr = hit_taken_on_jmp && is_jalr
380
381  def cfiIndex = {
382    val cfiIndex = Wire(ValidUndirectioned(UInt(log2Ceil(PredictWidth).W)))
383    cfiIndex.valid := real_slot_taken_mask().asUInt.orR
384    // when no takens, set cfiIndex to PredictWidth-1
385    cfiIndex.bits :=
386      ParallelPriorityMux(real_slot_taken_mask(), offsets) |
387      Fill(log2Ceil(PredictWidth), (!real_slot_taken_mask().asUInt.orR).asUInt)
388    cfiIndex
389  }
390
391  def taken = br_taken_mask.reduce(_||_) || slot_valids.last // || (is_jal || is_jalr)
392
393  def fromFtbEntry(entry: FTBEntry, pc: UInt, last_stage: Option[Tuple2[UInt, Bool]] = None) = {
394    slot_valids := entry.brSlots.map(_.valid) :+ entry.tailSlot.valid
395    targets := entry.getTargetVec(pc)
396    jalr_target := targets.last
397    offsets := entry.getOffsetVec
398    fallThroughAddr := entry.getFallThrough(pc)
399    oversize := entry.oversize
400    is_jal := entry.tailSlot.valid && entry.isJal
401    is_jalr := entry.tailSlot.valid && entry.isJalr
402    is_call := entry.tailSlot.valid && entry.isCall
403    is_ret := entry.tailSlot.valid && entry.isRet
404    is_br_sharing := entry.tailSlot.valid && entry.tailSlot.sharing
405
406    val startLower        = Cat(0.U(1.W),    pc(instOffsetBits+log2Ceil(PredictWidth), instOffsetBits))
407    val endLowerwithCarry = Cat(entry.carry, entry.pftAddr)
408    fallThroughErr := startLower >= endLowerwithCarry || (endLowerwithCarry - startLower) > (PredictWidth+1).U
409  }
410
411  def display(cond: Bool): Unit = {
412    XSDebug(cond, p"[taken_mask] ${Binary(br_taken_mask.asUInt)} [hit] $hit\n")
413  }
414}
415
416@chiselName
417class BranchPredictionBundle(implicit p: Parameters) extends XSBundle
418  with HasBPUConst with BPUUtils {
419  // def full_pred_info[T <: Data](x: T) = if (is_minimal) None else Some(x)
420  val pc = UInt(VAddrBits.W)
421
422  val valid = Bool()
423
424  val hasRedirect = Bool()
425  val ftq_idx = new FtqPtr
426  // val hit = Bool()
427  val is_minimal = Bool()
428  val minimal_pred = new MinimalBranchPrediction
429  val full_pred = new FullBranchPrediction
430
431
432  val folded_hist = new AllFoldedHistories(foldedGHistInfos)
433  val ghr = UInt(UbtbGHRLength.W)
434  val histPtr = new CGHPtr
435  val rasSp = UInt(log2Ceil(RasSize).W)
436  val rasTop = new RASEntry
437  // val specCnt = Vec(numBr, UInt(10.W))
438  // val meta = UInt(MaxMetaLength.W)
439
440  val ftb_entry = new FTBEntry()
441
442  def target(pc: UInt) = Mux(is_minimal, minimal_pred.target(pc),     full_pred.target(pc))
443  def cfiIndex         = Mux(is_minimal, minimal_pred.cfiIndex,       full_pred.cfiIndex)
444  def lastBrPosOH      = Mux(is_minimal, minimal_pred.lastBrPosOH,    full_pred.lastBrPosOH)
445  def brTaken          = Mux(is_minimal, minimal_pred.brTaken,        full_pred.brTaken)
446  def shouldShiftVec   = Mux(is_minimal, minimal_pred.shouldShiftVec, full_pred.shouldShiftVec)
447  def oversize         = Mux(is_minimal, minimal_pred.oversize,       full_pred.oversize)
448  def fallThruError    = Mux(is_minimal, minimal_pred.fallThruError,  full_pred.fallThruError)
449
450  def getTarget = target(pc)
451  def taken = cfiIndex.valid
452
453  def display(cond: Bool): Unit = {
454    XSDebug(cond, p"[pc] ${Hexadecimal(pc)}\n")
455    folded_hist.display(cond)
456    full_pred.display(cond)
457    ftb_entry.display(cond)
458  }
459}
460
461@chiselName
462class BranchPredictionResp(implicit p: Parameters) extends XSBundle with HasBPUConst {
463  // val valids = Vec(3, Bool())
464  val s1 = new BranchPredictionBundle
465  val s2 = new BranchPredictionBundle
466
467  def selectedResp ={
468    val res =
469      PriorityMux(Seq(
470        ((s2.valid && s2.hasRedirect) -> s2),
471        (s1.valid -> s1)
472      ))
473    // println("is minimal: ", res.is_minimal)
474    res
475  }
476  def selectedRespIdx =
477    PriorityMux(Seq(
478      ((s2.valid && s2.hasRedirect) -> BP_S2),
479      (s1.valid -> BP_S1)
480    ))
481  def lastStage = s2
482}
483
484class BpuToFtqBundle(implicit p: Parameters) extends BranchPredictionResp with HasBPUConst {
485  val meta = UInt(MaxMetaLength.W)
486}
487
488object BpuToFtqBundle {
489  def apply(resp: BranchPredictionResp)(implicit p: Parameters): BpuToFtqBundle = {
490    val e = Wire(new BpuToFtqBundle())
491    e.s1 := resp.s1
492    e.s2 := resp.s2
493
494    e.meta := DontCare
495    e
496  }
497}
498
499class BranchPredictionUpdate(implicit p: Parameters) extends BranchPredictionBundle with HasBPUConst {
500  val mispred_mask = Vec(numBr+1, Bool())
501  val false_hit = Bool()
502  val new_br_insert_pos = Vec(numBr, Bool())
503  val old_entry = Bool()
504  val meta = UInt(MaxMetaLength.W)
505  val full_target = UInt(VAddrBits.W)
506
507  def fromFtqRedirectSram(entry: Ftq_Redirect_SRAMEntry) = {
508    folded_hist := entry.folded_hist
509    ghr := entry.ghr
510    histPtr := entry.histPtr
511    rasSp := entry.rasSp
512    rasTop := entry.rasEntry
513    this
514  }
515
516  override def display(cond: Bool) = {
517    XSDebug(cond, p"-----------BranchPredictionUpdate-----------\n")
518    XSDebug(cond, p"[mispred_mask] ${Binary(mispred_mask.asUInt)} [false_hit] $false_hit\n")
519    XSDebug(cond, p"[new_br_insert_pos] ${Binary(new_br_insert_pos.asUInt)}\n")
520    super.display(cond)
521    XSDebug(cond, p"--------------------------------------------\n")
522  }
523}
524
525class BranchPredictionRedirect(implicit p: Parameters) extends Redirect with HasBPUConst {
526  // override def toPrintable: Printable = {
527  //   p"-----------BranchPredictionRedirect----------- " +
528  //     p"-----------cfiUpdate----------- " +
529  //     p"[pc] ${Hexadecimal(cfiUpdate.pc)} " +
530  //     p"[predTaken] ${cfiUpdate.predTaken}, [taken] ${cfiUpdate.taken}, [isMisPred] ${cfiUpdate.isMisPred} " +
531  //     p"[target] ${Hexadecimal(cfiUpdate.target)} " +
532  //     p"------------------------------- " +
533  //     p"[robPtr] f=${robIdx.flag} v=${robIdx.value} " +
534  //     p"[ftqPtr] f=${ftqIdx.flag} v=${ftqIdx.value} " +
535  //     p"[ftqOffset] ${ftqOffset} " +
536  //     p"[level] ${level}, [interrupt] ${interrupt} " +
537  //     p"[stFtqIdx] f=${stFtqIdx.flag} v=${stFtqIdx.value} " +
538  //     p"[stFtqOffset] ${stFtqOffset} " +
539  //     p"\n"
540
541  // }
542
543  def display(cond: Bool): Unit = {
544    XSDebug(cond, p"-----------BranchPredictionRedirect----------- \n")
545    XSDebug(cond, p"-----------cfiUpdate----------- \n")
546    XSDebug(cond, p"[pc] ${Hexadecimal(cfiUpdate.pc)}\n")
547    // XSDebug(cond, p"[hist] ${Binary(cfiUpdate.hist.predHist)}\n")
548    XSDebug(cond, p"[br_hit] ${cfiUpdate.br_hit} [isMisPred] ${cfiUpdate.isMisPred}\n")
549    XSDebug(cond, p"[pred_taken] ${cfiUpdate.predTaken} [taken] ${cfiUpdate.taken} [isMisPred] ${cfiUpdate.isMisPred}\n")
550    XSDebug(cond, p"[target] ${Hexadecimal(cfiUpdate.target)} \n")
551    XSDebug(cond, p"[shift] ${cfiUpdate.shift}\n")
552    XSDebug(cond, p"------------------------------- \n")
553    XSDebug(cond, p"[robPtr] f=${robIdx.flag} v=${robIdx.value}\n")
554    XSDebug(cond, p"[ftqPtr] f=${ftqIdx.flag} v=${ftqIdx.value} \n")
555    XSDebug(cond, p"[ftqOffset] ${ftqOffset} \n")
556    XSDebug(cond, p"[stFtqIdx] f=${stFtqIdx.flag} v=${stFtqIdx.value}\n")
557    XSDebug(cond, p"[stFtqOffset] ${stFtqOffset}\n")
558    XSDebug(cond, p"---------------------------------------------- \n")
559  }
560}
561