124519898SXuan Hu/*************************************************************************************** 224519898SXuan Hu* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences 324519898SXuan Hu* Copyright (c) 2020-2021 Peng Cheng Laboratory 424519898SXuan Hu* 524519898SXuan Hu* XiangShan is licensed under Mulan PSL v2. 624519898SXuan Hu* You can use this software according to the terms and conditions of the Mulan PSL v2. 724519898SXuan Hu* You may obtain a copy of Mulan PSL v2 at: 824519898SXuan Hu* http://license.coscl.org.cn/MulanPSL2 924519898SXuan Hu* 1024519898SXuan Hu* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 1124519898SXuan Hu* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 1224519898SXuan Hu* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 1324519898SXuan Hu* 1424519898SXuan Hu* See the Mulan PSL v2 for more details. 1524519898SXuan Hu***************************************************************************************/ 1624519898SXuan Hu 1724519898SXuan Hupackage xiangshan.backend 1824519898SXuan Hu 198891a219SYinan Xuimport org.chipsalliance.cde.config.Parameters 2024519898SXuan Huimport chisel3._ 2124519898SXuan Huimport chisel3.util._ 2224519898SXuan Huimport freechips.rocketchip.diplomacy.{LazyModule, LazyModuleImp} 2324519898SXuan Huimport utility._ 2424519898SXuan Huimport utils._ 2524519898SXuan Huimport xiangshan.ExceptionNO._ 2624519898SXuan Huimport xiangshan._ 2724519898SXuan Huimport xiangshan.backend.Bundles.{DecodedInst, DynInst, ExceptionInfo, ExuOutput} 282326221cSXuan Huimport xiangshan.backend.ctrlblock.{DebugLSIO, DebugLsInfoBundle, LsTopdownInfo, MemCtrl, RedirectGenerator} 2924519898SXuan Huimport xiangshan.backend.datapath.DataConfig.VAddrData 3024519898SXuan Huimport xiangshan.backend.decode.{DecodeStage, FusionDecoder} 3183ba63b3SXuan Huimport xiangshan.backend.dispatch.{CoreDispatchTopDownIO, Dispatch, DispatchQueue} 3224519898SXuan Huimport xiangshan.backend.fu.PFEvent 335110577fSZiyue Zhangimport xiangshan.backend.fu.vector.Bundles.{VType, Vl} 3415ed99a7SXuan Huimport xiangshan.backend.fu.wrapper.CSRToDecode 35870f462dSXuan Huimport xiangshan.backend.rename.{Rename, RenameTableWrapper, SnapshotGenerator} 3683ba63b3SXuan Huimport xiangshan.backend.rob.{Rob, RobCSRIO, RobCoreTopDownIO, RobDebugRollingIO, RobLsqIO, RobPtr} 376ce10964SXuan Huimport xiangshan.frontend.{FtqPtr, FtqRead, Ftq_RF_Components} 386ce10964SXuan Huimport xiangshan.mem.{LqPtr, LsqEnqIO} 3915ed99a7SXuan Huimport xiangshan.backend.issue.{FpScheduler, IntScheduler, MemScheduler, VfScheduler} 4024519898SXuan Hu 4124519898SXuan Huclass CtrlToFtqIO(implicit p: Parameters) extends XSBundle { 4224519898SXuan Hu val rob_commits = Vec(CommitWidth, Valid(new RobCommitInfo)) 4324519898SXuan Hu val redirect = Valid(new Redirect) 449342624fSGao-Zeyu val ftqIdxAhead = Vec(BackendRedirectNum, Valid(new FtqPtr)) 459342624fSGao-Zeyu val ftqIdxSelOH = Valid(UInt((BackendRedirectNum).W)) 4624519898SXuan Hu} 4724519898SXuan Hu 4824519898SXuan Huclass CtrlBlock(params: BackendParams)(implicit p: Parameters) extends LazyModule { 491ca4a39dSXuan Hu override def shouldBeInlined: Boolean = false 501ca4a39dSXuan Hu 5124519898SXuan Hu val rob = LazyModule(new Rob(params)) 5224519898SXuan Hu 5324519898SXuan Hu lazy val module = new CtrlBlockImp(this)(p, params) 5424519898SXuan Hu 556f483f86SXuan Hu val gpaMem = LazyModule(new GPAMem()) 5624519898SXuan Hu} 5724519898SXuan Hu 5824519898SXuan Huclass CtrlBlockImp( 5924519898SXuan Hu override val wrapper: CtrlBlock 6024519898SXuan Hu)(implicit 6124519898SXuan Hu p: Parameters, 6224519898SXuan Hu params: BackendParams 6324519898SXuan Hu) extends LazyModuleImp(wrapper) 6424519898SXuan Hu with HasXSParameter 6524519898SXuan Hu with HasCircularQueuePtrHelper 6624519898SXuan Hu with HasPerfEvents 6724519898SXuan Hu{ 6824519898SXuan Hu val pcMemRdIndexes = new NamedIndexes(Seq( 6924519898SXuan Hu "redirect" -> 1, 7024519898SXuan Hu "memPred" -> 1, 7124519898SXuan Hu "robFlush" -> 1, 7224519898SXuan Hu "load" -> params.LduCnt, 73b133b458SXuan Hu "hybrid" -> params.HyuCnt, 7483ba63b3SXuan Hu "store" -> (if(EnableStorePrefetchSMS) params.StaCnt else 0) 7524519898SXuan Hu )) 7624519898SXuan Hu 7724519898SXuan Hu private val numPcMemReadForExu = params.numPcReadPort 7824519898SXuan Hu private val numPcMemRead = pcMemRdIndexes.maxIdx 7924519898SXuan Hu 8029dbac5aSsinsanction // now pcMem read for exu is moved to PcTargetMem (OG0) 8124519898SXuan Hu println(s"pcMem read num: $numPcMemRead") 8224519898SXuan Hu println(s"pcMem read num for exu: $numPcMemReadForExu") 8324519898SXuan Hu 8424519898SXuan Hu val io = IO(new CtrlBlockIO()) 8524519898SXuan Hu 866f483f86SXuan Hu val gpaMem = wrapper.gpaMem.module 8724519898SXuan Hu val decode = Module(new DecodeStage) 8824519898SXuan Hu val fusionDecoder = Module(new FusionDecoder) 8924519898SXuan Hu val rat = Module(new RenameTableWrapper) 9024519898SXuan Hu val rename = Module(new Rename) 9124519898SXuan Hu val dispatch = Module(new Dispatch) 92c1e19666Sxiaofeibao-xjtu val intDq0 = Module(new DispatchQueue(dpParams.IntDqSize, RenameWidth, dpParams.IntDqDeqWidth/2, dqIndex = 0)) 93c1e19666Sxiaofeibao-xjtu val intDq1 = Module(new DispatchQueue(dpParams.IntDqSize, RenameWidth, dpParams.IntDqDeqWidth/2, dqIndex = 1)) 9460f0c5aeSxiaofeibao val fpDq = Module(new DispatchQueue(dpParams.FpDqSize, RenameWidth, dpParams.VecDqDeqWidth)) 9560f0c5aeSxiaofeibao val vecDq = Module(new DispatchQueue(dpParams.FpDqSize, RenameWidth, dpParams.VecDqDeqWidth)) 9624519898SXuan Hu val lsDq = Module(new DispatchQueue(dpParams.LsDqSize, RenameWidth, dpParams.LsDqDeqWidth)) 9724519898SXuan Hu val redirectGen = Module(new RedirectGenerator) 989477429fSsinceforYy private def hasRen: Boolean = true 999477429fSsinceforYy private val pcMem = Module(new SyncDataModuleTemplate(new Ftq_RF_Components, FtqSize, numPcMemRead, 1, "BackendPC", hasRen = hasRen)) 10024519898SXuan Hu private val rob = wrapper.rob.module 10124519898SXuan Hu private val memCtrl = Module(new MemCtrl(params)) 10224519898SXuan Hu 10324519898SXuan Hu private val disableFusion = decode.io.csrCtrl.singlestep || !decode.io.csrCtrl.fusion_enable 10424519898SXuan Hu 10524519898SXuan Hu private val s0_robFlushRedirect = rob.io.flushOut 10624519898SXuan Hu private val s1_robFlushRedirect = Wire(Valid(new Redirect)) 1075f8b6c9eSsinceforYy s1_robFlushRedirect.valid := GatedValidRegNext(s0_robFlushRedirect.valid, false.B) 10824519898SXuan Hu s1_robFlushRedirect.bits := RegEnable(s0_robFlushRedirect.bits, s0_robFlushRedirect.valid) 10924519898SXuan Hu 1109477429fSsinceforYy pcMem.io.ren.get(pcMemRdIndexes("robFlush").head) := s0_robFlushRedirect.valid 11124519898SXuan Hu pcMem.io.raddr(pcMemRdIndexes("robFlush").head) := s0_robFlushRedirect.bits.ftqIdx.value 112b1e92023SsinceforYy private val s1_robFlushPc = pcMem.io.rdata(pcMemRdIndexes("robFlush").head).getPc(RegEnable(s0_robFlushRedirect.bits.ftqOffset, s0_robFlushRedirect.valid)) 11324519898SXuan Hu private val s3_redirectGen = redirectGen.io.stage2Redirect 11424519898SXuan Hu private val s1_s3_redirect = Mux(s1_robFlushRedirect.valid, s1_robFlushRedirect, s3_redirectGen) 11524519898SXuan Hu private val s2_s4_pendingRedirectValid = RegInit(false.B) 11624519898SXuan Hu when (s1_s3_redirect.valid) { 11724519898SXuan Hu s2_s4_pendingRedirectValid := true.B 1185f8b6c9eSsinceforYy }.elsewhen (GatedValidRegNext(io.frontend.toFtq.redirect.valid)) { 11924519898SXuan Hu s2_s4_pendingRedirectValid := false.B 12024519898SXuan Hu } 12124519898SXuan Hu 12224519898SXuan Hu // Redirect will be RegNext at ExuBlocks and IssueBlocks 12324519898SXuan Hu val s2_s4_redirect = RegNextWithEnable(s1_s3_redirect) 12424519898SXuan Hu val s3_s5_redirect = RegNextWithEnable(s2_s4_redirect) 12524519898SXuan Hu 12624519898SXuan Hu private val delayedNotFlushedWriteBack = io.fromWB.wbData.map(x => { 12724519898SXuan Hu val valid = x.valid 128*54c6d89dSxiaofeibao-xjtu val killedByOlder = x.bits.robIdx.needFlush(Seq(s1_s3_redirect, s2_s4_redirect)) 12924519898SXuan Hu val delayed = Wire(Valid(new ExuOutput(x.bits.params))) 1305f8b6c9eSsinceforYy delayed.valid := GatedValidRegNext(valid && !killedByOlder) 13124519898SXuan Hu delayed.bits := RegEnable(x.bits, x.valid) 13296e858baSXuan Hu delayed.bits.debugInfo.writebackTime := GTimer() 13324519898SXuan Hu delayed 13483ba63b3SXuan Hu }).toSeq 135bd5909d0Sxiaofeibao-xjtu private val delayedWriteBack = Wire(chiselTypeOf(io.fromWB.wbData)) 136bd5909d0Sxiaofeibao-xjtu delayedWriteBack.zipWithIndex.map{ case (x,i) => 137bd5909d0Sxiaofeibao-xjtu x.valid := GatedValidRegNext(io.fromWB.wbData(i).valid) 138bd5909d0Sxiaofeibao-xjtu x.bits := delayedNotFlushedWriteBack(i).bits 139bd5909d0Sxiaofeibao-xjtu } 140571677c9Sxiaofeibao-xjtu val delayedNotFlushedWriteBackNeedFlush = Wire(Vec(params.allExuParams.filter(_.needExceptionGen).length, Bool())) 141571677c9Sxiaofeibao-xjtu delayedNotFlushedWriteBackNeedFlush := delayedNotFlushedWriteBack.filter(_.bits.params.needExceptionGen).map{ x => 142571677c9Sxiaofeibao-xjtu x.bits.exceptionVec.get.asUInt.orR || x.bits.flushPipe.getOrElse(false.B) || x.bits.replay.getOrElse(false.B) || 143571677c9Sxiaofeibao-xjtu (if (x.bits.trigger.nonEmpty) x.bits.trigger.get.getBackendCanFire else false.B) 144571677c9Sxiaofeibao-xjtu } 14524519898SXuan Hu 14685f51ecaSxiaofeibao-xjtu val wbDataNoStd = io.fromWB.wbData.filter(!_.bits.params.hasStdFu) 14747c01b71Sxiaofeibao-xjtu val intScheWbData = io.fromWB.wbData.filter(_.bits.params.schdType.isInstanceOf[IntScheduler]) 1485e7a1fcaSxiaofeibao val fpScheWbData = io.fromWB.wbData.filter(_.bits.params.schdType.isInstanceOf[FpScheduler]) 14947c01b71Sxiaofeibao-xjtu val vfScheWbData = io.fromWB.wbData.filter(_.bits.params.schdType.isInstanceOf[VfScheduler]) 150618b89e6Slewislzh val intCanCompress = intScheWbData.filter(_.bits.params.CanCompress) 151618b89e6Slewislzh val i2vWbData = intScheWbData.filter(_.bits.params.writeVecRf) 152618b89e6Slewislzh val f2vWbData = fpScheWbData.filter(_.bits.params.writeVecRf) 15347c01b71Sxiaofeibao-xjtu val memVloadWbData = io.fromWB.wbData.filter(x => x.bits.params.schdType.isInstanceOf[MemScheduler] && x.bits.params.hasVLoadFu) 15485f51ecaSxiaofeibao-xjtu private val delayedNotFlushedWriteBackNums = wbDataNoStd.map(x => { 15585f51ecaSxiaofeibao-xjtu val valid = x.valid 15685f51ecaSxiaofeibao-xjtu val killedByOlder = x.bits.robIdx.needFlush(Seq(s1_s3_redirect, s2_s4_redirect, s3_s5_redirect)) 15785f51ecaSxiaofeibao-xjtu val delayed = Wire(Valid(UInt(io.fromWB.wbData.size.U.getWidth.W))) 1585f8b6c9eSsinceforYy delayed.valid := GatedValidRegNext(valid && !killedByOlder) 159618b89e6Slewislzh val isIntSche = intCanCompress.contains(x) 1605e7a1fcaSxiaofeibao val isFpSche = fpScheWbData.contains(x) 16147c01b71Sxiaofeibao-xjtu val isVfSche = vfScheWbData.contains(x) 16247c01b71Sxiaofeibao-xjtu val isMemVload = memVloadWbData.contains(x) 163618b89e6Slewislzh val isi2v = i2vWbData.contains(x) 164618b89e6Slewislzh val isf2v = f2vWbData.contains(x) 165618b89e6Slewislzh val canSameRobidxWbData = if(isVfSche) { 166618b89e6Slewislzh i2vWbData ++ f2vWbData ++ vfScheWbData 167618b89e6Slewislzh } else if(isi2v) { 168618b89e6Slewislzh intCanCompress ++ fpScheWbData ++ vfScheWbData 169618b89e6Slewislzh } else if (isf2v) { 170618b89e6Slewislzh intCanCompress ++ fpScheWbData ++ vfScheWbData 171618b89e6Slewislzh } else if (isIntSche) { 172618b89e6Slewislzh intCanCompress ++ fpScheWbData 1735e7a1fcaSxiaofeibao } else if (isFpSche) { 174618b89e6Slewislzh intCanCompress ++ fpScheWbData 17547c01b71Sxiaofeibao-xjtu } else if (isMemVload) { 17647c01b71Sxiaofeibao-xjtu memVloadWbData 17747c01b71Sxiaofeibao-xjtu } else { 17847c01b71Sxiaofeibao-xjtu Seq(x) 17947c01b71Sxiaofeibao-xjtu } 18047c01b71Sxiaofeibao-xjtu val sameRobidxBools = VecInit(canSameRobidxWbData.map( wb => { 18185f51ecaSxiaofeibao-xjtu val killedByOlderThat = wb.bits.robIdx.needFlush(Seq(s1_s3_redirect, s2_s4_redirect, s3_s5_redirect)) 18285f51ecaSxiaofeibao-xjtu (wb.bits.robIdx === x.bits.robIdx) && wb.valid && x.valid && !killedByOlderThat && !killedByOlder 18385f51ecaSxiaofeibao-xjtu }).toSeq) 18441dbbdfdSsinceforYy delayed.bits := RegEnable(PopCount(sameRobidxBools), x.valid) 18585f51ecaSxiaofeibao-xjtu delayed 18685f51ecaSxiaofeibao-xjtu }).toSeq 18785f51ecaSxiaofeibao-xjtu 18824519898SXuan Hu private val exuPredecode = VecInit( 189*54c6d89dSxiaofeibao-xjtu io.fromWB.wbData.filter(_.bits.redirect.nonEmpty).map(x => x.bits.predecodeInfo.get).toSeq 19024519898SXuan Hu ) 19124519898SXuan Hu 192*54c6d89dSxiaofeibao-xjtu private val exuRedirects: Seq[ValidIO[Redirect]] = io.fromWB.wbData.filter(_.bits.redirect.nonEmpty).map(x => { 19324519898SXuan Hu val out = Wire(Valid(new Redirect())) 194*54c6d89dSxiaofeibao-xjtu out.valid := x.valid && x.bits.redirect.get.valid && x.bits.redirect.get.bits.cfiUpdate.isMisPred && !x.bits.robIdx.needFlush(Seq(s1_s3_redirect, s2_s4_redirect)) 19524519898SXuan Hu out.bits := x.bits.redirect.get.bits 196a63155a6SXuan Hu out.bits.debugIsCtrl := true.B 197a63155a6SXuan Hu out.bits.debugIsMemVio := false.B 19824519898SXuan Hu out 19983ba63b3SXuan Hu }).toSeq 200*54c6d89dSxiaofeibao-xjtu private val oldestOneHot = Redirect.selectOldestRedirect(exuRedirects) 201*54c6d89dSxiaofeibao-xjtu private val oldestExuRedirect = Mux1H(oldestOneHot, exuRedirects) 202*54c6d89dSxiaofeibao-xjtu private val oldestExuPredecode = Mux1H(oldestOneHot, exuPredecode) 20324519898SXuan Hu 20424519898SXuan Hu private val memViolation = io.fromMem.violation 20524519898SXuan Hu val loadReplay = Wire(ValidIO(new Redirect)) 206*54c6d89dSxiaofeibao-xjtu loadReplay.valid := GatedValidRegNext(memViolation.valid) 20724519898SXuan Hu loadReplay.bits := RegEnable(memViolation.bits, memViolation.valid) 208a63155a6SXuan Hu loadReplay.bits.debugIsCtrl := false.B 209a63155a6SXuan Hu loadReplay.bits.debugIsMemVio := true.B 21024519898SXuan Hu 211*54c6d89dSxiaofeibao-xjtu pcMem.io.ren.get(pcMemRdIndexes("redirect").head) := memViolation.valid 212*54c6d89dSxiaofeibao-xjtu pcMem.io.raddr(pcMemRdIndexes("redirect").head) := memViolation.bits.ftqIdx.value 213*54c6d89dSxiaofeibao-xjtu pcMem.io.ren.get(pcMemRdIndexes("memPred").head) := memViolation.valid 214*54c6d89dSxiaofeibao-xjtu pcMem.io.raddr(pcMemRdIndexes("memPred").head) := memViolation.bits.stFtqIdx.value 215*54c6d89dSxiaofeibao-xjtu redirectGen.io.memPredPcRead.data := pcMem.io.rdata(pcMemRdIndexes("memPred").head).getPc(RegEnable(memViolation.bits.stFtqOffset, memViolation.valid)) 21624519898SXuan Hu 21724519898SXuan Hu for ((pcMemIdx, i) <- pcMemRdIndexes("load").zipWithIndex) { 2188241cb85SXuan Hu // load read pcMem (s0) -> get rdata (s1) -> reg next in Memblock (s2) -> reg next in Memblock (s3) -> consumed by pf (s3) 219*54c6d89dSxiaofeibao-xjtu pcMem.io.ren.get(pcMemIdx) := io.memLdPcRead(i).valid 22024519898SXuan Hu pcMem.io.raddr(pcMemIdx) := io.memLdPcRead(i).ptr.value 221*54c6d89dSxiaofeibao-xjtu io.memLdPcRead(i).data := pcMem.io.rdata(pcMemIdx).getPc(RegEnable(io.memLdPcRead(i).offset, io.memLdPcRead(i).valid)) 22224519898SXuan Hu } 22324519898SXuan Hu 224b133b458SXuan Hu for ((pcMemIdx, i) <- pcMemRdIndexes("hybrid").zipWithIndex) { 2258241cb85SXuan Hu // load read pcMem (s0) -> get rdata (s1) -> reg next in Memblock (s2) -> reg next in Memblock (s3) -> consumed by pf (s3) 226*54c6d89dSxiaofeibao-xjtu pcMem.io.ren.get(pcMemIdx) := io.memHyPcRead(i).valid 227b133b458SXuan Hu pcMem.io.raddr(pcMemIdx) := io.memHyPcRead(i).ptr.value 228*54c6d89dSxiaofeibao-xjtu io.memHyPcRead(i).data := pcMem.io.rdata(pcMemIdx).getPc(RegEnable(io.memHyPcRead(i).offset, io.memHyPcRead(i).valid)) 229b133b458SXuan Hu } 230b133b458SXuan Hu 2314b0d80d8SXuan Hu if (EnableStorePrefetchSMS) { 2324b0d80d8SXuan Hu for ((pcMemIdx, i) <- pcMemRdIndexes("store").zipWithIndex) { 233*54c6d89dSxiaofeibao-xjtu pcMem.io.ren.get(pcMemIdx) := io.memStPcRead(i).valid 2344b0d80d8SXuan Hu pcMem.io.raddr(pcMemIdx) := io.memStPcRead(i).ptr.value 235*54c6d89dSxiaofeibao-xjtu io.memStPcRead(i).data := pcMem.io.rdata(pcMemIdx).getPc(RegEnable(io.memStPcRead(i).offset, io.memStPcRead(i).valid)) 2364b0d80d8SXuan Hu } 2374b0d80d8SXuan Hu } else { 23883ba63b3SXuan Hu io.memStPcRead.foreach(_.data := 0.U) 2394b0d80d8SXuan Hu } 2404b0d80d8SXuan Hu 24124519898SXuan Hu redirectGen.io.hartId := io.fromTop.hartId 242*54c6d89dSxiaofeibao-xjtu redirectGen.io.oldestExuRedirect.valid := GatedValidRegNext(oldestExuRedirect.valid) 243*54c6d89dSxiaofeibao-xjtu redirectGen.io.oldestExuRedirect.bits := RegEnable(oldestExuRedirect.bits, oldestExuRedirect.valid) 244*54c6d89dSxiaofeibao-xjtu redirectGen.io.oldestExuOutPredecode.valid := GatedValidRegNext(oldestExuPredecode.valid) 245*54c6d89dSxiaofeibao-xjtu redirectGen.io.oldestExuOutPredecode := RegEnable(oldestExuPredecode, oldestExuPredecode.valid) 24624519898SXuan Hu redirectGen.io.loadReplay <> loadReplay 247*54c6d89dSxiaofeibao-xjtu val loadRedirectPcRead = pcMem.io.rdata(pcMemRdIndexes("redirect").head).getPc(RegEnable(memViolation.bits.ftqOffset, memViolation.valid)) 248*54c6d89dSxiaofeibao-xjtu redirectGen.io.loadReplay.bits.cfiUpdate.pc := loadRedirectPcRead 249*54c6d89dSxiaofeibao-xjtu val load_pc_offset = Mux(loadReplay.bits.flushItself(), 0.U, Mux(loadReplay.bits.isRVC, 2.U, 4.U)) 250*54c6d89dSxiaofeibao-xjtu val load_target = loadRedirectPcRead + load_pc_offset 251*54c6d89dSxiaofeibao-xjtu redirectGen.io.loadReplay.bits.cfiUpdate.target := load_target 25224519898SXuan Hu 253*54c6d89dSxiaofeibao-xjtu redirectGen.io.robFlush := s1_robFlushRedirect 25424519898SXuan Hu 255ff7f931dSXuan Hu val s5_flushFromRobValidAhead = DelayN(s1_robFlushRedirect.valid, 4) 2565f8b6c9eSsinceforYy val s6_flushFromRobValid = GatedValidRegNext(s5_flushFromRobValidAhead) 25724519898SXuan Hu val frontendFlushBits = RegEnable(s1_robFlushRedirect.bits, s1_robFlushRedirect.valid) // ?? 25824519898SXuan Hu // When ROB commits an instruction with a flush, we notify the frontend of the flush without the commit. 25924519898SXuan Hu // Flushes to frontend may be delayed by some cycles and commit before flush causes errors. 26024519898SXuan Hu // Thus, we make all flush reasons to behave the same as exceptions for frontend. 26124519898SXuan Hu for (i <- 0 until CommitWidth) { 26224519898SXuan Hu // why flushOut: instructions with flushPipe are not commited to frontend 26324519898SXuan Hu // If we commit them to frontend, it will cause flush after commit, which is not acceptable by frontend. 26424519898SXuan Hu val s1_isCommit = rob.io.commits.commitValid(i) && rob.io.commits.isCommit && !s0_robFlushRedirect.valid 2655f8b6c9eSsinceforYy io.frontend.toFtq.rob_commits(i).valid := GatedValidRegNext(s1_isCommit) 26624519898SXuan Hu io.frontend.toFtq.rob_commits(i).bits := RegEnable(rob.io.commits.info(i), s1_isCommit) 26724519898SXuan Hu } 268ff7f931dSXuan Hu io.frontend.toFtq.redirect.valid := s6_flushFromRobValid || s3_redirectGen.valid 269ff7f931dSXuan Hu io.frontend.toFtq.redirect.bits := Mux(s6_flushFromRobValid, frontendFlushBits, s3_redirectGen.bits) 270ff7f931dSXuan Hu io.frontend.toFtq.ftqIdxSelOH.valid := s6_flushFromRobValid || redirectGen.io.stage2Redirect.valid 271ff7f931dSXuan Hu io.frontend.toFtq.ftqIdxSelOH.bits := Cat(s6_flushFromRobValid, redirectGen.io.stage2oldestOH & Fill(NumRedirect + 1, !s6_flushFromRobValid)) 2729342624fSGao-Zeyu 273*54c6d89dSxiaofeibao-xjtu //jmp/brh, sel oldest first, only use one read port 274*54c6d89dSxiaofeibao-xjtu io.frontend.toFtq.ftqIdxAhead(0).valid := RegNext(oldestExuRedirect.valid) && !s1_robFlushRedirect.valid && !s5_flushFromRobValidAhead 275*54c6d89dSxiaofeibao-xjtu io.frontend.toFtq.ftqIdxAhead(0).bits := RegEnable(oldestExuRedirect.bits.ftqIdx, oldestExuRedirect.valid) 2769342624fSGao-Zeyu //loadreplay 277ff7f931dSXuan Hu io.frontend.toFtq.ftqIdxAhead(NumRedirect).valid := loadReplay.valid && !s1_robFlushRedirect.valid && !s5_flushFromRobValidAhead 2789342624fSGao-Zeyu io.frontend.toFtq.ftqIdxAhead(NumRedirect).bits := loadReplay.bits.ftqIdx 2799342624fSGao-Zeyu //exception 280ff7f931dSXuan Hu io.frontend.toFtq.ftqIdxAhead.last.valid := s5_flushFromRobValidAhead 2819342624fSGao-Zeyu io.frontend.toFtq.ftqIdxAhead.last.bits := frontendFlushBits.ftqIdx 28205cc2a4eSXuan Hu 28305cc2a4eSXuan Hu io.frontend.canAccept := decode.io.canAccept 28405cc2a4eSXuan Hu 28524519898SXuan Hu // Be careful here: 28624519898SXuan Hu // T0: rob.io.flushOut, s0_robFlushRedirect 28724519898SXuan Hu // T1: s1_robFlushRedirect, rob.io.exception.valid 28824519898SXuan Hu // T2: csr.redirect.valid 28924519898SXuan Hu // T3: csr.exception.valid 29024519898SXuan Hu // T4: csr.trapTarget 29124519898SXuan Hu // T5: ctrlBlock.trapTarget 29224519898SXuan Hu // T6: io.frontend.toFtq.stage2Redirect.valid 29324519898SXuan Hu val s2_robFlushPc = RegEnable(Mux(s1_robFlushRedirect.bits.flushItself(), 29424519898SXuan Hu s1_robFlushPc, // replay inst 295870f462dSXuan Hu s1_robFlushPc + Mux(s1_robFlushRedirect.bits.isRVC, 2.U, 4.U) // flush pipe 29624519898SXuan Hu ), s1_robFlushRedirect.valid) 29724519898SXuan Hu private val s5_csrIsTrap = DelayN(rob.io.exception.valid, 4) 298dcdd1406SXuan Hu private val s5_trapTargetFromCsr = io.robio.csr.trapTarget 29924519898SXuan Hu 300dcdd1406SXuan Hu val flushTarget = Mux(s5_csrIsTrap, s5_trapTargetFromCsr, s2_robFlushPc) 301ff7f931dSXuan Hu when (s6_flushFromRobValid) { 30224519898SXuan Hu io.frontend.toFtq.redirect.bits.level := RedirectLevel.flush 30374f21f21SsinceforYy io.frontend.toFtq.redirect.bits.cfiUpdate.target := RegEnable(flushTarget, s5_flushFromRobValidAhead) 30424519898SXuan Hu } 30524519898SXuan Hu 3066f483f86SXuan Hu for (i <- 0 until DecodeWidth) { 3076f483f86SXuan Hu gpaMem.io.fromIFU := io.frontend.fromIfu 3086f483f86SXuan Hu gpaMem.io.exceptionReadAddr.valid := rob.io.readGPAMemAddr.valid 3096f483f86SXuan Hu gpaMem.io.exceptionReadAddr.bits.ftqPtr := rob.io.readGPAMemAddr.bits.ftqPtr 3106f483f86SXuan Hu gpaMem.io.exceptionReadAddr.bits.ftqOffset := rob.io.readGPAMemAddr.bits.ftqOffset 3116f483f86SXuan Hu } 3126f483f86SXuan Hu 31324519898SXuan Hu // vtype commit 31415ed99a7SXuan Hu decode.io.fromCSR := io.fromCSR.toDecode 31586727929Ssinsanction decode.io.isResumeVType := rob.io.toDecode.isResumeVType 31681535d7bSsinsanction decode.io.commitVType := rob.io.toDecode.commitVType 31781535d7bSsinsanction decode.io.walkVType := rob.io.toDecode.walkVType 31824519898SXuan Hu 319e25c13faSXuan Hu decode.io.redirect := s1_s3_redirect.valid || s2_s4_pendingRedirectValid 320f6458cc1SZiyue Zhang decode.io.vtypeRedirect := s1_s3_redirect.valid 32124519898SXuan Hu 32224519898SXuan Hu decode.io.in.zip(io.frontend.cfVec).foreach { case (decodeIn, frontendCf) => 32324519898SXuan Hu decodeIn.valid := frontendCf.valid 32424519898SXuan Hu frontendCf.ready := decodeIn.ready 32524519898SXuan Hu decodeIn.bits.connectCtrlFlow(frontendCf.bits) 32624519898SXuan Hu } 32724519898SXuan Hu decode.io.csrCtrl := RegNext(io.csrCtrl) 32824519898SXuan Hu decode.io.intRat <> rat.io.intReadPorts 32924519898SXuan Hu decode.io.fpRat <> rat.io.fpReadPorts 33024519898SXuan Hu decode.io.vecRat <> rat.io.vecReadPorts 331368cbcecSxiaofeibao decode.io.v0Rat <> rat.io.v0ReadPorts 332368cbcecSxiaofeibao decode.io.vlRat <> rat.io.vlReadPorts 33324519898SXuan Hu decode.io.fusion := 0.U.asTypeOf(decode.io.fusion) // Todo 334870f462dSXuan Hu decode.io.stallReason.in <> io.frontend.stallReason 33524519898SXuan Hu 336fa7f2c26STang Haojin // snapshot check 337c4b56310SHaojin Tang class CFIRobIdx extends Bundle { 338c4b56310SHaojin Tang val robIdx = Vec(RenameWidth, new RobPtr) 339c4b56310SHaojin Tang val isCFI = Vec(RenameWidth, Bool()) 340c4b56310SHaojin Tang } 341c4b56310SHaojin Tang val genSnapshot = Cat(rename.io.out.map(out => out.fire && out.bits.snapshot)).orR 342c4b56310SHaojin Tang val snpt = Module(new SnapshotGenerator(0.U.asTypeOf(new CFIRobIdx))) 343c4b56310SHaojin Tang snpt.io.enq := genSnapshot 344c4b56310SHaojin Tang snpt.io.enqData.robIdx := rename.io.out.map(_.bits.robIdx) 345c4b56310SHaojin Tang snpt.io.enqData.isCFI := rename.io.out.map(_.bits.snapshot) 346fa7f2c26STang Haojin snpt.io.deq := snpt.io.valids(snpt.io.deqPtr.value) && rob.io.commits.isCommit && 347c4b56310SHaojin Tang Cat(rob.io.commits.commitValid.zip(rob.io.commits.robIdx).map(x => x._1 && x._2 === snpt.io.snapshots(snpt.io.deqPtr.value).robIdx.head)).orR 348c4b56310SHaojin Tang snpt.io.redirect := s1_s3_redirect.valid 349c4b56310SHaojin Tang val flushVec = VecInit(snpt.io.snapshots.map { snapshot => 350c4b56310SHaojin Tang val notCFIMask = snapshot.isCFI.map(~_) 35137d77575SzhanglyGit val shouldFlush = snapshot.robIdx.map(robIdx => robIdx >= s1_s3_redirect.bits.robIdx || robIdx.value === s1_s3_redirect.bits.robIdx.value) 35237d77575SzhanglyGit val shouldFlushMask = (1 to RenameWidth).map(shouldFlush take _ reduce (_ || _)) 35337d77575SzhanglyGit s1_s3_redirect.valid && Cat(shouldFlushMask.zip(notCFIMask).map(x => x._1 | x._2)).andR 354c4b56310SHaojin Tang }) 355a6742963SHaojin Tang val flushVecNext = flushVec zip snpt.io.valids map (x => GatedValidRegNext(x._1 && x._2, false.B)) 356c4b56310SHaojin Tang snpt.io.flushVec := flushVecNext 357fa7f2c26STang Haojin 358fa7f2c26STang Haojin val useSnpt = VecInit.tabulate(RenameSnapshotNum)(idx => 359780712aaSxiaofeibao-xjtu snpt.io.valids(idx) && (s1_s3_redirect.bits.robIdx > snpt.io.snapshots(idx).robIdx.head || 360780712aaSxiaofeibao-xjtu !s1_s3_redirect.bits.flushItself() && s1_s3_redirect.bits.robIdx === snpt.io.snapshots(idx).robIdx.head) 361c61abc0cSXuan Hu ).reduceTree(_ || _) 362c61abc0cSXuan Hu val snptSelect = MuxCase( 363c61abc0cSXuan Hu 0.U(log2Ceil(RenameSnapshotNum).W), 364fa7f2c26STang Haojin (1 to RenameSnapshotNum).map(i => (snpt.io.enqPtr - i.U).value).map(idx => 365780712aaSxiaofeibao-xjtu (snpt.io.valids(idx) && (s1_s3_redirect.bits.robIdx > snpt.io.snapshots(idx).robIdx.head || 366780712aaSxiaofeibao-xjtu !s1_s3_redirect.bits.flushItself() && s1_s3_redirect.bits.robIdx === snpt.io.snapshots(idx).robIdx.head), idx) 367c61abc0cSXuan Hu ) 368c61abc0cSXuan Hu ) 369fa7f2c26STang Haojin 370fa7f2c26STang Haojin rob.io.snpt.snptEnq := DontCare 371fa7f2c26STang Haojin rob.io.snpt.snptDeq := snpt.io.deq 372fa7f2c26STang Haojin rob.io.snpt.useSnpt := useSnpt 373fa7f2c26STang Haojin rob.io.snpt.snptSelect := snptSelect 374c4b56310SHaojin Tang rob.io.snpt.flushVec := flushVecNext 375c4b56310SHaojin Tang rat.io.snpt.snptEnq := genSnapshot 376fa7f2c26STang Haojin rat.io.snpt.snptDeq := snpt.io.deq 377fa7f2c26STang Haojin rat.io.snpt.useSnpt := useSnpt 378fa7f2c26STang Haojin rat.io.snpt.snptSelect := snptSelect 379c4b56310SHaojin Tang rat.io.snpt.flushVec := flushVec 380fa7f2c26STang Haojin 38124519898SXuan Hu val decodeHasException = decode.io.out.map(x => x.bits.exceptionVec(instrPageFault) || x.bits.exceptionVec(instrAccessFault)) 38224519898SXuan Hu // fusion decoder 38324519898SXuan Hu for (i <- 0 until DecodeWidth) { 38424519898SXuan Hu fusionDecoder.io.in(i).valid := decode.io.out(i).valid && !(decodeHasException(i) || disableFusion) 38524519898SXuan Hu fusionDecoder.io.in(i).bits := decode.io.out(i).bits.instr 38624519898SXuan Hu if (i > 0) { 38724519898SXuan Hu fusionDecoder.io.inReady(i - 1) := decode.io.out(i).ready 38824519898SXuan Hu } 38924519898SXuan Hu } 39024519898SXuan Hu 39124519898SXuan Hu private val decodePipeRename = Wire(Vec(RenameWidth, DecoupledIO(new DecodedInst))) 39224519898SXuan Hu 39324519898SXuan Hu for (i <- 0 until RenameWidth) { 39424519898SXuan Hu PipelineConnect(decode.io.out(i), decodePipeRename(i), rename.io.in(i).ready, 39524519898SXuan Hu s1_s3_redirect.valid || s2_s4_pendingRedirectValid, moduleName = Some("decodePipeRenameModule")) 39624519898SXuan Hu 39724519898SXuan Hu decodePipeRename(i).ready := rename.io.in(i).ready 39824519898SXuan Hu rename.io.in(i).valid := decodePipeRename(i).valid && !fusionDecoder.io.clear(i) 39924519898SXuan Hu rename.io.in(i).bits := decodePipeRename(i).bits 40024519898SXuan Hu } 40124519898SXuan Hu 40224519898SXuan Hu for (i <- 0 until RenameWidth - 1) { 40324519898SXuan Hu fusionDecoder.io.dec(i) := decodePipeRename(i).bits 40424519898SXuan Hu rename.io.fusionInfo(i) := fusionDecoder.io.info(i) 40524519898SXuan Hu 40624519898SXuan Hu // update the first RenameWidth - 1 instructions 40724519898SXuan Hu decode.io.fusion(i) := fusionDecoder.io.out(i).valid && rename.io.out(i).fire 40824519898SXuan Hu when (fusionDecoder.io.out(i).valid) { 40924519898SXuan Hu fusionDecoder.io.out(i).bits.update(rename.io.in(i).bits) 41024519898SXuan Hu // TODO: remove this dirty code for ftq update 41124519898SXuan Hu val sameFtqPtr = rename.io.in(i).bits.ftqPtr.value === rename.io.in(i + 1).bits.ftqPtr.value 41224519898SXuan Hu val ftqOffset0 = rename.io.in(i).bits.ftqOffset 41324519898SXuan Hu val ftqOffset1 = rename.io.in(i + 1).bits.ftqOffset 41424519898SXuan Hu val ftqOffsetDiff = ftqOffset1 - ftqOffset0 41524519898SXuan Hu val cond1 = sameFtqPtr && ftqOffsetDiff === 1.U 41624519898SXuan Hu val cond2 = sameFtqPtr && ftqOffsetDiff === 2.U 41724519898SXuan Hu val cond3 = !sameFtqPtr && ftqOffset1 === 0.U 41824519898SXuan Hu val cond4 = !sameFtqPtr && ftqOffset1 === 1.U 41924519898SXuan Hu rename.io.in(i).bits.commitType := Mux(cond1, 4.U, Mux(cond2, 5.U, Mux(cond3, 6.U, 7.U))) 42024519898SXuan Hu XSError(!cond1 && !cond2 && !cond3 && !cond4, p"new condition $sameFtqPtr $ftqOffset0 $ftqOffset1\n") 42124519898SXuan Hu } 42224519898SXuan Hu 42324519898SXuan Hu } 42424519898SXuan Hu 42524519898SXuan Hu // memory dependency predict 42624519898SXuan Hu // when decode, send fold pc to mdp 4279477429fSsinceforYy private val mdpFlodPcVecVld = Wire(Vec(DecodeWidth, Bool())) 42824519898SXuan Hu private val mdpFlodPcVec = Wire(Vec(DecodeWidth, UInt(MemPredPCWidth.W))) 42924519898SXuan Hu for (i <- 0 until DecodeWidth) { 4309477429fSsinceforYy mdpFlodPcVecVld(i) := decode.io.out(i).fire || GatedValidRegNext(decode.io.out(i).fire) 43124519898SXuan Hu mdpFlodPcVec(i) := Mux( 43224519898SXuan Hu decode.io.out(i).fire, 43324519898SXuan Hu decode.io.in(i).bits.foldpc, 43424519898SXuan Hu rename.io.in(i).bits.foldpc 43524519898SXuan Hu ) 43624519898SXuan Hu } 43724519898SXuan Hu 43824519898SXuan Hu // currently, we only update mdp info when isReplay 43924519898SXuan Hu memCtrl.io.redirect := s1_s3_redirect 44024519898SXuan Hu memCtrl.io.csrCtrl := io.csrCtrl // RegNext in memCtrl 44124519898SXuan Hu memCtrl.io.stIn := io.fromMem.stIn // RegNext in memCtrl 44224519898SXuan Hu memCtrl.io.memPredUpdate := redirectGen.io.memPredUpdate // RegNext in memCtrl 4439477429fSsinceforYy memCtrl.io.mdpFoldPcVecVld := mdpFlodPcVecVld 44424519898SXuan Hu memCtrl.io.mdpFlodPcVec := mdpFlodPcVec 44524519898SXuan Hu memCtrl.io.dispatchLFSTio <> dispatch.io.lfst 44624519898SXuan Hu 44724519898SXuan Hu rat.io.redirect := s1_s3_redirect.valid 4486b102a39SHaojin Tang rat.io.rabCommits := rob.io.rabCommits 449cda1c534Sxiaofeibao-xjtu rat.io.diffCommits.foreach(_ := rob.io.diffCommits.get) 45024519898SXuan Hu rat.io.intRenamePorts := rename.io.intRenamePorts 45124519898SXuan Hu rat.io.fpRenamePorts := rename.io.fpRenamePorts 45224519898SXuan Hu rat.io.vecRenamePorts := rename.io.vecRenamePorts 453368cbcecSxiaofeibao rat.io.v0RenamePorts := rename.io.v0RenamePorts 454368cbcecSxiaofeibao rat.io.vlRenamePorts := rename.io.vlRenamePorts 45524519898SXuan Hu 45624519898SXuan Hu rename.io.redirect := s1_s3_redirect 4576b102a39SHaojin Tang rename.io.rabCommits := rob.io.rabCommits 45824519898SXuan Hu rename.io.waittable := (memCtrl.io.waitTable2Rename zip decode.io.out).map{ case(waittable2rename, decodeOut) => 45924519898SXuan Hu RegEnable(waittable2rename, decodeOut.fire) 46024519898SXuan Hu } 46124519898SXuan Hu rename.io.ssit := memCtrl.io.ssit2Rename 46224519898SXuan Hu rename.io.intReadPorts := VecInit(rat.io.intReadPorts.map(x => VecInit(x.map(_.data)))) 46324519898SXuan Hu rename.io.fpReadPorts := VecInit(rat.io.fpReadPorts.map(x => VecInit(x.map(_.data)))) 46424519898SXuan Hu rename.io.vecReadPorts := VecInit(rat.io.vecReadPorts.map(x => VecInit(x.map(_.data)))) 465368cbcecSxiaofeibao rename.io.v0ReadPorts := VecInit(rat.io.v0ReadPorts.map(x => VecInit(x.data))) 466368cbcecSxiaofeibao rename.io.vlReadPorts := VecInit(rat.io.vlReadPorts.map(x => VecInit(x.data))) 467dcf3a679STang Haojin rename.io.int_need_free := rat.io.int_need_free 468dcf3a679STang Haojin rename.io.int_old_pdest := rat.io.int_old_pdest 469dcf3a679STang Haojin rename.io.fp_old_pdest := rat.io.fp_old_pdest 4703cf50307SZiyue Zhang rename.io.vec_old_pdest := rat.io.vec_old_pdest 471368cbcecSxiaofeibao rename.io.v0_old_pdest := rat.io.v0_old_pdest 472368cbcecSxiaofeibao rename.io.vl_old_pdest := rat.io.vl_old_pdest 473b7d9e8d5Sxiaofeibao-xjtu rename.io.debug_int_rat.foreach(_ := rat.io.debug_int_rat.get) 474b7d9e8d5Sxiaofeibao-xjtu rename.io.debug_fp_rat.foreach(_ := rat.io.debug_fp_rat.get) 475b7d9e8d5Sxiaofeibao-xjtu rename.io.debug_vec_rat.foreach(_ := rat.io.debug_vec_rat.get) 476368cbcecSxiaofeibao rename.io.debug_v0_rat.foreach(_ := rat.io.debug_v0_rat.get) 477368cbcecSxiaofeibao rename.io.debug_vl_rat.foreach(_ := rat.io.debug_vl_rat.get) 478d2b20d1aSTang Haojin rename.io.stallReason.in <> decode.io.stallReason.out 479870f462dSXuan Hu rename.io.snpt.snptEnq := DontCare 480870f462dSXuan Hu rename.io.snpt.snptDeq := snpt.io.deq 481870f462dSXuan Hu rename.io.snpt.useSnpt := useSnpt 482870f462dSXuan Hu rename.io.snpt.snptSelect := snptSelect 483bb7e6e3aSxiaofeibao-xjtu rename.io.snptIsFull := snpt.io.valids.asUInt.andR 484c4b56310SHaojin Tang rename.io.snpt.flushVec := flushVecNext 485c4b56310SHaojin Tang rename.io.snptLastEnq.valid := !isEmpty(snpt.io.enqPtr, snpt.io.deqPtr) 486c4b56310SHaojin Tang rename.io.snptLastEnq.bits := snpt.io.snapshots((snpt.io.enqPtr - 1.U).value).robIdx.head 487870f462dSXuan Hu 488870f462dSXuan Hu val renameOut = Wire(chiselTypeOf(rename.io.out)) 489870f462dSXuan Hu renameOut <> rename.io.out 490ac78003fSzhanglyGit // pass all snapshot in the first element for correctness of blockBackward 491ac78003fSzhanglyGit renameOut.tail.foreach(_.bits.snapshot := false.B) 492ac78003fSzhanglyGit renameOut.head.bits.snapshot := Mux(isFull(snpt.io.enqPtr, snpt.io.deqPtr), 493ac78003fSzhanglyGit false.B, 494ac78003fSzhanglyGit Cat(rename.io.out.map(out => out.valid && out.bits.snapshot)).orR 495ac78003fSzhanglyGit ) 496ac78003fSzhanglyGit 497ac78003fSzhanglyGit // pipeline between rename and dispatch 498f5c17053Sxiaofeibao-xjtu PipeGroupConnect(renameOut, dispatch.io.fromRename, s1_s3_redirect.valid, dispatch.io.toRenameAllFire, "renamePipeDispatch") 49982674533Sxiaofeibao dispatch.io.intIQValidNumVec := io.intIQValidNumVec 50082674533Sxiaofeibao dispatch.io.fpIQValidNumVec := io.fpIQValidNumVec 501ff3fcdf1Sxiaofeibao-xjtu dispatch.io.fromIntDQ.intDQ0ValidDeq0Num := intDq0.io.validDeq0Num 502ff3fcdf1Sxiaofeibao-xjtu dispatch.io.fromIntDQ.intDQ0ValidDeq1Num := intDq0.io.validDeq1Num 503ff3fcdf1Sxiaofeibao-xjtu dispatch.io.fromIntDQ.intDQ1ValidDeq0Num := intDq1.io.validDeq0Num 504ff3fcdf1Sxiaofeibao-xjtu dispatch.io.fromIntDQ.intDQ1ValidDeq1Num := intDq1.io.validDeq1Num 505ff3fcdf1Sxiaofeibao-xjtu 50624519898SXuan Hu dispatch.io.hartId := io.fromTop.hartId 50724519898SXuan Hu dispatch.io.redirect := s1_s3_redirect 50824519898SXuan Hu dispatch.io.enqRob <> rob.io.enq 509d2b20d1aSTang Haojin dispatch.io.robHead := rob.io.debugRobHead 510d2b20d1aSTang Haojin dispatch.io.stallReason <> rename.io.stallReason.out 511d2b20d1aSTang Haojin dispatch.io.lqCanAccept := io.lqCanAccept 512d2b20d1aSTang Haojin dispatch.io.sqCanAccept := io.sqCanAccept 513d2b20d1aSTang Haojin dispatch.io.robHeadNotReady := rob.io.headNotReady 514d2b20d1aSTang Haojin dispatch.io.robFull := rob.io.robFull 5155f8b6c9eSsinceforYy dispatch.io.singleStep := GatedValidRegNext(io.csrCtrl.singlestep) 51624519898SXuan Hu 517ff3fcdf1Sxiaofeibao-xjtu intDq0.io.enq <> dispatch.io.toIntDq0 518ff3fcdf1Sxiaofeibao-xjtu intDq0.io.redirect <> s2_s4_redirect 519ff3fcdf1Sxiaofeibao-xjtu intDq1.io.enq <> dispatch.io.toIntDq1 520ff3fcdf1Sxiaofeibao-xjtu intDq1.io.redirect <> s2_s4_redirect 52124519898SXuan Hu 52224519898SXuan Hu fpDq.io.enq <> dispatch.io.toFpDq 52324519898SXuan Hu fpDq.io.redirect <> s2_s4_redirect 52424519898SXuan Hu 52560f0c5aeSxiaofeibao vecDq.io.enq <> dispatch.io.toVecDq 52660f0c5aeSxiaofeibao vecDq.io.redirect <> s2_s4_redirect 52760f0c5aeSxiaofeibao 52824519898SXuan Hu lsDq.io.enq <> dispatch.io.toLsDq 52924519898SXuan Hu lsDq.io.redirect <> s2_s4_redirect 53024519898SXuan Hu 531ff3fcdf1Sxiaofeibao-xjtu io.toIssueBlock.intUops <> (intDq0.io.deq :++ intDq1.io.deq) 53260f0c5aeSxiaofeibao io.toIssueBlock.fpUops <> fpDq.io.deq 53360f0c5aeSxiaofeibao io.toIssueBlock.vfUops <> vecDq.io.deq 53424519898SXuan Hu io.toIssueBlock.memUops <> lsDq.io.deq 53524519898SXuan Hu io.toIssueBlock.allocPregs <> dispatch.io.allocPregs 53624519898SXuan Hu io.toIssueBlock.flush <> s2_s4_redirect 53724519898SXuan Hu 5385f8b6c9eSsinceforYy pcMem.io.wen.head := GatedValidRegNext(io.frontend.fromFtq.pc_mem_wen) 53944b06f8aSXuan Hu pcMem.io.waddr.head := RegEnable(io.frontend.fromFtq.pc_mem_waddr.value, io.frontend.fromFtq.pc_mem_wen) 5403827c997SsinceforYy pcMem.io.wdata.head := RegEnable(io.frontend.fromFtq.pc_mem_wdata, io.frontend.fromFtq.pc_mem_wen) 54124519898SXuan Hu 54224519898SXuan Hu io.toDataPath.flush := s2_s4_redirect 54324519898SXuan Hu io.toExuBlock.flush := s2_s4_redirect 54424519898SXuan Hu 54524519898SXuan Hu 54624519898SXuan Hu rob.io.hartId := io.fromTop.hartId 54724519898SXuan Hu rob.io.redirect := s1_s3_redirect 54824519898SXuan Hu rob.io.writeback := delayedNotFlushedWriteBack 549bd5909d0Sxiaofeibao-xjtu rob.io.exuWriteback := delayedWriteBack 55085f51ecaSxiaofeibao-xjtu rob.io.writebackNums := VecInit(delayedNotFlushedWriteBackNums) 551571677c9Sxiaofeibao-xjtu rob.io.writebackNeedFlush := delayedNotFlushedWriteBackNeedFlush 5526f483f86SXuan Hu rob.io.readGPAMemData := gpaMem.io.exceptionReadData 55324519898SXuan Hu 55424519898SXuan Hu io.redirect := s1_s3_redirect 55524519898SXuan Hu 55624519898SXuan Hu // rob to int block 55724519898SXuan Hu io.robio.csr <> rob.io.csr 55824519898SXuan Hu // When wfi is disabled, it will not block ROB commit. 55924519898SXuan Hu rob.io.csr.wfiEvent := io.robio.csr.wfiEvent 56024519898SXuan Hu rob.io.wfi_enable := decode.io.csrCtrl.wfi_enable 56124519898SXuan Hu 56224519898SXuan Hu io.toTop.cpuHalt := DelayN(rob.io.cpu_halt, 5) 56324519898SXuan Hu 56424519898SXuan Hu io.robio.csr.perfinfo.retiredInstr <> RegNext(rob.io.csr.perfinfo.retiredInstr) 56524519898SXuan Hu io.robio.exception := rob.io.exception 56624519898SXuan Hu io.robio.exception.bits.pc := s1_robFlushPc 56724519898SXuan Hu 56824519898SXuan Hu // rob to mem block 56924519898SXuan Hu io.robio.lsq <> rob.io.lsq 57024519898SXuan Hu 571b7d9e8d5Sxiaofeibao-xjtu io.debug_int_rat .foreach(_ := rat.io.diff_int_rat.get) 572b7d9e8d5Sxiaofeibao-xjtu io.debug_fp_rat .foreach(_ := rat.io.diff_fp_rat.get) 573b7d9e8d5Sxiaofeibao-xjtu io.debug_vec_rat .foreach(_ := rat.io.diff_vec_rat.get) 574368cbcecSxiaofeibao io.debug_v0_rat.foreach(_ := rat.io.diff_v0_rat.get) 575368cbcecSxiaofeibao io.debug_vl_rat.foreach(_ := rat.io.diff_vl_rat.get) 57624519898SXuan Hu 57717b21f45SHaojin Tang rob.io.debug_ls := io.robio.debug_ls 57817b21f45SHaojin Tang rob.io.debugHeadLsIssue := io.robio.robHeadLsIssue 57917b21f45SHaojin Tang rob.io.lsTopdownInfo := io.robio.lsTopdownInfo 5806ce10964SXuan Hu rob.io.debugEnqLsq := io.debugEnqLsq 5816ce10964SXuan Hu 58217b21f45SHaojin Tang io.robio.robDeqPtr := rob.io.robDeqPtr 5838744445eSMaxpicca-Li 5847e4f0b19SZiyue-Zhang // rob to backend 5857e4f0b19SZiyue-Zhang io.robio.commitVType := rob.io.toDecode.commitVType 5867e4f0b19SZiyue-Zhang // exu block to decode 587d8a50338SZiyue Zhang decode.io.vsetvlVType := io.toDecode.vsetvlVType 5885110577fSZiyue Zhang // backend to decode 5895110577fSZiyue Zhang decode.io.vstart := io.toDecode.vstart 5905110577fSZiyue Zhang // backend to rob 5915110577fSZiyue Zhang rob.io.vstartIsZero := io.toDecode.vstart === 0.U 5927e4f0b19SZiyue-Zhang 59360ebee38STang Haojin io.debugTopDown.fromRob := rob.io.debugTopDown.toCore 59460ebee38STang Haojin dispatch.io.debugTopDown.fromRob := rob.io.debugTopDown.toDispatch 59560ebee38STang Haojin dispatch.io.debugTopDown.fromCore := io.debugTopDown.fromCore 5967cf78eb2Shappy-lx io.debugRolling := rob.io.debugRolling 59760ebee38STang Haojin 5985f8b6c9eSsinceforYy io.perfInfo.ctrlInfo.robFull := GatedValidRegNext(rob.io.robFull) 5995f8b6c9eSsinceforYy io.perfInfo.ctrlInfo.intdqFull := GatedValidRegNext(intDq0.io.dqFull || intDq1.io.dqFull) 60060f0c5aeSxiaofeibao io.perfInfo.ctrlInfo.fpdqFull := GatedValidRegNext(vecDq.io.dqFull) 6015f8b6c9eSsinceforYy io.perfInfo.ctrlInfo.lsdqFull := GatedValidRegNext(lsDq.io.dqFull) 60224519898SXuan Hu 603e1a85e9fSchengguanghui val perfEvents = Seq(decode, rename, dispatch, intDq0, intDq1, vecDq, lsDq, rob).flatMap(_.getPerfEvents) 60424519898SXuan Hu generatePerfEvent() 60524519898SXuan Hu} 60624519898SXuan Hu 60724519898SXuan Huclass CtrlBlockIO()(implicit p: Parameters, params: BackendParams) extends XSBundle { 60824519898SXuan Hu val fromTop = new Bundle { 60924519898SXuan Hu val hartId = Input(UInt(8.W)) 61024519898SXuan Hu } 61124519898SXuan Hu val toTop = new Bundle { 61224519898SXuan Hu val cpuHalt = Output(Bool()) 61324519898SXuan Hu } 61424519898SXuan Hu val frontend = Flipped(new FrontendToCtrlIO()) 61515ed99a7SXuan Hu val fromCSR = new Bundle{ 61615ed99a7SXuan Hu val toDecode = Input(new CSRToDecode) 61715ed99a7SXuan Hu } 61824519898SXuan Hu val toIssueBlock = new Bundle { 61924519898SXuan Hu val flush = ValidIO(new Redirect) 62024519898SXuan Hu val allocPregs = Vec(RenameWidth, Output(new ResetPregStateReq)) 62124519898SXuan Hu val intUops = Vec(dpParams.IntDqDeqWidth, DecoupledIO(new DynInst)) 62260f0c5aeSxiaofeibao val vfUops = Vec(dpParams.VecDqDeqWidth, DecoupledIO(new DynInst)) 62360f0c5aeSxiaofeibao val fpUops = Vec(dpParams.FpDqDeqWidth, DecoupledIO(new DynInst)) 62424519898SXuan Hu val memUops = Vec(dpParams.LsDqDeqWidth, DecoupledIO(new DynInst)) 62524519898SXuan Hu } 62624519898SXuan Hu val toDataPath = new Bundle { 62724519898SXuan Hu val flush = ValidIO(new Redirect) 62824519898SXuan Hu } 62924519898SXuan Hu val toExuBlock = new Bundle { 63024519898SXuan Hu val flush = ValidIO(new Redirect) 63124519898SXuan Hu } 63282674533Sxiaofeibao val intIQValidNumVec = Input(MixedVec(params.genIntIQValidNumBundle)) 63382674533Sxiaofeibao val fpIQValidNumVec = Input(MixedVec(params.genFpIQValidNumBundle)) 63424519898SXuan Hu val fromWB = new Bundle { 63524519898SXuan Hu val wbData = Flipped(MixedVec(params.genWrite2CtrlBundles)) 63624519898SXuan Hu } 63724519898SXuan Hu val redirect = ValidIO(new Redirect) 63824519898SXuan Hu val fromMem = new Bundle { 639272ec6b1SHaojin Tang val stIn = Vec(params.StaExuCnt, Flipped(ValidIO(new DynInst))) // use storeSetHit, ssid, robIdx 64024519898SXuan Hu val violation = Flipped(ValidIO(new Redirect)) 64124519898SXuan Hu } 64224519898SXuan Hu val memLdPcRead = Vec(params.LduCnt, Flipped(new FtqRead(UInt(VAddrBits.W)))) 64383ba63b3SXuan Hu val memStPcRead = Vec(params.StaCnt, Flipped(new FtqRead(UInt(VAddrBits.W)))) 644b133b458SXuan Hu val memHyPcRead = Vec(params.HyuCnt, Flipped(new FtqRead(UInt(VAddrBits.W)))) 6454b0d80d8SXuan Hu 64624519898SXuan Hu val csrCtrl = Input(new CustomCSRCtrlIO) 64724519898SXuan Hu val robio = new Bundle { 64824519898SXuan Hu val csr = new RobCSRIO 64924519898SXuan Hu val exception = ValidIO(new ExceptionInfo) 65024519898SXuan Hu val lsq = new RobLsqIO 6516810d1e8Ssfencevma val lsTopdownInfo = Vec(params.LduCnt + params.HyuCnt, Input(new LsTopdownInfo)) 6522326221cSXuan Hu val debug_ls = Input(new DebugLSIO()) 65317b21f45SHaojin Tang val robHeadLsIssue = Input(Bool()) 65417b21f45SHaojin Tang val robDeqPtr = Output(new RobPtr) 6557e4f0b19SZiyue-Zhang val commitVType = new Bundle { 6567e4f0b19SZiyue-Zhang val vtype = Output(ValidIO(VType())) 6577e4f0b19SZiyue-Zhang val hasVsetvl = Output(Bool()) 6587e4f0b19SZiyue-Zhang } 65924519898SXuan Hu } 66024519898SXuan Hu 661d8a50338SZiyue Zhang val toDecode = new Bundle { 662d8a50338SZiyue Zhang val vsetvlVType = Input(VType()) 6635110577fSZiyue Zhang val vstart = Input(Vl()) 664d8a50338SZiyue Zhang } 665d8a50338SZiyue Zhang 66624519898SXuan Hu val perfInfo = Output(new Bundle{ 66724519898SXuan Hu val ctrlInfo = new Bundle { 66824519898SXuan Hu val robFull = Bool() 66924519898SXuan Hu val intdqFull = Bool() 67024519898SXuan Hu val fpdqFull = Bool() 67124519898SXuan Hu val lsdqFull = Bool() 67224519898SXuan Hu } 67324519898SXuan Hu }) 674b7d9e8d5Sxiaofeibao-xjtu val debug_int_rat = if (params.debugEn) Some(Vec(32, Output(UInt(PhyRegIdxWidth.W)))) else None 675b7d9e8d5Sxiaofeibao-xjtu val debug_fp_rat = if (params.debugEn) Some(Vec(32, Output(UInt(PhyRegIdxWidth.W)))) else None 676d1e473c9Sxiaofeibao val debug_vec_rat = if (params.debugEn) Some(Vec(31, Output(UInt(PhyRegIdxWidth.W)))) else None 677d1e473c9Sxiaofeibao val debug_v0_rat = if (params.debugEn) Some(Vec(1, Output(UInt(PhyRegIdxWidth.W)))) else None 678d1e473c9Sxiaofeibao val debug_vl_rat = if (params.debugEn) Some(Vec(1, Output(UInt(PhyRegIdxWidth.W)))) else None 67924519898SXuan Hu 680c61abc0cSXuan Hu val sqCanAccept = Input(Bool()) 681c61abc0cSXuan Hu val lqCanAccept = Input(Bool()) 6824b0d80d8SXuan Hu 6834b0d80d8SXuan Hu val debugTopDown = new Bundle { 6844b0d80d8SXuan Hu val fromRob = new RobCoreTopDownIO 6854b0d80d8SXuan Hu val fromCore = new CoreDispatchTopDownIO 6864b0d80d8SXuan Hu } 6874b0d80d8SXuan Hu val debugRolling = new RobDebugRollingIO 6886ce10964SXuan Hu val debugEnqLsq = Input(new LsqEnqIO) 68924519898SXuan Hu} 69024519898SXuan Hu 69124519898SXuan Huclass NamedIndexes(namedCnt: Seq[(String, Int)]) { 69224519898SXuan Hu require(namedCnt.map(_._1).distinct.size == namedCnt.size, "namedCnt should not have the same name") 69324519898SXuan Hu 69424519898SXuan Hu val maxIdx = namedCnt.map(_._2).sum 69524519898SXuan Hu val nameRangeMap: Map[String, (Int, Int)] = namedCnt.indices.map { i => 69624519898SXuan Hu val begin = namedCnt.slice(0, i).map(_._2).sum 69724519898SXuan Hu val end = begin + namedCnt(i)._2 69824519898SXuan Hu (namedCnt(i)._1, (begin, end)) 69924519898SXuan Hu }.toMap 70024519898SXuan Hu 70124519898SXuan Hu def apply(name: String): Seq[Int] = { 70224519898SXuan Hu require(nameRangeMap.contains(name)) 70324519898SXuan Hu nameRangeMap(name)._1 until nameRangeMap(name)._2 70424519898SXuan Hu } 70524519898SXuan Hu} 706