xref: /XiangShan/src/main/scala/xiangshan/backend/issue/Scheduler.scala (revision 0f55a0d39d9e13a42b8a8ea5f45338f62ff484ef)
1730cfbc0SXuan Hupackage xiangshan.backend.issue
2730cfbc0SXuan Hu
3730cfbc0SXuan Huimport chipsalliance.rocketchip.config.Parameters
4730cfbc0SXuan Huimport chisel3._
5730cfbc0SXuan Huimport chisel3.util._
6730cfbc0SXuan Huimport freechips.rocketchip.diplomacy.{LazyModule, LazyModuleImp}
7730cfbc0SXuan Huimport xiangshan._
810fe9778SXuan Huimport xiangshan.backend.Bundles._
939c59369SXuan Huimport xiangshan.backend.datapath.DataConfig.{IntData, VAddrData, VecData}
1039c59369SXuan Huimport xiangshan.backend.datapath.WbConfig.{IntWB, VfWB}
11730cfbc0SXuan Huimport xiangshan.backend.regfile.RfWritePortWithConfig
12730cfbc0SXuan Huimport xiangshan.backend.rename.BusyTable
13730cfbc0SXuan Huimport xiangshan.mem.{LsqEnqCtrl, LsqEnqIO, MemWaitUpdateReq, SqPtr}
14730cfbc0SXuan Hu
15730cfbc0SXuan Husealed trait SchedulerType
16730cfbc0SXuan Hu
17730cfbc0SXuan Hucase class IntScheduler() extends SchedulerType
18730cfbc0SXuan Hucase class MemScheduler() extends SchedulerType
19730cfbc0SXuan Hucase class VfScheduler() extends SchedulerType
20730cfbc0SXuan Hucase class NoScheduler() extends SchedulerType
21730cfbc0SXuan Hu
22730cfbc0SXuan Huclass Scheduler(val params: SchdBlockParams)(implicit p: Parameters) extends LazyModule with HasXSParameter {
2339c59369SXuan Hu  val numIntStateWrite = backendParams.numPregWb(IntData())
2439c59369SXuan Hu  val numVfStateWrite = backendParams.numPregWb(VecData())
25730cfbc0SXuan Hu
26730cfbc0SXuan Hu  val dispatch2Iq = LazyModule(new Dispatch2Iq(params))
27730cfbc0SXuan Hu  val issueQueue = params.issueBlockParams.map(x => LazyModule(new IssueQueue(x).suggestName(x.getIQName)))
28730cfbc0SXuan Hu
29730cfbc0SXuan Hu  lazy val module = params.schdType match {
30730cfbc0SXuan Hu    case IntScheduler() => new SchedulerArithImp(this)(params, p)
31730cfbc0SXuan Hu    case MemScheduler() => new SchedulerMemImp(this)(params, p)
32730cfbc0SXuan Hu    case VfScheduler() => new SchedulerArithImp(this)(params, p)
33730cfbc0SXuan Hu    case _ => null
34730cfbc0SXuan Hu  }
35730cfbc0SXuan Hu}
36730cfbc0SXuan Hu
377f8233d5SHaojin Tangclass SchedulerIO()(implicit params: SchdBlockParams, p: Parameters) extends XSBundle {
3868d13085SXuan Hu  // params alias
397f8233d5SHaojin Tang  private val LoadQueueSize = VirtualLoadQueueSize
4068d13085SXuan Hu
41730cfbc0SXuan Hu  val fromTop = new Bundle {
42730cfbc0SXuan Hu    val hartId = Input(UInt(8.W))
43730cfbc0SXuan Hu  }
442e0a7dc5Sfdy  val fromWbFuBusyTable = new Bundle{
452e0a7dc5Sfdy    val fuBusyTableRead = MixedVec(params.issueBlockParams.map(x => Input(x.genWbFuBusyTableReadBundle)))
462e0a7dc5Sfdy  }
47dd970561SzhanglyGit  val wbFuBusyTable = MixedVec(params.issueBlockParams.map(x => Output(x.genWbFuBusyTableWriteBundle)))
48dd970561SzhanglyGit
49730cfbc0SXuan Hu  val fromCtrlBlock = new Bundle {
50730cfbc0SXuan Hu    val pcVec = Input(Vec(params.numPcReadPort, UInt(VAddrData().dataWidth.W)))
51730cfbc0SXuan Hu    val targetVec = Input(Vec(params.numPcReadPort, UInt(VAddrData().dataWidth.W)))
52730cfbc0SXuan Hu    val flush = Flipped(ValidIO(new Redirect))
53730cfbc0SXuan Hu  }
54730cfbc0SXuan Hu  val fromDispatch = new Bundle {
55730cfbc0SXuan Hu    val allocPregs = Vec(RenameWidth, Input(new ResetPregStateReq))
56730cfbc0SXuan Hu    val uops =  Vec(params.numUopIn, Flipped(DecoupledIO(new DynInst)))
57730cfbc0SXuan Hu  }
5839c59369SXuan Hu  val intWriteBack = MixedVec(Vec(backendParams.numPregWb(IntData()),
59730cfbc0SXuan Hu    new RfWritePortWithConfig(backendParams.intPregParams.dataCfg, backendParams.intPregParams.addrWidth)))
6039c59369SXuan Hu  val vfWriteBack = MixedVec(Vec(backendParams.numPregWb(VecData()),
61730cfbc0SXuan Hu    new RfWritePortWithConfig(backendParams.vfPregParams.dataCfg, backendParams.vfPregParams.addrWidth)))
6210fe9778SXuan Hu  val toDataPath: MixedVec[MixedVec[DecoupledIO[IssueQueueIssueBundle]]] = MixedVec(params.issueBlockParams.map(_.genIssueDecoupledBundle))
6359ef6009Sxiaofeibao-xjtu  val toDataPathAfterDelay: MixedVec[MixedVec[DecoupledIO[IssueQueueIssueBundle]]] = MixedVec(params.issueBlockParams.map(_.genIssueDecoupledBundle))
6459ef6009Sxiaofeibao-xjtu  val fromCancelNetwork = Flipped(MixedVec(params.issueBlockParams.map(_.genIssueDecoupledBundle)))
65730cfbc0SXuan Hu
66bf35baadSXuan Hu  val fromSchedulers = new Bundle {
67c0be7f33SXuan Hu    val wakeupVec: MixedVec[ValidIO[IssueQueueIQWakeUpBundle]] = Flipped(params.genIQWakeUpInValidBundle)
68bf35baadSXuan Hu  }
69bf35baadSXuan Hu
70bf35baadSXuan Hu  val toSchedulers = new Bundle {
71c0be7f33SXuan Hu    val wakeupVec: MixedVec[ValidIO[IssueQueueIQWakeUpBundle]] = params.genIQWakeUpOutValidBundle
72bf35baadSXuan Hu  }
73bf35baadSXuan Hu
74c0be7f33SXuan Hu  val fromDataPath = new Bundle {
7510fe9778SXuan Hu    val resp: MixedVec[MixedVec[OGRespBundle]] = MixedVec(params.issueBlockParams.map(x => Flipped(x.genOGRespBundle)))
76ea46c302SXuan Hu    val og0Cancel = Input(ExuVec(backendParams.numExu))
77ea46c302SXuan Hu    // Todo: remove this after no cancel signal from og1
78ea46c302SXuan Hu    val og1Cancel = Input(ExuVec(backendParams.numExu))
79c0be7f33SXuan Hu    // just be compatible to old code
80c0be7f33SXuan Hu    def apply(i: Int)(j: Int) = resp(i)(j)
81c0be7f33SXuan Hu  }
82c0be7f33SXuan Hu
83*0f55a0d3SHaojin Tang  val loadFinalIssueResp = MixedVec(params.issueBlockParams.map(x => MixedVec(Vec(x.LduCnt, Flipped(ValidIO(new IssueQueueDeqRespBundle()(p, x)))))))
84*0f55a0d3SHaojin Tang
85*0f55a0d3SHaojin Tang  val ldCancel = Vec(backendParams.LduCnt, Flipped(new LoadCancelIO))
86c0be7f33SXuan Hu
87730cfbc0SXuan Hu  val memIO = if (params.isMemSchd) Some(new Bundle {
88730cfbc0SXuan Hu    val lsqEnqIO = Flipped(new LsqEnqIO)
89730cfbc0SXuan Hu  }) else None
90730cfbc0SXuan Hu  val fromMem = if (params.isMemSchd) Some(new Bundle {
917b753bebSXuan Hu    val ldaFeedback = Flipped(Vec(params.LduCnt, new MemRSFeedbackIO))
927b753bebSXuan Hu    val staFeedback = Flipped(Vec(params.StaCnt, new MemRSFeedbackIO))
93730cfbc0SXuan Hu    val stIssuePtr = Input(new SqPtr())
94730cfbc0SXuan Hu    val lcommit = Input(UInt(log2Up(CommitWidth + 1).W))
95730cfbc0SXuan Hu    val scommit = Input(UInt(log2Ceil(EnsbufferWidth + 1).W)) // connected to `memBlock.io.sqDeq` instead of ROB
96730cfbc0SXuan Hu    // from lsq
97730cfbc0SXuan Hu    val lqCancelCnt = Input(UInt(log2Up(LoadQueueSize + 1).W))
98730cfbc0SXuan Hu    val sqCancelCnt = Input(UInt(log2Up(StoreQueueSize + 1).W))
99730cfbc0SXuan Hu    val memWaitUpdateReq = Flipped(new MemWaitUpdateReq)
100730cfbc0SXuan Hu  }) else None
101730cfbc0SXuan Hu  val toMem = if (params.isMemSchd) Some(new Bundle {
102730cfbc0SXuan Hu    val loadFastMatch = Output(Vec(params.LduCnt, new IssueQueueLoadBundle))
103730cfbc0SXuan Hu  }) else None
104730cfbc0SXuan Hu}
105730cfbc0SXuan Hu
106730cfbc0SXuan Huabstract class SchedulerImpBase(wrapper: Scheduler)(implicit params: SchdBlockParams, p: Parameters)
107730cfbc0SXuan Hu  extends LazyModuleImp(wrapper)
108730cfbc0SXuan Hu    with HasXSParameter
109730cfbc0SXuan Hu{
110730cfbc0SXuan Hu  val io = IO(new SchedulerIO())
111730cfbc0SXuan Hu
112730cfbc0SXuan Hu  // alias
113c0be7f33SXuan Hu  private val iqWakeUpInMap: Map[Int, ValidIO[IssueQueueIQWakeUpBundle]] =
114c0be7f33SXuan Hu    io.fromSchedulers.wakeupVec.map(x => (x.bits.exuIdx, x)).toMap
115730cfbc0SXuan Hu  private val schdType = params.schdType
116730cfbc0SXuan Hu
117730cfbc0SXuan Hu  // Modules
118730cfbc0SXuan Hu  val dispatch2Iq: Dispatch2IqImp = wrapper.dispatch2Iq.module
119730cfbc0SXuan Hu  val issueQueues: Seq[IssueQueueImp] = wrapper.issueQueue.map(_.module)
120730cfbc0SXuan Hu
121730cfbc0SXuan Hu  // BusyTable Modules
122730cfbc0SXuan Hu  val intBusyTable = schdType match {
12339c59369SXuan Hu    case IntScheduler() | MemScheduler() => Some(Module(new BusyTable(dispatch2Iq.numIntStateRead, wrapper.numIntStateWrite, IntPhyRegs)))
124730cfbc0SXuan Hu    case _ => None
125730cfbc0SXuan Hu  }
126730cfbc0SXuan Hu
127730cfbc0SXuan Hu  val vfBusyTable = schdType match {
12839c59369SXuan Hu    case VfScheduler() | MemScheduler() => Some(Module(new BusyTable(dispatch2Iq.numVfStateRead, wrapper.numVfStateWrite, VfPhyRegs)))
129730cfbc0SXuan Hu    case _ => None
130730cfbc0SXuan Hu  }
131730cfbc0SXuan Hu
132730cfbc0SXuan Hu  dispatch2Iq.io match { case dp2iq =>
133730cfbc0SXuan Hu    dp2iq.redirect <> io.fromCtrlBlock.flush
134730cfbc0SXuan Hu    dp2iq.in <> io.fromDispatch.uops
135730cfbc0SXuan Hu    dp2iq.readIntState.foreach(_ <> intBusyTable.get.io.read)
136730cfbc0SXuan Hu    dp2iq.readVfState.foreach(_ <> vfBusyTable.get.io.read)
137730cfbc0SXuan Hu  }
138730cfbc0SXuan Hu
139730cfbc0SXuan Hu  intBusyTable match {
140730cfbc0SXuan Hu    case Some(bt) =>
141730cfbc0SXuan Hu      bt.io.allocPregs.zip(io.fromDispatch.allocPregs).foreach { case (btAllocPregs, dpAllocPregs) =>
142730cfbc0SXuan Hu        btAllocPregs.valid := dpAllocPregs.isInt
143730cfbc0SXuan Hu        btAllocPregs.bits := dpAllocPregs.preg
144730cfbc0SXuan Hu      }
145730cfbc0SXuan Hu      bt.io.wbPregs.zipWithIndex.foreach { case (wb, i) =>
146730cfbc0SXuan Hu        wb.valid := io.intWriteBack(i).wen && io.intWriteBack(i).intWen
147730cfbc0SXuan Hu        wb.bits := io.intWriteBack(i).addr
148730cfbc0SXuan Hu      }
149730cfbc0SXuan Hu    case None =>
150730cfbc0SXuan Hu  }
151730cfbc0SXuan Hu
152730cfbc0SXuan Hu  vfBusyTable match {
153730cfbc0SXuan Hu    case Some(bt) =>
154730cfbc0SXuan Hu      bt.io.allocPregs.zip(io.fromDispatch.allocPregs).foreach { case (btAllocPregs, dpAllocPregs) =>
155730cfbc0SXuan Hu        btAllocPregs.valid := dpAllocPregs.isFp
156730cfbc0SXuan Hu        btAllocPregs.bits := dpAllocPregs.preg
157730cfbc0SXuan Hu      }
158730cfbc0SXuan Hu      bt.io.wbPregs.zipWithIndex.foreach { case (wb, i) =>
159730cfbc0SXuan Hu        wb.valid := io.vfWriteBack(i).wen && (io.vfWriteBack(i).fpWen || io.vfWriteBack(i).vecWen)
160730cfbc0SXuan Hu        wb.bits := io.vfWriteBack(i).addr
161730cfbc0SXuan Hu      }
162730cfbc0SXuan Hu    case None =>
163730cfbc0SXuan Hu  }
164730cfbc0SXuan Hu
165c0be7f33SXuan Hu  val wakeupFromWBVec = Wire(params.genWBWakeUpSinkValidBundle)
166730cfbc0SXuan Hu  val writeback = params.schdType match {
167730cfbc0SXuan Hu    case IntScheduler() => io.intWriteBack
168730cfbc0SXuan Hu    case MemScheduler() => io.intWriteBack ++ io.vfWriteBack
169730cfbc0SXuan Hu    case VfScheduler() => io.vfWriteBack
170730cfbc0SXuan Hu    case _ => Seq()
171730cfbc0SXuan Hu  }
172730cfbc0SXuan Hu  wakeupFromWBVec.zip(writeback).foreach { case (sink, source) =>
173730cfbc0SXuan Hu    sink.valid := source.wen
174730cfbc0SXuan Hu    sink.bits.rfWen := source.intWen
175730cfbc0SXuan Hu    sink.bits.fpWen := source.fpWen
176730cfbc0SXuan Hu    sink.bits.vecWen := source.vecWen
177730cfbc0SXuan Hu    sink.bits.pdest := source.addr
178730cfbc0SXuan Hu  }
179730cfbc0SXuan Hu
180bf35baadSXuan Hu  // Connect bundles having the same wakeup source
18159ef6009Sxiaofeibao-xjtu  issueQueues.zipWithIndex.foreach { case(iq, i) =>
182bf35baadSXuan Hu    iq.io.wakeupFromIQ.foreach { wakeUp =>
183c0be7f33SXuan Hu      wakeUp := iqWakeUpInMap(wakeUp.bits.exuIdx)
184bf35baadSXuan Hu    }
185ea46c302SXuan Hu    iq.io.og0Cancel := io.fromDataPath.og0Cancel
186ea46c302SXuan Hu    iq.io.og1Cancel := io.fromDataPath.og1Cancel
187*0f55a0d3SHaojin Tang    iq.io.ldCancel := io.ldCancel
18859ef6009Sxiaofeibao-xjtu    iq.io.fromCancelNetwork <> io.fromCancelNetwork(i)
189bf35baadSXuan Hu  }
190bf35baadSXuan Hu
191c0be7f33SXuan Hu  private val iqWakeUpOutMap: Map[Int, ValidIO[IssueQueueIQWakeUpBundle]] =
192bf35baadSXuan Hu    issueQueues.flatMap(_.io.wakeupToIQ)
193c0be7f33SXuan Hu      .map(x => (x.bits.exuIdx, x))
194bf35baadSXuan Hu      .toMap
195bf35baadSXuan Hu
196bf35baadSXuan Hu  // Connect bundles having the same wakeup source
197bf35baadSXuan Hu  io.toSchedulers.wakeupVec.foreach { wakeUp =>
198c0be7f33SXuan Hu    wakeUp := iqWakeUpOutMap(wakeUp.bits.exuIdx)
199bf35baadSXuan Hu  }
200bf35baadSXuan Hu
201730cfbc0SXuan Hu  io.toDataPath.zipWithIndex.foreach { case (toDp, i) =>
202730cfbc0SXuan Hu    toDp <> issueQueues(i).io.deq
203730cfbc0SXuan Hu  }
20459ef6009Sxiaofeibao-xjtu  io.toDataPathAfterDelay.zipWithIndex.foreach { case (toDpDy, i) =>
20559ef6009Sxiaofeibao-xjtu    toDpDy <> issueQueues(i).io.deqDelay
20659ef6009Sxiaofeibao-xjtu  }
207bf35baadSXuan Hu
208c0be7f33SXuan Hu  println(s"[Scheduler] io.fromSchedulers.wakeupVec: ${io.fromSchedulers.wakeupVec.map(x => backendParams.getExuName(x.bits.exuIdx))}")
209bf35baadSXuan Hu  println(s"[Scheduler] iqWakeUpInKeys: ${iqWakeUpInMap.keys}")
210bf35baadSXuan Hu
211bf35baadSXuan Hu  println(s"[Scheduler] iqWakeUpOutKeys: ${iqWakeUpOutMap.keys}")
212c0be7f33SXuan Hu  println(s"[Scheduler] io.toSchedulers.wakeupVec: ${io.toSchedulers.wakeupVec.map(x => backendParams.getExuName(x.bits.exuIdx))}")
213730cfbc0SXuan Hu}
214730cfbc0SXuan Hu
215730cfbc0SXuan Huclass SchedulerArithImp(override val wrapper: Scheduler)(implicit params: SchdBlockParams, p: Parameters)
216730cfbc0SXuan Hu  extends SchedulerImpBase(wrapper)
217730cfbc0SXuan Hu    with HasXSParameter
218730cfbc0SXuan Hu{
2192e0a7dc5Sfdy//  dontTouch(io.vfWbFuBusyTable)
220730cfbc0SXuan Hu  println(s"[SchedulerArithImp] " +
221730cfbc0SXuan Hu    s"has intBusyTable: ${intBusyTable.nonEmpty}, " +
222730cfbc0SXuan Hu    s"has vfBusyTable: ${vfBusyTable.nonEmpty}")
223730cfbc0SXuan Hu
224730cfbc0SXuan Hu  issueQueues.zipWithIndex.foreach { case (iq, i) =>
225730cfbc0SXuan Hu    iq.io.flush <> io.fromCtrlBlock.flush
226730cfbc0SXuan Hu    iq.io.enq <> dispatch2Iq.io.out(i)
227bf35baadSXuan Hu    iq.io.wakeupFromWB := wakeupFromWBVec
228730cfbc0SXuan Hu    iq.io.deqResp.zipWithIndex.foreach { case (deqResp, j) =>
229ea0f92d8Sczw      deqResp.valid := iq.io.deq(j).valid && io.toDataPath(i)(j).ready
230ea0f92d8Sczw      deqResp.bits.respType := RSFeedbackType.issueSuccess
2315db4956bSzhanglyGit      deqResp.bits.robIdx := iq.io.deq(j).bits.common.robIdx
2328d29ec32Sczw      deqResp.bits.rfWen := iq.io.deq(j).bits.common.rfWen.getOrElse(false.B)
2338d29ec32Sczw      deqResp.bits.fuType := iq.io.deq(j).bits.common.fuType
2348d29ec32Sczw
235730cfbc0SXuan Hu    }
236730cfbc0SXuan Hu    iq.io.og0Resp.zipWithIndex.foreach { case (og0Resp, j) =>
237730cfbc0SXuan Hu      og0Resp.valid := io.fromDataPath(i)(j).og0resp.valid
238730cfbc0SXuan Hu      og0Resp.bits.respType := io.fromDataPath(i)(j).og0resp.bits.respType
2395db4956bSzhanglyGit      og0Resp.bits.robIdx := io.fromDataPath(i)(j).og0resp.bits.robIdx
2408d29ec32Sczw      og0Resp.bits.rfWen := io.fromDataPath(i)(j).og0resp.bits.rfWen
2418d29ec32Sczw      og0Resp.bits.fuType := io.fromDataPath(i)(j).og0resp.bits.fuType
2428d29ec32Sczw
243730cfbc0SXuan Hu    }
244730cfbc0SXuan Hu    iq.io.og1Resp.zipWithIndex.foreach { case (og1Resp, j) =>
245730cfbc0SXuan Hu      og1Resp.valid := io.fromDataPath(i)(j).og1resp.valid
246730cfbc0SXuan Hu      og1Resp.bits.respType := io.fromDataPath(i)(j).og1resp.bits.respType
2475db4956bSzhanglyGit      og1Resp.bits.robIdx := io.fromDataPath(i)(j).og1resp.bits.robIdx
2488d29ec32Sczw      og1Resp.bits.rfWen := io.fromDataPath(i)(j).og1resp.bits.rfWen
2498d29ec32Sczw      og1Resp.bits.fuType := io.fromDataPath(i)(j).og1resp.bits.fuType
2508d29ec32Sczw
251730cfbc0SXuan Hu    }
2522e0a7dc5Sfdy
2532e0a7dc5Sfdy    iq.io.wbBusyTableRead := io.fromWbFuBusyTable.fuBusyTableRead(i)
254dd970561SzhanglyGit    io.wbFuBusyTable(i) := iq.io.wbBusyTableWrite
255730cfbc0SXuan Hu  }
256730cfbc0SXuan Hu
257730cfbc0SXuan Hu  val iqJumpBundleVec: Seq[IssueQueueJumpBundle] = issueQueues.map {
258730cfbc0SXuan Hu    case imp: IssueQueueIntImp => imp.io.enqJmp
259730cfbc0SXuan Hu    case _ => None
260730cfbc0SXuan Hu  }.filter(_.nonEmpty).flatMap(_.get)
261730cfbc0SXuan Hu  println(s"[Scheduler] iqJumpBundleVec: ${iqJumpBundleVec}")
262730cfbc0SXuan Hu
263730cfbc0SXuan Hu  iqJumpBundleVec.zip(io.fromCtrlBlock.pcVec zip io.fromCtrlBlock.targetVec).foreach { case (iqJmp, (pc, target)) =>
264730cfbc0SXuan Hu    iqJmp.pc := pc
265730cfbc0SXuan Hu    iqJmp.target := target
266730cfbc0SXuan Hu  }
267730cfbc0SXuan Hu}
268730cfbc0SXuan Hu
269730cfbc0SXuan Huclass SchedulerMemImp(override val wrapper: Scheduler)(implicit params: SchdBlockParams, p: Parameters)
270730cfbc0SXuan Hu  extends SchedulerImpBase(wrapper)
271730cfbc0SXuan Hu    with HasXSParameter
272730cfbc0SXuan Hu{
273730cfbc0SXuan Hu  println(s"[SchedulerMemImp] " +
274730cfbc0SXuan Hu    s"has intBusyTable: ${intBusyTable.nonEmpty}, " +
275730cfbc0SXuan Hu    s"has vfBusyTable: ${vfBusyTable.nonEmpty}")
276730cfbc0SXuan Hu
277730cfbc0SXuan Hu  val memAddrIQs = issueQueues.filter(iq => iq.params.StdCnt == 0)
278730cfbc0SXuan Hu  val stAddrIQs = issueQueues.filter(iq => iq.params.StaCnt > 0) // included in memAddrIQs
2797b753bebSXuan Hu  val ldAddrIQs = issueQueues.filter(iq => iq.params.LduCnt > 0)
280730cfbc0SXuan Hu  val stDataIQs = issueQueues.filter(iq => iq.params.StdCnt > 0)
281730cfbc0SXuan Hu  require(memAddrIQs.nonEmpty && stDataIQs.nonEmpty)
282730cfbc0SXuan Hu
283730cfbc0SXuan Hu  issueQueues.zipWithIndex.foreach { case (iq, i) =>
284730cfbc0SXuan Hu    iq.io.deqResp.zipWithIndex.foreach { case (deqResp, j) =>
285ea0f92d8Sczw      deqResp.valid := iq.io.deq(j).valid && io.toDataPath(i)(j).ready
286ea0f92d8Sczw      deqResp.bits.respType := RSFeedbackType.issueSuccess
2875db4956bSzhanglyGit      deqResp.bits.robIdx := iq.io.deq(j).bits.common.robIdx
2888d29ec32Sczw      deqResp.bits.rfWen := iq.io.deq(j).bits.common.rfWen.getOrElse(false.B)
2898d29ec32Sczw      deqResp.bits.fuType := iq.io.deq(j).bits.common.fuType
2908d29ec32Sczw
291730cfbc0SXuan Hu    }
292730cfbc0SXuan Hu    iq.io.og0Resp.zipWithIndex.foreach { case (og0Resp, j) =>
293730cfbc0SXuan Hu      og0Resp.valid := io.fromDataPath(i)(j).og0resp.valid
294730cfbc0SXuan Hu      og0Resp.bits.respType := io.fromDataPath(i)(j).og0resp.bits.respType
2955db4956bSzhanglyGit      og0Resp.bits.robIdx := io.fromDataPath(i)(j).og0resp.bits.robIdx
2968d29ec32Sczw      og0Resp.bits.rfWen := io.fromDataPath(i)(j).og0resp.bits.rfWen
2978d29ec32Sczw      og0Resp.bits.fuType := io.fromDataPath(i)(j).og0resp.bits.fuType
2988d29ec32Sczw
299730cfbc0SXuan Hu    }
300730cfbc0SXuan Hu    iq.io.og1Resp.zipWithIndex.foreach { case (og1Resp, j) =>
301730cfbc0SXuan Hu      og1Resp.valid := io.fromDataPath(i)(j).og1resp.valid
302730cfbc0SXuan Hu      og1Resp.bits.respType := io.fromDataPath(i)(j).og1resp.bits.respType
3035db4956bSzhanglyGit      og1Resp.bits.robIdx := io.fromDataPath(i)(j).og1resp.bits.robIdx
3048d29ec32Sczw      og1Resp.bits.rfWen := io.fromDataPath(i)(j).og1resp.bits.rfWen
3058d29ec32Sczw      og1Resp.bits.fuType := io.fromDataPath(i)(j).og1resp.bits.fuType
3068d29ec32Sczw
307730cfbc0SXuan Hu    }
308*0f55a0d3SHaojin Tang    iq.io.finalIssueResp.foreach(_.zipWithIndex.foreach { case (finalIssueResp, j) =>
309*0f55a0d3SHaojin Tang      finalIssueResp := io.loadFinalIssueResp(i)(j)
310*0f55a0d3SHaojin Tang    })
3112e0a7dc5Sfdy    iq.io.wbBusyTableRead := io.fromWbFuBusyTable.fuBusyTableRead(i)
312dd970561SzhanglyGit    io.wbFuBusyTable(i) := iq.io.wbBusyTableWrite
313730cfbc0SXuan Hu  }
314730cfbc0SXuan Hu
315730cfbc0SXuan Hu  memAddrIQs.zipWithIndex.foreach { case (iq, i) =>
316730cfbc0SXuan Hu    iq.io.flush <> io.fromCtrlBlock.flush
317730cfbc0SXuan Hu    iq.io.enq <> dispatch2Iq.io.out(i)
318bf35baadSXuan Hu    iq.io.wakeupFromWB := wakeupFromWBVec
319730cfbc0SXuan Hu  }
320730cfbc0SXuan Hu
3217b753bebSXuan Hu  ldAddrIQs.foreach {
322de784418SXuan Hu    case imp: IssueQueueMemAddrImp =>
323de784418SXuan Hu      imp.io.memIO.get.feedbackIO <> io.fromMem.get.ldaFeedback
324de784418SXuan Hu      imp.io.memIO.get.checkWait.memWaitUpdateReq := io.fromMem.get.memWaitUpdateReq
3257b753bebSXuan Hu    case _ =>
3267b753bebSXuan Hu  }
3277b753bebSXuan Hu
3287b753bebSXuan Hu  stAddrIQs.foreach {
3297b753bebSXuan Hu    case imp: IssueQueueMemAddrImp => imp.io.memIO.get.feedbackIO <> io.fromMem.get.staFeedback
3307b753bebSXuan Hu    case _ =>
3317b753bebSXuan Hu  }
332730cfbc0SXuan Hu
3339b258a00Sxgkiri  private val staIdxSeq = issueQueues.filter(iq => iq.params.StaCnt > 0).map(iq => iq.params.idxInSchBlk)
3349b258a00Sxgkiri
3359b258a00Sxgkiri  for ((idxInSchBlk, i) <- staIdxSeq.zipWithIndex) {
3369b258a00Sxgkiri    dispatch2Iq.io.out(idxInSchBlk).zip(stAddrIQs(i).io.enq).zip(stDataIQs(i).io.enq).foreach{ case((di, staIQ), stdIQ) =>
337730cfbc0SXuan Hu      val isAllReady = staIQ.ready && stdIQ.ready
338730cfbc0SXuan Hu      di.ready := isAllReady
339730cfbc0SXuan Hu      staIQ.valid := di.valid && isAllReady
340730cfbc0SXuan Hu      stdIQ.valid := di.valid && isAllReady
341730cfbc0SXuan Hu    }
3429b258a00Sxgkiri  }
343730cfbc0SXuan Hu
344730cfbc0SXuan Hu  require(stAddrIQs.size == stDataIQs.size, s"number of store address IQs(${stAddrIQs.size}) " +
345730cfbc0SXuan Hu    s"should be equal to number of data IQs(${stDataIQs})")
346730cfbc0SXuan Hu  stDataIQs.zip(stAddrIQs).zipWithIndex.foreach { case ((stdIQ, staIQ), i) =>
347730cfbc0SXuan Hu    stdIQ.io.flush <> io.fromCtrlBlock.flush
348730cfbc0SXuan Hu
349730cfbc0SXuan Hu    stdIQ.io.enq.zip(staIQ.io.enq).foreach { case (stdIQEnq, staIQEnq) =>
350730cfbc0SXuan Hu      stdIQEnq.bits  := staIQEnq.bits
351730cfbc0SXuan Hu      // Store data reuses store addr src(1) in dispatch2iq
352730cfbc0SXuan Hu      // [dispatch2iq] --src*------src*(0)--> [staIQ]
353730cfbc0SXuan Hu      //                       \
354730cfbc0SXuan Hu      //                        ---src*(1)--> [stdIQ]
355730cfbc0SXuan Hu      // Since the src(1) of sta is easier to get, stdIQEnq.bits.src*(0) is assigned to staIQEnq.bits.src*(1)
356730cfbc0SXuan Hu      // instead of dispatch2Iq.io.out(x).bits.src*(1)
357730cfbc0SXuan Hu      stdIQEnq.bits.srcState(0) := staIQEnq.bits.srcState(1)
358730cfbc0SXuan Hu      stdIQEnq.bits.srcType(0) := staIQEnq.bits.srcType(1)
359730cfbc0SXuan Hu      stdIQEnq.bits.psrc(0) := staIQEnq.bits.psrc(1)
360730cfbc0SXuan Hu      stdIQEnq.bits.sqIdx := staIQEnq.bits.sqIdx
361730cfbc0SXuan Hu    }
362bf35baadSXuan Hu    stdIQ.io.wakeupFromWB := wakeupFromWBVec
363730cfbc0SXuan Hu  }
364730cfbc0SXuan Hu
365730cfbc0SXuan Hu  val lsqEnqCtrl = Module(new LsqEnqCtrl)
366730cfbc0SXuan Hu
367730cfbc0SXuan Hu  lsqEnqCtrl.io.redirect <> io.fromCtrlBlock.flush
368730cfbc0SXuan Hu  lsqEnqCtrl.io.enq <> dispatch2Iq.io.enqLsqIO.get
369730cfbc0SXuan Hu  lsqEnqCtrl.io.lcommit := io.fromMem.get.lcommit
370730cfbc0SXuan Hu  lsqEnqCtrl.io.scommit := io.fromMem.get.scommit
371730cfbc0SXuan Hu  lsqEnqCtrl.io.lqCancelCnt := io.fromMem.get.lqCancelCnt
372730cfbc0SXuan Hu  lsqEnqCtrl.io.sqCancelCnt := io.fromMem.get.sqCancelCnt
373730cfbc0SXuan Hu  io.memIO.get.lsqEnqIO <> lsqEnqCtrl.io.enqLsq
374730cfbc0SXuan Hu}
375