xref: /XiangShan/src/main/scala/xiangshan/frontend/FrontendBundle.scala (revision c7fabd05bd7e19d09ab8dcb2c824ab5423020660)
109c6f1ddSLingrui98/***************************************************************************************
209c6f1ddSLingrui98* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences
309c6f1ddSLingrui98* Copyright (c) 2020-2021 Peng Cheng Laboratory
409c6f1ddSLingrui98*
509c6f1ddSLingrui98* XiangShan is licensed under Mulan PSL v2.
609c6f1ddSLingrui98* You can use this software according to the terms and conditions of the Mulan PSL v2.
709c6f1ddSLingrui98* You may obtain a copy of Mulan PSL v2 at:
809c6f1ddSLingrui98*          http://license.coscl.org.cn/MulanPSL2
909c6f1ddSLingrui98*
1009c6f1ddSLingrui98* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
1109c6f1ddSLingrui98* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
1209c6f1ddSLingrui98* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
1309c6f1ddSLingrui98*
1409c6f1ddSLingrui98* See the Mulan PSL v2 for more details.
1509c6f1ddSLingrui98***************************************************************************************/
1609c6f1ddSLingrui98package xiangshan.frontend
1709c6f1ddSLingrui98
1809c6f1ddSLingrui98import chipsalliance.rocketchip.config.Parameters
1909c6f1ddSLingrui98import chisel3._
2009c6f1ddSLingrui98import chisel3.util._
21bf358e08SLingrui98import chisel3.experimental.chiselName
2209c6f1ddSLingrui98import xiangshan._
23b37e4b45SLingrui98import xiangshan.frontend.icache.HasICacheParameters
2409c6f1ddSLingrui98import utils._
25c2ad24ebSLingrui98import scala.math._
2609c6f1ddSLingrui98
27bf358e08SLingrui98@chiselName
28b37e4b45SLingrui98class FetchRequestBundle(implicit p: Parameters) extends XSBundle with HasICacheParameters {
2909c6f1ddSLingrui98  val startAddr       = UInt(VAddrBits.W)
3034a88126SJinYue  val nextlineStart   = UInt(VAddrBits.W)
3109c6f1ddSLingrui98  val ftqIdx          = new FtqPtr
3209c6f1ddSLingrui98  val ftqOffset       = ValidUndirectioned(UInt(log2Ceil(PredictWidth).W))
336ce52296SJinYue  val nextStartAddr   = UInt(VAddrBits.W)
3409c6f1ddSLingrui98
356ce52296SJinYue  def crossCacheline = startAddr(blockOffBits - 1) === 1.U
366ce52296SJinYue
3709c6f1ddSLingrui98  def fromFtqPcBundle(b: Ftq_RF_Components) = {
3809c6f1ddSLingrui98    this.startAddr := b.startAddr
39b37e4b45SLingrui98    this.nextlineStart := b.nextLineAddr
40b37e4b45SLingrui98    when (b.fallThruError) {
41b37e4b45SLingrui98      val nextBlockHigherTemp = Mux(startAddr(log2Ceil(PredictWidth)+instOffsetBits), b.startAddr, b.nextLineAddr)
42b37e4b45SLingrui98      val nextBlockHigher = nextBlockHigherTemp(VAddrBits-1, log2Ceil(PredictWidth)+instOffsetBits+1)
43b37e4b45SLingrui98      this.nextStartAddr :=
44b37e4b45SLingrui98        Cat(nextBlockHigher,
45b37e4b45SLingrui98          startAddr(log2Ceil(PredictWidth)+instOffsetBits) ^ 1.U(1.W),
46b37e4b45SLingrui98          startAddr(log2Ceil(PredictWidth)+instOffsetBits-1, instOffsetBits),
47b37e4b45SLingrui98          0.U(instOffsetBits.W)
48b37e4b45SLingrui98        )
4909c6f1ddSLingrui98    }
5009c6f1ddSLingrui98    this
5109c6f1ddSLingrui98  }
5209c6f1ddSLingrui98  override def toPrintable: Printable = {
53b37e4b45SLingrui98    p"[start] ${Hexadecimal(startAddr)} [next] ${Hexadecimal(nextlineStart)}" +
54b37e4b45SLingrui98      p"[tgt] ${Hexadecimal(nextStartAddr)} [ftqIdx] $ftqIdx [jmp] v:${ftqOffset.valid}" +
5509c6f1ddSLingrui98      p" offset: ${ftqOffset.bits}\n"
5609c6f1ddSLingrui98  }
5709c6f1ddSLingrui98}
5809c6f1ddSLingrui98
5909c6f1ddSLingrui98class PredecodeWritebackBundle(implicit p:Parameters) extends XSBundle {
6009c6f1ddSLingrui98  val pc           = Vec(PredictWidth, UInt(VAddrBits.W))
6109c6f1ddSLingrui98  val pd           = Vec(PredictWidth, new PreDecodeInfo) // TODO: redefine Predecode
6209c6f1ddSLingrui98  val ftqIdx       = new FtqPtr
6309c6f1ddSLingrui98  val ftqOffset    = UInt(log2Ceil(PredictWidth).W)
6409c6f1ddSLingrui98  val misOffset    = ValidUndirectioned(UInt(log2Ceil(PredictWidth).W))
6509c6f1ddSLingrui98  val cfiOffset    = ValidUndirectioned(UInt(log2Ceil(PredictWidth).W))
6609c6f1ddSLingrui98  val target       = UInt(VAddrBits.W)
6709c6f1ddSLingrui98  val jalTarget    = UInt(VAddrBits.W)
6809c6f1ddSLingrui98  val instrRange   = Vec(PredictWidth, Bool())
6909c6f1ddSLingrui98}
7009c6f1ddSLingrui98
717052722fSJay// Ftq send req to Prefetch
727052722fSJayclass PrefetchRequest(implicit p:Parameters) extends XSBundle {
737052722fSJay  val target          = UInt(VAddrBits.W)
747052722fSJay}
7509c6f1ddSLingrui98
767052722fSJayclass FtqPrefechBundle(implicit p:Parameters) extends XSBundle {
777052722fSJay  val req = DecoupledIO(new PrefetchRequest)
7809c6f1ddSLingrui98}
7909c6f1ddSLingrui98
8009c6f1ddSLingrui98class FetchToIBuffer(implicit p: Parameters) extends XSBundle {
8109c6f1ddSLingrui98  val instrs    = Vec(PredictWidth, UInt(32.W))
8209c6f1ddSLingrui98  val valid     = UInt(PredictWidth.W)
832a3050c2SJay  val enqEnable = UInt(PredictWidth.W)
8409c6f1ddSLingrui98  val pd        = Vec(PredictWidth, new PreDecodeInfo)
8509c6f1ddSLingrui98  val pc        = Vec(PredictWidth, UInt(VAddrBits.W))
8609c6f1ddSLingrui98  val foldpc    = Vec(PredictWidth, UInt(MemPredPCWidth.W))
8709c6f1ddSLingrui98  val ftqPtr       = new FtqPtr
8809c6f1ddSLingrui98  val ftqOffset    = Vec(PredictWidth, ValidUndirectioned(UInt(log2Ceil(PredictWidth).W)))
8909c6f1ddSLingrui98  val ipf          = Vec(PredictWidth, Bool())
9009c6f1ddSLingrui98  val acf          = Vec(PredictWidth, Bool())
9109c6f1ddSLingrui98  val crossPageIPFFix = Vec(PredictWidth, Bool())
9272951335SLi Qianruo  val triggered    = Vec(PredictWidth, new TriggerCf)
9309c6f1ddSLingrui98}
9409c6f1ddSLingrui98
95c2ad24ebSLingrui98// class BitWiseUInt(val width: Int, val init: UInt) extends Module {
96c2ad24ebSLingrui98//   val io = IO(new Bundle {
97c2ad24ebSLingrui98//     val set
98c2ad24ebSLingrui98//   })
99c2ad24ebSLingrui98// }
10009c6f1ddSLingrui98// Move from BPU
101c2ad24ebSLingrui98abstract class GlobalHistory(implicit p: Parameters) extends XSBundle with HasBPUConst {
102c2ad24ebSLingrui98  def update(br_valids: Vec[Bool], real_taken_mask: Vec[Bool]): GlobalHistory
103c2ad24ebSLingrui98}
104c2ad24ebSLingrui98
105c2ad24ebSLingrui98class ShiftingGlobalHistory(implicit p: Parameters) extends GlobalHistory {
10609c6f1ddSLingrui98  val predHist = UInt(HistoryLength.W)
10709c6f1ddSLingrui98
108c2ad24ebSLingrui98  def update(shift: UInt, taken: Bool, hist: UInt = this.predHist): ShiftingGlobalHistory = {
109c2ad24ebSLingrui98    val g = Wire(new ShiftingGlobalHistory)
11009c6f1ddSLingrui98    g.predHist := (hist << shift) | taken
11109c6f1ddSLingrui98    g
11209c6f1ddSLingrui98  }
11309c6f1ddSLingrui98
114c2ad24ebSLingrui98  def update(br_valids: Vec[Bool], real_taken_mask: Vec[Bool]): ShiftingGlobalHistory = {
115eeb5ff92SLingrui98    require(br_valids.length == numBr)
116eeb5ff92SLingrui98    require(real_taken_mask.length == numBr)
117eeb5ff92SLingrui98    val last_valid_idx = PriorityMux(
118eeb5ff92SLingrui98      br_valids.reverse :+ true.B,
119eeb5ff92SLingrui98      (numBr to 0 by -1).map(_.U(log2Ceil(numBr+1).W))
120eeb5ff92SLingrui98    )
121eeb5ff92SLingrui98    val first_taken_idx = PriorityEncoder(false.B +: real_taken_mask)
122eeb5ff92SLingrui98    val smaller = Mux(last_valid_idx < first_taken_idx,
123eeb5ff92SLingrui98      last_valid_idx,
124eeb5ff92SLingrui98      first_taken_idx
125eeb5ff92SLingrui98    )
126eeb5ff92SLingrui98    val shift = smaller
127eeb5ff92SLingrui98    val taken = real_taken_mask.reduce(_||_)
128eeb5ff92SLingrui98    update(shift, taken, this.predHist)
129eeb5ff92SLingrui98  }
130eeb5ff92SLingrui98
131c2ad24ebSLingrui98  // static read
132c2ad24ebSLingrui98  def read(n: Int): Bool = predHist.asBools()(n)
133c2ad24ebSLingrui98
134c2ad24ebSLingrui98  final def === (that: ShiftingGlobalHistory): Bool = {
13509c6f1ddSLingrui98    predHist === that.predHist
13609c6f1ddSLingrui98  }
13709c6f1ddSLingrui98
138c2ad24ebSLingrui98  final def =/= (that: ShiftingGlobalHistory): Bool = !(this === that)
139c2ad24ebSLingrui98}
14009c6f1ddSLingrui98
141c2ad24ebSLingrui98// circular global history pointer
142c2ad24ebSLingrui98class CGHPtr(implicit p: Parameters) extends CircularQueuePtr[CGHPtr](
143c2ad24ebSLingrui98  p => p(XSCoreParamsKey).HistoryLength
144c2ad24ebSLingrui98){
145c2ad24ebSLingrui98  override def cloneType = (new CGHPtr).asInstanceOf[this.type]
146c2ad24ebSLingrui98}
147*c7fabd05SSteve Gou
148*c7fabd05SSteve Gouobject CGHPtr {
149*c7fabd05SSteve Gou  def apply(f: Bool, v: UInt)(implicit p: Parameters): CGHPtr = {
150*c7fabd05SSteve Gou    val ptr = Wire(new CGHPtr)
151*c7fabd05SSteve Gou    ptr.flag := f
152*c7fabd05SSteve Gou    ptr.value := v
153*c7fabd05SSteve Gou    ptr
154*c7fabd05SSteve Gou  }
155*c7fabd05SSteve Gou  def inverse(ptr: CGHPtr)(implicit p: Parameters): CGHPtr = {
156*c7fabd05SSteve Gou    apply(!ptr.flag, ptr.value)
157*c7fabd05SSteve Gou  }
158*c7fabd05SSteve Gou}
159*c7fabd05SSteve Gou
160c2ad24ebSLingrui98class CircularGlobalHistory(implicit p: Parameters) extends GlobalHistory {
161c2ad24ebSLingrui98  val buffer = Vec(HistoryLength, Bool())
162c2ad24ebSLingrui98  type HistPtr = UInt
163c2ad24ebSLingrui98  def update(br_valids: Vec[Bool], real_taken_mask: Vec[Bool]): CircularGlobalHistory = {
164c2ad24ebSLingrui98    this
165c2ad24ebSLingrui98  }
166c2ad24ebSLingrui98}
167c2ad24ebSLingrui98
168dd6c0695SLingrui98class FoldedHistory(val len: Int, val compLen: Int, val max_update_num: Int)(implicit p: Parameters)
169c2ad24ebSLingrui98  extends XSBundle with HasBPUConst {
170dd6c0695SLingrui98  require(compLen >= 1)
171c2ad24ebSLingrui98  require(len > 0)
172c2ad24ebSLingrui98  // require(folded_len <= len)
173dd6c0695SLingrui98  require(compLen >= max_update_num)
174dd6c0695SLingrui98  val folded_hist = UInt(compLen.W)
175dd6c0695SLingrui98
17667402d75SLingrui98  def need_oldest_bits = len > compLen
177dd6c0695SLingrui98  def info = (len, compLen)
178c2ad24ebSLingrui98  def oldest_bit_to_get_from_ghr = (0 until max_update_num).map(len - _ - 1)
179c2ad24ebSLingrui98  def oldest_bit_pos_in_folded = oldest_bit_to_get_from_ghr map (_ % compLen)
180c2ad24ebSLingrui98  def oldest_bit_wrap_around = oldest_bit_to_get_from_ghr map (_ / compLen > 0)
181c2ad24ebSLingrui98  def oldest_bit_start = oldest_bit_pos_in_folded.head
182c2ad24ebSLingrui98
183dd6c0695SLingrui98  def get_oldest_bits_from_ghr(ghr: Vec[Bool], histPtr: CGHPtr) = {
184c2ad24ebSLingrui98    // TODO: wrap inc for histPtr value
185dd6c0695SLingrui98    oldest_bit_to_get_from_ghr.map(i => ghr((histPtr + (i+1).U).value))
186c2ad24ebSLingrui98  }
187c2ad24ebSLingrui98
188ab890bfeSLingrui98  def circular_shift_left(src: UInt, shamt: Int) = {
189c2ad24ebSLingrui98    val srcLen = src.getWidth
190c2ad24ebSLingrui98    val src_doubled = Cat(src, src)
191ab890bfeSLingrui98    val shifted = src_doubled(srcLen*2-1-shamt, srcLen-shamt)
192ab890bfeSLingrui98    shifted
193c2ad24ebSLingrui98  }
194c2ad24ebSLingrui98
19567402d75SLingrui98  // slow path, read bits from ghr
196ab890bfeSLingrui98  def update(ghr: Vec[Bool], histPtr: CGHPtr, num: Int, taken: Bool): FoldedHistory = {
19767402d75SLingrui98    val oldest_bits = VecInit(get_oldest_bits_from_ghr(ghr, histPtr))
19867402d75SLingrui98    update(oldest_bits, num, taken)
19967402d75SLingrui98  }
20067402d75SLingrui98
20167402d75SLingrui98
20267402d75SLingrui98  // fast path, use pre-read oldest bits
20367402d75SLingrui98  def update(ob: Vec[Bool], num: Int, taken: Bool): FoldedHistory = {
204c2ad24ebSLingrui98    // do xors for several bitsets at specified bits
205c2ad24ebSLingrui98    def bitsets_xor(len: Int, bitsets: Seq[Seq[Tuple2[Int, Bool]]]) = {
206c2ad24ebSLingrui98      val res = Wire(Vec(len, Bool()))
207c2ad24ebSLingrui98      // println(f"num bitsets: ${bitsets.length}")
208c2ad24ebSLingrui98      // println(f"bitsets $bitsets")
209c2ad24ebSLingrui98      val resArr = Array.fill(len)(List[Bool]())
210c2ad24ebSLingrui98      for (bs <- bitsets) {
211c2ad24ebSLingrui98        for ((n, b) <- bs) {
212c2ad24ebSLingrui98          resArr(n) = b :: resArr(n)
213c2ad24ebSLingrui98        }
214c2ad24ebSLingrui98      }
215c2ad24ebSLingrui98      // println(f"${resArr.mkString}")
216c2ad24ebSLingrui98      // println(f"histLen: ${this.len}, foldedLen: $folded_len")
217c2ad24ebSLingrui98      for (i <- 0 until len) {
218c2ad24ebSLingrui98        // println(f"bit[$i], ${resArr(i).mkString}")
219c2ad24ebSLingrui98        if (resArr(i).length > 2) {
220c2ad24ebSLingrui98          println(f"[warning] update logic of foldest history has two or more levels of xor gates! " +
22186d9c530SLingrui98            f"histlen:${this.len}, compLen:$compLen, at bit $i")
222c2ad24ebSLingrui98        }
223c2ad24ebSLingrui98        if (resArr(i).length == 0) {
224dd6c0695SLingrui98          println(f"[error] bits $i is not assigned in folded hist update logic! histlen:${this.len}, compLen:$compLen")
225c2ad24ebSLingrui98        }
226c2ad24ebSLingrui98        res(i) := resArr(i).foldLeft(false.B)(_^_)
227c2ad24ebSLingrui98      }
228c2ad24ebSLingrui98      res.asUInt
229c2ad24ebSLingrui98    }
230c2ad24ebSLingrui98
23167402d75SLingrui98    val new_folded_hist = if (need_oldest_bits) {
23267402d75SLingrui98      val oldest_bits = ob
23367402d75SLingrui98      require(oldest_bits.length == max_update_num)
234c2ad24ebSLingrui98      // mask off bits that do not update
235c2ad24ebSLingrui98      val oldest_bits_masked = oldest_bits.zipWithIndex.map{
236ab890bfeSLingrui98        case (ob, i) => ob && (i < num).B
237c2ad24ebSLingrui98      }
238c2ad24ebSLingrui98      // if a bit does not wrap around, it should not be xored when it exits
239c2ad24ebSLingrui98      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)))
240c2ad24ebSLingrui98
241c2ad24ebSLingrui98      // println(f"old bits pos ${oldest_bits_set.map(_._1)}")
242c2ad24ebSLingrui98
243c2ad24ebSLingrui98      // only the last bit could be 1, as we have at most one taken branch at a time
244ab890bfeSLingrui98      val newest_bits_masked = VecInit((0 until max_update_num).map(i => taken && ((i+1) == num).B)).asUInt
245c2ad24ebSLingrui98      // if a bit does not wrap around, newest bits should not be xored onto it either
246e992912cSLingrui98      val newest_bits_set = (0 until max_update_num).map(i => (compLen-1-i, newest_bits_masked(i)))
247c2ad24ebSLingrui98
248c2ad24ebSLingrui98      // println(f"new bits set ${newest_bits_set.map(_._1)}")
249c2ad24ebSLingrui98      //
250c2ad24ebSLingrui98      val original_bits_masked = VecInit(folded_hist.asBools.zipWithIndex.map{
251ab890bfeSLingrui98        case (fb, i) => fb && !(num >= (len-i)).B
252c2ad24ebSLingrui98      })
253c2ad24ebSLingrui98      val original_bits_set = (0 until compLen).map(i => (i, original_bits_masked(i)))
254c2ad24ebSLingrui98
255c2ad24ebSLingrui98      // do xor then shift
256c2ad24ebSLingrui98      val xored = bitsets_xor(compLen, Seq(original_bits_set, oldest_bits_set, newest_bits_set))
257ab890bfeSLingrui98      circular_shift_left(xored, num)
25867402d75SLingrui98    } else {
25967402d75SLingrui98      // histLen too short to wrap around
26067402d75SLingrui98      ((folded_hist << num) | taken)(compLen-1,0)
261c2ad24ebSLingrui98    }
26267402d75SLingrui98
263c2ad24ebSLingrui98    val fh = WireInit(this)
264c2ad24ebSLingrui98    fh.folded_hist := new_folded_hist
265c2ad24ebSLingrui98    fh
266c2ad24ebSLingrui98  }
26709c6f1ddSLingrui98}
26809c6f1ddSLingrui98
26967402d75SLingrui98class AheadFoldedHistoryOldestBits(val len: Int, val max_update_num: Int)(implicit p: Parameters) extends XSBundle {
27067402d75SLingrui98  val bits = Vec(max_update_num*2, Bool())
27167402d75SLingrui98  // def info = (len, compLen)
27267402d75SLingrui98  def getRealOb(brNumOH: UInt): Vec[Bool] = {
27367402d75SLingrui98    val ob = Wire(Vec(max_update_num, Bool()))
27467402d75SLingrui98    for (i <- 0 until max_update_num) {
27567402d75SLingrui98      ob(i) := Mux1H(brNumOH, bits.drop(i).take(numBr+1))
27667402d75SLingrui98    }
27767402d75SLingrui98    ob
27867402d75SLingrui98  }
27967402d75SLingrui98}
28067402d75SLingrui98
28167402d75SLingrui98class AllAheadFoldedHistoryOldestBits(val gen: Seq[Tuple2[Int, Int]])(implicit p: Parameters) extends XSBundle with HasBPUConst {
28267402d75SLingrui98  val afhob = MixedVec(gen.filter(t => t._1 > t._2).map{_._1}
28367402d75SLingrui98    .toSet.toList.map(l => new AheadFoldedHistoryOldestBits(l, numBr))) // remove duplicates
28467402d75SLingrui98  require(gen.toSet.toList.equals(gen))
28567402d75SLingrui98  def getObWithInfo(info: Tuple2[Int, Int]) = {
28667402d75SLingrui98    val selected = afhob.filter(_.len == info._1)
28767402d75SLingrui98    require(selected.length == 1)
28867402d75SLingrui98    selected(0)
28967402d75SLingrui98  }
29067402d75SLingrui98  def read(ghv: Vec[Bool], ptr: CGHPtr) = {
29167402d75SLingrui98    val hisLens = afhob.map(_.len)
29267402d75SLingrui98    val bitsToRead = hisLens.flatMap(l => (0 until numBr*2).map(i => l-i-1)).toSet // remove duplicates
29367402d75SLingrui98    val bitsWithInfo = bitsToRead.map(pos => (pos, ghv((ptr+(pos+1).U).value)))
29467402d75SLingrui98    for (ob <- afhob) {
29567402d75SLingrui98      for (i <- 0 until numBr*2) {
29667402d75SLingrui98        val pos = ob.len - i - 1
29767402d75SLingrui98        val bit_found = bitsWithInfo.filter(_._1 == pos).toList
29867402d75SLingrui98        require(bit_found.length == 1)
29967402d75SLingrui98        ob.bits(i) := bit_found(0)._2
30067402d75SLingrui98      }
30167402d75SLingrui98    }
30267402d75SLingrui98  }
30367402d75SLingrui98}
30467402d75SLingrui98
30567402d75SLingrui98class AllFoldedHistories(val gen: Seq[Tuple2[Int, Int]])(implicit p: Parameters) extends XSBundle with HasBPUConst {
30667402d75SLingrui98  val hist = MixedVec(gen.map{case (l, cl) => new FoldedHistory(l, cl, numBr)})
30767402d75SLingrui98  // println(gen.mkString)
30867402d75SLingrui98  require(gen.toSet.toList.equals(gen))
30967402d75SLingrui98  def getHistWithInfo(info: Tuple2[Int, Int]) = {
31067402d75SLingrui98    val selected = hist.filter(_.info.equals(info))
31167402d75SLingrui98    require(selected.length == 1)
31267402d75SLingrui98    selected(0)
31367402d75SLingrui98  }
31467402d75SLingrui98  def autoConnectFrom(that: AllFoldedHistories) = {
31567402d75SLingrui98    require(this.hist.length <= that.hist.length)
31667402d75SLingrui98    for (h <- this.hist) {
31767402d75SLingrui98      h := that.getHistWithInfo(h.info)
31867402d75SLingrui98    }
31967402d75SLingrui98  }
32067402d75SLingrui98  def update(ghv: Vec[Bool], ptr: CGHPtr, shift: Int, taken: Bool): AllFoldedHistories = {
32167402d75SLingrui98    val res = WireInit(this)
32267402d75SLingrui98    for (i <- 0 until this.hist.length) {
32367402d75SLingrui98      res.hist(i) := this.hist(i).update(ghv, ptr, shift, taken)
32467402d75SLingrui98    }
32567402d75SLingrui98    res
32667402d75SLingrui98  }
32767402d75SLingrui98  def update(afhob: AllAheadFoldedHistoryOldestBits, lastBrNumOH: UInt, shift: Int, taken: Bool): AllFoldedHistories = {
32867402d75SLingrui98    val res = WireInit(this)
32967402d75SLingrui98    for (i <- 0 until this.hist.length) {
33067402d75SLingrui98      val fh = this.hist(i)
33167402d75SLingrui98      if (fh.need_oldest_bits) {
33267402d75SLingrui98        val info = fh.info
33367402d75SLingrui98        val selectedAfhob = afhob.getObWithInfo(info)
33467402d75SLingrui98        val ob = selectedAfhob.getRealOb(lastBrNumOH)
33567402d75SLingrui98        res.hist(i) := this.hist(i).update(ob, shift, taken)
33667402d75SLingrui98      } else {
33767402d75SLingrui98        val dumb = Wire(Vec(numBr, Bool())) // not needed
33867402d75SLingrui98        dumb := DontCare
33967402d75SLingrui98        res.hist(i) := this.hist(i).update(dumb, shift, taken)
34067402d75SLingrui98      }
34167402d75SLingrui98    }
34267402d75SLingrui98    res
34367402d75SLingrui98  }
34467402d75SLingrui98
34567402d75SLingrui98  def display(cond: Bool) = {
34667402d75SLingrui98    for (h <- hist) {
34767402d75SLingrui98      XSDebug(cond, p"hist len ${h.len}, folded len ${h.compLen}, value ${Binary(h.folded_hist)}\n")
34867402d75SLingrui98    }
34967402d75SLingrui98  }
35067402d75SLingrui98}
35167402d75SLingrui98
35209c6f1ddSLingrui98class TableAddr(val idxBits: Int, val banks: Int)(implicit p: Parameters) extends XSBundle{
35309c6f1ddSLingrui98  def tagBits = VAddrBits - idxBits - instOffsetBits
35409c6f1ddSLingrui98
35509c6f1ddSLingrui98  val tag = UInt(tagBits.W)
35609c6f1ddSLingrui98  val idx = UInt(idxBits.W)
35709c6f1ddSLingrui98  val offset = UInt(instOffsetBits.W)
35809c6f1ddSLingrui98
35909c6f1ddSLingrui98  def fromUInt(x: UInt) = x.asTypeOf(UInt(VAddrBits.W)).asTypeOf(this)
36009c6f1ddSLingrui98  def getTag(x: UInt) = fromUInt(x).tag
36109c6f1ddSLingrui98  def getIdx(x: UInt) = fromUInt(x).idx
36209c6f1ddSLingrui98  def getBank(x: UInt) = if (banks > 1) getIdx(x)(log2Up(banks) - 1, 0) else 0.U
36309c6f1ddSLingrui98  def getBankIdx(x: UInt) = if (banks > 1) getIdx(x)(idxBits - 1, log2Up(banks)) else getIdx(x)
36409c6f1ddSLingrui98}
365eeb5ff92SLingrui98
366b37e4b45SLingrui98trait BasicPrediction extends HasXSParameter {
367b37e4b45SLingrui98  def cfiIndex: ValidUndirectioned[UInt]
368b37e4b45SLingrui98  def target(pc: UInt): UInt
369b37e4b45SLingrui98  def lastBrPosOH: Vec[Bool]
370b37e4b45SLingrui98  def brTaken: Bool
371b37e4b45SLingrui98  def shouldShiftVec: Vec[Bool]
372b37e4b45SLingrui98  def fallThruError: Bool
373b37e4b45SLingrui98}
374b37e4b45SLingrui98class MinimalBranchPrediction(implicit p: Parameters) extends NewMicroBTBEntry with BasicPrediction {
375b37e4b45SLingrui98  val valid = Bool()
376b37e4b45SLingrui98  def cfiIndex = {
377b37e4b45SLingrui98    val res = Wire(ValidUndirectioned(UInt(log2Ceil(PredictWidth).W)))
378b37e4b45SLingrui98    res.valid := taken && valid
379b37e4b45SLingrui98    res.bits := cfiOffset | Fill(res.bits.getWidth, !valid)
380b37e4b45SLingrui98    res
381b37e4b45SLingrui98  }
382b37e4b45SLingrui98  def target(pc: UInt) = nextAddr
383b37e4b45SLingrui98  def lastBrPosOH: Vec[Bool] = VecInit(brNumOH.asBools())
384b37e4b45SLingrui98  def brTaken = takenOnBr
385b37e4b45SLingrui98  def shouldShiftVec: Vec[Bool] = VecInit((0 until numBr).map(i => lastBrPosOH.drop(i+1).reduce(_||_)))
386a60a2901SLingrui98  def fallThruError: Bool = false.B // we do this check on the following stages
387b37e4b45SLingrui98
388b37e4b45SLingrui98  def fromMicroBTBEntry(valid: Bool, entry: NewMicroBTBEntry, pc: UInt) = {
389b37e4b45SLingrui98    this.valid := valid
390b37e4b45SLingrui98    this.nextAddr := Mux(valid, entry.nextAddr, pc + (FetchWidth*4).U)
391b37e4b45SLingrui98    this.cfiOffset := entry.cfiOffset | Fill(cfiOffset.getWidth, !valid)
392b37e4b45SLingrui98    this.taken := entry.taken && valid
393b37e4b45SLingrui98    this.takenOnBr := entry.takenOnBr && valid
394b37e4b45SLingrui98    this.brNumOH := Mux(valid, entry.brNumOH, 1.U(3.W))
395b37e4b45SLingrui98  }
396b37e4b45SLingrui98}
397eeb5ff92SLingrui98@chiselName
398b37e4b45SLingrui98class FullBranchPrediction(implicit p: Parameters) extends XSBundle with HasBPUConst with BasicPrediction {
399eeb5ff92SLingrui98  val br_taken_mask = Vec(numBr, Bool())
40009c6f1ddSLingrui98
401eeb5ff92SLingrui98  val slot_valids = Vec(totalSlot, Bool())
40209c6f1ddSLingrui98
403eeb5ff92SLingrui98  val targets = Vec(totalSlot, UInt(VAddrBits.W))
404b30c10d6SLingrui98  val jalr_target = UInt(VAddrBits.W) // special path for indirect predictors
405a229ab6cSLingrui98  val offsets = Vec(totalSlot, UInt(log2Ceil(PredictWidth).W))
406a229ab6cSLingrui98  val fallThroughAddr = UInt(VAddrBits.W)
407b37e4b45SLingrui98  val fallThroughErr = Bool()
40809c6f1ddSLingrui98
40909c6f1ddSLingrui98  val is_jal = Bool()
41009c6f1ddSLingrui98  val is_jalr = Bool()
41109c6f1ddSLingrui98  val is_call = Bool()
41209c6f1ddSLingrui98  val is_ret = Bool()
413f4ebc4b2SLingrui98  val last_may_be_rvi_call = Bool()
414eeb5ff92SLingrui98  val is_br_sharing = Bool()
41509c6f1ddSLingrui98
41609c6f1ddSLingrui98  // val call_is_rvc = Bool()
41709c6f1ddSLingrui98  val hit = Bool()
41809c6f1ddSLingrui98
419eeb5ff92SLingrui98  def br_slot_valids = slot_valids.init
420eeb5ff92SLingrui98  def tail_slot_valid = slot_valids.last
421eeb5ff92SLingrui98
422eeb5ff92SLingrui98  def br_valids = {
423b37e4b45SLingrui98    VecInit(br_slot_valids :+ (tail_slot_valid && is_br_sharing))
424eeb5ff92SLingrui98  }
425eeb5ff92SLingrui98
426eeb5ff92SLingrui98  def taken_mask_on_slot = {
427eeb5ff92SLingrui98    VecInit(
428eeb5ff92SLingrui98      (br_slot_valids zip br_taken_mask.init).map{ case (t, v) => t && v } :+ (
429b30c10d6SLingrui98        tail_slot_valid && (
430b30c10d6SLingrui98          is_br_sharing && br_taken_mask.last || !is_br_sharing
431b30c10d6SLingrui98        )
432eeb5ff92SLingrui98      )
433eeb5ff92SLingrui98    )
434eeb5ff92SLingrui98  }
435eeb5ff92SLingrui98
436b37e4b45SLingrui98  def real_slot_taken_mask(): Vec[Bool] = {
437b37e4b45SLingrui98    VecInit(taken_mask_on_slot.map(_ && hit))
438b37e4b45SLingrui98  }
439b37e4b45SLingrui98
440b37e4b45SLingrui98  // len numBr
441b37e4b45SLingrui98  def real_br_taken_mask(): Vec[Bool] = {
442b37e4b45SLingrui98    VecInit(
443b37e4b45SLingrui98      taken_mask_on_slot.map(_ && hit).init :+
444b37e4b45SLingrui98      (br_taken_mask.last && tail_slot_valid && is_br_sharing && hit)
445b37e4b45SLingrui98    )
446b37e4b45SLingrui98  }
447b37e4b45SLingrui98
448b37e4b45SLingrui98  // the vec indicating if ghr should shift on each branch
449b37e4b45SLingrui98  def shouldShiftVec =
450b37e4b45SLingrui98    VecInit(br_valids.zipWithIndex.map{ case (v, i) =>
451b37e4b45SLingrui98      v && !real_br_taken_mask.take(i).reduceOption(_||_).getOrElse(false.B)})
452b37e4b45SLingrui98
453b37e4b45SLingrui98  def lastBrPosOH =
454b37e4b45SLingrui98    VecInit((!hit || !br_valids.reduce(_||_)) +: // not hit or no brs in entry
455b37e4b45SLingrui98      (0 until numBr).map(i =>
456b37e4b45SLingrui98        br_valids(i) &&
457b37e4b45SLingrui98        !real_br_taken_mask.take(i).reduceOption(_||_).getOrElse(false.B) && // no brs taken in front it
458b37e4b45SLingrui98        (real_br_taken_mask()(i) || !br_valids.drop(i+1).reduceOption(_||_).getOrElse(false.B)) && // no brs behind it
459b37e4b45SLingrui98        hit
460b37e4b45SLingrui98      )
461b37e4b45SLingrui98    )
462b37e4b45SLingrui98
46386d9c530SLingrui98  def brTaken = (br_valids zip br_taken_mask).map{ case (a, b) => a && b && hit}.reduce(_||_)
464b37e4b45SLingrui98
465b37e4b45SLingrui98  def target(pc: UInt): UInt = {
466d3854a00SLingrui98    val targetVec = targets :+ fallThroughAddr :+ (pc + (FetchWidth * 4).U)
467d3854a00SLingrui98    val tm = taken_mask_on_slot
468d3854a00SLingrui98    val selVecOH =
469d3854a00SLingrui98      tm.zipWithIndex.map{ case (t, i) => !tm.take(i).fold(false.B)(_||_) && t && hit} :+
470d3854a00SLingrui98      (!tm.asUInt.orR && hit) :+ !hit
471d3854a00SLingrui98    Mux1H(selVecOH, targetVec)
472b37e4b45SLingrui98  }
473b37e4b45SLingrui98
474b37e4b45SLingrui98  def fallThruError: Bool = hit && fallThroughErr
475b37e4b45SLingrui98
476b37e4b45SLingrui98  def hit_taken_on_jmp =
477b37e4b45SLingrui98    !real_slot_taken_mask().init.reduce(_||_) &&
478b37e4b45SLingrui98    real_slot_taken_mask().last && !is_br_sharing
479b37e4b45SLingrui98  def hit_taken_on_call = hit_taken_on_jmp && is_call
480b37e4b45SLingrui98  def hit_taken_on_ret  = hit_taken_on_jmp && is_ret
481b37e4b45SLingrui98  def hit_taken_on_jalr = hit_taken_on_jmp && is_jalr
482b37e4b45SLingrui98
483b37e4b45SLingrui98  def cfiIndex = {
484b37e4b45SLingrui98    val cfiIndex = Wire(ValidUndirectioned(UInt(log2Ceil(PredictWidth).W)))
485b37e4b45SLingrui98    cfiIndex.valid := real_slot_taken_mask().asUInt.orR
486b37e4b45SLingrui98    // when no takens, set cfiIndex to PredictWidth-1
487b37e4b45SLingrui98    cfiIndex.bits :=
488b37e4b45SLingrui98      ParallelPriorityMux(real_slot_taken_mask(), offsets) |
489b37e4b45SLingrui98      Fill(log2Ceil(PredictWidth), (!real_slot_taken_mask().asUInt.orR).asUInt)
490b37e4b45SLingrui98    cfiIndex
491b37e4b45SLingrui98  }
492b37e4b45SLingrui98
493eeb5ff92SLingrui98  def taken = br_taken_mask.reduce(_||_) || slot_valids.last // || (is_jal || is_jalr)
49409c6f1ddSLingrui98
495b30c10d6SLingrui98  def fromFtbEntry(entry: FTBEntry, pc: UInt, last_stage: Option[Tuple2[UInt, Bool]] = None) = {
496eeb5ff92SLingrui98    slot_valids := entry.brSlots.map(_.valid) :+ entry.tailSlot.valid
497eeb5ff92SLingrui98    targets := entry.getTargetVec(pc)
498b30c10d6SLingrui98    jalr_target := targets.last
499a229ab6cSLingrui98    offsets := entry.getOffsetVec
500eeb5ff92SLingrui98    is_jal := entry.tailSlot.valid && entry.isJal
501eeb5ff92SLingrui98    is_jalr := entry.tailSlot.valid && entry.isJalr
502eeb5ff92SLingrui98    is_call := entry.tailSlot.valid && entry.isCall
503eeb5ff92SLingrui98    is_ret := entry.tailSlot.valid && entry.isRet
504f4ebc4b2SLingrui98    last_may_be_rvi_call := entry.last_may_be_rvi_call
505eeb5ff92SLingrui98    is_br_sharing := entry.tailSlot.valid && entry.tailSlot.sharing
506a229ab6cSLingrui98
507a60a2901SLingrui98    val startLower        = Cat(0.U(1.W),    pc(instOffsetBits+log2Ceil(PredictWidth)-1, instOffsetBits))
508b37e4b45SLingrui98    val endLowerwithCarry = Cat(entry.carry, entry.pftAddr)
509a60a2901SLingrui98    fallThroughErr := startLower >= endLowerwithCarry
51086d9c530SLingrui98    fallThroughAddr := Mux(fallThroughErr, pc + (FetchWidth * 4).U, entry.getFallThrough(pc))
511a229ab6cSLingrui98  }
51209c6f1ddSLingrui98
51309c6f1ddSLingrui98  def display(cond: Bool): Unit = {
514eeb5ff92SLingrui98    XSDebug(cond, p"[taken_mask] ${Binary(br_taken_mask.asUInt)} [hit] $hit\n")
51509c6f1ddSLingrui98  }
51609c6f1ddSLingrui98}
51709c6f1ddSLingrui98
518bf358e08SLingrui98@chiselName
519b37e4b45SLingrui98class BranchPredictionBundle(implicit p: Parameters) extends XSBundle
520b37e4b45SLingrui98  with HasBPUConst with BPUUtils {
521b37e4b45SLingrui98  // def full_pred_info[T <: Data](x: T) = if (is_minimal) None else Some(x)
52209c6f1ddSLingrui98  val pc = UInt(VAddrBits.W)
52309c6f1ddSLingrui98
52409c6f1ddSLingrui98  val valid = Bool()
52509c6f1ddSLingrui98
52609c6f1ddSLingrui98  val hasRedirect = Bool()
52709c6f1ddSLingrui98  val ftq_idx = new FtqPtr
52809c6f1ddSLingrui98  // val hit = Bool()
529b37e4b45SLingrui98  val is_minimal = Bool()
530b37e4b45SLingrui98  val minimal_pred = new MinimalBranchPrediction
531b37e4b45SLingrui98  val full_pred = new FullBranchPrediction
532b37e4b45SLingrui98
53309c6f1ddSLingrui98
534dd6c0695SLingrui98  val folded_hist = new AllFoldedHistories(foldedGHistInfos)
53567402d75SLingrui98  val afhob = new AllAheadFoldedHistoryOldestBits(foldedGHistInfos)
53667402d75SLingrui98  val lastBrNumOH = UInt((numBr+1).W)
537c2ad24ebSLingrui98  val histPtr = new CGHPtr
53809c6f1ddSLingrui98  val rasSp = UInt(log2Ceil(RasSize).W)
53909c6f1ddSLingrui98  val rasTop = new RASEntry
540b37e4b45SLingrui98  // val specCnt = Vec(numBr, UInt(10.W))
54109c6f1ddSLingrui98  // val meta = UInt(MaxMetaLength.W)
54209c6f1ddSLingrui98
543b37e4b45SLingrui98  val ftb_entry = new FTBEntry()
54409c6f1ddSLingrui98
545b37e4b45SLingrui98  def target(pc: UInt) = Mux(is_minimal, minimal_pred.target(pc),     full_pred.target(pc))
546b37e4b45SLingrui98  def cfiIndex         = Mux(is_minimal, minimal_pred.cfiIndex,       full_pred.cfiIndex)
547b37e4b45SLingrui98  def lastBrPosOH      = Mux(is_minimal, minimal_pred.lastBrPosOH,    full_pred.lastBrPosOH)
548b37e4b45SLingrui98  def brTaken          = Mux(is_minimal, minimal_pred.brTaken,        full_pred.brTaken)
549b37e4b45SLingrui98  def shouldShiftVec   = Mux(is_minimal, minimal_pred.shouldShiftVec, full_pred.shouldShiftVec)
550b37e4b45SLingrui98  def fallThruError    = Mux(is_minimal, minimal_pred.fallThruError,  full_pred.fallThruError)
551eeb5ff92SLingrui98
552b37e4b45SLingrui98  def getTarget = target(pc)
553b37e4b45SLingrui98  def taken = cfiIndex.valid
55409c6f1ddSLingrui98
55509c6f1ddSLingrui98  def display(cond: Bool): Unit = {
55609c6f1ddSLingrui98    XSDebug(cond, p"[pc] ${Hexadecimal(pc)}\n")
557dd6c0695SLingrui98    folded_hist.display(cond)
558b37e4b45SLingrui98    full_pred.display(cond)
55909c6f1ddSLingrui98    ftb_entry.display(cond)
56009c6f1ddSLingrui98  }
56109c6f1ddSLingrui98}
56209c6f1ddSLingrui98
563bf358e08SLingrui98@chiselName
56409c6f1ddSLingrui98class BranchPredictionResp(implicit p: Parameters) extends XSBundle with HasBPUConst {
56509c6f1ddSLingrui98  // val valids = Vec(3, Bool())
566b37e4b45SLingrui98  val s1 = new BranchPredictionBundle
567b37e4b45SLingrui98  val s2 = new BranchPredictionBundle
568cb4f77ceSLingrui98  val s3 = new BranchPredictionBundle
56909c6f1ddSLingrui98
570b37e4b45SLingrui98  def selectedResp ={
571b37e4b45SLingrui98    val res =
57209c6f1ddSLingrui98      PriorityMux(Seq(
573cb4f77ceSLingrui98        ((s3.valid && s3.hasRedirect) -> s3),
57409c6f1ddSLingrui98        ((s2.valid && s2.hasRedirect) -> s2),
57509c6f1ddSLingrui98        (s1.valid -> s1)
57609c6f1ddSLingrui98      ))
577b37e4b45SLingrui98    // println("is minimal: ", res.is_minimal)
578b37e4b45SLingrui98    res
579b37e4b45SLingrui98  }
58009c6f1ddSLingrui98  def selectedRespIdx =
58109c6f1ddSLingrui98    PriorityMux(Seq(
582cb4f77ceSLingrui98      ((s3.valid && s3.hasRedirect) -> BP_S3),
58309c6f1ddSLingrui98      ((s2.valid && s2.hasRedirect) -> BP_S2),
58409c6f1ddSLingrui98      (s1.valid -> BP_S1)
58509c6f1ddSLingrui98    ))
586cb4f77ceSLingrui98  def lastStage = s3
58709c6f1ddSLingrui98}
58809c6f1ddSLingrui98
58909c6f1ddSLingrui98class BpuToFtqBundle(implicit p: Parameters) extends BranchPredictionResp with HasBPUConst {
59009c6f1ddSLingrui98  val meta = UInt(MaxMetaLength.W)
59109c6f1ddSLingrui98}
59209c6f1ddSLingrui98
59309c6f1ddSLingrui98object BpuToFtqBundle {
59409c6f1ddSLingrui98  def apply(resp: BranchPredictionResp)(implicit p: Parameters): BpuToFtqBundle = {
59509c6f1ddSLingrui98    val e = Wire(new BpuToFtqBundle())
59609c6f1ddSLingrui98    e.s1 := resp.s1
59709c6f1ddSLingrui98    e.s2 := resp.s2
598cb4f77ceSLingrui98    e.s3 := resp.s3
59909c6f1ddSLingrui98
60009c6f1ddSLingrui98    e.meta := DontCare
60109c6f1ddSLingrui98    e
60209c6f1ddSLingrui98  }
60309c6f1ddSLingrui98}
60409c6f1ddSLingrui98
60509c6f1ddSLingrui98class BranchPredictionUpdate(implicit p: Parameters) extends BranchPredictionBundle with HasBPUConst {
60609c6f1ddSLingrui98  val mispred_mask = Vec(numBr+1, Bool())
607edc18578SLingrui98  val pred_hit = Bool()
60809c6f1ddSLingrui98  val false_hit = Bool()
60909c6f1ddSLingrui98  val new_br_insert_pos = Vec(numBr, Bool())
61009c6f1ddSLingrui98  val old_entry = Bool()
61109c6f1ddSLingrui98  val meta = UInt(MaxMetaLength.W)
612abdbe4b7SLingrui98  val full_target = UInt(VAddrBits.W)
613edc18578SLingrui98  val from_stage = UInt(2.W)
61486d9c530SLingrui98  val ghist = UInt(HistoryLength.W)
61509c6f1ddSLingrui98
61609c6f1ddSLingrui98  def fromFtqRedirectSram(entry: Ftq_Redirect_SRAMEntry) = {
617dd6c0695SLingrui98    folded_hist := entry.folded_hist
61867402d75SLingrui98    afhob := entry.afhob
61967402d75SLingrui98    lastBrNumOH := entry.lastBrNumOH
620c2ad24ebSLingrui98    histPtr := entry.histPtr
62109c6f1ddSLingrui98    rasSp := entry.rasSp
62209c6f1ddSLingrui98    rasTop := entry.rasEntry
62309c6f1ddSLingrui98    this
62409c6f1ddSLingrui98  }
62509c6f1ddSLingrui98
626c2ad24ebSLingrui98  override def display(cond: Bool) = {
62709c6f1ddSLingrui98    XSDebug(cond, p"-----------BranchPredictionUpdate-----------\n")
62809c6f1ddSLingrui98    XSDebug(cond, p"[mispred_mask] ${Binary(mispred_mask.asUInt)} [false_hit] $false_hit\n")
62909c6f1ddSLingrui98    XSDebug(cond, p"[new_br_insert_pos] ${Binary(new_br_insert_pos.asUInt)}\n")
63009c6f1ddSLingrui98    super.display(cond)
63109c6f1ddSLingrui98    XSDebug(cond, p"--------------------------------------------\n")
63209c6f1ddSLingrui98  }
63309c6f1ddSLingrui98}
63409c6f1ddSLingrui98
63509c6f1ddSLingrui98class BranchPredictionRedirect(implicit p: Parameters) extends Redirect with HasBPUConst {
63609c6f1ddSLingrui98  // override def toPrintable: Printable = {
63709c6f1ddSLingrui98  //   p"-----------BranchPredictionRedirect----------- " +
63809c6f1ddSLingrui98  //     p"-----------cfiUpdate----------- " +
63909c6f1ddSLingrui98  //     p"[pc] ${Hexadecimal(cfiUpdate.pc)} " +
64009c6f1ddSLingrui98  //     p"[predTaken] ${cfiUpdate.predTaken}, [taken] ${cfiUpdate.taken}, [isMisPred] ${cfiUpdate.isMisPred} " +
64109c6f1ddSLingrui98  //     p"[target] ${Hexadecimal(cfiUpdate.target)} " +
64209c6f1ddSLingrui98  //     p"------------------------------- " +
6439aca92b9SYinan Xu  //     p"[robPtr] f=${robIdx.flag} v=${robIdx.value} " +
64409c6f1ddSLingrui98  //     p"[ftqPtr] f=${ftqIdx.flag} v=${ftqIdx.value} " +
64509c6f1ddSLingrui98  //     p"[ftqOffset] ${ftqOffset} " +
64609c6f1ddSLingrui98  //     p"[level] ${level}, [interrupt] ${interrupt} " +
64709c6f1ddSLingrui98  //     p"[stFtqIdx] f=${stFtqIdx.flag} v=${stFtqIdx.value} " +
64809c6f1ddSLingrui98  //     p"[stFtqOffset] ${stFtqOffset} " +
64909c6f1ddSLingrui98  //     p"\n"
65009c6f1ddSLingrui98
65109c6f1ddSLingrui98  // }
65209c6f1ddSLingrui98
65309c6f1ddSLingrui98  def display(cond: Bool): Unit = {
65409c6f1ddSLingrui98    XSDebug(cond, p"-----------BranchPredictionRedirect----------- \n")
65509c6f1ddSLingrui98    XSDebug(cond, p"-----------cfiUpdate----------- \n")
65609c6f1ddSLingrui98    XSDebug(cond, p"[pc] ${Hexadecimal(cfiUpdate.pc)}\n")
657c2ad24ebSLingrui98    // XSDebug(cond, p"[hist] ${Binary(cfiUpdate.hist.predHist)}\n")
65809c6f1ddSLingrui98    XSDebug(cond, p"[br_hit] ${cfiUpdate.br_hit} [isMisPred] ${cfiUpdate.isMisPred}\n")
65909c6f1ddSLingrui98    XSDebug(cond, p"[pred_taken] ${cfiUpdate.predTaken} [taken] ${cfiUpdate.taken} [isMisPred] ${cfiUpdate.isMisPred}\n")
66009c6f1ddSLingrui98    XSDebug(cond, p"[target] ${Hexadecimal(cfiUpdate.target)} \n")
66109c6f1ddSLingrui98    XSDebug(cond, p"[shift] ${cfiUpdate.shift}\n")
66209c6f1ddSLingrui98    XSDebug(cond, p"------------------------------- \n")
6639aca92b9SYinan Xu    XSDebug(cond, p"[robPtr] f=${robIdx.flag} v=${robIdx.value}\n")
66409c6f1ddSLingrui98    XSDebug(cond, p"[ftqPtr] f=${ftqIdx.flag} v=${ftqIdx.value} \n")
66509c6f1ddSLingrui98    XSDebug(cond, p"[ftqOffset] ${ftqOffset} \n")
66609c6f1ddSLingrui98    XSDebug(cond, p"[stFtqIdx] f=${stFtqIdx.flag} v=${stFtqIdx.value}\n")
66709c6f1ddSLingrui98    XSDebug(cond, p"[stFtqOffset] ${stFtqOffset}\n")
66809c6f1ddSLingrui98    XSDebug(cond, p"---------------------------------------------- \n")
66909c6f1ddSLingrui98  }
67009c6f1ddSLingrui98}
671