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