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 17package xiangshan.backend 18 19import org.chipsalliance.cde.config.Parameters 20import chisel3._ 21import chisel3.util._ 22import freechips.rocketchip.diplomacy.{LazyModule, LazyModuleImp} 23import utility._ 24import utils._ 25import xiangshan.ExceptionNO._ 26import xiangshan._ 27import xiangshan.backend.Bundles.{DecodedInst, DynInst, ExceptionInfo, ExuOutput, StaticInst, TrapInstInfo} 28import xiangshan.backend.ctrlblock.{DebugLSIO, DebugLsInfoBundle, LsTopdownInfo, MemCtrl, RedirectGenerator} 29import xiangshan.backend.datapath.DataConfig.VAddrData 30import xiangshan.backend.decode.{DecodeStage, FusionDecoder} 31import xiangshan.backend.dispatch.{CoreDispatchTopDownIO, Dispatch, DispatchQueue} 32import xiangshan.backend.fu.PFEvent 33import xiangshan.backend.fu.vector.Bundles.{VType, Vl} 34import xiangshan.backend.fu.wrapper.CSRToDecode 35import xiangshan.backend.rename.{Rename, RenameTableWrapper, SnapshotGenerator} 36import xiangshan.backend.rob.{Rob, RobCSRIO, RobCoreTopDownIO, RobDebugRollingIO, RobLsqIO, RobPtr} 37import xiangshan.frontend.{FtqPtr, FtqRead, Ftq_RF_Components} 38import xiangshan.mem.{LqPtr, LsqEnqIO} 39import xiangshan.backend.issue.{FpScheduler, IntScheduler, MemScheduler, VfScheduler} 40 41class CtrlToFtqIO(implicit p: Parameters) extends XSBundle { 42 val rob_commits = Vec(CommitWidth, Valid(new RobCommitInfo)) 43 val redirect = Valid(new Redirect) 44 val ftqIdxAhead = Vec(BackendRedirectNum, Valid(new FtqPtr)) 45 val ftqIdxSelOH = Valid(UInt((BackendRedirectNum).W)) 46} 47 48class CtrlBlock(params: BackendParams)(implicit p: Parameters) extends LazyModule { 49 override def shouldBeInlined: Boolean = false 50 51 val rob = LazyModule(new Rob(params)) 52 53 lazy val module = new CtrlBlockImp(this)(p, params) 54 55 val gpaMem = LazyModule(new GPAMem()) 56} 57 58class CtrlBlockImp( 59 override val wrapper: CtrlBlock 60)(implicit 61 p: Parameters, 62 params: BackendParams 63) extends LazyModuleImp(wrapper) 64 with HasXSParameter 65 with HasCircularQueuePtrHelper 66 with HasPerfEvents 67 with HasCriticalErrors 68{ 69 val pcMemRdIndexes = new NamedIndexes(Seq( 70 "redirect" -> 1, 71 "memPred" -> 1, 72 "robFlush" -> 1, 73 "load" -> params.LduCnt, 74 "hybrid" -> params.HyuCnt, 75 "store" -> (if(EnableStorePrefetchSMS) params.StaCnt else 0) 76 )) 77 78 private val numPcMemReadForExu = params.numPcReadPort 79 private val numPcMemRead = pcMemRdIndexes.maxIdx 80 81 // now pcMem read for exu is moved to PcTargetMem (OG0) 82 println(s"pcMem read num: $numPcMemRead") 83 println(s"pcMem read num for exu: $numPcMemReadForExu") 84 85 val io = IO(new CtrlBlockIO()) 86 87 val gpaMem = wrapper.gpaMem.module 88 val decode = Module(new DecodeStage) 89 val fusionDecoder = Module(new FusionDecoder) 90 val rat = Module(new RenameTableWrapper) 91 val rename = Module(new Rename) 92 val dispatch = Module(new Dispatch) 93 val intDq0 = Module(new DispatchQueue(dpParams.IntDqSize, RenameWidth, dpParams.IntDqDeqWidth/2, dqIndex = 0)) 94 val intDq1 = Module(new DispatchQueue(dpParams.IntDqSize, RenameWidth, dpParams.IntDqDeqWidth/2, dqIndex = 1)) 95 val fpDq = Module(new DispatchQueue(dpParams.FpDqSize, RenameWidth, dpParams.VecDqDeqWidth)) 96 val vecDq = Module(new DispatchQueue(dpParams.FpDqSize, RenameWidth, dpParams.VecDqDeqWidth)) 97 val lsDq = Module(new DispatchQueue(dpParams.LsDqSize, RenameWidth, dpParams.LsDqDeqWidth)) 98 val redirectGen = Module(new RedirectGenerator) 99 private def hasRen: Boolean = true 100 private val pcMem = Module(new SyncDataModuleTemplate(new Ftq_RF_Components, FtqSize, numPcMemRead, 1, "BackendPC", hasRen = hasRen)) 101 private val rob = wrapper.rob.module 102 private val memCtrl = Module(new MemCtrl(params)) 103 104 private val disableFusion = decode.io.csrCtrl.singlestep || !decode.io.csrCtrl.fusion_enable 105 106 private val s0_robFlushRedirect = rob.io.flushOut 107 private val s1_robFlushRedirect = Wire(Valid(new Redirect)) 108 s1_robFlushRedirect.valid := GatedValidRegNext(s0_robFlushRedirect.valid, false.B) 109 s1_robFlushRedirect.bits := RegEnable(s0_robFlushRedirect.bits, s0_robFlushRedirect.valid) 110 111 pcMem.io.ren.get(pcMemRdIndexes("robFlush").head) := s0_robFlushRedirect.valid 112 pcMem.io.raddr(pcMemRdIndexes("robFlush").head) := s0_robFlushRedirect.bits.ftqIdx.value 113 private val s1_robFlushPc = pcMem.io.rdata(pcMemRdIndexes("robFlush").head).getPc(RegEnable(s0_robFlushRedirect.bits.ftqOffset, s0_robFlushRedirect.valid)) 114 private val s3_redirectGen = redirectGen.io.stage2Redirect 115 private val s1_s3_redirect = Mux(s1_robFlushRedirect.valid, s1_robFlushRedirect, s3_redirectGen) 116 private val s2_s4_pendingRedirectValid = RegInit(false.B) 117 when (s1_s3_redirect.valid) { 118 s2_s4_pendingRedirectValid := true.B 119 }.elsewhen (GatedValidRegNext(io.frontend.toFtq.redirect.valid)) { 120 s2_s4_pendingRedirectValid := false.B 121 } 122 123 // Redirect will be RegNext at ExuBlocks and IssueBlocks 124 val s2_s4_redirect = RegNextWithEnable(s1_s3_redirect) 125 val s3_s5_redirect = RegNextWithEnable(s2_s4_redirect) 126 127 private val delayedNotFlushedWriteBack = io.fromWB.wbData.map(x => { 128 val valid = x.valid 129 val killedByOlder = x.bits.robIdx.needFlush(Seq(s1_s3_redirect, s2_s4_redirect)) 130 val delayed = Wire(Valid(new ExuOutput(x.bits.params))) 131 delayed.valid := GatedValidRegNext(valid && !killedByOlder) 132 delayed.bits := RegEnable(x.bits, x.valid) 133 delayed.bits.debugInfo.writebackTime := GTimer() 134 delayed 135 }).toSeq 136 private val delayedWriteBack = Wire(chiselTypeOf(io.fromWB.wbData)) 137 delayedWriteBack.zipWithIndex.map{ case (x,i) => 138 x.valid := GatedValidRegNext(io.fromWB.wbData(i).valid) 139 x.bits := delayedNotFlushedWriteBack(i).bits 140 } 141 val delayedNotFlushedWriteBackNeedFlush = Wire(Vec(params.allExuParams.filter(_.needExceptionGen).length, Bool())) 142 delayedNotFlushedWriteBackNeedFlush := delayedNotFlushedWriteBack.filter(_.bits.params.needExceptionGen).map{ x => 143 x.bits.exceptionVec.get.asUInt.orR || x.bits.flushPipe.getOrElse(false.B) || x.bits.replay.getOrElse(false.B) || 144 (if (x.bits.trigger.nonEmpty) TriggerAction.isDmode(x.bits.trigger.get) else false.B) 145 } 146 147 val wbDataNoStd = io.fromWB.wbData.filter(!_.bits.params.hasStdFu) 148 val intScheWbData = io.fromWB.wbData.filter(_.bits.params.schdType.isInstanceOf[IntScheduler]) 149 val fpScheWbData = io.fromWB.wbData.filter(_.bits.params.schdType.isInstanceOf[FpScheduler]) 150 val vfScheWbData = io.fromWB.wbData.filter(_.bits.params.schdType.isInstanceOf[VfScheduler]) 151 val intCanCompress = intScheWbData.filter(_.bits.params.CanCompress) 152 val i2vWbData = intScheWbData.filter(_.bits.params.writeVecRf) 153 val f2vWbData = fpScheWbData.filter(_.bits.params.writeVecRf) 154 val memVloadWbData = io.fromWB.wbData.filter(x => x.bits.params.schdType.isInstanceOf[MemScheduler] && x.bits.params.hasVLoadFu) 155 private val delayedNotFlushedWriteBackNums = wbDataNoStd.map(x => { 156 val valid = x.valid 157 val killedByOlder = x.bits.robIdx.needFlush(Seq(s1_s3_redirect, s2_s4_redirect, s3_s5_redirect)) 158 val delayed = Wire(Valid(UInt(io.fromWB.wbData.size.U.getWidth.W))) 159 delayed.valid := GatedValidRegNext(valid && !killedByOlder) 160 val isIntSche = intCanCompress.contains(x) 161 val isFpSche = fpScheWbData.contains(x) 162 val isVfSche = vfScheWbData.contains(x) 163 val isMemVload = memVloadWbData.contains(x) 164 val isi2v = i2vWbData.contains(x) 165 val isf2v = f2vWbData.contains(x) 166 val canSameRobidxWbData = if(isVfSche) { 167 i2vWbData ++ f2vWbData ++ vfScheWbData 168 } else if(isi2v) { 169 intCanCompress ++ fpScheWbData ++ vfScheWbData 170 } else if (isf2v) { 171 intCanCompress ++ fpScheWbData ++ vfScheWbData 172 } else if (isIntSche) { 173 intCanCompress ++ fpScheWbData 174 } else if (isFpSche) { 175 intCanCompress ++ fpScheWbData 176 } else if (isMemVload) { 177 memVloadWbData 178 } else { 179 Seq(x) 180 } 181 val sameRobidxBools = VecInit(canSameRobidxWbData.map( wb => { 182 val killedByOlderThat = wb.bits.robIdx.needFlush(Seq(s1_s3_redirect, s2_s4_redirect, s3_s5_redirect)) 183 (wb.bits.robIdx === x.bits.robIdx) && wb.valid && x.valid && !killedByOlderThat && !killedByOlder 184 }).toSeq) 185 delayed.bits := RegEnable(PopCount(sameRobidxBools), x.valid) 186 delayed 187 }).toSeq 188 189 private val exuPredecode = VecInit( 190 io.fromWB.wbData.filter(_.bits.redirect.nonEmpty).map(x => x.bits.predecodeInfo.get).toSeq 191 ) 192 193 private val exuRedirects: Seq[ValidIO[Redirect]] = io.fromWB.wbData.filter(_.bits.redirect.nonEmpty).map(x => { 194 val out = Wire(Valid(new Redirect())) 195 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)) 196 out.bits := x.bits.redirect.get.bits 197 out.bits.debugIsCtrl := true.B 198 out.bits.debugIsMemVio := false.B 199 out 200 }).toSeq 201 private val oldestOneHot = Redirect.selectOldestRedirect(exuRedirects) 202 private val oldestExuRedirect = Mux1H(oldestOneHot, exuRedirects) 203 private val oldestExuPredecode = Mux1H(oldestOneHot, exuPredecode) 204 205 private val memViolation = io.fromMem.violation 206 val loadReplay = Wire(ValidIO(new Redirect)) 207 loadReplay.valid := GatedValidRegNext(memViolation.valid) 208 loadReplay.bits := RegEnable(memViolation.bits, memViolation.valid) 209 loadReplay.bits.debugIsCtrl := false.B 210 loadReplay.bits.debugIsMemVio := true.B 211 212 pcMem.io.ren.get(pcMemRdIndexes("redirect").head) := memViolation.valid 213 pcMem.io.raddr(pcMemRdIndexes("redirect").head) := memViolation.bits.ftqIdx.value 214 pcMem.io.ren.get(pcMemRdIndexes("memPred").head) := memViolation.valid 215 pcMem.io.raddr(pcMemRdIndexes("memPred").head) := memViolation.bits.stFtqIdx.value 216 redirectGen.io.memPredPcRead.data := pcMem.io.rdata(pcMemRdIndexes("memPred").head).getPc(RegEnable(memViolation.bits.stFtqOffset, memViolation.valid)) 217 218 for ((pcMemIdx, i) <- pcMemRdIndexes("load").zipWithIndex) { 219 // load read pcMem (s0) -> get rdata (s1) -> reg next in Memblock (s2) -> reg next in Memblock (s3) -> consumed by pf (s3) 220 pcMem.io.ren.get(pcMemIdx) := io.memLdPcRead(i).valid 221 pcMem.io.raddr(pcMemIdx) := io.memLdPcRead(i).ptr.value 222 io.memLdPcRead(i).data := pcMem.io.rdata(pcMemIdx).getPc(RegEnable(io.memLdPcRead(i).offset, io.memLdPcRead(i).valid)) 223 } 224 225 for ((pcMemIdx, i) <- pcMemRdIndexes("hybrid").zipWithIndex) { 226 // load read pcMem (s0) -> get rdata (s1) -> reg next in Memblock (s2) -> reg next in Memblock (s3) -> consumed by pf (s3) 227 pcMem.io.ren.get(pcMemIdx) := io.memHyPcRead(i).valid 228 pcMem.io.raddr(pcMemIdx) := io.memHyPcRead(i).ptr.value 229 io.memHyPcRead(i).data := pcMem.io.rdata(pcMemIdx).getPc(RegEnable(io.memHyPcRead(i).offset, io.memHyPcRead(i).valid)) 230 } 231 232 if (EnableStorePrefetchSMS) { 233 for ((pcMemIdx, i) <- pcMemRdIndexes("store").zipWithIndex) { 234 pcMem.io.ren.get(pcMemIdx) := io.memStPcRead(i).valid 235 pcMem.io.raddr(pcMemIdx) := io.memStPcRead(i).ptr.value 236 io.memStPcRead(i).data := pcMem.io.rdata(pcMemIdx).getPc(RegEnable(io.memStPcRead(i).offset, io.memStPcRead(i).valid)) 237 } 238 } else { 239 io.memStPcRead.foreach(_.data := 0.U) 240 } 241 242 redirectGen.io.hartId := io.fromTop.hartId 243 redirectGen.io.oldestExuRedirect.valid := GatedValidRegNext(oldestExuRedirect.valid) 244 redirectGen.io.oldestExuRedirect.bits := RegEnable(oldestExuRedirect.bits, oldestExuRedirect.valid) 245 redirectGen.io.oldestExuOutPredecode.valid := GatedValidRegNext(oldestExuPredecode.valid) 246 redirectGen.io.oldestExuOutPredecode := RegEnable(oldestExuPredecode, oldestExuPredecode.valid) 247 redirectGen.io.loadReplay <> loadReplay 248 val loadRedirectPcRead = pcMem.io.rdata(pcMemRdIndexes("redirect").head).getPc(RegEnable(memViolation.bits.ftqOffset, memViolation.valid)) 249 redirectGen.io.loadReplay.bits.cfiUpdate.pc := loadRedirectPcRead 250 val load_pc_offset = Mux(loadReplay.bits.flushItself(), 0.U, Mux(loadReplay.bits.isRVC, 2.U, 4.U)) 251 val load_target = loadRedirectPcRead + load_pc_offset 252 redirectGen.io.loadReplay.bits.cfiUpdate.target := load_target 253 254 redirectGen.io.robFlush := s1_robFlushRedirect 255 256 val s5_flushFromRobValidAhead = DelayN(s1_robFlushRedirect.valid, 4) 257 val s6_flushFromRobValid = GatedValidRegNext(s5_flushFromRobValidAhead) 258 val frontendFlushBits = RegEnable(s1_robFlushRedirect.bits, s1_robFlushRedirect.valid) // ?? 259 // When ROB commits an instruction with a flush, we notify the frontend of the flush without the commit. 260 // Flushes to frontend may be delayed by some cycles and commit before flush causes errors. 261 // Thus, we make all flush reasons to behave the same as exceptions for frontend. 262 for (i <- 0 until CommitWidth) { 263 // why flushOut: instructions with flushPipe are not commited to frontend 264 // If we commit them to frontend, it will cause flush after commit, which is not acceptable by frontend. 265 val s1_isCommit = rob.io.commits.commitValid(i) && rob.io.commits.isCommit && !s0_robFlushRedirect.valid 266 io.frontend.toFtq.rob_commits(i).valid := GatedValidRegNext(s1_isCommit) 267 io.frontend.toFtq.rob_commits(i).bits := RegEnable(rob.io.commits.info(i), s1_isCommit) 268 } 269 io.frontend.toFtq.redirect.valid := s6_flushFromRobValid || s3_redirectGen.valid 270 io.frontend.toFtq.redirect.bits := Mux(s6_flushFromRobValid, frontendFlushBits, s3_redirectGen.bits) 271 io.frontend.toFtq.ftqIdxSelOH.valid := s6_flushFromRobValid || redirectGen.io.stage2Redirect.valid 272 io.frontend.toFtq.ftqIdxSelOH.bits := Cat(s6_flushFromRobValid, redirectGen.io.stage2oldestOH & Fill(NumRedirect + 1, !s6_flushFromRobValid)) 273 274 //jmp/brh, sel oldest first, only use one read port 275 io.frontend.toFtq.ftqIdxAhead(0).valid := RegNext(oldestExuRedirect.valid) && !s1_robFlushRedirect.valid && !s5_flushFromRobValidAhead 276 io.frontend.toFtq.ftqIdxAhead(0).bits := RegEnable(oldestExuRedirect.bits.ftqIdx, oldestExuRedirect.valid) 277 //loadreplay 278 io.frontend.toFtq.ftqIdxAhead(NumRedirect).valid := loadReplay.valid && !s1_robFlushRedirect.valid && !s5_flushFromRobValidAhead 279 io.frontend.toFtq.ftqIdxAhead(NumRedirect).bits := loadReplay.bits.ftqIdx 280 //exception 281 io.frontend.toFtq.ftqIdxAhead.last.valid := s5_flushFromRobValidAhead 282 io.frontend.toFtq.ftqIdxAhead.last.bits := frontendFlushBits.ftqIdx 283 284 // Be careful here: 285 // T0: rob.io.flushOut, s0_robFlushRedirect 286 // T1: s1_robFlushRedirect, rob.io.exception.valid 287 // T2: csr.redirect.valid 288 // T3: csr.exception.valid 289 // T4: csr.trapTarget 290 // T5: ctrlBlock.trapTarget 291 // T6: io.frontend.toFtq.stage2Redirect.valid 292 val s2_robFlushPc = RegEnable(Mux(s1_robFlushRedirect.bits.flushItself(), 293 s1_robFlushPc, // replay inst 294 s1_robFlushPc + Mux(s1_robFlushRedirect.bits.isRVC, 2.U, 4.U) // flush pipe 295 ), s1_robFlushRedirect.valid) 296 private val s5_csrIsTrap = DelayN(rob.io.exception.valid, 4) 297 private val s5_trapTargetFromCsr = io.robio.csr.trapTarget 298 299 val flushTarget = Mux(s5_csrIsTrap, s5_trapTargetFromCsr.pc, s2_robFlushPc) 300 val s5_trapTargetIAF = Mux(s5_csrIsTrap, s5_trapTargetFromCsr.raiseIAF, false.B) 301 val s5_trapTargetIPF = Mux(s5_csrIsTrap, s5_trapTargetFromCsr.raiseIPF, false.B) 302 val s5_trapTargetIGPF = Mux(s5_csrIsTrap, s5_trapTargetFromCsr.raiseIGPF, false.B) 303 when (s6_flushFromRobValid) { 304 io.frontend.toFtq.redirect.bits.level := RedirectLevel.flush 305 io.frontend.toFtq.redirect.bits.cfiUpdate.target := RegEnable(flushTarget, s5_flushFromRobValidAhead) 306 io.frontend.toFtq.redirect.bits.cfiUpdate.backendIAF := RegEnable(s5_trapTargetIAF, s5_flushFromRobValidAhead) 307 io.frontend.toFtq.redirect.bits.cfiUpdate.backendIPF := RegEnable(s5_trapTargetIPF, s5_flushFromRobValidAhead) 308 io.frontend.toFtq.redirect.bits.cfiUpdate.backendIGPF := RegEnable(s5_trapTargetIGPF, s5_flushFromRobValidAhead) 309 } 310 311 for (i <- 0 until DecodeWidth) { 312 gpaMem.io.fromIFU := io.frontend.fromIfu 313 gpaMem.io.exceptionReadAddr.valid := rob.io.readGPAMemAddr.valid 314 gpaMem.io.exceptionReadAddr.bits.ftqPtr := rob.io.readGPAMemAddr.bits.ftqPtr 315 gpaMem.io.exceptionReadAddr.bits.ftqOffset := rob.io.readGPAMemAddr.bits.ftqOffset 316 } 317 318 // vtype commit 319 decode.io.fromCSR := io.fromCSR.toDecode 320 decode.io.fromRob.isResumeVType := rob.io.toDecode.isResumeVType 321 decode.io.fromRob.walkToArchVType := rob.io.toDecode.walkToArchVType 322 decode.io.fromRob.commitVType := rob.io.toDecode.commitVType 323 decode.io.fromRob.walkVType := rob.io.toDecode.walkVType 324 325 decode.io.redirect := s1_s3_redirect.valid || s2_s4_pendingRedirectValid 326 327 // add decode Buf for in.ready better timing 328 val decodeBufBits = Reg(Vec(DecodeWidth, new StaticInst)) 329 val decodeBufValid = RegInit(VecInit(Seq.fill(DecodeWidth)(false.B))) 330 val decodeFromFrontend = io.frontend.cfVec 331 val decodeBufNotAccept = VecInit(decodeBufValid.zip(decode.io.in).map(x => x._1 && !x._2.ready)) 332 val decodeBufAcceptNum = PriorityMuxDefault(decodeBufNotAccept.zip(Seq.tabulate(DecodeWidth)(i => i.U)), DecodeWidth.U) 333 val decodeFromFrontendNotAccept = VecInit(decodeFromFrontend.zip(decode.io.in).map(x => decodeBufValid(0) || x._1.valid && !x._2.ready)) 334 val decodeFromFrontendAcceptNum = PriorityMuxDefault(decodeFromFrontendNotAccept.zip(Seq.tabulate(DecodeWidth)(i => i.U)), DecodeWidth.U) 335 if (backendParams.debugEn) { 336 dontTouch(decodeBufNotAccept) 337 dontTouch(decodeBufAcceptNum) 338 dontTouch(decodeFromFrontendNotAccept) 339 dontTouch(decodeFromFrontendAcceptNum) 340 } 341 val a = decodeBufNotAccept.drop(2) 342 for (i <- 0 until DecodeWidth) { 343 // decodeBufValid update 344 when(decode.io.redirect || decodeBufValid(0) && decodeBufValid(i) && decode.io.in(i).ready && !VecInit(decodeBufNotAccept.drop(i)).asUInt.orR) { 345 decodeBufValid(i) := false.B 346 }.elsewhen(decodeBufValid(i) && VecInit(decodeBufNotAccept.drop(i)).asUInt.orR) { 347 decodeBufValid(i) := Mux(decodeBufAcceptNum > DecodeWidth.U - 1.U - i.U, false.B, decodeBufValid(i.U + decodeBufAcceptNum)) 348 }.elsewhen(!decodeBufValid(0) && VecInit(decodeFromFrontendNotAccept.drop(i)).asUInt.orR) { 349 decodeBufValid(i) := Mux(decodeFromFrontendAcceptNum > DecodeWidth.U - 1.U - i.U, false.B, decodeFromFrontend(i.U + decodeFromFrontendAcceptNum).valid) 350 } 351 // decodeBufBits update 352 when(decodeBufValid(i) && VecInit(decodeBufNotAccept.drop(i)).asUInt.orR) { 353 decodeBufBits(i) := decodeBufBits(i.U + decodeBufAcceptNum) 354 }.elsewhen(!decodeBufValid(0) && VecInit(decodeFromFrontendNotAccept.drop(i)).asUInt.orR) { 355 decodeBufBits(i).connectCtrlFlow(decodeFromFrontend(i.U + decodeFromFrontendAcceptNum).bits) 356 } 357 } 358 val decodeConnectFromFrontend = Wire(Vec(DecodeWidth, new StaticInst)) 359 decodeConnectFromFrontend.zip(decodeFromFrontend).map(x => x._1.connectCtrlFlow(x._2.bits)) 360 decode.io.in.zipWithIndex.foreach { case (decodeIn, i) => 361 decodeIn.valid := Mux(decodeBufValid(0), decodeBufValid(i), decodeFromFrontend(i).valid) 362 decodeFromFrontend(i).ready := decodeFromFrontend(0).valid && !decodeBufValid(0) && decodeFromFrontend(i).valid && !decode.io.redirect 363 decodeIn.bits := Mux(decodeBufValid(i), decodeBufBits(i), decodeConnectFromFrontend(i)) 364 } 365 io.frontend.canAccept := !decodeBufValid(0) || !decodeFromFrontend(0).valid 366 decode.io.csrCtrl := RegNext(io.csrCtrl) 367 decode.io.intRat <> rat.io.intReadPorts 368 decode.io.fpRat <> rat.io.fpReadPorts 369 decode.io.vecRat <> rat.io.vecReadPorts 370 decode.io.v0Rat <> rat.io.v0ReadPorts 371 decode.io.vlRat <> rat.io.vlReadPorts 372 decode.io.fusion := 0.U.asTypeOf(decode.io.fusion) // Todo 373 decode.io.stallReason.in <> io.frontend.stallReason 374 375 // snapshot check 376 class CFIRobIdx extends Bundle { 377 val robIdx = Vec(RenameWidth, new RobPtr) 378 val isCFI = Vec(RenameWidth, Bool()) 379 } 380 val genSnapshot = Cat(rename.io.out.map(out => out.fire && out.bits.snapshot)).orR 381 val snpt = Module(new SnapshotGenerator(0.U.asTypeOf(new CFIRobIdx))) 382 snpt.io.enq := genSnapshot 383 snpt.io.enqData.robIdx := rename.io.out.map(_.bits.robIdx) 384 snpt.io.enqData.isCFI := rename.io.out.map(_.bits.snapshot) 385 snpt.io.deq := snpt.io.valids(snpt.io.deqPtr.value) && rob.io.commits.isCommit && 386 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 387 snpt.io.redirect := s1_s3_redirect.valid 388 val flushVec = VecInit(snpt.io.snapshots.map { snapshot => 389 val notCFIMask = snapshot.isCFI.map(~_) 390 val shouldFlush = snapshot.robIdx.map(robIdx => robIdx >= s1_s3_redirect.bits.robIdx || robIdx.value === s1_s3_redirect.bits.robIdx.value) 391 val shouldFlushMask = (1 to RenameWidth).map(shouldFlush take _ reduce (_ || _)) 392 s1_s3_redirect.valid && Cat(shouldFlushMask.zip(notCFIMask).map(x => x._1 | x._2)).andR 393 }) 394 val flushVecNext = flushVec zip snpt.io.valids map (x => GatedValidRegNext(x._1 && x._2, false.B)) 395 snpt.io.flushVec := flushVecNext 396 397 val useSnpt = VecInit.tabulate(RenameSnapshotNum)(idx => 398 snpt.io.valids(idx) && (s1_s3_redirect.bits.robIdx > snpt.io.snapshots(idx).robIdx.head || 399 !s1_s3_redirect.bits.flushItself() && s1_s3_redirect.bits.robIdx === snpt.io.snapshots(idx).robIdx.head) 400 ).reduceTree(_ || _) 401 val snptSelect = MuxCase( 402 0.U(log2Ceil(RenameSnapshotNum).W), 403 (1 to RenameSnapshotNum).map(i => (snpt.io.enqPtr - i.U).value).map(idx => 404 (snpt.io.valids(idx) && (s1_s3_redirect.bits.robIdx > snpt.io.snapshots(idx).robIdx.head || 405 !s1_s3_redirect.bits.flushItself() && s1_s3_redirect.bits.robIdx === snpt.io.snapshots(idx).robIdx.head), idx) 406 ) 407 ) 408 409 rob.io.snpt.snptEnq := DontCare 410 rob.io.snpt.snptDeq := snpt.io.deq 411 rob.io.snpt.useSnpt := useSnpt 412 rob.io.snpt.snptSelect := snptSelect 413 rob.io.snpt.flushVec := flushVecNext 414 rat.io.snpt.snptEnq := genSnapshot 415 rat.io.snpt.snptDeq := snpt.io.deq 416 rat.io.snpt.useSnpt := useSnpt 417 rat.io.snpt.snptSelect := snptSelect 418 rat.io.snpt.flushVec := flushVec 419 420 val decodeHasException = decode.io.out.map(x => x.bits.exceptionVec(instrPageFault) || x.bits.exceptionVec(instrAccessFault)) 421 // fusion decoder 422 for (i <- 0 until DecodeWidth) { 423 fusionDecoder.io.in(i).valid := decode.io.out(i).valid && !(decodeHasException(i) || disableFusion) 424 fusionDecoder.io.in(i).bits := decode.io.out(i).bits.instr 425 if (i > 0) { 426 fusionDecoder.io.inReady(i - 1) := decode.io.out(i).ready 427 } 428 } 429 430 private val decodePipeRename = Wire(Vec(RenameWidth, DecoupledIO(new DecodedInst))) 431 for (i <- 0 until RenameWidth) { 432 PipelineConnect(decode.io.out(i), decodePipeRename(i), rename.io.in(i).ready, 433 s1_s3_redirect.valid || s2_s4_pendingRedirectValid, moduleName = Some("decodePipeRenameModule")) 434 435 decodePipeRename(i).ready := rename.io.in(i).ready 436 rename.io.in(i).valid := decodePipeRename(i).valid && !fusionDecoder.io.clear(i) 437 rename.io.in(i).bits := decodePipeRename(i).bits 438 } 439 440 for (i <- 0 until RenameWidth - 1) { 441 fusionDecoder.io.dec(i) := decodePipeRename(i).bits 442 rename.io.fusionInfo(i) := fusionDecoder.io.info(i) 443 444 // update the first RenameWidth - 1 instructions 445 decode.io.fusion(i) := fusionDecoder.io.out(i).valid && rename.io.out(i).fire 446 when (fusionDecoder.io.out(i).valid) { 447 fusionDecoder.io.out(i).bits.update(rename.io.in(i).bits) 448 // TODO: remove this dirty code for ftq update 449 val sameFtqPtr = rename.io.in(i).bits.ftqPtr.value === rename.io.in(i + 1).bits.ftqPtr.value 450 val ftqOffset0 = rename.io.in(i).bits.ftqOffset 451 val ftqOffset1 = rename.io.in(i + 1).bits.ftqOffset 452 val ftqOffsetDiff = ftqOffset1 - ftqOffset0 453 val cond1 = sameFtqPtr && ftqOffsetDiff === 1.U 454 val cond2 = sameFtqPtr && ftqOffsetDiff === 2.U 455 val cond3 = !sameFtqPtr && ftqOffset1 === 0.U 456 val cond4 = !sameFtqPtr && ftqOffset1 === 1.U 457 rename.io.in(i).bits.commitType := Mux(cond1, 4.U, Mux(cond2, 5.U, Mux(cond3, 6.U, 7.U))) 458 XSError(!cond1 && !cond2 && !cond3 && !cond4, p"new condition $sameFtqPtr $ftqOffset0 $ftqOffset1\n") 459 } 460 461 } 462 463 // memory dependency predict 464 // when decode, send fold pc to mdp 465 private val mdpFlodPcVecVld = Wire(Vec(DecodeWidth, Bool())) 466 private val mdpFlodPcVec = Wire(Vec(DecodeWidth, UInt(MemPredPCWidth.W))) 467 for (i <- 0 until DecodeWidth) { 468 mdpFlodPcVecVld(i) := decode.io.out(i).fire || GatedValidRegNext(decode.io.out(i).fire) 469 mdpFlodPcVec(i) := Mux( 470 decode.io.out(i).fire, 471 decode.io.in(i).bits.foldpc, 472 rename.io.in(i).bits.foldpc 473 ) 474 } 475 476 // currently, we only update mdp info when isReplay 477 memCtrl.io.redirect := s1_s3_redirect 478 memCtrl.io.csrCtrl := io.csrCtrl // RegNext in memCtrl 479 memCtrl.io.stIn := io.fromMem.stIn // RegNext in memCtrl 480 memCtrl.io.memPredUpdate := redirectGen.io.memPredUpdate // RegNext in memCtrl 481 memCtrl.io.mdpFoldPcVecVld := mdpFlodPcVecVld 482 memCtrl.io.mdpFlodPcVec := mdpFlodPcVec 483 memCtrl.io.dispatchLFSTio <> dispatch.io.lfst 484 485 rat.io.redirect := s1_s3_redirect.valid 486 rat.io.rabCommits := rob.io.rabCommits 487 rat.io.diffCommits.foreach(_ := rob.io.diffCommits.get) 488 rat.io.intRenamePorts := rename.io.intRenamePorts 489 rat.io.fpRenamePorts := rename.io.fpRenamePorts 490 rat.io.vecRenamePorts := rename.io.vecRenamePorts 491 rat.io.v0RenamePorts := rename.io.v0RenamePorts 492 rat.io.vlRenamePorts := rename.io.vlRenamePorts 493 494 rename.io.redirect := s1_s3_redirect 495 rename.io.rabCommits := rob.io.rabCommits 496 rename.io.singleStep := GatedValidRegNext(io.csrCtrl.singlestep) 497 rename.io.waittable := (memCtrl.io.waitTable2Rename zip decode.io.out).map{ case(waittable2rename, decodeOut) => 498 RegEnable(waittable2rename, decodeOut.fire) 499 } 500 rename.io.ssit := memCtrl.io.ssit2Rename 501 rename.io.intReadPorts := VecInit(rat.io.intReadPorts.map(x => VecInit(x.map(_.data)))) 502 rename.io.fpReadPorts := VecInit(rat.io.fpReadPorts.map(x => VecInit(x.map(_.data)))) 503 rename.io.vecReadPorts := VecInit(rat.io.vecReadPorts.map(x => VecInit(x.map(_.data)))) 504 rename.io.v0ReadPorts := VecInit(rat.io.v0ReadPorts.map(x => VecInit(x.data))) 505 rename.io.vlReadPorts := VecInit(rat.io.vlReadPorts.map(x => VecInit(x.data))) 506 rename.io.int_need_free := rat.io.int_need_free 507 rename.io.int_old_pdest := rat.io.int_old_pdest 508 rename.io.fp_old_pdest := rat.io.fp_old_pdest 509 rename.io.vec_old_pdest := rat.io.vec_old_pdest 510 rename.io.v0_old_pdest := rat.io.v0_old_pdest 511 rename.io.vl_old_pdest := rat.io.vl_old_pdest 512 rename.io.debug_int_rat.foreach(_ := rat.io.debug_int_rat.get) 513 rename.io.debug_fp_rat.foreach(_ := rat.io.debug_fp_rat.get) 514 rename.io.debug_vec_rat.foreach(_ := rat.io.debug_vec_rat.get) 515 rename.io.debug_v0_rat.foreach(_ := rat.io.debug_v0_rat.get) 516 rename.io.debug_vl_rat.foreach(_ := rat.io.debug_vl_rat.get) 517 rename.io.stallReason.in <> decode.io.stallReason.out 518 rename.io.snpt.snptEnq := DontCare 519 rename.io.snpt.snptDeq := snpt.io.deq 520 rename.io.snpt.useSnpt := useSnpt 521 rename.io.snpt.snptSelect := snptSelect 522 rename.io.snptIsFull := snpt.io.valids.asUInt.andR 523 rename.io.snpt.flushVec := flushVecNext 524 rename.io.snptLastEnq.valid := !isEmpty(snpt.io.enqPtr, snpt.io.deqPtr) 525 rename.io.snptLastEnq.bits := snpt.io.snapshots((snpt.io.enqPtr - 1.U).value).robIdx.head 526 527 val renameOut = Wire(chiselTypeOf(rename.io.out)) 528 renameOut <> rename.io.out 529 // pass all snapshot in the first element for correctness of blockBackward 530 renameOut.tail.foreach(_.bits.snapshot := false.B) 531 renameOut.head.bits.snapshot := Mux(isFull(snpt.io.enqPtr, snpt.io.deqPtr), 532 false.B, 533 Cat(rename.io.out.map(out => out.valid && out.bits.snapshot)).orR 534 ) 535 536 // pipeline between rename and dispatch 537 PipeGroupConnect(renameOut, dispatch.io.fromRename, s1_s3_redirect.valid, dispatch.io.toRenameAllFire, "renamePipeDispatch") 538 dispatch.io.intIQValidNumVec := io.intIQValidNumVec 539 dispatch.io.fpIQValidNumVec := io.fpIQValidNumVec 540 dispatch.io.fromIntDQ.intDQ0ValidDeq0Num := intDq0.io.validDeq0Num 541 dispatch.io.fromIntDQ.intDQ0ValidDeq1Num := intDq0.io.validDeq1Num 542 dispatch.io.fromIntDQ.intDQ1ValidDeq0Num := intDq1.io.validDeq0Num 543 dispatch.io.fromIntDQ.intDQ1ValidDeq1Num := intDq1.io.validDeq1Num 544 545 dispatch.io.hartId := io.fromTop.hartId 546 dispatch.io.redirect := s1_s3_redirect 547 dispatch.io.enqRob <> rob.io.enq 548 dispatch.io.robHead := rob.io.debugRobHead 549 dispatch.io.stallReason <> rename.io.stallReason.out 550 dispatch.io.lqCanAccept := io.lqCanAccept 551 dispatch.io.sqCanAccept := io.sqCanAccept 552 dispatch.io.robHeadNotReady := rob.io.headNotReady 553 dispatch.io.robFull := rob.io.robFull 554 dispatch.io.singleStep := GatedValidRegNext(io.csrCtrl.singlestep) 555 556 intDq0.io.enq <> dispatch.io.toIntDq0 557 intDq0.io.redirect <> s2_s4_redirect 558 intDq1.io.enq <> dispatch.io.toIntDq1 559 intDq1.io.redirect <> s2_s4_redirect 560 561 fpDq.io.enq <> dispatch.io.toFpDq 562 fpDq.io.redirect <> s2_s4_redirect 563 564 vecDq.io.enq <> dispatch.io.toVecDq 565 vecDq.io.redirect <> s2_s4_redirect 566 567 lsDq.io.enq <> dispatch.io.toLsDq 568 lsDq.io.redirect <> s2_s4_redirect 569 570 io.toIssueBlock.intUops <> (intDq0.io.deq :++ intDq1.io.deq) 571 io.toIssueBlock.fpUops <> fpDq.io.deq 572 io.toIssueBlock.vfUops <> vecDq.io.deq 573 io.toIssueBlock.memUops <> lsDq.io.deq 574 io.toIssueBlock.allocPregs <> dispatch.io.allocPregs 575 io.toIssueBlock.flush <> s2_s4_redirect 576 577 pcMem.io.wen.head := GatedValidRegNext(io.frontend.fromFtq.pc_mem_wen) 578 pcMem.io.waddr.head := RegEnable(io.frontend.fromFtq.pc_mem_waddr, io.frontend.fromFtq.pc_mem_wen) 579 pcMem.io.wdata.head := RegEnable(io.frontend.fromFtq.pc_mem_wdata, io.frontend.fromFtq.pc_mem_wen) 580 581 io.toDataPath.flush := s2_s4_redirect 582 io.toExuBlock.flush := s2_s4_redirect 583 584 585 rob.io.hartId := io.fromTop.hartId 586 rob.io.redirect := s1_s3_redirect 587 rob.io.writeback := delayedNotFlushedWriteBack 588 rob.io.exuWriteback := delayedWriteBack 589 rob.io.writebackNums := VecInit(delayedNotFlushedWriteBackNums) 590 rob.io.writebackNeedFlush := delayedNotFlushedWriteBackNeedFlush 591 rob.io.readGPAMemData := gpaMem.io.exceptionReadData 592 rob.io.fromVecExcpMod.busy := io.fromVecExcpMod.busy 593 594 io.redirect := s1_s3_redirect 595 596 // rob to int block 597 io.robio.csr <> rob.io.csr 598 // When wfi is disabled, it will not block ROB commit. 599 rob.io.csr.wfiEvent := io.robio.csr.wfiEvent 600 rob.io.wfi_enable := decode.io.csrCtrl.wfi_enable 601 602 io.toTop.cpuHalt := DelayN(rob.io.cpu_halt, 5) 603 604 io.robio.csr.perfinfo.retiredInstr <> RegNext(rob.io.csr.perfinfo.retiredInstr) 605 io.robio.exception := rob.io.exception 606 io.robio.exception.bits.pc := s1_robFlushPc 607 608 // rob to mem block 609 io.robio.lsq <> rob.io.lsq 610 611 io.diff_int_rat.foreach(_ := rat.io.diff_int_rat.get) 612 io.diff_fp_rat .foreach(_ := rat.io.diff_fp_rat.get) 613 io.diff_vec_rat.foreach(_ := rat.io.diff_vec_rat.get) 614 io.diff_v0_rat .foreach(_ := rat.io.diff_v0_rat.get) 615 io.diff_vl_rat .foreach(_ := rat.io.diff_vl_rat.get) 616 617 rob.io.debug_ls := io.robio.debug_ls 618 rob.io.debugHeadLsIssue := io.robio.robHeadLsIssue 619 rob.io.lsTopdownInfo := io.robio.lsTopdownInfo 620 rob.io.criticalError := io.robio.criticalError 621 rob.io.debugEnqLsq := io.debugEnqLsq 622 623 io.robio.robDeqPtr := rob.io.robDeqPtr 624 625 // rob to backend 626 io.robio.commitVType := rob.io.toDecode.commitVType 627 // exu block to decode 628 decode.io.vsetvlVType := io.toDecode.vsetvlVType 629 // backend to decode 630 decode.io.vstart := io.toDecode.vstart 631 // backend to rob 632 rob.io.vstartIsZero := io.toDecode.vstart === 0.U 633 634 io.toCSR.trapInstInfo := decode.io.toCSR.trapInstInfo 635 636 io.toVecExcpMod.logicPhyRegMap := rob.io.toVecExcpMod.logicPhyRegMap 637 io.toVecExcpMod.excpInfo := rob.io.toVecExcpMod.excpInfo 638 // T : rat receive rabCommit 639 // T+1: rat return oldPdest 640 io.toVecExcpMod.ratOldPest match { 641 case fromRat => 642 (0 until RabCommitWidth).foreach { idx => 643 fromRat.v0OldVdPdest(idx).valid := RegNext( 644 rat.io.rabCommits.isCommit && 645 rat.io.rabCommits.isWalk && 646 rat.io.rabCommits.commitValid(idx) && 647 rat.io.rabCommits.info(idx).v0Wen 648 ) 649 fromRat.v0OldVdPdest(idx).bits := rat.io.v0_old_pdest(idx) 650 fromRat.vecOldVdPdest(idx).valid := RegNext( 651 rat.io.rabCommits.isCommit && 652 rat.io.rabCommits.isWalk && 653 rat.io.rabCommits.commitValid(idx) && 654 rat.io.rabCommits.info(idx).vecWen 655 ) 656 fromRat.vecOldVdPdest(idx).bits := rat.io.vec_old_pdest(idx) 657 } 658 } 659 660 io.debugTopDown.fromRob := rob.io.debugTopDown.toCore 661 dispatch.io.debugTopDown.fromRob := rob.io.debugTopDown.toDispatch 662 dispatch.io.debugTopDown.fromCore := io.debugTopDown.fromCore 663 io.debugRolling := rob.io.debugRolling 664 665 io.perfInfo.ctrlInfo.robFull := GatedValidRegNext(rob.io.robFull) 666 io.perfInfo.ctrlInfo.intdqFull := GatedValidRegNext(intDq0.io.dqFull || intDq1.io.dqFull) 667 io.perfInfo.ctrlInfo.fpdqFull := GatedValidRegNext(vecDq.io.dqFull) 668 io.perfInfo.ctrlInfo.lsdqFull := GatedValidRegNext(lsDq.io.dqFull) 669 670 val perfEvents = Seq(decode, rename, dispatch, intDq0, intDq1, vecDq, lsDq, rob).flatMap(_.getPerfEvents) 671 generatePerfEvent() 672 673 val criticalErrors = rob.getCriticalErrors 674 generateCriticalErrors() 675} 676 677class CtrlBlockIO()(implicit p: Parameters, params: BackendParams) extends XSBundle { 678 val fromTop = new Bundle { 679 val hartId = Input(UInt(8.W)) 680 } 681 val toTop = new Bundle { 682 val cpuHalt = Output(Bool()) 683 } 684 val frontend = Flipped(new FrontendToCtrlIO()) 685 val fromCSR = new Bundle{ 686 val toDecode = Input(new CSRToDecode) 687 } 688 val toIssueBlock = new Bundle { 689 val flush = ValidIO(new Redirect) 690 val allocPregs = Vec(RenameWidth, Output(new ResetPregStateReq)) 691 val intUops = Vec(dpParams.IntDqDeqWidth, DecoupledIO(new DynInst)) 692 val vfUops = Vec(dpParams.VecDqDeqWidth, DecoupledIO(new DynInst)) 693 val fpUops = Vec(dpParams.FpDqDeqWidth, DecoupledIO(new DynInst)) 694 val memUops = Vec(dpParams.LsDqDeqWidth, DecoupledIO(new DynInst)) 695 } 696 val toDataPath = new Bundle { 697 val flush = ValidIO(new Redirect) 698 } 699 val toExuBlock = new Bundle { 700 val flush = ValidIO(new Redirect) 701 } 702 val toCSR = new Bundle { 703 val trapInstInfo = Output(ValidIO(new TrapInstInfo)) 704 } 705 val intIQValidNumVec = Input(MixedVec(params.genIntIQValidNumBundle)) 706 val fpIQValidNumVec = Input(MixedVec(params.genFpIQValidNumBundle)) 707 val fromWB = new Bundle { 708 val wbData = Flipped(MixedVec(params.genWrite2CtrlBundles)) 709 } 710 val redirect = ValidIO(new Redirect) 711 val fromMem = new Bundle { 712 val stIn = Vec(params.StaExuCnt, Flipped(ValidIO(new DynInst))) // use storeSetHit, ssid, robIdx 713 val violation = Flipped(ValidIO(new Redirect)) 714 } 715 val memLdPcRead = Vec(params.LduCnt, Flipped(new FtqRead(UInt(VAddrBits.W)))) 716 val memStPcRead = Vec(params.StaCnt, Flipped(new FtqRead(UInt(VAddrBits.W)))) 717 val memHyPcRead = Vec(params.HyuCnt, Flipped(new FtqRead(UInt(VAddrBits.W)))) 718 719 val csrCtrl = Input(new CustomCSRCtrlIO) 720 val robio = new Bundle { 721 val csr = new RobCSRIO 722 val exception = ValidIO(new ExceptionInfo) 723 val lsq = new RobLsqIO 724 val lsTopdownInfo = Vec(params.LduCnt + params.HyuCnt, Input(new LsTopdownInfo)) 725 val debug_ls = Input(new DebugLSIO()) 726 val robHeadLsIssue = Input(Bool()) 727 val robDeqPtr = Output(new RobPtr) 728 val commitVType = new Bundle { 729 val vtype = Output(ValidIO(VType())) 730 val hasVsetvl = Output(Bool()) 731 } 732 val criticalError = Input(Bool()) 733 } 734 735 val toDecode = new Bundle { 736 val vsetvlVType = Input(VType()) 737 val vstart = Input(Vl()) 738 } 739 740 val fromVecExcpMod = Input(new Bundle { 741 val busy = Bool() 742 }) 743 744 val toVecExcpMod = Output(new Bundle { 745 val logicPhyRegMap = Vec(RabCommitWidth, ValidIO(new RegWriteFromRab)) 746 val excpInfo = ValidIO(new VecExcpInfo) 747 val ratOldPest = new RatToVecExcpMod 748 }) 749 750 val perfInfo = Output(new Bundle{ 751 val ctrlInfo = new Bundle { 752 val robFull = Bool() 753 val intdqFull = Bool() 754 val fpdqFull = Bool() 755 val lsdqFull = Bool() 756 } 757 }) 758 val diff_int_rat = if (params.basicDebugEn) Some(Vec(32, Output(UInt(PhyRegIdxWidth.W)))) else None 759 val diff_fp_rat = if (params.basicDebugEn) Some(Vec(32, Output(UInt(PhyRegIdxWidth.W)))) else None 760 val diff_vec_rat = if (params.basicDebugEn) Some(Vec(31, Output(UInt(PhyRegIdxWidth.W)))) else None 761 val diff_v0_rat = if (params.basicDebugEn) Some(Vec(1, Output(UInt(PhyRegIdxWidth.W)))) else None 762 val diff_vl_rat = if (params.basicDebugEn) Some(Vec(1, Output(UInt(PhyRegIdxWidth.W)))) else None 763 764 val sqCanAccept = Input(Bool()) 765 val lqCanAccept = Input(Bool()) 766 767 val debugTopDown = new Bundle { 768 val fromRob = new RobCoreTopDownIO 769 val fromCore = new CoreDispatchTopDownIO 770 } 771 val debugRolling = new RobDebugRollingIO 772 val debugEnqLsq = Input(new LsqEnqIO) 773} 774 775class NamedIndexes(namedCnt: Seq[(String, Int)]) { 776 require(namedCnt.map(_._1).distinct.size == namedCnt.size, "namedCnt should not have the same name") 777 778 val maxIdx = namedCnt.map(_._2).sum 779 val nameRangeMap: Map[String, (Int, Int)] = namedCnt.indices.map { i => 780 val begin = namedCnt.slice(0, i).map(_._2).sum 781 val end = begin + namedCnt(i)._2 782 (namedCnt(i)._1, (begin, end)) 783 }.toMap 784 785 def apply(name: String): Seq[Int] = { 786 require(nameRangeMap.contains(name)) 787 nameRangeMap(name)._1 until nameRangeMap(name)._2 788 } 789} 790