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 chipsalliance.rocketchip.config.Parameters 20import chisel3._ 21import chisel3.util._ 22import difftest._ 23import freechips.rocketchip.diplomacy.{LazyModule, LazyModuleImp} 24import utils._ 25import xiangshan._ 26import xiangshan.backend.decode.{DecodeStage, ImmUnion} 27import xiangshan.backend.dispatch.{Dispatch, DispatchQueue} 28import xiangshan.backend.fu.PFEvent 29import xiangshan.backend.rename.{Rename, RenameTableWrapper} 30import xiangshan.backend.rob.{Rob, RobCSRIO, RobLsqIO} 31import xiangshan.frontend.FtqRead 32import xiangshan.mem.mdp.{LFST, SSIT, WaitTable} 33 34class CtrlToFtqIO(implicit p: Parameters) extends XSBundle { 35 def numRedirect = exuParameters.JmpCnt + exuParameters.AluCnt 36 val rob_commits = Vec(CommitWidth, Valid(new RobCommitInfo)) 37 val redirect = Valid(new Redirect) 38 val for_redirect_gen = new Bundle { 39 val rawRedirect = Valid(new Redirect) 40 val s1_redirect_onehot = Output(Vec(numRedirect+1, Bool())) 41 val s1_oldest_redirect = ValidIO(new Redirect) 42 val s1_oldest_exu_output = ValidIO(new ExuOutput) 43 val s1_jumpTarget = Output(UInt(VAddrBits.W)) 44 val flushRedirect = Valid(new Redirect) 45 val frontendFlushTarget = Output(UInt(VAddrBits.W)) 46 } 47} 48 49class RedirectGenerator(implicit p: Parameters) extends XSModule 50 with HasCircularQueuePtrHelper { 51 52 class RedirectGeneratorIO(implicit p: Parameters) extends XSBundle { 53 def numRedirect = exuParameters.JmpCnt + exuParameters.AluCnt 54 val hartId = Input(UInt(8.W)) 55 val exuMispredict = Vec(numRedirect, Flipped(ValidIO(new ExuOutput))) 56 val loadReplay = Flipped(ValidIO(new Redirect)) 57 val flush = Input(Bool()) 58 val stage1PcRead = Vec(numRedirect+1, new FtqRead(UInt(VAddrBits.W))) 59 val stage2Redirect = ValidIO(new Redirect) 60 val stage3Redirect = ValidIO(new Redirect) 61 val memPredUpdate = Output(new MemPredUpdateReq) 62 val memPredPcRead = new FtqRead(UInt(VAddrBits.W)) // read req send form stage 2 63 val for_frontend_redirect_gen = new Bundle { 64 val s1_jumpTarget = Output(UInt(VAddrBits.W)) 65 val s1_redirect_onehot = Output(Vec(numRedirect+1, Bool())) 66 val s1_oldest_redirect = ValidIO(new Redirect) 67 val s1_oldest_exu_output = ValidIO(new ExuOutput) 68 val s1_real_pc = Input(UInt(VAddrBits.W)) 69 } 70 } 71 val io = IO(new RedirectGeneratorIO) 72 /* 73 LoadQueue Jump ALU0 ALU1 ALU2 ALU3 exception Stage1 74 | | | | | | | 75 |============= reg & compare =====| | ======== 76 | | 77 | | 78 | | Stage2 79 | | 80 redirect (flush backend) | 81 | | 82 === reg === | ======== 83 | | 84 |----- mux (exception first) -----| Stage3 85 | 86 redirect (send to frontend) 87 */ 88 private class Wrapper(val n: Int) extends Bundle { 89 val redirect = new Redirect 90 val valid = Bool() 91 val idx = UInt(log2Up(n).W) 92 } 93 def selectOldestRedirect(xs: Seq[Valid[Redirect]]): Vec[Bool] = { 94 val compareVec = (0 until xs.length).map(i => (0 until i).map(j => isAfter(xs(j).bits.robIdx, xs(i).bits.robIdx))) 95 val resultOnehot = VecInit((0 until xs.length).map(i => Cat((0 until xs.length).map(j => 96 (if (j < i) !xs(j).valid || compareVec(i)(j) 97 else if (j == i) xs(i).valid 98 else !xs(j).valid || !compareVec(j)(i)) 99 )).andR)) 100 resultOnehot 101 } 102 103 val redirects = io.exuMispredict.map(_.bits.redirect) :+ io.loadReplay.bits 104 val stage1FtqReadPcs = 105 (io.stage1PcRead zip redirects).map{ case (r, redirect) => 106 r(redirect.ftqIdx, redirect.ftqOffset) 107 } 108 109 def getRedirect(exuOut: Valid[ExuOutput]): ValidIO[Redirect] = { 110 val redirect = Wire(Valid(new Redirect)) 111 redirect.valid := exuOut.valid && exuOut.bits.redirect.cfiUpdate.isMisPred 112 redirect.bits := exuOut.bits.redirect 113 redirect 114 } 115 116 val jumpOut = io.exuMispredict.head 117 val allRedirect = VecInit(io.exuMispredict.map(x => getRedirect(x)) :+ io.loadReplay) 118 val oldestOneHot = selectOldestRedirect(allRedirect) 119 val needFlushVec = VecInit(allRedirect.map(_.bits.robIdx.needFlush(io.stage2Redirect) || io.flush)) 120 val oldestValid = VecInit(oldestOneHot.zip(needFlushVec).map{ case (v, f) => v && !f }).asUInt.orR 121 val oldestExuOutput = Mux1H(io.exuMispredict.indices.map(oldestOneHot), io.exuMispredict) 122 val oldestRedirect = Mux1H(oldestOneHot, allRedirect) 123 124 val s1_jumpTarget = RegEnable(jumpOut.bits.redirect.cfiUpdate.target, jumpOut.valid) 125 val s1_imm12_reg = RegNext(oldestExuOutput.bits.uop.ctrl.imm(11, 0)) 126 val s1_pd = RegNext(oldestExuOutput.bits.uop.cf.pd) 127 val s1_redirect_bits_reg = RegNext(oldestRedirect.bits) 128 val s1_redirect_valid_reg = RegNext(oldestValid) 129 val s1_redirect_onehot = RegNext(oldestOneHot) 130 io.for_frontend_redirect_gen.s1_jumpTarget := s1_jumpTarget 131 io.for_frontend_redirect_gen.s1_redirect_onehot := s1_redirect_onehot 132 io.for_frontend_redirect_gen.s1_oldest_redirect.valid := s1_redirect_valid_reg 133 io.for_frontend_redirect_gen.s1_oldest_redirect.bits := s1_redirect_bits_reg 134 io.for_frontend_redirect_gen.s1_oldest_exu_output := RegNext(oldestExuOutput) 135 136 // stage1 -> stage2 137 io.stage2Redirect.valid := s1_redirect_valid_reg && !io.flush 138 io.stage2Redirect.bits := s1_redirect_bits_reg 139 140 val s1_isReplay = s1_redirect_onehot.last 141 val s1_isJump = s1_redirect_onehot.head 142 val real_pc = Mux1H(s1_redirect_onehot, stage1FtqReadPcs) 143 val brTarget = real_pc + SignExt(ImmUnion.B.toImm32(s1_imm12_reg), XLEN) 144 val snpc = real_pc + Mux(s1_pd.isRVC, 2.U, 4.U) 145 val target = Mux(s1_isReplay, 146 real_pc, // replay from itself 147 Mux(s1_redirect_bits_reg.cfiUpdate.taken, 148 Mux(s1_isJump, s1_jumpTarget, brTarget), 149 snpc 150 ) 151 ) 152 153 val stage2CfiUpdate = io.stage2Redirect.bits.cfiUpdate 154 stage2CfiUpdate.pc := real_pc 155 stage2CfiUpdate.pd := s1_pd 156 // stage2CfiUpdate.predTaken := s1_redirect_bits_reg.cfiUpdate.predTaken 157 stage2CfiUpdate.target := target 158 // stage2CfiUpdate.taken := s1_redirect_bits_reg.cfiUpdate.taken 159 // stage2CfiUpdate.isMisPred := s1_redirect_bits_reg.cfiUpdate.isMisPred 160 161 val s2_target = RegEnable(target, enable = s1_redirect_valid_reg) 162 val s2_pc = RegEnable(real_pc, enable = s1_redirect_valid_reg) 163 val s2_redirect_bits_reg = RegEnable(s1_redirect_bits_reg, enable = s1_redirect_valid_reg) 164 val s2_redirect_valid_reg = RegNext(s1_redirect_valid_reg && !io.flush, init = false.B) 165 166 io.stage3Redirect.valid := s2_redirect_valid_reg 167 io.stage3Redirect.bits := s2_redirect_bits_reg 168 169 // get pc from ftq 170 // valid only if redirect is caused by load violation 171 // store_pc is used to update store set 172 val store_pc = io.memPredPcRead(s1_redirect_bits_reg.stFtqIdx, s1_redirect_bits_reg.stFtqOffset) 173 174 val s1_real_pc_from_frontend = io.for_frontend_redirect_gen.s1_real_pc 175 // update load violation predictor if load violation redirect triggered 176 io.memPredUpdate.valid := RegNext(s1_isReplay && s1_redirect_valid_reg, init = false.B) 177 // update wait table 178 io.memPredUpdate.waddr := RegNext(XORFold(s1_real_pc_from_frontend(VAddrBits-1, 1), MemPredPCWidth)) 179 io.memPredUpdate.wdata := true.B 180 // update store set 181 io.memPredUpdate.ldpc := RegNext(XORFold(s1_real_pc_from_frontend(VAddrBits-1, 1), MemPredPCWidth)) 182 // store pc is ready 1 cycle after s1_isReplay is judged 183 io.memPredUpdate.stpc := XORFold(store_pc(VAddrBits-1, 1), MemPredPCWidth) 184 185 XSError(io.memPredUpdate.valid && RegNext(s1_real_pc_from_frontend) =/= RegNext(real_pc), "s1_real_pc error") 186 187 // recover runahead checkpoint if redirect 188 if (!env.FPGAPlatform) { 189 val runahead_redirect = Module(new DifftestRunaheadRedirectEvent) 190 runahead_redirect.io.clock := clock 191 runahead_redirect.io.coreid := io.hartId 192 runahead_redirect.io.valid := io.stage3Redirect.valid 193 runahead_redirect.io.pc := s2_pc // for debug only 194 runahead_redirect.io.target_pc := s2_target // for debug only 195 runahead_redirect.io.checkpoint_id := io.stage3Redirect.bits.debug_runahead_checkpoint_id // make sure it is right 196 } 197} 198 199class CtrlBlock(implicit p: Parameters) extends LazyModule 200 with HasWritebackSink with HasWritebackSource { 201 val rob = LazyModule(new Rob) 202 203 override def addWritebackSink(source: Seq[HasWritebackSource], index: Option[Seq[Int]]): HasWritebackSink = { 204 rob.addWritebackSink(Seq(this), Some(Seq(writebackSinks.length))) 205 super.addWritebackSink(source, index) 206 } 207 208 lazy val module = new CtrlBlockImp(this) 209 210 override lazy val writebackSourceParams: Seq[WritebackSourceParams] = { 211 writebackSinksParams 212 } 213 override lazy val writebackSourceImp: HasWritebackSourceImp = module 214 215 override def generateWritebackIO( 216 thisMod: Option[HasWritebackSource] = None, 217 thisModImp: Option[HasWritebackSourceImp] = None 218 ): Unit = { 219 module.io.writeback.zip(writebackSinksImp(thisMod, thisModImp)).foreach(x => x._1 := x._2) 220 } 221} 222 223class CtrlBlockImp(outer: CtrlBlock)(implicit p: Parameters) extends LazyModuleImp(outer) 224 with HasXSParameter 225 with HasCircularQueuePtrHelper 226 with HasWritebackSourceImp 227 with HasPerfEvents 228{ 229 val writebackLengths = outer.writebackSinksParams.map(_.length) 230 231 val io = IO(new Bundle { 232 val hartId = Input(UInt(8.W)) 233 val cpu_halt = Output(Bool()) 234 val frontend = Flipped(new FrontendToCtrlIO) 235 val allocPregs = Vec(RenameWidth, Output(new ResetPregStateReq)) 236 val dispatch = Vec(3*dpParams.IntDqDeqWidth, DecoupledIO(new MicroOp)) 237 // from int block 238 val exuRedirect = Vec(exuParameters.AluCnt + exuParameters.JmpCnt, Flipped(ValidIO(new ExuOutput))) 239 val stIn = Vec(exuParameters.StuCnt, Flipped(ValidIO(new ExuInput))) 240 val memoryViolation = Flipped(ValidIO(new Redirect)) 241 val jumpPc = Output(UInt(VAddrBits.W)) 242 val jalr_target = Output(UInt(VAddrBits.W)) 243 val robio = new Bundle { 244 // to int block 245 val toCSR = new RobCSRIO 246 val exception = ValidIO(new ExceptionInfo) 247 // to mem block 248 val lsq = new RobLsqIO 249 } 250 val csrCtrl = Input(new CustomCSRCtrlIO) 251 val perfInfo = Output(new Bundle{ 252 val ctrlInfo = new Bundle { 253 val robFull = Input(Bool()) 254 val intdqFull = Input(Bool()) 255 val fpdqFull = Input(Bool()) 256 val lsdqFull = Input(Bool()) 257 } 258 }) 259 val writeback = MixedVec(writebackLengths.map(num => Vec(num, Flipped(ValidIO(new ExuOutput))))) 260 // redirect out 261 val redirect = ValidIO(new Redirect) 262 val debug_int_rat = Vec(32, Output(UInt(PhyRegIdxWidth.W))) 263 val debug_fp_rat = Vec(32, Output(UInt(PhyRegIdxWidth.W))) 264 }) 265 266 override def writebackSource: Option[Seq[Seq[Valid[ExuOutput]]]] = { 267 Some(io.writeback.map(writeback => { 268 val exuOutput = WireInit(writeback) 269 val timer = GTimer() 270 for ((wb_next, wb) <- exuOutput.zip(writeback)) { 271 wb_next.valid := RegNext(wb.valid && !wb.bits.uop.robIdx.needFlush(stage2Redirect)) 272 wb_next.bits := RegNext(wb.bits) 273 wb_next.bits.uop.debugInfo.writebackTime := timer 274 } 275 exuOutput 276 })) 277 } 278 279 val decode = Module(new DecodeStage) 280 val rat = Module(new RenameTableWrapper) 281 val ssit = Module(new SSIT) 282 val waittable = Module(new WaitTable) 283 val rename = Module(new Rename) 284 val dispatch = Module(new Dispatch) 285 val intDq = Module(new DispatchQueue(dpParams.IntDqSize, RenameWidth, dpParams.IntDqDeqWidth)) 286 val fpDq = Module(new DispatchQueue(dpParams.FpDqSize, RenameWidth, dpParams.FpDqDeqWidth)) 287 val lsDq = Module(new DispatchQueue(dpParams.LsDqSize, RenameWidth, dpParams.LsDqDeqWidth)) 288 val redirectGen = Module(new RedirectGenerator) 289 290 val rob = outer.rob.module 291 292 val robPcRead = io.frontend.fromFtq.getRobFlushPcRead 293 val flushPC = robPcRead(rob.io.flushOut.bits.ftqIdx, rob.io.flushOut.bits.ftqOffset) 294 295 val flushRedirect = Wire(Valid(new Redirect)) 296 flushRedirect.valid := RegNext(rob.io.flushOut.valid) 297 flushRedirect.bits := RegEnable(rob.io.flushOut.bits, rob.io.flushOut.valid) 298 299 val flushRedirectReg = Wire(Valid(new Redirect)) 300 flushRedirectReg.valid := RegNext(flushRedirect.valid, init = false.B) 301 flushRedirectReg.bits := RegEnable(flushRedirect.bits, enable = flushRedirect.valid) 302 303 val stage2Redirect = Mux(flushRedirect.valid, flushRedirect, redirectGen.io.stage2Redirect) 304 // val stage3Redirect = Mux(flushRedirectReg.valid, flushRedirectReg, redirectGen.io.stage3Redirect) 305 306 val exuRedirect = io.exuRedirect.map(x => { 307 val valid = x.valid && x.bits.redirectValid 308 val killedByOlder = x.bits.uop.robIdx.needFlush(stage2Redirect) 309 val delayed = Wire(Valid(new ExuOutput)) 310 delayed.valid := RegNext(valid && !killedByOlder, init = false.B) 311 delayed.bits := RegEnable(x.bits, x.valid) 312 delayed 313 }) 314 val loadReplay = Wire(Valid(new Redirect)) 315 loadReplay.valid := RegNext(io.memoryViolation.valid && 316 !io.memoryViolation.bits.robIdx.needFlush(stage2Redirect), 317 init = false.B 318 ) 319 loadReplay.bits := RegEnable(io.memoryViolation.bits, io.memoryViolation.valid) 320 io.frontend.fromFtq.getRedirectPcRead <> redirectGen.io.stage1PcRead 321 io.frontend.fromFtq.getMemPredPcRead <> redirectGen.io.memPredPcRead 322 redirectGen.io.hartId := io.hartId 323 redirectGen.io.exuMispredict <> exuRedirect 324 redirectGen.io.loadReplay <> loadReplay 325 redirectGen.io.flush := flushRedirect.valid 326 327 val frontendFlushValid = DelayN(flushRedirect.valid, 5) 328 val frontendFlushBits = RegEnable(flushRedirect.bits, flushRedirect.valid) 329 // When ROB commits an instruction with a flush, we notify the frontend of the flush without the commit. 330 // Flushes to frontend may be delayed by some cycles and commit before flush causes errors. 331 // Thus, we make all flush reasons to behave the same as exceptions for frontend. 332 for (i <- 0 until CommitWidth) { 333 val is_commit = rob.io.commits.valid(i) && !rob.io.commits.isWalk && !rob.io.flushOut.valid 334 io.frontend.toFtq.rob_commits(i).valid := RegNext(is_commit) 335 io.frontend.toFtq.rob_commits(i).bits := RegEnable(rob.io.commits.info(i), is_commit) 336 } 337 io.frontend.toFtq.redirect.valid := frontendFlushValid || redirectGen.io.stage2Redirect.valid 338 io.frontend.toFtq.redirect.bits := Mux(frontendFlushValid, frontendFlushBits, redirectGen.io.stage2Redirect.bits) 339 // Be careful here: 340 // T0: flushRedirect.valid, exception.valid 341 // T1: csr.redirect.valid 342 // T2: csr.exception.valid 343 // T3: csr.trapTarget 344 // T4: ctrlBlock.trapTarget 345 // T5: io.frontend.toFtq.stage2Redirect.valid 346 val pc_from_csr = io.robio.toCSR.isXRet || DelayN(rob.io.exception.valid, 4) 347 val rob_flush_pc = RegEnable(Mux(flushRedirect.bits.flushItself(), 348 flushPC, // replay inst 349 flushPC + 4.U // flush pipe 350 ), flushRedirect.valid) 351 val flushTarget = Mux(pc_from_csr, io.robio.toCSR.trapTarget, rob_flush_pc) 352 when (frontendFlushValid) { 353 io.frontend.toFtq.redirect.bits.level := RedirectLevel.flush 354 io.frontend.toFtq.redirect.bits.cfiUpdate.target := RegNext(flushTarget) 355 } 356 redirectGen.io.for_frontend_redirect_gen.s1_real_pc := io.frontend.fromFtq.redirect_s1_real_pc 357 io.frontend.toFtq.for_redirect_gen.s1_oldest_redirect := redirectGen.io.for_frontend_redirect_gen.s1_oldest_redirect 358 io.frontend.toFtq.for_redirect_gen.s1_oldest_exu_output := redirectGen.io.for_frontend_redirect_gen.s1_oldest_exu_output 359 io.frontend.toFtq.for_redirect_gen.s1_redirect_onehot := redirectGen.io.for_frontend_redirect_gen.s1_redirect_onehot 360 io.frontend.toFtq.for_redirect_gen.s1_jumpTarget := redirectGen.io.for_frontend_redirect_gen.s1_jumpTarget 361 io.frontend.toFtq.for_redirect_gen.rawRedirect := redirectGen.io.stage2Redirect 362 io.frontend.toFtq.for_redirect_gen.flushRedirect.valid := frontendFlushValid 363 io.frontend.toFtq.for_redirect_gen.flushRedirect.bits := frontendFlushBits 364 365 io.frontend.toFtq.for_redirect_gen.frontendFlushTarget := RegNext(flushTarget) 366 367 368 val pendingRedirect = RegInit(false.B) 369 when (stage2Redirect.valid) { 370 pendingRedirect := true.B 371 }.elsewhen (RegNext(io.frontend.toFtq.redirect.valid)) { 372 pendingRedirect := false.B 373 } 374 375 decode.io.in <> io.frontend.cfVec 376 decode.io.csrCtrl := RegNext(io.csrCtrl) 377 378 // memory dependency predict 379 // when decode, send fold pc to mdp 380 for (i <- 0 until DecodeWidth) { 381 val mdp_foldpc = Mux( 382 decode.io.out(i).fire(), 383 decode.io.in(i).bits.foldpc, 384 rename.io.in(i).bits.cf.foldpc 385 ) 386 ssit.io.raddr(i) := mdp_foldpc 387 waittable.io.raddr(i) := mdp_foldpc 388 } 389 // currently, we only update mdp info when isReplay 390 ssit.io.update <> RegNext(redirectGen.io.memPredUpdate) 391 ssit.io.csrCtrl := RegNext(io.csrCtrl) 392 waittable.io.update <> RegNext(redirectGen.io.memPredUpdate) 393 waittable.io.csrCtrl := RegNext(io.csrCtrl) 394 395 // LFST lookup and update 396 val lfst = Module(new LFST) 397 lfst.io.redirect <> RegNext(io.redirect) 398 lfst.io.storeIssue <> RegNext(io.stIn) 399 lfst.io.csrCtrl <> RegNext(io.csrCtrl) 400 lfst.io.dispatch <> dispatch.io.lfst 401 402 rat.io.robCommits := rob.io.commits 403 for ((r, i) <- rat.io.intReadPorts.zipWithIndex) { 404 val raddr = decode.io.out(i).bits.ctrl.lsrc.take(2) :+ decode.io.out(i).bits.ctrl.ldest 405 r.map(_.addr).zip(raddr).foreach(x => x._1 := x._2) 406 rename.io.intReadPorts(i) := r.map(_.data) 407 r.foreach(_.hold := !rename.io.in(i).ready) 408 } 409 rat.io.intRenamePorts := rename.io.intRenamePorts 410 for ((r, i) <- rat.io.fpReadPorts.zipWithIndex) { 411 val raddr = decode.io.out(i).bits.ctrl.lsrc.take(3) :+ decode.io.out(i).bits.ctrl.ldest 412 r.map(_.addr).zip(raddr).foreach(x => x._1 := x._2) 413 rename.io.fpReadPorts(i) := r.map(_.data) 414 r.foreach(_.hold := !rename.io.in(i).ready) 415 } 416 rat.io.fpRenamePorts := rename.io.fpRenamePorts 417 rat.io.debug_int_rat <> io.debug_int_rat 418 rat.io.debug_fp_rat <> io.debug_fp_rat 419 420 // pipeline between decode and rename 421 for (i <- 0 until RenameWidth) { 422 PipelineConnect(decode.io.out(i), rename.io.in(i), rename.io.in(i).ready, 423 stage2Redirect.valid || pendingRedirect) 424 } 425 426 rename.io.redirect <> stage2Redirect 427 rename.io.robCommits <> rob.io.commits 428 rename.io.ssit <> ssit.io.rdata 429 rename.io.waittable <> RegNext(waittable.io.rdata) 430 431 // pipeline between rename and dispatch 432 for (i <- 0 until RenameWidth) { 433 PipelineConnect(rename.io.out(i), dispatch.io.fromRename(i), dispatch.io.recv(i), stage2Redirect.valid) 434 } 435 436 dispatch.io.hartId := io.hartId 437 dispatch.io.redirect <> stage2Redirect 438 dispatch.io.enqRob <> rob.io.enq 439 dispatch.io.toIntDq <> intDq.io.enq 440 dispatch.io.toFpDq <> fpDq.io.enq 441 dispatch.io.toLsDq <> lsDq.io.enq 442 dispatch.io.allocPregs <> io.allocPregs 443 dispatch.io.singleStep := RegNext(io.csrCtrl.singlestep) 444 445 intDq.io.redirect <> stage2Redirect 446 fpDq.io.redirect <> stage2Redirect 447 lsDq.io.redirect <> stage2Redirect 448 449 io.dispatch <> intDq.io.deq ++ lsDq.io.deq ++ fpDq.io.deq 450 451 val pingpong = RegInit(false.B) 452 pingpong := !pingpong 453 val jumpInst = Mux(pingpong && (exuParameters.AluCnt > 2).B, io.dispatch(2).bits, io.dispatch(0).bits) 454 val jumpPcRead = io.frontend.fromFtq.getJumpPcRead 455 io.jumpPc := jumpPcRead(jumpInst.cf.ftqPtr, jumpInst.cf.ftqOffset) 456 val jumpTargetRead = io.frontend.fromFtq.target_read 457 io.jalr_target := jumpTargetRead(jumpInst.cf.ftqPtr, jumpInst.cf.ftqOffset) 458 459 rob.io.hartId := io.hartId 460 io.cpu_halt := DelayN(rob.io.cpu_halt, 5) 461 rob.io.redirect <> stage2Redirect 462 outer.rob.generateWritebackIO(Some(outer), Some(this)) 463 464 io.redirect <> stage2Redirect 465 466 // rob to int block 467 io.robio.toCSR <> rob.io.csr 468 io.robio.toCSR.perfinfo.retiredInstr <> RegNext(rob.io.csr.perfinfo.retiredInstr) 469 io.robio.exception := rob.io.exception 470 io.robio.exception.bits.uop.cf.pc := flushPC 471 472 // rob to mem block 473 io.robio.lsq <> rob.io.lsq 474 475 io.perfInfo.ctrlInfo.robFull := RegNext(rob.io.robFull) 476 io.perfInfo.ctrlInfo.intdqFull := RegNext(intDq.io.dqFull) 477 io.perfInfo.ctrlInfo.fpdqFull := RegNext(fpDq.io.dqFull) 478 io.perfInfo.ctrlInfo.lsdqFull := RegNext(lsDq.io.dqFull) 479 480 val pfevent = Module(new PFEvent) 481 pfevent.io.distribute_csr := RegNext(io.csrCtrl.distribute_csr) 482 val csrevents = pfevent.io.hpmevent.slice(8,16) 483 484 val perfinfo = IO(new Bundle(){ 485 val perfEventsRs = Input(Vec(NumRs, new PerfEvent)) 486 val perfEventsEu0 = Input(Vec(6, new PerfEvent)) 487 val perfEventsEu1 = Input(Vec(6, new PerfEvent)) 488 }) 489 490 val allPerfEvents = Seq(decode, rename, dispatch, intDq, fpDq, lsDq, rob).flatMap(_.getPerf) 491 val hpmEvents = allPerfEvents ++ perfinfo.perfEventsEu0 ++ perfinfo.perfEventsEu1 ++ perfinfo.perfEventsRs 492 val perfEvents = HPerfMonitor(csrevents, hpmEvents).getPerfEvents 493 generatePerfEvent() 494} 495