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