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