2016-11-28 01:16:37 +01:00
|
|
|
// See LICENSE.Berkeley for license details.
|
|
|
|
// See LICENSE.SiFive for license details.
|
2014-09-13 03:06:41 +02:00
|
|
|
|
2014-03-25 13:22:04 +01:00
|
|
|
package rocket
|
|
|
|
|
|
|
|
import Chisel._
|
2016-11-18 23:05:14 +01:00
|
|
|
import config._
|
2016-09-28 06:27:07 +02:00
|
|
|
import util._
|
2016-09-29 01:10:32 +02:00
|
|
|
import Chisel.ImplicitConversions._
|
2016-11-22 20:50:41 +01:00
|
|
|
import uncore.util.PseudoLRU
|
2014-03-25 13:22:04 +01:00
|
|
|
|
2015-10-06 06:48:05 +02:00
|
|
|
case object BtbKey extends Field[BtbParameters]
|
2015-10-17 04:11:57 +02:00
|
|
|
|
|
|
|
case class BtbParameters(
|
2016-09-07 10:51:27 +02:00
|
|
|
nEntries: Int = 40,
|
2015-10-17 04:11:57 +02:00
|
|
|
nRAS: Int = 2,
|
|
|
|
updatesOutOfOrder: Boolean = false)
|
2015-10-06 06:48:05 +02:00
|
|
|
|
|
|
|
abstract trait HasBtbParameters extends HasCoreParameters {
|
2015-10-07 03:20:19 +02:00
|
|
|
val matchBits = pgIdxBits
|
2015-10-06 06:48:05 +02:00
|
|
|
val entries = p(BtbKey).nEntries
|
|
|
|
val nRAS = p(BtbKey).nRAS
|
|
|
|
val updatesOutOfOrder = p(BtbKey).updatesOutOfOrder
|
2014-08-12 03:36:23 +02:00
|
|
|
val nPages = ((1 max(log2Up(entries)))+1)/2*2 // control logic assumes 2 divides pages
|
|
|
|
val opaqueBits = log2Up(entries)
|
|
|
|
val nBHT = 1 << log2Up(entries*2)
|
|
|
|
}
|
2014-04-08 00:58:49 +02:00
|
|
|
|
2015-10-06 06:48:05 +02:00
|
|
|
abstract class BtbModule(implicit val p: Parameters) extends Module with HasBtbParameters
|
|
|
|
abstract class BtbBundle(implicit val p: Parameters) extends ParameterizedBundle()(p)
|
|
|
|
with HasBtbParameters
|
|
|
|
|
2014-08-08 21:23:02 +02:00
|
|
|
class RAS(nras: Int) {
|
2014-04-08 00:58:49 +02:00
|
|
|
def push(addr: UInt): Unit = {
|
2014-08-08 21:23:02 +02:00
|
|
|
when (count < nras) { count := count + 1 }
|
2015-01-30 00:29:25 +01:00
|
|
|
val nextPos = Mux(Bool(isPow2(nras)) || pos < nras-1, pos+1, UInt(0))
|
2014-04-08 00:58:49 +02:00
|
|
|
stack(nextPos) := addr
|
|
|
|
pos := nextPos
|
|
|
|
}
|
|
|
|
def peek: UInt = stack(pos)
|
2016-07-02 23:27:29 +02:00
|
|
|
def pop(): Unit = when (!isEmpty) {
|
2014-04-08 00:58:49 +02:00
|
|
|
count := count - 1
|
2014-08-08 21:23:02 +02:00
|
|
|
pos := Mux(Bool(isPow2(nras)) || pos > 0, pos-1, UInt(nras-1))
|
2014-04-08 00:58:49 +02:00
|
|
|
}
|
2016-07-02 23:27:29 +02:00
|
|
|
def clear(): Unit = count := UInt(0)
|
2014-04-08 00:58:49 +02:00
|
|
|
def isEmpty: Bool = count === UInt(0)
|
|
|
|
|
2016-07-02 23:27:29 +02:00
|
|
|
private val count = Reg(UInt(width = log2Up(nras+1)))
|
|
|
|
private val pos = Reg(UInt(width = log2Up(nras)))
|
2016-01-14 22:57:45 +01:00
|
|
|
private val stack = Reg(Vec(nras, UInt()))
|
2014-04-08 00:58:49 +02:00
|
|
|
}
|
|
|
|
|
2015-10-06 06:48:05 +02:00
|
|
|
class BHTResp(implicit p: Parameters) extends BtbBundle()(p) {
|
2014-09-20 00:05:45 +02:00
|
|
|
val history = UInt(width = log2Up(nBHT).max(1))
|
2014-04-08 00:58:49 +02:00
|
|
|
val value = UInt(width = 2)
|
|
|
|
}
|
|
|
|
|
2014-10-03 13:22:58 +02:00
|
|
|
// BHT contains table of 2-bit counters and a global history register.
|
|
|
|
// The BHT only predicts and updates when there is a BTB hit.
|
|
|
|
// The global history:
|
|
|
|
// - updated speculatively in fetch (if there's a BTB hit).
|
|
|
|
// - on a mispredict, the history register is reset (again, only if BTB hit).
|
|
|
|
// The counter table:
|
2014-11-17 07:02:27 +01:00
|
|
|
// - each counter corresponds with the address of the fetch packet ("fetch pc").
|
2014-10-04 01:08:08 +02:00
|
|
|
// - updated when a branch resolves (and BTB was a hit for that branch).
|
2014-10-15 03:10:29 +02:00
|
|
|
// The updating branch must provide its "fetch pc".
|
2016-07-29 23:59:04 +02:00
|
|
|
class BHT(nbht: Int)(implicit val p: Parameters) extends HasCoreParameters {
|
2014-09-26 19:39:57 +02:00
|
|
|
val nbhtbits = log2Up(nbht)
|
2014-09-30 06:41:07 +02:00
|
|
|
def get(addr: UInt, update: Bool): BHTResp = {
|
2015-07-16 05:24:18 +02:00
|
|
|
val res = Wire(new BHTResp)
|
2016-07-29 23:59:04 +02:00
|
|
|
val index = addr(nbhtbits+1, log2Up(coreInstBytes)) ^ history
|
2014-10-04 01:08:08 +02:00
|
|
|
res.value := table(index)
|
2014-09-28 14:16:36 +02:00
|
|
|
res.history := history
|
2014-09-30 06:41:07 +02:00
|
|
|
val taken = res.value(0)
|
|
|
|
when (update) { history := Cat(taken, history(nbhtbits-1,1)) }
|
2014-04-08 00:58:49 +02:00
|
|
|
res
|
|
|
|
}
|
2014-11-17 07:02:27 +01:00
|
|
|
def update(addr: UInt, d: BHTResp, taken: Bool, mispredict: Bool): Unit = {
|
2016-07-29 23:59:04 +02:00
|
|
|
val index = addr(nbhtbits+1, log2Up(coreInstBytes)) ^ d.history
|
2014-10-04 01:08:08 +02:00
|
|
|
table(index) := Cat(taken, (d.value(1) & d.value(0)) | ((d.value(1) | d.value(0)) & taken))
|
2014-11-17 07:02:27 +01:00
|
|
|
when (mispredict) { history := Cat(taken, d.history(nbhtbits-1,1)) }
|
2014-04-08 00:58:49 +02:00
|
|
|
}
|
|
|
|
|
2015-09-30 23:36:26 +02:00
|
|
|
private val table = Mem(nbht, UInt(width = 2))
|
2014-08-08 21:23:02 +02:00
|
|
|
val history = Reg(UInt(width = nbhtbits))
|
2014-04-02 00:01:27 +02:00
|
|
|
}
|
|
|
|
|
2014-11-11 12:34:05 +01:00
|
|
|
// BTB update occurs during branch resolution (and only on a mispredict).
|
2014-09-17 23:24:03 +02:00
|
|
|
// - "pc" is what future fetch PCs will tag match against.
|
|
|
|
// - "br_pc" is the PC of the branch instruction.
|
2015-10-06 06:48:05 +02:00
|
|
|
class BTBUpdate(implicit p: Parameters) extends BtbBundle()(p) {
|
2014-04-02 00:01:27 +02:00
|
|
|
val prediction = Valid(new BTBResp)
|
2014-08-12 03:36:23 +02:00
|
|
|
val pc = UInt(width = vaddrBits)
|
|
|
|
val target = UInt(width = vaddrBits)
|
2014-04-02 00:01:27 +02:00
|
|
|
val taken = Bool()
|
2016-07-30 00:01:05 +02:00
|
|
|
val isValid = Bool()
|
2014-04-08 00:58:49 +02:00
|
|
|
val isJump = Bool()
|
2014-04-02 00:01:27 +02:00
|
|
|
val isReturn = Bool()
|
2014-09-17 23:24:03 +02:00
|
|
|
val br_pc = UInt(width = vaddrBits)
|
2014-04-02 00:01:27 +02:00
|
|
|
}
|
|
|
|
|
2014-11-17 07:02:27 +01:00
|
|
|
// BHT update occurs during branch resolution on all conditional branches.
|
|
|
|
// - "pc" is what future fetch PCs will tag match against.
|
2015-10-06 06:48:05 +02:00
|
|
|
class BHTUpdate(implicit p: Parameters) extends BtbBundle()(p) {
|
2014-11-17 07:02:27 +01:00
|
|
|
val prediction = Valid(new BTBResp)
|
|
|
|
val pc = UInt(width = vaddrBits)
|
|
|
|
val taken = Bool()
|
|
|
|
val mispredict = Bool()
|
|
|
|
}
|
|
|
|
|
2015-10-06 06:48:05 +02:00
|
|
|
class RASUpdate(implicit p: Parameters) extends BtbBundle()(p) {
|
2014-11-11 12:34:05 +01:00
|
|
|
val isCall = Bool()
|
|
|
|
val isReturn = Bool()
|
|
|
|
val returnAddr = UInt(width = vaddrBits)
|
|
|
|
val prediction = Valid(new BTBResp)
|
|
|
|
}
|
|
|
|
|
|
|
|
// - "bridx" is the low-order PC bits of the predicted branch (after
|
2014-11-17 07:02:27 +01:00
|
|
|
// shifting off the lowest log(inst_bytes) bits off).
|
2016-03-26 13:37:26 +01:00
|
|
|
// - "mask" provides a mask of valid instructions (instructions are
|
|
|
|
// masked off by the predicted taken branch from the BTB).
|
2015-10-06 06:48:05 +02:00
|
|
|
class BTBResp(implicit p: Parameters) extends BtbBundle()(p) {
|
2014-04-02 00:01:27 +02:00
|
|
|
val taken = Bool()
|
2015-10-06 06:48:05 +02:00
|
|
|
val mask = Bits(width = fetchWidth)
|
|
|
|
val bridx = Bits(width = log2Up(fetchWidth))
|
2014-08-12 03:36:23 +02:00
|
|
|
val target = UInt(width = vaddrBits)
|
|
|
|
val entry = UInt(width = opaqueBits)
|
2014-04-08 00:58:49 +02:00
|
|
|
val bht = new BHTResp
|
2014-04-02 00:01:27 +02:00
|
|
|
}
|
|
|
|
|
2015-10-06 06:48:05 +02:00
|
|
|
class BTBReq(implicit p: Parameters) extends BtbBundle()(p) {
|
2014-09-30 06:41:07 +02:00
|
|
|
val addr = UInt(width = vaddrBits)
|
|
|
|
}
|
|
|
|
|
2014-03-25 13:22:04 +01:00
|
|
|
// fully-associative branch target buffer
|
2014-11-11 12:34:05 +01:00
|
|
|
// Higher-performance processors may cause BTB updates to occur out-of-order,
|
|
|
|
// which requires an extra CAM port for updates (to ensure no duplicates get
|
|
|
|
// placed in BTB).
|
2015-10-06 06:48:05 +02:00
|
|
|
class BTB(implicit p: Parameters) extends BtbModule {
|
2014-03-25 13:22:04 +01:00
|
|
|
val io = new Bundle {
|
2014-09-30 06:41:07 +02:00
|
|
|
val req = Valid(new BTBReq).flip
|
2014-04-02 00:01:27 +02:00
|
|
|
val resp = Valid(new BTBResp)
|
2014-11-17 07:02:27 +01:00
|
|
|
val btb_update = Valid(new BTBUpdate).flip
|
|
|
|
val bht_update = Valid(new BHTUpdate).flip
|
2014-11-11 12:34:05 +01:00
|
|
|
val ras_update = Valid(new RASUpdate).flip
|
2014-03-25 13:22:04 +01:00
|
|
|
}
|
|
|
|
|
2016-07-15 02:10:27 +02:00
|
|
|
val idxs = Reg(Vec(entries, UInt(width=matchBits - log2Up(coreInstBytes))))
|
2016-07-02 23:27:29 +02:00
|
|
|
val idxPages = Reg(Vec(entries, UInt(width=log2Up(nPages))))
|
2016-07-15 02:10:27 +02:00
|
|
|
val tgts = Reg(Vec(entries, UInt(width=matchBits - log2Up(coreInstBytes))))
|
2016-07-02 23:27:29 +02:00
|
|
|
val tgtPages = Reg(Vec(entries, UInt(width=log2Up(nPages))))
|
2016-07-15 02:10:27 +02:00
|
|
|
val pages = Reg(Vec(nPages, UInt(width=vaddrBits - matchBits)))
|
2016-07-07 00:54:33 +02:00
|
|
|
val pageValid = Reg(init = UInt(0, nPages))
|
2014-08-12 03:36:23 +02:00
|
|
|
val idxPagesOH = idxPages.map(UIntToOH(_)(nPages-1,0))
|
|
|
|
val tgtPagesOH = tgtPages.map(UIntToOH(_)(nPages-1,0))
|
2014-04-02 00:01:27 +02:00
|
|
|
|
2016-07-30 00:01:05 +02:00
|
|
|
val isValid = Reg(init = UInt(0, entries))
|
|
|
|
val isReturn = Reg(UInt(width = entries))
|
2016-07-02 23:27:29 +02:00
|
|
|
val isJump = Reg(UInt(width = entries))
|
2016-07-15 02:10:27 +02:00
|
|
|
val brIdx = Reg(Vec(entries, UInt(width=log2Up(fetchWidth))))
|
2014-03-25 13:22:04 +01:00
|
|
|
|
2014-08-12 03:36:23 +02:00
|
|
|
private def page(addr: UInt) = addr >> matchBits
|
2014-03-25 13:22:04 +01:00
|
|
|
private def pageMatch(addr: UInt) = {
|
|
|
|
val p = page(addr)
|
2016-08-01 02:13:52 +02:00
|
|
|
pageValid & pages.map(_ === p).asUInt
|
2014-03-25 13:22:04 +01:00
|
|
|
}
|
2015-07-31 13:59:45 +02:00
|
|
|
private def tagMatch(addr: UInt, pgMatch: UInt) = {
|
2016-08-01 02:13:52 +02:00
|
|
|
val idxMatch = idxs.map(_ === addr(matchBits-1, log2Up(coreInstBytes))).asUInt
|
|
|
|
val idxPageMatch = idxPagesOH.map(_ & pgMatch).map(_.orR).asUInt
|
2016-07-30 00:01:05 +02:00
|
|
|
idxMatch & idxPageMatch & isValid
|
2014-03-25 13:22:04 +01:00
|
|
|
}
|
|
|
|
|
2014-11-17 07:02:27 +01:00
|
|
|
val r_btb_update = Pipe(io.btb_update)
|
2014-09-30 06:41:07 +02:00
|
|
|
val update_target = io.req.bits.addr
|
2014-04-02 00:01:27 +02:00
|
|
|
|
2014-09-30 06:41:07 +02:00
|
|
|
val pageHit = pageMatch(io.req.bits.addr)
|
2016-07-02 23:27:29 +02:00
|
|
|
val hitsVec = tagMatch(io.req.bits.addr, pageHit)
|
2016-08-01 02:13:52 +02:00
|
|
|
val hits = hitsVec.asUInt
|
2014-11-17 07:02:27 +01:00
|
|
|
val updatePageHit = pageMatch(r_btb_update.bits.pc)
|
2016-07-07 00:54:33 +02:00
|
|
|
|
2014-11-17 07:02:27 +01:00
|
|
|
val updateHits = tagMatch(r_btb_update.bits.pc, updatePageHit)
|
2016-07-07 00:54:33 +02:00
|
|
|
val updateHit = if (updatesOutOfOrder) updateHits.orR else r_btb_update.bits.prediction.valid
|
|
|
|
val updateHitAddr = if (updatesOutOfOrder) OHToUInt(updateHits) else r_btb_update.bits.prediction.bits.entry
|
2016-09-13 01:52:03 +02:00
|
|
|
|
|
|
|
// we'd prefer PseudoLRU replacement, but it only works for powers of 2
|
|
|
|
val nextRepl =
|
|
|
|
if (!isPow2(entries)) {
|
|
|
|
Counter(r_btb_update.valid && !updateHit, entries)._1
|
|
|
|
} else {
|
|
|
|
val plru = new PseudoLRU(entries)
|
|
|
|
when (hits.orR) { plru.access(OHToUInt(hits)) }
|
|
|
|
plru.replace
|
|
|
|
}
|
2014-03-25 13:22:04 +01:00
|
|
|
|
2014-04-02 00:01:27 +02:00
|
|
|
val useUpdatePageHit = updatePageHit.orR
|
2016-07-02 23:27:29 +02:00
|
|
|
val usePageHit = pageHit.orR
|
2014-11-17 07:02:27 +01:00
|
|
|
val doIdxPageRepl = !useUpdatePageHit
|
2016-07-07 00:54:33 +02:00
|
|
|
val nextPageRepl = Reg(UInt(width = log2Ceil(nPages)))
|
2016-07-06 12:16:05 +02:00
|
|
|
val idxPageRepl = Mux(usePageHit, Cat(pageHit(nPages-2,0), pageHit(nPages-1)), UIntToOH(nextPageRepl))
|
|
|
|
val idxPageUpdateOH = Mux(useUpdatePageHit, updatePageHit, idxPageRepl)
|
2014-04-08 00:58:49 +02:00
|
|
|
val idxPageUpdate = OHToUInt(idxPageUpdateOH)
|
2014-03-25 13:22:04 +01:00
|
|
|
val idxPageReplEn = Mux(doIdxPageRepl, idxPageRepl, UInt(0))
|
|
|
|
|
2014-11-17 07:02:27 +01:00
|
|
|
val samePage = page(r_btb_update.bits.pc) === page(update_target)
|
|
|
|
val doTgtPageRepl = !samePage && !usePageHit
|
2016-07-02 23:27:29 +02:00
|
|
|
val tgtPageRepl = Mux(samePage, idxPageUpdateOH, Cat(idxPageUpdateOH(nPages-2,0), idxPageUpdateOH(nPages-1)))
|
2014-04-08 00:58:49 +02:00
|
|
|
val tgtPageUpdate = OHToUInt(Mux(usePageHit, pageHit, tgtPageRepl))
|
2014-03-25 13:22:04 +01:00
|
|
|
val tgtPageReplEn = Mux(doTgtPageRepl, tgtPageRepl, UInt(0))
|
|
|
|
|
2016-07-02 23:27:29 +02:00
|
|
|
when (r_btb_update.valid && (doIdxPageRepl || doTgtPageRepl)) {
|
|
|
|
val both = doIdxPageRepl && doTgtPageRepl
|
|
|
|
val next = nextPageRepl + Mux[UInt](both, 2, 1)
|
|
|
|
nextPageRepl := Mux(next >= nPages, next(0), next)
|
|
|
|
}
|
2014-04-08 00:58:49 +02:00
|
|
|
|
2016-07-30 00:01:05 +02:00
|
|
|
when (r_btb_update.valid) {
|
|
|
|
val waddr = Mux(updateHit, updateHitAddr, nextRepl)
|
2016-07-07 00:54:33 +02:00
|
|
|
val mask = UIntToOH(waddr)
|
2016-07-30 00:01:05 +02:00
|
|
|
idxs(waddr) := r_btb_update.bits.pc(matchBits-1, log2Up(coreInstBytes))
|
2016-07-15 02:10:27 +02:00
|
|
|
tgts(waddr) := update_target(matchBits-1, log2Up(coreInstBytes))
|
2014-11-11 12:34:05 +01:00
|
|
|
idxPages(waddr) := idxPageUpdate
|
|
|
|
tgtPages(waddr) := tgtPageUpdate
|
2016-07-30 00:01:05 +02:00
|
|
|
isValid := Mux(r_btb_update.bits.isValid, isValid | mask, isValid & ~mask)
|
|
|
|
isReturn := Mux(r_btb_update.bits.isReturn, isReturn | mask, isReturn & ~mask)
|
2016-07-02 23:27:29 +02:00
|
|
|
isJump := Mux(r_btb_update.bits.isJump, isJump | mask, isJump & ~mask)
|
2016-07-05 08:43:25 +02:00
|
|
|
if (fetchWidth > 1)
|
2015-10-06 06:48:05 +02:00
|
|
|
brIdx(waddr) := r_btb_update.bits.br_pc >> log2Up(coreInstBytes)
|
2014-03-25 13:22:04 +01:00
|
|
|
|
2014-08-12 03:36:23 +02:00
|
|
|
require(nPages % 2 == 0)
|
2016-07-02 23:27:29 +02:00
|
|
|
val idxWritesEven = !idxPageUpdate(0)
|
2014-03-25 13:22:04 +01:00
|
|
|
|
2016-07-02 23:27:29 +02:00
|
|
|
def writeBank(i: Int, mod: Int, en: UInt, data: UInt) =
|
2014-08-12 03:36:23 +02:00
|
|
|
for (i <- i until nPages by mod)
|
2016-07-02 23:27:29 +02:00
|
|
|
when (en(i)) { pages(i) := data }
|
2014-05-19 04:25:43 +02:00
|
|
|
|
2016-07-02 23:27:29 +02:00
|
|
|
writeBank(0, 2, Mux(idxWritesEven, idxPageReplEn, tgtPageReplEn),
|
2014-11-17 07:02:27 +01:00
|
|
|
Mux(idxWritesEven, page(r_btb_update.bits.pc), page(update_target)))
|
2016-07-02 23:27:29 +02:00
|
|
|
writeBank(1, 2, Mux(idxWritesEven, tgtPageReplEn, idxPageReplEn),
|
2014-11-17 07:02:27 +01:00
|
|
|
Mux(idxWritesEven, page(update_target), page(r_btb_update.bits.pc)))
|
2016-07-07 00:54:33 +02:00
|
|
|
pageValid := pageValid | tgtPageReplEn | idxPageReplEn
|
2014-03-25 13:22:04 +01:00
|
|
|
}
|
|
|
|
|
2015-07-31 13:59:45 +02:00
|
|
|
io.resp.valid := hits.orR
|
2016-07-30 00:01:05 +02:00
|
|
|
io.resp.bits.taken := true
|
2016-07-15 02:10:27 +02:00
|
|
|
io.resp.bits.target := Cat(Mux1H(Mux1H(hitsVec, tgtPagesOH), pages), Mux1H(hitsVec, tgts) << log2Up(coreInstBytes))
|
2014-04-08 00:58:49 +02:00
|
|
|
io.resp.bits.entry := OHToUInt(hits)
|
2016-07-30 01:36:07 +02:00
|
|
|
io.resp.bits.bridx := (if (fetchWidth > 1) Mux1H(hitsVec, brIdx) else UInt(0))
|
2016-07-05 08:43:25 +02:00
|
|
|
io.resp.bits.mask := Cat((UInt(1) << ~Mux(io.resp.bits.taken, ~io.resp.bits.bridx, UInt(0)))-1, UInt(1))
|
2014-04-08 00:58:49 +02:00
|
|
|
|
2016-10-06 18:41:46 +02:00
|
|
|
// if multiple entries for same PC land in BTB, zap them
|
|
|
|
when (PopCountAtLeast(hits, 2)) {
|
|
|
|
isValid := isValid & ~hits
|
|
|
|
}
|
|
|
|
|
2014-08-12 03:36:23 +02:00
|
|
|
if (nBHT > 0) {
|
2014-10-04 01:08:08 +02:00
|
|
|
val bht = new BHT(nBHT)
|
2016-07-02 23:27:29 +02:00
|
|
|
val isBranch = !(hits & isJump).orR
|
2015-07-30 00:03:01 +02:00
|
|
|
val res = bht.get(io.req.bits.addr, io.req.valid && io.resp.valid && isBranch)
|
2014-11-17 07:02:27 +01:00
|
|
|
val update_btb_hit = io.bht_update.bits.prediction.valid
|
|
|
|
when (io.bht_update.valid && update_btb_hit) {
|
|
|
|
bht.update(io.bht_update.bits.pc, io.bht_update.bits.prediction.bits.bht, io.bht_update.bits.taken, io.bht_update.bits.mispredict)
|
2014-09-26 19:39:57 +02:00
|
|
|
}
|
2015-07-30 00:03:01 +02:00
|
|
|
when (!res.value(0) && isBranch) { io.resp.bits.taken := false }
|
2014-04-08 00:58:49 +02:00
|
|
|
io.resp.bits.bht := res
|
|
|
|
}
|
2014-04-02 00:01:27 +02:00
|
|
|
|
2014-08-12 03:36:23 +02:00
|
|
|
if (nRAS > 0) {
|
|
|
|
val ras = new RAS(nRAS)
|
2016-07-30 00:01:05 +02:00
|
|
|
val doPeek = (hits & isReturn).orR
|
2014-04-08 08:47:53 +02:00
|
|
|
when (!ras.isEmpty && doPeek) {
|
2014-04-08 00:58:49 +02:00
|
|
|
io.resp.bits.target := ras.peek
|
2014-04-02 00:01:27 +02:00
|
|
|
}
|
2014-11-11 12:34:05 +01:00
|
|
|
when (io.ras_update.valid) {
|
|
|
|
when (io.ras_update.bits.isCall) {
|
|
|
|
ras.push(io.ras_update.bits.returnAddr)
|
2014-04-08 08:47:53 +02:00
|
|
|
when (doPeek) {
|
2014-11-11 12:34:05 +01:00
|
|
|
io.resp.bits.target := io.ras_update.bits.returnAddr
|
2014-04-08 08:47:53 +02:00
|
|
|
}
|
2014-11-11 12:34:05 +01:00
|
|
|
}.elsewhen (io.ras_update.bits.isReturn && io.ras_update.bits.prediction.valid) {
|
2016-07-02 23:27:29 +02:00
|
|
|
ras.pop()
|
2014-04-08 00:58:49 +02:00
|
|
|
}
|
2014-04-02 00:01:27 +02:00
|
|
|
}
|
|
|
|
}
|
2014-03-25 13:22:04 +01:00
|
|
|
}
|