xref: /XiangShan/src/main/scala/xiangshan/frontend/BPU.scala (revision ed328a5de3531b3fdc5c9d06f41246c8a0e691e8)
1package xiangshan.frontend
2
3import chisel3._
4import chisel3.util._
5import utils._
6import xiangshan._
7import xiangshan.backend.ALUOpType
8import xiangshan.backend.JumpOpType
9
10trait HasBPUParameter extends HasXSParameter {
11  val BPUDebug = false
12}
13
14class TableAddr(val idxBits: Int, val banks: Int) extends XSBundle {
15  def tagBits = VAddrBits - idxBits - 1
16
17  val tag = UInt(tagBits.W)
18  val idx = UInt(idxBits.W)
19  val offset = UInt(1.W)
20
21  def fromUInt(x: UInt) = x.asTypeOf(UInt(VAddrBits.W)).asTypeOf(this)
22  def getTag(x: UInt) = fromUInt(x).tag
23  def getIdx(x: UInt) = fromUInt(x).idx
24  def getBank(x: UInt) = getIdx(x)(log2Up(banks) - 1, 0)
25  def getBankIdx(x: UInt) = getIdx(x)(idxBits - 1, log2Up(banks))
26}
27
28class PredictorResponse extends XSBundle {
29  class UbtbResp extends XSBundle {
30  // the valid bits indicates whether a target is hit
31    val targets = Vec(PredictWidth, UInt(VAddrBits.W))
32    val hits = Vec(PredictWidth, Bool())
33    val takens = Vec(PredictWidth, Bool())
34    val notTakens = Vec(PredictWidth, Bool())
35    val is_RVC = Vec(PredictWidth, Bool())
36  }
37  class BtbResp extends XSBundle {
38  // the valid bits indicates whether a target is hit
39    val targets = Vec(PredictWidth, UInt(VAddrBits.W))
40    val hits = Vec(PredictWidth, Bool())
41    val types = Vec(PredictWidth, UInt(2.W))
42    val isRVC = Vec(PredictWidth, Bool())
43  }
44  class BimResp extends XSBundle {
45    val ctrs = Vec(PredictWidth, UInt(2.W))
46  }
47  class TageResp extends XSBundle {
48  // the valid bits indicates whether a prediction is hit
49    val takens = Vec(PredictWidth, Bool())
50    val hits = Vec(PredictWidth, Bool())
51  }
52  class LoopResp extends XSBundle {
53    val exit = Vec(PredictWidth, Bool())
54  }
55
56  val ubtb = new UbtbResp
57  val btb = new BtbResp
58  val bim = new BimResp
59  val tage = new TageResp
60  val loop = new LoopResp
61}
62
63abstract class BasePredictor extends XSModule with HasBPUParameter{
64  val metaLen = 0
65
66  // An implementation MUST extend the IO bundle with a response
67  // and the special input from other predictors, as well as
68  // the metas to store in BRQ
69  abstract class Resp extends XSBundle {}
70  abstract class FromOthers extends XSBundle {}
71  abstract class Meta extends XSBundle {}
72
73  class DefaultBasePredictorIO extends XSBundle {
74    val flush = Input(Bool())
75    val pc = Flipped(ValidIO(UInt(VAddrBits.W)))
76    val hist = Input(UInt(HistoryLength.W))
77    val inMask = Input(UInt(PredictWidth.W))
78    val update = Flipped(ValidIO(new BranchUpdateInfoWithHist))
79  }
80
81  val io = new DefaultBasePredictorIO
82
83  val debug = false
84
85  // circular shifting
86  def circularShiftLeft(source: UInt, len: Int, shamt: UInt): UInt = {
87    val res = Wire(UInt(len.W))
88    val higher = source << shamt
89    val lower = source >> (len.U - shamt)
90    res := higher | lower
91    res
92  }
93
94  def circularShiftRight(source: UInt, len: Int, shamt: UInt): UInt = {
95    val res = Wire(UInt(len.W))
96    val higher = source << (len.U - shamt)
97    val lower = source >> shamt
98    res := higher | lower
99    res
100  }
101}
102
103class BPUStageIO extends XSBundle {
104  val pc = UInt(VAddrBits.W)
105  val mask = UInt(PredictWidth.W)
106  val resp = new PredictorResponse
107  val target = UInt(VAddrBits.W)
108  val brInfo = Vec(PredictWidth, new BranchInfo)
109}
110
111
112abstract class BPUStage extends XSModule with HasBPUParameter{
113  class DefaultIO extends XSBundle {
114    val flush = Input(Bool())
115    val in = Flipped(Decoupled(new BPUStageIO))
116    val pred = Decoupled(new BranchPrediction)
117    val out = Decoupled(new BPUStageIO)
118    val predecode = Flipped(ValidIO(new Predecode))
119  }
120  val io = IO(new DefaultIO)
121
122  val predValid = RegInit(false.B)
123
124  io.in.ready := !predValid || io.out.fire() && io.pred.fire() || io.flush
125
126  def npc(pc: UInt, instCount: UInt) = pc + (instCount << 1.U)
127
128  val inFire = io.in.fire()
129  val inLatch = RegEnable(io.in.bits, inFire)
130
131  val outFire = io.out.fire()
132
133  // Each stage has its own logic to decide
134  // takens, notTakens and target
135
136  val takens = Wire(Vec(PredictWidth, Bool()))
137  val notTakens = Wire(Vec(PredictWidth, Bool()))
138  val jmpIdx = PriorityEncoder(takens)
139  val hasNTBr = (0 until PredictWidth).map(i => i.U <= jmpIdx && notTakens(i)).reduce(_||_)
140  val taken = takens.reduce(_||_)
141  // get the last valid inst
142  // val lastValidPos = MuxCase(0.U, (PredictWidth-1 to 0).map(i => (inLatch.mask(i), i.U)))
143  val lastValidPos = PriorityMux(Reverse(inLatch.mask), (PredictWidth-1 to 0 by -1).map(i => i.U))
144  val lastHit   = Wire(Bool())
145  val lastIsRVC = Wire(Bool())
146  // val lastValidPos = WireInit(0.U(log2Up(PredictWidth).W))
147  // for (i <- 0 until PredictWidth) {
148  //   when (inLatch.mask(i)) { lastValidPos := i.U }
149  // }
150  val targetSrc = Wire(Vec(PredictWidth, UInt(VAddrBits.W)))
151  val target = Mux(taken, targetSrc(jmpIdx), npc(inLatch.pc, PopCount(inLatch.mask)))
152
153  io.pred.bits <> DontCare
154  io.pred.bits.redirect := target =/= inLatch.target
155  io.pred.bits.taken := taken
156  io.pred.bits.jmpIdx := jmpIdx
157  io.pred.bits.hasNotTakenBrs := hasNTBr
158  io.pred.bits.target := target
159  io.pred.bits.saveHalfRVI := ((lastValidPos === jmpIdx && taken) || !taken ) && !lastIsRVC && lastHit
160
161  io.out.bits <> DontCare
162  io.out.bits.pc := inLatch.pc
163  io.out.bits.mask := inLatch.mask
164  io.out.bits.target := target
165  io.out.bits.resp <> inLatch.resp
166  io.out.bits.brInfo := inLatch.brInfo
167
168  // Default logic
169  //  pred.ready not taken into consideration
170  //  could be broken
171  when (io.flush)     { predValid := false.B }
172  .elsewhen (inFire)  { predValid := true.B }
173  .elsewhen (outFire) { predValid := false.B }
174  .otherwise          { predValid := predValid }
175
176  io.out.valid  := predValid && !io.flush
177  io.pred.valid := predValid && !io.flush
178
179  if (BPUDebug) {
180    XSDebug(io.in.fire(), "in:(%d %d) pc=%x, mask=%b, target=%x\n",
181      io.in.valid, io.in.ready, io.in.bits.pc, io.in.bits.mask, io.in.bits.target)
182    XSDebug(io.out.fire(), "out:(%d %d) pc=%x, mask=%b, target=%x\n",
183      io.out.valid, io.out.ready, io.out.bits.pc, io.out.bits.mask, io.out.bits.target)
184    XSDebug("flush=%d\n", io.flush)
185    XSDebug("taken=%d, takens=%b, notTakens=%b, jmpIdx=%d, hasNTBr=%d, lastValidPos=%d, target=%x\n",
186      taken, takens.asUInt, notTakens.asUInt, jmpIdx, hasNTBr, lastValidPos, target)
187    val p = io.pred.bits
188    XSDebug(io.pred.fire(), "outPred: redirect=%d, taken=%d, jmpIdx=%d, hasNTBrs=%d, target=%x, saveHalfRVI=%d\n",
189      p.redirect, p.taken, p.jmpIdx, p.hasNotTakenBrs, p.target, p.saveHalfRVI)
190    XSDebug(io.pred.fire() && p.taken, "outPredTaken: fetchPC:%x, jmpPC:%x\n",
191      inLatch.pc, inLatch.pc + (jmpIdx << 1.U))
192    XSDebug(io.pred.fire() && p.redirect, "outPred: previous target:%x redirected to %x \n",
193      inLatch.target, p.target)
194    XSDebug(io.pred.fire(), "outPred targetSrc: ")
195    for (i <- 0 until PredictWidth) {
196      XSDebug(false, io.pred.fire(), "(%d):%x ", i.U, targetSrc(i))
197    }
198    XSDebug(false, io.pred.fire(), "\n")
199  }
200}
201
202class BPUStage1 extends BPUStage {
203
204  // 'overrides' default logic
205  // when flush, the prediction should also starts
206  when (inFire)        { predValid := true.B }
207  .elsewhen (io.flush) { predValid := false.B }
208  .elsewhen (outFire)  { predValid := false.B }
209  .otherwise           { predValid := predValid }
210  // io.out.valid := predValid
211
212  // ubtb is accessed with inLatch pc in s1,
213  // so we use io.in instead of inLatch
214  val ubtbResp = io.in.bits.resp.ubtb
215  // the read operation is already masked, so we do not need to mask here
216  takens    := VecInit((0 until PredictWidth).map(i => ubtbResp.hits(i) && ubtbResp.takens(i)))
217  notTakens := VecInit((0 until PredictWidth).map(i => ubtbResp.hits(i) && ubtbResp.notTakens(i)))
218  targetSrc := ubtbResp.targets
219
220  lastIsRVC := ubtbResp.is_RVC(lastValidPos)
221  lastHit   := ubtbResp.hits(lastValidPos)
222
223  // resp and brInfo are from the components,
224  // so it does not need to be latched
225  io.out.bits.resp <> io.in.bits.resp
226  io.out.bits.brInfo := io.in.bits.brInfo
227
228  if (BPUDebug) {
229    io.out.bits.brInfo.map(_.debug_ubtb_cycle := GTimer())
230    XSDebug(io.pred.fire(), "outPred using ubtb resp: hits:%b, takens:%b, notTakens:%b, isRVC:%b\n",
231      ubtbResp.hits.asUInt, ubtbResp.takens.asUInt, ubtbResp.notTakens.asUInt, ubtbResp.is_RVC.asUInt)
232  }
233}
234
235class BPUStage2 extends BPUStage {
236
237  // Use latched response from s1
238  val btbResp = inLatch.resp.btb
239  val bimResp = inLatch.resp.bim
240  takens    := VecInit((0 until PredictWidth).map(i => btbResp.hits(i) && (btbResp.types(i) === BTBtype.B && bimResp.ctrs(i)(1) || btbResp.types(i) =/= BTBtype.B)))
241  notTakens := VecInit((0 until PredictWidth).map(i => btbResp.hits(i) && btbResp.types(i) === BTBtype.B && !bimResp.ctrs(i)(1)))
242  targetSrc := btbResp.targets
243
244  lastIsRVC := btbResp.isRVC(lastValidPos)
245  lastHit   := btbResp.hits(lastValidPos)
246
247
248  if (BPUDebug) {
249    io.out.bits.brInfo.map(_.debug_btb_cycle := GTimer())
250    XSDebug(io.pred.fire(), "outPred using btb&bim resp: hits:%b, ctrTakens:%b\n",
251      btbResp.hits.asUInt, VecInit(bimResp.ctrs.map(_(1))).asUInt)
252  }
253}
254
255class BPUStage3 extends BPUStage {
256
257  io.out.valid := predValid && io.predecode.valid && !io.flush
258
259  // TAGE has its own pipelines and the
260  // response comes directly from s3,
261  // so we do not use those from inLatch
262  val tageResp = io.in.bits.resp.tage
263  val tageTakens = tageResp.takens
264
265  val loopResp = io.in.bits.resp.loop.exit
266
267  val pdMask = io.predecode.bits.mask
268  val pds    = io.predecode.bits.pd
269
270  val btbHits   = inLatch.resp.btb.hits.asUInt
271  val bimTakens = VecInit(inLatch.resp.bim.ctrs.map(_(1)))
272
273  val brs   = pdMask & Reverse(Cat(pds.map(_.isBr)))
274  val jals  = pdMask & Reverse(Cat(pds.map(_.isJal)))
275  val jalrs = pdMask & Reverse(Cat(pds.map(_.isJalr)))
276  // val calls = pdMask & Reverse(Cat(pds.map(_.isCall)))
277  // val rets  = pdMask & Reverse(Cat(pds.map(_.isRet)))
278
279  // val callIdx = PriorityEncoder(calls)
280  // val retIdx  = PriorityEncoder(rets)
281
282  val brTakens = brs &
283    (if (EnableBPD) Reverse(Cat((0 until PredictWidth).map(i => tageTakens(i)))) else Reverse(Cat((0 until PredictWidth).map(i => bimTakens(i))))) &
284    (if (EnableLoop) ~loopResp.asUInt else Fill(PredictWidth, 1.U(1.W)))
285    // if (EnableBPD) {
286    //   brs & Reverse(Cat((0 until PredictWidth).map(i => tageValidTakens(i))))
287    // } else {
288    //   brs & Reverse(Cat((0 until PredictWidth).map(i => bimTakens(i))))
289    // }
290
291  // predict taken only if btb has a target, jal targets will be provided by IFU
292  takens := VecInit((0 until PredictWidth).map(i => (brTakens(i) || jalrs(i)) && btbHits(i) || jals(i)))
293  // Whether should we count in branches that are not recorded in btb?
294  // PS: Currently counted in. Whenever tage does not provide a valid
295  //     taken prediction, the branch is counted as a not taken branch
296  notTakens := ((if (EnableBPD) { VecInit((0 until PredictWidth).map(i => brs(i) && !tageTakens(i)))}
297                else           { VecInit((0 until PredictWidth).map(i => brs(i) && !bimTakens(i)))}).asUInt |
298               (if (EnableLoop) { VecInit((0 until PredictWidth).map(i => brs(i) && loopResp(i)))}
299                else { WireInit(0.U.asTypeOf(UInt(PredictWidth.W))) }).asUInt).asTypeOf(Vec(PredictWidth, Bool()))
300  targetSrc := inLatch.resp.btb.targets
301
302  lastIsRVC := pds(lastValidPos).isRVC
303  when (lastValidPos === 1.U) {
304    lastHit := pdMask(1) |
305      !pdMask(0) & !pdMask(1) |
306      pdMask(0) & !pdMask(1) & (pds(0).isRVC | !io.predecode.bits.isFetchpcEqualFirstpc)
307  }.elsewhen (lastValidPos > 0.U) {
308    lastHit := pdMask(lastValidPos) |
309      !pdMask(lastValidPos - 1.U) & !pdMask(lastValidPos) |
310      pdMask(lastValidPos - 1.U) & !pdMask(lastValidPos) & pds(lastValidPos - 1.U).isRVC
311  }.otherwise {
312    lastHit := pdMask(0) | !pdMask(0) & !pds(0).isRVC
313  }
314
315
316  // Wrap tage resp and tage meta in
317  // This is ugly
318  io.out.bits.resp.tage <> io.in.bits.resp.tage
319  io.out.bits.resp.loop <> io.in.bits.resp.loop
320  for (i <- 0 until PredictWidth) {
321    io.out.bits.brInfo(i).tageMeta := io.in.bits.brInfo(i).tageMeta
322    io.out.bits.brInfo(i).specCnt := io.in.bits.brInfo(i).specCnt
323  }
324
325  if (BPUDebug) {
326    io.out.bits.brInfo.map(_.debug_tage_cycle := GTimer())
327    XSDebug(io.predecode.valid, "predecode: pc:%x, mask:%b\n", inLatch.pc, io.predecode.bits.mask)
328    for (i <- 0 until PredictWidth) {
329      val p = io.predecode.bits.pd(i)
330      XSDebug(io.predecode.valid && io.predecode.bits.mask(i), "predecode(%d): brType:%d, br:%d, jal:%d, jalr:%d, call:%d, ret:%d, RVC:%d, excType:%d\n",
331        i.U, p.brType, p.isBr, p.isJal, p.isJalr, p.isCall, p.isRet, p.isRVC, p.excType)
332    }
333  }
334}
335
336trait BranchPredictorComponents extends HasXSParameter {
337  val ubtb = Module(new MicroBTB)
338  val btb = Module(new BTB)
339  val bim = Module(new BIM)
340  val tage = (if(EnableBPD) { Module(new Tage) }
341              else          { Module(new FakeTage) })
342  val loop = Module(new LoopPredictor)
343  val preds = Seq(ubtb, btb, bim, tage, loop)
344  preds.map(_.io := DontCare)
345}
346
347class BPUReq extends XSBundle {
348  val pc = UInt(VAddrBits.W)
349  val hist = UInt(HistoryLength.W)
350  val inMask = UInt(PredictWidth.W)
351}
352
353class BranchUpdateInfoWithHist extends XSBundle {
354  val ui = new BranchUpdateInfo
355  val hist = UInt(HistoryLength.W)
356}
357
358object BranchUpdateInfoWithHist {
359  def apply (brInfo: BranchUpdateInfo, hist: UInt) = {
360    val b = Wire(new BranchUpdateInfoWithHist)
361    b.ui <> brInfo
362    b.hist := hist
363    b
364  }
365}
366
367abstract class BaseBPU extends XSModule with BranchPredictorComponents with HasBPUParameter{
368  val io = IO(new Bundle() {
369    // from backend
370    val inOrderBrInfo    = Flipped(ValidIO(new BranchUpdateInfoWithHist))
371    val outOfOrderBrInfo = Flipped(ValidIO(new BranchUpdateInfoWithHist))
372    // from ifu, frontend redirect
373    val flush = Input(Vec(3, Bool()))
374    // from if1
375    val in = Flipped(ValidIO(new BPUReq))
376    // to if2/if3/if4
377    val out = Vec(3, Decoupled(new BranchPrediction))
378    // from if4
379    val predecode = Flipped(ValidIO(new Predecode))
380    // to if4, some bpu info used for updating
381    val branchInfo = Decoupled(Vec(PredictWidth, new BranchInfo))
382  })
383
384  def npc(pc: UInt, instCount: UInt) = pc + (instCount << 1.U)
385
386  preds.map(_.io.update <> io.outOfOrderBrInfo)
387  tage.io.update <> io.inOrderBrInfo
388
389  val s1 = Module(new BPUStage1)
390  val s2 = Module(new BPUStage2)
391  val s3 = Module(new BPUStage3)
392
393  s1.io.flush := io.flush(0)
394  s2.io.flush := io.flush(1)
395  s3.io.flush := io.flush(2)
396
397  s1.io.in <> DontCare
398  s2.io.in <> s1.io.out
399  s3.io.in <> s2.io.out
400
401  io.out(0) <> s1.io.pred
402  io.out(1) <> s2.io.pred
403  io.out(2) <> s3.io.pred
404
405  s1.io.predecode <> DontCare
406  s2.io.predecode <> DontCare
407  s3.io.predecode <> io.predecode
408
409  io.branchInfo.valid := s3.io.out.valid
410  io.branchInfo.bits := s3.io.out.bits.brInfo
411  s3.io.out.ready := io.branchInfo.ready
412
413  if (BPUDebug) {
414    XSDebug(io.branchInfo.fire(), "branchInfo sent!\n")
415    for (i <- 0 until PredictWidth) {
416      val b = io.branchInfo.bits(i)
417      XSDebug(io.branchInfo.fire(), "brInfo(%d): ubtbWrWay:%d, ubtbHit:%d, btbWrWay:%d, btbHitJal:%d, bimCtr:%d, fetchIdx:%d\n",
418        i.U, b.ubtbWriteWay, b.ubtbHits, b.btbWriteWay, b.btbHitJal, b.bimCtr, b.fetchIdx)
419      val t = b.tageMeta
420      XSDebug(io.branchInfo.fire(), "  tageMeta: pvder(%d):%d, altDiffers:%d, pvderU:%d, pvderCtr:%d, allocate(%d):%d\n",
421        t.provider.valid, t.provider.bits, t.altDiffers, t.providerU, t.providerCtr, t.allocate.valid, t.allocate.bits)
422    }
423  }
424  val debug_verbose = false
425}
426
427
428class FakeBPU extends BaseBPU {
429  io.out.foreach(i => {
430    // Provide not takens
431    i.valid := true.B
432    i.bits <> DontCare
433    i.bits.redirect := false.B
434  })
435  io.branchInfo <> DontCare
436}
437
438class BPU extends BaseBPU {
439
440  //**********************Stage 1****************************//
441  val s1_fire = s1.io.in.fire()
442  val s1_resp_in = Wire(new PredictorResponse)
443  val s1_brInfo_in = Wire(Vec(PredictWidth, new BranchInfo))
444
445  s1_resp_in.tage := DontCare
446  s1_resp_in.loop := DontCare
447  s1_brInfo_in    := DontCare
448  (0 until PredictWidth).foreach(i => s1_brInfo_in(i).fetchIdx := i.U)
449
450  val s1_inLatch = RegEnable(io.in, s1_fire)
451  ubtb.io.flush := io.flush(0) // TODO: fix this
452  ubtb.io.pc.valid := s1_inLatch.valid
453  ubtb.io.pc.bits := s1_inLatch.bits.pc
454  ubtb.io.inMask := s1_inLatch.bits.inMask
455
456
457
458  // Wrap ubtb response into resp_in and brInfo_in
459  s1_resp_in.ubtb <> ubtb.io.out
460  for (i <- 0 until PredictWidth) {
461    s1_brInfo_in(i).ubtbWriteWay := ubtb.io.uBTBBranchInfo.writeWay(i)
462    s1_brInfo_in(i).ubtbHits := ubtb.io.uBTBBranchInfo.hits(i)
463  }
464
465  btb.io.flush := io.flush(0) // TODO: fix this
466  btb.io.pc.valid := io.in.valid
467  btb.io.pc.bits := io.in.bits.pc
468  btb.io.inMask := io.in.bits.inMask
469
470
471
472  // Wrap btb response into resp_in and brInfo_in
473  s1_resp_in.btb <> btb.io.resp
474  for (i <- 0 until PredictWidth) {
475    s1_brInfo_in(i).btbWriteWay := btb.io.meta.writeWay(i)
476    s1_brInfo_in(i).btbHitJal   := btb.io.meta.hitJal(i)
477  }
478
479  bim.io.flush := io.flush(0) // TODO: fix this
480  bim.io.pc.valid := io.in.valid
481  bim.io.pc.bits := io.in.bits.pc
482  bim.io.inMask := io.in.bits.inMask
483
484
485  // Wrap bim response into resp_in and brInfo_in
486  s1_resp_in.bim <> bim.io.resp
487  for (i <- 0 until PredictWidth) {
488    s1_brInfo_in(i).bimCtr := bim.io.meta.ctrs(i)
489  }
490
491
492  s1.io.in.valid := io.in.valid
493  s1.io.in.bits.pc := io.in.bits.pc
494  s1.io.in.bits.mask := io.in.bits.inMask
495  s1.io.in.bits.target := npc(io.in.bits.pc, PopCount(io.in.bits.inMask)) // Deault target npc
496  s1.io.in.bits.resp <> s1_resp_in
497  s1.io.in.bits.brInfo <> s1_brInfo_in
498
499  val s1_hist = RegEnable(io.in.bits.hist, enable=io.in.valid)
500
501  //**********************Stage 2****************************//
502  tage.io.flush := io.flush(1) // TODO: fix this
503  tage.io.pc.valid := s1.io.out.fire()
504  tage.io.pc.bits := s1.io.out.bits.pc // PC from s1
505  tage.io.hist := s1_hist // The inst is from s1
506  tage.io.inMask := s1.io.out.bits.mask
507  tage.io.s3Fire := s3.io.in.fire() // Tell tage to march 1 stage
508  tage.io.bim <> s1.io.out.bits.resp.bim // Use bim results from s1
509
510  //**********************Stage 3****************************//
511  // Wrap tage response and meta into s3.io.in.bits
512  // This is ugly
513
514  loop.io.flush := io.flush(2)
515  loop.io.pc.valid := s2.io.out.fire()
516  loop.io.pc.bits := s2.io.out.bits.pc
517
518  s3.io.in.bits.resp.tage <> tage.io.resp
519  s3.io.in.bits.resp.loop <> loop.io.resp
520  for (i <- 0 until PredictWidth) {
521    s3.io.in.bits.brInfo(i).tageMeta := tage.io.meta(i)
522    s3.io.in.bits.brInfo(i).specCnt := loop.io.meta.specCnts(i)
523  }
524
525  if (BPUDebug) {
526    if (debug_verbose) {
527      val uo = ubtb.io.out
528      XSDebug("debug: ubtb hits:%b, takens:%b, notTakens:%b\n", uo.hits.asUInt, uo.takens.asUInt, uo.notTakens.asUInt)
529      val bio = bim.io.resp
530      XSDebug("debug: bim takens:%b\n", VecInit(bio.ctrs.map(_(1))).asUInt)
531      val bo = btb.io.resp
532      XSDebug("debug: btb hits:%b\n", bo.hits.asUInt)
533    }
534  }
535
536}
537