1package xiangshan.frontend 2 3import chisel3._ 4import chisel3.util._ 5import device.RAMHelper 6import xiangshan._ 7import utils._ 8import xiangshan.cache._ 9 10trait HasIFUConst { this: XSModule => 11 val resetVector = 0x80000000L//TODO: set reset vec 12 val groupAlign = log2Up(FetchWidth * 4 * 2) 13 def groupPC(pc: UInt): UInt = Cat(pc(VAddrBits-1, groupAlign), 0.U(groupAlign.W)) 14 // each 1 bit in mask stands for 2 Bytes 15 def mask(pc: UInt): UInt = (Fill(PredictWidth * 2, 1.U(1.W)) >> pc(groupAlign - 1, 1))(PredictWidth - 1, 0) 16 def snpc(pc: UInt): UInt = pc + (PopCount(mask(pc)) << 1) 17 18 val IFUDebug = true 19} 20 21class GlobalHistoryInfo() extends XSBundle { 22 val sawNTBr = Bool() 23 val takenOnBr = Bool() 24 val saveHalfRVI = Bool() 25 def shifted = takenOnBr || sawNTBr 26 def newPtr(ptr: UInt) = Mux(shifted, ptr - 1.U, ptr) 27 implicit val name = "IFU" 28 def debug = XSDebug("[GHInfo] sawNTBr=%d, takenOnBr=%d, saveHalfRVI=%d\n", sawNTBr, takenOnBr, saveHalfRVI) 29 // override def toString(): String = "histPtr=%d, sawNTBr=%d, takenOnBr=%d, saveHalfRVI=%d".format(histPtr, sawNTBr, takenOnBr, saveHalfRVI) 30} 31 32class IFUIO extends XSBundle 33{ 34 val fetchPacket = DecoupledIO(new FetchPacket) 35 val redirect = Flipped(ValidIO(new Redirect)) 36 val outOfOrderBrInfo = Flipped(ValidIO(new BranchUpdateInfo)) 37 val inOrderBrInfo = Flipped(ValidIO(new BranchUpdateInfo)) 38 val icacheReq = DecoupledIO(new ICacheReq) 39 val icacheResp = Flipped(DecoupledIO(new ICacheResp)) 40 val icacheFlush = Output(UInt(2.W)) 41 // val loopBufPar = Flipped(new LoopBufferParameters) 42} 43 44class IFU extends XSModule with HasIFUConst 45{ 46 val io = IO(new IFUIO) 47 val bpu = BPU(EnableBPU) 48 val pd = Module(new PreDecode) 49 val loopBuffer = if(EnableLB) { Module(new LoopBuffer) } else { Module(new FakeLoopBuffer) } 50 51 val if2_redirect, if3_redirect, if4_redirect = WireInit(false.B) 52 val if1_flush, if2_flush, if3_flush, if4_flush = WireInit(false.B) 53 54 val loopBufPar = loopBuffer.io.loopBufPar 55 val inLoop = WireInit(loopBuffer.io.out.valid) 56 val icacheResp = WireInit(Mux(inLoop, loopBuffer.io.out.bits, io.icacheResp.bits)) 57 58 if4_flush := io.redirect.valid || loopBufPar.LBredirect.valid 59 if3_flush := if4_flush || if4_redirect 60 if2_flush := if3_flush || if3_redirect 61 if1_flush := if2_flush || if2_redirect 62 63 loopBuffer.io.flush := io.redirect.valid 64 65 //********************** IF1 ****************************// 66 val if1_valid = !reset.asBool && GTimer() > 500.U 67 val if1_npc = WireInit(0.U(VAddrBits.W)) 68 val if2_ready = WireInit(false.B) 69 val if1_fire = if1_valid && (if2_ready || if1_flush) && (inLoop || io.icacheReq.ready) 70 71 72 val if1_histPtr, if2_histPtr, if3_histPtr, if4_histPtr = Wire(UInt(log2Up(ExtHistoryLength).W)) 73 val if2_newPtr, if3_newPtr, if4_newPtr = Wire(UInt(log2Up(ExtHistoryLength).W)) 74 75 val extHist = RegInit(VecInit(Seq.fill(ExtHistoryLength)(0.U(1.W)))) 76 val shiftPtr = WireInit(false.B) 77 val newPtr = Wire(UInt(log2Up(ExtHistoryLength).W)) 78 val ptr = Mux(shiftPtr, newPtr, if1_histPtr) 79 val hist = Wire(Vec(HistoryLength, UInt(1.W))) 80 for (i <- 0 until HistoryLength) { 81 hist(i) := extHist(ptr + i.U) 82 } 83 84 shiftPtr := false.B 85 newPtr := if1_histPtr 86 87 def wrapGHInfo(bp: BranchPrediction) = { 88 val ghi = Wire(new GlobalHistoryInfo()) 89 ghi.sawNTBr := bp.hasNotTakenBrs 90 ghi.takenOnBr := bp.takenOnBr 91 ghi.saveHalfRVI := bp.saveHalfRVI 92 ghi 93 } 94 95 //********************** IF2 ****************************// 96 val if2_valid = RegInit(init = false.B) 97 val if3_ready = WireInit(false.B) 98 val if2_fire = if2_valid && if3_ready && !if2_flush 99 val if2_pc = RegEnable(next = if1_npc, init = resetVector.U, enable = if1_fire) 100 val if2_snpc = snpc(if2_pc) 101 val if2_predHistPtr = RegEnable(ptr, enable=if1_fire) 102 if2_ready := if2_fire || !if2_valid || if2_flush 103 when (if1_fire) { if2_valid := if1_valid } 104 .elsewhen (if2_flush) { if2_valid := false.B } 105 .elsewhen (if2_fire) { if2_valid := false.B } 106 107 when (RegNext(reset.asBool) && !reset.asBool) { 108 if1_npc := resetVector.U(VAddrBits.W) 109 }.elsewhen (if2_fire) { 110 if1_npc := if2_snpc 111 }.otherwise { 112 if1_npc := RegNext(if1_npc) 113 } 114 115 val if2_bp = bpu.io.out(0) 116 // if taken, bp_redirect should be true 117 // when taken on half RVI, we suppress this redirect signal 118 if2_redirect := if2_fire && if2_bp.redirect && !if2_bp.saveHalfRVI 119 when (if2_redirect) { 120 if1_npc := if2_bp.target 121 } 122 123 val if2_GHInfo = wrapGHInfo(if2_bp) 124 125 when (if2_fire && if2_GHInfo.shifted) { 126 shiftPtr := true.B 127 newPtr := if2_newPtr 128 } 129 when (if2_GHInfo.shifted && if2_newPtr >= ptr) { 130 hist(if2_newPtr-ptr) := if2_GHInfo.takenOnBr.asUInt 131 } 132 133 134 135 //********************** IF3 ****************************// 136 val if3_valid = RegInit(init = false.B) 137 val if4_ready = WireInit(false.B) 138 val if3_fire = if3_valid && if4_ready && (inLoop || io.icacheResp.valid) && !if3_flush 139 val if3_pc = RegEnable(if2_pc, if2_fire) 140 val if3_predHistPtr = RegEnable(if2_predHistPtr, enable=if2_fire) 141 if3_ready := if3_fire || !if3_valid || if3_flush 142 when (if3_flush) { if3_valid := false.B } 143 .elsewhen (if2_fire) { if3_valid := true.B } 144 .elsewhen (if3_fire) { if3_valid := false.B } 145 146 val if3_bp = bpu.io.out(1) 147 148 val if3_GHInfo = wrapGHInfo(if3_bp) 149 150 class PrevHalfInstr extends Bundle { 151 val valid = Bool() 152 val taken = Bool() 153 val ghInfo = new GlobalHistoryInfo() 154 val fetchpc = UInt(VAddrBits.W) // only for debug 155 val idx = UInt(VAddrBits.W) // only for debug 156 val pc = UInt(VAddrBits.W) 157 val target = UInt(VAddrBits.W) 158 val instr = UInt(16.W) 159 val ipf = Bool() 160 val newPtr = UInt(log2Up(ExtHistoryLength).W) 161 } 162 163 val if3_prevHalfInstr = RegInit(0.U.asTypeOf(new PrevHalfInstr)) 164 val if4_prevHalfInstr = Wire(new PrevHalfInstr) 165 // 32-bit instr crosses 2 pages, and the higher 16-bit triggers page fault 166 val crossPageIPF = WireInit(false.B) 167 when (if4_prevHalfInstr.valid) { 168 if3_prevHalfInstr := if4_prevHalfInstr 169 } 170 val prevHalfInstr = Mux(if4_prevHalfInstr.valid, if4_prevHalfInstr, if3_prevHalfInstr) 171 172 // the previous half of RVI instruction waits until it meets its last half 173 val if3_hasPrevHalfInstr = prevHalfInstr.valid && (prevHalfInstr.pc + 2.U) === if3_pc 174 // set to invalid once consumed or redirect from backend 175 val prevHalfConsumed = if3_hasPrevHalfInstr && if3_fire || if4_flush 176 when (prevHalfConsumed) { 177 if3_prevHalfInstr.valid := false.B 178 } 179 180 val if4_takenPrevHalf = RegInit(false.B) 181 182 // when bp signal a redirect, we distinguish between taken and not taken 183 // if taken and saveHalfRVI is true, we do not redirect to the target 184 if3_redirect := if3_fire && (if3_hasPrevHalfInstr && prevHalfInstr.taken || if3_bp.redirect && (if3_bp.taken && !if3_bp.saveHalfRVI || !if3_bp.taken) ) 185 186 when (if3_redirect) { 187 when (!(if3_hasPrevHalfInstr && prevHalfInstr.taken)) { 188 if1_npc := if3_bp.target 189 when (if3_GHInfo.shifted){ 190 shiftPtr := true.B 191 newPtr := if3_newPtr 192 } 193 } 194 } 195 196 // when it does not redirect, we still need to modify hist(wire) 197 when(if3_GHInfo.shifted && if3_newPtr >= ptr) { 198 hist(if3_newPtr-ptr) := if3_GHInfo.takenOnBr 199 } 200 when (if3_hasPrevHalfInstr && prevHalfInstr.ghInfo.shifted && prevHalfInstr.newPtr >= ptr) { 201 hist(prevHalfInstr.newPtr-ptr) := prevHalfInstr.ghInfo.takenOnBr 202 } 203 204 //********************** IF4 ****************************// 205 val if4_pd = RegEnable(pd.io.out, if3_fire) 206 val if4_ipf = RegEnable(icacheResp.ipf || if3_hasPrevHalfInstr && prevHalfInstr.ipf, if3_fire) 207 val if4_crossPageIPF = RegEnable(crossPageIPF, if3_fire) 208 val if4_valid = RegInit(false.B) 209 val if4_fire = if4_valid && io.fetchPacket.ready 210 val if4_pc = RegEnable(if3_pc, if3_fire) 211 212 val if4_predHistPtr = RegEnable(if3_predHistPtr, enable=if3_fire) 213 if4_ready := (if4_fire || !if4_valid || if4_flush) && GTimer() > 500.U 214 when (if4_flush) { if4_valid := false.B } 215 .elsewhen (if3_fire) { if4_valid := true.B } 216 .elsewhen (if4_fire) { if4_valid := false.B } 217 218 val if4_bp = Wire(new BranchPrediction) 219 if4_bp := bpu.io.out(2) 220 221 val if4_GHInfo = wrapGHInfo(if4_bp) 222 223 val if4_cfi_jal = if4_pd.instrs(if4_bp.jmpIdx) 224 val if4_cfi_jal_tgt = if4_pd.pc(if4_bp.jmpIdx) + Mux(if4_pd.pd(if4_bp.jmpIdx).isRVC, 225 SignExt(Cat(if4_cfi_jal(12), if4_cfi_jal(8), if4_cfi_jal(10, 9), if4_cfi_jal(6), if4_cfi_jal(7), if4_cfi_jal(2), if4_cfi_jal(11), if4_cfi_jal(5, 3), 0.U(1.W)), XLEN), 226 SignExt(Cat(if4_cfi_jal(31), if4_cfi_jal(19, 12), if4_cfi_jal(20), if4_cfi_jal(30, 21), 0.U(1.W)), XLEN)) 227 if4_bp.target := Mux(if4_pd.pd(if4_bp.jmpIdx).isJal && if4_bp.taken, if4_cfi_jal_tgt, bpu.io.out(2).target) 228 if4_bp.redirect := bpu.io.out(2).redirect || if4_pd.pd(if4_bp.jmpIdx).isJal && if4_bp.taken && if4_cfi_jal_tgt =/= bpu.io.out(2).target 229 230 if4_prevHalfInstr := 0.U.asTypeOf(new PrevHalfInstr) 231 when (if4_fire && if4_bp.saveHalfRVI) { 232 if4_prevHalfInstr.valid := true.B 233 if4_prevHalfInstr.taken := if4_bp.taken 234 if4_prevHalfInstr.ghInfo := if4_GHInfo 235 // Make sure shifted can work 236 if4_prevHalfInstr.ghInfo.saveHalfRVI := false.B 237 if4_prevHalfInstr.newPtr := if4_newPtr 238 if4_prevHalfInstr.fetchpc := if4_pc 239 if4_prevHalfInstr.idx := PopCount(mask(if4_pc)) - 1.U 240 if4_prevHalfInstr.pc := if4_pd.pc(if4_prevHalfInstr.idx) 241 if4_prevHalfInstr.target := if4_bp.target 242 if4_prevHalfInstr.instr := if4_pd.instrs(if4_prevHalfInstr.idx)(15, 0) 243 if4_prevHalfInstr.ipf := if4_ipf 244 } 245 246 when (if3_hasPrevHalfInstr && if3_fire && prevHalfInstr.taken) { 247 if4_takenPrevHalf := true.B 248 }.elsewhen (if4_fire || if4_flush) { 249 if4_takenPrevHalf := false.B 250 } 251 252 // Redirect and npc logic for if4 253 when (if4_fire && if4_bp.redirect) { 254 if4_redirect := true.B 255 when (if4_bp.saveHalfRVI) { 256 if1_npc := snpc(if4_pc) 257 }.otherwise { 258 if1_npc := if4_bp.target 259 } 260 } 261 262 // This should cover the if4 redirect to snpc when saveHalfRVI 263 when (if3_redirect) { 264 when (if3_hasPrevHalfInstr && prevHalfInstr.taken) { 265 if1_npc := prevHalfInstr.target 266 } 267 } 268 269 // history logic for if4 270 when (if4_fire && if4_bp.redirect) { 271 shiftPtr := true.B 272 newPtr := if4_newPtr 273 } 274 275 when (if4_GHInfo.shifted && if4_newPtr >= ptr) { 276 hist(if4_newPtr-ptr) := if4_GHInfo.takenOnBr 277 } 278 279 when (if3_redirect) { 280 // when redirect and if3_hasPrevHalfInstr, this prevHalfInstr should only be taken 281 when (if3_hasPrevHalfInstr && prevHalfInstr.ghInfo.shifted) { 282 shiftPtr := true.B 283 newPtr := prevHalfInstr.newPtr 284 extHist(prevHalfInstr.newPtr) := prevHalfInstr.ghInfo.takenOnBr 285 } 286 } 287 288 // modify GHR at the end of a prediction lifetime 289 when (if4_fire && if4_GHInfo.shifted) { 290 extHist(if4_newPtr) := if4_GHInfo.takenOnBr 291 } 292 293 // This is a histPtr which is only modified when a prediction 294 // is sent, so that it can get the final prediction info 295 val finalPredHistPtr = RegInit(0.U(log2Up(ExtHistoryLength).W)) 296 if4_histPtr := finalPredHistPtr 297 if4_newPtr := if3_histPtr 298 when (if4_fire && if4_GHInfo.shifted) { 299 finalPredHistPtr := if4_newPtr 300 } 301 302 if3_histPtr := Mux(if4_GHInfo.shifted && if4_valid && !if4_flush, if4_histPtr - 1.U, if4_histPtr) 303 if3_newPtr := if2_histPtr 304 305 if2_histPtr := Mux(if3_GHInfo.shifted && if3_valid && !if3_flush, if3_histPtr - 1.U, if3_histPtr) 306 if2_newPtr := if1_histPtr 307 308 if1_histPtr := Mux(if2_GHInfo.shifted && if2_valid && !if2_flush, if2_histPtr - 1.U, if2_histPtr) 309 310 311 312 313 when (io.outOfOrderBrInfo.valid && io.outOfOrderBrInfo.bits.isMisPred) { 314 val b = io.outOfOrderBrInfo.bits 315 val oldPtr = b.brInfo.histPtr 316 shiftPtr := true.B 317 when (!b.pd.isBr && !b.brInfo.sawNotTakenBranch) { 318 // If mispredicted cfi is not a branch, 319 // and there wasn't any not taken branch before it, 320 // we should only recover the pointer to an unshifted state 321 newPtr := oldPtr 322 finalPredHistPtr := oldPtr 323 }.otherwise { 324 newPtr := oldPtr - 1.U 325 finalPredHistPtr := oldPtr - 1.U 326 hist(0) := Mux(b.pd.isBr, b.taken, 0.U) 327 extHist(newPtr) := Mux(b.pd.isBr, b.taken, 0.U) 328 } 329 } 330 331 when (loopBufPar.LBredirect.valid) { 332 if1_npc := loopBufPar.LBredirect.bits 333 } 334 335 when (io.redirect.valid) { 336 if1_npc := io.redirect.bits.target 337 } 338 339 when(inLoop) { 340 io.icacheReq.valid := if4_flush 341 }.otherwise { 342 io.icacheReq.valid := if1_valid && if2_ready 343 } 344 io.icacheResp.ready := if4_ready 345 io.icacheReq.bits.addr := if1_npc 346 347 // when(if4_bp.taken) { 348 // when(if4_bp.saveHalfRVI) { 349 // io.loopBufPar.LBReq := snpc(if4_pc) 350 // }.otherwise { 351 // io.loopBufPar.LBReq := if4_bp.target 352 // } 353 // }.otherwise { 354 // io.loopBufPar.LBReq := snpc(if4_pc) 355 // XSDebug(p"snpc(if4_pc)=${Hexadecimal(snpc(if4_pc))}\n") 356 // } 357 loopBufPar.fetchReq := if3_pc 358 359 io.icacheReq.bits.mask := mask(if1_npc) 360 361 io.icacheFlush := Cat(if3_flush, if2_flush) 362 363 val inOrderBrHist = Wire(Vec(HistoryLength, UInt(1.W))) 364 (0 until HistoryLength).foreach(i => inOrderBrHist(i) := extHist(i.U + io.inOrderBrInfo.bits.brInfo.predHistPtr)) 365 bpu.io.inOrderBrInfo.valid := io.inOrderBrInfo.valid 366 bpu.io.inOrderBrInfo.bits := BranchUpdateInfoWithHist(io.inOrderBrInfo.bits, inOrderBrHist.asUInt) 367 bpu.io.outOfOrderBrInfo.valid := io.outOfOrderBrInfo.valid 368 bpu.io.outOfOrderBrInfo.bits := BranchUpdateInfoWithHist(io.outOfOrderBrInfo.bits, inOrderBrHist.asUInt) // Dont care about hist 369 370 // bpu.io.flush := Cat(if4_flush, if3_flush, if2_flush) 371 bpu.io.flush := VecInit(if2_flush, if3_flush, if4_flush) 372 bpu.io.inFire(0) := if1_fire 373 bpu.io.inFire(1) := if2_fire 374 bpu.io.inFire(2) := if3_fire 375 bpu.io.inFire(3) := if4_fire 376 bpu.io.stageValid(0) := if2_valid 377 bpu.io.stageValid(1) := if3_valid 378 bpu.io.stageValid(2) := if4_valid 379 bpu.io.in.pc := if1_npc 380 bpu.io.in.hist := hist.asUInt 381 bpu.io.in.histPtr := ptr 382 bpu.io.in.inMask := mask(if1_npc) 383 bpu.io.predecode.mask := if4_pd.mask 384 bpu.io.predecode.pd := if4_pd.pd 385 bpu.io.predecode.isFetchpcEqualFirstpc := if4_pc === if4_pd.pc(0) 386 387 pd.io.in := icacheResp 388 when(inLoop) { 389 pd.io.in.mask := loopBuffer.io.out.bits.mask & mask(loopBuffer.io.out.bits.pc) // TODO: Maybe this is unnecessary 390 // XSDebug("Fetch from LB\n") 391 // XSDebug(p"pc=${Hexadecimal(io.loopBufPar.LBResp.pc)}\n") 392 // XSDebug(p"data=${Hexadecimal(io.loopBufPar.LBResp.data)}\n") 393 // XSDebug(p"mask=${Hexadecimal(io.loopBufPar.LBResp.mask)}\n") 394 } 395 396 pd.io.prev.valid := if3_hasPrevHalfInstr 397 pd.io.prev.bits := prevHalfInstr.instr 398 // if a fetch packet triggers page fault, set the pf instruction to nop 399 when (!if3_hasPrevHalfInstr && icacheResp.ipf) { 400 val instrs = Wire(Vec(FetchWidth, UInt(32.W))) 401 (0 until FetchWidth).foreach(i => instrs(i) := ZeroExt("b0010011".U, 32)) // nop 402 pd.io.in.data := instrs.asUInt 403 }.elsewhen (if3_hasPrevHalfInstr && (prevHalfInstr.ipf || icacheResp.ipf)) { 404 pd.io.prev.bits := ZeroExt("b0010011".U, 16) 405 val instrs = Wire(Vec(FetchWidth, UInt(32.W))) 406 (0 until FetchWidth).foreach(i => instrs(i) := Cat(ZeroExt("b0010011".U, 16), Fill(16, 0.U(1.W)))) 407 pd.io.in.data := instrs.asUInt 408 409 when (icacheResp.ipf && !prevHalfInstr.ipf) { crossPageIPF := true.B } // higher 16 bits page fault 410 } 411 412 //Performance Counter 413 // if (!env.FPGAPlatform ) { 414 // ExcitingUtils.addSource(io.fetchPacket.fire && !inLoop, "CntFetchFromICache", Perf) 415 // ExcitingUtils.addSource(io.fetchPacket.fire && inLoop, "CntFetchFromLoopBuffer", Perf) 416 // } 417 418 val fetchPacketValid = if4_valid && !io.redirect.valid 419 val fetchPacketWire = Wire(new FetchPacket) 420 421 // io.fetchPacket.valid := if4_valid && !io.redirect.valid 422 fetchPacketWire.instrs := if4_pd.instrs 423 fetchPacketWire.mask := Mux(if4_takenPrevHalf, 424 1.U(PredictWidth.W), 425 if4_pd.mask & (Fill(PredictWidth, !if4_bp.taken) | (Fill(PredictWidth, 1.U(1.W)) >> (~if4_bp.jmpIdx)))) 426 427 loopBufPar.noTakenMask := if4_pd.mask 428 fetchPacketWire.pc := if4_pd.pc 429 (0 until PredictWidth).foreach(i => fetchPacketWire.pnpc(i) := if4_pd.pc(i) + Mux(if4_pd.pd(i).isRVC, 2.U, 4.U)) 430 when (if4_bp.taken) { 431 fetchPacketWire.pnpc(if4_bp.jmpIdx) := if4_bp.target 432 } 433 fetchPacketWire.brInfo := bpu.io.branchInfo 434 (0 until PredictWidth).foreach(i => fetchPacketWire.brInfo(i).histPtr := finalPredHistPtr) 435 (0 until PredictWidth).foreach(i => fetchPacketWire.brInfo(i).predHistPtr := if4_predHistPtr) 436 fetchPacketWire.pd := if4_pd.pd 437 fetchPacketWire.ipf := if4_ipf 438 fetchPacketWire.crossPageIPFFix := if4_crossPageIPF 439 440 // predTaken Vec 441 fetchPacketWire.predTaken := if4_bp.taken 442 443 loopBuffer.io.in.bits := fetchPacketWire 444 io.fetchPacket.bits := fetchPacketWire 445 io.fetchPacket.valid := fetchPacketValid 446 loopBuffer.io.in.valid := io.fetchPacket.fire 447 448 // debug info 449 if (IFUDebug) { 450 XSDebug(RegNext(reset.asBool) && !reset.asBool, "Reseting...\n") 451 XSDebug(io.icacheFlush(0).asBool, "Flush icache stage2...\n") 452 XSDebug(io.icacheFlush(1).asBool, "Flush icache stage3...\n") 453 XSDebug(io.redirect.valid, "Redirect from backend! isExcp=%d isFpp:%d isMisPred=%d isReplay=%d pc=%x\n", 454 io.redirect.bits.isException, io.redirect.bits.isFlushPipe, io.redirect.bits.isMisPred, io.redirect.bits.isReplay, io.redirect.bits.pc) 455 XSDebug(io.redirect.valid, p"Redirect from backend! target=${Hexadecimal(io.redirect.bits.target)} brTag=${io.redirect.bits.brTag}\n") 456 457 XSDebug("[IF1] v=%d fire=%d flush=%d pc=%x ptr=%d mask=%b\n", if1_valid, if1_fire, if1_flush, if1_npc, ptr, mask(if1_npc)) 458 XSDebug("[IF2] v=%d r=%d fire=%d redirect=%d flush=%d pc=%x ptr=%d snpc=%x\n", if2_valid, if2_ready, if2_fire, if2_redirect, if2_flush, if2_pc, if2_histPtr, if2_snpc) 459 XSDebug("[IF3] v=%d r=%d fire=%d redirect=%d flush=%d pc=%x ptr=%d crossPageIPF=%d sawNTBrs=%d\n", if3_valid, if3_ready, if3_fire, if3_redirect, if3_flush, if3_pc, if3_histPtr, crossPageIPF, if3_GHInfo.sawNTBr) 460 XSDebug("[IF4] v=%d r=%d fire=%d redirect=%d flush=%d pc=%x ptr=%d crossPageIPF=%d sawNTBrs=%d\n", if4_valid, if4_ready, if4_fire, if4_redirect, if4_flush, if4_pc, if4_histPtr, if4_crossPageIPF, if4_GHInfo.sawNTBr) 461 XSDebug("[IF1][icacheReq] v=%d r=%d addr=%x\n", io.icacheReq.valid, io.icacheReq.ready, io.icacheReq.bits.addr) 462 XSDebug("[IF1][ghr] headPtr=%d shiftPtr=%d newPtr=%d ptr=%d\n", if1_histPtr, shiftPtr, newPtr, ptr) 463 XSDebug("[IF1][ghr] hist=%b\n", hist.asUInt) 464 XSDebug("[IF1][ghr] extHist=%b\n\n", extHist.asUInt) 465 466 XSDebug("[IF2][bp] redirect=%d taken=%d jmpIdx=%d hasNTBrs=%d target=%x saveHalfRVI=%d\n\n", if2_bp.redirect, if2_bp.taken, if2_bp.jmpIdx, if2_bp.hasNotTakenBrs, if2_bp.target, if2_bp.saveHalfRVI) 467 if2_GHInfo.debug 468 469 XSDebug("[IF3][icacheResp] v=%d r=%d pc=%x mask=%b\n", io.icacheResp.valid, io.icacheResp.ready, io.icacheResp.bits.pc, io.icacheResp.bits.mask) 470 XSDebug("[IF3][bp] redirect=%d taken=%d jmpIdx=%d hasNTBrs=%d target=%x saveHalfRVI=%d\n", if3_bp.redirect, if3_bp.taken, if3_bp.jmpIdx, if3_bp.hasNotTakenBrs, if3_bp.target, if3_bp.saveHalfRVI) 471 // XSDebug("[IF3][prevHalfInstr] v=%d redirect=%d fetchpc=%x idx=%d tgt=%x taken=%d instr=%x\n\n", 472 // prev_half_valid, prev_half_redirect, prev_half_fetchpc, prev_half_idx, prev_half_tgt, prev_half_taken, prev_half_instr) 473 XSDebug("[IF3][ prevHalfInstr] v=%d taken=%d fetchpc=%x idx=%d pc=%x tgt=%x instr=%x ipf=%d\n", 474 prevHalfInstr.valid, prevHalfInstr.taken, prevHalfInstr.fetchpc, prevHalfInstr.idx, prevHalfInstr.pc, prevHalfInstr.target, prevHalfInstr.instr, prevHalfInstr.ipf) 475 XSDebug("[IF3][if3_prevHalfInstr] v=%d taken=%d fetchpc=%x idx=%d pc=%x tgt=%x instr=%x ipf=%d\n\n", 476 if3_prevHalfInstr.valid, if3_prevHalfInstr.taken, if3_prevHalfInstr.fetchpc, if3_prevHalfInstr.idx, if3_prevHalfInstr.pc, if3_prevHalfInstr.target, if3_prevHalfInstr.instr, if3_prevHalfInstr.ipf) 477 if3_GHInfo.debug 478 479 XSDebug("[IF4][predecode] mask=%b\n", if4_pd.mask) 480 XSDebug("[IF4][bp] redirect=%d taken=%d jmpIdx=%d hasNTBrs=%d target=%x saveHalfRVI=%d\n", if4_bp.redirect, if4_bp.taken, if4_bp.jmpIdx, if4_bp.hasNotTakenBrs, if4_bp.target, if4_bp.saveHalfRVI) 481 XSDebug(if4_pd.pd(if4_bp.jmpIdx).isJal && if4_bp.taken, "[IF4] cfi is jal! instr=%x target=%x\n", if4_cfi_jal, if4_cfi_jal_tgt) 482 XSDebug("[IF4][if4_prevHalfInstr] v=%d taken=%d fetchpc=%x idx=%d pc=%x tgt=%x instr=%x ipf=%d\n", 483 if4_prevHalfInstr.valid, if4_prevHalfInstr.taken, if4_prevHalfInstr.fetchpc, if4_prevHalfInstr.idx, if4_prevHalfInstr.pc, if4_prevHalfInstr.target, if4_prevHalfInstr.instr, if4_prevHalfInstr.ipf) 484 if4_GHInfo.debug 485 XSDebug(io.fetchPacket.fire(), "[IF4][fetchPacket] v=%d r=%d mask=%b ipf=%d crossPageIPF=%d\n", 486 io.fetchPacket.valid, io.fetchPacket.ready, io.fetchPacket.bits.mask, io.fetchPacket.bits.ipf, io.fetchPacket.bits.crossPageIPFFix) 487 for (i <- 0 until PredictWidth) { 488 XSDebug(io.fetchPacket.fire(), "[IF4][fetchPacket] %b %x pc=%x pnpc=%x pd: rvc=%d brType=%b call=%d ret=%d\n", 489 io.fetchPacket.bits.mask(i), 490 io.fetchPacket.bits.instrs(i), 491 io.fetchPacket.bits.pc(i), 492 io.fetchPacket.bits.pnpc(i), 493 io.fetchPacket.bits.pd(i).isRVC, 494 io.fetchPacket.bits.pd(i).brType, 495 io.fetchPacket.bits.pd(i).isCall, 496 io.fetchPacket.bits.pd(i).isRet 497 ) 498 } 499 } 500}