xref: /XiangShan/src/main/scala/xiangshan/backend/issue/Scheduler.scala (revision bc7d694377e9068c6d69974d390752064d76fd98)
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))
79*bc7d6943SzhanglyGit    val cancelToBusyTable = Vec(backendParams.numExu, Flipped(ValidIO(new CancelSignal)))
80c0be7f33SXuan Hu    // just be compatible to old code
81c0be7f33SXuan Hu    def apply(i: Int)(j: Int) = resp(i)(j)
82c0be7f33SXuan Hu  }
83c0be7f33SXuan Hu
840f55a0d3SHaojin Tang  val loadFinalIssueResp = MixedVec(params.issueBlockParams.map(x => MixedVec(Vec(x.LduCnt, Flipped(ValidIO(new IssueQueueDeqRespBundle()(p, x)))))))
850f55a0d3SHaojin Tang
860f55a0d3SHaojin Tang  val ldCancel = Vec(backendParams.LduCnt, Flipped(new LoadCancelIO))
87c0be7f33SXuan Hu
88730cfbc0SXuan Hu  val memIO = if (params.isMemSchd) Some(new Bundle {
89730cfbc0SXuan Hu    val lsqEnqIO = Flipped(new LsqEnqIO)
90730cfbc0SXuan Hu  }) else None
91730cfbc0SXuan Hu  val fromMem = if (params.isMemSchd) Some(new Bundle {
927b753bebSXuan Hu    val ldaFeedback = Flipped(Vec(params.LduCnt, new MemRSFeedbackIO))
937b753bebSXuan Hu    val staFeedback = Flipped(Vec(params.StaCnt, new MemRSFeedbackIO))
94730cfbc0SXuan Hu    val stIssuePtr = Input(new SqPtr())
95730cfbc0SXuan Hu    val lcommit = Input(UInt(log2Up(CommitWidth + 1).W))
96730cfbc0SXuan Hu    val scommit = Input(UInt(log2Ceil(EnsbufferWidth + 1).W)) // connected to `memBlock.io.sqDeq` instead of ROB
97730cfbc0SXuan Hu    // from lsq
98730cfbc0SXuan Hu    val lqCancelCnt = Input(UInt(log2Up(LoadQueueSize + 1).W))
99730cfbc0SXuan Hu    val sqCancelCnt = Input(UInt(log2Up(StoreQueueSize + 1).W))
100730cfbc0SXuan Hu    val memWaitUpdateReq = Flipped(new MemWaitUpdateReq)
101730cfbc0SXuan Hu  }) else None
102730cfbc0SXuan Hu  val toMem = if (params.isMemSchd) Some(new Bundle {
103730cfbc0SXuan Hu    val loadFastMatch = Output(Vec(params.LduCnt, new IssueQueueLoadBundle))
104730cfbc0SXuan Hu  }) else None
105730cfbc0SXuan Hu}
106730cfbc0SXuan Hu
107730cfbc0SXuan Huabstract class SchedulerImpBase(wrapper: Scheduler)(implicit params: SchdBlockParams, p: Parameters)
108730cfbc0SXuan Hu  extends LazyModuleImp(wrapper)
109730cfbc0SXuan Hu    with HasXSParameter
110730cfbc0SXuan Hu{
111730cfbc0SXuan Hu  val io = IO(new SchedulerIO())
112730cfbc0SXuan Hu
113730cfbc0SXuan Hu  // alias
114c0be7f33SXuan Hu  private val iqWakeUpInMap: Map[Int, ValidIO[IssueQueueIQWakeUpBundle]] =
115c0be7f33SXuan Hu    io.fromSchedulers.wakeupVec.map(x => (x.bits.exuIdx, x)).toMap
116730cfbc0SXuan Hu  private val schdType = params.schdType
117730cfbc0SXuan Hu
118730cfbc0SXuan Hu  // Modules
119730cfbc0SXuan Hu  val dispatch2Iq: Dispatch2IqImp = wrapper.dispatch2Iq.module
120730cfbc0SXuan Hu  val issueQueues: Seq[IssueQueueImp] = wrapper.issueQueue.map(_.module)
121730cfbc0SXuan Hu
122730cfbc0SXuan Hu  // BusyTable Modules
123730cfbc0SXuan Hu  val intBusyTable = schdType match {
124*bc7d6943SzhanglyGit    case IntScheduler() | MemScheduler() => Some(Module(new BusyTable(dispatch2Iq.numIntStateRead, wrapper.numIntStateWrite, IntPhyRegs, IntWB())))
125730cfbc0SXuan Hu    case _ => None
126730cfbc0SXuan Hu  }
127730cfbc0SXuan Hu
128730cfbc0SXuan Hu  val vfBusyTable = schdType match {
129*bc7d6943SzhanglyGit    case VfScheduler() | MemScheduler() => Some(Module(new BusyTable(dispatch2Iq.numVfStateRead, wrapper.numVfStateWrite, VfPhyRegs, VfWB())))
130730cfbc0SXuan Hu    case _ => None
131730cfbc0SXuan Hu  }
132730cfbc0SXuan Hu
133730cfbc0SXuan Hu  dispatch2Iq.io match { case dp2iq =>
134730cfbc0SXuan Hu    dp2iq.redirect <> io.fromCtrlBlock.flush
135730cfbc0SXuan Hu    dp2iq.in <> io.fromDispatch.uops
136730cfbc0SXuan Hu    dp2iq.readIntState.foreach(_ <> intBusyTable.get.io.read)
137730cfbc0SXuan Hu    dp2iq.readVfState.foreach(_ <> vfBusyTable.get.io.read)
138730cfbc0SXuan Hu  }
139730cfbc0SXuan Hu
140730cfbc0SXuan Hu  intBusyTable match {
141730cfbc0SXuan Hu    case Some(bt) =>
142730cfbc0SXuan Hu      bt.io.allocPregs.zip(io.fromDispatch.allocPregs).foreach { case (btAllocPregs, dpAllocPregs) =>
143730cfbc0SXuan Hu        btAllocPregs.valid := dpAllocPregs.isInt
144730cfbc0SXuan Hu        btAllocPregs.bits := dpAllocPregs.preg
145730cfbc0SXuan Hu      }
146730cfbc0SXuan Hu      bt.io.wbPregs.zipWithIndex.foreach { case (wb, i) =>
147730cfbc0SXuan Hu        wb.valid := io.intWriteBack(i).wen && io.intWriteBack(i).intWen
148730cfbc0SXuan Hu        wb.bits := io.intWriteBack(i).addr
149730cfbc0SXuan Hu      }
150*bc7d6943SzhanglyGit      bt.io.wakeUp := io.fromSchedulers.wakeupVec
151*bc7d6943SzhanglyGit      bt.io.cancel := io.fromDataPath.cancelToBusyTable
152730cfbc0SXuan Hu    case None =>
153730cfbc0SXuan Hu  }
154730cfbc0SXuan Hu
155730cfbc0SXuan Hu  vfBusyTable match {
156730cfbc0SXuan Hu    case Some(bt) =>
157730cfbc0SXuan Hu      bt.io.allocPregs.zip(io.fromDispatch.allocPregs).foreach { case (btAllocPregs, dpAllocPregs) =>
158730cfbc0SXuan Hu        btAllocPregs.valid := dpAllocPregs.isFp
159730cfbc0SXuan Hu        btAllocPregs.bits := dpAllocPregs.preg
160730cfbc0SXuan Hu      }
161730cfbc0SXuan Hu      bt.io.wbPregs.zipWithIndex.foreach { case (wb, i) =>
162730cfbc0SXuan Hu        wb.valid := io.vfWriteBack(i).wen && (io.vfWriteBack(i).fpWen || io.vfWriteBack(i).vecWen)
163730cfbc0SXuan Hu        wb.bits := io.vfWriteBack(i).addr
164730cfbc0SXuan Hu      }
165*bc7d6943SzhanglyGit      bt.io.wakeUp := io.fromSchedulers.wakeupVec
166*bc7d6943SzhanglyGit      bt.io.cancel := io.fromDataPath.cancelToBusyTable
167730cfbc0SXuan Hu    case None =>
168730cfbc0SXuan Hu  }
169730cfbc0SXuan Hu
170c0be7f33SXuan Hu  val wakeupFromWBVec = Wire(params.genWBWakeUpSinkValidBundle)
171730cfbc0SXuan Hu  val writeback = params.schdType match {
172730cfbc0SXuan Hu    case IntScheduler() => io.intWriteBack
173730cfbc0SXuan Hu    case MemScheduler() => io.intWriteBack ++ io.vfWriteBack
174730cfbc0SXuan Hu    case VfScheduler() => io.vfWriteBack
175730cfbc0SXuan Hu    case _ => Seq()
176730cfbc0SXuan Hu  }
177730cfbc0SXuan Hu  wakeupFromWBVec.zip(writeback).foreach { case (sink, source) =>
178730cfbc0SXuan Hu    sink.valid := source.wen
179730cfbc0SXuan Hu    sink.bits.rfWen := source.intWen
180730cfbc0SXuan Hu    sink.bits.fpWen := source.fpWen
181730cfbc0SXuan Hu    sink.bits.vecWen := source.vecWen
182730cfbc0SXuan Hu    sink.bits.pdest := source.addr
183730cfbc0SXuan Hu  }
184730cfbc0SXuan Hu
185bf35baadSXuan Hu  // Connect bundles having the same wakeup source
18659ef6009Sxiaofeibao-xjtu  issueQueues.zipWithIndex.foreach { case(iq, i) =>
187bf35baadSXuan Hu    iq.io.wakeupFromIQ.foreach { wakeUp =>
188c0be7f33SXuan Hu      wakeUp := iqWakeUpInMap(wakeUp.bits.exuIdx)
189bf35baadSXuan Hu    }
190ea46c302SXuan Hu    iq.io.og0Cancel := io.fromDataPath.og0Cancel
191ea46c302SXuan Hu    iq.io.og1Cancel := io.fromDataPath.og1Cancel
1920f55a0d3SHaojin Tang    iq.io.ldCancel := io.ldCancel
19359ef6009Sxiaofeibao-xjtu    iq.io.fromCancelNetwork <> io.fromCancelNetwork(i)
194bf35baadSXuan Hu  }
195bf35baadSXuan Hu
196c0be7f33SXuan Hu  private val iqWakeUpOutMap: Map[Int, ValidIO[IssueQueueIQWakeUpBundle]] =
197bf35baadSXuan Hu    issueQueues.flatMap(_.io.wakeupToIQ)
198c0be7f33SXuan Hu      .map(x => (x.bits.exuIdx, x))
199bf35baadSXuan Hu      .toMap
200bf35baadSXuan Hu
201bf35baadSXuan Hu  // Connect bundles having the same wakeup source
202bf35baadSXuan Hu  io.toSchedulers.wakeupVec.foreach { wakeUp =>
203c0be7f33SXuan Hu    wakeUp := iqWakeUpOutMap(wakeUp.bits.exuIdx)
204bf35baadSXuan Hu  }
205bf35baadSXuan Hu
206730cfbc0SXuan Hu  io.toDataPath.zipWithIndex.foreach { case (toDp, i) =>
207730cfbc0SXuan Hu    toDp <> issueQueues(i).io.deq
208730cfbc0SXuan Hu  }
20959ef6009Sxiaofeibao-xjtu  io.toDataPathAfterDelay.zipWithIndex.foreach { case (toDpDy, i) =>
21059ef6009Sxiaofeibao-xjtu    toDpDy <> issueQueues(i).io.deqDelay
21159ef6009Sxiaofeibao-xjtu  }
212bf35baadSXuan Hu
213c0be7f33SXuan Hu  println(s"[Scheduler] io.fromSchedulers.wakeupVec: ${io.fromSchedulers.wakeupVec.map(x => backendParams.getExuName(x.bits.exuIdx))}")
214bf35baadSXuan Hu  println(s"[Scheduler] iqWakeUpInKeys: ${iqWakeUpInMap.keys}")
215bf35baadSXuan Hu
216bf35baadSXuan Hu  println(s"[Scheduler] iqWakeUpOutKeys: ${iqWakeUpOutMap.keys}")
217c0be7f33SXuan Hu  println(s"[Scheduler] io.toSchedulers.wakeupVec: ${io.toSchedulers.wakeupVec.map(x => backendParams.getExuName(x.bits.exuIdx))}")
218730cfbc0SXuan Hu}
219730cfbc0SXuan Hu
220730cfbc0SXuan Huclass SchedulerArithImp(override val wrapper: Scheduler)(implicit params: SchdBlockParams, p: Parameters)
221730cfbc0SXuan Hu  extends SchedulerImpBase(wrapper)
222730cfbc0SXuan Hu    with HasXSParameter
223730cfbc0SXuan Hu{
2242e0a7dc5Sfdy//  dontTouch(io.vfWbFuBusyTable)
225730cfbc0SXuan Hu  println(s"[SchedulerArithImp] " +
226730cfbc0SXuan Hu    s"has intBusyTable: ${intBusyTable.nonEmpty}, " +
227730cfbc0SXuan Hu    s"has vfBusyTable: ${vfBusyTable.nonEmpty}")
228730cfbc0SXuan Hu
229730cfbc0SXuan Hu  issueQueues.zipWithIndex.foreach { case (iq, i) =>
230730cfbc0SXuan Hu    iq.io.flush <> io.fromCtrlBlock.flush
231730cfbc0SXuan Hu    iq.io.enq <> dispatch2Iq.io.out(i)
232bf35baadSXuan Hu    iq.io.wakeupFromWB := wakeupFromWBVec
233730cfbc0SXuan Hu    iq.io.deqResp.zipWithIndex.foreach { case (deqResp, j) =>
234ea0f92d8Sczw      deqResp.valid := iq.io.deq(j).valid && io.toDataPath(i)(j).ready
235ea0f92d8Sczw      deqResp.bits.respType := RSFeedbackType.issueSuccess
2365db4956bSzhanglyGit      deqResp.bits.robIdx := iq.io.deq(j).bits.common.robIdx
2378d29ec32Sczw      deqResp.bits.rfWen := iq.io.deq(j).bits.common.rfWen.getOrElse(false.B)
2388d29ec32Sczw      deqResp.bits.fuType := iq.io.deq(j).bits.common.fuType
2398d29ec32Sczw
240730cfbc0SXuan Hu    }
241730cfbc0SXuan Hu    iq.io.og0Resp.zipWithIndex.foreach { case (og0Resp, j) =>
242730cfbc0SXuan Hu      og0Resp.valid := io.fromDataPath(i)(j).og0resp.valid
243730cfbc0SXuan Hu      og0Resp.bits.respType := io.fromDataPath(i)(j).og0resp.bits.respType
2445db4956bSzhanglyGit      og0Resp.bits.robIdx := io.fromDataPath(i)(j).og0resp.bits.robIdx
2458d29ec32Sczw      og0Resp.bits.rfWen := io.fromDataPath(i)(j).og0resp.bits.rfWen
2468d29ec32Sczw      og0Resp.bits.fuType := io.fromDataPath(i)(j).og0resp.bits.fuType
2478d29ec32Sczw
248730cfbc0SXuan Hu    }
249730cfbc0SXuan Hu    iq.io.og1Resp.zipWithIndex.foreach { case (og1Resp, j) =>
250730cfbc0SXuan Hu      og1Resp.valid := io.fromDataPath(i)(j).og1resp.valid
251730cfbc0SXuan Hu      og1Resp.bits.respType := io.fromDataPath(i)(j).og1resp.bits.respType
2525db4956bSzhanglyGit      og1Resp.bits.robIdx := io.fromDataPath(i)(j).og1resp.bits.robIdx
2538d29ec32Sczw      og1Resp.bits.rfWen := io.fromDataPath(i)(j).og1resp.bits.rfWen
2548d29ec32Sczw      og1Resp.bits.fuType := io.fromDataPath(i)(j).og1resp.bits.fuType
2558d29ec32Sczw
256730cfbc0SXuan Hu    }
2572e0a7dc5Sfdy
2582e0a7dc5Sfdy    iq.io.wbBusyTableRead := io.fromWbFuBusyTable.fuBusyTableRead(i)
259dd970561SzhanglyGit    io.wbFuBusyTable(i) := iq.io.wbBusyTableWrite
260730cfbc0SXuan Hu  }
261730cfbc0SXuan Hu
262730cfbc0SXuan Hu  val iqJumpBundleVec: Seq[IssueQueueJumpBundle] = issueQueues.map {
263730cfbc0SXuan Hu    case imp: IssueQueueIntImp => imp.io.enqJmp
264730cfbc0SXuan Hu    case _ => None
265730cfbc0SXuan Hu  }.filter(_.nonEmpty).flatMap(_.get)
266730cfbc0SXuan Hu  println(s"[Scheduler] iqJumpBundleVec: ${iqJumpBundleVec}")
267730cfbc0SXuan Hu
268730cfbc0SXuan Hu  iqJumpBundleVec.zip(io.fromCtrlBlock.pcVec zip io.fromCtrlBlock.targetVec).foreach { case (iqJmp, (pc, target)) =>
269730cfbc0SXuan Hu    iqJmp.pc := pc
270730cfbc0SXuan Hu    iqJmp.target := target
271730cfbc0SXuan Hu  }
272730cfbc0SXuan Hu}
273730cfbc0SXuan Hu
274730cfbc0SXuan Huclass SchedulerMemImp(override val wrapper: Scheduler)(implicit params: SchdBlockParams, p: Parameters)
275730cfbc0SXuan Hu  extends SchedulerImpBase(wrapper)
276730cfbc0SXuan Hu    with HasXSParameter
277730cfbc0SXuan Hu{
278730cfbc0SXuan Hu  println(s"[SchedulerMemImp] " +
279730cfbc0SXuan Hu    s"has intBusyTable: ${intBusyTable.nonEmpty}, " +
280730cfbc0SXuan Hu    s"has vfBusyTable: ${vfBusyTable.nonEmpty}")
281730cfbc0SXuan Hu
282730cfbc0SXuan Hu  val memAddrIQs = issueQueues.filter(iq => iq.params.StdCnt == 0)
283730cfbc0SXuan Hu  val stAddrIQs = issueQueues.filter(iq => iq.params.StaCnt > 0) // included in memAddrIQs
2847b753bebSXuan Hu  val ldAddrIQs = issueQueues.filter(iq => iq.params.LduCnt > 0)
285730cfbc0SXuan Hu  val stDataIQs = issueQueues.filter(iq => iq.params.StdCnt > 0)
286730cfbc0SXuan Hu  require(memAddrIQs.nonEmpty && stDataIQs.nonEmpty)
287730cfbc0SXuan Hu
288730cfbc0SXuan Hu  issueQueues.zipWithIndex.foreach { case (iq, i) =>
289730cfbc0SXuan Hu    iq.io.deqResp.zipWithIndex.foreach { case (deqResp, j) =>
290ea0f92d8Sczw      deqResp.valid := iq.io.deq(j).valid && io.toDataPath(i)(j).ready
291ea0f92d8Sczw      deqResp.bits.respType := RSFeedbackType.issueSuccess
2925db4956bSzhanglyGit      deqResp.bits.robIdx := iq.io.deq(j).bits.common.robIdx
2938d29ec32Sczw      deqResp.bits.rfWen := iq.io.deq(j).bits.common.rfWen.getOrElse(false.B)
2948d29ec32Sczw      deqResp.bits.fuType := iq.io.deq(j).bits.common.fuType
2958d29ec32Sczw
296730cfbc0SXuan Hu    }
297730cfbc0SXuan Hu    iq.io.og0Resp.zipWithIndex.foreach { case (og0Resp, j) =>
298730cfbc0SXuan Hu      og0Resp.valid := io.fromDataPath(i)(j).og0resp.valid
299730cfbc0SXuan Hu      og0Resp.bits.respType := io.fromDataPath(i)(j).og0resp.bits.respType
3005db4956bSzhanglyGit      og0Resp.bits.robIdx := io.fromDataPath(i)(j).og0resp.bits.robIdx
3018d29ec32Sczw      og0Resp.bits.rfWen := io.fromDataPath(i)(j).og0resp.bits.rfWen
3028d29ec32Sczw      og0Resp.bits.fuType := io.fromDataPath(i)(j).og0resp.bits.fuType
3038d29ec32Sczw
304730cfbc0SXuan Hu    }
305730cfbc0SXuan Hu    iq.io.og1Resp.zipWithIndex.foreach { case (og1Resp, j) =>
306730cfbc0SXuan Hu      og1Resp.valid := io.fromDataPath(i)(j).og1resp.valid
307730cfbc0SXuan Hu      og1Resp.bits.respType := io.fromDataPath(i)(j).og1resp.bits.respType
3085db4956bSzhanglyGit      og1Resp.bits.robIdx := io.fromDataPath(i)(j).og1resp.bits.robIdx
3098d29ec32Sczw      og1Resp.bits.rfWen := io.fromDataPath(i)(j).og1resp.bits.rfWen
3108d29ec32Sczw      og1Resp.bits.fuType := io.fromDataPath(i)(j).og1resp.bits.fuType
3118d29ec32Sczw
312730cfbc0SXuan Hu    }
3130f55a0d3SHaojin Tang    iq.io.finalIssueResp.foreach(_.zipWithIndex.foreach { case (finalIssueResp, j) =>
3140f55a0d3SHaojin Tang      finalIssueResp := io.loadFinalIssueResp(i)(j)
3150f55a0d3SHaojin Tang    })
3162e0a7dc5Sfdy    iq.io.wbBusyTableRead := io.fromWbFuBusyTable.fuBusyTableRead(i)
317dd970561SzhanglyGit    io.wbFuBusyTable(i) := iq.io.wbBusyTableWrite
318730cfbc0SXuan Hu  }
319730cfbc0SXuan Hu
320730cfbc0SXuan Hu  memAddrIQs.zipWithIndex.foreach { case (iq, i) =>
321730cfbc0SXuan Hu    iq.io.flush <> io.fromCtrlBlock.flush
322730cfbc0SXuan Hu    iq.io.enq <> dispatch2Iq.io.out(i)
323bf35baadSXuan Hu    iq.io.wakeupFromWB := wakeupFromWBVec
324730cfbc0SXuan Hu  }
325730cfbc0SXuan Hu
3267b753bebSXuan Hu  ldAddrIQs.foreach {
327de784418SXuan Hu    case imp: IssueQueueMemAddrImp =>
328de784418SXuan Hu      imp.io.memIO.get.feedbackIO <> io.fromMem.get.ldaFeedback
329de784418SXuan Hu      imp.io.memIO.get.checkWait.memWaitUpdateReq := io.fromMem.get.memWaitUpdateReq
3307b753bebSXuan Hu    case _ =>
3317b753bebSXuan Hu  }
3327b753bebSXuan Hu
3337b753bebSXuan Hu  stAddrIQs.foreach {
3347b753bebSXuan Hu    case imp: IssueQueueMemAddrImp => imp.io.memIO.get.feedbackIO <> io.fromMem.get.staFeedback
3357b753bebSXuan Hu    case _ =>
3367b753bebSXuan Hu  }
337730cfbc0SXuan Hu
3389b258a00Sxgkiri  private val staIdxSeq = issueQueues.filter(iq => iq.params.StaCnt > 0).map(iq => iq.params.idxInSchBlk)
3399b258a00Sxgkiri
3409b258a00Sxgkiri  for ((idxInSchBlk, i) <- staIdxSeq.zipWithIndex) {
3419b258a00Sxgkiri    dispatch2Iq.io.out(idxInSchBlk).zip(stAddrIQs(i).io.enq).zip(stDataIQs(i).io.enq).foreach{ case((di, staIQ), stdIQ) =>
342730cfbc0SXuan Hu      val isAllReady = staIQ.ready && stdIQ.ready
343730cfbc0SXuan Hu      di.ready := isAllReady
344730cfbc0SXuan Hu      staIQ.valid := di.valid && isAllReady
345730cfbc0SXuan Hu      stdIQ.valid := di.valid && isAllReady
346730cfbc0SXuan Hu    }
3479b258a00Sxgkiri  }
348730cfbc0SXuan Hu
349730cfbc0SXuan Hu  require(stAddrIQs.size == stDataIQs.size, s"number of store address IQs(${stAddrIQs.size}) " +
350730cfbc0SXuan Hu    s"should be equal to number of data IQs(${stDataIQs})")
351730cfbc0SXuan Hu  stDataIQs.zip(stAddrIQs).zipWithIndex.foreach { case ((stdIQ, staIQ), i) =>
352730cfbc0SXuan Hu    stdIQ.io.flush <> io.fromCtrlBlock.flush
353730cfbc0SXuan Hu
354730cfbc0SXuan Hu    stdIQ.io.enq.zip(staIQ.io.enq).foreach { case (stdIQEnq, staIQEnq) =>
355730cfbc0SXuan Hu      stdIQEnq.bits  := staIQEnq.bits
356730cfbc0SXuan Hu      // Store data reuses store addr src(1) in dispatch2iq
357730cfbc0SXuan Hu      // [dispatch2iq] --src*------src*(0)--> [staIQ]
358730cfbc0SXuan Hu      //                       \
359730cfbc0SXuan Hu      //                        ---src*(1)--> [stdIQ]
360730cfbc0SXuan Hu      // Since the src(1) of sta is easier to get, stdIQEnq.bits.src*(0) is assigned to staIQEnq.bits.src*(1)
361730cfbc0SXuan Hu      // instead of dispatch2Iq.io.out(x).bits.src*(1)
362730cfbc0SXuan Hu      stdIQEnq.bits.srcState(0) := staIQEnq.bits.srcState(1)
363730cfbc0SXuan Hu      stdIQEnq.bits.srcType(0) := staIQEnq.bits.srcType(1)
364*bc7d6943SzhanglyGit      stdIQEnq.bits.dataSource(0) := staIQEnq.bits.dataSource(1)
365*bc7d6943SzhanglyGit      stdIQEnq.bits.l1ExuOH(0) := staIQEnq.bits.l1ExuOH(1)
366730cfbc0SXuan Hu      stdIQEnq.bits.psrc(0) := staIQEnq.bits.psrc(1)
367730cfbc0SXuan Hu      stdIQEnq.bits.sqIdx := staIQEnq.bits.sqIdx
368730cfbc0SXuan Hu    }
369bf35baadSXuan Hu    stdIQ.io.wakeupFromWB := wakeupFromWBVec
370730cfbc0SXuan Hu  }
371730cfbc0SXuan Hu
372730cfbc0SXuan Hu  val lsqEnqCtrl = Module(new LsqEnqCtrl)
373730cfbc0SXuan Hu
374730cfbc0SXuan Hu  lsqEnqCtrl.io.redirect <> io.fromCtrlBlock.flush
375730cfbc0SXuan Hu  lsqEnqCtrl.io.enq <> dispatch2Iq.io.enqLsqIO.get
376730cfbc0SXuan Hu  lsqEnqCtrl.io.lcommit := io.fromMem.get.lcommit
377730cfbc0SXuan Hu  lsqEnqCtrl.io.scommit := io.fromMem.get.scommit
378730cfbc0SXuan Hu  lsqEnqCtrl.io.lqCancelCnt := io.fromMem.get.lqCancelCnt
379730cfbc0SXuan Hu  lsqEnqCtrl.io.sqCancelCnt := io.fromMem.get.sqCancelCnt
380730cfbc0SXuan Hu  io.memIO.get.lsqEnqIO <> lsqEnqCtrl.io.enqLsq
381730cfbc0SXuan Hu}
382