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