xref: /XiangShan/src/main/scala/xiangshan/frontend/IFU.scala (revision 2a3050c2e8117b17b696d8d20582def0e1751b5e)
109c6f1ddSLingrui98/***************************************************************************************
209c6f1ddSLingrui98* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences
309c6f1ddSLingrui98* Copyright (c) 2020-2021 Peng Cheng Laboratory
409c6f1ddSLingrui98*
509c6f1ddSLingrui98* XiangShan is licensed under Mulan PSL v2.
609c6f1ddSLingrui98* You can use this software according to the terms and conditions of the Mulan PSL v2.
709c6f1ddSLingrui98* You may obtain a copy of Mulan PSL v2 at:
809c6f1ddSLingrui98*          http://license.coscl.org.cn/MulanPSL2
909c6f1ddSLingrui98*
1009c6f1ddSLingrui98* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
1109c6f1ddSLingrui98* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
1209c6f1ddSLingrui98* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
1309c6f1ddSLingrui98*
1409c6f1ddSLingrui98* See the Mulan PSL v2 for more details.
1509c6f1ddSLingrui98***************************************************************************************/
1609c6f1ddSLingrui98
1709c6f1ddSLingrui98package xiangshan.frontend
1809c6f1ddSLingrui98
1909c6f1ddSLingrui98import chipsalliance.rocketchip.config.Parameters
2009c6f1ddSLingrui98import chisel3._
2109c6f1ddSLingrui98import chisel3.util._
22*2a3050c2SJayimport freechips.rocketchip.rocket.RVCDecoder
2309c6f1ddSLingrui98import xiangshan._
2409c6f1ddSLingrui98import xiangshan.cache.mmu._
251d8f4dcbSJayimport xiangshan.frontend.icache._
2609c6f1ddSLingrui98import utils._
27b6982e83SLemoverimport xiangshan.backend.fu.{PMPReqBundle, PMPRespBundle}
2809c6f1ddSLingrui98
2909c6f1ddSLingrui98trait HasInstrMMIOConst extends HasXSParameter with HasIFUConst{
3009c6f1ddSLingrui98  def mmioBusWidth = 64
3109c6f1ddSLingrui98  def mmioBusBytes = mmioBusWidth / 8
320be662e4SJay  def maxInstrLen = 32
3309c6f1ddSLingrui98}
3409c6f1ddSLingrui98
3509c6f1ddSLingrui98trait HasIFUConst extends HasXSParameter{
361d8f4dcbSJay  def addrAlign(addr: UInt, bytes: Int, highest: Int): UInt = Cat(addr(highest-1, log2Ceil(bytes)), 0.U(log2Ceil(bytes).W))
371d8f4dcbSJay  def fetchQueueSize = 2
381d8f4dcbSJay
39*2a3050c2SJay  def getBasicBlockIdx( pc: UInt, start:  UInt ): UInt = {
40*2a3050c2SJay    val byteOffset = pc - start
41*2a3050c2SJay    (byteOffset - instBytes.U)(log2Ceil(PredictWidth),instOffsetBits)
421d8f4dcbSJay  }
4309c6f1ddSLingrui98}
4409c6f1ddSLingrui98
4509c6f1ddSLingrui98class IfuToFtqIO(implicit p:Parameters) extends XSBundle {
4609c6f1ddSLingrui98  val pdWb = Valid(new PredecodeWritebackBundle)
4709c6f1ddSLingrui98}
4809c6f1ddSLingrui98
4909c6f1ddSLingrui98class FtqInterface(implicit p: Parameters) extends XSBundle {
5009c6f1ddSLingrui98  val fromFtq = Flipped(new FtqToIfuIO)
5109c6f1ddSLingrui98  val toFtq   = new IfuToFtqIO
5209c6f1ddSLingrui98}
5309c6f1ddSLingrui98
540be662e4SJayclass UncacheInterface(implicit p: Parameters) extends XSBundle {
550be662e4SJay  val fromUncache = Flipped(DecoupledIO(new InsUncacheResp))
560be662e4SJay  val toUncache   = DecoupledIO( new InsUncacheReq )
570be662e4SJay}
5809c6f1ddSLingrui98class NewIFUIO(implicit p: Parameters) extends XSBundle {
5909c6f1ddSLingrui98  val ftqInter        = new FtqInterface
601d8f4dcbSJay  val icacheInter     = Vec(2, Flipped(new ICacheMainPipeBundle))
611d8f4dcbSJay  val icacheStop      = Output(Bool())
621d8f4dcbSJay  val icachePerfInfo  = Input(new ICachePerfInfo)
6309c6f1ddSLingrui98  val toIbuffer       = Decoupled(new FetchToIBuffer)
640be662e4SJay  val uncacheInter   =  new UncacheInterface
6572951335SLi Qianruo  val frontendTrigger = Flipped(new FrontendTdataDistributeIO)
6672951335SLi Qianruo  val csrTriggerEnable = Input(Vec(4, Bool()))
67a37fbf10SJay  val rob_commits = Flipped(Vec(CommitWidth, Valid(new RobCommitInfo)))
6809c6f1ddSLingrui98}
6909c6f1ddSLingrui98
7009c6f1ddSLingrui98// record the situation in which fallThruAddr falls into
7109c6f1ddSLingrui98// the middle of an RVI inst
7209c6f1ddSLingrui98class LastHalfInfo(implicit p: Parameters) extends XSBundle {
7309c6f1ddSLingrui98  val valid = Bool()
7409c6f1ddSLingrui98  val middlePC = UInt(VAddrBits.W)
7509c6f1ddSLingrui98  def matchThisBlock(startAddr: UInt) = valid && middlePC === startAddr
7609c6f1ddSLingrui98}
7709c6f1ddSLingrui98
7809c6f1ddSLingrui98class IfuToPreDecode(implicit p: Parameters) extends XSBundle {
7909c6f1ddSLingrui98  val data                =  if(HasCExtension) Vec(PredictWidth + 1, UInt(16.W)) else Vec(PredictWidth, UInt(32.W))
8072951335SLi Qianruo  val frontendTrigger     = new FrontendTdataDistributeIO
8172951335SLi Qianruo  val csrTriggerEnable    = Vec(4, Bool())
82*2a3050c2SJay  val pc                  = Vec(PredictWidth, UInt(VAddrBits.W))
8309c6f1ddSLingrui98}
8409c6f1ddSLingrui98
85*2a3050c2SJay
86*2a3050c2SJayclass IfuToPredChecker(implicit p: Parameters) extends XSBundle {
87*2a3050c2SJay  val ftqOffset     = Valid(UInt(log2Ceil(PredictWidth).W))
88*2a3050c2SJay  val jumpOffset    = Vec(PredictWidth, UInt(XLEN.W))
89*2a3050c2SJay  val target        = UInt(VAddrBits.W)
90*2a3050c2SJay  val instrRange    = Vec(PredictWidth, Bool())
91*2a3050c2SJay  val instrValid    = Vec(PredictWidth, Bool())
92*2a3050c2SJay  val pds           = Vec(PredictWidth, new PreDecodeInfo)
93*2a3050c2SJay  val pc            = Vec(PredictWidth, UInt(VAddrBits.W))
94*2a3050c2SJay}
95*2a3050c2SJay
96*2a3050c2SJayclass NewIFU(implicit p: Parameters) extends XSModule
97*2a3050c2SJay  with HasICacheParameters
98*2a3050c2SJay  with HasIFUConst
99*2a3050c2SJay  with HasPdConst
100*2a3050c2SJay  with HasCircularQueuePtrHelper
101*2a3050c2SJay  with HasPerfEvents
10209c6f1ddSLingrui98{
10309c6f1ddSLingrui98  println(s"icache ways: ${nWays} sets:${nSets}")
10409c6f1ddSLingrui98  val io = IO(new NewIFUIO)
10509c6f1ddSLingrui98  val (toFtq, fromFtq)    = (io.ftqInter.toFtq, io.ftqInter.fromFtq)
1061d8f4dcbSJay  val (toICache, fromICache) = (VecInit(io.icacheInter.map(_.req)), VecInit(io.icacheInter.map(_.resp)))
1070be662e4SJay  val (toUncache, fromUncache) = (io.uncacheInter.toUncache , io.uncacheInter.fromUncache)
10809c6f1ddSLingrui98
10909c6f1ddSLingrui98  def isCrossLineReq(start: UInt, end: UInt): Bool = start(blockOffBits) ^ end(blockOffBits)
11009c6f1ddSLingrui98
11109c6f1ddSLingrui98  def isLastInCacheline(fallThruAddr: UInt): Bool = fallThruAddr(blockOffBits - 1, 1) === 0.U
11209c6f1ddSLingrui98
1131d8f4dcbSJay  class TlbExept(implicit p: Parameters) extends XSBundle{
1141d8f4dcbSJay    val pageFault = Bool()
1151d8f4dcbSJay    val accessFault = Bool()
1161d8f4dcbSJay    val mmio = Bool()
117b005f7c6SJay  }
11809c6f1ddSLingrui98
119*2a3050c2SJay  val preDecoder      = Module(new PreDecode)
120*2a3050c2SJay  val predChecker     = Module(new PredChecker)
121*2a3050c2SJay  val frontendTrigger = Module(new FrontendTrigger)
122*2a3050c2SJay  val (preDecoderIn, preDecoderOut)   = (preDecoder.io.in, preDecoder.io.out)
123*2a3050c2SJay  val (checkerIn, checkerOut)         = (predChecker.io.in, predChecker.io.out)
1241d8f4dcbSJay
12509c6f1ddSLingrui98  //---------------------------------------------
12609c6f1ddSLingrui98  //  Fetch Stage 1 :
12709c6f1ddSLingrui98  //  * Send req to ICache Meta/Data
12809c6f1ddSLingrui98  //  * Check whether need 2 line fetch
12909c6f1ddSLingrui98  //---------------------------------------------
13009c6f1ddSLingrui98
13109c6f1ddSLingrui98  val f0_valid                             = fromFtq.req.valid
13209c6f1ddSLingrui98  val f0_ftq_req                           = fromFtq.req.bits
13309c6f1ddSLingrui98  val f0_situation                         = VecInit(Seq(isCrossLineReq(f0_ftq_req.startAddr, f0_ftq_req.fallThruAddr), isLastInCacheline(f0_ftq_req.fallThruAddr)))
13409c6f1ddSLingrui98  val f0_doubleLine                        = f0_situation(0) || f0_situation(1)
13509c6f1ddSLingrui98  val f0_vSetIdx                           = VecInit(get_idx((f0_ftq_req.startAddr)), get_idx(f0_ftq_req.fallThruAddr))
13609c6f1ddSLingrui98  val f0_fire                              = fromFtq.req.fire()
13709c6f1ddSLingrui98
13809c6f1ddSLingrui98  val f0_flush, f1_flush, f2_flush, f3_flush = WireInit(false.B)
13909c6f1ddSLingrui98  val from_bpu_f0_flush, from_bpu_f1_flush, from_bpu_f2_flush, from_bpu_f3_flush = WireInit(false.B)
14009c6f1ddSLingrui98
14109c6f1ddSLingrui98  from_bpu_f0_flush := fromFtq.flushFromBpu.shouldFlushByStage2(f0_ftq_req.ftqIdx) ||
14209c6f1ddSLingrui98                       fromFtq.flushFromBpu.shouldFlushByStage3(f0_ftq_req.ftqIdx)
14309c6f1ddSLingrui98
144*2a3050c2SJay  val wb_redirect , mmio_redirect,  backend_redirect= WireInit(false.B)
145*2a3050c2SJay  val f3_wb_not_flush = WireInit(false.B)
146*2a3050c2SJay
147*2a3050c2SJay  backend_redirect := fromFtq.redirect.valid
148*2a3050c2SJay  f3_flush := backend_redirect || (wb_redirect && !f3_wb_not_flush)
149*2a3050c2SJay  f2_flush := backend_redirect || mmio_redirect || wb_redirect
15009c6f1ddSLingrui98  f1_flush := f2_flush || from_bpu_f1_flush
15109c6f1ddSLingrui98  f0_flush := f1_flush || from_bpu_f0_flush
15209c6f1ddSLingrui98
15309c6f1ddSLingrui98  val f1_ready, f2_ready, f3_ready         = WireInit(false.B)
15409c6f1ddSLingrui98
1551d8f4dcbSJay  fromFtq.req.ready := toICache(0).ready && toICache(1).ready && f2_ready && GTimer() > 500.U
15609c6f1ddSLingrui98
157*2a3050c2SJay  toICache(0).valid       := fromFtq.req.valid && !f0_flush
1581d8f4dcbSJay  toICache(0).bits.vaddr  := fromFtq.req.bits.startAddr
159*2a3050c2SJay  toICache(1).valid       := fromFtq.req.valid && f0_doubleLine && !f0_flush
1601d8f4dcbSJay  toICache(1).bits.vaddr  := fromFtq.req.bits.fallThruAddr
16109c6f1ddSLingrui98
162f7c29b0aSJinYue
163*2a3050c2SJay  /** Fetch Stage 1  */
1641d8f4dcbSJay
1651d8f4dcbSJay  val f1_valid      = RegInit(false.B)
1661d8f4dcbSJay  val f1_ftq_req    = RegEnable(next = f0_ftq_req,    enable=f0_fire)
1671d8f4dcbSJay  val f1_situation  = RegEnable(next = f0_situation,  enable=f0_fire)
1681d8f4dcbSJay  val f1_doubleLine = RegEnable(next = f0_doubleLine, enable=f0_fire)
1691d8f4dcbSJay  val f1_vSetIdx    = RegEnable(next = f0_vSetIdx,    enable=f0_fire)
1701d8f4dcbSJay  val f1_fire       = f1_valid && f1_ready
1711d8f4dcbSJay
1721d8f4dcbSJay  f1_ready := f2_ready || !f1_valid
1731d8f4dcbSJay
1741d8f4dcbSJay  from_bpu_f1_flush := fromFtq.flushFromBpu.shouldFlushByStage3(f1_ftq_req.ftqIdx)
1751d8f4dcbSJay
1761d8f4dcbSJay  when(f1_flush)                  {f1_valid  := false.B}
1771d8f4dcbSJay  .elsewhen(f0_fire && !f0_flush) {f1_valid  := true.B}
1781d8f4dcbSJay  .elsewhen(f1_fire)              {f1_valid  := false.B}
179*2a3050c2SJay
180*2a3050c2SJay  val f1_pc                 = VecInit((0 until PredictWidth).map(i => f1_ftq_req.startAddr + (i * 2).U))
181*2a3050c2SJay  val f1_half_snpc          = VecInit((0 until PredictWidth).map(i => f1_ftq_req.startAddr + ((i+2) * 2).U))
182*2a3050c2SJay  val f1_cut_ptr            = if(HasCExtension)  VecInit((0 until PredictWidth + 1).map(i =>  Cat(0.U(1.W), f1_ftq_req.startAddr(blockOffBits-1, 1)) + i.U ))
183*2a3050c2SJay                                  else           VecInit((0 until PredictWidth).map(i =>     Cat(0.U(1.W), f1_ftq_req.startAddr(blockOffBits-1, 2)) + i.U ))
184*2a3050c2SJay
185*2a3050c2SJay  /** Fetch Stage 2  */
1861d8f4dcbSJay  val icacheRespAllValid = WireInit(false.B)
18709c6f1ddSLingrui98
18809c6f1ddSLingrui98  val f2_valid      = RegInit(false.B)
18909c6f1ddSLingrui98  val f2_ftq_req    = RegEnable(next = f1_ftq_req,    enable=f1_fire)
19009c6f1ddSLingrui98  val f2_situation  = RegEnable(next = f1_situation,  enable=f1_fire)
19109c6f1ddSLingrui98  val f2_doubleLine = RegEnable(next = f1_doubleLine, enable=f1_fire)
1921d8f4dcbSJay  val f2_vSetIdx    = RegEnable(next = f1_vSetIdx,    enable=f1_fire)
1931d8f4dcbSJay  val f2_fire       = f2_valid && f2_ready
1941d8f4dcbSJay
1951d8f4dcbSJay  f2_ready := f3_ready && icacheRespAllValid || !f2_valid
1961d8f4dcbSJay  //TODO: addr compare may be timing critical
1971d8f4dcbSJay  val f2_icache_all_resp_wire       =  fromICache(0).valid && (fromICache(0).bits.vaddr ===  f2_ftq_req.startAddr) && ((fromICache(1).valid && (fromICache(1).bits.vaddr ===  f2_ftq_req.fallThruAddr)) || !f2_doubleLine)
1981d8f4dcbSJay  val f2_icache_all_resp_reg        = RegInit(false.B)
1991d8f4dcbSJay
2001d8f4dcbSJay  icacheRespAllValid := f2_icache_all_resp_reg || f2_icache_all_resp_wire
2011d8f4dcbSJay
2021d8f4dcbSJay  io.icacheStop := !f3_ready
2031d8f4dcbSJay
2041d8f4dcbSJay  when(f2_flush)                                              {f2_icache_all_resp_reg := false.B}
2051d8f4dcbSJay  .elsewhen(f2_valid && f2_icache_all_resp_wire && !f3_ready) {f2_icache_all_resp_reg := true.B}
2061d8f4dcbSJay  .elsewhen(f2_fire && f2_icache_all_resp_reg)                {f2_icache_all_resp_reg := false.B}
20709c6f1ddSLingrui98
20809c6f1ddSLingrui98  when(f2_flush)                  {f2_valid := false.B}
20909c6f1ddSLingrui98  .elsewhen(f1_fire && !f1_flush) {f2_valid := true.B }
21009c6f1ddSLingrui98  .elsewhen(f2_fire)              {f2_valid := false.B}
21109c6f1ddSLingrui98
2121d8f4dcbSJay  val f2_cache_response_data = ResultHoldBypass(valid = f2_icache_all_resp_wire, data = VecInit(fromICache.map(_.bits.readData)))
21309c6f1ddSLingrui98
2141d8f4dcbSJay  val f2_except_pf    = VecInit((0 until PortNumber).map(i => fromICache(i).bits.tlbExcp.pageFault))
2151d8f4dcbSJay  val f2_except_af    = VecInit((0 until PortNumber).map(i => fromICache(i).bits.tlbExcp.accessFault))
216c0b2b8e9Srvcoresjw  val f2_mmio         = fromICache(0).bits.tlbExcp.mmio && !fromICache(0).bits.tlbExcp.accessFault &&
217c0b2b8e9Srvcoresjw                                                           !fromICache(0).bits.tlbExcp.pageFault
2180be662e4SJay
219*2a3050c2SJay  val f2_pc               = RegEnable(next = f1_pc, enable = f1_fire)
220*2a3050c2SJay  val f2_half_snpc        = RegEnable(next = f1_half_snpc, enable = f1_fire)
221*2a3050c2SJay  val f2_cut_ptr          = RegEnable(next = f1_cut_ptr, enable = f1_fire)
222*2a3050c2SJay  val f2_half_match       = VecInit(f2_half_snpc.map(_ === f2_ftq_req.fallThruAddr))
223*2a3050c2SJay
224*2a3050c2SJay
225*2a3050c2SJay  def isNextLine(pc: UInt, startAddr: UInt) = {
226*2a3050c2SJay    startAddr(blockOffBits) ^ pc(blockOffBits)
227*2a3050c2SJay  }
228*2a3050c2SJay
229*2a3050c2SJay  def isLastInLine(pc: UInt) = {
230*2a3050c2SJay    pc(blockOffBits - 1, 0) === "b111110".U
231*2a3050c2SJay  }
232*2a3050c2SJay
233*2a3050c2SJay  //calculate
234*2a3050c2SJay  val f2_foldpc = VecInit(f2_pc.map(i => XORFold(i(VAddrBits-1,1), MemPredPCWidth)))
235*2a3050c2SJay  val f2_jump_range = Fill(PredictWidth, !f2_ftq_req.ftqOffset.valid) | Fill(PredictWidth, 1.U(1.W)) >> ~f2_ftq_req.ftqOffset.bits
236*2a3050c2SJay  val f2_ftr_range  = Fill(PredictWidth, f2_ftq_req.oversize) | Fill(PredictWidth, 1.U(1.W)) >> ~getBasicBlockIdx(f2_ftq_req.fallThruAddr, f2_ftq_req.startAddr)
237*2a3050c2SJay  val f2_instr_range = f2_jump_range & f2_ftr_range
238*2a3050c2SJay  val f2_pf_vec = VecInit((0 until PredictWidth).map(i => (!isNextLine(f2_pc(i), f2_ftq_req.startAddr) && f2_except_pf(0)   ||  isNextLine(f2_pc(i), f2_ftq_req.startAddr) && f2_doubleLine &&  f2_except_pf(1))))
239*2a3050c2SJay  val f2_af_vec = VecInit((0 until PredictWidth).map(i => (!isNextLine(f2_pc(i), f2_ftq_req.startAddr) && f2_except_af(0)   ||  isNextLine(f2_pc(i), f2_ftq_req.startAddr) && f2_doubleLine && f2_except_af(1))))
240*2a3050c2SJay
2411d8f4dcbSJay  val f2_paddrs       = VecInit((0 until PortNumber).map(i => fromICache(i).bits.paddr))
2421d8f4dcbSJay  val f2_perf_info    = io.icachePerfInfo
24309c6f1ddSLingrui98
244*2a3050c2SJay  def cut(cacheline: UInt, cutPtr: Vec[UInt]) : Vec[UInt] ={
24509c6f1ddSLingrui98    if(HasCExtension){
24609c6f1ddSLingrui98      val result   = Wire(Vec(PredictWidth + 1, UInt(16.W)))
24709c6f1ddSLingrui98      val dataVec  = cacheline.asTypeOf(Vec(blockBytes * 2/ 2, UInt(16.W)))
24809c6f1ddSLingrui98      (0 until PredictWidth + 1).foreach( i =>
249*2a3050c2SJay        result(i) := dataVec(cutPtr(i))
25009c6f1ddSLingrui98      )
25109c6f1ddSLingrui98      result
25209c6f1ddSLingrui98    } else {
25309c6f1ddSLingrui98      val result   = Wire(Vec(PredictWidth, UInt(32.W)) )
25409c6f1ddSLingrui98      val dataVec  = cacheline.asTypeOf(Vec(blockBytes * 2/ 4, UInt(32.W)))
25509c6f1ddSLingrui98      (0 until PredictWidth).foreach( i =>
256*2a3050c2SJay        result(i) := dataVec(cutPtr(i))
25709c6f1ddSLingrui98      )
25809c6f1ddSLingrui98      result
25909c6f1ddSLingrui98    }
26009c6f1ddSLingrui98  }
26109c6f1ddSLingrui98
262*2a3050c2SJay  val f2_datas        = VecInit((0 until PortNumber).map(i => f2_cache_response_data(i)))
263*2a3050c2SJay  val f2_cut_data = cut( Cat(f2_datas.map(cacheline => cacheline.asUInt ).reverse).asUInt, f2_cut_ptr )
264*2a3050c2SJay
265*2a3050c2SJay  //** predecoder   **//
266*2a3050c2SJay  preDecoderIn.data := f2_cut_data
267*2a3050c2SJay//  preDecoderIn.lastHalfMatch := f2_lastHalfMatch
268*2a3050c2SJay  preDecoderIn.frontendTrigger := io.frontendTrigger
269*2a3050c2SJay  preDecoderIn.csrTriggerEnable := io.csrTriggerEnable
270*2a3050c2SJay  preDecoderIn.pc  := f2_pc
271*2a3050c2SJay
272*2a3050c2SJay  val f2_expd_instr   = preDecoderOut.expInstr
273*2a3050c2SJay  val f2_pd           = preDecoderOut.pd
274*2a3050c2SJay  val f2_jump_offset  = preDecoderOut.jumpOffset
275*2a3050c2SJay//  val f2_triggered    = preDecoderOut.triggered
276*2a3050c2SJay  val f2_hasHalfValid  =  preDecoderOut.hasHalfValid
277*2a3050c2SJay  val f2_crossPageFault = VecInit((0 until PredictWidth).map(i => isLastInLine(f2_pc(i)) && !f2_except_pf(0) && f2_doubleLine &&  f2_except_pf(1) && !f2_pd(i).isRVC ))
278*2a3050c2SJay
2791d8f4dcbSJay  val predecodeOutValid = WireInit(false.B)
2801d8f4dcbSJay
28109c6f1ddSLingrui98
282*2a3050c2SJay  /** Fetch Stage 3  */
28309c6f1ddSLingrui98  val f3_valid          = RegInit(false.B)
28409c6f1ddSLingrui98  val f3_ftq_req        = RegEnable(next = f2_ftq_req,    enable=f2_fire)
28509c6f1ddSLingrui98  val f3_situation      = RegEnable(next = f2_situation,  enable=f2_fire)
28609c6f1ddSLingrui98  val f3_doubleLine     = RegEnable(next = f2_doubleLine, enable=f2_fire)
2871d8f4dcbSJay  val f3_fire           = io.toIbuffer.fire()
2881d8f4dcbSJay
2891d8f4dcbSJay  f3_ready := io.toIbuffer.ready || !f3_valid
29009c6f1ddSLingrui98
29109c6f1ddSLingrui98  val f3_cut_data       = RegEnable(next = f2_cut_data, enable=f2_fire)
2921d8f4dcbSJay
29309c6f1ddSLingrui98  val f3_except_pf      = RegEnable(next = f2_except_pf, enable = f2_fire)
29409c6f1ddSLingrui98  val f3_except_af      = RegEnable(next = f2_except_af, enable = f2_fire)
2950be662e4SJay  val f3_mmio           = RegEnable(next = f2_mmio   , enable = f2_fire)
29609c6f1ddSLingrui98
297*2a3050c2SJay  val f3_expd_instr     = RegEnable(next = f2_expd_instr,  enable = f2_fire)
298*2a3050c2SJay  val f3_pd             = RegEnable(next = f2_pd,          enable = f2_fire)
299*2a3050c2SJay  val f3_jump_offset    = RegEnable(next = f2_jump_offset, enable = f2_fire)
300*2a3050c2SJay  val f3_af_vec         = RegEnable(next = f2_af_vec,      enable = f2_fire)
301*2a3050c2SJay  val f3_pf_vec         = RegEnable(next = f2_pf_vec ,     enable = f2_fire)
302*2a3050c2SJay  val f3_pc             = RegEnable(next = f2_pc,          enable = f2_fire)
303*2a3050c2SJay  val f3_half_snpc        = RegEnable(next = f2_half_snpc, enable = f2_fire)
304*2a3050c2SJay  val f3_half_match     = RegEnable(next = f2_half_match,   enable = f2_fire)
305*2a3050c2SJay  val f3_instr_range    = RegEnable(next = f2_instr_range, enable = f2_fire)
306*2a3050c2SJay  val f3_foldpc         = RegEnable(next = f2_foldpc,      enable = f2_fire)
307*2a3050c2SJay  val f3_crossPageFault = RegEnable(next = f2_crossPageFault,      enable = f2_fire)
308*2a3050c2SJay  val f3_hasHalfValid   = RegEnable(next = f2_hasHalfValid,      enable = f2_fire)
30909c6f1ddSLingrui98  val f3_except         = VecInit((0 until 2).map{i => f3_except_pf(i) || f3_except_af(i)})
31009c6f1ddSLingrui98  val f3_has_except     = f3_valid && (f3_except_af.reduce(_||_) || f3_except_pf.reduce(_||_))
3111d8f4dcbSJay  val f3_pAddrs   = RegEnable(next = f2_paddrs, enable = f2_fire)
312a37fbf10SJay
313*2a3050c2SJay  /*** MMIO State Machine***/
314a37fbf10SJay  val f3_mmio_data    = Reg(UInt(maxInstrLen.W))
315a37fbf10SJay
316*2a3050c2SJay//  val f3_data = if(HasCExtension) Wire(Vec(PredictWidth + 1, UInt(16.W))) else Wire(Vec(PredictWidth, UInt(32.W)))
317*2a3050c2SJay//  f3_data       :=  f3_cut_data
31809c6f1ddSLingrui98
319*2a3050c2SJay  val mmio_idle :: mmio_send_req :: mmio_w_resp :: mmio_resend :: mmio_resend_w_resp :: mmio_wait_commit :: mmio_commited :: Nil = Enum(7)
320a37fbf10SJay  val mmio_state = RegInit(mmio_idle)
321a37fbf10SJay
3229bae7d6eSJay  val f3_req_is_mmio     = f3_mmio && f3_valid
323*2a3050c2SJay  val mmio_commit = VecInit(io.rob_commits.map{commit => commit.valid && commit.bits.ftqIdx === f3_ftq_req.ftqIdx &&  commit.bits.ftqOffset === 0.U}).asUInt.orR
324*2a3050c2SJay  val f3_mmio_req_commit = f3_req_is_mmio && mmio_state === mmio_commited
325a37fbf10SJay
326*2a3050c2SJay  val f3_mmio_to_commit =  f3_req_is_mmio && mmio_state === mmio_wait_commit
327a37fbf10SJay  val f3_mmio_to_commit_next = RegNext(f3_mmio_to_commit)
328a37fbf10SJay  val f3_mmio_can_go      = f3_mmio_to_commit && !f3_mmio_to_commit_next
329a37fbf10SJay
3309bae7d6eSJay  val f3_ftq_flush_self     = fromFtq.redirect.valid && RedirectLevel.flushItself(fromFtq.redirect.bits.level)
331167bcd01SJay  val f3_ftq_flush_by_older = fromFtq.redirect.valid && isBefore(fromFtq.redirect.bits.ftqIdx, f3_ftq_req.ftqIdx)
3329bae7d6eSJay
333167bcd01SJay  val f3_need_not_flush = f3_req_is_mmio && fromFtq.redirect.valid && !f3_ftq_flush_self && !f3_ftq_flush_by_older
3349bae7d6eSJay
3359bae7d6eSJay  when(f3_flush && !f3_need_not_flush)               {f3_valid := false.B}
336a37fbf10SJay  .elsewhen(f2_fire && !f2_flush )                   {f3_valid := true.B }
337a37fbf10SJay  .elsewhen(io.toIbuffer.fire() && !f3_req_is_mmio)          {f3_valid := false.B}
338a37fbf10SJay  .elsewhen{f3_req_is_mmio && f3_mmio_req_commit}            {f3_valid := false.B}
339a37fbf10SJay
340a37fbf10SJay  val f3_mmio_use_seq_pc = RegInit(false.B)
341a37fbf10SJay
342a37fbf10SJay  val (redirect_ftqIdx, redirect_ftqOffset)  = (fromFtq.redirect.bits.ftqIdx,fromFtq.redirect.bits.ftqOffset)
343a37fbf10SJay  val redirect_mmio_req = fromFtq.redirect.valid && redirect_ftqIdx === f3_ftq_req.ftqIdx && redirect_ftqOffset === 0.U
344a37fbf10SJay
345a37fbf10SJay  when(RegNext(f2_fire && !f2_flush) && f3_req_is_mmio)        { f3_mmio_use_seq_pc := true.B  }
346a37fbf10SJay  .elsewhen(redirect_mmio_req)                                 { f3_mmio_use_seq_pc := false.B }
347a37fbf10SJay
348a37fbf10SJay  f3_ready := Mux(f3_req_is_mmio, io.toIbuffer.ready && f3_mmio_req_commit || !f3_valid , io.toIbuffer.ready || !f3_valid)
349a37fbf10SJay
350a37fbf10SJay  when(fromUncache.fire())    {f3_mmio_data   :=  fromUncache.bits.data}
351a37fbf10SJay
352a37fbf10SJay
353a37fbf10SJay  switch(mmio_state){
354a37fbf10SJay    is(mmio_idle){
3559bae7d6eSJay      when(f3_req_is_mmio){
356a37fbf10SJay        mmio_state :=  mmio_send_req
357a37fbf10SJay      }
358a37fbf10SJay    }
359a37fbf10SJay
360a37fbf10SJay    is(mmio_send_req){
361a37fbf10SJay      mmio_state :=  Mux(toUncache.fire(), mmio_w_resp, mmio_send_req )
362a37fbf10SJay    }
363a37fbf10SJay
364a37fbf10SJay    is(mmio_w_resp){
365a37fbf10SJay      when(fromUncache.fire()){
366a37fbf10SJay          val isRVC =  fromUncache.bits.data(1,0) =/= 3.U
367*2a3050c2SJay          mmio_state :=  Mux(isRVC, mmio_resend , mmio_wait_commit)
368a37fbf10SJay      }
369a37fbf10SJay    }
370a37fbf10SJay
371a37fbf10SJay    is(mmio_resend){
372a37fbf10SJay      mmio_state :=  Mux(toUncache.fire(), mmio_resend_w_resp, mmio_resend )
373a37fbf10SJay    }
374a37fbf10SJay
375a37fbf10SJay    is(mmio_resend_w_resp){
376a37fbf10SJay      when(fromUncache.fire()){
377*2a3050c2SJay          mmio_state :=  mmio_wait_commit
378a37fbf10SJay      }
379a37fbf10SJay    }
380a37fbf10SJay
381*2a3050c2SJay    is(mmio_wait_commit){
382*2a3050c2SJay      when(mmio_commit){
383*2a3050c2SJay          mmio_state  :=  mmio_commited
384a37fbf10SJay      }
385a37fbf10SJay    }
386*2a3050c2SJay
387*2a3050c2SJay    is(mmio_commited){
388*2a3050c2SJay        mmio_state := mmio_idle
389*2a3050c2SJay    }
390a37fbf10SJay  }
391a37fbf10SJay
392167bcd01SJay  when(f3_ftq_flush_self || f3_ftq_flush_by_older)  {
3939bae7d6eSJay    mmio_state := mmio_idle
3949bae7d6eSJay    f3_mmio_data := 0.U
3959bae7d6eSJay  }
3969bae7d6eSJay
397a37fbf10SJay  toUncache.valid     :=  ((mmio_state === mmio_send_req) || (mmio_state === mmio_resend)) && f3_req_is_mmio
398a37fbf10SJay  toUncache.bits.addr := Mux((mmio_state === mmio_resend), f3_pAddrs(0) + 2.U, f3_pAddrs(0))
399a37fbf10SJay  fromUncache.ready   := true.B
400a37fbf10SJay
40109c6f1ddSLingrui98
402*2a3050c2SJay  val f3_lastHalf       = RegInit(0.U.asTypeOf(new LastHalfInfo))
40309c6f1ddSLingrui98
40409c6f1ddSLingrui98  val f3_predecode_range = VecInit(preDecoderOut.pd.map(inst => inst.valid)).asUInt
4050be662e4SJay  val f3_mmio_range      = VecInit((0 until PredictWidth).map(i => if(i ==0) true.B else false.B))
406*2a3050c2SJay  val f3_instr_valid     = Wire(Vec(PredictWidth, Bool()))
40709c6f1ddSLingrui98
408*2a3050c2SJay  /*** prediction result check   ***/
409*2a3050c2SJay  checkerIn.ftqOffset   := f3_ftq_req.ftqOffset
410*2a3050c2SJay  checkerIn.jumpOffset  := f3_jump_offset
411*2a3050c2SJay  checkerIn.target      := f3_ftq_req.target
412*2a3050c2SJay  checkerIn.instrRange  := f3_instr_range.asTypeOf(Vec(PredictWidth, Bool()))
413*2a3050c2SJay  checkerIn.instrValid  := f3_instr_valid.asTypeOf(Vec(PredictWidth, Bool()))
414*2a3050c2SJay  checkerIn.pds         := f3_pd
415*2a3050c2SJay  checkerIn.pc          := f3_pc
416*2a3050c2SJay
417*2a3050c2SJay  /*** process half RVI in the last 2 Bytes  ***/
418*2a3050c2SJay
419*2a3050c2SJay  def hasLastHalf(idx: UInt) = {
420*2a3050c2SJay    !f3_pd(idx).isRVC && checkerOut.fixedRange(idx) && f3_instr_valid(idx) && !checkerOut.fixedTaken(idx) && !checkerOut.fixedMissPred(idx) && ! f3_req_is_mmio && !f3_ftq_req.oversize
421*2a3050c2SJay  }
422*2a3050c2SJay
423*2a3050c2SJay  val f3_last_validIdx             = ~ParallelPriorityEncoder(checkerOut.fixedRange.reverse)
424*2a3050c2SJay
425*2a3050c2SJay  val f3_hasLastHalf         = hasLastHalf((PredictWidth - 1).U)
426*2a3050c2SJay  val f3_false_lastHalf      = hasLastHalf(f3_last_validIdx)
427*2a3050c2SJay  val f3_false_snpc          = f3_half_snpc(f3_last_validIdx)
428*2a3050c2SJay
429*2a3050c2SJay  val f3_lastHalf_mask    = VecInit((0 until PredictWidth).map( i => if(i ==0) false.B else true.B )).asUInt()
430*2a3050c2SJay
431*2a3050c2SJay  when (f3_flush) {
432*2a3050c2SJay    f3_lastHalf.valid := false.B
433*2a3050c2SJay  }.elsewhen (f3_fire) {
434*2a3050c2SJay    f3_lastHalf.valid := f3_hasLastHalf
435*2a3050c2SJay    f3_lastHalf.middlePC := f3_ftq_req.fallThruAddr
436*2a3050c2SJay  }
437*2a3050c2SJay
438*2a3050c2SJay  f3_instr_valid := Mux(f3_lastHalf.valid,f3_hasHalfValid ,VecInit(f3_pd.map(inst => inst.valid)))
439*2a3050c2SJay
440*2a3050c2SJay  /*** frontend Trigger  ***/
441*2a3050c2SJay  frontendTrigger.io.pds  := f3_pd
442*2a3050c2SJay  frontendTrigger.io.pc   := f3_pc
443*2a3050c2SJay  frontendTrigger.io.data   := f3_cut_data
444*2a3050c2SJay
445*2a3050c2SJay  frontendTrigger.io.frontendTrigger  := io.frontendTrigger
446*2a3050c2SJay  frontendTrigger.io.csrTriggerEnable := io.csrTriggerEnable
447*2a3050c2SJay
448*2a3050c2SJay  val f3_triggered = frontendTrigger.io.triggered
449*2a3050c2SJay
450*2a3050c2SJay  /*** send to Ibuffer  ***/
451*2a3050c2SJay
452*2a3050c2SJay  io.toIbuffer.valid            := f3_valid && (!f3_req_is_mmio || f3_mmio_can_go) && !f3_flush
453*2a3050c2SJay  io.toIbuffer.bits.instrs      := f3_expd_instr
454*2a3050c2SJay  io.toIbuffer.bits.valid       := f3_instr_valid.asUInt
455*2a3050c2SJay  io.toIbuffer.bits.enqEnable   := checkerOut.fixedRange.asUInt & f3_instr_valid.asUInt
456*2a3050c2SJay  io.toIbuffer.bits.pd          := f3_pd
45709c6f1ddSLingrui98  io.toIbuffer.bits.ftqPtr      := f3_ftq_req.ftqIdx
458*2a3050c2SJay  io.toIbuffer.bits.pc          := f3_pc
459*2a3050c2SJay  io.toIbuffer.bits.ftqOffset.zipWithIndex.map{case(a, i) => a.bits := i.U; a.valid := checkerOut.fixedTaken(i) && !f3_req_is_mmio}
460*2a3050c2SJay  io.toIbuffer.bits.foldpc      := f3_foldpc
461*2a3050c2SJay  io.toIbuffer.bits.ipf         := f3_pf_vec
462*2a3050c2SJay  io.toIbuffer.bits.acf         := f3_af_vec
463*2a3050c2SJay  io.toIbuffer.bits.crossPageIPFFix := f3_crossPageFault
464*2a3050c2SJay  io.toIbuffer.bits.triggered   := f3_triggered
465*2a3050c2SJay
466*2a3050c2SJay  val lastHalfMask = VecInit((0 until PredictWidth).map(i => if(i ==0) false.B else true.B))
467*2a3050c2SJay  when(f3_lastHalf.valid){
468*2a3050c2SJay    io.toIbuffer.bits.enqEnable := checkerOut.fixedRange.asUInt & f3_instr_valid.asUInt & lastHalfMask.asUInt
469*2a3050c2SJay    io.toIbuffer.bits.valid     := f3_lastHalf_mask & f3_instr_valid.asUInt
470*2a3050c2SJay  }
471*2a3050c2SJay
472*2a3050c2SJay  /** external predecode for MMIO instruction */
473*2a3050c2SJay  when(f3_req_is_mmio){
474*2a3050c2SJay    val inst  = Cat(f3_mmio_data(31,16), f3_mmio_data(15,0))
475*2a3050c2SJay    val currentIsRVC   = isRVC(inst)
476*2a3050c2SJay
477*2a3050c2SJay    val brType::isCall::isRet::Nil = brInfo(inst)
478*2a3050c2SJay    val jalOffset = jal_offset(inst, currentIsRVC)
479*2a3050c2SJay    val brOffset  = br_offset(inst, currentIsRVC)
480*2a3050c2SJay
481*2a3050c2SJay    io.toIbuffer.bits.instrs (0) := new RVCDecoder(inst, XLEN).decode.bits
482*2a3050c2SJay
483*2a3050c2SJay    io.toIbuffer.bits.pd(0).valid   := true.B
484*2a3050c2SJay    io.toIbuffer.bits.pd(0).isRVC   := currentIsRVC
485*2a3050c2SJay    io.toIbuffer.bits.pd(0).brType  := brType
486*2a3050c2SJay    io.toIbuffer.bits.pd(0).isCall  := isCall
487*2a3050c2SJay    io.toIbuffer.bits.pd(0).isRet   := isRet
488*2a3050c2SJay
489*2a3050c2SJay    io.toIbuffer.bits.enqEnable   := f3_mmio_range.asUInt
490*2a3050c2SJay  }
491*2a3050c2SJay
49209c6f1ddSLingrui98
49309c6f1ddSLingrui98  //Write back to Ftq
494a37fbf10SJay  val f3_cache_fetch = f3_valid && !(f2_fire && !f2_flush)
495a37fbf10SJay  val finishFetchMaskReg = RegNext(f3_cache_fetch)
496a37fbf10SJay
497*2a3050c2SJay  val mmioFlushWb = Wire(Valid(new PredecodeWritebackBundle))
4980be662e4SJay  val f3_mmio_missOffset = Wire(ValidUndirectioned(UInt(log2Ceil(PredictWidth).W)))
499a37fbf10SJay  f3_mmio_missOffset.valid := f3_req_is_mmio
5000be662e4SJay  f3_mmio_missOffset.bits  := 0.U
5010be662e4SJay
502*2a3050c2SJay  mmioFlushWb.valid           := (f3_req_is_mmio && mmio_state === mmio_wait_commit && RegNext(fromUncache.fire())  && f3_mmio_use_seq_pc)
503*2a3050c2SJay  mmioFlushWb.bits.pc         := f3_pc
504*2a3050c2SJay  mmioFlushWb.bits.pd         := f3_pd
505*2a3050c2SJay  mmioFlushWb.bits.pd.zipWithIndex.map{case(instr,i) => instr.valid :=  f3_mmio_range(i)}
506*2a3050c2SJay  mmioFlushWb.bits.ftqIdx     := f3_ftq_req.ftqIdx
507*2a3050c2SJay  mmioFlushWb.bits.ftqOffset  := f3_ftq_req.ftqOffset.bits
508*2a3050c2SJay  mmioFlushWb.bits.misOffset  := f3_mmio_missOffset
509*2a3050c2SJay  mmioFlushWb.bits.cfiOffset  := DontCare
510*2a3050c2SJay  mmioFlushWb.bits.target     := Mux((f3_mmio_data(1,0) =/= 3.U), f3_ftq_req.startAddr + 2.U , f3_ftq_req.startAddr + 4.U)
511*2a3050c2SJay  mmioFlushWb.bits.jalTarget  := DontCare
512*2a3050c2SJay  mmioFlushWb.bits.instrRange := f3_mmio_range
51309c6f1ddSLingrui98
514*2a3050c2SJay  mmio_redirect := (f3_req_is_mmio && mmio_state === mmio_wait_commit && RegNext(fromUncache.fire())  && f3_mmio_use_seq_pc)
515*2a3050c2SJay
516*2a3050c2SJay  /* ---------------------------------------------------------------------
517*2a3050c2SJay   * Ftq Write back :
518*2a3050c2SJay   *
519*2a3050c2SJay   * ---------------------------------------------------------------------
520*2a3050c2SJay   */
521*2a3050c2SJay  val wb_valid          = RegNext(RegNext(f2_fire && !f2_flush) && !f3_req_is_mmio && !f3_flush)
522*2a3050c2SJay  val wb_ftq_req        = RegNext(f3_ftq_req)
523*2a3050c2SJay
524*2a3050c2SJay  val wb_check_result   = RegNext(checkerOut)
525*2a3050c2SJay  val wb_instr_range    = RegNext(io.toIbuffer.bits.enqEnable)
526*2a3050c2SJay  val wb_pc             = RegNext(f3_pc)
527*2a3050c2SJay  val wb_pd             = RegNext(f3_pd)
528*2a3050c2SJay  val wb_instr_valid    = RegNext(f3_instr_valid)
529*2a3050c2SJay
530*2a3050c2SJay  /* false hit lastHalf */
531*2a3050c2SJay  val wb_lastIdx        = RegNext(f3_last_validIdx)
532*2a3050c2SJay  val wb_false_lastHalf = RegNext(f3_false_lastHalf) && wb_lastIdx =/= (PredictWidth - 1).U
533*2a3050c2SJay  val wb_false_target   = RegNext(f3_false_snpc)
534*2a3050c2SJay
535*2a3050c2SJay  val wb_half_flush = wb_false_lastHalf
536*2a3050c2SJay  val wb_half_target = wb_false_target
537*2a3050c2SJay
538*2a3050c2SJay  f3_wb_not_flush := wb_ftq_req.ftqIdx === f3_ftq_req.ftqIdx && f3_valid && wb_valid
539*2a3050c2SJay
540*2a3050c2SJay  val checkFlushWb = Wire(Valid(new PredecodeWritebackBundle))
541*2a3050c2SJay  checkFlushWb.valid                  := wb_valid
542*2a3050c2SJay  checkFlushWb.bits.pc                := wb_pc
543*2a3050c2SJay  checkFlushWb.bits.pd                := wb_pd
544*2a3050c2SJay  checkFlushWb.bits.pd.zipWithIndex.map{case(instr,i) => instr.valid := wb_instr_valid(i)}
545*2a3050c2SJay  checkFlushWb.bits.ftqIdx            := wb_ftq_req.ftqIdx
546*2a3050c2SJay  checkFlushWb.bits.ftqOffset         := wb_ftq_req.ftqOffset.bits
547*2a3050c2SJay  checkFlushWb.bits.misOffset.valid   := ParallelOR(wb_check_result.fixedMissPred) || wb_half_flush
548*2a3050c2SJay  checkFlushWb.bits.misOffset.bits    := Mux(wb_half_flush, (PredictWidth - 1).U, ParallelPriorityEncoder(wb_check_result.fixedMissPred))
549*2a3050c2SJay  checkFlushWb.bits.cfiOffset.valid   := ParallelOR(wb_check_result.fixedTaken)
550*2a3050c2SJay  checkFlushWb.bits.cfiOffset.bits    := ParallelPriorityEncoder(wb_check_result.fixedTaken)
551*2a3050c2SJay  checkFlushWb.bits.target            := Mux(wb_half_flush, wb_half_target, wb_check_result.fixedTarget(ParallelPriorityEncoder(wb_check_result.fixedMissPred)))
552*2a3050c2SJay  checkFlushWb.bits.jalTarget         := wb_check_result.fixedTarget(ParallelPriorityEncoder(VecInit(wb_pd.map{pd => pd.isJal })))
553*2a3050c2SJay  checkFlushWb.bits.instrRange        := wb_instr_range.asTypeOf(Vec(PredictWidth, Bool()))
554*2a3050c2SJay
555*2a3050c2SJay  toFtq.pdWb := Mux(f3_req_is_mmio, mmioFlushWb,  checkFlushWb)
556*2a3050c2SJay
557*2a3050c2SJay  wb_redirect := checkFlushWb.bits.misOffset.valid && wb_valid
55809c6f1ddSLingrui98
5591d8f4dcbSJay
5601d8f4dcbSJay  /** performance counter */
5611d8f4dcbSJay  val f3_perf_info     = RegEnable(next = f2_perf_info, enable = f2_fire)
5621d8f4dcbSJay  val f3_req_0    = io.toIbuffer.fire()
5631d8f4dcbSJay  val f3_req_1    = io.toIbuffer.fire() && f3_doubleLine
5641d8f4dcbSJay  val f3_hit_0    = io.toIbuffer.fire() && f3_perf_info.bank_hit(0)
5651d8f4dcbSJay  val f3_hit_1    = io.toIbuffer.fire() && f3_doubleLine & f3_perf_info.bank_hit(1)
5661d8f4dcbSJay  val f3_hit      = f3_perf_info.hit
567cd365d4cSrvcoresjw  val perfEvents = Seq(
568*2a3050c2SJay    ("frontendFlush                ", wb_redirect                                ),
569cd365d4cSrvcoresjw    ("ifu_req                      ", io.toIbuffer.fire()                        ),
5701d8f4dcbSJay    ("ifu_miss                     ", io.toIbuffer.fire() && !f3_perf_info.hit   ),
571cd365d4cSrvcoresjw    ("ifu_req_cacheline_0          ", f3_req_0                                   ),
572cd365d4cSrvcoresjw    ("ifu_req_cacheline_1          ", f3_req_1                                   ),
573cd365d4cSrvcoresjw    ("ifu_req_cacheline_0_hit      ", f3_hit_1                                   ),
574cd365d4cSrvcoresjw    ("ifu_req_cacheline_1_hit      ", f3_hit_1                                   ),
5751d8f4dcbSJay    ("only_0_hit                   ", f3_perf_info.only_0_hit       && io.toIbuffer.fire() ),
5761d8f4dcbSJay    ("only_0_miss                  ", f3_perf_info.only_0_miss      && io.toIbuffer.fire() ),
5771d8f4dcbSJay    ("hit_0_hit_1                  ", f3_perf_info.hit_0_hit_1      && io.toIbuffer.fire() ),
5781d8f4dcbSJay    ("hit_0_miss_1                 ", f3_perf_info.hit_0_miss_1     && io.toIbuffer.fire() ),
5791d8f4dcbSJay    ("miss_0_hit_1                 ", f3_perf_info.miss_0_hit_1     && io.toIbuffer.fire() ),
5801d8f4dcbSJay    ("miss_0_miss_1                ", f3_perf_info.miss_0_miss_1    && io.toIbuffer.fire() ),
581cd365d4cSrvcoresjw    ("cross_line_block             ", io.toIbuffer.fire() && f3_situation(0)     ),
582cd365d4cSrvcoresjw    ("fall_through_is_cacheline_end", io.toIbuffer.fire() && f3_situation(1)     ),
583cd365d4cSrvcoresjw  )
5841ca0e4f3SYinan Xu  generatePerfEvent()
58509c6f1ddSLingrui98
586f7c29b0aSJinYue  XSPerfAccumulate("ifu_req",   io.toIbuffer.fire() )
587f7c29b0aSJinYue  XSPerfAccumulate("ifu_miss",  io.toIbuffer.fire() && !f3_hit )
588f7c29b0aSJinYue  XSPerfAccumulate("ifu_req_cacheline_0", f3_req_0  )
589f7c29b0aSJinYue  XSPerfAccumulate("ifu_req_cacheline_1", f3_req_1  )
590f7c29b0aSJinYue  XSPerfAccumulate("ifu_req_cacheline_0_hit",   f3_hit_0 )
591f7c29b0aSJinYue  XSPerfAccumulate("ifu_req_cacheline_1_hit",   f3_hit_1 )
592*2a3050c2SJay  XSPerfAccumulate("frontendFlush",  wb_redirect )
5931d8f4dcbSJay  XSPerfAccumulate("only_0_hit",      f3_perf_info.only_0_hit   && io.toIbuffer.fire()  )
5941d8f4dcbSJay  XSPerfAccumulate("only_0_miss",     f3_perf_info.only_0_miss  && io.toIbuffer.fire()  )
5951d8f4dcbSJay  XSPerfAccumulate("hit_0_hit_1",     f3_perf_info.hit_0_hit_1  && io.toIbuffer.fire()  )
5961d8f4dcbSJay  XSPerfAccumulate("hit_0_miss_1",    f3_perf_info.hit_0_miss_1  && io.toIbuffer.fire()  )
5971d8f4dcbSJay  XSPerfAccumulate("miss_0_hit_1",    f3_perf_info.miss_0_hit_1   && io.toIbuffer.fire() )
5981d8f4dcbSJay  XSPerfAccumulate("miss_0_miss_1",   f3_perf_info.miss_0_miss_1 && io.toIbuffer.fire() )
599f7c29b0aSJinYue  XSPerfAccumulate("cross_line_block", io.toIbuffer.fire() && f3_situation(0) )
600f7c29b0aSJinYue  XSPerfAccumulate("fall_through_is_cacheline_end", io.toIbuffer.fire() && f3_situation(1) )
60109c6f1ddSLingrui98}
602