xref: /XiangShan/src/main/scala/xiangshan/frontend/SC.scala (revision 2caa7ef23d5d6566d68f5f98a59dc7ee9066b96a)
1/***************************************************************************************
2* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences
3* Copyright (c) 2020-2021 Peng Cheng Laboratory
4*
5* XiangShan is licensed under Mulan PSL v2.
6* You can use this software according to the terms and conditions of the Mulan PSL v2.
7* You may obtain a copy of Mulan PSL v2 at:
8*          http://license.coscl.org.cn/MulanPSL2
9*
10* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13*
14* See the Mulan PSL v2 for more details.
15*
16*
17* Acknowledgement
18*
19* This implementation is inspired by several key papers:
20* [1] André Seznec. "[Tage-sc-l branch predictors.](https://inria.hal.science/hal-01086920)" The Journal of
21* Instruction-Level Parallelism (JILP) 4th JILP Workshop on Computer Architecture Competitions (JWAC): Championship
22* Branch Prediction (CBP). 2014.
23* [2] André Seznec. "[Tage-sc-l branch predictors again.](https://inria.hal.science/hal-01354253)" The Journal of
24* Instruction-Level Parallelism (JILP) 5th JILP Workshop on Computer Architecture Competitions (JWAC): Championship
25* Branch Prediction (CBP). 2016.
26***************************************************************************************/
27
28package xiangshan.frontend
29
30import chisel3._
31import chisel3.util._
32import org.chipsalliance.cde.config.Parameters
33import scala.{Tuple2 => &}
34import scala.math.min
35import utility._
36import utility.mbist.MbistPipeline
37import xiangshan._
38
39trait HasSCParameter extends TageParams {}
40
41class SCReq(implicit p: Parameters) extends TageReq
42
43abstract class SCBundle(implicit p: Parameters) extends TageBundle with HasSCParameter {}
44abstract class SCModule(implicit p: Parameters) extends TageModule with HasSCParameter {}
45
46class SCMeta(val ntables: Int)(implicit p: Parameters) extends XSBundle with HasSCParameter {
47  val scPreds = Vec(numBr, Bool())
48  // Suppose ctrbits of all tables are identical
49  val ctrs = Vec(numBr, Vec(ntables, SInt(SCCtrBits.W)))
50}
51
52class SCResp(val ctrBits: Int = 6)(implicit p: Parameters) extends SCBundle {
53  val ctrs = Vec(numBr, Vec(2, SInt(ctrBits.W)))
54}
55
56class SCUpdate(val ctrBits: Int = 6)(implicit p: Parameters) extends SCBundle {
57  val pc        = UInt(VAddrBits.W)
58  val ghist     = UInt(HistoryLength.W)
59  val mask      = Vec(numBr, Bool())
60  val oldCtrs   = Vec(numBr, SInt(ctrBits.W))
61  val tagePreds = Vec(numBr, Bool())
62  val takens    = Vec(numBr, Bool())
63}
64
65class SCTableIO(val ctrBits: Int = 6)(implicit p: Parameters) extends SCBundle {
66  val req    = Input(Valid(new SCReq))
67  val resp   = Output(new SCResp(ctrBits))
68  val update = Input(new SCUpdate(ctrBits))
69}
70
71class SCTable(val nRows: Int, val ctrBits: Int, val histLen: Int)(implicit p: Parameters)
72    extends SCModule with HasFoldedHistory {
73  val io = IO(new SCTableIO(ctrBits))
74
75  // val table = Module(new SRAMTemplate(SInt(ctrBits.W), set=nRows, way=2*TageBanks, shouldReset=true, holdRead=true, singlePort=false))
76  val table = Module(new SRAMTemplate(
77    SInt(ctrBits.W),
78    set = nRows,
79    way = 2 * TageBanks,
80    shouldReset = true,
81    holdRead = true,
82    singlePort = false,
83    bypassWrite = true,
84    withClockGate = true,
85    hasMbist = hasMbist
86  ))
87  private val mbistPl = MbistPipeline.PlaceMbistPipeline(1, "MbistPipeSc", hasMbist)
88  // def getIdx(hist: UInt, pc: UInt) = {
89  //   (compute_folded_ghist(hist, log2Ceil(nRows)) ^ (pc >> instOffsetBits))(log2Ceil(nRows)-1,0)
90  // }
91
92  val idxFhInfo = (histLen, min(log2Ceil(nRows), histLen))
93
94  def getFoldedHistoryInfo = Set(idxFhInfo).filter(_._1 > 0)
95
96  def getIdx(pc: UInt, allFh: AllFoldedHistories) =
97    if (histLen > 0) {
98      val idx_fh = allFh.getHistWithInfo(idxFhInfo).folded_hist
99      // require(idx_fh.getWidth == log2Ceil(nRows))
100      ((pc >> instOffsetBits) ^ idx_fh)(log2Ceil(nRows) - 1, 0)
101    } else {
102      (pc >> instOffsetBits)(log2Ceil(nRows) - 1, 0)
103    }
104
105  def ctrUpdate(ctr: SInt, cond: Bool): SInt = signedSatUpdate(ctr, ctrBits, cond)
106
107  val s0_idx = getIdx(io.req.bits.pc, io.req.bits.folded_hist)
108  val s1_idx = RegEnable(s0_idx, io.req.valid)
109
110  val s1_pc           = RegEnable(io.req.bits.pc, io.req.fire)
111  val s1_unhashed_idx = s1_pc >> instOffsetBits
112
113  table.io.r.req.valid       := io.req.valid
114  table.io.r.req.bits.setIdx := s0_idx
115
116  val update_wdata        = Wire(Vec(numBr, SInt(ctrBits.W))) // correspond to physical bridx
117  val update_wdata_packed = VecInit(update_wdata.map(Seq.fill(2)(_)).reduce(_ ++ _))
118  val updateWayMask       = Wire(Vec(2 * numBr, Bool()))      // correspond to physical bridx
119
120  val update_unhashed_idx = io.update.pc >> instOffsetBits
121  for (pi <- 0 until numBr) {
122    updateWayMask(2 * pi) := Seq.tabulate(numBr)(li =>
123      io.update.mask(li) && get_phy_br_idx(update_unhashed_idx, li) === pi.U && !io.update.tagePreds(li)
124    ).reduce(_ || _)
125    updateWayMask(2 * pi + 1) := Seq.tabulate(numBr)(li =>
126      io.update.mask(li) && get_phy_br_idx(update_unhashed_idx, li) === pi.U && io.update.tagePreds(li)
127    ).reduce(_ || _)
128  }
129
130  val update_folded_hist = WireInit(0.U.asTypeOf(new AllFoldedHistories(foldedGHistInfos)))
131  if (histLen > 0) {
132    update_folded_hist.getHistWithInfo(idxFhInfo).folded_hist := compute_folded_ghist(io.update.ghist, log2Ceil(nRows))
133  }
134  val update_idx = getIdx(io.update.pc, update_folded_hist)
135
136  // SCTable dual port SRAM reads and writes to the same address processing
137  val conflict_buffer_valid   = RegInit(false.B)
138  val conflict_buffer_data    = RegInit(0.U.asTypeOf(update_wdata_packed))
139  val conflict_buffer_idx     = RegInit(0.U.asTypeOf(update_idx))
140  val conflict_buffer_waymask = RegInit(0.U.asTypeOf(updateWayMask))
141
142  val write_conflict = update_idx === s0_idx && io.update.mask.reduce(_ || _) && io.req.valid
143  val can_write      = (conflict_buffer_idx =/= s0_idx || !io.req.valid) && conflict_buffer_valid
144
145  when(write_conflict) {
146    conflict_buffer_valid   := true.B
147    conflict_buffer_data    := update_wdata_packed
148    conflict_buffer_idx     := update_idx
149    conflict_buffer_waymask := updateWayMask
150  }
151  when(can_write) {
152    conflict_buffer_valid := false.B
153  }
154
155  // Using buffer data for prediction
156  val use_conflict_data = conflict_buffer_valid && conflict_buffer_idx === s1_idx
157  val conflict_data_bypass = conflict_buffer_data.zip(conflict_buffer_waymask).map { case (data, mask) =>
158    Mux(mask, data, 0.U.asTypeOf(data))
159  }
160  val conflict_prediction_data = conflict_data_bypass.sliding(2, 2).toSeq.map(VecInit(_))
161  val per_br_ctrs_unshuffled   = table.io.r.resp.data.sliding(2, 2).toSeq.map(VecInit(_))
162  val per_br_ctrs = VecInit((0 until numBr).map(i =>
163    Mux1H(
164      UIntToOH(get_phy_br_idx(s1_unhashed_idx, i), numBr),
165      per_br_ctrs_unshuffled
166    )
167  ))
168  val conflict_br_ctrs = VecInit((0 until numBr).map(i =>
169    Mux1H(
170      UIntToOH(get_phy_br_idx(s1_unhashed_idx, i), numBr),
171      conflict_prediction_data
172    )
173  ))
174
175  io.resp.ctrs := Mux(use_conflict_data, conflict_br_ctrs, per_br_ctrs)
176
177  table.io.w.apply(
178    valid = (io.update.mask.reduce(_ || _) && !write_conflict) || can_write,
179    data = Mux(can_write, conflict_buffer_data, update_wdata_packed),
180    setIdx = Mux(can_write, conflict_buffer_idx, update_idx),
181    waymask = Mux(can_write, conflict_buffer_waymask.asUInt, updateWayMask.asUInt)
182  )
183
184  val wrBypassEntries = 16
185
186  // let it corresponds to logical brIdx
187  val wrbypasses = Seq.fill(numBr)(Module(new WrBypass(SInt(ctrBits.W), wrBypassEntries, log2Ceil(nRows), numWays = 2)))
188
189  for (pi <- 0 until numBr) {
190    val br_lidx = get_lgc_br_idx(update_unhashed_idx, pi.U(log2Ceil(numBr).W))
191
192    val wrbypass_io = Mux1H(UIntToOH(br_lidx, numBr), wrbypasses.map(_.io))
193
194    val ctrPos        = Mux1H(UIntToOH(br_lidx, numBr), io.update.tagePreds)
195    val bypass_ctr    = wrbypass_io.hit_data(ctrPos)
196    val previous_ctr  = Mux1H(UIntToOH(br_lidx, numBr), io.update.oldCtrs)
197    val hit_and_valid = wrbypass_io.hit && bypass_ctr.valid
198    val oldCtr        = Mux(hit_and_valid, bypass_ctr.bits, previous_ctr)
199    val taken         = Mux1H(UIntToOH(br_lidx, numBr), io.update.takens)
200    update_wdata(pi) := ctrUpdate(oldCtr, taken)
201  }
202
203  val per_br_update_wdata_packed = update_wdata_packed.sliding(2, 2).map(VecInit(_)).toSeq
204  val per_br_update_way_mask     = updateWayMask.sliding(2, 2).map(VecInit(_)).toSeq
205  for (li <- 0 until numBr) {
206    val wrbypass = wrbypasses(li)
207    val br_pidx  = get_phy_br_idx(update_unhashed_idx, li)
208    wrbypass.io.wen        := io.update.mask(li)
209    wrbypass.io.write_idx  := update_idx
210    wrbypass.io.write_data := Mux1H(UIntToOH(br_pidx, numBr), per_br_update_wdata_packed)
211    wrbypass.io.write_way_mask.map(_ := Mux1H(UIntToOH(br_pidx, numBr), per_br_update_way_mask))
212  }
213
214  val u = io.update
215  XSDebug(
216    io.req.valid,
217    p"scTableReq: pc=0x${Hexadecimal(io.req.bits.pc)}, " +
218      p"s0_idx=${s0_idx}\n"
219  )
220  XSDebug(
221    RegNext(io.req.valid),
222    p"scTableResp: s1_idx=${s1_idx}," +
223      p"ctr:${io.resp.ctrs}\n"
224  )
225  XSDebug(
226    io.update.mask.reduce(_ || _),
227    p"update Table: pc:${Hexadecimal(u.pc)}, " +
228      p"tageTakens:${u.tagePreds}, taken:${u.takens}, oldCtr:${u.oldCtrs}\n"
229  )
230}
231
232class SCThreshold(val ctrBits: Int = 6)(implicit p: Parameters) extends SCBundle {
233  val ctr = UInt(ctrBits.W)
234  def satPos(ctr: UInt = this.ctr) = ctr === ((1.U << ctrBits) - 1.U)
235  def satNeg(ctr: UInt = this.ctr) = ctr === 0.U
236  def neutralVal = (1 << (ctrBits - 1)).U
237  val thres      = UInt(8.W)
238  def initVal    = 6.U
239  def minThres   = 6.U
240  def maxThres   = 31.U
241  def update(cause: Bool): SCThreshold = {
242    val res    = Wire(new SCThreshold(this.ctrBits))
243    val newCtr = satUpdate(this.ctr, this.ctrBits, cause)
244    val newThres = Mux(
245      res.satPos(newCtr) && this.thres <= maxThres,
246      this.thres + 2.U,
247      Mux(res.satNeg(newCtr) && this.thres >= minThres, this.thres - 2.U, this.thres)
248    )
249    res.thres := newThres
250    res.ctr   := Mux(res.satPos(newCtr) || res.satNeg(newCtr), res.neutralVal, newCtr)
251    // XSDebug(true.B, p"scThres Update: cause${cause} newCtr ${newCtr} newThres ${newThres}\n")
252    res
253  }
254}
255
256object SCThreshold {
257  def apply(bits: Int)(implicit p: Parameters) = {
258    val t = Wire(new SCThreshold(ctrBits = bits))
259    t.ctr   := t.neutralVal
260    t.thres := t.initVal
261    t
262  }
263}
264
265trait HasSC extends HasSCParameter with HasPerfEvents { this: Tage =>
266  val update_on_mispred, update_on_unconf = WireInit(0.U.asTypeOf(Vec(TageBanks, Bool())))
267  var sc_fh_info                          = Set[FoldedHistoryInfo]()
268  if (EnableSC) {
269    val scTables = SCTableInfos.map {
270      case (nRows, ctrBits, histLen) => {
271        val t   = Module(new SCTable(nRows / TageBanks, ctrBits, histLen))
272        val req = t.io.req
273        req.valid            := io.s0_fire(3)
274        req.bits.pc          := s0_pc_dup(3)
275        req.bits.folded_hist := io.in.bits.folded_hist(3)
276        req.bits.ghist       := DontCare
277        if (!EnableSC) { t.io.update := DontCare }
278        t
279      }
280    }
281    sc_fh_info = scTables.map(_.getFoldedHistoryInfo).reduce(_ ++ _).toSet
282
283    val scThresholds  = List.fill(TageBanks)(RegInit(SCThreshold(5)))
284    val useThresholds = VecInit(scThresholds map (_.thres))
285
286    def sign(x: SInt) = x(x.getWidth - 1)
287    def pos(x:  SInt) = !sign(x)
288    def neg(x:  SInt) = sign(x)
289
290    def aboveThreshold(scSum: SInt, tagePvdr: SInt, threshold: UInt): Bool = {
291      val signedThres = threshold.zext
292      val totalSum    = scSum +& tagePvdr
293      (scSum > signedThres - tagePvdr) && pos(totalSum) ||
294      (scSum < -signedThres - tagePvdr) && neg(totalSum)
295    }
296    val updateThresholds = VecInit(useThresholds map (t => (t << 3) +& 21.U))
297
298    val s1_scResps = VecInit(scTables.map(t => t.io.resp))
299
300    val scUpdateMask      = WireInit(0.U.asTypeOf(Vec(numBr, Vec(SCNTables, Bool()))))
301    val scUpdateTagePreds = Wire(Vec(TageBanks, Bool()))
302    val scUpdateTakens    = Wire(Vec(TageBanks, Bool()))
303    val scUpdateOldCtrs   = Wire(Vec(numBr, Vec(SCNTables, SInt(SCCtrBits.W))))
304    scUpdateTagePreds := DontCare
305    scUpdateTakens    := DontCare
306    scUpdateOldCtrs   := DontCare
307
308    val updateSCMeta = updateMeta.scMeta.get
309
310    val s2_sc_used, s2_conf, s2_unconf, s2_agree, s2_disagree =
311      WireInit(0.U.asTypeOf(Vec(TageBanks, Bool())))
312    val update_sc_used, update_conf, update_unconf, update_agree, update_disagree =
313      WireInit(0.U.asTypeOf(Vec(TageBanks, Bool())))
314    val sc_misp_tage_corr, sc_corr_tage_misp =
315      WireInit(0.U.asTypeOf(Vec(TageBanks, Bool())))
316
317    // for sc ctrs
318    def getCentered(ctr: SInt): SInt = Cat(ctr, 1.U(1.W)).asSInt
319    // for tage ctrs, (2*(ctr-4)+1)*8
320    def getPvdrCentered(ctr: UInt): SInt = Cat(ctr ^ (1 << (TageCtrBits - 1)).U, 1.U(1.W), 0.U(3.W)).asSInt
321
322    val scMeta = resp_meta.scMeta.get
323    scMeta := DontCare
324    for (w <- 0 until TageBanks) {
325      // do summation in s2
326      val s1_scTableSums = VecInit(
327        (0 to 1) map { i =>
328          ParallelSingedExpandingAdd(s1_scResps map (r => getCentered(r.ctrs(w)(i)))) // TODO: rewrite with wallace tree
329        }
330      )
331      val s2_scTableSums         = RegEnable(s1_scTableSums, io.s1_fire(3))
332      val s2_tagePrvdCtrCentered = getPvdrCentered(RegEnable(s1_providerResps(w).ctr, io.s1_fire(3)))
333      val s2_totalSums           = s2_scTableSums.map(_ +& s2_tagePrvdCtrCentered)
334      val s2_sumAboveThresholds =
335        VecInit((0 to 1).map(i => aboveThreshold(s2_scTableSums(i), s2_tagePrvdCtrCentered, useThresholds(w))))
336      val s2_scPreds = VecInit(s2_totalSums.map(_ >= 0.S))
337
338      val s2_scResps   = VecInit(RegEnable(s1_scResps, io.s1_fire(3)).map(_.ctrs(w)))
339      val s2_scCtrs    = VecInit(s2_scResps.map(_(s2_tageTakens_dup(3)(w).asUInt)))
340      val s2_chooseBit = s2_tageTakens_dup(3)(w)
341
342      val s2_pred =
343        Mux(s2_provideds(w) && s2_sumAboveThresholds(s2_chooseBit), s2_scPreds(s2_chooseBit), s2_tageTakens_dup(3)(w))
344
345      val s3_disagree = RegEnable(s2_disagree, io.s2_fire(3))
346      io.out.last_stage_spec_info.sc_disagree.map(_ := s3_disagree)
347
348      scMeta.scPreds(w) := RegEnable(s2_scPreds(s2_chooseBit), io.s2_fire(3))
349      scMeta.ctrs(w)    := RegEnable(s2_scCtrs, io.s2_fire(3))
350
351      val pred     = s2_scPreds(s2_chooseBit)
352      val debug_pc = Cat(debug_pc_s2, w.U, 0.U(instOffsetBits.W))
353      when(s2_provideds(w)) {
354        s2_sc_used(w) := true.B
355        s2_unconf(w)  := !s2_sumAboveThresholds(s2_chooseBit)
356        s2_conf(w)    := s2_sumAboveThresholds(s2_chooseBit)
357        // Use prediction from Statistical Corrector
358        when(s2_sumAboveThresholds(s2_chooseBit)) {
359          s2_agree(w)    := s2_tageTakens_dup(3)(w) === pred
360          s2_disagree(w) := s2_tageTakens_dup(3)(w) =/= pred
361          // fit to always-taken condition
362          // io.out.s2.full_pred.br_taken_mask(w) := pred
363        }
364      }
365      XSDebug(s2_provideds(w), p"---------tage_bank_${w} provided so that sc used---------\n")
366      XSDebug(
367        s2_provideds(w) && s2_sumAboveThresholds(s2_chooseBit),
368        p"pc(${Hexadecimal(debug_pc)}) SC(${w.U}) overriden pred to ${pred}\n"
369      )
370
371      val s3_pred_dup   = io.s2_fire.map(f => RegEnable(s2_pred, f))
372      val sc_enable_dup = dup(RegNext(io.ctrl.sc_enable))
373      for (
374        sc_enable & fp & s3_pred <-
375          sc_enable_dup zip io.out.s3.full_pred zip s3_pred_dup
376      ) {
377        when(sc_enable) {
378          fp.br_taken_mask(w) := s3_pred
379        }
380      }
381
382      val updateTageMeta    = updateMeta
383      val scPred            = updateSCMeta.scPreds(w)
384      val tagePred          = updateTageMeta.takens(w)
385      val taken             = update.br_taken_mask(w)
386      val scOldCtrs         = updateSCMeta.ctrs(w)
387      val pvdrCtr           = updateTageMeta.providerResps(w).ctr
388      val tableSum          = ParallelSingedExpandingAdd(scOldCtrs.map(getCentered))
389      val totalSumAbs       = (tableSum +& getPvdrCentered(pvdrCtr)).abs.asUInt
390      val updateThres       = updateThresholds(w)
391      val sumAboveThreshold = aboveThreshold(tableSum, getPvdrCentered(pvdrCtr), updateThres)
392      val thres             = useThresholds(w)
393      val newThres          = scThresholds(w).update(scPred =/= taken)
394      when(updateValids(w) && updateTageMeta.providers(w).valid) {
395        scUpdateTagePreds(w) := tagePred
396        scUpdateTakens(w)    := taken
397        (scUpdateOldCtrs(w) zip scOldCtrs).foreach { case (t, c) => t := c }
398
399        update_sc_used(w)    := true.B
400        update_unconf(w)     := !sumAboveThreshold
401        update_conf(w)       := sumAboveThreshold
402        update_agree(w)      := scPred === tagePred
403        update_disagree(w)   := scPred =/= tagePred
404        sc_corr_tage_misp(w) := scPred === taken && tagePred =/= taken && update_conf(w)
405        sc_misp_tage_corr(w) := scPred =/= taken && tagePred === taken && update_conf(w)
406
407        when(scPred =/= tagePred && totalSumAbs >= thres - 4.U && totalSumAbs <= thres - 2.U) {
408          scThresholds(w) := newThres
409        }
410
411        when(scPred =/= taken || !sumAboveThreshold) {
412          scUpdateMask(w).foreach(_ := true.B)
413          update_on_mispred(w) := scPred =/= taken
414          update_on_unconf(w)  := scPred === taken
415        }
416      }
417      XSDebug(
418        updateValids(w) && updateTageMeta.providers(w).valid &&
419          scPred =/= tagePred && totalSumAbs >= thres - 4.U && totalSumAbs <= thres - 2.U,
420        p"scThres $w update: old ${useThresholds(w)} --> new ${newThres.thres}\n"
421      )
422      XSDebug(
423        updateValids(w) && updateTageMeta.providers(w).valid &&
424          (scPred =/= taken || !sumAboveThreshold) &&
425          tableSum < 0.S,
426        p"scUpdate: bank(${w}), scPred(${scPred}), tagePred(${tagePred}), " +
427          p"scSum(-${tableSum.abs}), mispred: sc(${scPred =/= taken}), tage(${updateMisPreds(w)})\n"
428      )
429      XSDebug(
430        updateValids(w) && updateTageMeta.providers(w).valid &&
431          (scPred =/= taken || !sumAboveThreshold) &&
432          tableSum >= 0.S,
433        p"scUpdate: bank(${w}), scPred(${scPred}), tagePred(${tagePred}), " +
434          p"scSum(+${tableSum.abs}), mispred: sc(${scPred =/= taken}), tage(${updateMisPreds(w)})\n"
435      )
436      XSDebug(
437        updateValids(w) && updateTageMeta.providers(w).valid &&
438          (scPred =/= taken || !sumAboveThreshold),
439        p"bank(${w}), update: sc: ${updateSCMeta}\n"
440      )
441    }
442
443    val realWens = scUpdateMask.transpose.map(v => v.reduce(_ | _))
444    for (b <- 0 until TageBanks) {
445      for (i <- 0 until SCNTables) {
446        val realWen = realWens(i)
447        scTables(i).io.update.mask(b)      := RegNext(scUpdateMask(b)(i))
448        scTables(i).io.update.tagePreds(b) := RegEnable(scUpdateTagePreds(b), realWen)
449        scTables(i).io.update.takens(b)    := RegEnable(scUpdateTakens(b), realWen)
450        scTables(i).io.update.oldCtrs(b)   := RegEnable(scUpdateOldCtrs(b)(i), realWen)
451        scTables(i).io.update.pc           := RegEnable(update_pc, realWen)
452        scTables(i).io.update.ghist        := RegEnable(update.ghist, realWen)
453      }
454    }
455
456    tage_perf("sc_conf", PopCount(s2_conf), PopCount(update_conf))
457    tage_perf("sc_unconf", PopCount(s2_unconf), PopCount(update_unconf))
458    tage_perf("sc_agree", PopCount(s2_agree), PopCount(update_agree))
459    tage_perf("sc_disagree", PopCount(s2_disagree), PopCount(update_disagree))
460    tage_perf("sc_used", PopCount(s2_sc_used), PopCount(update_sc_used))
461    XSPerfAccumulate("sc_update_on_mispred", PopCount(update_on_mispred))
462    XSPerfAccumulate("sc_update_on_unconf", PopCount(update_on_unconf))
463    XSPerfAccumulate("sc_mispred_but_tage_correct", PopCount(sc_misp_tage_corr))
464    XSPerfAccumulate("sc_correct_and_tage_wrong", PopCount(sc_corr_tage_misp))
465
466  }
467
468  override def getFoldedHistoryInfo = Some(tage_fh_info ++ sc_fh_info)
469
470  override val perfEvents = Seq(
471    ("tage_tht_hit                  ", PopCount(updateMeta.providers.map(_.valid))),
472    ("sc_update_on_mispred          ", PopCount(update_on_mispred)),
473    ("sc_update_on_unconf           ", PopCount(update_on_unconf))
474  )
475  generatePerfEvent()
476}
477