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 if(HasEncoder){ 249 trace.io.fromEncoder.stall := io.traceCoreInterface.fromEncoder.stall 250 trace.io.fromEncoder.enable := io.traceCoreInterface.fromEncoder.enable 251 } else if(!HasEncoder && TraceEnable) { 252 trace.io.fromEncoder.enable := true.B 253 trace.io.fromEncoder.stall := false.B 254 } else if(!HasEncoder && !TraceEnable) { 255 trace.io.fromEncoder.enable := false.B 256 trace.io.fromEncoder.stall := false.B 257 } 258 259 trace.io.fromRob := rob.io.trace.traceCommitInfo 260 rob.io.trace.blockCommit := trace.io.blockRobCommit 261 262 if(backendParams.debugEn){ 263 dontTouch(trace.io.toEncoder) 264 } 265 266 for ((pcMemIdx, i) <- pcMemRdIndexes("trace").zipWithIndex) { 267 val traceValid = trace.toPcMem(i).valid 268 pcMem.io.ren.get(pcMemIdx) := traceValid 269 pcMem.io.raddr(pcMemIdx) := trace.toPcMem(i).bits.ftqIdx.get.value 270 trace.io.fromPcMem(i) := pcMem.io.rdata(pcMemIdx).getPc(RegEnable(trace.toPcMem(i).bits.ftqOffset.get, traceValid)) 271 } 272 273 io.traceCoreInterface.toEncoder.cause := trace.io.toEncoder.trap.cause.asUInt 274 io.traceCoreInterface.toEncoder.tval := trace.io.toEncoder.trap.tval.asUInt 275 io.traceCoreInterface.toEncoder.priv := trace.io.toEncoder.trap.priv.asUInt 276 io.traceCoreInterface.toEncoder.iaddr := VecInit(trace.io.toEncoder.blocks.map(_.bits.iaddr.get)).asUInt 277 io.traceCoreInterface.toEncoder.itype := VecInit(trace.io.toEncoder.blocks.map(_.bits.tracePipe.itype)).asUInt 278 io.traceCoreInterface.toEncoder.iretire := VecInit(trace.io.toEncoder.blocks.map(_.bits.tracePipe.iretire)).asUInt 279 io.traceCoreInterface.toEncoder.ilastsize := VecInit(trace.io.toEncoder.blocks.map(_.bits.tracePipe.ilastsize)).asUInt 280 281 /** 282 * trace end 283 */ 284 285 286 redirectGen.io.hartId := io.fromTop.hartId 287 redirectGen.io.oldestExuRedirect.valid := GatedValidRegNext(oldestExuRedirect.valid) 288 redirectGen.io.oldestExuRedirect.bits := RegEnable(oldestExuRedirect.bits, oldestExuRedirect.valid) 289 redirectGen.io.oldestExuOutPredecode.valid := GatedValidRegNext(oldestExuPredecode.valid) 290 redirectGen.io.oldestExuOutPredecode := RegEnable(oldestExuPredecode, oldestExuPredecode.valid) 291 redirectGen.io.loadReplay <> loadReplay 292 val loadRedirectPcRead = pcMem.io.rdata(pcMemRdIndexes("redirect").head).getPc(RegEnable(memViolation.bits.ftqOffset, memViolation.valid)) 293 redirectGen.io.loadReplay.bits.cfiUpdate.pc := loadRedirectPcRead 294 val load_pc_offset = Mux(loadReplay.bits.flushItself(), 0.U, Mux(loadReplay.bits.isRVC, 2.U, 4.U)) 295 val load_target = loadRedirectPcRead + load_pc_offset 296 redirectGen.io.loadReplay.bits.cfiUpdate.target := load_target 297 298 redirectGen.io.robFlush := s1_robFlushRedirect 299 300 val s5_flushFromRobValidAhead = DelayN(s1_robFlushRedirect.valid, 4) 301 val s6_flushFromRobValid = GatedValidRegNext(s5_flushFromRobValidAhead) 302 val frontendFlushBits = RegEnable(s1_robFlushRedirect.bits, s1_robFlushRedirect.valid) // ?? 303 // When ROB commits an instruction with a flush, we notify the frontend of the flush without the commit. 304 // Flushes to frontend may be delayed by some cycles and commit before flush causes errors. 305 // Thus, we make all flush reasons to behave the same as exceptions for frontend. 306 for (i <- 0 until CommitWidth) { 307 // why flushOut: instructions with flushPipe are not commited to frontend 308 // If we commit them to frontend, it will cause flush after commit, which is not acceptable by frontend. 309 val s1_isCommit = rob.io.commits.commitValid(i) && rob.io.commits.isCommit && !s0_robFlushRedirect.valid 310 io.frontend.toFtq.rob_commits(i).valid := GatedValidRegNext(s1_isCommit) 311 io.frontend.toFtq.rob_commits(i).bits := RegEnable(rob.io.commits.info(i), s1_isCommit) 312 } 313 io.frontend.toFtq.redirect.valid := s6_flushFromRobValid || s3_redirectGen.valid 314 io.frontend.toFtq.redirect.bits := Mux(s6_flushFromRobValid, frontendFlushBits, s3_redirectGen.bits) 315 io.frontend.toFtq.ftqIdxSelOH.valid := s6_flushFromRobValid || redirectGen.io.stage2Redirect.valid 316 io.frontend.toFtq.ftqIdxSelOH.bits := Cat(s6_flushFromRobValid, redirectGen.io.stage2oldestOH & Fill(NumRedirect + 1, !s6_flushFromRobValid)) 317 318 //jmp/brh, sel oldest first, only use one read port 319 io.frontend.toFtq.ftqIdxAhead(0).valid := RegNext(oldestExuRedirect.valid) && !s1_robFlushRedirect.valid && !s5_flushFromRobValidAhead 320 io.frontend.toFtq.ftqIdxAhead(0).bits := RegEnable(oldestExuRedirect.bits.ftqIdx, oldestExuRedirect.valid) 321 //loadreplay 322 io.frontend.toFtq.ftqIdxAhead(NumRedirect).valid := loadReplay.valid && !s1_robFlushRedirect.valid && !s5_flushFromRobValidAhead 323 io.frontend.toFtq.ftqIdxAhead(NumRedirect).bits := loadReplay.bits.ftqIdx 324 //exception 325 io.frontend.toFtq.ftqIdxAhead.last.valid := s5_flushFromRobValidAhead 326 io.frontend.toFtq.ftqIdxAhead.last.bits := frontendFlushBits.ftqIdx 327 328 // Be careful here: 329 // T0: rob.io.flushOut, s0_robFlushRedirect 330 // T1: s1_robFlushRedirect, rob.io.exception.valid 331 // T2: csr.redirect.valid 332 // T3: csr.exception.valid 333 // T4: csr.trapTarget 334 // T5: ctrlBlock.trapTarget 335 // T6: io.frontend.toFtq.stage2Redirect.valid 336 val s2_robFlushPc = RegEnable(Mux(s1_robFlushRedirect.bits.flushItself(), 337 s1_robFlushPc, // replay inst 338 s1_robFlushPc + Mux(s1_robFlushRedirect.bits.isRVC, 2.U, 4.U) // flush pipe 339 ), s1_robFlushRedirect.valid) 340 private val s5_csrIsTrap = DelayN(rob.io.exception.valid, 4) 341 private val s5_trapTargetFromCsr = io.robio.csr.trapTarget 342 343 val flushTarget = Mux(s5_csrIsTrap, s5_trapTargetFromCsr.pc, s2_robFlushPc) 344 val s5_trapTargetIAF = Mux(s5_csrIsTrap, s5_trapTargetFromCsr.raiseIAF, false.B) 345 val s5_trapTargetIPF = Mux(s5_csrIsTrap, s5_trapTargetFromCsr.raiseIPF, false.B) 346 val s5_trapTargetIGPF = Mux(s5_csrIsTrap, s5_trapTargetFromCsr.raiseIGPF, false.B) 347 when (s6_flushFromRobValid) { 348 io.frontend.toFtq.redirect.bits.level := RedirectLevel.flush 349 io.frontend.toFtq.redirect.bits.cfiUpdate.target := RegEnable(flushTarget, s5_flushFromRobValidAhead) 350 io.frontend.toFtq.redirect.bits.cfiUpdate.backendIAF := RegEnable(s5_trapTargetIAF, s5_flushFromRobValidAhead) 351 io.frontend.toFtq.redirect.bits.cfiUpdate.backendIPF := RegEnable(s5_trapTargetIPF, s5_flushFromRobValidAhead) 352 io.frontend.toFtq.redirect.bits.cfiUpdate.backendIGPF := RegEnable(s5_trapTargetIGPF, s5_flushFromRobValidAhead) 353 } 354 355 for (i <- 0 until DecodeWidth) { 356 gpaMem.io.fromIFU := io.frontend.fromIfu 357 gpaMem.io.exceptionReadAddr.valid := rob.io.readGPAMemAddr.valid 358 gpaMem.io.exceptionReadAddr.bits.ftqPtr := rob.io.readGPAMemAddr.bits.ftqPtr 359 gpaMem.io.exceptionReadAddr.bits.ftqOffset := rob.io.readGPAMemAddr.bits.ftqOffset 360 } 361 362 // vtype commit 363 decode.io.fromCSR := io.fromCSR.toDecode 364 decode.io.fromRob.isResumeVType := rob.io.toDecode.isResumeVType 365 decode.io.fromRob.walkToArchVType := rob.io.toDecode.walkToArchVType 366 decode.io.fromRob.commitVType := rob.io.toDecode.commitVType 367 decode.io.fromRob.walkVType := rob.io.toDecode.walkVType 368 369 decode.io.redirect := s1_s3_redirect.valid || s2_s4_pendingRedirectValid 370 371 // add decode Buf for in.ready better timing 372 val decodeBufBits = Reg(Vec(DecodeWidth, new StaticInst)) 373 val decodeBufValid = RegInit(VecInit(Seq.fill(DecodeWidth)(false.B))) 374 val decodeFromFrontend = io.frontend.cfVec 375 val decodeBufNotAccept = VecInit(decodeBufValid.zip(decode.io.in).map(x => x._1 && !x._2.ready)) 376 val decodeBufAcceptNum = PriorityMuxDefault(decodeBufNotAccept.zip(Seq.tabulate(DecodeWidth)(i => i.U)), DecodeWidth.U) 377 val decodeFromFrontendNotAccept = VecInit(decodeFromFrontend.zip(decode.io.in).map(x => decodeBufValid(0) || x._1.valid && !x._2.ready)) 378 val decodeFromFrontendAcceptNum = PriorityMuxDefault(decodeFromFrontendNotAccept.zip(Seq.tabulate(DecodeWidth)(i => i.U)), DecodeWidth.U) 379 if (backendParams.debugEn) { 380 dontTouch(decodeBufNotAccept) 381 dontTouch(decodeBufAcceptNum) 382 dontTouch(decodeFromFrontendNotAccept) 383 dontTouch(decodeFromFrontendAcceptNum) 384 } 385 val a = decodeBufNotAccept.drop(2) 386 for (i <- 0 until DecodeWidth) { 387 // decodeBufValid update 388 when(decode.io.redirect || decodeBufValid(0) && decodeBufValid(i) && decode.io.in(i).ready && !VecInit(decodeBufNotAccept.drop(i)).asUInt.orR) { 389 decodeBufValid(i) := false.B 390 }.elsewhen(decodeBufValid(i) && VecInit(decodeBufNotAccept.drop(i)).asUInt.orR) { 391 decodeBufValid(i) := Mux(decodeBufAcceptNum > DecodeWidth.U - 1.U - i.U, false.B, decodeBufValid(i.U + decodeBufAcceptNum)) 392 }.elsewhen(!decodeBufValid(0) && VecInit(decodeFromFrontendNotAccept.drop(i)).asUInt.orR) { 393 decodeBufValid(i) := Mux(decodeFromFrontendAcceptNum > DecodeWidth.U - 1.U - i.U, false.B, decodeFromFrontend(i.U + decodeFromFrontendAcceptNum).valid) 394 } 395 // decodeBufBits update 396 when(decodeBufValid(i) && VecInit(decodeBufNotAccept.drop(i)).asUInt.orR) { 397 decodeBufBits(i) := decodeBufBits(i.U + decodeBufAcceptNum) 398 }.elsewhen(!decodeBufValid(0) && VecInit(decodeFromFrontendNotAccept.drop(i)).asUInt.orR) { 399 decodeBufBits(i).connectCtrlFlow(decodeFromFrontend(i.U + decodeFromFrontendAcceptNum).bits) 400 } 401 } 402 val decodeConnectFromFrontend = Wire(Vec(DecodeWidth, new StaticInst)) 403 decodeConnectFromFrontend.zip(decodeFromFrontend).map(x => x._1.connectCtrlFlow(x._2.bits)) 404 decode.io.in.zipWithIndex.foreach { case (decodeIn, i) => 405 decodeIn.valid := Mux(decodeBufValid(0), decodeBufValid(i), decodeFromFrontend(i).valid) 406 decodeFromFrontend(i).ready := decodeFromFrontend(0).valid && !decodeBufValid(0) && decodeFromFrontend(i).valid && !decode.io.redirect 407 decodeIn.bits := Mux(decodeBufValid(i), decodeBufBits(i), decodeConnectFromFrontend(i)) 408 } 409 io.frontend.canAccept := !decodeBufValid(0) || !decodeFromFrontend(0).valid 410 decode.io.csrCtrl := RegNext(io.csrCtrl) 411 decode.io.intRat <> rat.io.intReadPorts 412 decode.io.fpRat <> rat.io.fpReadPorts 413 decode.io.vecRat <> rat.io.vecReadPorts 414 decode.io.v0Rat <> rat.io.v0ReadPorts 415 decode.io.vlRat <> rat.io.vlReadPorts 416 decode.io.fusion := 0.U.asTypeOf(decode.io.fusion) // Todo 417 decode.io.stallReason.in <> io.frontend.stallReason 418 419 // snapshot check 420 class CFIRobIdx extends Bundle { 421 val robIdx = Vec(RenameWidth, new RobPtr) 422 val isCFI = Vec(RenameWidth, Bool()) 423 } 424 val genSnapshot = Cat(rename.io.out.map(out => out.fire && out.bits.snapshot)).orR 425 val snpt = Module(new SnapshotGenerator(0.U.asTypeOf(new CFIRobIdx))) 426 snpt.io.enq := genSnapshot 427 snpt.io.enqData.robIdx := rename.io.out.map(_.bits.robIdx) 428 snpt.io.enqData.isCFI := rename.io.out.map(_.bits.snapshot) 429 snpt.io.deq := snpt.io.valids(snpt.io.deqPtr.value) && rob.io.commits.isCommit && 430 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 431 snpt.io.redirect := s1_s3_redirect.valid 432 val flushVec = VecInit(snpt.io.snapshots.map { snapshot => 433 val notCFIMask = snapshot.isCFI.map(~_) 434 val shouldFlush = snapshot.robIdx.map(robIdx => robIdx >= s1_s3_redirect.bits.robIdx || robIdx.value === s1_s3_redirect.bits.robIdx.value) 435 val shouldFlushMask = (1 to RenameWidth).map(shouldFlush take _ reduce (_ || _)) 436 s1_s3_redirect.valid && Cat(shouldFlushMask.zip(notCFIMask).map(x => x._1 | x._2)).andR 437 }) 438 val flushVecNext = flushVec zip snpt.io.valids map (x => GatedValidRegNext(x._1 && x._2, false.B)) 439 snpt.io.flushVec := flushVecNext 440 441 val useSnpt = VecInit.tabulate(RenameSnapshotNum)(idx => 442 snpt.io.valids(idx) && (s1_s3_redirect.bits.robIdx > snpt.io.snapshots(idx).robIdx.head || 443 !s1_s3_redirect.bits.flushItself() && s1_s3_redirect.bits.robIdx === snpt.io.snapshots(idx).robIdx.head) 444 ).reduceTree(_ || _) 445 val snptSelect = MuxCase( 446 0.U(log2Ceil(RenameSnapshotNum).W), 447 (1 to RenameSnapshotNum).map(i => (snpt.io.enqPtr - i.U).value).map(idx => 448 (snpt.io.valids(idx) && (s1_s3_redirect.bits.robIdx > snpt.io.snapshots(idx).robIdx.head || 449 !s1_s3_redirect.bits.flushItself() && s1_s3_redirect.bits.robIdx === snpt.io.snapshots(idx).robIdx.head), idx) 450 ) 451 ) 452 453 rob.io.snpt.snptEnq := DontCare 454 rob.io.snpt.snptDeq := snpt.io.deq 455 rob.io.snpt.useSnpt := useSnpt 456 rob.io.snpt.snptSelect := snptSelect 457 rob.io.snpt.flushVec := flushVecNext 458 rat.io.snpt.snptEnq := genSnapshot 459 rat.io.snpt.snptDeq := snpt.io.deq 460 rat.io.snpt.useSnpt := useSnpt 461 rat.io.snpt.snptSelect := snptSelect 462 rat.io.snpt.flushVec := flushVec 463 464 val decodeHasException = decode.io.out.map(x => x.bits.exceptionVec(instrPageFault) || x.bits.exceptionVec(instrAccessFault)) 465 // fusion decoder 466 for (i <- 0 until DecodeWidth) { 467 fusionDecoder.io.in(i).valid := decode.io.out(i).valid && !(decodeHasException(i) || disableFusion) 468 fusionDecoder.io.in(i).bits := decode.io.out(i).bits.instr 469 if (i > 0) { 470 fusionDecoder.io.inReady(i - 1) := decode.io.out(i).ready 471 } 472 } 473 474 private val decodePipeRename = Wire(Vec(RenameWidth, DecoupledIO(new DecodedInst))) 475 for (i <- 0 until RenameWidth) { 476 PipelineConnect(decode.io.out(i), decodePipeRename(i), rename.io.in(i).ready, 477 s1_s3_redirect.valid || s2_s4_pendingRedirectValid, moduleName = Some("decodePipeRenameModule")) 478 479 decodePipeRename(i).ready := rename.io.in(i).ready 480 rename.io.in(i).valid := decodePipeRename(i).valid && !fusionDecoder.io.clear(i) 481 rename.io.in(i).bits := decodePipeRename(i).bits 482 } 483 484 for (i <- 0 until RenameWidth - 1) { 485 fusionDecoder.io.dec(i) := decodePipeRename(i).bits 486 rename.io.fusionInfo(i) := fusionDecoder.io.info(i) 487 488 // update the first RenameWidth - 1 instructions 489 decode.io.fusion(i) := fusionDecoder.io.out(i).valid && rename.io.out(i).fire 490 when (fusionDecoder.io.out(i).valid) { 491 fusionDecoder.io.out(i).bits.update(rename.io.in(i).bits) 492 // TODO: remove this dirty code for ftq update 493 val sameFtqPtr = rename.io.in(i).bits.ftqPtr.value === rename.io.in(i + 1).bits.ftqPtr.value 494 val ftqOffset0 = rename.io.in(i).bits.ftqOffset 495 val ftqOffset1 = rename.io.in(i + 1).bits.ftqOffset 496 val ftqOffsetDiff = ftqOffset1 - ftqOffset0 497 val cond1 = sameFtqPtr && ftqOffsetDiff === 1.U 498 val cond2 = sameFtqPtr && ftqOffsetDiff === 2.U 499 val cond3 = !sameFtqPtr && ftqOffset1 === 0.U 500 val cond4 = !sameFtqPtr && ftqOffset1 === 1.U 501 rename.io.in(i).bits.commitType := Mux(cond1, 4.U, Mux(cond2, 5.U, Mux(cond3, 6.U, 7.U))) 502 XSError(!cond1 && !cond2 && !cond3 && !cond4, p"new condition $sameFtqPtr $ftqOffset0 $ftqOffset1\n") 503 } 504 505 } 506 507 // memory dependency predict 508 // when decode, send fold pc to mdp 509 private val mdpFlodPcVecVld = Wire(Vec(DecodeWidth, Bool())) 510 private val mdpFlodPcVec = Wire(Vec(DecodeWidth, UInt(MemPredPCWidth.W))) 511 for (i <- 0 until DecodeWidth) { 512 mdpFlodPcVecVld(i) := decode.io.out(i).fire || GatedValidRegNext(decode.io.out(i).fire) 513 mdpFlodPcVec(i) := Mux( 514 decode.io.out(i).fire, 515 decode.io.in(i).bits.foldpc, 516 rename.io.in(i).bits.foldpc 517 ) 518 } 519 520 // currently, we only update mdp info when isReplay 521 memCtrl.io.redirect := s1_s3_redirect 522 memCtrl.io.csrCtrl := io.csrCtrl // RegNext in memCtrl 523 memCtrl.io.stIn := io.fromMem.stIn // RegNext in memCtrl 524 memCtrl.io.memPredUpdate := redirectGen.io.memPredUpdate // RegNext in memCtrl 525 memCtrl.io.mdpFoldPcVecVld := mdpFlodPcVecVld 526 memCtrl.io.mdpFlodPcVec := mdpFlodPcVec 527 memCtrl.io.dispatchLFSTio <> dispatch.io.lfst 528 529 rat.io.redirect := s1_s3_redirect.valid 530 rat.io.rabCommits := rob.io.rabCommits 531 rat.io.diffCommits.foreach(_ := rob.io.diffCommits.get) 532 rat.io.intRenamePorts := rename.io.intRenamePorts 533 rat.io.fpRenamePorts := rename.io.fpRenamePorts 534 rat.io.vecRenamePorts := rename.io.vecRenamePorts 535 rat.io.v0RenamePorts := rename.io.v0RenamePorts 536 rat.io.vlRenamePorts := rename.io.vlRenamePorts 537 538 rename.io.redirect := s1_s3_redirect 539 rename.io.rabCommits := rob.io.rabCommits 540 rename.io.singleStep := GatedValidRegNext(io.csrCtrl.singlestep) 541 rename.io.waittable := (memCtrl.io.waitTable2Rename zip decode.io.out).map{ case(waittable2rename, decodeOut) => 542 RegEnable(waittable2rename, decodeOut.fire) 543 } 544 rename.io.ssit := memCtrl.io.ssit2Rename 545 rename.io.intReadPorts := VecInit(rat.io.intReadPorts.map(x => VecInit(x.map(_.data)))) 546 rename.io.fpReadPorts := VecInit(rat.io.fpReadPorts.map(x => VecInit(x.map(_.data)))) 547 rename.io.vecReadPorts := VecInit(rat.io.vecReadPorts.map(x => VecInit(x.map(_.data)))) 548 rename.io.v0ReadPorts := VecInit(rat.io.v0ReadPorts.map(x => VecInit(x.data))) 549 rename.io.vlReadPorts := VecInit(rat.io.vlReadPorts.map(x => VecInit(x.data))) 550 rename.io.int_need_free := rat.io.int_need_free 551 rename.io.int_old_pdest := rat.io.int_old_pdest 552 rename.io.fp_old_pdest := rat.io.fp_old_pdest 553 rename.io.vec_old_pdest := rat.io.vec_old_pdest 554 rename.io.v0_old_pdest := rat.io.v0_old_pdest 555 rename.io.vl_old_pdest := rat.io.vl_old_pdest 556 rename.io.debug_int_rat.foreach(_ := rat.io.debug_int_rat.get) 557 rename.io.debug_fp_rat.foreach(_ := rat.io.debug_fp_rat.get) 558 rename.io.debug_vec_rat.foreach(_ := rat.io.debug_vec_rat.get) 559 rename.io.debug_v0_rat.foreach(_ := rat.io.debug_v0_rat.get) 560 rename.io.debug_vl_rat.foreach(_ := rat.io.debug_vl_rat.get) 561 rename.io.stallReason.in <> decode.io.stallReason.out 562 rename.io.snpt.snptEnq := DontCare 563 rename.io.snpt.snptDeq := snpt.io.deq 564 rename.io.snpt.useSnpt := useSnpt 565 rename.io.snpt.snptSelect := snptSelect 566 rename.io.snptIsFull := snpt.io.valids.asUInt.andR 567 rename.io.snpt.flushVec := flushVecNext 568 rename.io.snptLastEnq.valid := !isEmpty(snpt.io.enqPtr, snpt.io.deqPtr) 569 rename.io.snptLastEnq.bits := snpt.io.snapshots((snpt.io.enqPtr - 1.U).value).robIdx.head 570 571 val renameOut = Wire(chiselTypeOf(rename.io.out)) 572 renameOut <> rename.io.out 573 // pass all snapshot in the first element for correctness of blockBackward 574 renameOut.tail.foreach(_.bits.snapshot := false.B) 575 renameOut.head.bits.snapshot := Mux(isFull(snpt.io.enqPtr, snpt.io.deqPtr), 576 false.B, 577 Cat(rename.io.out.map(out => out.valid && out.bits.snapshot)).orR 578 ) 579 580 // pipeline between rename and dispatch 581 PipeGroupConnect(renameOut, dispatch.io.fromRename, s1_s3_redirect.valid, dispatch.io.toRenameAllFire, "renamePipeDispatch") 582 dispatch.io.intIQValidNumVec := io.intIQValidNumVec 583 dispatch.io.fpIQValidNumVec := io.fpIQValidNumVec 584 dispatch.io.fromIntDQ.intDQ0ValidDeq0Num := intDq0.io.validDeq0Num 585 dispatch.io.fromIntDQ.intDQ0ValidDeq1Num := intDq0.io.validDeq1Num 586 dispatch.io.fromIntDQ.intDQ1ValidDeq0Num := intDq1.io.validDeq0Num 587 dispatch.io.fromIntDQ.intDQ1ValidDeq1Num := intDq1.io.validDeq1Num 588 589 dispatch.io.hartId := io.fromTop.hartId 590 dispatch.io.redirect := s1_s3_redirect 591 dispatch.io.enqRob <> rob.io.enq 592 dispatch.io.robHead := rob.io.debugRobHead 593 dispatch.io.stallReason <> rename.io.stallReason.out 594 dispatch.io.lqCanAccept := io.lqCanAccept 595 dispatch.io.sqCanAccept := io.sqCanAccept 596 dispatch.io.robHeadNotReady := rob.io.headNotReady 597 dispatch.io.robFull := rob.io.robFull 598 dispatch.io.singleStep := GatedValidRegNext(io.csrCtrl.singlestep) 599 600 intDq0.io.enq <> dispatch.io.toIntDq0 601 intDq0.io.redirect <> s2_s4_redirect 602 intDq1.io.enq <> dispatch.io.toIntDq1 603 intDq1.io.redirect <> s2_s4_redirect 604 605 fpDq.io.enq <> dispatch.io.toFpDq 606 fpDq.io.redirect <> s2_s4_redirect 607 608 vecDq.io.enq <> dispatch.io.toVecDq 609 vecDq.io.redirect <> s2_s4_redirect 610 611 lsDq.io.enq <> dispatch.io.toLsDq 612 lsDq.io.redirect <> s2_s4_redirect 613 614 io.toIssueBlock.intUops <> (intDq0.io.deq :++ intDq1.io.deq) 615 io.toIssueBlock.fpUops <> fpDq.io.deq 616 io.toIssueBlock.vfUops <> vecDq.io.deq 617 io.toIssueBlock.memUops <> lsDq.io.deq 618 io.toIssueBlock.allocPregs <> dispatch.io.allocPregs 619 io.toIssueBlock.flush <> s2_s4_redirect 620 621 pcMem.io.wen.head := GatedValidRegNext(io.frontend.fromFtq.pc_mem_wen) 622 pcMem.io.waddr.head := RegEnable(io.frontend.fromFtq.pc_mem_waddr, io.frontend.fromFtq.pc_mem_wen) 623 pcMem.io.wdata.head := RegEnable(io.frontend.fromFtq.pc_mem_wdata, io.frontend.fromFtq.pc_mem_wen) 624 625 io.toDataPath.flush := s2_s4_redirect 626 io.toExuBlock.flush := s2_s4_redirect 627 628 629 rob.io.hartId := io.fromTop.hartId 630 rob.io.redirect := s1_s3_redirect 631 rob.io.writeback := delayedNotFlushedWriteBack 632 rob.io.exuWriteback := delayedWriteBack 633 rob.io.writebackNums := VecInit(delayedNotFlushedWriteBackNums) 634 rob.io.writebackNeedFlush := delayedNotFlushedWriteBackNeedFlush 635 rob.io.readGPAMemData := gpaMem.io.exceptionReadData 636 rob.io.fromVecExcpMod.busy := io.fromVecExcpMod.busy 637 638 io.redirect := s1_s3_redirect 639 640 // rob to int block 641 io.robio.csr <> rob.io.csr 642 // When wfi is disabled, it will not block ROB commit. 643 rob.io.csr.wfiEvent := io.robio.csr.wfiEvent 644 rob.io.wfi_enable := decode.io.csrCtrl.wfi_enable 645 646 io.toTop.cpuHalt := DelayN(rob.io.cpu_halt, 5) 647 648 io.robio.csr.perfinfo.retiredInstr <> RegNext(rob.io.csr.perfinfo.retiredInstr) 649 io.robio.exception := rob.io.exception 650 io.robio.exception.bits.pc := s1_robFlushPc 651 652 // rob to mem block 653 io.robio.lsq <> rob.io.lsq 654 655 io.diff_int_rat.foreach(_ := rat.io.diff_int_rat.get) 656 io.diff_fp_rat .foreach(_ := rat.io.diff_fp_rat.get) 657 io.diff_vec_rat.foreach(_ := rat.io.diff_vec_rat.get) 658 io.diff_v0_rat .foreach(_ := rat.io.diff_v0_rat.get) 659 io.diff_vl_rat .foreach(_ := rat.io.diff_vl_rat.get) 660 661 rob.io.debug_ls := io.robio.debug_ls 662 rob.io.debugHeadLsIssue := io.robio.robHeadLsIssue 663 rob.io.lsTopdownInfo := io.robio.lsTopdownInfo 664 rob.io.csr.criticalErrorState := io.robio.csr.criticalErrorState 665 rob.io.debugEnqLsq := io.debugEnqLsq 666 667 io.robio.robDeqPtr := rob.io.robDeqPtr 668 669 io.robio.storeDebugInfo <> rob.io.storeDebugInfo 670 671 // rob to backend 672 io.robio.commitVType := rob.io.toDecode.commitVType 673 // exu block to decode 674 decode.io.vsetvlVType := io.toDecode.vsetvlVType 675 // backend to decode 676 decode.io.vstart := io.toDecode.vstart 677 // backend to rob 678 rob.io.vstartIsZero := io.toDecode.vstart === 0.U 679 680 io.toCSR.trapInstInfo := decode.io.toCSR.trapInstInfo 681 682 io.toVecExcpMod.logicPhyRegMap := rob.io.toVecExcpMod.logicPhyRegMap 683 io.toVecExcpMod.excpInfo := rob.io.toVecExcpMod.excpInfo 684 // T : rat receive rabCommit 685 // T+1: rat return oldPdest 686 io.toVecExcpMod.ratOldPest match { 687 case fromRat => 688 (0 until RabCommitWidth).foreach { idx => 689 fromRat.v0OldVdPdest(idx).valid := RegNext( 690 rat.io.rabCommits.isCommit && 691 rat.io.rabCommits.isWalk && 692 rat.io.rabCommits.commitValid(idx) && 693 rat.io.rabCommits.info(idx).v0Wen 694 ) 695 fromRat.v0OldVdPdest(idx).bits := rat.io.v0_old_pdest(idx) 696 fromRat.vecOldVdPdest(idx).valid := RegNext( 697 rat.io.rabCommits.isCommit && 698 rat.io.rabCommits.isWalk && 699 rat.io.rabCommits.commitValid(idx) && 700 rat.io.rabCommits.info(idx).vecWen 701 ) 702 fromRat.vecOldVdPdest(idx).bits := rat.io.vec_old_pdest(idx) 703 } 704 } 705 706 io.debugTopDown.fromRob := rob.io.debugTopDown.toCore 707 dispatch.io.debugTopDown.fromRob := rob.io.debugTopDown.toDispatch 708 dispatch.io.debugTopDown.fromCore := io.debugTopDown.fromCore 709 io.debugRolling := rob.io.debugRolling 710 711 io.perfInfo.ctrlInfo.robFull := GatedValidRegNext(rob.io.robFull) 712 io.perfInfo.ctrlInfo.intdqFull := GatedValidRegNext(intDq0.io.dqFull || intDq1.io.dqFull) 713 io.perfInfo.ctrlInfo.fpdqFull := GatedValidRegNext(vecDq.io.dqFull) 714 io.perfInfo.ctrlInfo.lsdqFull := GatedValidRegNext(lsDq.io.dqFull) 715 716 val perfEvents = Seq(decode, rename, dispatch, intDq0, intDq1, vecDq, lsDq, rob).flatMap(_.getPerfEvents) 717 generatePerfEvent() 718 719 val criticalErrors = rob.getCriticalErrors 720 generateCriticalErrors() 721} 722 723class CtrlBlockIO()(implicit p: Parameters, params: BackendParams) extends XSBundle { 724 val fromTop = new Bundle { 725 val hartId = Input(UInt(8.W)) 726 } 727 val toTop = new Bundle { 728 val cpuHalt = Output(Bool()) 729 } 730 val frontend = Flipped(new FrontendToCtrlIO()) 731 val fromCSR = new Bundle{ 732 val toDecode = Input(new CSRToDecode) 733 } 734 val toIssueBlock = new Bundle { 735 val flush = ValidIO(new Redirect) 736 val allocPregs = Vec(RenameWidth, Output(new ResetPregStateReq)) 737 val intUops = Vec(dpParams.IntDqDeqWidth, DecoupledIO(new DynInst)) 738 val vfUops = Vec(dpParams.VecDqDeqWidth, DecoupledIO(new DynInst)) 739 val fpUops = Vec(dpParams.FpDqDeqWidth, DecoupledIO(new DynInst)) 740 val memUops = Vec(dpParams.LsDqDeqWidth, DecoupledIO(new DynInst)) 741 } 742 val toDataPath = new Bundle { 743 val flush = ValidIO(new Redirect) 744 } 745 val toExuBlock = new Bundle { 746 val flush = ValidIO(new Redirect) 747 } 748 val toCSR = new Bundle { 749 val trapInstInfo = Output(ValidIO(new TrapInstInfo)) 750 } 751 val intIQValidNumVec = Input(MixedVec(params.genIntIQValidNumBundle)) 752 val fpIQValidNumVec = Input(MixedVec(params.genFpIQValidNumBundle)) 753 val fromWB = new Bundle { 754 val wbData = Flipped(MixedVec(params.genWrite2CtrlBundles)) 755 } 756 val redirect = ValidIO(new Redirect) 757 val fromMem = new Bundle { 758 val stIn = Vec(params.StaExuCnt, Flipped(ValidIO(new DynInst))) // use storeSetHit, ssid, robIdx 759 val violation = Flipped(ValidIO(new Redirect)) 760 } 761 val memLdPcRead = Vec(params.LduCnt, Flipped(new FtqRead(UInt(VAddrBits.W)))) 762 val memStPcRead = Vec(params.StaCnt, Flipped(new FtqRead(UInt(VAddrBits.W)))) 763 val memHyPcRead = Vec(params.HyuCnt, Flipped(new FtqRead(UInt(VAddrBits.W)))) 764 765 val csrCtrl = Input(new CustomCSRCtrlIO) 766 val robio = new Bundle { 767 val csr = new RobCSRIO 768 val exception = ValidIO(new ExceptionInfo) 769 val lsq = new RobLsqIO 770 val lsTopdownInfo = Vec(params.LduCnt + params.HyuCnt, Input(new LsTopdownInfo)) 771 val debug_ls = Input(new DebugLSIO()) 772 val robHeadLsIssue = Input(Bool()) 773 val robDeqPtr = Output(new RobPtr) 774 val commitVType = new Bundle { 775 val vtype = Output(ValidIO(VType())) 776 val hasVsetvl = Output(Bool()) 777 } 778 779 // store event difftest information 780 val storeDebugInfo = Vec(EnsbufferWidth, new Bundle { 781 val robidx = Input(new RobPtr) 782 val pc = Output(UInt(VAddrBits.W)) 783 }) 784 } 785 786 val toDecode = new Bundle { 787 val vsetvlVType = Input(VType()) 788 val vstart = Input(Vl()) 789 } 790 791 val fromVecExcpMod = Input(new Bundle { 792 val busy = Bool() 793 }) 794 795 val toVecExcpMod = Output(new Bundle { 796 val logicPhyRegMap = Vec(RabCommitWidth, ValidIO(new RegWriteFromRab)) 797 val excpInfo = ValidIO(new VecExcpInfo) 798 val ratOldPest = new RatToVecExcpMod 799 }) 800 801 val traceCoreInterface = new TraceCoreInterface 802 803 val perfInfo = Output(new Bundle{ 804 val ctrlInfo = new Bundle { 805 val robFull = Bool() 806 val intdqFull = Bool() 807 val fpdqFull = Bool() 808 val lsdqFull = Bool() 809 } 810 }) 811 val diff_int_rat = if (params.basicDebugEn) Some(Vec(32, Output(UInt(PhyRegIdxWidth.W)))) else None 812 val diff_fp_rat = if (params.basicDebugEn) Some(Vec(32, Output(UInt(PhyRegIdxWidth.W)))) else None 813 val diff_vec_rat = if (params.basicDebugEn) Some(Vec(31, Output(UInt(PhyRegIdxWidth.W)))) else None 814 val diff_v0_rat = if (params.basicDebugEn) Some(Vec(1, Output(UInt(PhyRegIdxWidth.W)))) else None 815 val diff_vl_rat = if (params.basicDebugEn) Some(Vec(1, Output(UInt(PhyRegIdxWidth.W)))) else None 816 817 val sqCanAccept = Input(Bool()) 818 val lqCanAccept = Input(Bool()) 819 820 val debugTopDown = new Bundle { 821 val fromRob = new RobCoreTopDownIO 822 val fromCore = new CoreDispatchTopDownIO 823 } 824 val debugRolling = new RobDebugRollingIO 825 val debugEnqLsq = Input(new LsqEnqIO) 826} 827 828class NamedIndexes(namedCnt: Seq[(String, Int)]) { 829 require(namedCnt.map(_._1).distinct.size == namedCnt.size, "namedCnt should not have the same name") 830 831 val maxIdx = namedCnt.map(_._2).sum 832 val nameRangeMap: Map[String, (Int, Int)] = namedCnt.indices.map { i => 833 val begin = namedCnt.slice(0, i).map(_._2).sum 834 val end = begin + namedCnt(i)._2 835 (namedCnt(i)._1, (begin, end)) 836 }.toMap 837 838 def apply(name: String): Seq[Int] = { 839 require(nameRangeMap.contains(name)) 840 nameRangeMap(name)._1 until nameRangeMap(name)._2 841 } 842} 843