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