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.rob 18 19import chipsalliance.rocketchip.config.Parameters 20import chisel3._ 21import chisel3.util._ 22import difftest._ 23import freechips.rocketchip.diplomacy.{LazyModule, LazyModuleImp} 24import utils._ 25import utility._ 26import xiangshan._ 27import xiangshan.backend.exu.ExuConfig 28import xiangshan.frontend.FtqPtr 29 30class RobPtr(implicit p: Parameters) extends CircularQueuePtr[RobPtr]( 31 p => p(XSCoreParamsKey).RobSize 32) with HasCircularQueuePtrHelper { 33 34 def needFlush(redirect: Valid[Redirect]): Bool = { 35 val flushItself = redirect.bits.flushItself() && this === redirect.bits.robIdx 36 redirect.valid && (flushItself || isAfter(this, redirect.bits.robIdx)) 37 } 38 39 def needFlush(redirect: Seq[Valid[Redirect]]): Bool = VecInit(redirect.map(needFlush)).asUInt.orR 40} 41 42object RobPtr { 43 def apply(f: Bool, v: UInt)(implicit p: Parameters): RobPtr = { 44 val ptr = Wire(new RobPtr) 45 ptr.flag := f 46 ptr.value := v 47 ptr 48 } 49} 50 51class RobCSRIO(implicit p: Parameters) extends XSBundle { 52 val intrBitSet = Input(Bool()) 53 val trapTarget = Input(UInt(VAddrBits.W)) 54 val isXRet = Input(Bool()) 55 val wfiEvent = Input(Bool()) 56 57 val fflags = Output(Valid(UInt(5.W))) 58 val dirty_fs = Output(Bool()) 59 val perfinfo = new Bundle { 60 val retiredInstr = Output(UInt(3.W)) 61 } 62 63 val vcsrFlag = Output(Bool()) 64} 65 66class RobLsqIO(implicit p: Parameters) extends XSBundle { 67 val lcommit = Output(UInt(log2Up(CommitWidth + 1).W)) 68 val scommit = Output(UInt(log2Up(CommitWidth + 1).W)) 69 val pendingld = Output(Bool()) 70 val pendingst = Output(Bool()) 71 val commit = Output(Bool()) 72} 73 74class RobEnqIO(implicit p: Parameters) extends XSBundle { 75 val canAccept = Output(Bool()) 76 val isEmpty = Output(Bool()) 77 // valid vector, for robIdx gen and walk 78 val needAlloc = Vec(RenameWidth, Input(Bool())) 79 val req = Vec(RenameWidth, Flipped(ValidIO(new MicroOp))) 80 val resp = Vec(RenameWidth, Output(new RobPtr)) 81} 82 83class RobDispatchData(implicit p: Parameters) extends RobCommitInfo 84 85class RobDeqPtrWrapper(implicit p: Parameters) extends XSModule with HasCircularQueuePtrHelper { 86 val io = IO(new Bundle { 87 // for commits/flush 88 val state = Input(UInt(2.W)) 89 val deq_v = Vec(CommitWidth, Input(Bool())) 90 val deq_w = Vec(CommitWidth, Input(Bool())) 91 val exception_state = Flipped(ValidIO(new RobExceptionInfo)) 92 // for flush: when exception occurs, reset deqPtrs to range(0, CommitWidth) 93 val intrBitSetReg = Input(Bool()) 94 val hasNoSpecExec = Input(Bool()) 95 val interrupt_safe = Input(Bool()) 96 val blockCommit = Input(Bool()) 97 // output: the CommitWidth deqPtr 98 val out = Vec(CommitWidth, Output(new RobPtr)) 99 val next_out = Vec(CommitWidth, Output(new RobPtr)) 100 }) 101 102 val deqPtrVec = RegInit(VecInit((0 until CommitWidth).map(_.U.asTypeOf(new RobPtr)))) 103 104 // for exceptions (flushPipe included) and interrupts: 105 // only consider the first instruction 106 val intrEnable = io.intrBitSetReg && !io.hasNoSpecExec && io.interrupt_safe 107 val exceptionEnable = io.deq_w(0) && io.exception_state.valid && io.exception_state.bits.not_commit && io.exception_state.bits.robIdx === deqPtrVec(0) 108 val redirectOutValid = io.state === 0.U && io.deq_v(0) && (intrEnable || exceptionEnable) 109 110 // for normal commits: only to consider when there're no exceptions 111 // we don't need to consider whether the first instruction has exceptions since it wil trigger exceptions. 112 val commit_exception = io.exception_state.valid && !isAfter(io.exception_state.bits.robIdx, deqPtrVec.last) 113 val canCommit = VecInit((0 until CommitWidth).map(i => io.deq_v(i) && io.deq_w(i))) 114 val normalCommitCnt = PriorityEncoder(canCommit.map(c => !c) :+ true.B) 115 // when io.intrBitSetReg or there're possible exceptions in these instructions, 116 // only one instruction is allowed to commit 117 val allowOnlyOne = commit_exception || io.intrBitSetReg 118 val commitCnt = Mux(allowOnlyOne, canCommit(0), normalCommitCnt) 119 120 val commitDeqPtrVec = VecInit(deqPtrVec.map(_ + commitCnt)) 121 val deqPtrVec_next = Mux(io.state === 0.U && !redirectOutValid && !io.blockCommit, commitDeqPtrVec, deqPtrVec) 122 123 deqPtrVec := deqPtrVec_next 124 125 io.next_out := deqPtrVec_next 126 io.out := deqPtrVec 127 128 when (io.state === 0.U) { 129 XSInfo(io.state === 0.U && commitCnt > 0.U, "retired %d insts\n", commitCnt) 130 } 131 132} 133 134class RobEnqPtrWrapper(implicit p: Parameters) extends XSModule with HasCircularQueuePtrHelper { 135 val io = IO(new Bundle { 136 // for input redirect 137 val redirect = Input(Valid(new Redirect)) 138 // for enqueue 139 val allowEnqueue = Input(Bool()) 140 val hasBlockBackward = Input(Bool()) 141 val enq = Vec(RenameWidth, Input(Bool())) 142 val out = Output(Vec(RenameWidth, new RobPtr)) 143 }) 144 145 val enqPtrVec = RegInit(VecInit.tabulate(RenameWidth)(_.U.asTypeOf(new RobPtr))) 146 147 // enqueue 148 val canAccept = io.allowEnqueue && !io.hasBlockBackward 149 val dispatchNum = Mux(canAccept, PopCount(io.enq), 0.U) 150 151 for ((ptr, i) <- enqPtrVec.zipWithIndex) { 152 when(io.redirect.valid) { 153 ptr := Mux(io.redirect.bits.flushItself(), io.redirect.bits.robIdx + i.U, io.redirect.bits.robIdx + (i + 1).U) 154 }.otherwise { 155 ptr := ptr + dispatchNum 156 } 157 } 158 159 io.out := enqPtrVec 160 161} 162 163class RobExceptionInfo(implicit p: Parameters) extends XSBundle { 164 // val valid = Bool() 165 val robIdx = new RobPtr 166 val exceptionVec = ExceptionVec() 167 val flushPipe = Bool() 168 val isVset = Bool() 169 val replayInst = Bool() // redirect to that inst itself 170 val singleStep = Bool() // TODO add frontend hit beneath 171 val crossPageIPFFix = Bool() 172 val trigger = new TriggerCf 173 174// def trigger_before = !trigger.getTimingBackend && trigger.getHitBackend 175// def trigger_after = trigger.getTimingBackend && trigger.getHitBackend 176 def has_exception = exceptionVec.asUInt.orR || flushPipe || singleStep || replayInst || trigger.hit 177 def not_commit = exceptionVec.asUInt.orR || singleStep || replayInst || trigger.hit 178 // only exceptions are allowed to writeback when enqueue 179 def can_writeback = exceptionVec.asUInt.orR || singleStep || trigger.hit 180} 181 182class ExceptionGen(implicit p: Parameters) extends XSModule with HasCircularQueuePtrHelper { 183 val io = IO(new Bundle { 184 val redirect = Input(Valid(new Redirect)) 185 val flush = Input(Bool()) 186 val enq = Vec(RenameWidth, Flipped(ValidIO(new RobExceptionInfo))) 187 val wb = Vec(1 + LoadPipelineWidth + StorePipelineWidth, Flipped(ValidIO(new RobExceptionInfo))) 188 val out = ValidIO(new RobExceptionInfo) 189 val state = ValidIO(new RobExceptionInfo) 190 }) 191 192 def getOldest(valid: Seq[Bool], bits: Seq[RobExceptionInfo]): (Seq[Bool], Seq[RobExceptionInfo]) = { 193 assert(valid.length == bits.length) 194 assert(isPow2(valid.length)) 195 if (valid.length == 1) { 196 (valid, bits) 197 } else if (valid.length == 2) { 198 val res = Seq.fill(2)(Wire(ValidIO(chiselTypeOf(bits(0))))) 199 for (i <- res.indices) { 200 res(i).valid := valid(i) 201 res(i).bits := bits(i) 202 } 203 val oldest = Mux(!valid(1) || valid(0) && isAfter(bits(1).robIdx, bits(0).robIdx), res(0), res(1)) 204 (Seq(oldest.valid), Seq(oldest.bits)) 205 } else { 206 val left = getOldest(valid.take(valid.length / 2), bits.take(valid.length / 2)) 207 val right = getOldest(valid.takeRight(valid.length / 2), bits.takeRight(valid.length / 2)) 208 getOldest(left._1 ++ right._1, left._2 ++ right._2) 209 } 210 } 211 212 val currentValid = RegInit(false.B) 213 val current = Reg(new RobExceptionInfo) 214 215 // orR the exceptionVec 216 val lastCycleFlush = RegNext(io.flush) 217 val in_enq_valid = VecInit(io.enq.map(e => e.valid && e.bits.has_exception && !lastCycleFlush)) 218 val in_wb_valid = io.wb.map(w => w.valid && w.bits.has_exception && !lastCycleFlush) 219 220 // s0: compare wb(1)~wb(LoadPipelineWidth) and wb(1 + LoadPipelineWidth)~wb(LoadPipelineWidth + StorePipelineWidth) 221 val wb_valid = in_wb_valid.zip(io.wb.map(_.bits)).map{ case (v, bits) => v && !(bits.robIdx.needFlush(io.redirect) || io.flush) } 222 val csr_wb_bits = io.wb(0).bits 223 val load_wb_bits = getOldest(in_wb_valid.slice(1, 1 + LoadPipelineWidth), io.wb.map(_.bits).slice(1, 1 + LoadPipelineWidth))._2(0) 224 val store_wb_bits = getOldest(in_wb_valid.slice(1 + LoadPipelineWidth, 1 + LoadPipelineWidth + StorePipelineWidth), io.wb.map(_.bits).slice(1 + LoadPipelineWidth, 1 + LoadPipelineWidth + StorePipelineWidth))._2(0) 225 val s0_out_valid = RegNext(VecInit(Seq(wb_valid(0), wb_valid.slice(1, 1 + LoadPipelineWidth).reduce(_ || _), wb_valid.slice(1 + LoadPipelineWidth, 1 + LoadPipelineWidth + StorePipelineWidth).reduce(_ || _)))) 226 val s0_out_bits = RegNext(VecInit(Seq(csr_wb_bits, load_wb_bits, store_wb_bits))) 227 228 // s1: compare last four and current flush 229 val s1_valid = VecInit(s0_out_valid.zip(s0_out_bits).map{ case (v, b) => v && !(b.robIdx.needFlush(io.redirect) || io.flush) }) 230 val compare_01_valid = s0_out_valid(0) || s0_out_valid(1) 231 val compare_01_bits = Mux(!s0_out_valid(0) || s0_out_valid(1) && isAfter(s0_out_bits(0).robIdx, s0_out_bits(1).robIdx), s0_out_bits(1), s0_out_bits(0)) 232 val compare_bits = Mux(!s0_out_valid(2) || compare_01_valid && isAfter(s0_out_bits(2).robIdx, compare_01_bits.robIdx), compare_01_bits, s0_out_bits(2)) 233 val s1_out_bits = RegNext(compare_bits) 234 val s1_out_valid = RegNext(s1_valid.asUInt.orR) 235 236 val enq_valid = RegNext(in_enq_valid.asUInt.orR && !io.redirect.valid && !io.flush) 237 val enq_bits = RegNext(ParallelPriorityMux(in_enq_valid, io.enq.map(_.bits))) 238 239 // s2: compare the input exception with the current one 240 // priorities: 241 // (1) system reset 242 // (2) current is valid: flush, remain, merge, update 243 // (3) current is not valid: s1 or enq 244 val current_flush = current.robIdx.needFlush(io.redirect) || io.flush 245 val s1_flush = s1_out_bits.robIdx.needFlush(io.redirect) || io.flush 246 when (currentValid) { 247 when (current_flush) { 248 currentValid := Mux(s1_flush, false.B, s1_out_valid) 249 } 250 when (s1_out_valid && !s1_flush) { 251 when (isAfter(current.robIdx, s1_out_bits.robIdx)) { 252 current := s1_out_bits 253 }.elsewhen (current.robIdx === s1_out_bits.robIdx) { 254 current.exceptionVec := (s1_out_bits.exceptionVec.asUInt | current.exceptionVec.asUInt).asTypeOf(ExceptionVec()) 255 current.flushPipe := s1_out_bits.flushPipe || current.flushPipe 256 current.replayInst := s1_out_bits.replayInst || current.replayInst 257 current.singleStep := s1_out_bits.singleStep || current.singleStep 258 current.trigger := (s1_out_bits.trigger.asUInt | current.trigger.asUInt).asTypeOf(new TriggerCf) 259 } 260 } 261 }.elsewhen (s1_out_valid && !s1_flush) { 262 currentValid := true.B 263 current := s1_out_bits 264 }.elsewhen (enq_valid && !(io.redirect.valid || io.flush)) { 265 currentValid := true.B 266 current := enq_bits 267 } 268 269 io.out.valid := s1_out_valid || enq_valid && enq_bits.can_writeback 270 io.out.bits := Mux(s1_out_valid, s1_out_bits, enq_bits) 271 io.state.valid := currentValid 272 io.state.bits := current 273 274} 275 276class RobFlushInfo(implicit p: Parameters) extends XSBundle { 277 val ftqIdx = new FtqPtr 278 val robIdx = new RobPtr 279 val ftqOffset = UInt(log2Up(PredictWidth).W) 280 val replayInst = Bool() 281} 282 283class Rob(implicit p: Parameters) extends LazyModule with HasWritebackSink with HasXSParameter { 284 285 lazy val module = new RobImp(this) 286 287 override def generateWritebackIO( 288 thisMod: Option[HasWritebackSource] = None, 289 thisModImp: Option[HasWritebackSourceImp] = None 290 ): Unit = { 291 val sources = writebackSinksImp(thisMod, thisModImp) 292 module.io.writeback.zip(sources).foreach(x => x._1 := x._2) 293 } 294} 295 296class RobImp(outer: Rob)(implicit p: Parameters) extends LazyModuleImp(outer) 297 with HasXSParameter with HasCircularQueuePtrHelper with HasPerfEvents { 298 val wbExuConfigs = outer.writebackSinksParams.map(_.exuConfigs) 299 val numWbPorts = wbExuConfigs.map(_.length) 300 301 val io = IO(new Bundle() { 302 val hartId = Input(UInt(8.W)) 303 val redirect = Input(Valid(new Redirect)) 304 val enq = new RobEnqIO 305 val flushOut = ValidIO(new Redirect) 306 val isVsetFlushPipe = Output(Bool()) 307 val exception = ValidIO(new ExceptionInfo) 308 // exu + brq 309 val writeback = MixedVec(numWbPorts.map(num => Vec(num, Flipped(ValidIO(new ExuOutput))))) 310 val commits = Output(new RobCommitIO) 311 val lsq = new RobLsqIO 312 val robDeqPtr = Output(new RobPtr) 313 val csr = new RobCSRIO 314 val robFull = Output(Bool()) 315 val cpu_halt = Output(Bool()) 316 val wfi_enable = Input(Bool()) 317 }) 318 319 def selectWb(index: Int, func: Seq[ExuConfig] => Boolean): Seq[(Seq[ExuConfig], ValidIO[ExuOutput])] = { 320 wbExuConfigs(index).zip(io.writeback(index)).filter(x => func(x._1)) 321 } 322 val exeWbSel = outer.selWritebackSinks(_.exuConfigs.length) 323 val fflagsWbSel = outer.selWritebackSinks(_.exuConfigs.count(_.exists(_.writeFflags))) 324 val fflagsPorts = selectWb(fflagsWbSel, _.exists(_.writeFflags)) 325 val exceptionWbSel = outer.selWritebackSinks(_.exuConfigs.count(_.exists(_.needExceptionGen))) 326 val exceptionPorts = selectWb(fflagsWbSel, _.exists(_.needExceptionGen)) 327 val exuWbPorts = selectWb(exeWbSel, _.forall(_ != StdExeUnitCfg)) 328 val stdWbPorts = selectWb(exeWbSel, _.contains(StdExeUnitCfg)) 329 println(s"Rob: size $RobSize, numWbPorts: $numWbPorts, commitwidth: $CommitWidth") 330 println(s"exuPorts: ${exuWbPorts.map(_._1.map(_.name))}") 331 println(s"stdPorts: ${stdWbPorts.map(_._1.map(_.name))}") 332 println(s"fflags: ${fflagsPorts.map(_._1.map(_.name))}") 333 334 335 val exuWriteback = exuWbPorts.map(_._2) 336 val stdWriteback = stdWbPorts.map(_._2) 337 338 // instvalid field 339 val valid = RegInit(VecInit(Seq.fill(RobSize)(false.B))) 340 // writeback status 341 val writebacked = Mem(RobSize, Bool()) 342 val store_data_writebacked = Mem(RobSize, Bool()) 343 // data for redirect, exception, etc. 344 val flagBkup = Mem(RobSize, Bool()) 345 // some instructions are not allowed to trigger interrupts 346 // They have side effects on the states of the processor before they write back 347 val interrupt_safe = Mem(RobSize, Bool()) 348 349 // data for debug 350 // Warn: debug_* prefix should not exist in generated verilog. 351 val debug_microOp = Mem(RobSize, new MicroOp) 352 val debug_exuData = Reg(Vec(RobSize, UInt(XLEN.W)))//for debug 353 val debug_exuDebug = Reg(Vec(RobSize, new DebugBundle))//for debug 354 355 // pointers 356 // For enqueue ptr, we don't duplicate it since only enqueue needs it. 357 val enqPtrVec = Wire(Vec(RenameWidth, new RobPtr)) 358 val deqPtrVec = Wire(Vec(CommitWidth, new RobPtr)) 359 360 val walkPtrVec = Reg(Vec(CommitWidth, new RobPtr)) 361 val allowEnqueue = RegInit(true.B) 362 363 val enqPtr = enqPtrVec.head 364 val deqPtr = deqPtrVec(0) 365 val walkPtr = walkPtrVec(0) 366 367 val isEmpty = enqPtr === deqPtr 368 val isReplaying = io.redirect.valid && RedirectLevel.flushItself(io.redirect.bits.level) 369 370 /** 371 * states of Rob 372 */ 373 val s_idle :: s_walk :: Nil = Enum(2) 374 val state = RegInit(s_idle) 375 376 /** 377 * Data Modules 378 * 379 * CommitDataModule: data from dispatch 380 * (1) read: commits/walk/exception 381 * (2) write: enqueue 382 * 383 * WritebackData: data from writeback 384 * (1) read: commits/walk/exception 385 * (2) write: write back from exe units 386 */ 387 val dispatchData = Module(new SyncDataModuleTemplate(new RobDispatchData, RobSize, CommitWidth, RenameWidth)) 388// val dispatchData = Module(new SyncDataModuleTemplate(new RobDispatchData, RobSize, CommitWidth, RenameWidth)) 389 val dispatchDataRead = dispatchData.io.rdata 390 391 val exceptionGen = Module(new ExceptionGen) 392 val exceptionDataRead = exceptionGen.io.state 393 val fflagsDataRead = Wire(Vec(CommitWidth, UInt(5.W))) 394 395 io.robDeqPtr := deqPtr 396 397 /** 398 * Enqueue (from dispatch) 399 */ 400 // special cases 401 val hasBlockBackward = RegInit(false.B) 402 val hasNoSpecExec = RegInit(false.B) 403 val doingSvinval = RegInit(false.B) 404 // When blockBackward instruction leaves Rob (commit or walk), hasBlockBackward should be set to false.B 405 // To reduce registers usage, for hasBlockBackward cases, we allow enqueue after ROB is empty. 406 when (isEmpty) { hasBlockBackward:= false.B } 407 // When any instruction commits, hasNoSpecExec should be set to false.B 408 when (io.commits.hasWalkInstr || io.commits.hasCommitInstr) { hasNoSpecExec:= false.B } 409 410 // The wait-for-interrupt (WFI) instruction waits in the ROB until an interrupt might need servicing. 411 // io.csr.wfiEvent will be asserted if the WFI can resume execution, and we change the state to s_wfi_idle. 412 // It does not affect how interrupts are serviced. Note that WFI is noSpecExec and it does not trigger interrupts. 413 val hasWFI = RegInit(false.B) 414 io.cpu_halt := hasWFI 415 // WFI Timeout: 2^20 = 1M cycles 416 val wfi_cycles = RegInit(0.U(20.W)) 417 when (hasWFI) { 418 wfi_cycles := wfi_cycles + 1.U 419 }.elsewhen (!hasWFI && RegNext(hasWFI)) { 420 wfi_cycles := 0.U 421 } 422 val wfi_timeout = wfi_cycles.andR 423 when (RegNext(RegNext(io.csr.wfiEvent)) || io.flushOut.valid || wfi_timeout) { 424 hasWFI := false.B 425 } 426 427 val allocatePtrVec = VecInit((0 until RenameWidth).map(i => enqPtrVec(PopCount(io.enq.needAlloc.take(i))))) 428 io.enq.canAccept := allowEnqueue && !hasBlockBackward 429 io.enq.resp := allocatePtrVec 430 val canEnqueue = VecInit(io.enq.req.map(_.valid && io.enq.canAccept)) 431 val timer = GTimer() 432 for (i <- 0 until RenameWidth) { 433 // we don't check whether io.redirect is valid here since redirect has higher priority 434 when (canEnqueue(i)) { 435 val enqUop = io.enq.req(i).bits 436 val enqIndex = allocatePtrVec(i).value 437 // store uop in data module and debug_microOp Vec 438 debug_microOp(enqIndex) := enqUop 439 debug_microOp(enqIndex).debugInfo.dispatchTime := timer 440 debug_microOp(enqIndex).debugInfo.enqRsTime := timer 441 debug_microOp(enqIndex).debugInfo.selectTime := timer 442 debug_microOp(enqIndex).debugInfo.issueTime := timer 443 debug_microOp(enqIndex).debugInfo.writebackTime := timer 444 when (enqUop.ctrl.blockBackward) { 445 hasBlockBackward := true.B 446 } 447 when (enqUop.ctrl.noSpecExec) { 448 hasNoSpecExec := true.B 449 } 450 val enqHasTriggerHit = io.enq.req(i).bits.cf.trigger.getHitFrontend 451 val enqHasException = ExceptionNO.selectFrontend(enqUop.cf.exceptionVec).asUInt.orR 452 // the begin instruction of Svinval enqs so mark doingSvinval as true to indicate this process 453 when(!enqHasTriggerHit && !enqHasException && FuType.isSvinvalBegin(enqUop.ctrl.fuType, enqUop.ctrl.fuOpType, enqUop.ctrl.flushPipe)) 454 { 455 doingSvinval := true.B 456 } 457 // the end instruction of Svinval enqs so clear doingSvinval 458 when(!enqHasTriggerHit && !enqHasException && FuType.isSvinvalEnd(enqUop.ctrl.fuType, enqUop.ctrl.fuOpType, enqUop.ctrl.flushPipe)) 459 { 460 doingSvinval := false.B 461 } 462 // when we are in the process of Svinval software code area , only Svinval.vma and end instruction of Svinval can appear 463 assert(!doingSvinval || (FuType.isSvinval(enqUop.ctrl.fuType, enqUop.ctrl.fuOpType, enqUop.ctrl.flushPipe) || 464 FuType.isSvinvalEnd(enqUop.ctrl.fuType, enqUop.ctrl.fuOpType, enqUop.ctrl.flushPipe))) 465 when (enqUop.ctrl.isWFI && !enqHasException && !enqHasTriggerHit) { 466 hasWFI := true.B 467 } 468 } 469 } 470 val dispatchNum = Mux(io.enq.canAccept, PopCount(io.enq.req.map(_.valid)), 0.U) 471 io.enq.isEmpty := RegNext(isEmpty && !VecInit(io.enq.req.map(_.valid)).asUInt.orR) 472 473 when (!io.wfi_enable) { 474 hasWFI := false.B 475 } 476 // sel vsetvl's flush position 477 val vs_idle :: vs_waitVinstr :: vs_waitFlush :: Nil = Enum(3) 478 val vsetvlState = RegInit(vs_idle) 479 480 val firstVInstrFtqPtr = RegInit(0.U.asTypeOf(new FtqPtr)) 481 val firstVInstrFtqOffset = RegInit(0.U.asTypeOf(UInt(log2Up(PredictWidth).W))) 482 val firstVInstrRobIdx = RegInit(0.U.asTypeOf(new RobPtr)) 483 484 val enq0 = io.enq.req(0) 485 val enq0IsVset = FuType.isIntExu(enq0.bits.ctrl.fuType) && ALUOpType.isVset(enq0.bits.ctrl.fuOpType) && enq0.bits.ctrl.uopIdx.andR && canEnqueue(0) 486 val enq0IsVsetFlush = enq0IsVset && enq0.bits.ctrl.flushPipe 487 val enqIsVInstrVec = io.enq.req.zip(canEnqueue).map{case (req, fire) => FuType.isVpu(req.bits.ctrl.fuType) && fire} 488 // for vs_idle 489 val firstVInstrIdle = PriorityMux(enqIsVInstrVec.zip(io.enq.req).drop(1) :+ (true.B, 0.U.asTypeOf(io.enq.req(0).cloneType))) 490 // for vs_waitVinstr 491 val enqIsVInstrOrVset = (enqIsVInstrVec(0) || enq0IsVset) +: enqIsVInstrVec.drop(1) 492 val firstVInstrWait = PriorityMux(enqIsVInstrOrVset, io.enq.req) 493 when(vsetvlState === vs_idle){ 494 firstVInstrFtqPtr := firstVInstrIdle.bits.cf.ftqPtr 495 firstVInstrFtqOffset := firstVInstrIdle.bits.cf.ftqOffset 496 firstVInstrRobIdx := firstVInstrIdle.bits.robIdx 497 }.elsewhen(vsetvlState === vs_waitVinstr){ 498 firstVInstrFtqPtr := firstVInstrWait.bits.cf.ftqPtr 499 firstVInstrFtqOffset := firstVInstrWait.bits.cf.ftqOffset 500 firstVInstrRobIdx := firstVInstrWait.bits.robIdx 501 } 502 503 val hasVInstrAfterI = Cat(enqIsVInstrVec.drop(1)).orR 504 when(vsetvlState === vs_idle){ 505 when(enq0IsVsetFlush){ 506 vsetvlState := Mux(hasVInstrAfterI, vs_waitFlush, vs_waitVinstr) 507 } 508 }.elsewhen(vsetvlState === vs_waitVinstr){ 509 when(io.redirect.valid){ 510 vsetvlState := vs_idle 511 }.elsewhen(Cat(enqIsVInstrOrVset).orR){ 512 vsetvlState := vs_waitFlush 513 } 514 }.elsewhen(vsetvlState === vs_waitFlush){ 515 when(io.redirect.valid){ 516 vsetvlState := vs_idle 517 } 518 } 519 520 /** 521 * Writeback (from execution units) 522 */ 523 for (wb <- exuWriteback) { 524 when (wb.valid) { 525 val wbIdx = wb.bits.uop.robIdx.value 526 debug_exuData(wbIdx) := wb.bits.data 527 debug_exuDebug(wbIdx) := wb.bits.debug 528 debug_microOp(wbIdx).debugInfo.enqRsTime := wb.bits.uop.debugInfo.enqRsTime 529 debug_microOp(wbIdx).debugInfo.selectTime := wb.bits.uop.debugInfo.selectTime 530 debug_microOp(wbIdx).debugInfo.issueTime := wb.bits.uop.debugInfo.issueTime 531 debug_microOp(wbIdx).debugInfo.writebackTime := wb.bits.uop.debugInfo.writebackTime 532 533 // debug for lqidx and sqidx 534 debug_microOp(wbIdx).lqIdx := wb.bits.uop.lqIdx 535 debug_microOp(wbIdx).sqIdx := wb.bits.uop.sqIdx 536 537 val debug_Uop = debug_microOp(wbIdx) 538 XSInfo(true.B, 539 p"writebacked pc 0x${Hexadecimal(debug_Uop.cf.pc)} wen ${debug_Uop.ctrl.rfWen} " + 540 p"data 0x${Hexadecimal(wb.bits.data)} ldst ${debug_Uop.ctrl.ldest} pdst ${debug_Uop.pdest} " + 541 p"skip ${wb.bits.debug.isMMIO} robIdx: ${wb.bits.uop.robIdx}\n" 542 ) 543 } 544 } 545 val writebackNum = PopCount(exuWriteback.map(_.valid)) 546 XSInfo(writebackNum =/= 0.U, "writebacked %d insts\n", writebackNum) 547 548 549 /** 550 * RedirectOut: Interrupt and Exceptions 551 */ 552 val deqDispatchData = dispatchDataRead(0) 553 val debug_deqUop = debug_microOp(deqPtr.value) 554 555 val intrBitSetReg = RegNext(io.csr.intrBitSet) 556 val intrEnable = intrBitSetReg && !hasNoSpecExec && interrupt_safe(deqPtr.value) 557 val deqHasExceptionOrFlush = exceptionDataRead.valid && exceptionDataRead.bits.robIdx === deqPtr 558 val deqHasException = deqHasExceptionOrFlush && (exceptionDataRead.bits.exceptionVec.asUInt.orR || 559 exceptionDataRead.bits.singleStep || exceptionDataRead.bits.trigger.hit) 560 val deqHasFlushPipe = deqHasExceptionOrFlush && exceptionDataRead.bits.flushPipe 561 val deqHasReplayInst = deqHasExceptionOrFlush && exceptionDataRead.bits.replayInst 562 val exceptionEnable = writebacked(deqPtr.value) && deqHasException 563 564 XSDebug(deqHasException && exceptionDataRead.bits.singleStep, "Debug Mode: Deq has singlestep exception\n") 565 XSDebug(deqHasException && exceptionDataRead.bits.trigger.getHitFrontend, "Debug Mode: Deq has frontend trigger exception\n") 566 XSDebug(deqHasException && exceptionDataRead.bits.trigger.getHitBackend, "Debug Mode: Deq has backend trigger exception\n") 567 568 val isFlushPipe = writebacked(deqPtr.value) && (deqHasFlushPipe || deqHasReplayInst) 569 570 val isVsetFlushPipe = writebacked(deqPtr.value) && deqHasFlushPipe && exceptionDataRead.bits.isVset 571 val needModifyFtqIdxOffset = isVsetFlushPipe && (vsetvlState === vs_waitFlush) 572 io.isVsetFlushPipe := RegNext(isVsetFlushPipe) 573 // io.flushOut will trigger redirect at the next cycle. 574 // Block any redirect or commit at the next cycle. 575 val lastCycleFlush = RegNext(io.flushOut.valid) 576 577 io.flushOut.valid := (state === s_idle) && valid(deqPtr.value) && (intrEnable || exceptionEnable || isFlushPipe) && !lastCycleFlush 578 io.flushOut.bits := DontCare 579 io.flushOut.bits.robIdx := Mux(needModifyFtqIdxOffset, firstVInstrRobIdx, deqPtr) 580 io.flushOut.bits.ftqIdx := Mux(needModifyFtqIdxOffset, firstVInstrFtqPtr, deqDispatchData.ftqIdx) 581 io.flushOut.bits.ftqOffset := Mux(needModifyFtqIdxOffset, firstVInstrFtqOffset, deqDispatchData.ftqOffset) 582 io.flushOut.bits.level := Mux(deqHasReplayInst || intrEnable || exceptionEnable || needModifyFtqIdxOffset, RedirectLevel.flush, RedirectLevel.flushAfter) // TODO use this to implement "exception next" 583 io.flushOut.bits.interrupt := true.B 584 XSPerfAccumulate("interrupt_num", io.flushOut.valid && intrEnable) 585 XSPerfAccumulate("exception_num", io.flushOut.valid && exceptionEnable) 586 XSPerfAccumulate("flush_pipe_num", io.flushOut.valid && isFlushPipe) 587 XSPerfAccumulate("replay_inst_num", io.flushOut.valid && isFlushPipe && deqHasReplayInst) 588 589 val exceptionHappen = (state === s_idle) && valid(deqPtr.value) && (intrEnable || exceptionEnable) && !lastCycleFlush 590 io.exception.valid := RegNext(exceptionHappen) 591 io.exception.bits.uop := RegEnable(debug_deqUop, exceptionHappen) 592 io.exception.bits.uop.ctrl.commitType := RegEnable(deqDispatchData.commitType, exceptionHappen) 593 io.exception.bits.uop.cf.exceptionVec := RegEnable(exceptionDataRead.bits.exceptionVec, exceptionHappen) 594 io.exception.bits.uop.ctrl.singleStep := RegEnable(exceptionDataRead.bits.singleStep, exceptionHappen) 595 io.exception.bits.uop.cf.crossPageIPFFix := RegEnable(exceptionDataRead.bits.crossPageIPFFix, exceptionHappen) 596 io.exception.bits.isInterrupt := RegEnable(intrEnable, exceptionHappen) 597 io.exception.bits.uop.cf.trigger := RegEnable(exceptionDataRead.bits.trigger, exceptionHappen) 598 599 XSDebug(io.flushOut.valid, 600 p"generate redirect: pc 0x${Hexadecimal(io.exception.bits.uop.cf.pc)} intr $intrEnable " + 601 p"excp $exceptionEnable flushPipe $isFlushPipe " + 602 p"Trap_target 0x${Hexadecimal(io.csr.trapTarget)} exceptionVec ${Binary(exceptionDataRead.bits.exceptionVec.asUInt)}\n") 603 604 605 /** 606 * Commits (and walk) 607 * They share the same width. 608 */ 609 val walkCounter = Reg(UInt(log2Up(RobSize + 1).W)) 610 val shouldWalkVec = VecInit((0 until CommitWidth).map(_.U < walkCounter)) 611 val walkFinished = walkCounter <= CommitWidth.U 612 613 require(RenameWidth <= CommitWidth) 614 615 // wiring to csr 616 val (wflags, fpWen) = (0 until CommitWidth).map(i => { 617 val v = io.commits.commitValid(i) 618 val info = io.commits.info(i) 619 (v & info.wflags, v & info.fpWen) 620 }).unzip 621 val fflags = Wire(Valid(UInt(5.W))) 622 fflags.valid := io.commits.isCommit && VecInit(wflags).asUInt.orR 623 fflags.bits := wflags.zip(fflagsDataRead).map({ 624 case (w, f) => Mux(w, f, 0.U) 625 }).reduce(_|_) 626 val dirty_fs = io.commits.isCommit && VecInit(fpWen).asUInt.orR 627 628 // when mispredict branches writeback, stop commit in the next 2 cycles 629 // TODO: don't check all exu write back 630 val misPredWb = Cat(VecInit(exuWriteback.map(wb => 631 wb.bits.redirect.cfiUpdate.isMisPred && wb.bits.redirectValid 632 ))).orR 633 val misPredBlockCounter = Reg(UInt(3.W)) 634 misPredBlockCounter := Mux(misPredWb, 635 "b111".U, 636 misPredBlockCounter >> 1.U 637 ) 638 val misPredBlock = misPredBlockCounter(0) 639 val blockCommit = misPredBlock || isReplaying || lastCycleFlush || hasWFI 640 641 io.commits.isWalk := state === s_walk 642 io.commits.isCommit := state === s_idle && !blockCommit 643 val walk_v = VecInit(walkPtrVec.map(ptr => valid(ptr.value))) 644 val commit_v = VecInit(deqPtrVec.map(ptr => valid(ptr.value))) 645 // store will be commited iff both sta & std have been writebacked 646 val commit_w = VecInit(deqPtrVec.map(ptr => writebacked(ptr.value) && store_data_writebacked(ptr.value))) 647 val commit_exception = exceptionDataRead.valid && !isAfter(exceptionDataRead.bits.robIdx, deqPtrVec.last) 648 val commit_block = VecInit((0 until CommitWidth).map(i => !commit_w(i))) 649 val allowOnlyOneCommit = commit_exception || intrBitSetReg 650 // for instructions that may block others, we don't allow them to commit 651 for (i <- 0 until CommitWidth) { 652 // defaults: state === s_idle and instructions commit 653 // when intrBitSetReg, allow only one instruction to commit at each clock cycle 654 val isBlocked = if (i != 0) Cat(commit_block.take(i)).orR || allowOnlyOneCommit else intrEnable || deqHasException || deqHasReplayInst 655 io.commits.commitValid(i) := commit_v(i) && commit_w(i) && !isBlocked 656 io.commits.info(i) := dispatchDataRead(i) 657 658 when (state === s_walk) { 659 io.commits.walkValid(i) := shouldWalkVec(i) 660 when (io.commits.isWalk && state === s_walk && shouldWalkVec(i)) { 661 XSError(!walk_v(i), s"why not $i???\n") 662 } 663 } 664 665 XSInfo(io.commits.isCommit && io.commits.commitValid(i), 666 "retired pc %x wen %d ldest %d pdest %x old_pdest %x data %x fflags: %b\n", 667 debug_microOp(deqPtrVec(i).value).cf.pc, 668 io.commits.info(i).rfWen, 669 io.commits.info(i).ldest, 670 io.commits.info(i).pdest, 671 io.commits.info(i).old_pdest, 672 debug_exuData(deqPtrVec(i).value), 673 fflagsDataRead(i) 674 ) 675 XSInfo(state === s_walk && io.commits.walkValid(i), "walked pc %x wen %d ldst %d data %x\n", 676 debug_microOp(walkPtrVec(i).value).cf.pc, 677 io.commits.info(i).rfWen, 678 io.commits.info(i).ldest, 679 debug_exuData(walkPtrVec(i).value) 680 ) 681 } 682 if (env.EnableDifftest) { 683 io.commits.info.map(info => dontTouch(info.pc)) 684 } 685 686 // sync fflags/dirty_fs to csr 687 io.csr.fflags := RegNext(fflags) 688 io.csr.dirty_fs := RegNext(dirty_fs) 689 690 // sync v csr to csr 691// io.csr.vcsrFlag := RegNext(isVsetFlushPipe) 692 693 // commit load/store to lsq 694 val ldCommitVec = VecInit((0 until CommitWidth).map(i => io.commits.commitValid(i) && io.commits.info(i).commitType === CommitType.LOAD)) 695 val stCommitVec = VecInit((0 until CommitWidth).map(i => io.commits.commitValid(i) && io.commits.info(i).commitType === CommitType.STORE)) 696 io.lsq.lcommit := RegNext(Mux(io.commits.isCommit, PopCount(ldCommitVec), 0.U)) 697 io.lsq.scommit := RegNext(Mux(io.commits.isCommit, PopCount(stCommitVec), 0.U)) 698 // indicate a pending load or store 699 io.lsq.pendingld := RegNext(io.commits.isCommit && io.commits.info(0).commitType === CommitType.LOAD && valid(deqPtr.value)) 700 io.lsq.pendingst := RegNext(io.commits.isCommit && io.commits.info(0).commitType === CommitType.STORE && valid(deqPtr.value)) 701 io.lsq.commit := RegNext(io.commits.isCommit && io.commits.commitValid(0)) 702 703 /** 704 * state changes 705 * (1) redirect: switch to s_walk 706 * (2) walk: when walking comes to the end, switch to s_idle 707 */ 708 val state_next = Mux(io.redirect.valid, s_walk, Mux(state === s_walk && walkFinished, s_idle, state)) 709 XSPerfAccumulate("s_idle_to_idle", state === s_idle && state_next === s_idle) 710 XSPerfAccumulate("s_idle_to_walk", state === s_idle && state_next === s_walk) 711 XSPerfAccumulate("s_walk_to_idle", state === s_walk && state_next === s_idle) 712 XSPerfAccumulate("s_walk_to_walk", state === s_walk && state_next === s_walk) 713 state := state_next 714 715 /** 716 * pointers and counters 717 */ 718 val deqPtrGenModule = Module(new RobDeqPtrWrapper) 719 deqPtrGenModule.io.state := state 720 deqPtrGenModule.io.deq_v := commit_v 721 deqPtrGenModule.io.deq_w := commit_w 722 deqPtrGenModule.io.exception_state := exceptionDataRead 723 deqPtrGenModule.io.intrBitSetReg := intrBitSetReg 724 deqPtrGenModule.io.hasNoSpecExec := hasNoSpecExec 725 deqPtrGenModule.io.interrupt_safe := interrupt_safe(deqPtr.value) 726 deqPtrGenModule.io.blockCommit := blockCommit 727 deqPtrVec := deqPtrGenModule.io.out 728 val deqPtrVec_next = deqPtrGenModule.io.next_out 729 730 val enqPtrGenModule = Module(new RobEnqPtrWrapper) 731 enqPtrGenModule.io.redirect := io.redirect 732 enqPtrGenModule.io.allowEnqueue := allowEnqueue 733 enqPtrGenModule.io.hasBlockBackward := hasBlockBackward 734 enqPtrGenModule.io.enq := VecInit(io.enq.req.map(_.valid)) 735 enqPtrVec := enqPtrGenModule.io.out 736 737 val thisCycleWalkCount = Mux(walkFinished, walkCounter, CommitWidth.U) 738 // next walkPtrVec: 739 // (1) redirect occurs: update according to state 740 // (2) walk: move forwards 741 val walkPtrVec_next = Mux(io.redirect.valid, 742 deqPtrVec_next, 743 Mux(state === s_walk, VecInit(walkPtrVec.map(_ + CommitWidth.U)), walkPtrVec) 744 ) 745 walkPtrVec := walkPtrVec_next 746 747 val numValidEntries = distanceBetween(enqPtr, deqPtr) 748 val isLastUopVec = io.commits.info.map(_.uopIdx.andR) 749 val commitCnt = PopCount(io.commits.commitValid.zip(isLastUopVec).map{case(isCommitValid, isLastUop) => isCommitValid && isLastUop}) 750 751 allowEnqueue := numValidEntries + dispatchNum <= (RobSize - RenameWidth).U 752 753 val currentWalkPtr = Mux(state === s_walk, walkPtr, deqPtrVec_next(0)) 754 val redirectWalkDistance = distanceBetween(io.redirect.bits.robIdx, deqPtrVec_next(0)) 755 when (io.redirect.valid) { 756 // full condition: 757 // +& is used here because: 758 // When rob is full and the tail instruction causes a misprediction, 759 // the redirect robIdx is the deqPtr - 1. In this case, redirectWalkDistance 760 // is RobSize - 1. 761 // Since misprediction does not flush the instruction itself, flushItSelf is false.B. 762 // Previously we use `+` to count the walk distance and it causes overflows 763 // when RobSize is power of 2. We change it to `+&` to allow walkCounter to be RobSize. 764 // The width of walkCounter also needs to be changed. 765 // empty condition: 766 // When the last instruction in ROB commits and causes a flush, a redirect 767 // will be raised later. In such circumstances, the redirect robIdx is before 768 // the deqPtrVec_next(0) and will cause underflow. 769 walkCounter := Mux(isBefore(io.redirect.bits.robIdx, deqPtrVec_next(0)), 0.U, 770 redirectWalkDistance +& !io.redirect.bits.flushItself()) 771 }.elsewhen (state === s_walk) { 772 walkCounter := walkCounter - thisCycleWalkCount 773 XSInfo(p"rolling back: $enqPtr $deqPtr walk $walkPtr walkcnt $walkCounter\n") 774 } 775 776 777 /** 778 * States 779 * We put all the stage bits changes here. 780 781 * All events: (1) enqueue (dispatch); (2) writeback; (3) cancel; (4) dequeue (commit); 782 * All states: (1) valid; (2) writebacked; (3) flagBkup 783 */ 784 val commitReadAddr = Mux(state === s_idle, VecInit(deqPtrVec.map(_.value)), VecInit(walkPtrVec.map(_.value))) 785 786 // redirect logic writes 6 valid 787 val redirectHeadVec = Reg(Vec(RenameWidth, new RobPtr)) 788 val redirectTail = Reg(new RobPtr) 789 val redirectIdle :: redirectBusy :: Nil = Enum(2) 790 val redirectState = RegInit(redirectIdle) 791 val invMask = redirectHeadVec.map(redirectHead => isBefore(redirectHead, redirectTail)) 792 when(redirectState === redirectBusy) { 793 redirectHeadVec.foreach(redirectHead => redirectHead := redirectHead + RenameWidth.U) 794 redirectHeadVec zip invMask foreach { 795 case (redirectHead, inv) => when(inv) { 796 valid(redirectHead.value) := false.B 797 } 798 } 799 when(!invMask.last) { 800 redirectState := redirectIdle 801 } 802 } 803 when(io.redirect.valid) { 804 redirectState := redirectBusy 805 when(redirectState === redirectIdle) { 806 redirectTail := enqPtr 807 } 808 redirectHeadVec.zipWithIndex.foreach { case (redirectHead, i) => 809 redirectHead := Mux(io.redirect.bits.flushItself(), io.redirect.bits.robIdx + i.U, io.redirect.bits.robIdx + (i + 1).U) 810 } 811 } 812 // enqueue logic writes 6 valid 813 for (i <- 0 until RenameWidth) { 814 when (canEnqueue(i) && !io.redirect.valid) { 815 valid(allocatePtrVec(i).value) := true.B 816 } 817 } 818 // dequeue logic writes 6 valid 819 for (i <- 0 until CommitWidth) { 820 val commitValid = io.commits.isCommit && io.commits.commitValid(i) 821 when (commitValid) { 822 valid(commitReadAddr(i)) := false.B 823 } 824 } 825 826 // status field: writebacked 827 // enqueue logic set 6 writebacked to false 828 for (i <- 0 until RenameWidth) { 829 when (canEnqueue(i)) { 830 val enqHasException = ExceptionNO.selectFrontend(io.enq.req(i).bits.cf.exceptionVec).asUInt.orR 831 val enqHasTriggerHit = io.enq.req(i).bits.cf.trigger.getHitFrontend 832 val enqIsWritebacked = io.enq.req(i).bits.eliminatedMove 833 writebacked(allocatePtrVec(i).value) := enqIsWritebacked && !enqHasException && !enqHasTriggerHit 834 val isStu = io.enq.req(i).bits.ctrl.fuType === FuType.stu 835 store_data_writebacked(allocatePtrVec(i).value) := !isStu 836 } 837 } 838 when (exceptionGen.io.out.valid) { 839 val wbIdx = exceptionGen.io.out.bits.robIdx.value 840 writebacked(wbIdx) := true.B 841 store_data_writebacked(wbIdx) := true.B 842 } 843 // writeback logic set numWbPorts writebacked to true 844 for ((wb, cfgs) <- exuWriteback.zip(wbExuConfigs(exeWbSel))) { 845 when (wb.valid) { 846 val wbIdx = wb.bits.uop.robIdx.value 847 val wbHasException = ExceptionNO.selectByExu(wb.bits.uop.cf.exceptionVec, cfgs).asUInt.orR 848 val wbHasTriggerHit = wb.bits.uop.cf.trigger.getHitBackend 849 val wbHasFlushPipe = cfgs.exists(_.flushPipe).B && wb.bits.uop.ctrl.flushPipe 850 val wbHasReplayInst = cfgs.exists(_.replayInst).B && wb.bits.uop.ctrl.replayInst 851 val block_wb = wbHasException || wbHasFlushPipe || wbHasReplayInst || wbHasTriggerHit 852 writebacked(wbIdx) := !block_wb 853 } 854 } 855 // store data writeback logic mark store as data_writebacked 856 for (wb <- stdWriteback) { 857 when(RegNext(wb.valid)) { 858 store_data_writebacked(RegNext(wb.bits.uop.robIdx.value)) := true.B 859 } 860 } 861 862 // flagBkup 863 // enqueue logic set 6 flagBkup at most 864 for (i <- 0 until RenameWidth) { 865 when (canEnqueue(i)) { 866 flagBkup(allocatePtrVec(i).value) := allocatePtrVec(i).flag 867 } 868 } 869 870 // interrupt_safe 871 for (i <- 0 until RenameWidth) { 872 // We RegNext the updates for better timing. 873 // Note that instructions won't change the system's states in this cycle. 874 when (RegNext(canEnqueue(i))) { 875 // For now, we allow non-load-store instructions to trigger interrupts 876 // For MMIO instructions, they should not trigger interrupts since they may 877 // be sent to lower level before it writes back. 878 // However, we cannot determine whether a load/store instruction is MMIO. 879 // Thus, we don't allow load/store instructions to trigger an interrupt. 880 // TODO: support non-MMIO load-store instructions to trigger interrupts 881 val allow_interrupts = !CommitType.isLoadStore(io.enq.req(i).bits.ctrl.commitType) 882 interrupt_safe(RegNext(allocatePtrVec(i).value)) := RegNext(allow_interrupts) 883 } 884 } 885 886 /** 887 * read and write of data modules 888 */ 889 val commitReadAddr_next = Mux(state_next === s_idle, 890 VecInit(deqPtrVec_next.map(_.value)), 891 VecInit(walkPtrVec_next.map(_.value)) 892 ) 893 dispatchData.io.wen := canEnqueue 894 dispatchData.io.waddr := allocatePtrVec.map(_.value) 895 dispatchData.io.wdata.zip(io.enq.req.map(_.bits)).foreach{ case (wdata, req) => 896 wdata.ldest := req.ctrl.ldest 897 wdata.rfWen := req.ctrl.rfWen 898 wdata.fpWen := req.ctrl.fpWen 899 wdata.vecWen := req.ctrl.vecWen 900 wdata.wflags := req.ctrl.fpu.wflags 901 wdata.commitType := req.ctrl.commitType 902 wdata.pdest := req.pdest 903 wdata.old_pdest := req.old_pdest 904 wdata.ftqIdx := req.cf.ftqPtr 905 wdata.ftqOffset := req.cf.ftqOffset 906 wdata.isMove := req.eliminatedMove 907 wdata.pc := req.cf.pc 908 wdata.uopIdx := req.ctrl.uopIdx 909 wdata.vconfig := req.ctrl.vconfig 910 } 911 dispatchData.io.raddr := commitReadAddr_next 912 913 exceptionGen.io.redirect <> io.redirect 914 exceptionGen.io.flush := io.flushOut.valid 915 for (i <- 0 until RenameWidth) { 916 exceptionGen.io.enq(i).valid := canEnqueue(i) 917 exceptionGen.io.enq(i).bits.robIdx := io.enq.req(i).bits.robIdx 918 exceptionGen.io.enq(i).bits.exceptionVec := ExceptionNO.selectFrontend(io.enq.req(i).bits.cf.exceptionVec) 919 exceptionGen.io.enq(i).bits.flushPipe := io.enq.req(i).bits.ctrl.flushPipe 920 exceptionGen.io.enq(i).bits.isVset := FuType.isIntExu(io.enq.req(i).bits.ctrl.fuType) && ALUOpType.isVset(io.enq.req(i).bits.ctrl.fuOpType) 921 exceptionGen.io.enq(i).bits.replayInst := false.B 922 XSError(canEnqueue(i) && io.enq.req(i).bits.ctrl.replayInst, "enq should not set replayInst") 923 exceptionGen.io.enq(i).bits.singleStep := io.enq.req(i).bits.ctrl.singleStep 924 exceptionGen.io.enq(i).bits.crossPageIPFFix := io.enq.req(i).bits.cf.crossPageIPFFix 925 exceptionGen.io.enq(i).bits.trigger.clear() 926 exceptionGen.io.enq(i).bits.trigger.frontendHit := io.enq.req(i).bits.cf.trigger.frontendHit 927 } 928 929 println(s"ExceptionGen:") 930 val exceptionCases = exceptionPorts.map(_._1.flatMap(_.exceptionOut).distinct.sorted) 931 require(exceptionCases.length == exceptionGen.io.wb.length) 932 for ((((configs, wb), exc_wb), i) <- exceptionPorts.zip(exceptionGen.io.wb).zipWithIndex) { 933 exc_wb.valid := wb.valid 934 exc_wb.bits.robIdx := wb.bits.uop.robIdx 935 exc_wb.bits.exceptionVec := ExceptionNO.selectByExu(wb.bits.uop.cf.exceptionVec, configs) 936 exc_wb.bits.flushPipe := configs.exists(_.flushPipe).B && wb.bits.uop.ctrl.flushPipe 937 exc_wb.bits.isVset := false.B 938 exc_wb.bits.replayInst := configs.exists(_.replayInst).B && wb.bits.uop.ctrl.replayInst 939 exc_wb.bits.singleStep := false.B 940 exc_wb.bits.crossPageIPFFix := false.B 941 // TODO: make trigger configurable 942 exc_wb.bits.trigger.clear() 943 exc_wb.bits.trigger.backendHit := wb.bits.uop.cf.trigger.backendHit 944 println(s" [$i] ${configs.map(_.name)}: exception ${exceptionCases(i)}, " + 945 s"flushPipe ${configs.exists(_.flushPipe)}, " + 946 s"replayInst ${configs.exists(_.replayInst)}") 947 } 948 949 val fflags_wb = fflagsPorts.map(_._2) 950 val fflagsDataModule = Module(new SyncDataModuleTemplate( 951 UInt(5.W), RobSize, CommitWidth, fflags_wb.size) 952 ) 953 for(i <- fflags_wb.indices){ 954 fflagsDataModule.io.wen (i) := fflags_wb(i).valid 955 fflagsDataModule.io.waddr(i) := fflags_wb(i).bits.uop.robIdx.value 956 fflagsDataModule.io.wdata(i) := fflags_wb(i).bits.fflags 957 } 958 fflagsDataModule.io.raddr := VecInit(deqPtrVec_next.map(_.value)) 959 fflagsDataRead := fflagsDataModule.io.rdata 960 961 962 val instrCntReg = RegInit(0.U(64.W)) 963 val fuseCommitCnt = PopCount(io.commits.commitValid.zip(io.commits.info).map{ case (v, i) => RegNext(v && CommitType.isFused(i.commitType)) }) 964 val trueCommitCnt = RegNext(commitCnt) +& fuseCommitCnt 965 val retireCounter = Mux(RegNext(io.commits.isCommit), trueCommitCnt, 0.U) 966 val instrCnt = instrCntReg + retireCounter 967 instrCntReg := instrCnt 968 io.csr.perfinfo.retiredInstr := retireCounter 969 io.robFull := !allowEnqueue 970 971 /** 972 * debug info 973 */ 974 XSDebug(p"enqPtr ${enqPtr} deqPtr ${deqPtr}\n") 975 XSDebug("") 976 for(i <- 0 until RobSize){ 977 XSDebug(false, !valid(i), "-") 978 XSDebug(false, valid(i) && writebacked(i), "w") 979 XSDebug(false, valid(i) && !writebacked(i), "v") 980 } 981 XSDebug(false, true.B, "\n") 982 983 for(i <- 0 until RobSize) { 984 if(i % 4 == 0) XSDebug("") 985 XSDebug(false, true.B, "%x ", debug_microOp(i).cf.pc) 986 XSDebug(false, !valid(i), "- ") 987 XSDebug(false, valid(i) && writebacked(i), "w ") 988 XSDebug(false, valid(i) && !writebacked(i), "v ") 989 if(i % 4 == 3) XSDebug(false, true.B, "\n") 990 } 991 992 def ifCommit(counter: UInt): UInt = Mux(io.commits.isCommit, counter, 0.U) 993 def ifCommitReg(counter: UInt): UInt = Mux(RegNext(io.commits.isCommit), counter, 0.U) 994 995 val commitDebugUop = deqPtrVec.map(_.value).map(debug_microOp(_)) 996 XSPerfAccumulate("clock_cycle", 1.U) 997 QueuePerf(RobSize, PopCount((0 until RobSize).map(valid(_))), !allowEnqueue) 998 XSPerfAccumulate("commitUop", ifCommit(commitCnt)) 999 XSPerfAccumulate("commitInstr", ifCommitReg(trueCommitCnt)) 1000 val commitIsMove = commitDebugUop.map(_.ctrl.isMove) 1001 XSPerfAccumulate("commitInstrMove", ifCommit(PopCount(io.commits.commitValid.zip(commitIsMove).map{ case (v, m) => v && m }))) 1002 val commitMoveElim = commitDebugUop.map(_.debugInfo.eliminatedMove) 1003 XSPerfAccumulate("commitInstrMoveElim", ifCommit(PopCount(io.commits.commitValid zip commitMoveElim map { case (v, e) => v && e }))) 1004 XSPerfAccumulate("commitInstrFused", ifCommitReg(fuseCommitCnt)) 1005 val commitIsLoad = io.commits.info.map(_.commitType).map(_ === CommitType.LOAD) 1006 val commitLoadValid = io.commits.commitValid.zip(commitIsLoad).map{ case (v, t) => v && t } 1007 XSPerfAccumulate("commitInstrLoad", ifCommit(PopCount(commitLoadValid))) 1008 val commitIsBranch = io.commits.info.map(_.commitType).map(_ === CommitType.BRANCH) 1009 val commitBranchValid = io.commits.commitValid.zip(commitIsBranch).map{ case (v, t) => v && t } 1010 XSPerfAccumulate("commitInstrBranch", ifCommit(PopCount(commitBranchValid))) 1011 val commitLoadWaitBit = commitDebugUop.map(_.cf.loadWaitBit) 1012 XSPerfAccumulate("commitInstrLoadWait", ifCommit(PopCount(commitLoadValid.zip(commitLoadWaitBit).map{ case (v, w) => v && w }))) 1013 val commitIsStore = io.commits.info.map(_.commitType).map(_ === CommitType.STORE) 1014 XSPerfAccumulate("commitInstrStore", ifCommit(PopCount(io.commits.commitValid.zip(commitIsStore).map{ case (v, t) => v && t }))) 1015 XSPerfAccumulate("writeback", PopCount((0 until RobSize).map(i => valid(i) && writebacked(i)))) 1016 // XSPerfAccumulate("enqInstr", PopCount(io.dp1Req.map(_.fire))) 1017 // XSPerfAccumulate("d2rVnR", PopCount(io.dp1Req.map(p => p.valid && !p.ready))) 1018 XSPerfAccumulate("walkInstr", Mux(io.commits.isWalk, PopCount(io.commits.walkValid), 0.U)) 1019 XSPerfAccumulate("walkCycle", state === s_walk) 1020 val deqNotWritebacked = valid(deqPtr.value) && !writebacked(deqPtr.value) 1021 val deqUopCommitType = io.commits.info(0).commitType 1022 XSPerfAccumulate("waitNormalCycle", deqNotWritebacked && deqUopCommitType === CommitType.NORMAL) 1023 XSPerfAccumulate("waitBranchCycle", deqNotWritebacked && deqUopCommitType === CommitType.BRANCH) 1024 XSPerfAccumulate("waitLoadCycle", deqNotWritebacked && deqUopCommitType === CommitType.LOAD) 1025 XSPerfAccumulate("waitStoreCycle", deqNotWritebacked && deqUopCommitType === CommitType.STORE) 1026 XSPerfAccumulate("robHeadPC", io.commits.info(0).pc) 1027 val dispatchLatency = commitDebugUop.map(uop => uop.debugInfo.dispatchTime - uop.debugInfo.renameTime) 1028 val enqRsLatency = commitDebugUop.map(uop => uop.debugInfo.enqRsTime - uop.debugInfo.dispatchTime) 1029 val selectLatency = commitDebugUop.map(uop => uop.debugInfo.selectTime - uop.debugInfo.enqRsTime) 1030 val issueLatency = commitDebugUop.map(uop => uop.debugInfo.issueTime - uop.debugInfo.selectTime) 1031 val executeLatency = commitDebugUop.map(uop => uop.debugInfo.writebackTime - uop.debugInfo.issueTime) 1032 val rsFuLatency = commitDebugUop.map(uop => uop.debugInfo.writebackTime - uop.debugInfo.enqRsTime) 1033 val commitLatency = commitDebugUop.map(uop => timer - uop.debugInfo.writebackTime) 1034 def latencySum(cond: Seq[Bool], latency: Seq[UInt]): UInt = { 1035 cond.zip(latency).map(x => Mux(x._1, x._2, 0.U)).reduce(_ +& _) 1036 } 1037 for (fuType <- FuType.functionNameMap.keys) { 1038 val fuName = FuType.functionNameMap(fuType) 1039 val commitIsFuType = io.commits.commitValid.zip(commitDebugUop).map(x => x._1 && x._2.ctrl.fuType === fuType.U ) 1040 XSPerfAccumulate(s"${fuName}_instr_cnt", ifCommit(PopCount(commitIsFuType))) 1041 XSPerfAccumulate(s"${fuName}_latency_dispatch", ifCommit(latencySum(commitIsFuType, dispatchLatency))) 1042 XSPerfAccumulate(s"${fuName}_latency_enq_rs", ifCommit(latencySum(commitIsFuType, enqRsLatency))) 1043 XSPerfAccumulate(s"${fuName}_latency_select", ifCommit(latencySum(commitIsFuType, selectLatency))) 1044 XSPerfAccumulate(s"${fuName}_latency_issue", ifCommit(latencySum(commitIsFuType, issueLatency))) 1045 XSPerfAccumulate(s"${fuName}_latency_execute", ifCommit(latencySum(commitIsFuType, executeLatency))) 1046 XSPerfAccumulate(s"${fuName}_latency_enq_rs_execute", ifCommit(latencySum(commitIsFuType, rsFuLatency))) 1047 XSPerfAccumulate(s"${fuName}_latency_commit", ifCommit(latencySum(commitIsFuType, commitLatency))) 1048 if (fuType == FuType.fmac.litValue) { 1049 val commitIsFma = commitIsFuType.zip(commitDebugUop).map(x => x._1 && x._2.ctrl.fpu.ren3 ) 1050 XSPerfAccumulate(s"${fuName}_instr_cnt_fma", ifCommit(PopCount(commitIsFma))) 1051 XSPerfAccumulate(s"${fuName}_latency_enq_rs_execute_fma", ifCommit(latencySum(commitIsFma, rsFuLatency))) 1052 XSPerfAccumulate(s"${fuName}_latency_execute_fma", ifCommit(latencySum(commitIsFma, executeLatency))) 1053 } 1054 } 1055 1056 //difftest signals 1057 val firstValidCommit = (deqPtr + PriorityMux(io.commits.commitValid, VecInit(List.tabulate(CommitWidth)(_.U(log2Up(CommitWidth).W))))).value 1058 1059 val wdata = Wire(Vec(CommitWidth, UInt(XLEN.W))) 1060 val wpc = Wire(Vec(CommitWidth, UInt(XLEN.W))) 1061 1062 for(i <- 0 until CommitWidth) { 1063 val idx = deqPtrVec(i).value 1064 wdata(i) := debug_exuData(idx) 1065 wpc(i) := SignExt(commitDebugUop(i).cf.pc, XLEN) 1066 } 1067 1068 if (env.EnableDifftest) { 1069 for (i <- 0 until CommitWidth) { 1070 val difftest = Module(new DifftestInstrCommit) 1071 // assgin default value 1072 difftest.io := DontCare 1073 1074 difftest.io.clock := clock 1075 difftest.io.coreid := io.hartId 1076 difftest.io.index := i.U 1077 1078 val ptr = deqPtrVec(i).value 1079 val uop = commitDebugUop(i) 1080 val exuOut = debug_exuDebug(ptr) 1081 val exuData = debug_exuData(ptr) 1082 difftest.io.valid := RegNext(RegNext(RegNext(io.commits.commitValid(i) && io.commits.isCommit))) 1083 difftest.io.pc := RegNext(RegNext(RegNext(SignExt(uop.cf.pc, XLEN)))) 1084 difftest.io.instr := RegNext(RegNext(RegNext(uop.cf.instr))) 1085 difftest.io.robIdx := RegNext(RegNext(RegNext(ZeroExt(ptr, 10)))) 1086 difftest.io.lqIdx := RegNext(RegNext(RegNext(ZeroExt(uop.lqIdx.value, 7)))) 1087 difftest.io.sqIdx := RegNext(RegNext(RegNext(ZeroExt(uop.sqIdx.value, 7)))) 1088 difftest.io.isLoad := RegNext(RegNext(RegNext(io.commits.info(i).commitType === CommitType.LOAD))) 1089 difftest.io.isStore := RegNext(RegNext(RegNext(io.commits.info(i).commitType === CommitType.STORE))) 1090 difftest.io.special := RegNext(RegNext(RegNext(CommitType.isFused(io.commits.info(i).commitType)))) 1091 // when committing an eliminated move instruction, 1092 // we must make sure that skip is properly set to false (output from EXU is random value) 1093 difftest.io.skip := RegNext(RegNext(RegNext(Mux(uop.eliminatedMove, false.B, exuOut.isMMIO || exuOut.isPerfCnt)))) 1094 difftest.io.isRVC := RegNext(RegNext(RegNext(uop.cf.pd.isRVC))) 1095 difftest.io.rfwen := RegNext(RegNext(RegNext(io.commits.commitValid(i) && io.commits.info(i).rfWen && io.commits.info(i).ldest =/= 0.U))) 1096 difftest.io.fpwen := RegNext(RegNext(RegNext(io.commits.commitValid(i) && io.commits.info(i).fpWen))) 1097 difftest.io.vecwen := RegNext(RegNext(RegNext(io.commits.commitValid(i) && io.commits.info(i).vecWen))) 1098 difftest.io.fpvecwen := RegNext(RegNext(RegNext(io.commits.commitValid(i) && io.commits.info(i).fpVecWen))) 1099 difftest.io.wpdest := RegNext(RegNext(RegNext(io.commits.info(i).pdest))) 1100 difftest.io.wdest := RegNext(RegNext(RegNext(io.commits.info(i).ldest))) 1101 1102 difftest.io.isVsetFirst := RegNext(RegNext(RegNext(io.commits.commitValid(i) && !io.commits.info(i).uopIdx.orR))) 1103 // // runahead commit hint 1104 // val runahead_commit = Module(new DifftestRunaheadCommitEvent) 1105 // runahead_commit.io.clock := clock 1106 // runahead_commit.io.coreid := io.hartId 1107 // runahead_commit.io.index := i.U 1108 // runahead_commit.io.valid := difftest.io.valid && 1109 // (commitBranchValid(i) || commitIsStore(i)) 1110 // // TODO: is branch or store 1111 // runahead_commit.io.pc := difftest.io.pc 1112 } 1113 } 1114 else if (env.AlwaysBasicDiff) { 1115 // These are the structures used by difftest only and should be optimized after synthesis. 1116 val dt_eliminatedMove = Mem(RobSize, Bool()) 1117 val dt_isRVC = Mem(RobSize, Bool()) 1118 val dt_exuDebug = Reg(Vec(RobSize, new DebugBundle)) 1119 for (i <- 0 until RenameWidth) { 1120 when (canEnqueue(i)) { 1121 dt_eliminatedMove(allocatePtrVec(i).value) := io.enq.req(i).bits.eliminatedMove 1122 dt_isRVC(allocatePtrVec(i).value) := io.enq.req(i).bits.cf.pd.isRVC 1123 } 1124 } 1125 for (wb <- exuWriteback) { 1126 when (wb.valid) { 1127 val wbIdx = wb.bits.uop.robIdx.value 1128 dt_exuDebug(wbIdx) := wb.bits.debug 1129 } 1130 } 1131 // Always instantiate basic difftest modules. 1132 for (i <- 0 until CommitWidth) { 1133 val commitInfo = io.commits.info(i) 1134 val ptr = deqPtrVec(i).value 1135 val exuOut = dt_exuDebug(ptr) 1136 val eliminatedMove = dt_eliminatedMove(ptr) 1137 val isRVC = dt_isRVC(ptr) 1138 1139 val difftest = Module(new DifftestBasicInstrCommit) 1140 difftest.io.clock := clock 1141 difftest.io.coreid := io.hartId 1142 difftest.io.index := i.U 1143 difftest.io.valid := RegNext(RegNext(RegNext(io.commits.commitValid(i) && io.commits.isCommit))) 1144 difftest.io.special := RegNext(RegNext(RegNext(CommitType.isFused(commitInfo.commitType)))) 1145 difftest.io.skip := RegNext(RegNext(RegNext(Mux(eliminatedMove, false.B, exuOut.isMMIO || exuOut.isPerfCnt)))) 1146 difftest.io.isRVC := RegNext(RegNext(RegNext(isRVC))) 1147 difftest.io.rfwen := RegNext(RegNext(RegNext(io.commits.commitValid(i) && commitInfo.rfWen && commitInfo.ldest =/= 0.U))) 1148 difftest.io.fpwen := RegNext(RegNext(RegNext(io.commits.commitValid(i) && commitInfo.fpWen))) 1149 difftest.io.vecwen := RegNext(RegNext(RegNext(io.commits.commitValid(i) && io.commits.info(i).vecWen))) 1150 difftest.io.fpvecwen := RegNext(RegNext(RegNext(io.commits.commitValid(i) && io.commits.info(i).fpVecWen))) 1151 difftest.io.wpdest := RegNext(RegNext(RegNext(commitInfo.pdest))) 1152 difftest.io.wdest := RegNext(RegNext(RegNext(commitInfo.ldest))) 1153 } 1154 } 1155 1156 if (env.EnableDifftest) { 1157 for (i <- 0 until CommitWidth) { 1158 val difftest = Module(new DifftestLoadEvent) 1159 difftest.io.clock := clock 1160 difftest.io.coreid := io.hartId 1161 difftest.io.index := i.U 1162 1163 val ptr = deqPtrVec(i).value 1164 val uop = commitDebugUop(i) 1165 val exuOut = debug_exuDebug(ptr) 1166 difftest.io.valid := RegNext(RegNext(RegNext(io.commits.commitValid(i) && io.commits.isCommit))) 1167 difftest.io.paddr := RegNext(RegNext(RegNext(exuOut.paddr))) 1168 difftest.io.opType := RegNext(RegNext(RegNext(uop.ctrl.fuOpType))) 1169 difftest.io.fuType := RegNext(RegNext(RegNext(uop.ctrl.fuType))) 1170 } 1171 } 1172 1173 // Always instantiate basic difftest modules. 1174 if (env.EnableDifftest) { 1175 val dt_isXSTrap = Mem(RobSize, Bool()) 1176 for (i <- 0 until RenameWidth) { 1177 when (canEnqueue(i)) { 1178 dt_isXSTrap(allocatePtrVec(i).value) := io.enq.req(i).bits.ctrl.isXSTrap 1179 } 1180 } 1181 val trapVec = io.commits.commitValid.zip(deqPtrVec).map{ case (v, d) => io.commits.isCommit && v && dt_isXSTrap(d.value) } 1182 val hitTrap = trapVec.reduce(_||_) 1183 val trapCode = PriorityMux(wdata.zip(trapVec).map(x => x._2 -> x._1)) 1184 val trapPC = SignExt(PriorityMux(wpc.zip(trapVec).map(x => x._2 ->x._1)), XLEN) 1185 val difftest = Module(new DifftestTrapEvent) 1186 difftest.io.clock := clock 1187 difftest.io.coreid := io.hartId 1188 difftest.io.valid := hitTrap 1189 difftest.io.code := trapCode 1190 difftest.io.pc := trapPC 1191 difftest.io.cycleCnt := timer 1192 difftest.io.instrCnt := instrCnt 1193 difftest.io.hasWFI := hasWFI 1194 } 1195 else if (env.AlwaysBasicDiff) { 1196 val dt_isXSTrap = Mem(RobSize, Bool()) 1197 for (i <- 0 until RenameWidth) { 1198 when (canEnqueue(i)) { 1199 dt_isXSTrap(allocatePtrVec(i).value) := io.enq.req(i).bits.ctrl.isXSTrap 1200 } 1201 } 1202 val trapVec = io.commits.commitValid.zip(deqPtrVec).map{ case (v, d) => io.commits.isCommit && v && dt_isXSTrap(d.value) } 1203 val hitTrap = trapVec.reduce(_||_) 1204 val difftest = Module(new DifftestBasicTrapEvent) 1205 difftest.io.clock := clock 1206 difftest.io.coreid := io.hartId 1207 difftest.io.valid := hitTrap 1208 difftest.io.cycleCnt := timer 1209 difftest.io.instrCnt := instrCnt 1210 } 1211 1212 val validEntriesBanks = (0 until (RobSize + 63) / 64).map(i => RegNext(PopCount(valid.drop(i * 64).take(64)))) 1213 val validEntries = RegNext(ParallelOperation(validEntriesBanks, (a: UInt, b: UInt) => a +& b)) 1214 val commitMoveVec = VecInit(io.commits.commitValid.zip(commitIsMove).map{ case (v, m) => v && m }) 1215 val commitLoadVec = VecInit(commitLoadValid) 1216 val commitBranchVec = VecInit(commitBranchValid) 1217 val commitLoadWaitVec = VecInit(commitLoadValid.zip(commitLoadWaitBit).map{ case (v, w) => v && w }) 1218 val commitStoreVec = VecInit(io.commits.commitValid.zip(commitIsStore).map{ case (v, t) => v && t }) 1219 val perfEvents = Seq( 1220 ("rob_interrupt_num ", io.flushOut.valid && intrEnable ), 1221 ("rob_exception_num ", io.flushOut.valid && exceptionEnable ), 1222 ("rob_flush_pipe_num ", io.flushOut.valid && isFlushPipe ), 1223 ("rob_replay_inst_num ", io.flushOut.valid && isFlushPipe && deqHasReplayInst ), 1224 ("rob_commitUop ", ifCommit(commitCnt) ), 1225 ("rob_commitInstr ", ifCommitReg(trueCommitCnt) ), 1226 ("rob_commitInstrMove ", ifCommitReg(PopCount(RegNext(commitMoveVec))) ), 1227 ("rob_commitInstrFused ", ifCommitReg(fuseCommitCnt) ), 1228 ("rob_commitInstrLoad ", ifCommitReg(PopCount(RegNext(commitLoadVec))) ), 1229 ("rob_commitInstrBranch ", ifCommitReg(PopCount(RegNext(commitBranchVec))) ), 1230 ("rob_commitInstrLoadWait", ifCommitReg(PopCount(RegNext(commitLoadWaitVec))) ), 1231 ("rob_commitInstrStore ", ifCommitReg(PopCount(RegNext(commitStoreVec))) ), 1232 ("rob_walkInstr ", Mux(io.commits.isWalk, PopCount(io.commits.walkValid), 0.U) ), 1233 ("rob_walkCycle ", (state === s_walk) ), 1234 ("rob_1_4_valid ", validEntries <= (RobSize / 4).U ), 1235 ("rob_2_4_valid ", validEntries > (RobSize / 4).U && validEntries <= (RobSize / 2).U ), 1236 ("rob_3_4_valid ", validEntries > (RobSize / 2).U && validEntries <= (RobSize * 3 / 4).U), 1237 ("rob_4_4_valid ", validEntries > (RobSize * 3 / 4).U ), 1238 ) 1239 generatePerfEvent() 1240} 1241