1package xiangshan.backend.issue 2 3import org.chipsalliance.cde.config.Parameters 4import chisel3._ 5import chisel3.util._ 6import freechips.rocketchip.diplomacy.{LazyModule, LazyModuleImp} 7import utility.{GTimer, HasCircularQueuePtrHelper, SelectOne} 8import utils._ 9import xiangshan._ 10import xiangshan.backend.Bundles._ 11import xiangshan.backend.decode.{ImmUnion, Imm_LUI_LOAD} 12import xiangshan.backend.datapath.DataConfig._ 13import xiangshan.backend.datapath.DataSource 14import xiangshan.backend.fu.{FuConfig, FuType} 15import xiangshan.mem.{MemWaitUpdateReq, SqPtr, LqPtr} 16import xiangshan.backend.rob.RobPtr 17import xiangshan.backend.datapath.NewPipelineConnect 18 19class IssueQueue(params: IssueBlockParams)(implicit p: Parameters) extends LazyModule with HasXSParameter { 20 override def shouldBeInlined: Boolean = false 21 22 implicit val iqParams = params 23 lazy val module: IssueQueueImp = iqParams.schdType match { 24 case IntScheduler() => new IssueQueueIntImp(this) 25 case VfScheduler() => new IssueQueueVfImp(this) 26 case MemScheduler() => 27 if (iqParams.StdCnt == 0 && !iqParams.isVecMemIQ) new IssueQueueMemAddrImp(this) 28 else if (iqParams.isVecMemIQ) new IssueQueueVecMemImp(this) 29 else new IssueQueueIntImp(this) 30 case _ => null 31 } 32} 33 34class IssueQueueStatusBundle(numEnq: Int, numEntries: Int) extends Bundle { 35 val empty = Output(Bool()) 36 val full = Output(Bool()) 37 val validCnt = Output(UInt(log2Ceil(numEntries).W)) 38 val leftVec = Output(Vec(numEnq + 1, Bool())) 39} 40 41class IssueQueueDeqRespBundle(implicit p:Parameters, params: IssueBlockParams) extends EntryDeqRespBundle 42 43class IssueQueueIO()(implicit p: Parameters, params: IssueBlockParams) extends XSBundle { 44 // Inputs 45 val flush = Flipped(ValidIO(new Redirect)) 46 val enq = Vec(params.numEnq, Flipped(DecoupledIO(new DynInst))) 47 48 val og0Resp = Vec(params.numDeq, Flipped(ValidIO(new IssueQueueDeqRespBundle))) 49 val og1Resp = Vec(params.numDeq, Flipped(ValidIO(new IssueQueueDeqRespBundle))) 50 val finalIssueResp = OptionWrapper(params.LdExuCnt > 0, Vec(params.LdExuCnt, Flipped(ValidIO(new IssueQueueDeqRespBundle)))) 51 val memAddrIssueResp = OptionWrapper(params.LdExuCnt > 0, Vec(params.LdExuCnt, Flipped(ValidIO(new IssueQueueDeqRespBundle)))) 52 val wbBusyTableRead = Input(params.genWbFuBusyTableReadBundle()) 53 val wbBusyTableWrite = Output(params.genWbFuBusyTableWriteBundle()) 54 val wakeupFromWB: MixedVec[ValidIO[IssueQueueWBWakeUpBundle]] = Flipped(params.genWBWakeUpSinkValidBundle) 55 val wakeupFromIQ: MixedVec[ValidIO[IssueQueueIQWakeUpBundle]] = Flipped(params.genIQWakeUpSinkValidBundle) 56 val og0Cancel = Input(ExuOH(backendParams.numExu)) 57 val og1Cancel = Input(ExuOH(backendParams.numExu)) 58 val ldCancel = Vec(backendParams.LduCnt + backendParams.HyuCnt, Flipped(new LoadCancelIO)) 59 val finalBlock = Vec(params.numExu, Input(Bool())) 60 61 // Outputs 62 val wakeupToIQ: MixedVec[ValidIO[IssueQueueIQWakeUpBundle]] = params.genIQWakeUpSourceValidBundle 63 val status = Output(new IssueQueueStatusBundle(params.numEnq, params.numEntries)) 64 // val statusNext = Output(new IssueQueueStatusBundle(params.numEnq)) 65 66 val deqDelay: MixedVec[DecoupledIO[IssueQueueIssueBundle]] = params.genIssueDecoupledBundle// = deq.cloneType 67 def allWakeUp = wakeupFromWB ++ wakeupFromIQ 68} 69 70class IssueQueueImp(override val wrapper: IssueQueue)(implicit p: Parameters, val params: IssueBlockParams) 71 extends LazyModuleImp(wrapper) 72 with HasXSParameter { 73 74 println(s"[IssueQueueImp] ${params.getIQName} wakeupFromWB(${io.wakeupFromWB.size}), " + 75 s"wakeup exu in(${params.wakeUpInExuSources.size}): ${params.wakeUpInExuSources.map(_.name).mkString("{",",","}")}, " + 76 s"wakeup exu out(${params.wakeUpOutExuSources.size}): ${params.wakeUpOutExuSources.map(_.name).mkString("{",",","}")}, " + 77 s"numEntries: ${params.numEntries}, numRegSrc: ${params.numRegSrc}") 78 79 require(params.numExu <= 2, "IssueQueue has not supported more than 2 deq ports") 80 val deqFuCfgs : Seq[Seq[FuConfig]] = params.exuBlockParams.map(_.fuConfigs) 81 val allDeqFuCfgs : Seq[FuConfig] = params.exuBlockParams.flatMap(_.fuConfigs) 82 val fuCfgsCnt : Map[FuConfig, Int] = allDeqFuCfgs.groupBy(x => x).map { case (cfg, cfgSeq) => (cfg, cfgSeq.length) } 83 val commonFuCfgs : Seq[FuConfig] = fuCfgsCnt.filter(_._2 > 1).keys.toSeq 84 val fuLatencyMaps : Seq[Map[FuType.OHType, Int]] = params.exuBlockParams.map(x => x.fuLatencyMap) 85 86 println(s"[IssueQueueImp] ${params.getIQName} fuLatencyMaps: ${fuLatencyMaps}") 87 println(s"[IssueQueueImp] ${params.getIQName} commonFuCfgs: ${commonFuCfgs.map(_.name)}") 88 lazy val io = IO(new IssueQueueIO()) 89 // Modules 90 91 val entries = Module(new Entries) 92 val fuBusyTableWrite = params.exuBlockParams.map { case x => OptionWrapper(x.latencyValMax > 0, Module(new FuBusyTableWrite(x.fuLatencyMap))) } 93 val fuBusyTableRead = params.exuBlockParams.map { case x => OptionWrapper(x.latencyValMax > 0, Module(new FuBusyTableRead(x.fuLatencyMap))) } 94 val intWbBusyTableWrite = params.exuBlockParams.map { case x => OptionWrapper(x.intLatencyCertain, Module(new FuBusyTableWrite(x.intFuLatencyMap))) } 95 val intWbBusyTableRead = params.exuBlockParams.map { case x => OptionWrapper(x.intLatencyCertain, Module(new FuBusyTableRead(x.intFuLatencyMap))) } 96 val vfWbBusyTableWrite = params.exuBlockParams.map { case x => OptionWrapper(x.vfLatencyCertain, Module(new FuBusyTableWrite(x.vfFuLatencyMap))) } 97 val vfWbBusyTableRead = params.exuBlockParams.map { case x => OptionWrapper(x.vfLatencyCertain, Module(new FuBusyTableRead(x.vfFuLatencyMap))) } 98 99 class WakeupQueueFlush extends Bundle { 100 val redirect = ValidIO(new Redirect) 101 val ldCancel = Vec(backendParams.LduCnt + backendParams.HyuCnt, new LoadCancelIO) 102 val og0Fail = Output(Bool()) 103 val og1Fail = Output(Bool()) 104 val finalFail = Output(Bool()) 105 } 106 107 private def flushFunc(exuInput: ExuInput, flush: WakeupQueueFlush, stage: Int): Bool = { 108 val redirectFlush = exuInput.robIdx.needFlush(flush.redirect) 109 val loadDependencyFlush = LoadShouldCancel(exuInput.loadDependency, flush.ldCancel) 110 val ogFailFlush = stage match { 111 case 1 => flush.og0Fail 112 case 2 => flush.og1Fail 113 case 3 => flush.finalFail 114 case _ => false.B 115 } 116 redirectFlush || loadDependencyFlush || ogFailFlush 117 } 118 119 private def modificationFunc(exuInput: ExuInput): ExuInput = { 120 val newExuInput = WireDefault(exuInput) 121 newExuInput.loadDependency match { 122 case Some(deps) => deps.zip(exuInput.loadDependency.get).foreach(x => x._1 := x._2 << 1) 123 case None => 124 } 125 newExuInput 126 } 127 128 val wakeUpQueues: Seq[Option[MultiWakeupQueue[ExuInput, WakeupQueueFlush]]] = params.exuBlockParams.map { x => OptionWrapper(x.isIQWakeUpSource, Module( 129 new MultiWakeupQueue(new ExuInput(x), new WakeupQueueFlush, x.fuLatancySet, flushFunc, modificationFunc) 130 ))} 131 val deqBeforeDly = Wire(params.genIssueDecoupledBundle) 132 133 val intWbBusyTableIn = io.wbBusyTableRead.map(_.intWbBusyTable) 134 val vfWbBusyTableIn = io.wbBusyTableRead.map(_.vfWbBusyTable) 135 val intWbBusyTableOut = io.wbBusyTableWrite.map(_.intWbBusyTable) 136 val vfWbBusyTableOut = io.wbBusyTableWrite.map(_.vfWbBusyTable) 137 val intDeqRespSetOut = io.wbBusyTableWrite.map(_.intDeqRespSet) 138 val vfDeqRespSetOut = io.wbBusyTableWrite.map(_.vfDeqRespSet) 139 val fuBusyTableMask = Wire(Vec(params.numDeq, UInt(params.numEntries.W))) 140 val intWbBusyTableMask = Wire(Vec(params.numDeq, UInt(params.numEntries.W))) 141 val vfWbBusyTableMask = Wire(Vec(params.numDeq, UInt(params.numEntries.W))) 142 val s0_enqValidVec = io.enq.map(_.valid) 143 val s0_enqSelValidVec = Wire(Vec(params.numEnq, Bool())) 144 val s0_enqNotFlush = !io.flush.valid 145 val s0_enqBits = WireInit(VecInit(io.enq.map(_.bits))) 146 val s0_doEnqSelValidVec = s0_enqSelValidVec.map(_ && s0_enqNotFlush) //enqValid && notFlush && enqReady 147 148 149 val finalDeqSelValidVec = Wire(Vec(params.numDeq, Bool())) 150 val finalDeqSelOHVec = Wire(Vec(params.numDeq, UInt(params.numEntries.W))) 151 152 val validVec = VecInit(entries.io.valid.asBools) 153 val canIssueVec = VecInit(entries.io.canIssue.asBools) 154 val clearVec = VecInit(entries.io.clear.asBools) 155 val deqFirstIssueVec = VecInit(entries.io.deq.map(_.isFirstIssue)) 156 157 val dataSources: Vec[Vec[DataSource]] = entries.io.dataSources 158 val finalDataSources: Vec[Vec[DataSource]] = VecInit(finalDeqSelOHVec.map(oh => Mux1H(oh, dataSources))) 159 // (entryIdx)(srcIdx)(exuIdx) 160 val wakeUpL1ExuOH: Option[Vec[Vec[UInt]]] = entries.io.srcWakeUpL1ExuOH 161 val srcTimer: Option[Vec[Vec[UInt]]] = entries.io.srcTimer 162 163 // (deqIdx)(srcIdx)(exuIdx) 164 val finalWakeUpL1ExuOH: Option[Vec[Vec[UInt]]] = wakeUpL1ExuOH.map(x => VecInit(finalDeqSelOHVec.map(oh => Mux1H(oh, x)))) 165 val finalSrcTimer = srcTimer.map(x => VecInit(finalDeqSelOHVec.map(oh => Mux1H(oh, x)))) 166 167 val wakeupEnqSrcStateBypassFromWB: Vec[Vec[UInt]] = Wire(Vec(io.enq.size, Vec(io.enq.head.bits.srcType.size, SrcState()))) 168 val wakeupEnqSrcStateBypassFromIQ: Vec[Vec[UInt]] = Wire(Vec(io.enq.size, Vec(io.enq.head.bits.srcType.size, SrcState()))) 169 val srcWakeUpEnqByIQMatrix = Wire(Vec(params.numEnq, Vec(params.numRegSrc, Vec(params.numWakeupFromIQ, Bool())))) 170 171 val shiftedWakeupLoadDependencyByIQVec = Wire(Vec(params.numWakeupFromIQ, Vec(LoadPipelineWidth, UInt(3.W)))) 172 shiftedWakeupLoadDependencyByIQVec 173 .zip(io.wakeupFromIQ.map(_.bits.loadDependency)) 174 .zip(params.wakeUpInExuSources.map(_.name)).foreach { 175 case ((deps, originalDeps), name) => deps.zip(originalDeps).zipWithIndex.foreach { 176 case ((dep, originalDep), deqPortIdx) => 177 if (params.backendParam.getLdExuIdx(params.backendParam.allExuParams.find(_.name == name).get) == deqPortIdx) 178 dep := (originalDep << 2).asUInt | 2.U 179 else 180 dep := originalDep << 1 181 } 182 } 183 184 for (i <- io.enq.indices) { 185 for (j <- s0_enqBits(i).srcType.indices) { 186 wakeupEnqSrcStateBypassFromWB(i)(j) := Cat( 187 io.wakeupFromWB.map(x => x.bits.wakeUp(Seq((s0_enqBits(i).psrc(j), s0_enqBits(i).srcType(j))), x.valid).head).toSeq 188 ).orR 189 } 190 } 191 192 for (i <- io.enq.indices) { 193 val numLsrc = s0_enqBits(i).srcType.size.min(entries.io.enq(i).bits.status.srcType.size) 194 for (j <- s0_enqBits(i).srcType.indices) { 195 val ldTransCancel = if (params.numWakeupFromIQ > 0 && j < numLsrc) Mux( 196 srcWakeUpEnqByIQMatrix(i)(j).asUInt.orR, 197 Mux1H(srcWakeUpEnqByIQMatrix(i)(j), io.wakeupFromIQ.map(_.bits.loadDependency).map(dep => LoadShouldCancel(Some(dep), io.ldCancel)).toSeq), 198 false.B 199 ) else false.B 200 if (params.numWakeupFromIQ > 0 && j < numLsrc) { 201 wakeupEnqSrcStateBypassFromIQ(i)(j) := srcWakeUpEnqByIQMatrix(i)(j).asUInt.orR && !ldTransCancel 202 } else { 203 wakeupEnqSrcStateBypassFromIQ(i)(j) := false.B 204 } 205 } 206 } 207 208 srcWakeUpEnqByIQMatrix.zipWithIndex.foreach { case (wakeups: Vec[Vec[Bool]], i) => 209 if (io.wakeupFromIQ.isEmpty) { 210 wakeups := 0.U.asTypeOf(wakeups) 211 } else { 212 val wakeupVec: IndexedSeq[IndexedSeq[Bool]] = io.wakeupFromIQ.map((bundle: ValidIO[IssueQueueIQWakeUpBundle]) => 213 bundle.bits.wakeUp(s0_enqBits(i).psrc.take(params.numRegSrc) zip s0_enqBits(i).srcType.take(params.numRegSrc), bundle.valid) 214 ).toIndexedSeq.transpose 215 val cancelSel = io.wakeupFromIQ.map(x => x.bits.exuIdx).map(x => io.og0Cancel(x)) 216 wakeups := wakeupVec.map(x => VecInit(x.zip(cancelSel).map { case (wakeup, cancel) => wakeup && !cancel })) 217 } 218 } 219 220 val fuTypeVec = Wire(Vec(params.numEntries, FuType())) 221 val transEntryDeqVec = Wire(Vec(params.numEnq, ValidIO(new EntryBundle))) 222 val deqEntryVec = Wire(Vec(params.numDeq, ValidIO(new EntryBundle))) 223 val transSelVec = Wire(Vec(params.numEnq, UInt((params.numEntries-params.numEnq).W))) 224 val canIssueMergeAllBusy = Wire(Vec(params.numDeq, UInt(params.numEntries.W))) 225 val deqCanIssue = Wire(Vec(params.numDeq, UInt(params.numEntries.W))) 226 227 val enqEntryOldestSel = Wire(Vec(params.numDeq, ValidIO(UInt(params.numEnq.W)))) 228 val othersEntryOldestSel = Wire(Vec(params.numDeq, ValidIO(UInt((params.numEntries - params.numEnq).W)))) 229 val deqSelValidVec = Wire(Vec(params.numDeq, Bool())) 230 val deqSelOHVec = Wire(Vec(params.numDeq, UInt(params.numEntries.W))) 231 val cancelDeqVec = Wire(Vec(params.numDeq, Bool())) 232 233 val subDeqSelValidVec = OptionWrapper(params.deqFuSame, Wire(Vec(params.numDeq, Bool()))) 234 val subDeqSelOHVec = OptionWrapper(params.deqFuSame, Wire(Vec(params.numDeq, UInt(params.numEntries.W)))) 235 val subDeqRequest = OptionWrapper(params.deqFuSame, Wire(UInt(params.numEntries.W))) 236 237 /** 238 * Connection of [[entries]] 239 */ 240 entries.io match { case entriesIO: EntriesIO => 241 entriesIO.flush <> io.flush 242 entriesIO.wakeUpFromWB := io.wakeupFromWB 243 entriesIO.wakeUpFromIQ := io.wakeupFromIQ 244 entriesIO.og0Cancel := io.og0Cancel 245 entriesIO.og1Cancel := io.og1Cancel 246 entriesIO.ldCancel := io.ldCancel 247 entriesIO.enq.zipWithIndex.foreach { case (enq: ValidIO[EntryBundle], i) => 248 enq.valid := s0_doEnqSelValidVec(i) 249 val numLsrc = s0_enqBits(i).srcType.size.min(enq.bits.status.srcType.size) 250 for(j <- 0 until numLsrc) { 251 enq.bits.status.srcState(j) := s0_enqBits(i).srcState(j) | 252 wakeupEnqSrcStateBypassFromWB(i)(j) | 253 wakeupEnqSrcStateBypassFromIQ(i)(j) 254 enq.bits.status.psrc(j) := s0_enqBits(i).psrc(j) 255 enq.bits.status.srcType(j) := s0_enqBits(i).srcType(j) 256 enq.bits.status.dataSources(j).value := Mux(wakeupEnqSrcStateBypassFromIQ(i)(j).asBool, DataSource.bypass, DataSource.reg) 257 enq.bits.payload.debugInfo.enqRsTime := GTimer() 258 } 259 enq.bits.status.fuType := s0_enqBits(i).fuType 260 enq.bits.status.robIdx := s0_enqBits(i).robIdx 261 enq.bits.status.uopIdx.foreach(_ := s0_enqBits(i).uopIdx) 262 enq.bits.status.issueTimer := "b10".U 263 enq.bits.status.deqPortIdx := 0.U 264 enq.bits.status.issued := false.B 265 enq.bits.status.firstIssue := false.B 266 enq.bits.status.blocked := false.B 267 enq.bits.status.srcWakeUpL1ExuOH match { 268 case Some(value) => value.zip(srcWakeUpEnqByIQMatrix(i)).zipWithIndex.foreach { 269 case ((exuOH, wakeUpByIQOH), srcIdx) => 270 when(wakeUpByIQOH.asUInt.orR) { 271 exuOH := Mux1H(wakeUpByIQOH, io.wakeupFromIQ.toSeq.map(x => MathUtils.IntToOH(x.bits.exuIdx).U(backendParams.numExu.W))) 272 }.otherwise { 273 exuOH := 0.U.asTypeOf(exuOH) 274 } 275 } 276 case None => 277 } 278 enq.bits.status.srcTimer match { 279 case Some(value) => value.zip(srcWakeUpEnqByIQMatrix(i)).zipWithIndex.foreach { 280 case ((timer, wakeUpByIQOH), srcIdx) => 281 when(wakeUpByIQOH.asUInt.orR) { 282 timer := 2.U.asTypeOf(timer) 283 }.otherwise { 284 timer := 3.U.asTypeOf(timer) 285 } 286 } 287 case None => 288 } 289 enq.bits.status.srcLoadDependency.foreach(_.zip(srcWakeUpEnqByIQMatrix(i)).zipWithIndex.foreach { 290 case ((dep, wakeUpByIQOH), srcIdx) => 291 dep := Mux(wakeUpByIQOH.asUInt.orR, Mux1H(wakeUpByIQOH, shiftedWakeupLoadDependencyByIQVec), 0.U.asTypeOf(dep)) 292 }) 293 enq.bits.imm := s0_enqBits(i).imm 294 enq.bits.payload := s0_enqBits(i) 295 } 296 entriesIO.deq.zipWithIndex.foreach { case (deq, i) => 297 deq.enqEntryOldestSel := enqEntryOldestSel(i) 298 deq.othersEntryOldestSel := othersEntryOldestSel(i) 299 deq.subDeqRequest.foreach(_ := subDeqRequest.get) 300 deq.subDeqSelOH.foreach(_ := subDeqSelOHVec.get(i)) 301 deq.deqReady := deqBeforeDly(i).ready 302 deq.deqSelOH.valid := deqSelValidVec(i) 303 deq.deqSelOH.bits := deqSelOHVec(i) 304 } 305 entriesIO.og0Resp.zipWithIndex.foreach { case (og0Resp, i) => 306 og0Resp.valid := io.og0Resp(i).valid 307 og0Resp.bits.robIdx := io.og0Resp(i).bits.robIdx 308 og0Resp.bits.uopIdx := io.og0Resp(i).bits.uopIdx 309 og0Resp.bits.dataInvalidSqIdx := io.og0Resp(i).bits.dataInvalidSqIdx 310 og0Resp.bits.respType := io.og0Resp(i).bits.respType 311 og0Resp.bits.rfWen := io.og0Resp(i).bits.rfWen 312 og0Resp.bits.fuType := io.og0Resp(i).bits.fuType 313 } 314 entriesIO.og1Resp.zipWithIndex.foreach { case (og1Resp, i) => 315 og1Resp.valid := io.og1Resp(i).valid 316 og1Resp.bits.robIdx := io.og1Resp(i).bits.robIdx 317 og1Resp.bits.uopIdx := io.og1Resp(i).bits.uopIdx 318 og1Resp.bits.dataInvalidSqIdx := io.og1Resp(i).bits.dataInvalidSqIdx 319 og1Resp.bits.respType := io.og1Resp(i).bits.respType 320 og1Resp.bits.rfWen := io.og1Resp(i).bits.rfWen 321 og1Resp.bits.fuType := io.og1Resp(i).bits.fuType 322 } 323 entriesIO.finalIssueResp.foreach(_.zipWithIndex.foreach { case (finalIssueResp, i) => 324 finalIssueResp := io.finalIssueResp.get(i) 325 }) 326 entriesIO.memAddrIssueResp.foreach(_.zipWithIndex.foreach { case (memAddrIssueResp, i) => 327 memAddrIssueResp := io.memAddrIssueResp.get(i) 328 }) 329 transEntryDeqVec := entriesIO.transEntryDeqVec 330 deqEntryVec := entriesIO.deq.map(_.deqEntry) 331 fuTypeVec := entriesIO.fuType 332 cancelDeqVec := entriesIO.cancelDeqVec 333 transSelVec := entriesIO.transSelVec 334 } 335 336 337 s0_enqSelValidVec := s0_enqValidVec.zip(io.enq).map{ case (enqValid, enq) => enqValid && enq.ready} 338 339 protected val commonAccept: UInt = Cat(fuTypeVec.map(fuType => 340 FuType.FuTypeOrR(fuType, commonFuCfgs.map(_.fuType)) 341 ).reverse) 342 343 // if deq port can accept the uop 344 protected val canAcceptVec: Seq[UInt] = deqFuCfgs.map { fuCfgs: Seq[FuConfig] => 345 Cat(fuTypeVec.map(fuType => 346 FuType.FuTypeOrR(fuType, fuCfgs.map(_.fuType)) 347 ).reverse) 348 } 349 350 protected val deqCanAcceptVec: Seq[IndexedSeq[Bool]] = deqFuCfgs.map { fuCfgs: Seq[FuConfig] => 351 fuTypeVec.map(fuType => 352 FuType.FuTypeOrR(fuType, fuCfgs.map(_.fuType))) 353 } 354 355 canIssueMergeAllBusy.zipWithIndex.foreach { case (merge, i) => 356 val mergeFuBusy = { 357 if (fuBusyTableWrite(i).nonEmpty) canIssueVec.asUInt & (~fuBusyTableMask(i)) 358 else canIssueVec.asUInt 359 } 360 val mergeIntWbBusy = { 361 if (intWbBusyTableRead(i).nonEmpty) mergeFuBusy & (~intWbBusyTableMask(i)) 362 else mergeFuBusy 363 } 364 val mergeVfWbBusy = { 365 if (vfWbBusyTableRead(i).nonEmpty) mergeIntWbBusy & (~vfWbBusyTableMask(i)) 366 else mergeIntWbBusy 367 } 368 merge := mergeVfWbBusy 369 } 370 371 deqCanIssue.zipWithIndex.foreach { case (req, i) => 372 req := canIssueMergeAllBusy(i) & VecInit(deqCanAcceptVec(i)).asUInt 373 } 374 375 if (params.numDeq == 2) { 376 require(params.deqFuSame || params.deqFuDiff, "The 2 deq ports need to be identical or completely different") 377 } 378 379 if (params.numDeq == 2 && params.deqFuSame) { 380 enqEntryOldestSel := DontCare 381 382 othersEntryOldestSel(0) := AgeDetector(numEntries = params.numEntries - params.numEnq, 383 enq = VecInit(transEntryDeqVec.zip(transSelVec).map{ case (transEntry, transSel) => Fill(params.numEntries-params.numEnq, transEntry.valid) & transSel }), 384 canIssue = canIssueVec.asUInt(params.numEntries-1, params.numEnq) 385 ) 386 othersEntryOldestSel(1) := DontCare 387 388 subDeqRequest.get := canIssueVec.asUInt & ~Cat(othersEntryOldestSel(0).bits, 0.U((params.numEnq).W)) 389 390 val subDeqPolicy = Module(new DeqPolicy()) 391 subDeqPolicy.io.request := subDeqRequest.get 392 subDeqSelValidVec.get := subDeqPolicy.io.deqSelOHVec.map(oh => oh.valid) 393 subDeqSelOHVec.get := subDeqPolicy.io.deqSelOHVec.map(oh => oh.bits) 394 395 deqSelValidVec(0) := othersEntryOldestSel(0).valid || subDeqSelValidVec.get(1) 396 deqSelValidVec(1) := subDeqSelValidVec.get(0) 397 deqSelOHVec(0) := Mux(othersEntryOldestSel(0).valid, 398 Cat(othersEntryOldestSel(0).bits, 0.U((params.numEnq).W)), 399 subDeqSelOHVec.get(1)) & canIssueMergeAllBusy(0) 400 deqSelOHVec(1) := subDeqSelOHVec.get(0) & canIssueMergeAllBusy(1) 401 402 finalDeqSelValidVec.zip(finalDeqSelOHVec).zip(deqSelValidVec).zip(deqSelOHVec).zipWithIndex.foreach { case ((((selValid, selOH), deqValid), deqOH), i) => 403 selValid := deqValid && deqOH.orR && deqBeforeDly(i).ready 404 selOH := deqOH 405 } 406 } 407 else { 408 enqEntryOldestSel := NewAgeDetector(numEntries = params.numEnq, 409 enq = VecInit(s0_doEnqSelValidVec), 410 canIssue = VecInit(deqCanIssue.map(_(params.numEnq-1, 0))) 411 ) 412 413 othersEntryOldestSel := AgeDetector(numEntries = params.numEntries - params.numEnq, 414 enq = VecInit(transEntryDeqVec.zip(transSelVec).map{ case (transEntry, transSel) => Fill(params.numEntries-params.numEnq, transEntry.valid) & transSel }), 415 canIssue = VecInit(deqCanIssue.map(_(params.numEntries-1, params.numEnq))) 416 ) 417 418 deqSelValidVec.zip(deqSelOHVec).zipWithIndex.foreach { case ((selValid, selOH), i) => 419 if (params.exuBlockParams(i).fuConfigs.contains(FuConfig.FakeHystaCfg)) { 420 selValid := false.B 421 selOH := 0.U.asTypeOf(selOH) 422 } else { 423 selValid := othersEntryOldestSel(i).valid || enqEntryOldestSel(i).valid 424 selOH := Cat(othersEntryOldestSel(i).bits, Fill(params.numEnq, enqEntryOldestSel(i).valid && !othersEntryOldestSel(i).valid) & enqEntryOldestSel(i).bits) 425 } 426 } 427 428 finalDeqSelValidVec.zip(finalDeqSelOHVec).zip(deqSelValidVec).zip(deqSelOHVec).zipWithIndex.foreach { case ((((selValid, selOH), deqValid), deqOH), i) => 429 selValid := deqValid && deqBeforeDly(i).ready 430 selOH := deqOH 431 } 432 } 433 434 val toBusyTableDeqResp = Wire(Vec(params.numDeq, ValidIO(new IssueQueueDeqRespBundle))) 435 436 toBusyTableDeqResp.zipWithIndex.foreach { case (deqResp, i) => 437 deqResp.valid := finalDeqSelValidVec(i) 438 deqResp.bits.respType := RSFeedbackType.issueSuccess 439 deqResp.bits.robIdx := DontCare 440 deqResp.bits.dataInvalidSqIdx := DontCare 441 deqResp.bits.rfWen := DontCare 442 deqResp.bits.fuType := deqBeforeDly(i).bits.common.fuType 443 deqResp.bits.uopIdx := DontCare 444 } 445 446 //fuBusyTable 447 fuBusyTableWrite.zip(fuBusyTableRead).zipWithIndex.foreach { case ((busyTableWrite: Option[FuBusyTableWrite], busyTableRead: Option[FuBusyTableRead]), i) => 448 if(busyTableWrite.nonEmpty) { 449 val btwr = busyTableWrite.get 450 val btrd = busyTableRead.get 451 btwr.io.in.deqResp := toBusyTableDeqResp(i) 452 btwr.io.in.og0Resp := io.og0Resp(i) 453 btwr.io.in.og1Resp := io.og1Resp(i) 454 btrd.io.in.fuBusyTable := btwr.io.out.fuBusyTable 455 btrd.io.in.fuTypeRegVec := fuTypeVec 456 fuBusyTableMask(i) := btrd.io.out.fuBusyTableMask 457 } 458 else { 459 fuBusyTableMask(i) := 0.U(params.numEntries.W) 460 } 461 } 462 463 //wbfuBusyTable write 464 intWbBusyTableWrite.zip(intWbBusyTableOut).zip(intDeqRespSetOut).zipWithIndex.foreach { case (((busyTableWrite: Option[FuBusyTableWrite], busyTable: Option[UInt]), deqResp), i) => 465 if(busyTableWrite.nonEmpty) { 466 val btwr = busyTableWrite.get 467 val bt = busyTable.get 468 val dq = deqResp.get 469 btwr.io.in.deqResp := toBusyTableDeqResp(i) 470 btwr.io.in.og0Resp := io.og0Resp(i) 471 btwr.io.in.og1Resp := io.og1Resp(i) 472 bt := btwr.io.out.fuBusyTable 473 dq := btwr.io.out.deqRespSet 474 } 475 } 476 477 vfWbBusyTableWrite.zip(vfWbBusyTableOut).zip(vfDeqRespSetOut).zipWithIndex.foreach { case (((busyTableWrite: Option[FuBusyTableWrite], busyTable: Option[UInt]), deqResp), i) => 478 if (busyTableWrite.nonEmpty) { 479 val btwr = busyTableWrite.get 480 val bt = busyTable.get 481 val dq = deqResp.get 482 btwr.io.in.deqResp := toBusyTableDeqResp(i) 483 btwr.io.in.og0Resp := io.og0Resp(i) 484 btwr.io.in.og1Resp := io.og1Resp(i) 485 bt := btwr.io.out.fuBusyTable 486 dq := btwr.io.out.deqRespSet 487 } 488 } 489 490 //wbfuBusyTable read 491 intWbBusyTableRead.zip(intWbBusyTableIn).zipWithIndex.foreach { case ((busyTableRead: Option[FuBusyTableRead], busyTable: Option[UInt]), i) => 492 if(busyTableRead.nonEmpty) { 493 val btrd = busyTableRead.get 494 val bt = busyTable.get 495 btrd.io.in.fuBusyTable := bt 496 btrd.io.in.fuTypeRegVec := fuTypeVec 497 intWbBusyTableMask(i) := btrd.io.out.fuBusyTableMask 498 } 499 else { 500 intWbBusyTableMask(i) := 0.U(params.numEntries.W) 501 } 502 } 503 vfWbBusyTableRead.zip(vfWbBusyTableIn).zipWithIndex.foreach { case ((busyTableRead: Option[FuBusyTableRead], busyTable: Option[UInt]), i) => 504 if (busyTableRead.nonEmpty) { 505 val btrd = busyTableRead.get 506 val bt = busyTable.get 507 btrd.io.in.fuBusyTable := bt 508 btrd.io.in.fuTypeRegVec := fuTypeVec 509 vfWbBusyTableMask(i) := btrd.io.out.fuBusyTableMask 510 } 511 else { 512 vfWbBusyTableMask(i) := 0.U(params.numEntries.W) 513 } 514 } 515 516 wakeUpQueues.zipWithIndex.foreach { case (wakeUpQueueOption, i) => 517 val og0RespEach = io.og0Resp(i) 518 val og1RespEach = io.og1Resp(i) 519 wakeUpQueueOption.foreach { 520 wakeUpQueue => 521 val flush = Wire(new WakeupQueueFlush) 522 flush.redirect := io.flush 523 flush.ldCancel := io.ldCancel 524 flush.og0Fail := io.og0Resp(i).valid && RSFeedbackType.isBlocked(io.og0Resp(i).bits.respType) 525 flush.og1Fail := io.og1Resp(i).valid && RSFeedbackType.isBlocked(io.og1Resp(i).bits.respType) 526 flush.finalFail := io.finalBlock(i) 527 wakeUpQueue.io.flush := flush 528 wakeUpQueue.io.enq.valid := deqBeforeDly(i).fire && { 529 deqBeforeDly(i).bits.common.rfWen.getOrElse(false.B) && deqBeforeDly(i).bits.common.pdest =/= 0.U || 530 deqBeforeDly(i).bits.common.fpWen.getOrElse(false.B) || 531 deqBeforeDly(i).bits.common.vecWen.getOrElse(false.B) 532 } 533 wakeUpQueue.io.enq.bits.uop := deqBeforeDly(i).bits.common 534 wakeUpQueue.io.enq.bits.lat := getDeqLat(i, deqBeforeDly(i).bits.common.fuType) 535 wakeUpQueue.io.og0IssueFail := flush.og0Fail 536 wakeUpQueue.io.og1IssueFail := flush.og1Fail 537 } 538 } 539 540 deqBeforeDly.zipWithIndex.foreach { case (deq, i) => 541 deq.valid := finalDeqSelValidVec(i) && !cancelDeqVec(i) 542 deq.bits.addrOH := finalDeqSelOHVec(i) 543 deq.bits.common.isFirstIssue := deqFirstIssueVec(i) 544 deq.bits.common.iqIdx := OHToUInt(finalDeqSelOHVec(i)) 545 deq.bits.common.fuType := deqEntryVec(i).bits.payload.fuType 546 deq.bits.common.fuOpType := deqEntryVec(i).bits.payload.fuOpType 547 deq.bits.common.rfWen.foreach(_ := deqEntryVec(i).bits.payload.rfWen) 548 deq.bits.common.fpWen.foreach(_ := deqEntryVec(i).bits.payload.fpWen) 549 deq.bits.common.vecWen.foreach(_ := deqEntryVec(i).bits.payload.vecWen) 550 deq.bits.common.flushPipe.foreach(_ := deqEntryVec(i).bits.payload.flushPipe) 551 deq.bits.common.pdest := deqEntryVec(i).bits.payload.pdest 552 deq.bits.common.robIdx := deqEntryVec(i).bits.payload.robIdx 553 deq.bits.common.dataSources.zip(finalDataSources(i)).zipWithIndex.foreach { 554 case ((sink, source), srcIdx) => 555 sink.value := Mux( 556 SrcType.isXp(deqEntryVec(i).bits.payload.srcType(srcIdx)) && deqEntryVec(i).bits.payload.psrc(srcIdx) === 0.U, 557 DataSource.none, 558 source.value 559 ) 560 } 561 deq.bits.common.l1ExuOH.foreach(_ := finalWakeUpL1ExuOH.get(i)) 562 deq.bits.common.srcTimer.foreach(_ := finalSrcTimer.get(i)) 563 deq.bits.common.loadDependency.foreach(_ := deqEntryVec(i).bits.status.mergedLoadDependency.get) 564 deq.bits.common.deqLdExuIdx.foreach(_ := params.backendParam.getLdExuIdx(deq.bits.exuParams).U) 565 deq.bits.common.src := DontCare 566 deq.bits.common.preDecode.foreach(_ := deqEntryVec(i).bits.payload.preDecodeInfo) 567 568 deq.bits.rf.zip(deqEntryVec(i).bits.payload.psrc).foreach { case (rf, psrc) => 569 rf.foreach(_.addr := psrc) // psrc in payload array can be pregIdx of IntRegFile or VfRegFile 570 } 571 deq.bits.rf.zip(deqEntryVec(i).bits.payload.srcType).foreach { case (rf, srcType) => 572 rf.foreach(_.srcType := srcType) // psrc in payload array can be pregIdx of IntRegFile or VfRegFile 573 } 574 deq.bits.srcType.zip(deqEntryVec(i).bits.payload.srcType).foreach { case (sink, source) => 575 sink := source 576 } 577 deq.bits.immType := deqEntryVec(i).bits.payload.selImm 578 579 if (params.inIntSchd && params.AluCnt > 0) { 580 // dirty code for lui+addi(w) fusion 581 val isLuiAddiFusion = deqEntryVec(i).bits.payload.isLUI32 582 val luiImm = Cat(deqEntryVec(i).bits.payload.lsrc(1), deqEntryVec(i).bits.payload.lsrc(0), deqEntryVec(i).bits.imm(ImmUnion.maxLen - 1, 0)) 583 deq.bits.common.imm := Mux(isLuiAddiFusion, ImmUnion.LUI32.toImm32(luiImm), deqEntryVec(i).bits.imm) 584 } 585 else if (params.inMemSchd && params.LduCnt > 0) { 586 // dirty code for fused_lui_load 587 val isLuiLoadFusion = SrcType.isNotReg(deqEntryVec(i).bits.payload.srcType(0)) && FuType.isLoad(deqEntryVec(i).bits.payload.fuType) 588 deq.bits.common.imm := Mux(isLuiLoadFusion, Imm_LUI_LOAD().getLuiImm(deqEntryVec(i).bits.payload), deqEntryVec(i).bits.imm) 589 } 590 else { 591 deq.bits.common.imm := deqEntryVec(i).bits.imm 592 } 593 594 deq.bits.common.perfDebugInfo := deqEntryVec(i).bits.payload.debugInfo 595 deq.bits.common.perfDebugInfo.selectTime := GTimer() 596 deq.bits.common.perfDebugInfo.issueTime := GTimer() + 1.U 597 } 598 599 private val ldCancels = deqBeforeDly.map(in => 600 LoadShouldCancel(in.bits.common.loadDependency, io.ldCancel) 601 ) 602 private val deqShift = WireDefault(deqBeforeDly) 603 deqShift.zip(deqBeforeDly).foreach { 604 case (shifted, original) => 605 original.ready := shifted.ready // this will not cause combinational loop 606 shifted.bits.common.loadDependency.foreach( 607 _ := original.bits.common.loadDependency.get.map(_ << 1) 608 ) 609 } 610 io.deqDelay.zip(deqShift).zip(ldCancels).foreach { case ((deqDly, deq), ldCancel) => 611 NewPipelineConnect( 612 deq, deqDly, deqDly.valid, 613 deq.bits.common.robIdx.needFlush(io.flush) || ldCancel, 614 Option("Scheduler2DataPathPipe") 615 ) 616 } 617 if(backendParams.debugEn) { 618 dontTouch(io.deqDelay) 619 } 620 io.wakeupToIQ.zipWithIndex.foreach { case (wakeup, i) => 621 if (wakeUpQueues(i).nonEmpty && finalWakeUpL1ExuOH.nonEmpty) { 622 wakeup.valid := wakeUpQueues(i).get.io.deq.valid 623 wakeup.bits.fromExuInput(wakeUpQueues(i).get.io.deq.bits, finalWakeUpL1ExuOH.get(i)) 624 wakeup.bits.loadDependency := wakeUpQueues(i).get.io.deq.bits.loadDependency.getOrElse(0.U.asTypeOf(wakeup.bits.loadDependency)) 625 } else if (wakeUpQueues(i).nonEmpty) { 626 wakeup.valid := wakeUpQueues(i).get.io.deq.valid 627 wakeup.bits.fromExuInput(wakeUpQueues(i).get.io.deq.bits) 628 wakeup.bits.loadDependency := wakeUpQueues(i).get.io.deq.bits.loadDependency.getOrElse(0.U.asTypeOf(wakeup.bits.loadDependency)) 629 } else { 630 wakeup.valid := false.B 631 wakeup.bits := 0.U.asTypeOf(wakeup.bits) 632 } 633 } 634 635 // Todo: better counter implementation 636 private val enqHasValid = validVec.take(params.numEnq).reduce(_ | _) 637 private val enqEntryValidCnt = PopCount(validVec.take(params.numEnq)) 638 private val othersValidCnt = PopCount(validVec.drop(params.numEnq)) 639 io.status.leftVec(0) := validVec.drop(params.numEnq).reduce(_ & _) 640 for (i <- 0 until params.numEnq) { 641 io.status.leftVec(i + 1) := othersValidCnt === (params.numEntries - params.numEnq - (i + 1)).U 642 } 643 private val othersLeftOneCaseVec = Wire(Vec(params.numEntries - params.numEnq, UInt((params.numEntries - params.numEnq).W))) 644 othersLeftOneCaseVec.zipWithIndex.foreach { case (leftone, i) => 645 leftone := ~(1.U((params.numEntries - params.numEnq).W) << i) 646 } 647 private val othersLeftOne = othersLeftOneCaseVec.map(_ === VecInit(validVec.drop(params.numEnq)).asUInt).reduce(_ | _) 648 private val othersCanotIn = othersLeftOne || validVec.drop(params.numEnq).reduce(_ & _) 649 650 io.enq.foreach(_.ready := !othersCanotIn || !enqHasValid) 651 io.status.empty := !Cat(validVec).orR 652 io.status.full := othersCanotIn 653 io.status.validCnt := PopCount(validVec) 654 655 protected def getDeqLat(deqPortIdx: Int, fuType: UInt) : UInt = { 656 Mux1H(fuLatencyMaps(deqPortIdx) map { case (k, v) => (fuType(k.id), v.U) }) 657 } 658 659 // issue perf counter 660 // enq count 661 XSPerfAccumulate("enq_valid_cnt", PopCount(io.enq.map(_.fire))) 662 XSPerfAccumulate("enq_fire_cnt", PopCount(io.enq.map(_.fire))) 663 // valid count 664 XSPerfHistogram("enq_entry_valid_cnt", enqEntryValidCnt, true.B, 0, params.numEnq + 1) 665 XSPerfHistogram("other_entry_valid_cnt", othersValidCnt, true.B, 0, params.numEntries - params.numEnq + 1) 666 XSPerfHistogram("valid_cnt", PopCount(validVec), true.B, 0, params.numEntries + 1) 667 // only split when more than 1 func type 668 if (params.getFuCfgs.size > 0) { 669 for (t <- FuType.functionNameMap.keys) { 670 val fuName = FuType.functionNameMap(t) 671 if (params.getFuCfgs.map(_.fuType == t).reduce(_ | _)) { 672 XSPerfHistogram(s"valid_cnt_hist_futype_${fuName}", PopCount(validVec.zip(fuTypeVec).map { case (v, fu) => v && fu === t.U }), true.B, 0, params.numEntries, 1) 673 } 674 } 675 } 676 // ready instr count 677 private val readyEntriesCnt = PopCount(validVec.zip(canIssueVec).map(x => x._1 && x._2)) 678 XSPerfHistogram("ready_cnt", readyEntriesCnt, true.B, 0, params.numEntries + 1) 679 // only split when more than 1 func type 680 if (params.getFuCfgs.size > 0) { 681 for (t <- FuType.functionNameMap.keys) { 682 val fuName = FuType.functionNameMap(t) 683 if (params.getFuCfgs.map(_.fuType == t).reduce(_ | _)) { 684 XSPerfHistogram(s"ready_cnt_hist_futype_${fuName}", PopCount(validVec.zip(canIssueVec).zip(fuTypeVec).map { case ((v, c), fu) => v && c && fu === t.U }), true.B, 0, params.numEntries, 1) 685 } 686 } 687 } 688 689 // deq instr count 690 XSPerfAccumulate("issue_instr_pre_count", PopCount(deqBeforeDly.map(_.valid))) 691 XSPerfHistogram("issue_instr_pre_count_hist", PopCount(deqBeforeDly.map(_.valid)), true.B, 0, params.numDeq + 1, 1) 692 XSPerfAccumulate("issue_instr_count", PopCount(io.deqDelay.map(_.valid))) 693 XSPerfHistogram("issue_instr_count_hist", PopCount(io.deqDelay.map(_.valid)), true.B, 0, params.numDeq + 1, 1) 694 695 // deq instr data source count 696 XSPerfAccumulate("issue_datasource_reg", deqBeforeDly.map{ deq => 697 PopCount(deq.bits.common.dataSources.zipWithIndex.map{ case (ds, j) => deq.valid && ds.value === DataSource.reg && !SrcType.isNotReg(deq.bits.srcType(j)) }) 698 }.reduce(_ +& _)) 699 XSPerfAccumulate("issue_datasource_bypass", deqBeforeDly.map{ deq => 700 PopCount(deq.bits.common.dataSources.zipWithIndex.map{ case (ds, j) => deq.valid && ds.value === DataSource.bypass && !SrcType.isNotReg(deq.bits.srcType(j)) }) 701 }.reduce(_ +& _)) 702 XSPerfAccumulate("issue_datasource_forward", deqBeforeDly.map{ deq => 703 PopCount(deq.bits.common.dataSources.zipWithIndex.map{ case (ds, j) => deq.valid && ds.value === DataSource.forward && !SrcType.isNotReg(deq.bits.srcType(j)) }) 704 }.reduce(_ +& _)) 705 XSPerfAccumulate("issue_datasource_noreg", deqBeforeDly.map{ deq => 706 PopCount(deq.bits.common.dataSources.zipWithIndex.map{ case (ds, j) => deq.valid && SrcType.isNotReg(deq.bits.srcType(j)) }) 707 }.reduce(_ +& _)) 708 709 XSPerfHistogram("issue_datasource_reg_hist", deqBeforeDly.map{ deq => 710 PopCount(deq.bits.common.dataSources.zipWithIndex.map{ case (ds, j) => deq.valid && ds.value === DataSource.reg && !SrcType.isNotReg(deq.bits.srcType(j)) }) 711 }.reduce(_ +& _), true.B, 0, params.numDeq * params.numRegSrc + 1, 1) 712 XSPerfHistogram("issue_datasource_bypass_hist", deqBeforeDly.map{ deq => 713 PopCount(deq.bits.common.dataSources.zipWithIndex.map{ case (ds, j) => deq.valid && ds.value === DataSource.bypass && !SrcType.isNotReg(deq.bits.srcType(j)) }) 714 }.reduce(_ +& _), true.B, 0, params.numDeq * params.numRegSrc + 1, 1) 715 XSPerfHistogram("issue_datasource_forward_hist", deqBeforeDly.map{ deq => 716 PopCount(deq.bits.common.dataSources.zipWithIndex.map{ case (ds, j) => deq.valid && ds.value === DataSource.forward && !SrcType.isNotReg(deq.bits.srcType(j)) }) 717 }.reduce(_ +& _), true.B, 0, params.numDeq * params.numRegSrc + 1, 1) 718 XSPerfHistogram("issue_datasource_noreg_hist", deqBeforeDly.map{ deq => 719 PopCount(deq.bits.common.dataSources.zipWithIndex.map{ case (ds, j) => deq.valid && SrcType.isNotReg(deq.bits.srcType(j)) }) 720 }.reduce(_ +& _), true.B, 0, params.numDeq * params.numRegSrc + 1, 1) 721 722 // deq instr data source count for each futype 723 for (t <- FuType.functionNameMap.keys) { 724 val fuName = FuType.functionNameMap(t) 725 if (params.getFuCfgs.map(_.fuType == t).reduce(_ | _)) { 726 XSPerfAccumulate(s"issue_datasource_reg_futype_${fuName}", deqBeforeDly.map{ deq => 727 PopCount(deq.bits.common.dataSources.zipWithIndex.map{ case (ds, j) => deq.valid && ds.value === DataSource.reg && !SrcType.isNotReg(deq.bits.srcType(j)) && deq.bits.common.fuType === t.U }) 728 }.reduce(_ +& _)) 729 XSPerfAccumulate(s"issue_datasource_bypass_futype_${fuName}", deqBeforeDly.map{ deq => 730 PopCount(deq.bits.common.dataSources.zipWithIndex.map{ case (ds, j) => deq.valid && ds.value === DataSource.bypass && !SrcType.isNotReg(deq.bits.srcType(j)) && deq.bits.common.fuType === t.U }) 731 }.reduce(_ +& _)) 732 XSPerfAccumulate(s"issue_datasource_forward_futype_${fuName}", deqBeforeDly.map{ deq => 733 PopCount(deq.bits.common.dataSources.zipWithIndex.map{ case (ds, j) => deq.valid && ds.value === DataSource.forward && !SrcType.isNotReg(deq.bits.srcType(j)) && deq.bits.common.fuType === t.U }) 734 }.reduce(_ +& _)) 735 XSPerfAccumulate(s"issue_datasource_noreg_futype_${fuName}", deqBeforeDly.map{ deq => 736 PopCount(deq.bits.common.dataSources.zipWithIndex.map{ case (ds, j) => deq.valid && SrcType.isNotReg(deq.bits.srcType(j)) && deq.bits.common.fuType === t.U }) 737 }.reduce(_ +& _)) 738 739 XSPerfHistogram(s"issue_datasource_reg_hist_futype_${fuName}", deqBeforeDly.map{ deq => 740 PopCount(deq.bits.common.dataSources.zipWithIndex.map{ case (ds, j) => deq.valid && ds.value === DataSource.reg && !SrcType.isNotReg(deq.bits.srcType(j)) && deq.bits.common.fuType === t.U }) 741 }.reduce(_ +& _), true.B, 0, params.numDeq * params.numRegSrc + 1, 1) 742 XSPerfHistogram(s"issue_datasource_bypass_hist_futype_${fuName}", deqBeforeDly.map{ deq => 743 PopCount(deq.bits.common.dataSources.zipWithIndex.map{ case (ds, j) => deq.valid && ds.value === DataSource.bypass && !SrcType.isNotReg(deq.bits.srcType(j)) && deq.bits.common.fuType === t.U }) 744 }.reduce(_ +& _), true.B, 0, params.numDeq * params.numRegSrc + 1, 1) 745 XSPerfHistogram(s"issue_datasource_forward_hist_futype_${fuName}", deqBeforeDly.map{ deq => 746 PopCount(deq.bits.common.dataSources.zipWithIndex.map{ case (ds, j) => deq.valid && ds.value === DataSource.forward && !SrcType.isNotReg(deq.bits.srcType(j)) && deq.bits.common.fuType === t.U }) 747 }.reduce(_ +& _), true.B, 0, params.numDeq * params.numRegSrc + 1, 1) 748 XSPerfHistogram(s"issue_datasource_noreg_hist_futype_${fuName}", deqBeforeDly.map{ deq => 749 PopCount(deq.bits.common.dataSources.zipWithIndex.map{ case (ds, j) => deq.valid && SrcType.isNotReg(deq.bits.srcType(j)) && deq.bits.common.fuType === t.U }) 750 }.reduce(_ +& _), true.B, 0, params.numDeq * params.numRegSrc + 1, 1) 751 } 752 } 753 754 // cancel instr count 755 if (params.hasIQWakeUp) { 756 val cancelVec: Vec[Bool] = entries.io.cancel.get 757 XSPerfAccumulate("cancel_instr_count", PopCount(validVec.zip(cancelVec).map(x => x._1 & x._2))) 758 XSPerfHistogram("cancel_instr_hist", PopCount(validVec.zip(cancelVec).map(x => x._1 & x._2)), true.B, 0, params.numEntries, 1) 759 for (t <- FuType.functionNameMap.keys) { 760 val fuName = FuType.functionNameMap(t) 761 if (params.getFuCfgs.map(_.fuType == t).reduce(_ | _)) { 762 XSPerfAccumulate(s"cancel_instr_count_futype_${fuName}", PopCount(validVec.zip(cancelVec).zip(fuTypeVec).map{ case ((x, y), fu) => x & y & fu === t.U })) 763 XSPerfHistogram(s"cancel_instr_hist_futype_${fuName}", PopCount(validVec.zip(cancelVec).zip(fuTypeVec).map{ case ((x, y), fu) => x & y & fu === t.U }), true.B, 0, params.numEntries, 1) 764 } 765 } 766 } 767} 768 769class IssueQueueJumpBundle extends Bundle { 770 val pc = UInt(VAddrData().dataWidth.W) 771} 772 773class IssueQueueLoadBundle(implicit p: Parameters) extends XSBundle { 774 val fastMatch = UInt(backendParams.LduCnt.W) 775 val fastImm = UInt(12.W) 776} 777 778class IssueQueueIntIO()(implicit p: Parameters, params: IssueBlockParams) extends IssueQueueIO 779 780class IssueQueueIntImp(override val wrapper: IssueQueue)(implicit p: Parameters, iqParams: IssueBlockParams) 781 extends IssueQueueImp(wrapper) 782{ 783 io.suggestName("none") 784 override lazy val io = IO(new IssueQueueIntIO).suggestName("io") 785 786 if(params.needPc) { 787 entries.io.enq.zipWithIndex.foreach { case (entriesEnq, i) => 788 entriesEnq.bits.status.pc.foreach(_ := io.enq(i).bits.pc) 789 } 790 } 791 792 deqBeforeDly.zipWithIndex.foreach{ case (deq, i) => { 793 deq.bits.common.pc.foreach(_ := deqEntryVec(i).bits.status.pc.get) 794 deq.bits.common.preDecode.foreach(_ := deqEntryVec(i).bits.payload.preDecodeInfo) 795 deq.bits.common.ftqIdx.foreach(_ := deqEntryVec(i).bits.payload.ftqPtr) 796 deq.bits.common.ftqOffset.foreach(_ := deqEntryVec(i).bits.payload.ftqOffset) 797 deq.bits.common.predictInfo.foreach(x => { 798 x.target := DontCare 799 x.taken := deqEntryVec(i).bits.payload.pred_taken 800 }) 801 // for std 802 deq.bits.common.sqIdx.foreach(_ := deqEntryVec(i).bits.payload.sqIdx) 803 // for i2f 804 deq.bits.common.fpu.foreach(_ := deqEntryVec(i).bits.payload.fpu) 805 }} 806} 807 808class IssueQueueVfImp(override val wrapper: IssueQueue)(implicit p: Parameters, iqParams: IssueBlockParams) 809 extends IssueQueueImp(wrapper) 810{ 811 s0_enqBits.foreach{ x => 812 x.srcType(3) := SrcType.vp // v0: mask src 813 x.srcType(4) := SrcType.vp // vl&vtype 814 } 815 deqBeforeDly.zipWithIndex.foreach{ case (deq, i) => { 816 deq.bits.common.fpu.foreach(_ := deqEntryVec(i).bits.payload.fpu) 817 deq.bits.common.vpu.foreach(_ := deqEntryVec(i).bits.payload.vpu) 818 deq.bits.common.vpu.foreach(_.vuopIdx := deqEntryVec(i).bits.payload.uopIdx) 819 deq.bits.common.vpu.foreach(_.lastUop := deqEntryVec(i).bits.payload.lastUop) 820 }} 821} 822 823class IssueQueueMemBundle(implicit p: Parameters, params: IssueBlockParams) extends Bundle { 824 val feedbackIO = Flipped(Vec(params.numDeq, new MemRSFeedbackIO)) 825 val checkWait = new Bundle { 826 val stIssuePtr = Input(new SqPtr) 827 val memWaitUpdateReq = Flipped(new MemWaitUpdateReq) 828 } 829 val loadFastMatch = Output(Vec(params.LduCnt, new IssueQueueLoadBundle)) 830 831 // vector 832 val sqDeqPtr = OptionWrapper(params.isVecMemIQ, Input(new SqPtr)) 833 val lqDeqPtr = OptionWrapper(params.isVecMemIQ, Input(new LqPtr)) 834} 835 836class IssueQueueMemIO(implicit p: Parameters, params: IssueBlockParams) extends IssueQueueIO { 837 val memIO = Some(new IssueQueueMemBundle) 838} 839 840class IssueQueueMemAddrImp(override val wrapper: IssueQueue)(implicit p: Parameters, params: IssueBlockParams) 841 extends IssueQueueImp(wrapper) with HasCircularQueuePtrHelper { 842 843 require(params.StdCnt == 0 && (params.LduCnt + params.StaCnt + params.HyuCnt + params.VlduCnt) > 0, "IssueQueueMemAddrImp can only be instance of MemAddr IQ, " + 844 s"StdCnt: ${params.StdCnt}, LduCnt: ${params.LduCnt}, StaCnt: ${params.StaCnt}, HyuCnt: ${params.HyuCnt}") 845 println(s"[IssueQueueMemAddrImp] StdCnt: ${params.StdCnt}, LduCnt: ${params.LduCnt}, StaCnt: ${params.StaCnt}, HyuCnt: ${params.HyuCnt}") 846 847 io.suggestName("none") 848 override lazy val io = IO(new IssueQueueMemIO).suggestName("io") 849 private val memIO = io.memIO.get 850 851 memIO.loadFastMatch := 0.U.asTypeOf(memIO.loadFastMatch) // TODO: is still needed? 852 853 for (i <- io.enq.indices) { 854 val blockNotReleased = isAfter(io.enq(i).bits.sqIdx, memIO.checkWait.stIssuePtr) 855 val storeAddrWaitForIsIssuing = VecInit((0 until StorePipelineWidth).map(i => { 856 memIO.checkWait.memWaitUpdateReq.robIdx(i).valid && 857 memIO.checkWait.memWaitUpdateReq.robIdx(i).bits.value === io.enq(i).bits.waitForRobIdx.value 858 })).asUInt.orR && !io.enq(i).bits.loadWaitStrict // is waiting for store addr ready 859 s0_enqBits(i).loadWaitBit := io.enq(i).bits.loadWaitBit && !storeAddrWaitForIsIssuing && blockNotReleased 860 // when have vpu 861 if (params.VlduCnt > 0 || params.VstuCnt > 0) { 862 s0_enqBits(i).srcType(3) := SrcType.vp // v0: mask src 863 s0_enqBits(i).srcType(4) := SrcType.vp // vl&vtype 864 } 865 } 866 867 for (i <- entries.io.enq.indices) { 868 entries.io.enq(i).bits.status match { case enqData => 869 enqData.blocked := false.B // s0_enqBits(i).loadWaitBit 870 enqData.mem.get.strictWait := s0_enqBits(i).loadWaitStrict 871 enqData.mem.get.waitForStd := false.B 872 enqData.mem.get.waitForRobIdx := s0_enqBits(i).waitForRobIdx 873 enqData.mem.get.waitForSqIdx := 0.U.asTypeOf(enqData.mem.get.waitForSqIdx) // generated by sq, will be updated later 874 enqData.mem.get.sqIdx := s0_enqBits(i).sqIdx 875 } 876 877 entries.io.fromMem.get.slowResp.zipWithIndex.foreach { case (slowResp, i) => 878 slowResp.valid := memIO.feedbackIO(i).feedbackSlow.valid 879 slowResp.bits.robIdx := memIO.feedbackIO(i).feedbackSlow.bits.robIdx 880 slowResp.bits.uopIdx := DontCare 881 slowResp.bits.respType := Mux(memIO.feedbackIO(i).feedbackSlow.bits.hit, RSFeedbackType.fuIdle, RSFeedbackType.feedbackInvalid) 882 slowResp.bits.dataInvalidSqIdx := memIO.feedbackIO(i).feedbackSlow.bits.dataInvalidSqIdx 883 slowResp.bits.rfWen := DontCare 884 slowResp.bits.fuType := DontCare 885 } 886 887 entries.io.fromMem.get.fastResp.zipWithIndex.foreach { case (fastResp, i) => 888 fastResp.valid := memIO.feedbackIO(i).feedbackFast.valid 889 fastResp.bits.robIdx := memIO.feedbackIO(i).feedbackFast.bits.robIdx 890 fastResp.bits.uopIdx := DontCare 891 fastResp.bits.respType := Mux(memIO.feedbackIO(i).feedbackFast.bits.hit, RSFeedbackType.fuIdle, memIO.feedbackIO(i).feedbackFast.bits.sourceType) 892 fastResp.bits.dataInvalidSqIdx := 0.U.asTypeOf(fastResp.bits.dataInvalidSqIdx) 893 fastResp.bits.rfWen := DontCare 894 fastResp.bits.fuType := DontCare 895 } 896 897 entries.io.fromMem.get.memWaitUpdateReq := memIO.checkWait.memWaitUpdateReq 898 entries.io.fromMem.get.stIssuePtr := memIO.checkWait.stIssuePtr 899 } 900 901 deqBeforeDly.zipWithIndex.foreach { case (deq, i) => 902 deq.bits.common.loadWaitBit.foreach(_ := deqEntryVec(i).bits.payload.loadWaitBit) 903 deq.bits.common.waitForRobIdx.foreach(_ := deqEntryVec(i).bits.payload.waitForRobIdx) 904 deq.bits.common.storeSetHit.foreach(_ := deqEntryVec(i).bits.payload.storeSetHit) 905 deq.bits.common.loadWaitStrict.foreach(_ := deqEntryVec(i).bits.payload.loadWaitStrict) 906 deq.bits.common.ssid.foreach(_ := deqEntryVec(i).bits.payload.ssid) 907 deq.bits.common.sqIdx.get := deqEntryVec(i).bits.payload.sqIdx 908 deq.bits.common.lqIdx.get := deqEntryVec(i).bits.payload.lqIdx 909 deq.bits.common.ftqIdx.foreach(_ := deqEntryVec(i).bits.payload.ftqPtr) 910 deq.bits.common.ftqOffset.foreach(_ := deqEntryVec(i).bits.payload.ftqOffset) 911 // when have vpu 912 if (params.VlduCnt > 0 || params.VstuCnt > 0) { 913 deq.bits.common.vpu.foreach(_ := deqEntryVec(i).bits.payload.vpu) 914 deq.bits.common.vpu.foreach(_.vuopIdx := deqEntryVec(i).bits.payload.uopIdx) 915 } 916 } 917} 918 919class IssueQueueVecMemImp(override val wrapper: IssueQueue)(implicit p: Parameters, params: IssueBlockParams) 920 extends IssueQueueImp(wrapper) with HasCircularQueuePtrHelper { 921 922 require((params.VstdCnt + params.VlduCnt + params.VstaCnt) > 0, "IssueQueueVecMemImp can only be instance of VecMem IQ") 923 924 io.suggestName("none") 925 override lazy val io = IO(new IssueQueueMemIO).suggestName("io") 926 private val memIO = io.memIO.get 927 928 def selectOldUop(robIdx: Seq[RobPtr], uopIdx: Seq[UInt], valid: Seq[Bool]): Vec[Bool] = { 929 val compareVec = (0 until robIdx.length).map(i => (0 until i).map(j => isAfter(robIdx(j), robIdx(i)) || (robIdx(j).value === robIdx(i).value && uopIdx(i) < uopIdx(j)))) 930 val resultOnehot = VecInit((0 until robIdx.length).map(i => Cat((0 until robIdx.length).map(j => 931 (if (j < i) !valid(j) || compareVec(i)(j) 932 else if (j == i) valid(i) 933 else !valid(j) || !compareVec(j)(i)) 934 )).andR)) 935 resultOnehot 936 } 937 938 val robIdxVec = entries.io.robIdx.get 939 val uopIdxVec = entries.io.uopIdx.get 940 val allEntryOldestOH = selectOldUop(robIdxVec, uopIdxVec, validVec) 941 942 finalDeqSelValidVec.head := (allEntryOldestOH.asUInt & canIssueVec.asUInt).orR 943 finalDeqSelOHVec.head := allEntryOldestOH.asUInt & canIssueVec.asUInt 944 945 if (params.isVecMemAddrIQ) { 946 s0_enqBits.foreach{ x => 947 x.srcType(3) := SrcType.vp // v0: mask src 948 x.srcType(4) := SrcType.vp // vl&vtype 949 } 950 951 for (i <- io.enq.indices) { 952 s0_enqBits(i).loadWaitBit := false.B 953 } 954 955 for (i <- entries.io.enq.indices) { 956 entries.io.enq(i).bits.status match { case enqData => 957 enqData.blocked := false.B // s0_enqBits(i).loadWaitBit 958 enqData.mem.get.strictWait := s0_enqBits(i).loadWaitStrict 959 enqData.mem.get.waitForStd := false.B 960 enqData.mem.get.waitForRobIdx := s0_enqBits(i).waitForRobIdx 961 enqData.mem.get.waitForSqIdx := 0.U.asTypeOf(enqData.mem.get.waitForSqIdx) // generated by sq, will be updated later 962 enqData.mem.get.sqIdx := s0_enqBits(i).sqIdx 963 } 964 965 entries.io.fromMem.get.slowResp.zipWithIndex.foreach { case (slowResp, i) => 966 slowResp.valid := memIO.feedbackIO(i).feedbackSlow.valid 967 slowResp.bits.robIdx := memIO.feedbackIO(i).feedbackSlow.bits.robIdx 968 slowResp.bits.uopIdx := DontCare 969 slowResp.bits.respType := Mux(memIO.feedbackIO(i).feedbackSlow.bits.hit, RSFeedbackType.fuIdle, RSFeedbackType.feedbackInvalid) 970 slowResp.bits.dataInvalidSqIdx := memIO.feedbackIO(i).feedbackSlow.bits.dataInvalidSqIdx 971 slowResp.bits.rfWen := DontCare 972 slowResp.bits.fuType := DontCare 973 } 974 975 entries.io.fromMem.get.fastResp.zipWithIndex.foreach { case (fastResp, i) => 976 fastResp.valid := memIO.feedbackIO(i).feedbackFast.valid 977 fastResp.bits.robIdx := memIO.feedbackIO(i).feedbackFast.bits.robIdx 978 fastResp.bits.uopIdx := DontCare 979 fastResp.bits.respType := memIO.feedbackIO(i).feedbackFast.bits.sourceType 980 fastResp.bits.dataInvalidSqIdx := 0.U.asTypeOf(fastResp.bits.dataInvalidSqIdx) 981 fastResp.bits.rfWen := DontCare 982 fastResp.bits.fuType := DontCare 983 } 984 985 entries.io.fromMem.get.memWaitUpdateReq := memIO.checkWait.memWaitUpdateReq 986 entries.io.fromMem.get.stIssuePtr := memIO.checkWait.stIssuePtr 987 } 988 } 989 990 for (i <- entries.io.enq.indices) { 991 entries.io.enq(i).bits.status match { case enqData => 992 enqData.vecMem.get.sqIdx := s0_enqBits(i).sqIdx 993 enqData.vecMem.get.lqIdx := s0_enqBits(i).lqIdx 994 } 995 } 996 997 entries.io.fromLsq.get.sqDeqPtr := memIO.sqDeqPtr.get 998 entries.io.fromLsq.get.lqDeqPtr := memIO.lqDeqPtr.get 999 1000 deqBeforeDly.zipWithIndex.foreach { case (deq, i) => 1001 deq.bits.common.sqIdx.foreach(_ := deqEntryVec(i).bits.payload.sqIdx) 1002 deq.bits.common.lqIdx.foreach(_ := deqEntryVec(i).bits.payload.lqIdx) 1003 if (params.isVecLdAddrIQ) { 1004 deq.bits.common.ftqIdx.get := deqEntryVec(i).bits.payload.ftqPtr 1005 deq.bits.common.ftqOffset.get := deqEntryVec(i).bits.payload.ftqOffset 1006 } 1007 deq.bits.common.fpu.foreach(_ := deqEntryVec(i).bits.payload.fpu) 1008 deq.bits.common.vpu.foreach(_ := deqEntryVec(i).bits.payload.vpu) 1009 deq.bits.common.vpu.foreach(_.vuopIdx := deqEntryVec(i).bits.payload.uopIdx) 1010 deq.bits.common.vpu.foreach(_.lastUop := deqEntryVec(i).bits.payload.lastUop) 1011 } 1012} 1013