xref: /XiangShan/src/main/scala/xiangshan/backend/issue/Scheduler.scala (revision c0be7f3326dfca5bea51a5a98f3c07e847728c49)
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._
8730cfbc0SXuan Huimport xiangshan.backend.Bundles
9730cfbc0SXuan Huimport xiangshan.backend.datapath.DataConfig.VAddrData
10730cfbc0SXuan Huimport xiangshan.backend.regfile.RfWritePortWithConfig
11730cfbc0SXuan Huimport xiangshan.backend.rename.BusyTable
12730cfbc0SXuan Huimport xiangshan.mem.{LsqEnqCtrl, LsqEnqIO, MemWaitUpdateReq, SqPtr}
13*c0be7f33SXuan Huimport xiangshan.backend.Bundles.{DynInst, IssueQueueCancelBundle, IssueQueueIQWakeUpBundle, IssueQueueWBWakeUpBundle}
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 {
23730cfbc0SXuan Hu  val numIntStateWrite = backendParams.numIntWb
24730cfbc0SXuan Hu  val numVfStateWrite = backendParams.numVfWb
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
37730cfbc0SXuan Huclass SchedulerIO()(implicit params: SchdBlockParams, p: Parameters) extends XSBundle {
3868d13085SXuan Hu  // params alias
3968d13085SXuan Hu  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  }
58730cfbc0SXuan Hu  val intWriteBack = MixedVec(Vec(backendParams.intPregParams.numWrite,
59730cfbc0SXuan Hu    new RfWritePortWithConfig(backendParams.intPregParams.dataCfg, backendParams.intPregParams.addrWidth)))
60730cfbc0SXuan Hu  val vfWriteBack = MixedVec(Vec(backendParams.vfPregParams.numWrite,
61730cfbc0SXuan Hu    new RfWritePortWithConfig(backendParams.vfPregParams.dataCfg, backendParams.vfPregParams.addrWidth)))
62730cfbc0SXuan Hu  val toDataPath: MixedVec[MixedVec[DecoupledIO[Bundles.IssueQueueIssueBundle]]] = MixedVec(params.issueBlockParams.map(_.genIssueDecoupledBundle))
63730cfbc0SXuan Hu
64bf35baadSXuan Hu  val fromSchedulers = new Bundle {
65*c0be7f33SXuan Hu    val wakeupVec: MixedVec[ValidIO[IssueQueueIQWakeUpBundle]] = Flipped(params.genIQWakeUpInValidBundle)
66bf35baadSXuan Hu  }
67bf35baadSXuan Hu
68bf35baadSXuan Hu  val toSchedulers = new Bundle {
69*c0be7f33SXuan Hu    val wakeupVec: MixedVec[ValidIO[IssueQueueIQWakeUpBundle]] = params.genIQWakeUpOutValidBundle
70bf35baadSXuan Hu  }
71bf35baadSXuan Hu
72*c0be7f33SXuan Hu  val fromDataPath = new Bundle {
73*c0be7f33SXuan Hu    val resp: MixedVec[MixedVec[Bundles.OGRespBundle]] = MixedVec(params.issueBlockParams.map(x => Flipped(x.genOGRespBundle)))
74*c0be7f33SXuan Hu    val cancel: MixedVec[IssueQueueCancelBundle] = Input(MixedVec(params.genCancelBundle(cancelStages)))
75*c0be7f33SXuan Hu    // just be compatible to old code
76*c0be7f33SXuan Hu    def apply(i: Int)(j: Int) = resp(i)(j)
77*c0be7f33SXuan Hu  }
78*c0be7f33SXuan Hu
79*c0be7f33SXuan Hu
80730cfbc0SXuan Hu  val memIO = if (params.isMemSchd) Some(new Bundle {
81730cfbc0SXuan Hu    val lsqEnqIO = Flipped(new LsqEnqIO)
82730cfbc0SXuan Hu  }) else None
83730cfbc0SXuan Hu  val fromMem = if (params.isMemSchd) Some(new Bundle {
847b753bebSXuan Hu    val ldaFeedback = Flipped(Vec(params.LduCnt, new MemRSFeedbackIO))
857b753bebSXuan Hu    val staFeedback = Flipped(Vec(params.StaCnt, new MemRSFeedbackIO))
86730cfbc0SXuan Hu    val stIssuePtr = Input(new SqPtr())
87730cfbc0SXuan Hu    val lcommit = Input(UInt(log2Up(CommitWidth + 1).W))
88730cfbc0SXuan Hu    val scommit = Input(UInt(log2Ceil(EnsbufferWidth + 1).W)) // connected to `memBlock.io.sqDeq` instead of ROB
89730cfbc0SXuan Hu    // from lsq
90730cfbc0SXuan Hu    val lqCancelCnt = Input(UInt(log2Up(LoadQueueSize + 1).W))
91730cfbc0SXuan Hu    val sqCancelCnt = Input(UInt(log2Up(StoreQueueSize + 1).W))
92730cfbc0SXuan Hu    val memWaitUpdateReq = Flipped(new MemWaitUpdateReq)
93730cfbc0SXuan Hu  }) else None
94730cfbc0SXuan Hu  val toMem = if (params.isMemSchd) Some(new Bundle {
95730cfbc0SXuan Hu    val loadFastMatch = Output(Vec(params.LduCnt, new IssueQueueLoadBundle))
96730cfbc0SXuan Hu  }) else None
97730cfbc0SXuan Hu}
98730cfbc0SXuan Hu
99730cfbc0SXuan Huabstract class SchedulerImpBase(wrapper: Scheduler)(implicit params: SchdBlockParams, p: Parameters)
100730cfbc0SXuan Hu  extends LazyModuleImp(wrapper)
101730cfbc0SXuan Hu    with HasXSParameter
102730cfbc0SXuan Hu{
103730cfbc0SXuan Hu  val io = IO(new SchedulerIO())
104730cfbc0SXuan Hu
105730cfbc0SXuan Hu  // alias
106*c0be7f33SXuan Hu  private val iqWakeUpInMap: Map[Int, ValidIO[IssueQueueIQWakeUpBundle]] =
107*c0be7f33SXuan Hu    io.fromSchedulers.wakeupVec.map(x => (x.bits.exuIdx, x)).toMap
108730cfbc0SXuan Hu  private val schdType = params.schdType
109730cfbc0SXuan Hu  private val (numRfRead, numRfWrite) = params.numRfReadWrite.getOrElse((0, 0))
110730cfbc0SXuan Hu  private val numPregs = params.numPregs
111730cfbc0SXuan Hu
112730cfbc0SXuan Hu  // Modules
113730cfbc0SXuan Hu  val dispatch2Iq: Dispatch2IqImp = wrapper.dispatch2Iq.module
114730cfbc0SXuan Hu  val issueQueues: Seq[IssueQueueImp] = wrapper.issueQueue.map(_.module)
115730cfbc0SXuan Hu
116730cfbc0SXuan Hu  // BusyTable Modules
117730cfbc0SXuan Hu  val intBusyTable = schdType match {
118730cfbc0SXuan Hu    case IntScheduler() | MemScheduler() => Some(Module(new BusyTable(dispatch2Iq.numIntStateRead, wrapper.numIntStateWrite)))
119730cfbc0SXuan Hu    case _ => None
120730cfbc0SXuan Hu  }
121730cfbc0SXuan Hu
122730cfbc0SXuan Hu  val vfBusyTable = schdType match {
123730cfbc0SXuan Hu    case VfScheduler() | MemScheduler() => Some(Module(new BusyTable(dispatch2Iq.numVfStateRead, wrapper.numVfStateWrite)))
124730cfbc0SXuan Hu    case _ => None
125730cfbc0SXuan Hu  }
126730cfbc0SXuan Hu
127730cfbc0SXuan Hu  dispatch2Iq.io match { case dp2iq =>
128730cfbc0SXuan Hu    dp2iq.redirect <> io.fromCtrlBlock.flush
129730cfbc0SXuan Hu    dp2iq.in <> io.fromDispatch.uops
130730cfbc0SXuan Hu    dp2iq.readIntState.foreach(_ <> intBusyTable.get.io.read)
131730cfbc0SXuan Hu    dp2iq.readVfState.foreach(_ <> vfBusyTable.get.io.read)
132730cfbc0SXuan Hu  }
133730cfbc0SXuan Hu
134730cfbc0SXuan Hu  intBusyTable match {
135730cfbc0SXuan Hu    case Some(bt) =>
136730cfbc0SXuan Hu      bt.io.allocPregs.zip(io.fromDispatch.allocPregs).foreach { case (btAllocPregs, dpAllocPregs) =>
137730cfbc0SXuan Hu        btAllocPregs.valid := dpAllocPregs.isInt
138730cfbc0SXuan Hu        btAllocPregs.bits := dpAllocPregs.preg
139730cfbc0SXuan Hu      }
140730cfbc0SXuan Hu      bt.io.wbPregs.zipWithIndex.foreach { case (wb, i) =>
141730cfbc0SXuan Hu        wb.valid := io.intWriteBack(i).wen && io.intWriteBack(i).intWen
142730cfbc0SXuan Hu        wb.bits := io.intWriteBack(i).addr
143730cfbc0SXuan Hu      }
144730cfbc0SXuan Hu    case None =>
145730cfbc0SXuan Hu  }
146730cfbc0SXuan Hu
147730cfbc0SXuan Hu  vfBusyTable match {
148730cfbc0SXuan Hu    case Some(bt) =>
149730cfbc0SXuan Hu      bt.io.allocPregs.zip(io.fromDispatch.allocPregs).foreach { case (btAllocPregs, dpAllocPregs) =>
150730cfbc0SXuan Hu        btAllocPregs.valid := dpAllocPregs.isFp
151730cfbc0SXuan Hu        btAllocPregs.bits := dpAllocPregs.preg
152730cfbc0SXuan Hu      }
153730cfbc0SXuan Hu      bt.io.wbPregs.zipWithIndex.foreach { case (wb, i) =>
154730cfbc0SXuan Hu        wb.valid := io.vfWriteBack(i).wen && (io.vfWriteBack(i).fpWen || io.vfWriteBack(i).vecWen)
155730cfbc0SXuan Hu        wb.bits := io.vfWriteBack(i).addr
156730cfbc0SXuan Hu      }
157730cfbc0SXuan Hu    case None =>
158730cfbc0SXuan Hu  }
159730cfbc0SXuan Hu
160*c0be7f33SXuan Hu  val wakeupFromWBVec = Wire(params.genWBWakeUpSinkValidBundle)
161730cfbc0SXuan Hu  val writeback = params.schdType match {
162730cfbc0SXuan Hu    case IntScheduler() => io.intWriteBack
163730cfbc0SXuan Hu    case MemScheduler() => io.intWriteBack ++ io.vfWriteBack
164730cfbc0SXuan Hu    case VfScheduler() => io.vfWriteBack
165730cfbc0SXuan Hu    case _ => Seq()
166730cfbc0SXuan Hu  }
167730cfbc0SXuan Hu  wakeupFromWBVec.zip(writeback).foreach { case (sink, source) =>
168730cfbc0SXuan Hu    sink.valid := source.wen
169730cfbc0SXuan Hu    sink.bits.rfWen := source.intWen
170730cfbc0SXuan Hu    sink.bits.fpWen := source.fpWen
171730cfbc0SXuan Hu    sink.bits.vecWen := source.vecWen
172730cfbc0SXuan Hu    sink.bits.pdest := source.addr
173730cfbc0SXuan Hu  }
174730cfbc0SXuan Hu
175bf35baadSXuan Hu  // Connect bundles having the same wakeup source
176bf35baadSXuan Hu  issueQueues.foreach { iq =>
177bf35baadSXuan Hu    iq.io.wakeupFromIQ.foreach { wakeUp =>
178*c0be7f33SXuan Hu      wakeUp := iqWakeUpInMap(wakeUp.bits.exuIdx)
179bf35baadSXuan Hu    }
180*c0be7f33SXuan Hu    iq.io.cancelFromDataPath.map (sink => {
181*c0be7f33SXuan Hu      sink.cancelVec := io.fromDataPath.cancel.find(_.exuIdx == sink.exuIdx).get.cancelVec
182*c0be7f33SXuan Hu    })
183bf35baadSXuan Hu  }
184bf35baadSXuan Hu
185*c0be7f33SXuan Hu  private val iqWakeUpOutMap: Map[Int, ValidIO[IssueQueueIQWakeUpBundle]] =
186bf35baadSXuan Hu    issueQueues.flatMap(_.io.wakeupToIQ)
187*c0be7f33SXuan Hu      .map(x => (x.bits.exuIdx, x))
188bf35baadSXuan Hu      .toMap
189bf35baadSXuan Hu
190bf35baadSXuan Hu  // Connect bundles having the same wakeup source
191bf35baadSXuan Hu  io.toSchedulers.wakeupVec.foreach { wakeUp =>
192*c0be7f33SXuan Hu    wakeUp := iqWakeUpOutMap(wakeUp.bits.exuIdx)
193bf35baadSXuan Hu  }
194bf35baadSXuan Hu
195730cfbc0SXuan Hu  io.toDataPath.zipWithIndex.foreach { case (toDp, i) =>
196730cfbc0SXuan Hu    toDp <> issueQueues(i).io.deq
197730cfbc0SXuan Hu  }
198bf35baadSXuan Hu
199*c0be7f33SXuan Hu  println(s"[Scheduler] io.fromSchedulers.wakeupVec: ${io.fromSchedulers.wakeupVec.map(x => backendParams.getExuName(x.bits.exuIdx))}")
200bf35baadSXuan Hu  println(s"[Scheduler] iqWakeUpInKeys: ${iqWakeUpInMap.keys}")
201bf35baadSXuan Hu
202bf35baadSXuan Hu  println(s"[Scheduler] iqWakeUpOutKeys: ${iqWakeUpOutMap.keys}")
203*c0be7f33SXuan Hu  println(s"[Scheduler] io.toSchedulers.wakeupVec: ${io.toSchedulers.wakeupVec.map(x => backendParams.getExuName(x.bits.exuIdx))}")
204730cfbc0SXuan Hu}
205730cfbc0SXuan Hu
206730cfbc0SXuan Huclass SchedulerArithImp(override val wrapper: Scheduler)(implicit params: SchdBlockParams, p: Parameters)
207730cfbc0SXuan Hu  extends SchedulerImpBase(wrapper)
208730cfbc0SXuan Hu    with HasXSParameter
209730cfbc0SXuan Hu{
2102e0a7dc5Sfdy//  dontTouch(io.vfWbFuBusyTable)
211730cfbc0SXuan Hu  println(s"[SchedulerArithImp] " +
212730cfbc0SXuan Hu    s"has intBusyTable: ${intBusyTable.nonEmpty}, " +
213730cfbc0SXuan Hu    s"has vfBusyTable: ${vfBusyTable.nonEmpty}")
214730cfbc0SXuan Hu
215730cfbc0SXuan Hu  issueQueues.zipWithIndex.foreach { case (iq, i) =>
216730cfbc0SXuan Hu    iq.io.flush <> io.fromCtrlBlock.flush
217730cfbc0SXuan Hu    iq.io.enq <> dispatch2Iq.io.out(i)
218bf35baadSXuan Hu    iq.io.wakeupFromWB := wakeupFromWBVec
219730cfbc0SXuan Hu    iq.io.deqResp.zipWithIndex.foreach { case (deqResp, j) =>
220ea0f92d8Sczw      deqResp.valid := iq.io.deq(j).valid && io.toDataPath(i)(j).ready
221ea0f92d8Sczw      deqResp.bits.respType := RSFeedbackType.issueSuccess
222730cfbc0SXuan Hu      deqResp.bits.addrOH := iq.io.deq(j).bits.addrOH
2238d29ec32Sczw      deqResp.bits.rfWen := iq.io.deq(j).bits.common.rfWen.getOrElse(false.B)
2248d29ec32Sczw      deqResp.bits.fuType := iq.io.deq(j).bits.common.fuType
2258d29ec32Sczw
226730cfbc0SXuan Hu    }
227730cfbc0SXuan Hu    iq.io.og0Resp.zipWithIndex.foreach { case (og0Resp, j) =>
228730cfbc0SXuan Hu      og0Resp.valid := io.fromDataPath(i)(j).og0resp.valid
229730cfbc0SXuan Hu      og0Resp.bits.respType := io.fromDataPath(i)(j).og0resp.bits.respType
230730cfbc0SXuan Hu      og0Resp.bits.addrOH := io.fromDataPath(i)(j).og0resp.bits.addrOH
2318d29ec32Sczw      og0Resp.bits.rfWen := io.fromDataPath(i)(j).og0resp.bits.rfWen
2328d29ec32Sczw      og0Resp.bits.fuType := io.fromDataPath(i)(j).og0resp.bits.fuType
2338d29ec32Sczw
234730cfbc0SXuan Hu    }
235730cfbc0SXuan Hu    iq.io.og1Resp.zipWithIndex.foreach { case (og1Resp, j) =>
236730cfbc0SXuan Hu      og1Resp.valid := io.fromDataPath(i)(j).og1resp.valid
237730cfbc0SXuan Hu      og1Resp.bits.respType := io.fromDataPath(i)(j).og1resp.bits.respType
238730cfbc0SXuan Hu      og1Resp.bits.addrOH := io.fromDataPath(i)(j).og1resp.bits.addrOH
2398d29ec32Sczw      og1Resp.bits.rfWen := io.fromDataPath(i)(j).og1resp.bits.rfWen
2408d29ec32Sczw      og1Resp.bits.fuType := io.fromDataPath(i)(j).og1resp.bits.fuType
2418d29ec32Sczw
242730cfbc0SXuan Hu    }
2432e0a7dc5Sfdy
2442e0a7dc5Sfdy    iq.io.wbBusyTableRead := io.fromWbFuBusyTable.fuBusyTableRead(i)
245dd970561SzhanglyGit    io.wbFuBusyTable(i) := iq.io.wbBusyTableWrite
246730cfbc0SXuan Hu  }
247730cfbc0SXuan Hu
248730cfbc0SXuan Hu  val iqJumpBundleVec: Seq[IssueQueueJumpBundle] = issueQueues.map {
249730cfbc0SXuan Hu    case imp: IssueQueueIntImp => imp.io.enqJmp
250730cfbc0SXuan Hu    case _ => None
251730cfbc0SXuan Hu  }.filter(_.nonEmpty).flatMap(_.get)
252730cfbc0SXuan Hu  println(s"[Scheduler] iqJumpBundleVec: ${iqJumpBundleVec}")
253730cfbc0SXuan Hu
254730cfbc0SXuan Hu  iqJumpBundleVec.zip(io.fromCtrlBlock.pcVec zip io.fromCtrlBlock.targetVec).foreach { case (iqJmp, (pc, target)) =>
255730cfbc0SXuan Hu    iqJmp.pc := pc
256730cfbc0SXuan Hu    iqJmp.target := target
257730cfbc0SXuan Hu  }
258730cfbc0SXuan Hu}
259730cfbc0SXuan Hu
260730cfbc0SXuan Huclass SchedulerMemImp(override val wrapper: Scheduler)(implicit params: SchdBlockParams, p: Parameters)
261730cfbc0SXuan Hu  extends SchedulerImpBase(wrapper)
262730cfbc0SXuan Hu    with HasXSParameter
263730cfbc0SXuan Hu{
264730cfbc0SXuan Hu  println(s"[SchedulerMemImp] " +
265730cfbc0SXuan Hu    s"has intBusyTable: ${intBusyTable.nonEmpty}, " +
266730cfbc0SXuan Hu    s"has vfBusyTable: ${vfBusyTable.nonEmpty}")
267730cfbc0SXuan Hu
268730cfbc0SXuan Hu  val memAddrIQs = issueQueues.filter(iq => iq.params.StdCnt == 0)
269730cfbc0SXuan Hu  val stAddrIQs = issueQueues.filter(iq => iq.params.StaCnt > 0) // included in memAddrIQs
2707b753bebSXuan Hu  val ldAddrIQs = issueQueues.filter(iq => iq.params.LduCnt > 0)
271730cfbc0SXuan Hu  val stDataIQs = issueQueues.filter(iq => iq.params.StdCnt > 0)
272730cfbc0SXuan Hu  require(memAddrIQs.nonEmpty && stDataIQs.nonEmpty)
273730cfbc0SXuan Hu
274730cfbc0SXuan Hu  issueQueues.zipWithIndex.foreach { case (iq, i) =>
275730cfbc0SXuan Hu    iq.io.deqResp.zipWithIndex.foreach { case (deqResp, j) =>
276ea0f92d8Sczw      deqResp.valid := iq.io.deq(j).valid && io.toDataPath(i)(j).ready
277ea0f92d8Sczw      deqResp.bits.respType := RSFeedbackType.issueSuccess
278730cfbc0SXuan Hu      deqResp.bits.addrOH := iq.io.deq(j).bits.addrOH
2798d29ec32Sczw      deqResp.bits.rfWen := iq.io.deq(j).bits.common.rfWen.getOrElse(false.B)
2808d29ec32Sczw      deqResp.bits.fuType := iq.io.deq(j).bits.common.fuType
2818d29ec32Sczw
282730cfbc0SXuan Hu    }
283730cfbc0SXuan Hu    iq.io.og0Resp.zipWithIndex.foreach { case (og0Resp, j) =>
284730cfbc0SXuan Hu      og0Resp.valid := io.fromDataPath(i)(j).og0resp.valid
285730cfbc0SXuan Hu      og0Resp.bits.respType := io.fromDataPath(i)(j).og0resp.bits.respType
286730cfbc0SXuan Hu      og0Resp.bits.addrOH := io.fromDataPath(i)(j).og0resp.bits.addrOH
2878d29ec32Sczw      og0Resp.bits.rfWen := io.fromDataPath(i)(j).og0resp.bits.rfWen
2888d29ec32Sczw      og0Resp.bits.fuType := io.fromDataPath(i)(j).og0resp.bits.fuType
2898d29ec32Sczw
290730cfbc0SXuan Hu    }
291730cfbc0SXuan Hu    iq.io.og1Resp.zipWithIndex.foreach { case (og1Resp, j) =>
292730cfbc0SXuan Hu      og1Resp.valid := io.fromDataPath(i)(j).og1resp.valid
293730cfbc0SXuan Hu      og1Resp.bits.respType := io.fromDataPath(i)(j).og1resp.bits.respType
294730cfbc0SXuan Hu      og1Resp.bits.addrOH := io.fromDataPath(i)(j).og1resp.bits.addrOH
2958d29ec32Sczw      og1Resp.bits.rfWen := io.fromDataPath(i)(j).og1resp.bits.rfWen
2968d29ec32Sczw      og1Resp.bits.fuType := io.fromDataPath(i)(j).og1resp.bits.fuType
2978d29ec32Sczw
298730cfbc0SXuan Hu    }
2992e0a7dc5Sfdy    iq.io.wbBusyTableRead := io.fromWbFuBusyTable.fuBusyTableRead(i)
300dd970561SzhanglyGit    io.wbFuBusyTable(i) := iq.io.wbBusyTableWrite
301730cfbc0SXuan Hu  }
302730cfbc0SXuan Hu
303730cfbc0SXuan Hu  memAddrIQs.zipWithIndex.foreach { case (iq, i) =>
304730cfbc0SXuan Hu    iq.io.flush <> io.fromCtrlBlock.flush
305730cfbc0SXuan Hu    iq.io.enq <> dispatch2Iq.io.out(i)
306bf35baadSXuan Hu    iq.io.wakeupFromWB := wakeupFromWBVec
307730cfbc0SXuan Hu  }
308730cfbc0SXuan Hu
3097b753bebSXuan Hu  ldAddrIQs.foreach {
3107b753bebSXuan Hu    case imp: IssueQueueMemAddrImp => imp.io.memIO.get.feedbackIO <> io.fromMem.get.ldaFeedback
3117b753bebSXuan Hu    case _ =>
3127b753bebSXuan Hu  }
3137b753bebSXuan Hu
3147b753bebSXuan Hu  stAddrIQs.foreach {
3157b753bebSXuan Hu    case imp: IssueQueueMemAddrImp => imp.io.memIO.get.feedbackIO <> io.fromMem.get.staFeedback
3167b753bebSXuan Hu    case _ =>
3177b753bebSXuan Hu  }
318730cfbc0SXuan Hu
3199b258a00Sxgkiri  private val staIdxSeq = issueQueues.filter(iq => iq.params.StaCnt > 0).map(iq => iq.params.idxInSchBlk)
3209b258a00Sxgkiri
3219b258a00Sxgkiri  for ((idxInSchBlk, i) <- staIdxSeq.zipWithIndex) {
3229b258a00Sxgkiri    dispatch2Iq.io.out(idxInSchBlk).zip(stAddrIQs(i).io.enq).zip(stDataIQs(i).io.enq).foreach{ case((di, staIQ), stdIQ) =>
323730cfbc0SXuan Hu      val isAllReady = staIQ.ready && stdIQ.ready
324730cfbc0SXuan Hu      di.ready := isAllReady
325730cfbc0SXuan Hu      staIQ.valid := di.valid && isAllReady
326730cfbc0SXuan Hu      stdIQ.valid := di.valid && isAllReady
327730cfbc0SXuan Hu    }
3289b258a00Sxgkiri  }
329730cfbc0SXuan Hu
330730cfbc0SXuan Hu  require(stAddrIQs.size == stDataIQs.size, s"number of store address IQs(${stAddrIQs.size}) " +
331730cfbc0SXuan Hu    s"should be equal to number of data IQs(${stDataIQs})")
332730cfbc0SXuan Hu  stDataIQs.zip(stAddrIQs).zipWithIndex.foreach { case ((stdIQ, staIQ), i) =>
333730cfbc0SXuan Hu    stdIQ.io.flush <> io.fromCtrlBlock.flush
334730cfbc0SXuan Hu
335730cfbc0SXuan Hu    stdIQ.io.enq.zip(staIQ.io.enq).foreach { case (stdIQEnq, staIQEnq) =>
336730cfbc0SXuan Hu      stdIQEnq.bits  := staIQEnq.bits
337730cfbc0SXuan Hu      // Store data reuses store addr src(1) in dispatch2iq
338730cfbc0SXuan Hu      // [dispatch2iq] --src*------src*(0)--> [staIQ]
339730cfbc0SXuan Hu      //                       \
340730cfbc0SXuan Hu      //                        ---src*(1)--> [stdIQ]
341730cfbc0SXuan Hu      // Since the src(1) of sta is easier to get, stdIQEnq.bits.src*(0) is assigned to staIQEnq.bits.src*(1)
342730cfbc0SXuan Hu      // instead of dispatch2Iq.io.out(x).bits.src*(1)
343730cfbc0SXuan Hu      stdIQEnq.bits.srcState(0) := staIQEnq.bits.srcState(1)
344730cfbc0SXuan Hu      stdIQEnq.bits.srcType(0) := staIQEnq.bits.srcType(1)
345730cfbc0SXuan Hu      stdIQEnq.bits.psrc(0) := staIQEnq.bits.psrc(1)
346730cfbc0SXuan Hu      stdIQEnq.bits.sqIdx := staIQEnq.bits.sqIdx
347730cfbc0SXuan Hu    }
348bf35baadSXuan Hu    stdIQ.io.wakeupFromWB := wakeupFromWBVec
349730cfbc0SXuan Hu  }
350730cfbc0SXuan Hu
351730cfbc0SXuan Hu  val lsqEnqCtrl = Module(new LsqEnqCtrl)
352730cfbc0SXuan Hu
353730cfbc0SXuan Hu  lsqEnqCtrl.io.redirect <> io.fromCtrlBlock.flush
354730cfbc0SXuan Hu  lsqEnqCtrl.io.enq <> dispatch2Iq.io.enqLsqIO.get
355730cfbc0SXuan Hu  lsqEnqCtrl.io.lcommit := io.fromMem.get.lcommit
356730cfbc0SXuan Hu  lsqEnqCtrl.io.scommit := io.fromMem.get.scommit
357730cfbc0SXuan Hu  lsqEnqCtrl.io.lqCancelCnt := io.fromMem.get.lqCancelCnt
358730cfbc0SXuan Hu  lsqEnqCtrl.io.sqCancelCnt := io.fromMem.get.sqCancelCnt
359730cfbc0SXuan Hu  io.memIO.get.lsqEnqIO <> lsqEnqCtrl.io.enqLsq
360730cfbc0SXuan Hu}
361