xref: /XiangShan/src/main/scala/xiangshan/frontend/IFU.scala (revision 3861072a0e929eaa6de55cc97c8677602b51e1d2)
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 = false
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}
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
50  val if2_redirect, if3_redirect, if4_redirect = WireInit(false.B)
51  val if1_flush, if2_flush, if3_flush, if4_flush = WireInit(false.B)
52
53  if4_flush := io.redirect.valid
54  if3_flush := if4_flush || if4_redirect
55  if2_flush := if3_flush || if3_redirect
56  if1_flush := if2_flush || if2_redirect
57
58  //********************** IF1 ****************************//
59  val if1_valid = !reset.asBool && GTimer() > 500.U
60  val if1_npc = WireInit(0.U(VAddrBits.W))
61  val if2_ready = WireInit(false.B)
62  val if1_fire = if1_valid && (if2_ready || if1_flush) && io.icacheReq.ready
63
64
65  val if1_histPtr, if2_histPtr, if3_histPtr, if4_histPtr = Wire(UInt(log2Up(ExtHistoryLength).W))
66  val if2_newPtr, if3_newPtr, if4_newPtr = Wire(UInt(log2Up(ExtHistoryLength).W))
67
68  val extHist = RegInit(VecInit(Seq.fill(ExtHistoryLength)(0.U(1.W))))
69  val shiftPtr = WireInit(false.B)
70  val newPtr = Wire(UInt(log2Up(ExtHistoryLength).W))
71  val ptr = Mux(shiftPtr, newPtr, if1_histPtr)
72  val hist = Wire(Vec(HistoryLength, UInt(1.W)))
73  for (i <- 0 until HistoryLength) {
74    hist(i) := extHist(ptr + i.U)
75  }
76
77  shiftPtr := false.B
78  newPtr := if1_histPtr
79
80
81
82  val if1_GHInfo = Wire(new GlobalHistoryInfo())
83  if1_GHInfo := 0.U.asTypeOf(new GlobalHistoryInfo)
84
85  //********************** IF2 ****************************//
86  val if2_valid = RegEnable(next = if1_valid, init = false.B, enable = if1_fire)
87  val if3_ready = WireInit(false.B)
88  val if2_fire = if2_valid && if3_ready && !if2_flush
89  val if2_pc = RegEnable(next = if1_npc, init = resetVector.U, enable = if1_fire)
90  val if2_snpc = snpc(if2_pc)
91  val if2_GHInfo = RegEnable(if1_GHInfo, if1_fire)
92  if2_ready := if2_fire || !if2_valid || if2_flush
93  when (if2_flush) { if2_valid := if1_fire }
94  .elsewhen (if1_fire) { if2_valid := if1_valid }
95  .elsewhen (if2_fire) { if2_valid := false.B }
96
97  when (RegNext(reset.asBool) && !reset.asBool) {
98    if1_npc := resetVector.U(VAddrBits.W)
99  }.elsewhen (if2_fire) {
100    if1_npc := if2_snpc
101  }.otherwise {
102    if1_npc := RegNext(if1_npc)
103  }
104
105  val if2_bp = bpu.io.out(0).bits
106  // if taken, bp_redirect should be true
107  // when taken on half RVI, we suppress this redirect signal
108  if2_redirect := if2_fire && bpu.io.out(0).valid && if2_bp.redirect && !if2_bp.saveHalfRVI
109  when (if2_redirect) {
110    if1_npc := if2_bp.target
111  }
112
113  val if2_realGHInfo = Wire(new GlobalHistoryInfo())
114  if2_realGHInfo.sawNTBr     := if2_bp.hasNotTakenBrs
115  if2_realGHInfo.takenOnBr   := if2_bp.takenOnBr
116  if2_realGHInfo.saveHalfRVI := if2_bp.saveHalfRVI
117
118  when (if2_fire && if2_realGHInfo.shifted) {
119    shiftPtr := true.B
120    newPtr := if2_newPtr
121    hist(if2_newPtr-ptr) := if2_realGHInfo.takenOnBr.asUInt
122  }
123
124
125
126  //********************** IF3 ****************************//
127  val if3_valid = RegEnable(next = if2_valid, init = false.B, enable = if2_fire)
128  val if4_ready = WireInit(false.B)
129  val if3_fire = if3_valid && if4_ready && io.icacheResp.valid && !if3_flush
130  val if3_pc = RegEnable(if2_pc, if2_fire)
131  val if3_GHInfo = RegEnable(if2_realGHInfo, if2_fire)
132  if3_ready := if3_fire || !if3_valid || if3_flush
133  when (if3_flush) { if3_valid := false.B }
134  .elsewhen (if2_fire) { if3_valid := if2_valid }
135  .elsewhen (if3_fire) { if3_valid := false.B }
136
137  val if3_bp = bpu.io.out(1).bits
138
139  val if3_realGHInfo = Wire(new GlobalHistoryInfo())
140  if3_realGHInfo.sawNTBr     := if3_bp.hasNotTakenBrs
141  if3_realGHInfo.takenOnBr   := if3_bp.takenOnBr
142  if3_realGHInfo.saveHalfRVI := if3_bp.saveHalfRVI
143
144  class PrevHalfInstr extends Bundle {
145    val valid = Bool()
146    val taken = Bool()
147    val ghInfo = new GlobalHistoryInfo()
148    val fetchpc = UInt(VAddrBits.W) // only for debug
149    val idx = UInt(VAddrBits.W) // only for debug
150    val pc = UInt(VAddrBits.W)
151    val target = UInt(VAddrBits.W)
152    val instr = UInt(16.W)
153    val ipf = Bool()
154    val newPtr = UInt(log2Up(ExtHistoryLength).W)
155  }
156
157  val if3_prevHalfInstr = RegInit(0.U.asTypeOf(new PrevHalfInstr))
158  val if4_prevHalfInstr = Wire(new PrevHalfInstr)
159  // 32-bit instr crosses 2 pages, and the higher 16-bit triggers page fault
160  val crossPageIPF = WireInit(false.B)
161  when (if4_prevHalfInstr.valid) {
162    if3_prevHalfInstr := if4_prevHalfInstr
163  }
164  val prevHalfInstr = Mux(if4_prevHalfInstr.valid, if4_prevHalfInstr, if3_prevHalfInstr)
165
166  // the previous half of RVI instruction waits until it meets its last half
167  val if3_hasPrevHalfInstr = prevHalfInstr.valid && (prevHalfInstr.pc + 2.U) === if3_pc
168  // set to invalid once consumed
169  val prevHalfConsumed = if3_hasPrevHalfInstr && if3_fire
170  when (prevHalfConsumed) {
171    if3_prevHalfInstr.valid := false.B
172  }
173
174  // when bp signal a redirect, we distinguish between taken and not taken
175  // if taken and saveHalfRVI is true, we do not redirect to the target
176  if3_redirect := if3_fire && bpu.io.out(1).valid && (if3_hasPrevHalfInstr && prevHalfInstr.taken || if3_bp.redirect && (if3_bp.taken && !if3_bp.saveHalfRVI || !if3_bp.taken) )
177
178  when (if3_redirect) {
179    when (!(if3_hasPrevHalfInstr && prevHalfInstr.taken)) {
180      if1_npc := if3_bp.target
181      when (if3_realGHInfo.shifted){
182        shiftPtr := true.B
183        newPtr := if3_newPtr
184      }
185    }
186  }
187
188  // when it does not redirect, we still need to modify hist(wire)
189  when(if3_realGHInfo.shifted) {
190    hist(if3_newPtr-ptr) := if3_realGHInfo.takenOnBr
191  }.elsewhen (if3_hasPrevHalfInstr && prevHalfInstr.ghInfo.shifted) {
192    hist(prevHalfInstr.newPtr-ptr) := prevHalfInstr.ghInfo.takenOnBr
193  }
194
195  //********************** IF4 ****************************//
196  val if4_pd = RegEnable(pd.io.out, if3_fire)
197  val if4_ipf = RegEnable(io.icacheResp.bits.ipf || if3_hasPrevHalfInstr && prevHalfInstr.ipf, if3_fire)
198  val if4_crossPageIPF = RegEnable(crossPageIPF, if3_fire)
199  val if4_valid = RegInit(false.B)
200  val if4_fire = if4_valid && io.fetchPacket.ready
201  val if4_pc = RegEnable(if3_pc, if3_fire)
202
203  val if4_GHInfo = RegEnable(if3_realGHInfo, if3_fire)
204  if4_ready := (if4_fire || !if4_valid || if4_flush) && GTimer() > 500.U
205  when (if4_flush)     { if4_valid := false.B }
206  .elsewhen (if3_fire) { if4_valid := if3_valid }
207  .elsewhen(if4_fire)  { if4_valid := false.B }
208
209  val if4_bp = Wire(new BranchPrediction)
210  if4_bp := bpu.io.out(2).bits
211
212  val if4_realGHInfo = Wire(new GlobalHistoryInfo())
213  if4_realGHInfo.sawNTBr     := if4_bp.hasNotTakenBrs
214  if4_realGHInfo.takenOnBr   := if4_bp.takenOnBr
215  if4_realGHInfo.saveHalfRVI := if4_bp.saveHalfRVI
216
217
218  val if4_cfi_jal = if4_pd.instrs(if4_bp.jmpIdx)
219  val if4_cfi_jal_tgt = if4_pd.pc(if4_bp.jmpIdx) + Mux(if4_pd.pd(if4_bp.jmpIdx).isRVC,
220    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),
221    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))
222  if4_bp.target := Mux(if4_pd.pd(if4_bp.jmpIdx).isJal && if4_bp.taken, if4_cfi_jal_tgt, bpu.io.out(2).bits.target)
223  if4_bp.redirect := bpu.io.out(2).bits.redirect || if4_pd.pd(if4_bp.jmpIdx).isJal && if4_bp.taken && if4_cfi_jal_tgt =/= bpu.io.out(2).bits.target
224
225  if4_prevHalfInstr := 0.U.asTypeOf(new PrevHalfInstr)
226  when (bpu.io.out(2).valid && if4_fire && if4_bp.saveHalfRVI) {
227    if4_prevHalfInstr.valid := true.B
228    if4_prevHalfInstr.taken := if4_bp.taken
229    if4_prevHalfInstr.ghInfo := if4_realGHInfo
230    // Make sure shifted can work
231    if4_prevHalfInstr.ghInfo.saveHalfRVI := false.B
232    if4_prevHalfInstr.newPtr := if4_newPtr
233    if4_prevHalfInstr.fetchpc := if4_pc
234    if4_prevHalfInstr.idx := PopCount(mask(if4_pc)) - 1.U
235    if4_prevHalfInstr.pc := if4_pd.pc(if4_prevHalfInstr.idx)
236    if4_prevHalfInstr.target := if4_bp.target
237    if4_prevHalfInstr.instr := if4_pd.instrs(if4_prevHalfInstr.idx)(15, 0)
238    if4_prevHalfInstr.ipf := if4_ipf
239  }
240
241  // Redirect and npc logic for if4
242  when (bpu.io.out(2).valid && if4_fire && if4_bp.redirect) {
243    if4_redirect := true.B
244    when (if4_bp.saveHalfRVI) {
245      if1_npc := snpc(if4_pc)
246    }.otherwise {
247      if1_npc := if4_bp.target
248    }
249  }
250  // }.elsewhen (bpu.io.out(2).valid && if4_fire/* && !if4_bp.redirect*/) {
251  //   // We redirect the pipeline to the next fetch packet,
252  //   // which contains the last half of the RVI instruction
253  //   when (if4_bp.saveHalfRVI && if4_bp.taken) {
254  //     if4_redirect := true.B
255  //     if1_npc := snpc(if4_pc)
256  //   }
257  // }
258
259  // This should cover the if4 redirect to snpc when saveHalfRVI
260  when (if3_redirect) {
261    when (if3_hasPrevHalfInstr && prevHalfInstr.taken) {
262      if1_npc := prevHalfInstr.target
263    }
264  }
265
266  // history logic for if4
267  when (bpu.io.out(2).valid && if4_fire && if4_bp.redirect) {
268    shiftPtr := true.B
269    newPtr := if4_newPtr
270  // }.elsewhen (bpu.io.out(2).valid && if4_fire/* && !if4_bp.redirect*/) {
271  //   // only if we hasn't seen not taken branches and
272  //   // see a not taken branch in if4 should we tell
273  //   // if3 and if4 to update histptr
274  //   // We do not shift global history pointer unless we have the full
275  //   // RVI instruction
276  //   when (if4_newSawNTBrs && !if4_bp.takenOnBr) {
277  //     shiftPtr := true.B
278  //     // newPtr := if4_realGHInfo.newPtr
279  //   }
280  }
281
282  when (if4_realGHInfo.shifted) {
283    hist(if4_newPtr-ptr) := if4_realGHInfo.takenOnBr
284  }
285
286  when (if3_redirect) {
287    // when redirect and if3_hasPrevHalfInstr, this prevHalfInstr should only be taken
288    when (if3_hasPrevHalfInstr && prevHalfInstr.ghInfo.shifted) {
289      shiftPtr := true.B
290      newPtr := prevHalfInstr.newPtr
291      hist(prevHalfInstr.newPtr-ptr) := prevHalfInstr.ghInfo.takenOnBr
292    }
293  }
294
295  // modify GHR at the end of a prediction lifetime
296  when (if4_fire && if4_realGHInfo.shifted) {
297    extHist(if4_newPtr) := if4_realGHInfo.takenOnBr
298  }
299
300  // This is a histPtr which is only modified when a prediction
301  // is sent, so that it can get the final prediction info
302  val if4_predHistPtr = RegInit(0.U(log2Up(ExtHistoryLength).W))
303  if4_histPtr := if4_predHistPtr
304  if4_newPtr  := if3_histPtr
305  when (if4_fire && if4_realGHInfo.shifted) {
306    if4_predHistPtr := if4_newPtr
307  }
308
309  if3_histPtr := Mux(if4_realGHInfo.shifted && if4_valid && !if4_flush, if4_histPtr - 1.U, if4_histPtr)
310  if3_newPtr  := if2_histPtr
311
312  if2_histPtr := Mux(if3_realGHInfo.shifted && if3_valid && !if3_flush, if3_histPtr - 1.U, if3_histPtr)
313  if2_newPtr  := if1_histPtr
314
315  if1_histPtr := Mux(if2_realGHInfo.shifted && if2_valid && !if2_flush, if2_histPtr - 1.U, if2_histPtr)
316
317
318
319
320  when (io.outOfOrderBrInfo.valid && io.outOfOrderBrInfo.bits.isMisPred) {
321    val b = io.outOfOrderBrInfo.bits
322    val oldPtr = b.brInfo.histPtr
323    shiftPtr := true.B
324    when (!b.pd.isBr && !b.brInfo.sawNotTakenBranch) {
325      // If mispredicted cfi is not a branch,
326      // and there wasn't any not taken branch before it,
327      // we should only recover the pointer to an unshifted state
328      newPtr := oldPtr
329      if4_predHistPtr := oldPtr
330    }.otherwise {
331      newPtr := oldPtr - 1.U
332      if4_predHistPtr := oldPtr - 1.U
333      hist(0) := Mux(b.pd.isBr, b.taken, 0.U)
334      extHist(newPtr) := Mux(b.pd.isBr, b.taken, 0.U)
335    }
336  }
337
338  when (io.redirect.valid) {
339    if1_npc := io.redirect.bits.target
340  }
341
342  io.icacheReq.valid := if1_valid && if2_ready
343  io.icacheReq.bits.addr := if1_npc
344  io.icacheReq.bits.mask := mask(if1_npc)
345  io.icacheResp.ready := if4_ready
346  //io.icacheResp.ready := if3_valid
347  io.icacheFlush := Cat(if3_flush, if2_flush)
348
349  val inOrderBrHist = Wire(Vec(HistoryLength, UInt(1.W)))
350  (0 until HistoryLength).foreach(i => inOrderBrHist(i) := extHist(i.U + io.inOrderBrInfo.bits.brInfo.histPtr))
351  bpu.io.inOrderBrInfo.valid := io.inOrderBrInfo.valid
352  bpu.io.inOrderBrInfo.bits := BranchUpdateInfoWithHist(io.inOrderBrInfo.bits, inOrderBrHist.asUInt)
353  bpu.io.outOfOrderBrInfo.valid := io.outOfOrderBrInfo.valid
354  bpu.io.outOfOrderBrInfo.bits := BranchUpdateInfoWithHist(io.outOfOrderBrInfo.bits, inOrderBrHist.asUInt) // Dont care about hist
355
356  // bpu.io.flush := Cat(if4_flush, if3_flush, if2_flush)
357  bpu.io.flush := VecInit(if2_flush, if3_flush, if4_flush)
358  bpu.io.cacheValid := io.icacheResp.valid
359  bpu.io.in.valid := if1_fire
360  bpu.io.in.bits.pc := if1_npc
361  bpu.io.in.bits.hist := hist.asUInt
362  bpu.io.in.bits.inMask := mask(if1_npc)
363  bpu.io.out(0).ready := if2_fire
364  bpu.io.out(1).ready := if3_fire
365  bpu.io.out(2).ready := if4_fire
366  bpu.io.predecode.valid := if4_valid
367  bpu.io.predecode.bits.mask := if4_pd.mask
368  bpu.io.predecode.bits.pd := if4_pd.pd
369  bpu.io.predecode.bits.isFetchpcEqualFirstpc := if4_pc === if4_pd.pc(0)
370  bpu.io.branchInfo.ready := if4_fire
371
372  pd.io.in := io.icacheResp.bits
373  pd.io.prev.valid := if3_hasPrevHalfInstr
374  pd.io.prev.bits := prevHalfInstr.instr
375  // if a fetch packet triggers page fault, set the pf instruction to nop
376  when (!if3_hasPrevHalfInstr && io.icacheResp.bits.ipf) {
377    val instrs = Wire(Vec(FetchWidth, UInt(32.W)))
378    (0 until FetchWidth).foreach(i => instrs(i) := ZeroExt("b0010011".U, 32)) // nop
379    pd.io.in.data := instrs.asUInt
380  }.elsewhen (if3_hasPrevHalfInstr && (prevHalfInstr.ipf || io.icacheResp.bits.ipf)) {
381    pd.io.prev.bits := ZeroExt("b0010011".U, 16)
382    val instrs = Wire(Vec(FetchWidth, UInt(32.W)))
383    (0 until FetchWidth).foreach(i => instrs(i) := Cat(ZeroExt("b0010011".U, 16), Fill(16, 0.U(1.W))))
384    pd.io.in.data := instrs.asUInt
385
386    when (io.icacheResp.bits.ipf && !prevHalfInstr.ipf) { crossPageIPF := true.B } // higher 16 bits page fault
387  }
388
389  io.fetchPacket.valid := if4_valid && !io.redirect.valid
390  io.fetchPacket.bits.instrs := if4_pd.instrs
391  io.fetchPacket.bits.mask := if4_pd.mask & (Fill(PredictWidth, !if4_bp.taken) | (Fill(PredictWidth, 1.U(1.W)) >> (~if4_bp.jmpIdx)))
392  io.fetchPacket.bits.pc := if4_pd.pc
393  (0 until PredictWidth).foreach(i => io.fetchPacket.bits.pnpc(i) := if4_pd.pc(i) + Mux(if4_pd.pd(i).isRVC, 2.U, 4.U))
394  when (if4_bp.taken) {
395    io.fetchPacket.bits.pnpc(if4_bp.jmpIdx) := if4_bp.target
396  }
397  io.fetchPacket.bits.brInfo := bpu.io.branchInfo.bits
398  (0 until PredictWidth).foreach(i => io.fetchPacket.bits.brInfo(i).histPtr := if4_predHistPtr)
399  io.fetchPacket.bits.pd := if4_pd.pd
400  io.fetchPacket.bits.ipf := if4_ipf
401  io.fetchPacket.bits.crossPageIPFFix := if4_crossPageIPF
402
403  // debug info
404  if (IFUDebug) {
405    XSDebug(RegNext(reset.asBool) && !reset.asBool, "Reseting...\n")
406    XSDebug(io.icacheFlush(0).asBool, "Flush icache stage2...\n")
407    XSDebug(io.icacheFlush(1).asBool, "Flush icache stage3...\n")
408    XSDebug(io.redirect.valid, "Redirect from backend! isExcp=%d isFpp:%d isMisPred=%d isReplay=%d pc=%x\n",
409      io.redirect.bits.isException, io.redirect.bits.isFlushPipe, io.redirect.bits.isMisPred, io.redirect.bits.isReplay, io.redirect.bits.pc)
410    XSDebug(io.redirect.valid, p"Redirect from backend! target=${Hexadecimal(io.redirect.bits.target)} brTag=${io.redirect.bits.brTag}\n")
411
412    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))
413    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)
414    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_realGHInfo.sawNTBr)
415    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_realGHInfo.sawNTBr)
416    XSDebug("[IF1][icacheReq] v=%d r=%d addr=%x\n", io.icacheReq.valid, io.icacheReq.ready, io.icacheReq.bits.addr)
417    XSDebug("[IF1][ghr] headPtr=%d shiftPtr=%d newPtr=%d ptr=%d\n", if1_histPtr, shiftPtr, newPtr, ptr)
418    XSDebug("[IF1][ghr] hist=%b\n", hist.asUInt)
419    XSDebug("[IF1][ghr] extHist=%b\n\n", extHist.asUInt)
420
421    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)
422    // XSDebug("[IF2][GHInfo]: %s\n", if2_realGHInfo)
423    if2_realGHInfo.debug
424
425    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)
426    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)
427    // XSDebug("[IF3][prevHalfInstr] v=%d redirect=%d fetchpc=%x idx=%d tgt=%x taken=%d instr=%x\n\n",
428    //   prev_half_valid, prev_half_redirect, prev_half_fetchpc, prev_half_idx, prev_half_tgt, prev_half_taken, prev_half_instr)
429    XSDebug("[IF3][    prevHalfInstr] v=%d taken=%d fetchpc=%x idx=%d pc=%x tgt=%x instr=%x ipf=%d\n",
430      prevHalfInstr.valid, prevHalfInstr.taken, prevHalfInstr.fetchpc, prevHalfInstr.idx, prevHalfInstr.pc, prevHalfInstr.target, prevHalfInstr.instr, prevHalfInstr.ipf)
431    XSDebug("[IF3][if3_prevHalfInstr] v=%d taken=%d fetchpc=%x idx=%d pc=%x tgt=%x instr=%x ipf=%d\n\n",
432      if3_prevHalfInstr.valid, if3_prevHalfInstr.taken, if3_prevHalfInstr.fetchpc, if3_prevHalfInstr.idx, if3_prevHalfInstr.pc, if3_prevHalfInstr.target, if3_prevHalfInstr.instr, if3_prevHalfInstr.ipf)
433    // XSDebug("[IF3][GHInfo]: %s\n", if3_realGHInfo)
434    if3_realGHInfo.debug
435
436    XSDebug("[IF4][predecode] mask=%b\n", if4_pd.mask)
437    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)
438    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)
439    XSDebug("[IF4][if4_prevHalfInstr] v=%d taken=%d fetchpc=%x idx=%d pc=%x tgt=%x instr=%x ipf=%d\n",
440      if4_prevHalfInstr.valid, if4_prevHalfInstr.taken, if4_prevHalfInstr.fetchpc, if4_prevHalfInstr.idx, if4_prevHalfInstr.pc, if4_prevHalfInstr.target, if4_prevHalfInstr.instr, if4_prevHalfInstr.ipf)
441    // XSDebug("[IF4][GHInfo]: %s\n", if4_realGHInfo)
442    if4_realGHInfo.debug
443    XSDebug(io.fetchPacket.fire(), "[IF4][fetchPacket] v=%d r=%d mask=%b ipf=%d crossPageIPF=%d\n",
444      io.fetchPacket.valid, io.fetchPacket.ready, io.fetchPacket.bits.mask, io.fetchPacket.bits.ipf, io.fetchPacket.bits.crossPageIPFFix)
445    for (i <- 0 until PredictWidth) {
446      XSDebug(io.fetchPacket.fire(), "[IF4][fetchPacket] %b %x pc=%x pnpc=%x pd: rvc=%d brType=%b call=%d ret=%d\n",
447        io.fetchPacket.bits.mask(i),
448        io.fetchPacket.bits.instrs(i),
449        io.fetchPacket.bits.pc(i),
450        io.fetchPacket.bits.pnpc(i),
451        io.fetchPacket.bits.pd(i).isRVC,
452        io.fetchPacket.bits.pd(i).brType,
453        io.fetchPacket.bits.pd(i).isCall,
454        io.fetchPacket.bits.pd(i).isRet
455      )
456    }
457  }
458}