xref: /XiangShan/src/main/scala/xiangshan/frontend/BPU.scala (revision a273862e37f1d43bee748f2a6353320a2f52f6f4)
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.experimental.chiselName
22import chisel3.util._
23import xiangshan._
24import utils._
25
26import scala.math.min
27
28trait HasBPUConst extends HasXSParameter with HasIFUConst {
29  val MaxMetaLength = 1024 // TODO: Reduce meta length
30  val MaxBasicBlockSize = 32
31  val LHistoryLength = 32
32  val numBr = 2
33  val useBPD = true
34  val useLHist = true
35  val shareTailSlot = true
36  val numBrSlot = if (shareTailSlot) numBr-1 else numBr
37  val totalSlot = numBrSlot + 1
38
39  def BP_STAGES = (0 until 3).map(_.U(2.W))
40  def BP_S1 = BP_STAGES(0)
41  def BP_S2 = BP_STAGES(1)
42  def BP_S3 = BP_STAGES(2)
43  val numBpStages = BP_STAGES.length
44
45  val debug = true
46  val resetVector = 0x10000000L//TODO: set reset vec
47  // TODO: Replace log2Up by log2Ceil
48}
49
50trait HasBPUParameter extends HasXSParameter with HasBPUConst {
51  val BPUDebug = true && !env.FPGAPlatform && env.EnablePerfDebug
52  val EnableCFICommitLog = true
53  val EnbaleCFIPredLog = true
54  val EnableBPUTimeRecord = (EnableCFICommitLog || EnbaleCFIPredLog) && !env.FPGAPlatform
55  val EnableCommit = false
56}
57
58class BPUCtrl(implicit p: Parameters) extends XSBundle {
59  val ubtb_enable = Bool()
60  val btb_enable  = Bool()
61  val bim_enable  = Bool()
62  val tage_enable = Bool()
63  val sc_enable   = Bool()
64  val ras_enable  = Bool()
65  val loop_enable = Bool()
66}
67
68trait BPUUtils extends HasXSParameter {
69  // circular shifting
70  def circularShiftLeft(source: UInt, len: Int, shamt: UInt): UInt = {
71    val res = Wire(UInt(len.W))
72    val higher = source << shamt
73    val lower = source >> (len.U - shamt)
74    res := higher | lower
75    res
76  }
77
78  def circularShiftRight(source: UInt, len: Int, shamt: UInt): UInt = {
79    val res = Wire(UInt(len.W))
80    val higher = source << (len.U - shamt)
81    val lower = source >> shamt
82    res := higher | lower
83    res
84  }
85
86  // To be verified
87  def satUpdate(old: UInt, len: Int, taken: Bool): UInt = {
88    val oldSatTaken = old === ((1 << len)-1).U
89    val oldSatNotTaken = old === 0.U
90    Mux(oldSatTaken && taken, ((1 << len)-1).U,
91      Mux(oldSatNotTaken && !taken, 0.U,
92        Mux(taken, old + 1.U, old - 1.U)))
93  }
94
95  def signedSatUpdate(old: SInt, len: Int, taken: Bool): SInt = {
96    val oldSatTaken = old === ((1 << (len-1))-1).S
97    val oldSatNotTaken = old === (-(1 << (len-1))).S
98    Mux(oldSatTaken && taken, ((1 << (len-1))-1).S,
99      Mux(oldSatNotTaken && !taken, (-(1 << (len-1))).S,
100        Mux(taken, old + 1.S, old - 1.S)))
101  }
102
103  def getFallThroughAddr(start: UInt, carry: Bool, pft: UInt) = {
104    val higher = start.head(VAddrBits-log2Ceil(PredictWidth)-instOffsetBits-1)
105    Cat(Mux(carry, higher+1.U, higher), pft, 0.U(instOffsetBits.W))
106  }
107
108  def foldTag(tag: UInt, l: Int): UInt = {
109    val nChunks = (tag.getWidth + l - 1) / l
110    val chunks = (0 until nChunks).map { i =>
111      tag(min((i+1)*l, tag.getWidth)-1, i*l)
112    }
113    ParallelXOR(chunks)
114  }
115}
116
117// class BranchPredictionUpdate(implicit p: Parameters) extends XSBundle with HasBPUConst {
118//   val pc = UInt(VAddrBits.W)
119//   val br_offset = Vec(num_br, UInt(log2Up(MaxBasicBlockSize).W))
120//   val br_mask = Vec(MaxBasicBlockSize, Bool())
121//
122//   val jmp_valid = Bool()
123//   val jmp_type = UInt(3.W)
124//
125//   val is_NextMask = Vec(FetchWidth*2, Bool())
126//
127//   val cfi_idx = Valid(UInt(log2Ceil(MaxBasicBlockSize).W))
128//   val cfi_mispredict = Bool()
129//   val cfi_is_br = Bool()
130//   val cfi_is_jal = Bool()
131//   val cfi_is_jalr = Bool()
132//
133//   val ghist = new GlobalHistory()
134//
135//   val target = UInt(VAddrBits.W)
136//
137//   val meta = UInt(MaxMetaLength.W)
138//   val spec_meta = UInt(MaxMetaLength.W)
139//
140//   def taken = cfi_idx.valid
141// }
142
143class BasePredictorInput (implicit p: Parameters) extends XSBundle with HasBPUConst {
144  def nInputs = 1
145
146  val s0_pc = UInt(VAddrBits.W)
147
148  val ghist = UInt(HistoryLength.W)
149  val phist = UInt(PathHistoryLength.W)
150
151  val resp_in = Vec(nInputs, new BranchPredictionResp)
152  // val toFtq_fire = Bool()
153
154  // val s0_all_ready = Bool()
155}
156
157class BasePredictorOutput (implicit p: Parameters) extends XSBundle with HasBPUConst {
158  val s3_meta = UInt(MaxMetaLength.W) // This is use by composer
159  val resp = new BranchPredictionResp
160
161  // These store in meta, extract in composer
162  // val rasSp = UInt(log2Ceil(RasSize).W)
163  // val rasTop = new RASEntry
164  // val specCnt = Vec(PredictWidth, UInt(10.W))
165}
166
167class BasePredictorIO (implicit p: Parameters) extends XSBundle with HasBPUConst {
168  val in  = Flipped(DecoupledIO(new BasePredictorInput)) // TODO: Remove DecoupledIO
169  // val out = DecoupledIO(new BasePredictorOutput)
170  val out = Output(new BasePredictorOutput)
171  // val flush_out = Valid(UInt(VAddrBits.W))
172
173  // val ctrl = Input(new BPUCtrl())
174
175  val s0_fire = Input(Bool())
176  val s1_fire = Input(Bool())
177  val s2_fire = Input(Bool())
178  val s3_fire = Input(Bool())
179
180  val s1_ready = Output(Bool())
181  val s2_ready = Output(Bool())
182  val s3_ready = Output(Bool())
183
184  val update = Flipped(Valid(new BranchPredictionUpdate))
185  val redirect = Flipped(Valid(new BranchPredictionRedirect))
186}
187
188abstract class BasePredictor(implicit p: Parameters) extends XSModule with HasBPUConst with BPUUtils {
189  val meta_size = 0
190  val spec_meta_size = 0
191
192  val io = IO(new BasePredictorIO())
193
194  io.out.resp := io.in.bits.resp_in(0)
195
196  io.out.s3_meta := 0.U
197
198  io.in.ready := !io.redirect.valid
199
200  io.s1_ready := true.B
201  io.s2_ready := true.B
202  io.s3_ready := true.B
203
204  val s0_pc       = WireInit(io.in.bits.s0_pc) // fetchIdx(io.f0_pc)
205  val s1_pc       = RegEnable(s0_pc, resetVector.U, io.s0_fire)
206  val s2_pc       = RegEnable(s1_pc, io.s1_fire)
207  val s3_pc       = RegEnable(s2_pc, io.s2_fire)
208}
209
210class FakePredictor(implicit p: Parameters) extends BasePredictor {
211  io.in.ready                 := true.B
212  io.out.s3_meta              := 0.U
213  io.out.resp := io.in.bits.resp_in(0)
214}
215
216class BpuToFtqIO(implicit p: Parameters) extends XSBundle {
217  val resp = DecoupledIO(new BpuToFtqBundle())
218}
219
220class PredictorIO(implicit p: Parameters) extends XSBundle {
221  val bpu_to_ftq = new BpuToFtqIO()
222  val ftq_to_bpu = Flipped(new FtqToBpuIO())
223}
224
225class FakeBPU(implicit p: Parameters) extends XSModule with HasBPUConst {
226  val io = IO(new PredictorIO)
227
228  val toFtq_fire = io.bpu_to_ftq.resp.valid && io.bpu_to_ftq.resp.ready
229
230  val s0_pc = RegInit(resetVector.U)
231
232  when(toFtq_fire) {
233    s0_pc := s0_pc + (FetchWidth*4).U
234  }
235
236  when (io.ftq_to_bpu.redirect.valid) {
237    s0_pc := io.ftq_to_bpu.redirect.bits.cfiUpdate.target
238  }
239
240  io.bpu_to_ftq.resp.valid := !reset.asBool() && !io.ftq_to_bpu.redirect.valid
241
242  io.bpu_to_ftq.resp.bits := 0.U.asTypeOf(new BranchPredictionBundle)
243  io.bpu_to_ftq.resp.bits.s1.pc := s0_pc
244  io.bpu_to_ftq.resp.bits.s1.ftb_entry.pftAddr := s0_pc + (FetchWidth*4).U
245}
246
247@chiselName
248class Predictor(implicit p: Parameters) extends XSModule with HasBPUConst {
249  val io = IO(new PredictorIO)
250
251  val predictors = Module(if (useBPD) new Composer else new FakePredictor)
252
253  val s0_fire, s1_fire, s2_fire, s3_fire = Wire(Bool())
254  val s1_valid, s2_valid, s3_valid = RegInit(false.B)
255  val s1_ready, s2_ready, s3_ready = Wire(Bool())
256  val s1_components_ready, s2_components_ready, s3_components_ready = Wire(Bool())
257
258  val s0_pc = WireInit(resetVector.U)
259  val s0_pc_reg = RegNext(s0_pc, init=resetVector.U)
260  val s1_pc = RegEnable(s0_pc, s0_fire)
261  val s2_pc = RegEnable(s1_pc, s1_fire)
262  val s3_pc = RegEnable(s2_pc, s2_fire)
263
264  val s0_ghist = WireInit(0.U.asTypeOf(new GlobalHistory))
265  val s0_ghist_reg = RegNext(s0_ghist, init=0.U.asTypeOf(new GlobalHistory))
266  val s1_ghist = RegEnable(s0_ghist, 0.U.asTypeOf(new GlobalHistory), s0_fire)
267  val s2_ghist = RegEnable(s1_ghist, 0.U.asTypeOf(new GlobalHistory), s1_fire)
268  val s3_ghist = RegEnable(s2_ghist, 0.U.asTypeOf(new GlobalHistory), s2_fire)
269
270  val s0_phist = WireInit(0.U(PathHistoryLength.W))
271  val s0_phist_reg = RegNext(s0_phist, init=0.U(PathHistoryLength.W))
272  val s1_phist = RegEnable(s0_phist, 0.U, s0_fire)
273  val s2_phist = RegEnable(s1_phist, 0.U, s1_fire)
274  val s3_phist = RegEnable(s2_phist, 0.U, s2_fire)
275
276  val resp = predictors.io.out.resp
277
278
279  val toFtq_fire = io.bpu_to_ftq.resp.valid && io.bpu_to_ftq.resp.ready
280
281  when(RegNext(reset.asBool) && !reset.asBool) {
282    s0_ghist := 0.U.asTypeOf(new GlobalHistory)
283    s0_phist := 0.U
284    s0_pc := resetVector.U
285  }
286
287  // when(toFtq_fire) {
288    // final_gh := s3_gh.update(io.bpu_to_ftq.resp.bits.ftb_entry.brValids.reduce(_||_) && !io.bpu_to_ftq.resp.bits.preds.taken,
289    //   io.bpu_to_ftq.resp.bits.preds.taken)
290  // }
291
292  val s1_flush, s2_flush, s3_flush = Wire(Bool())
293  val s2_redirect, s3_redirect = Wire(Bool())
294
295  // val s1_bp_resp = predictors.io.out.resp.s1
296  // val s2_bp_resp = predictors.io.out.resp.s2
297  // val s3_bp_resp = predictors.io.out.resp.s3
298
299  // predictors.io := DontCare
300  predictors.io.in.valid := s0_fire
301  predictors.io.in.bits.s0_pc := s0_pc
302  predictors.io.in.bits.ghist := s0_ghist.predHist
303  predictors.io.in.bits.phist := s0_phist
304  predictors.io.in.bits.resp_in(0) := (0.U).asTypeOf(new BranchPredictionResp)
305  // predictors.io.in.bits.resp_in(0).s1.pc := s0_pc
306  // predictors.io.in.bits.toFtq_fire := toFtq_fire
307
308  // predictors.io.out.ready := io.bpu_to_ftq.resp.ready
309
310  // Pipeline logic
311  s2_redirect := false.B
312  s3_redirect := false.B
313
314  s3_flush := io.ftq_to_bpu.redirect.valid
315  s2_flush := s3_flush || s3_redirect
316  s1_flush := s2_flush || s2_redirect
317
318  s1_components_ready := predictors.io.s1_ready
319  s1_ready := s1_fire || !s1_valid
320  s0_fire := !reset.asBool && s1_components_ready && s1_ready
321  predictors.io.s0_fire := s0_fire
322
323  s2_components_ready := predictors.io.s2_ready
324  s2_ready := s2_fire || !s2_valid
325  s1_fire := s1_valid && s2_components_ready && s2_ready && io.bpu_to_ftq.resp.ready
326
327  when(s0_fire)         { s1_valid := true.B  }
328    .elsewhen(s1_flush) { s1_valid := false.B }
329    .elsewhen(s1_fire)  { s1_valid := false.B }
330
331  predictors.io.s1_fire := s1_fire
332
333  s3_components_ready := predictors.io.s3_ready
334  s3_ready := s3_fire || !s3_valid
335  s2_fire := s2_valid && s3_components_ready && s3_ready
336
337  when(s2_flush)                    { s2_valid := false.B }
338    .elsewhen(s1_fire && !s1_flush) { s2_valid := true.B  }
339    .elsewhen(s2_fire)              { s2_valid := false.B }
340
341  predictors.io.s2_fire := s2_fire
342
343  // s3_fire := s3_valid && io.bpu_to_ftq.resp.ready
344  s3_fire := s3_valid
345
346  when(s3_flush)                    { s3_valid := false.B }
347    .elsewhen(s2_fire && !s2_flush) { s3_valid := true.B  }
348    .elsewhen(s3_fire)              { s3_valid := false.B }
349
350  predictors.io.s3_fire := s3_fire
351
352  io.bpu_to_ftq.resp.valid :=
353    s1_valid && s2_components_ready && s2_ready ||
354    s2_fire && s2_redirect ||
355    s3_fire && s3_redirect
356  io.bpu_to_ftq.resp.bits  := BpuToFtqBundle(predictors.io.out.resp)
357  io.bpu_to_ftq.resp.bits.meta  := predictors.io.out.s3_meta
358  io.bpu_to_ftq.resp.bits.s3.ghist  := s3_ghist
359  io.bpu_to_ftq.resp.bits.s3.phist  := s3_phist
360
361  s0_pc := s0_pc_reg
362  s0_ghist := s0_ghist_reg
363  s0_phist := s0_phist_reg
364
365  // History manage
366  // s1
367  val s1_predicted_ghist = s1_ghist.update(resp.s1.preds.br_valids, resp.s1.real_br_taken_mask())
368
369  XSDebug(p"[hit] ${resp.s1.preds.hit} [s1_real_br_taken_mask] ${Binary(resp.s1.real_br_taken_mask.asUInt)}\n")
370  XSDebug(p"s1_predicted_ghist=${Binary(s1_predicted_ghist.predHist)}\n")
371
372  when(s1_valid) {
373    s0_pc := resp.s1.target
374    s0_ghist := s1_predicted_ghist
375    s0_phist := (s1_phist << 1) | s1_pc(instOffsetBits)
376  }
377
378  // s2
379  val s2_predicted_ghist = s2_ghist.update(resp.s2.preds.br_valids, resp.s2.real_br_taken_mask())
380
381  val s2_correct_s1_ghist = s1_ghist =/= s2_predicted_ghist
382  val s2_correct_s0_ghist_reg = s0_ghist_reg =/= s2_predicted_ghist
383
384  val previous_s1_pred_taken = RegEnable(resp.s1.real_slot_taken_mask.asUInt.orR, init=false.B, enable=s1_fire)
385  val s2_pred_taken = resp.s2.real_slot_taken_mask.asUInt.orR
386
387  when(s2_fire) {
388    when((s1_valid && (s1_pc =/= resp.s2.target || s2_correct_s1_ghist)) ||
389      !s1_valid && (s0_pc_reg =/= resp.s2.target || s2_correct_s0_ghist_reg) ||
390      previous_s1_pred_taken =/= s2_pred_taken) {
391      s0_ghist := s2_predicted_ghist
392      s2_redirect := true.B
393      s0_pc := resp.s2.target
394      s0_phist := (s2_phist << 1) | s2_pc(instOffsetBits)
395      XSDebug(p"s1_valid=$s1_valid, s1_pc=${Hexadecimal(s1_pc)}, s2_resp_target=${Hexadecimal(resp.s2.target)}\n")
396      XSDebug(p"s2_correct_s1_ghist=$s2_correct_s1_ghist\n")
397      XSDebug(p"s1_ghist=${Binary(s1_ghist.predHist)}\n")
398      XSDebug(p"s2_predicted_ghist=${Binary(s2_predicted_ghist.predHist)}\n")
399    }
400  }
401
402  val s2_redirect_target = s2_fire && s1_valid && s1_pc =/= resp.s2.target
403  val s2_saw_s1_hit = RegEnable(resp.s1.preds.hit, s1_fire)
404  val s2_redirect_target_both_hit = s2_redirect_target &&  s2_saw_s1_hit &&  resp.s2.preds.hit
405
406  XSPerfAccumulate("s2_redirect_because_s1_not_valid", s2_fire && !s1_valid)
407  XSPerfAccumulate("s2_redirect_because_target_diff", s2_fire && s1_valid && s1_pc =/= resp.s2.target)
408  XSPerfAccumulate("s2_redirect_target_diff_s1_nhit_s2_hit", s2_redirect_target && !s2_saw_s1_hit &&  resp.s2.preds.hit)
409  XSPerfAccumulate("s2_redirect_target_diff_s1_hit_s2_nhit", s2_redirect_target &&  s2_saw_s1_hit && !resp.s2.preds.hit)
410  XSPerfAccumulate("s2_redirect_target_diff_both_hit",  s2_redirect_target &&  s2_saw_s1_hit &&  resp.s2.preds.hit)
411  XSPerfAccumulate("s2_redirect_br_direction_diff",
412    s2_redirect_target_both_hit &&
413    RegEnable(PriorityEncoder(resp.s1.preds.br_taken_mask), s1_fire) =/= PriorityEncoder(resp.s2.preds.br_taken_mask))
414  XSPerfAccumulate("s2_redirect_because_ghist_diff", s2_fire && s1_valid && s2_correct_s1_ghist)
415
416  // s3
417  val s3_predicted_ghist = s3_ghist.update(resp.s3.preds.br_valids, resp.s3.real_br_taken_mask())
418
419  val s3_correct_s2_ghist = s2_ghist =/= s3_predicted_ghist
420  val s3_correct_s1_ghist = s1_ghist =/= s3_predicted_ghist
421  val s3_correct_s0_ghist_reg = s0_ghist_reg =/= s3_predicted_ghist
422
423  val previous_s2_pred_taken = RegEnable(resp.s2.real_slot_taken_mask.asUInt.orR, init=false.B, enable=s2_fire)
424  val s3_pred_taken = resp.s3.real_slot_taken_mask.asUInt.orR
425
426  when(s3_fire) {
427    when((s2_valid && (s2_pc =/= resp.s3.target || s3_correct_s2_ghist)) ||
428      (!s2_valid && s1_valid && (s1_pc =/= resp.s3.target || s3_correct_s1_ghist)) ||
429      (!s2_valid && !s1_valid && (s0_pc_reg =/= resp.s3.target || s3_correct_s0_ghist_reg)) ||
430      previous_s2_pred_taken =/= s3_pred_taken) {
431
432      s0_ghist := s3_predicted_ghist
433      s3_redirect := true.B
434      s0_pc := resp.s3.target
435      s0_phist := (s3_phist << 1) | s3_pc(instOffsetBits)
436    }
437  }
438
439  // Send signal tell Ftq override
440  val s2_ftq_idx = RegEnable(io.ftq_to_bpu.enq_ptr, s1_fire)
441  val s3_ftq_idx = RegEnable(s2_ftq_idx, s2_fire)
442
443  io.bpu_to_ftq.resp.bits.s1.valid := s1_fire && !s1_flush
444  io.bpu_to_ftq.resp.bits.s1.hasRedirect := false.B
445  io.bpu_to_ftq.resp.bits.s1.ftq_idx := DontCare
446  io.bpu_to_ftq.resp.bits.s2.valid := s2_fire && !s2_flush
447  io.bpu_to_ftq.resp.bits.s2.hasRedirect := s2_redirect
448  io.bpu_to_ftq.resp.bits.s2.ftq_idx := s2_ftq_idx
449  io.bpu_to_ftq.resp.bits.s3.valid := s3_fire && !s3_flush
450  io.bpu_to_ftq.resp.bits.s3.hasRedirect := s3_redirect
451  io.bpu_to_ftq.resp.bits.s3.ftq_idx := s3_ftq_idx
452
453  val redirect = io.ftq_to_bpu.redirect.bits
454
455  predictors.io.update := io.ftq_to_bpu.update
456  predictors.io.redirect := io.ftq_to_bpu.redirect
457
458  when(io.ftq_to_bpu.redirect.valid) {
459    val oldGh = redirect.cfiUpdate.hist
460
461    val shift = redirect.cfiUpdate.shift
462    val addIntoHist = redirect.cfiUpdate.addIntoHist
463
464    val isBr = redirect.cfiUpdate.pd.isBr
465    val taken = redirect.cfiUpdate.taken
466
467    val updatedGh = oldGh.update(shift, taken && addIntoHist)
468    s0_ghist := updatedGh // TODO: History fix logic
469    s0_pc := redirect.cfiUpdate.target
470    val oldPh = redirect.cfiUpdate.phist
471    val phNewBit = redirect.cfiUpdate.phNewBit
472    s0_phist := (oldPh << 1) | phNewBit
473
474    XSDebug(io.ftq_to_bpu.redirect.valid, p"-------------redirect Repair------------\n")
475    // XSDebug(io.ftq_to_bpu.redirect.valid, p"taken_mask=${Binary(taken_mask.asUInt)}, brValids=${Binary(brValids.asUInt)}\n")
476    XSDebug(io.ftq_to_bpu.redirect.valid, p"isBr: ${isBr}, taken: ${taken}, addIntoHist: ${addIntoHist}, shift: ${shift}\n")
477    XSDebug(io.ftq_to_bpu.redirect.valid, p"oldGh   =${Binary(oldGh.predHist)}\n")
478    XSDebug(io.ftq_to_bpu.redirect.valid, p"updateGh=${Binary(updatedGh.predHist)}\n")
479
480  }
481
482  XSDebug(RegNext(reset.asBool) && !reset.asBool, "Reseting...\n")
483  XSDebug(io.ftq_to_bpu.update.valid, p"Update from ftq\n")
484  XSDebug(io.ftq_to_bpu.redirect.valid, p"Redirect from ftq\n")
485
486  XSDebug("[BP0]                 fire=%d                      pc=%x\n", s0_fire, s0_pc)
487  XSDebug("[BP1] v=%d r=%d cr=%d fire=%d             flush=%d pc=%x\n",
488    s1_valid, s1_ready, s1_components_ready, s1_fire, s1_flush, s1_pc)
489  XSDebug("[BP2] v=%d r=%d cr=%d fire=%d redirect=%d flush=%d pc=%x\n",
490  s2_valid, s2_ready, s2_components_ready, s2_fire, s2_redirect, s2_flush, s2_pc)
491  XSDebug("[BP3] v=%d r=%d cr=%d fire=%d redirect=%d flush=%d pc=%x\n",
492  s3_valid, s3_ready, s3_components_ready, s3_fire, s3_redirect, s3_flush, s3_pc)
493  XSDebug("[FTQ] ready=%d\n", io.bpu_to_ftq.resp.ready)
494  XSDebug("resp.s1.target=%x\n", resp.s1.target)
495  XSDebug("resp.s2.target=%x\n", resp.s2.target)
496  XSDebug("s0_ghist: %b\n", s0_ghist.predHist)
497  XSDebug("s1_ghist: %b\n", s1_ghist.predHist)
498  XSDebug("s2_ghist: %b\n", s2_ghist.predHist)
499  XSDebug("s3_ghist: %b\n", s3_ghist.predHist)
500  XSDebug("s2_predicted_ghist: %b\n", s2_predicted_ghist.predHist)
501  XSDebug("s3_predicted_ghist: %b\n", s3_predicted_ghist.predHist)
502  XSDebug("s3_correct_s2_ghist: %b, s3_correct_s1_ghist: %b, s2_correct_s1_ghist: %b\n",
503  s3_correct_s2_ghist,  s3_correct_s1_ghist,  s2_correct_s1_ghist)
504
505
506  io.ftq_to_bpu.update.bits.display(io.ftq_to_bpu.update.valid)
507  io.ftq_to_bpu.redirect.bits.display(io.ftq_to_bpu.redirect.valid)
508
509
510  XSPerfAccumulate("s2_redirect", s2_redirect)
511  XSPerfAccumulate("s3_redirect", s3_redirect)
512
513  val perfEvents = predictors.asInstanceOf[Composer].perfEvents.map(_._1).zip(predictors.asInstanceOf[Composer].perfinfo.perfEvents.perf_events)
514  val perfinfo = IO(new Bundle(){
515    val perfEvents = Output(new PerfEventsBundle(predictors.asInstanceOf[Composer].perfinfo.perfEvents.perf_events.length))
516  })
517  perfinfo.perfEvents := predictors.asInstanceOf[Composer].perfinfo.perfEvents
518
519}
520