Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/scala/xiangshan/XSCore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ case class XSCoreParameters
EnableRAS: Boolean = true,
EnableLB: Boolean = false,
EnableLoop: Boolean = true,
EnableSC: Boolean = false,
EnableSC: Boolean = true,
EnbaleTlbDebug: Boolean = false,
EnableJal: Boolean = false,
EnableUBTB: Boolean = true,
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/xiangshan/frontend/Bim.scala
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ class BIM extends BasePredictor with BimParams {
when (needToUpdate(b)) {
wrbypass_ctr_valids(wrbypass_enq_idx)(b) := true.B
wrbypass_ctrs(wrbypass_enq_idx)(b) := newCtrs(b)
wrbypass_rows(wrbypass_enq_idx) := updateRow
}
}
}
}

when (needToUpdate.reduce(_||_) && !wrbypass_hit) {
wrbypass_rows(wrbypass_enq_idx) := updateRow
wrbypass_enq_idx := (wrbypass_enq_idx + 1.U)(log2Up(bypassEntries)-1,0)
}

Expand Down
9 changes: 4 additions & 5 deletions src/main/scala/xiangshan/frontend/LoopPredictor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,8 @@ class LoopPredictor extends BasePredictor with LTBParams {
val updateValid = io.update.valid
val update = io.update.bits

val do_redirect = RegNext(io.redirect)
val redirectValid = do_redirect.valid
val redirect = do_redirect.bits.cfiUpdate
val redirectValid = io.redirect.valid
val redirect = io.redirect.bits.cfiUpdate
val redirectPC = redirect.pc
val redirectBank = ltbAddr.getBank(redirectPC)

Expand All @@ -363,7 +362,7 @@ class LoopPredictor extends BasePredictor with LTBParams {
ltbs(i).io.redirect.bits.specCnt := redirect.specCnt(i)
ltbs(i).io.redirect.bits.mispred := redirect.isMisPred
ltbs(i).io.redirect.bits.taken := redirect.taken
ltbs(i).io.redirect.bits.isReplay := do_redirect.bits.flushItself
ltbs(i).io.redirect.bits.isReplay := io.redirect.bits.flushItself

ltbs(i).io.repair := redirectValid && redirectBank =/= i.U
}
Expand Down Expand Up @@ -394,7 +393,7 @@ class LoopPredictor extends BasePredictor with LTBParams {
XSDebug("[IF4][req] inMask=%b\n", inMask)

XSDebug("[IF4][req] updatePC=%x, updateValid=%d, isBr=%b\n", update.ftqPC, updateValid, update.br_mask.asUInt)
XSDebug("[IF4][req] redirectPC=%x redirectBank=%d, redirectValid=%d, isBr=%d, isReplay=%d\n", redirect.pc, redirectBank, redirectValid, redirect.pd.isBr, do_redirect.bits.flushItself)
XSDebug("[IF4][req] redirectPC=%x redirectBank=%d, redirectValid=%d, isBr=%d, isReplay=%d\n", redirect.pc, redirectBank, redirectValid, redirect.pd.isBr, io.redirect.bits.flushItself)
XSDebug("[IF4][req] isMisPred=%d\n", redirect.isMisPred)

XSDebug(redirectValid, "[redirect SpecCnt] ")
Expand Down
38 changes: 19 additions & 19 deletions src/main/scala/xiangshan/frontend/SC.scala
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ class SCTable(val nRows: Int, val ctrBits: Int, val histLen: Int)
when (io.update.mask(w)) {
wrbypass_ctr_valids(wrbypass_enq_idx)(ctrPos) := true.B
wrbypass_ctrs(wrbypass_enq_idx)(w) := update_wdatas(w)
wrbypass_idxs(wrbypass_enq_idx) := update_idx
}
}
}
}

when (io.update.mask.reduce(_||_) && !wrbypass_hit) {
wrbypass_idxs(wrbypass_enq_idx) := update_idx
wrbypass_enq_idx := (wrbypass_enq_idx + 1.U)(log2Ceil(wrBypassEntries)-1,0)
}

Expand Down Expand Up @@ -157,19 +157,20 @@ class SCTable(val nRows: Int, val ctrBits: Int, val histLen: Int)

}

class SCThreshold(val ctrBits: Int = 5) extends SCBundle {
class SCThreshold(val ctrBits: Int = 6) extends SCBundle {
val ctr = UInt(ctrBits.W)
def satPos(ctr: UInt = this.ctr) = ctr === ((1.U << ctrBits) - 1.U)
def satNeg(ctr: UInt = this.ctr) = ctr === 0.U
def neutralVal = (1.U << (ctrBits - 1))
val thres = UInt(5.W)
def minThres = 5.U
def maxThres = 31.U
val thres = UInt(8.W)
def initVal = 60.U
def minThres = 6.U
def maxThres = 255.U
def update(cause: Bool): SCThreshold = {
val res = Wire(new SCThreshold(this.ctrBits))
val newCtr = satUpdate(this.ctr, this.ctrBits, cause)
val newThres = Mux(res.satPos(newCtr), this.thres + 1.U,
Mux(res.satNeg(newCtr), this.thres - 1.U,
val newThres = Mux(res.satPos(newCtr) && this.thres <= maxThres, this.thres + 2.U,
Mux(res.satNeg(newCtr) && this.thres >= minThres, this.thres - 2.U,
this.thres))
res.thres := newThres
res.ctr := Mux(res.satPos(newCtr) || res.satNeg(newCtr), res.neutralVal, newCtr)
Expand All @@ -182,7 +183,7 @@ object SCThreshold {
def apply(bits: Int) = {
val t = Wire(new SCThreshold(ctrBits=bits))
t.ctr := t.neutralVal
t.thres := t.minThres
t.thres := t.initVal
t
}
}
Expand All @@ -202,9 +203,9 @@ trait HasSC extends HasSCParameter { this: Tage =>
}
}

val scThreshold = RegInit(SCThreshold(5))
val useThreshold = WireInit(scThreshold.thres)
val updateThreshold = WireInit((useThreshold << 3) + 21.U)
val scThresholds = List.fill(TageBanks)(RegInit(SCThreshold(5)))
val useThresholds = VecInit(scThresholds map (_.thres))
val updateThresholds = VecInit(useThresholds map (t => (t << 3) + 21.U))

val if3_scResps = VecInit(scTables.map(t => t.io.resp))

Expand Down Expand Up @@ -240,7 +241,7 @@ trait HasSC extends HasSCParameter { this: Tage =>
val if3_pvdrCtrCentered = getPvdrCentered(providerCtr)
val if3_totalSums = VecInit(if3_scTableSums.map(_ + if3_pvdrCtrCentered))
val if3_sumAbs = VecInit(if3_totalSums.map(_.abs.asUInt))
val if3_sumBelowThresholds = VecInit(if3_sumAbs.map(_ < useThreshold))
val if3_sumBelowThresholds = VecInit(if3_sumAbs zip useThresholds map {case (s, t) => s < t})
val if3_scPreds = VecInit(if3_totalSums.map (_ >= 0.S))

val if4_sumBelowThresholds = RegEnable(if3_sumBelowThresholds, s3_fire)
Expand Down Expand Up @@ -282,12 +283,11 @@ trait HasSC extends HasSCParameter { this: Tage =>
scUpdateTakens(w) := taken
(scUpdateOldCtrs(w) zip scOldCtrs).foreach{case (t, c) => t := c}

when (scPred =/= tagePred && sumAbs < useThreshold - 2.U) {
val newThres = scThreshold.update(scPred =/= taken)
scThreshold := newThres
XSDebug(p"scThres update: old d${useThreshold} --> new ${newThres.thres}\n")
}
when (scPred =/= taken || sumAbs < updateThreshold) {
when (scPred =/= taken || sumAbs < useThresholds(w)) {
val newThres = scThresholds(w).update(scPred =/= taken)
scThresholds(w) := newThres
XSDebug(p"scThres $w update: old ${useThresholds(w)} --> new ${newThres.thres}\n")

scUpdateMask.foreach(t => t(w) := true.B)
XSDebug(sum < 0.S,
p"scUpdate: bank(${w}), scPred(${scPred}), tagePred(${tagePred}), " +
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/xiangshan/frontend/Tage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,14 @@ class TageTable(val nRows: Int, val histLen: Int, val tagLen: Int, val uBitPerio
when (io.update.mask(w)) {
wrbypass_ctr_valids(wrbypass_enq_idx)(w) := true.B
wrbypass_ctrs(wrbypass_enq_idx)(w) := update_wdata(w).ctr
wrbypass_tags(wrbypass_enq_idx) := update_tag
wrbypass_idxs(wrbypass_enq_idx) := update_idx
}
}
}
}

when (io.update.mask.reduce(_||_) && !wrbypass_hit) {
wrbypass_tags(wrbypass_enq_idx) := update_tag
wrbypass_idxs(wrbypass_enq_idx) := update_idx
wrbypass_enq_idx := (wrbypass_enq_idx + 1.U)(log2Ceil(wrBypassEntries)-1,0)
}

Expand Down