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