xref: /XiangShan/src/main/scala/xiangshan/backend/issue/Entries.scala (revision 99ce5576f0ecce1b5045b7bc0dbbb2debd934fbb)
15db4956bSzhanglyGitpackage xiangshan.backend.issue
25db4956bSzhanglyGit
383ba63b3SXuan Huimport org.chipsalliance.cde.config.Parameters
45db4956bSzhanglyGitimport chisel3._
55db4956bSzhanglyGitimport chisel3.util._
65db4956bSzhanglyGitimport utility.HasCircularQueuePtrHelper
7a6938b17Ssinsanctionimport utils._
84fa640e4Ssinsanctionimport utility._
95db4956bSzhanglyGitimport xiangshan._
105db4956bSzhanglyGitimport xiangshan.backend.Bundles._
115db4956bSzhanglyGitimport xiangshan.backend.datapath.DataConfig.VAddrData
125db4956bSzhanglyGitimport xiangshan.backend.datapath.DataSource
135db4956bSzhanglyGitimport xiangshan.backend.fu.FuType
145db4956bSzhanglyGitimport xiangshan.backend.fu.vector.Utils.NOnes
155db4956bSzhanglyGitimport xiangshan.backend.rob.RobPtr
16aa2bcc31SzhanglyGitimport xiangshan.backend.issue.EntryBundles._
179e12e8edScz4eimport xiangshan.mem.{LqPtr, SqPtr}
18*99ce5576Scz4eimport xiangshan.mem.Bundles.MemWaitUpdateReqBundle
195db4956bSzhanglyGit
205db4956bSzhanglyGitclass Entries(implicit p: Parameters, params: IssueBlockParams) extends XSModule {
210721d1aaSXuan Hu  override def desiredName: String = params.getEntryName
220721d1aaSXuan Hu
2327811ea4SXuan Hu  require(params.numEnq <= 2, "number of enq should be no more than 2")
2427811ea4SXuan Hu
255db4956bSzhanglyGit  private val EnqEntryNum         = params.numEnq
265db4956bSzhanglyGit  private val OthersEntryNum      = params.numEntries - params.numEnq
2728607074Ssinsanction  private val SimpEntryNum        = params.numSimp
2828607074Ssinsanction  private val CompEntryNum        = params.numComp
295db4956bSzhanglyGit  val io = IO(new EntriesIO)
305db4956bSzhanglyGit
31c838dea1SXuan Hu  // only memAddrIQ use it
327e471bf8SXuan Hu  val memEtyResps: Seq[ValidIO[EntryDeqRespBundle]] = {
337e471bf8SXuan Hu    val resps =
34d3372210SzhanglyGit      if (params.isLdAddrIQ && !params.isStAddrIQ)                                                    //LDU
35dd40a82bSsinsanction        Seq(io.fromLoad.get.finalIssueResp, io.fromLoad.get.memAddrIssueResp)
36d3372210SzhanglyGit      else if (params.isLdAddrIQ && params.isStAddrIQ || params.isHyAddrIQ)                           //HYU
37dd40a82bSsinsanction        Seq(io.fromLoad.get.finalIssueResp, io.fromLoad.get.memAddrIssueResp, io.fromMem.get.fastResp, io.fromMem.get.slowResp)
387e471bf8SXuan Hu      else if (params.isStAddrIQ)                                                                     //STU
39dd40a82bSsinsanction        Seq(io.fromMem.get.slowResp)
408f3cbbcfSXuan Hu      else if (params.isVecLduIQ && params.isVecStuIQ) // Vector store IQ need no vecLdIn.resp, but for now vector store share the vector load IQ
413bba894fSxiaofeibao        Seq(io.vecLdIn.get.resp, io.fromMem.get.slowResp, io.vecLdIn.get.finalIssueResp)
427e471bf8SXuan Hu      else Seq()
437e471bf8SXuan Hu    if (params.isMemAddrIQ) {
447e471bf8SXuan Hu      println(s"[${this.desiredName}] resp: {" +
457e471bf8SXuan Hu        s"og0Resp: ${resps.contains(io.og0Resp)}, " +
467e471bf8SXuan Hu        s"og1Resp: ${resps.contains(io.og1Resp)}, " +
477e471bf8SXuan Hu        s"finalResp: ${io.fromLoad.nonEmpty && resps.contains(io.fromLoad.get.finalIssueResp)}, " +
487e471bf8SXuan Hu        s"loadBorderResp: ${io.fromLoad.nonEmpty && resps.contains(io.fromLoad.get.memAddrIssueResp)}, " +
497e471bf8SXuan Hu        s"memFastResp: ${io.fromMem.nonEmpty && resps.contains(io.fromMem.get.fastResp)}, " +
507e471bf8SXuan Hu        s"memSlowResp: ${io.fromMem.nonEmpty && resps.contains(io.fromMem.get.slowResp)}, " +
517e471bf8SXuan Hu        s"vecLoadBorderResp: ${io.vecLdIn.nonEmpty && resps.contains(io.vecLdIn.get.resp)}, " +
527e471bf8SXuan Hu        s"}"
537e471bf8SXuan Hu      )
547e471bf8SXuan Hu    }
557e471bf8SXuan Hu    resps.flatten
56c838dea1SXuan Hu  }
57c838dea1SXuan Hu
58ae0295f4STang Haojin  val resps: Vec[Vec[ValidIO[EntryDeqRespBundle]]] = Wire(Vec(4, chiselTypeOf(io.og0Resp)))
59ae0295f4STang Haojin
6042b6cdf9Ssinsanction  if (params.needOg2Resp)
61ae0295f4STang Haojin    resps := Seq(io.og0Resp, io.og1Resp, io.og2Resp.get, WireDefault(0.U.asTypeOf(io.og0Resp)))
62c38df446SzhanglyGit  else
63ae0295f4STang Haojin    resps := Seq(io.og0Resp, io.og1Resp, WireDefault(0.U.asTypeOf(io.og0Resp)), WireDefault(0.U.asTypeOf(io.og0Resp)))
645db4956bSzhanglyGit
657e471bf8SXuan Hu
667e471bf8SXuan Hu
675db4956bSzhanglyGit  //Module
68df26db8aSsinsanction  val enqEntries          = Seq.fill(EnqEntryNum)(Module(EnqEntry(isComp = true)(p, params)))
6928607074Ssinsanction  val othersEntriesSimp   = Seq.fill(SimpEntryNum)(Module(OthersEntry(isComp = false)(p, params)))
7028607074Ssinsanction  val othersEntriesComp   = Seq.fill(CompEntryNum)(Module(OthersEntry(isComp = true)(p, params)))
7128607074Ssinsanction  val othersEntries       = othersEntriesSimp ++ othersEntriesComp
7228607074Ssinsanction  val othersTransPolicy   = OptionWrapper(params.isAllComp || params.isAllSimp, Module(new EnqPolicy))
7328607074Ssinsanction  val simpTransPolicy     = OptionWrapper(params.hasCompAndSimp, Module(new EnqPolicy))
7428607074Ssinsanction  val compTransPolicy     = OptionWrapper(params.hasCompAndSimp, Module(new EnqPolicy))
755db4956bSzhanglyGit
765db4956bSzhanglyGit  //Wire
77aa2bcc31SzhanglyGit  //entries status
785db4956bSzhanglyGit  val entries             = Wire(Vec(params.numEntries, ValidIO(new EntryBundle)))
79aa2bcc31SzhanglyGit  val robIdxVec           = Wire(Vec(params.numEntries, new RobPtr))
805db4956bSzhanglyGit  val validVec            = Wire(Vec(params.numEntries, Bool()))
81c0beb497Sxiaofeibao  val issuedVec           = Wire(Vec(params.numEntries, Bool()))
82c0beb497Sxiaofeibao  val validForTrans       = VecInit(validVec.zip(issuedVec).map(x => x._1 && !x._2))
835db4956bSzhanglyGit  val canIssueVec         = Wire(Vec(params.numEntries, Bool()))
845db4956bSzhanglyGit  val fuTypeVec           = Wire(Vec(params.numEntries, FuType()))
855db4956bSzhanglyGit  val isFirstIssueVec     = Wire(Vec(params.numEntries, Bool()))
865db4956bSzhanglyGit  val issueTimerVec       = Wire(Vec(params.numEntries, UInt(2.W)))
8728ac1c16Sxiaofeibao-xjtu  val sqIdxVec            = OptionWrapper(params.needFeedBackSqIdx || params.needFeedBackLqIdx, Wire(Vec(params.numEntries, new SqPtr())))
8828ac1c16Sxiaofeibao-xjtu  val lqIdxVec            = OptionWrapper(params.needFeedBackSqIdx || params.needFeedBackLqIdx, Wire(Vec(params.numEntries, new LqPtr())))
89aa2bcc31SzhanglyGit  //src status
90aa2bcc31SzhanglyGit  val dataSourceVec       = Wire(Vec(params.numEntries, Vec(params.numRegSrc, DataSource())))
91ec49b127Ssinsanction  val loadDependencyVec   = Wire(Vec(params.numEntries, Vec(LoadPipelineWidth, UInt(LoadDependencyWidth.W))))
92f57d73d6Ssinsanction  val exuSourceVec        = OptionWrapper(params.hasIQWakeUp, Wire(Vec(params.numEntries, Vec(params.numRegSrc, ExuSource()))))
93aa2bcc31SzhanglyGit  //deq sel
94aa2bcc31SzhanglyGit  val deqSelVec           = Wire(Vec(params.numEntries, Bool()))
95aa2bcc31SzhanglyGit  val issueRespVec        = Wire(Vec(params.numEntries, ValidIO(new EntryDeqRespBundle)))
965db4956bSzhanglyGit  val deqPortIdxWriteVec  = Wire(Vec(params.numEntries, UInt(1.W)))
975db4956bSzhanglyGit  val deqPortIdxReadVec   = Wire(Vec(params.numEntries, UInt(1.W)))
98aa2bcc31SzhanglyGit  //trans sel
9928607074Ssinsanction  val othersEntryEnqReadyVec = Wire(Vec(OthersEntryNum, Bool()))
10028607074Ssinsanction  val othersEntryEnqVec      = Wire(Vec(OthersEntryNum, Valid(new EntryBundle)))
10128607074Ssinsanction  val enqEntryTransVec       = Wire(Vec(EnqEntryNum, Valid(new EntryBundle)))
10228607074Ssinsanction  val simpEntryTransVec      = OptionWrapper(params.hasCompAndSimp, Wire(Vec(SimpEntryNum, Valid(new EntryBundle))))
10328607074Ssinsanction  val compEnqVec             = OptionWrapper(params.hasCompAndSimp, Wire(Vec(EnqEntryNum, Valid(new EntryBundle))))
10428607074Ssinsanction
10528607074Ssinsanction  val enqCanTrans2Simp       = OptionWrapper(params.hasCompAndSimp, Wire(Bool()))
10628607074Ssinsanction  val enqCanTrans2Comp       = OptionWrapper(params.hasCompAndSimp, Wire(Bool()))
10728607074Ssinsanction  val simpCanTrans2Comp      = OptionWrapper(params.hasCompAndSimp, Wire(Vec(EnqEntryNum, Bool())))
10828607074Ssinsanction  val simpTransSelVec        = OptionWrapper(params.hasCompAndSimp, Wire(Vec(EnqEntryNum, Valid(UInt(SimpEntryNum.W)))))
10928607074Ssinsanction  val compTransSelVec        = OptionWrapper(params.hasCompAndSimp, Wire(Vec(EnqEntryNum, Valid(UInt(CompEntryNum.W)))))
11028607074Ssinsanction  val finalSimpTransSelVec   = OptionWrapper(params.hasCompAndSimp, Wire(Vec(EnqEntryNum, UInt(SimpEntryNum.W))))
11128607074Ssinsanction  val finalCompTransSelVec   = OptionWrapper(params.hasCompAndSimp, Wire(Vec(EnqEntryNum, UInt(CompEntryNum.W))))
11228607074Ssinsanction
11328607074Ssinsanction  val enqCanTrans2Others     = OptionWrapper(params.isAllComp || params.isAllSimp, Wire(Bool()))
11428607074Ssinsanction  val othersTransSelVec      = OptionWrapper(params.isAllComp || params.isAllSimp, Wire(Vec(EnqEntryNum, Valid(UInt(OthersEntryNum.W)))))
11528607074Ssinsanction  val finalOthersTransSelVec = OptionWrapper(params.isAllComp || params.isAllSimp, Wire(Vec(EnqEntryNum, UInt(OthersEntryNum.W))))
11628607074Ssinsanction
11728607074Ssinsanction  val simpEntryEnqReadyVec   = othersEntryEnqReadyVec.take(SimpEntryNum)
11828607074Ssinsanction  val compEntryEnqReadyVec   = othersEntryEnqReadyVec.takeRight(CompEntryNum)
11928607074Ssinsanction  val simpEntryEnqVec        = othersEntryEnqVec.take(SimpEntryNum)
12028607074Ssinsanction  val compEntryEnqVec        = othersEntryEnqVec.takeRight(CompEntryNum)
121aa2bcc31SzhanglyGit  //debug
122a6938b17Ssinsanction  val entryInValidVec        = Wire(Vec(params.numEntries, Bool()))
123a6938b17Ssinsanction  val entryOutDeqValidVec    = Wire(Vec(params.numEntries, Bool()))
124a6938b17Ssinsanction  val entryOutTransValidVec  = Wire(Vec(params.numEntries, Bool()))
125e3ef3537Ssinsanction  val perfLdCancelVec        = OptionWrapper(params.hasIQWakeUp, Wire(Vec(params.numEntries, Vec(params.numRegSrc, Bool()))))
126e3ef3537Ssinsanction  val perfOg0CancelVec       = OptionWrapper(params.hasIQWakeUp, Wire(Vec(params.numEntries, Vec(params.numRegSrc, Bool()))))
127e3ef3537Ssinsanction  val perfWakeupByWBVec      = Wire(Vec(params.numEntries, Vec(params.numRegSrc, Bool())))
128e3ef3537Ssinsanction  val perfWakeupByIQVec      = OptionWrapper(params.hasIQWakeUp, Wire(Vec(params.numEntries, Vec(params.numRegSrc, Vec(params.numWakeupFromIQ, Bool())))))
129a4d38a63SzhanglyGit  //cancel bypass
130eea4a3caSzhanglyGit  val cancelBypassVec        = Wire(Vec(params.numEntries, Bool()))
1315db4956bSzhanglyGit
1325db4956bSzhanglyGit
1335db4956bSzhanglyGit  //enqEntries
1345db4956bSzhanglyGit  enqEntries.zipWithIndex.foreach { case (enqEntry, entryIdx) =>
135aa2bcc31SzhanglyGit    enqEntry.io.commonIn.enq                  := io.enq(entryIdx)
13628607074Ssinsanction    enqEntry.io.commonIn.transSel             := (if (params.isAllComp || params.isAllSimp) enqCanTrans2Others.get && othersTransSelVec.get(entryIdx).valid
13728607074Ssinsanction                                                  else enqCanTrans2Simp.get && simpTransSelVec.get(entryIdx).valid || enqCanTrans2Comp.get && compTransSelVec.get(entryIdx).valid)
138aa2bcc31SzhanglyGit    EntriesConnect(enqEntry.io.commonIn, enqEntry.io.commonOut, entryIdx)
1399df83ee5Sxiaofeibao    enqEntry.io.enqDelayIn1.wakeUpFromWB := io.wakeUpFromWBDelayed
1409df83ee5Sxiaofeibao    enqEntry.io.enqDelayIn1.wakeUpFromIQ := io.wakeUpFromIQDelayed
1418338e674Sxiaofeibao-xjtu    enqEntry.io.enqDelayIn1.srcLoadDependency := RegEnable(VecInit(io.enq(entryIdx).bits.payload.srcLoadDependency.take(params.numRegSrc)), io.enq(entryIdx).valid)
142be9ff987Ssinsanction    enqEntry.io.enqDelayIn1.og0Cancel         := RegNext(io.og0Cancel)
1434fa640e4Ssinsanction    enqEntry.io.enqDelayIn1.ldCancel          := RegNext(io.ldCancel)
1444fa640e4Ssinsanction    // note: these signals with 2 cycle delay should not be enabled by io.enq.valid
1454fa640e4Ssinsanction    enqEntry.io.enqDelayIn2.wakeUpFromWB      := DelayN(io.wakeUpFromWB, 2)
1464fa640e4Ssinsanction    enqEntry.io.enqDelayIn2.wakeUpFromIQ      := DelayN(io.wakeUpFromIQ, 2)
14791f31488Sxiaofeibao-xjtu    enqEntry.io.enqDelayIn2.srcLoadDependency := DelayN(VecInit(io.enq(entryIdx).bits.payload.srcLoadDependency.take(params.numRegSrc)), 2)
148be9ff987Ssinsanction    enqEntry.io.enqDelayIn2.og0Cancel         := DelayN(io.og0Cancel, 2)
1494fa640e4Ssinsanction    enqEntry.io.enqDelayIn2.ldCancel          := DelayN(io.ldCancel, 2)
15028607074Ssinsanction    enqEntryTransVec(entryIdx)                := enqEntry.io.commonOut.transEntry
1515db4956bSzhanglyGit  }
1525db4956bSzhanglyGit  //othersEntries
1535db4956bSzhanglyGit  othersEntries.zipWithIndex.foreach { case (othersEntry, entryIdx) =>
15428607074Ssinsanction    othersEntry.io.commonIn.enq               := othersEntryEnqVec(entryIdx)
15528607074Ssinsanction    othersEntry.io.commonIn.transSel          := (if (params.hasCompAndSimp && (entryIdx < SimpEntryNum))
15628607074Ssinsanction                                                    io.simpEntryDeqSelVec.get.zip(simpCanTrans2Comp.get).map(x => x._1(entryIdx) && x._2).reduce(_ | _)
15728607074Ssinsanction                                                  else false.B)
158aa2bcc31SzhanglyGit    EntriesConnect(othersEntry.io.commonIn, othersEntry.io.commonOut, entryIdx + EnqEntryNum)
15928607074Ssinsanction    othersEntryEnqReadyVec(entryIdx)          := othersEntry.io.commonOut.enqReady
16028607074Ssinsanction    if (params.hasCompAndSimp && (entryIdx < SimpEntryNum)) {
16128607074Ssinsanction      simpEntryTransVec.get(entryIdx)         := othersEntry.io.commonOut.transEntry
16228607074Ssinsanction    }
1635db4956bSzhanglyGit  }
1645db4956bSzhanglyGit
1655db4956bSzhanglyGit
1665db4956bSzhanglyGit  deqSelVec.zip(deqPortIdxWriteVec).zipWithIndex.foreach { case ((deqSel, deqPortIdxWrite), i) =>
167aa2bcc31SzhanglyGit    val deqVec = io.deqSelOH.zip(io.deqReady).map(x => x._1.valid && x._1.bits(i) && x._2)
1685db4956bSzhanglyGit    deqPortIdxWrite := OHToUInt(deqVec)
1695db4956bSzhanglyGit    deqSel := deqVec.reduce(_ | _)
1705db4956bSzhanglyGit  }
1715db4956bSzhanglyGit
1725db4956bSzhanglyGit
17328607074Ssinsanction  if (params.isAllComp || params.isAllSimp) {
1745db4956bSzhanglyGit    //transPolicy
175b9631a81Sxiaofeibao-xjtu    othersTransPolicy.get.io.canEnq := VecInit(validVec.takeRight(OthersEntryNum).map(!_)).asUInt
176b43488b9Ssinsanction
177b43488b9Ssinsanction    // we only allow all or none of the enq entries transfering to others entries.
178b9631a81Sxiaofeibao-xjtu    enqCanTrans2Others.get := PopCount(validVec.take(EnqEntryNum)) <= PopCount(validVec.takeRight(OthersEntryNum).map(!_))
179b43488b9Ssinsanction    // othersTransSelVec(i) is the target others entry for enq entry [i].
180b43488b9Ssinsanction    // note that dispatch does not guarantee the validity of enq entries with low index.
181b43488b9Ssinsanction    // that means in some cases enq entry [0] is invalid while enq entry [1] is valid.
182b43488b9Ssinsanction    // in this case, enq entry [1] should use result [0] of TransPolicy.
183c0beb497Sxiaofeibao    othersTransSelVec.get(0).valid := othersTransPolicy.get.io.enqSelOHVec(0).valid && validForTrans(0)
18428607074Ssinsanction    othersTransSelVec.get(0).bits  := othersTransPolicy.get.io.enqSelOHVec(0).bits
1858321ef33Ssinsanction    if (params.numEnq == 2) {
186c0beb497Sxiaofeibao      othersTransSelVec.get(1).valid := Mux(!validForTrans(0), othersTransPolicy.get.io.enqSelOHVec(0).valid, othersTransPolicy.get.io.enqSelOHVec(1).valid) && validForTrans(1)
187c0beb497Sxiaofeibao      othersTransSelVec.get(1).bits  := Mux(!validForTrans(0), othersTransPolicy.get.io.enqSelOHVec(0).bits,  othersTransPolicy.get.io.enqSelOHVec(1).bits)
1888321ef33Ssinsanction    }
1898321ef33Ssinsanction
19028607074Ssinsanction    finalOthersTransSelVec.get.zip(othersTransSelVec.get).zipWithIndex.foreach { case ((finalOH, selOH), enqIdx) =>
19128607074Ssinsanction      finalOH := Fill(OthersEntryNum, enqCanTrans2Others.get && selOH.valid) & selOH.bits
1925db4956bSzhanglyGit    }
1935db4956bSzhanglyGit
19428607074Ssinsanction    //othersEntryEnq
19528607074Ssinsanction    othersEntryEnqVec.zipWithIndex.foreach { case (othersEntryEnq, othersIdx) =>
19628607074Ssinsanction      val othersEnqOH = finalOthersTransSelVec.get.map(_(othersIdx))
19728607074Ssinsanction      if (othersEnqOH.size == 1)
19828607074Ssinsanction        othersEntryEnq := Mux(othersEnqOH.head, enqEntryTransVec.head, 0.U.asTypeOf(enqEntryTransVec.head))
19928607074Ssinsanction      else
20028607074Ssinsanction        othersEntryEnq := Mux1H(othersEnqOH, enqEntryTransVec)
2015db4956bSzhanglyGit    }
20228607074Ssinsanction  }
20328607074Ssinsanction  else {
20428607074Ssinsanction    //transPolicy
20528607074Ssinsanction    simpTransPolicy.get.io.canEnq := VecInit(simpEntryEnqReadyVec).asUInt
20628607074Ssinsanction    compTransPolicy.get.io.canEnq := VecInit(validVec.takeRight(CompEntryNum).map(!_)).asUInt
20728607074Ssinsanction
208b43488b9Ssinsanction    // we only allow all or none of the enq entries transfering to comp/simp entries.
209b43488b9Ssinsanction    // when all of simp entries are empty and comp entries are enough, transfer to comp entries.
210b43488b9Ssinsanction    // otherwise, transfer to simp entries.
21128607074Ssinsanction    enqCanTrans2Comp.get := PopCount(validVec.take(EnqEntryNum)) <= PopCount(validVec.takeRight(CompEntryNum).map(!_)) && !validVec.drop(EnqEntryNum).take(SimpEntryNum).reduce(_ || _)
21228607074Ssinsanction    enqCanTrans2Simp.get := !enqCanTrans2Comp.get && PopCount(validVec.take(EnqEntryNum)) <= PopCount(simpEntryEnqReadyVec)
21328607074Ssinsanction    simpCanTrans2Comp.get.zipWithIndex.foreach { case (canTrans, idx) =>
21428607074Ssinsanction      canTrans := !enqCanTrans2Comp.get && PopCount(validVec.takeRight(CompEntryNum).map(!_)) >= (idx + 1).U
21528607074Ssinsanction    }
21628607074Ssinsanction
217b43488b9Ssinsanction    // simp/compTransSelVec(i) is the target simp/comp entry for enq entry [i].
218b43488b9Ssinsanction    // note that dispatch does not guarantee the validity of enq entries with low index.
219b43488b9Ssinsanction    // that means in some cases enq entry [0] is invalid while enq entry [1] is valid.
220b43488b9Ssinsanction    // in this case, enq entry [1] should use result [0] of TransPolicy.
221c0beb497Sxiaofeibao    simpTransSelVec.get(0).valid := simpTransPolicy.get.io.enqSelOHVec(0).valid && validForTrans(0)
22228607074Ssinsanction    simpTransSelVec.get(0).bits  := simpTransPolicy.get.io.enqSelOHVec(0).bits
223c0beb497Sxiaofeibao    compTransSelVec.get(0).valid := compTransPolicy.get.io.enqSelOHVec(0).valid && validForTrans(0)
22428607074Ssinsanction    compTransSelVec.get(0).bits  := compTransPolicy.get.io.enqSelOHVec(0).bits
22528607074Ssinsanction    if (params.numEnq == 2) {
226c0beb497Sxiaofeibao      simpTransSelVec.get(1).valid := Mux(!validForTrans(0), simpTransPolicy.get.io.enqSelOHVec(0).valid, simpTransPolicy.get.io.enqSelOHVec(1).valid) && validForTrans(1)
227c0beb497Sxiaofeibao      simpTransSelVec.get(1).bits  := Mux(!validForTrans(0), simpTransPolicy.get.io.enqSelOHVec(0).bits,  simpTransPolicy.get.io.enqSelOHVec(1).bits)
228c0beb497Sxiaofeibao      compTransSelVec.get(1).valid := Mux(!validForTrans(0), compTransPolicy.get.io.enqSelOHVec(0).valid, compTransPolicy.get.io.enqSelOHVec(1).valid) && validForTrans(1)
229c0beb497Sxiaofeibao      compTransSelVec.get(1).bits  := Mux(!validForTrans(0), compTransPolicy.get.io.enqSelOHVec(0).bits,  compTransPolicy.get.io.enqSelOHVec(1).bits)
23028607074Ssinsanction    }
23128607074Ssinsanction
23228607074Ssinsanction    finalSimpTransSelVec.get.zip(simpTransSelVec.get).zipWithIndex.foreach { case ((finalOH, selOH), enqIdx) =>
23328607074Ssinsanction      finalOH := Fill(SimpEntryNum, enqCanTrans2Simp.get && selOH.valid) & selOH.bits
23428607074Ssinsanction    }
23528607074Ssinsanction    finalCompTransSelVec.get.zip(compTransSelVec.get).zip(compTransPolicy.get.io.enqSelOHVec).zipWithIndex.foreach {
23628607074Ssinsanction      case (((finalOH, selOH), origSelOH), enqIdx) =>
23728607074Ssinsanction        finalOH := Mux(enqCanTrans2Comp.get, Fill(CompEntryNum, selOH.valid) & selOH.bits, Fill(CompEntryNum, origSelOH.valid) & origSelOH.bits)
23828607074Ssinsanction    }
23928607074Ssinsanction
24028607074Ssinsanction    //othersEntryEnq
24128607074Ssinsanction    simpEntryEnqVec.zipWithIndex.foreach { case (simpEntryEnq, simpIdx) =>
24228607074Ssinsanction      val simpEnqOH = finalSimpTransSelVec.get.map(_(simpIdx))
24328607074Ssinsanction      // shit Mux1H directly returns in(0) if the seq has only 1 elements
24428607074Ssinsanction      if (simpEnqOH.size == 1)
24528607074Ssinsanction        simpEntryEnq := Mux(simpEnqOH.head, enqEntryTransVec.head, 0.U.asTypeOf(enqEntryTransVec.head))
24628607074Ssinsanction      else
24728607074Ssinsanction        simpEntryEnq := Mux1H(simpEnqOH, enqEntryTransVec)
24828607074Ssinsanction    }
24928607074Ssinsanction
25028607074Ssinsanction    compEnqVec.get.zip(enqEntryTransVec).zip(io.simpEntryDeqSelVec.get).foreach { case ((compEnq, enqEntry), deqSel) =>
25128607074Ssinsanction      compEnq := Mux(enqCanTrans2Comp.get, enqEntry, Mux1H(deqSel, simpEntryTransVec.get))
25228607074Ssinsanction    }
25328607074Ssinsanction    compEntryEnqVec.zipWithIndex.foreach { case (compEntryEnq, compIdx) =>
25428607074Ssinsanction      val compEnqOH = finalCompTransSelVec.get.map(_(compIdx))
25528607074Ssinsanction      // shit Mux1H directly returns in(0) if the seq has only 1 elements
25628607074Ssinsanction      if (compEnqOH.size == 1)
25728607074Ssinsanction        compEntryEnq := Mux(compEnqOH.head, compEnqVec.get.head, 0.U.asTypeOf(compEnqVec.get.head))
25828607074Ssinsanction      else
25928607074Ssinsanction        compEntryEnq := Mux1H(compEnqOH, compEnqVec.get)
26028607074Ssinsanction    }
26128607074Ssinsanction
26228607074Ssinsanction    assert(PopCount(simpEntryEnqVec.map(_.valid)) <= params.numEnq.U, "the number of simpEntryEnq is more than numEnq\n")
26328607074Ssinsanction    assert(PopCount(compEntryEnqVec.map(_.valid)) <= params.numEnq.U, "the number of compEntryEnq is more than numEnq\n")
26428607074Ssinsanction  }
26528607074Ssinsanction
2668d081717Sszw_kaixin  if(backendParams.debugEn) {
26728607074Ssinsanction    dontTouch(othersEntryEnqVec)
2688d081717Sszw_kaixin  }
2695db4956bSzhanglyGit
2705db4956bSzhanglyGit  //issueRespVec
27128ac1c16Sxiaofeibao-xjtu  if (params.needFeedBackSqIdx || params.needFeedBackLqIdx) {
27228ac1c16Sxiaofeibao-xjtu    issueRespVec.lazyZip(sqIdxVec.get.zip(lqIdxVec.get)).lazyZip(issueTimerVec.lazyZip(deqPortIdxReadVec)).foreach { case (issueResp, (sqIdx, lqIdx), (issueTimer, deqPortIdx)) =>
27342b6cdf9Ssinsanction      val respInDatapath = if (!params.isVecMemIQ) resps(issueTimer(0))(deqPortIdx)
27442b6cdf9Ssinsanction                           else resps(issueTimer)(deqPortIdx)
275dd40a82bSsinsanction      val respAfterDatapath = Wire(chiselTypeOf(respInDatapath))
276f7890d3cSXuan Hu      val hitRespsVec = VecInit(memEtyResps.map(x =>
27728ac1c16Sxiaofeibao-xjtu        x.valid &&
27828ac1c16Sxiaofeibao-xjtu        (if (params.needFeedBackSqIdx) x.bits.sqIdx.get === sqIdx else true.B) &&
27928ac1c16Sxiaofeibao-xjtu        (if (params.needFeedBackLqIdx) x.bits.lqIdx.get === lqIdx else true.B)
280f7890d3cSXuan Hu      ).toSeq)
281dd40a82bSsinsanction      respAfterDatapath.valid := hitRespsVec.reduce(_ | _)
282dd40a82bSsinsanction      respAfterDatapath.bits  := (if (memEtyResps.size == 1) memEtyResps.head.bits
283dd40a82bSsinsanction                                  else Mux1H(hitRespsVec, memEtyResps.map(_.bits).toSeq))
28442b6cdf9Ssinsanction      issueResp := (if (!params.isVecMemIQ) Mux(issueTimer(1), respAfterDatapath, respInDatapath)
28542b6cdf9Ssinsanction                    else Mux(issueTimer === "b11".U, respAfterDatapath, respInDatapath))
286887f9c3dSzhanglinjuan    }
2875db4956bSzhanglyGit  }
2885db4956bSzhanglyGit  else {
289dd40a82bSsinsanction    issueRespVec.lazyZip(issueTimerVec.lazyZip(deqPortIdxReadVec)).foreach { case (issueResp, (issueTimer, deqPortIdx)) =>
2905db4956bSzhanglyGit      val Resp = resps(issueTimer)(deqPortIdx)
2915db4956bSzhanglyGit      issueResp := Resp
2925db4956bSzhanglyGit    }
2935db4956bSzhanglyGit  }
2945db4956bSzhanglyGit
29540283787Ssinsanction  //deq
29628607074Ssinsanction  val enqEntryOldest          = Wire(Vec(params.numDeq, ValidIO(new EntryBundle)))
29728607074Ssinsanction  val simpEntryOldest         = OptionWrapper(params.hasCompAndSimp, Wire(Vec(params.numDeq, ValidIO(new EntryBundle))))
29828607074Ssinsanction  val compEntryOldest         = OptionWrapper(params.hasCompAndSimp, Wire(Vec(params.numDeq, ValidIO(new EntryBundle))))
29928607074Ssinsanction  val othersEntryOldest       = OptionWrapper(params.isAllComp || params.isAllSimp, Wire(Vec(params.numDeq, ValidIO(new EntryBundle))))
30028607074Ssinsanction  val enqEntryOldestCancel    = Wire(Vec(params.numDeq, Bool()))
30128607074Ssinsanction  val simpEntryOldestCancel   = OptionWrapper(params.hasCompAndSimp, Wire(Vec(params.numDeq, Bool())))
30228607074Ssinsanction  val compEntryOldestCancel   = OptionWrapper(params.hasCompAndSimp, Wire(Vec(params.numDeq, Bool())))
30328607074Ssinsanction  val othersEntryOldestCancel = OptionWrapper(params.isAllComp || params.isAllSimp, Wire(Vec(params.numDeq, Bool())))
30428607074Ssinsanction
30528607074Ssinsanction  io.enqEntryOldestSel.zipWithIndex.map { case (sel, deqIdx) =>
30628607074Ssinsanction    enqEntryOldest(deqIdx) := Mux1H(sel.bits, entries.take(EnqEntryNum))
307eea4a3caSzhanglyGit    enqEntryOldestCancel(deqIdx) := Mux1H(sel.bits, cancelBypassVec.take(EnqEntryNum))
30840283787Ssinsanction  }
30928607074Ssinsanction
31028607074Ssinsanction  if (params.isAllComp || params.isAllSimp) {
31128607074Ssinsanction    io.othersEntryOldestSel.get.zipWithIndex.map { case (sel, deqIdx) =>
31228607074Ssinsanction      othersEntryOldest.get(deqIdx) := Mux1H(sel.bits, entries.drop(EnqEntryNum))
313eea4a3caSzhanglyGit      othersEntryOldestCancel.get(deqIdx) := Mux1H(sel.bits, cancelBypassVec.drop(EnqEntryNum))
314af4bd265SzhanglyGit    }
31540283787Ssinsanction  }
31628607074Ssinsanction  else {
31728607074Ssinsanction    io.simpEntryOldestSel.get.zipWithIndex.map { case (sel, deqIdx) =>
31828607074Ssinsanction      simpEntryOldest.get(deqIdx) := Mux1H(sel.bits, entries.drop(EnqEntryNum).take(SimpEntryNum))
319eea4a3caSzhanglyGit      simpEntryOldestCancel.get(deqIdx) := Mux1H(sel.bits, cancelBypassVec.drop(EnqEntryNum).take(SimpEntryNum))
32028607074Ssinsanction    }
32128607074Ssinsanction    io.compEntryOldestSel.get.zipWithIndex.map { case (sel, deqIdx) =>
32228607074Ssinsanction      compEntryOldest.get(deqIdx) := Mux1H(sel.bits, entries.drop(EnqEntryNum).takeRight(CompEntryNum))
323eea4a3caSzhanglyGit      compEntryOldestCancel.get(deqIdx) := Mux1H(sel.bits, cancelBypassVec.drop(EnqEntryNum).takeRight(CompEntryNum))
32428607074Ssinsanction    }
325af4bd265SzhanglyGit  }
326cf4a131aSsinsanction
327cf4a131aSsinsanction  if (params.deqFuSame) {
328cf4a131aSsinsanction    val subDeqPolicyEntryVec = Wire(Vec(params.numDeq, ValidIO(new EntryBundle)))
329cf4a131aSsinsanction    val subDeqPolicyValidVec = Wire(Vec(params.numDeq, Bool()))
330a4d38a63SzhanglyGit    val subDeqPolicyCancelBypassVec = Wire(Vec(params.numDeq, Bool()))
331cf4a131aSsinsanction
332aa2bcc31SzhanglyGit    subDeqPolicyValidVec(0) := PopCount(io.subDeqRequest.get(0)) >= 1.U
333aa2bcc31SzhanglyGit    subDeqPolicyValidVec(1) := PopCount(io.subDeqRequest.get(0)) >= 2.U
33428607074Ssinsanction
33528607074Ssinsanction    if (params.isAllComp || params.isAllSimp) {
33628607074Ssinsanction      subDeqPolicyEntryVec(0) := PriorityMux(io.subDeqRequest.get(0), entries)
33728607074Ssinsanction      subDeqPolicyEntryVec(1) := PriorityMux(Reverse(io.subDeqRequest.get(0)), entries.reverse)
338eea4a3caSzhanglyGit      subDeqPolicyCancelBypassVec(0) := PriorityMux(io.subDeqRequest.get(0), cancelBypassVec)
339eea4a3caSzhanglyGit      subDeqPolicyCancelBypassVec(1) := PriorityMux(Reverse(io.subDeqRequest.get(0)), cancelBypassVec.reverse)
340cf4a131aSsinsanction
34128607074Ssinsanction      io.deqEntry(0) := Mux(io.othersEntryOldestSel.get(0).valid, othersEntryOldest.get(0), subDeqPolicyEntryVec(1))
342aa2bcc31SzhanglyGit      io.deqEntry(1) := subDeqPolicyEntryVec(0)
34328607074Ssinsanction      io.cancelDeqVec(0) := Mux(io.othersEntryOldestSel.get(0).valid, othersEntryOldestCancel.get(0), subDeqPolicyCancelBypassVec(1))
344a4d38a63SzhanglyGit      io.cancelDeqVec(1) := subDeqPolicyCancelBypassVec(0)
34528607074Ssinsanction    }
34628607074Ssinsanction    else {
34728607074Ssinsanction      subDeqPolicyEntryVec(0) := PriorityMux(Reverse(io.subDeqRequest.get(0)), entries.reverse)
34828607074Ssinsanction      subDeqPolicyEntryVec(1) := PriorityMux(io.subDeqRequest.get(0), entries)
349eea4a3caSzhanglyGit      subDeqPolicyCancelBypassVec(0) := PriorityMux(Reverse(io.subDeqRequest.get(0)), cancelBypassVec.reverse)
350eea4a3caSzhanglyGit      subDeqPolicyCancelBypassVec(1) := PriorityMux(io.subDeqRequest.get(0), cancelBypassVec)
35128607074Ssinsanction
35228607074Ssinsanction      io.deqEntry(0) := Mux(io.compEntryOldestSel.get(0).valid,
35328607074Ssinsanction                            compEntryOldest.get(0),
35428607074Ssinsanction                            Mux(io.simpEntryOldestSel.get(0).valid, simpEntryOldest.get(0), subDeqPolicyEntryVec(1)))
35528607074Ssinsanction      io.deqEntry(1) := subDeqPolicyEntryVec(0)
35628607074Ssinsanction      io.cancelDeqVec(0) := Mux(io.compEntryOldestSel.get(0).valid,
35728607074Ssinsanction                                compEntryOldestCancel.get(0),
35828607074Ssinsanction                                Mux(io.simpEntryOldestSel.get(0).valid, simpEntryOldestCancel.get(0), subDeqPolicyCancelBypassVec(1)))
35928607074Ssinsanction      io.cancelDeqVec(1) := subDeqPolicyCancelBypassVec(0)
36028607074Ssinsanction    }
361cf4a131aSsinsanction
362cf4a131aSsinsanction    when (subDeqPolicyValidVec(0)) {
363aa2bcc31SzhanglyGit      assert(Mux1H(io.subDeqSelOH.get(0), entries).bits.status.robIdx === subDeqPolicyEntryVec(0).bits.status.robIdx, "subDeqSelOH(0) is not the same\n")
36440283787Ssinsanction    }
365cf4a131aSsinsanction    when (subDeqPolicyValidVec(1)) {
366aa2bcc31SzhanglyGit      assert(Mux1H(io.subDeqSelOH.get(1), entries).bits.status.robIdx === subDeqPolicyEntryVec(1).bits.status.robIdx, "subDeqSelOH(1) is not the same\n")
367f7f73727Ssinsanction    }
368f7f73727Ssinsanction  }
369f7f73727Ssinsanction  else {
37028607074Ssinsanction    if (params.isAllComp || params.isAllSimp) {
37128607074Ssinsanction      io.othersEntryOldestSel.get.zipWithIndex.foreach { case (sel, i) =>
37228607074Ssinsanction        io.deqEntry(i)     := Mux(sel.valid, othersEntryOldest.get(i), enqEntryOldest(i))
37328607074Ssinsanction        io.cancelDeqVec(i) := Mux(sel.valid, othersEntryOldestCancel.get(i), enqEntryOldestCancel(i))
37428607074Ssinsanction      }
37528607074Ssinsanction    }
37628607074Ssinsanction    else {
37728607074Ssinsanction      io.compEntryOldestSel.get.zip(io.simpEntryOldestSel.get).zipWithIndex.foreach { case ((compSel, simpSel), i) =>
37828607074Ssinsanction        io.deqEntry(i)     := Mux(compSel.valid,
37928607074Ssinsanction                                  compEntryOldest.get(i),
38028607074Ssinsanction                                  Mux(simpSel.valid, simpEntryOldest.get(i), enqEntryOldest(i)))
38128607074Ssinsanction        io.cancelDeqVec(i) := Mux(compSel.valid,
38228607074Ssinsanction                                  compEntryOldestCancel.get(i),
38328607074Ssinsanction                                  Mux(simpSel.valid, simpEntryOldestCancel.get(i), enqEntryOldestCancel(i)))
38428607074Ssinsanction      }
385af4bd265SzhanglyGit    }
386af4bd265SzhanglyGit  }
387af4bd265SzhanglyGit
3885db4956bSzhanglyGit  io.valid                          := validVec.asUInt
389c0beb497Sxiaofeibao  io.issued                         := issuedVec.asUInt
3905db4956bSzhanglyGit  io.canIssue                       := canIssueVec.asUInt
3915db4956bSzhanglyGit  io.fuType                         := fuTypeVec
3925db4956bSzhanglyGit  io.dataSources                    := dataSourceVec
393f57d73d6Ssinsanction  io.exuSources.foreach(_           := exuSourceVec.get)
394eea4a3caSzhanglyGit  io.loadDependency                 := loadDependencyVec
395aa2bcc31SzhanglyGit  io.isFirstIssue.zipWithIndex.foreach{ case (isFirstIssue, deqIdx) =>
396aa2bcc31SzhanglyGit    isFirstIssue                    := io.deqSelOH(deqIdx).valid && Mux1H(io.deqSelOH(deqIdx).bits, isFirstIssueVec)
3978d081717Sszw_kaixin  }
39828607074Ssinsanction  io.simpEntryEnqSelVec.foreach(_   := finalSimpTransSelVec.get.zip(enqEntryTransVec).map(x => x._1 & Fill(SimpEntryNum, x._2.valid)))
39928607074Ssinsanction  io.compEntryEnqSelVec.foreach(_   := finalCompTransSelVec.get.zip(compEnqVec.get).map(x => x._1 & Fill(CompEntryNum, x._2.valid)))
40028607074Ssinsanction  io.othersEntryEnqSelVec.foreach(_ := finalOthersTransSelVec.get.zip(enqEntryTransVec).map(x => x._1 & Fill(OthersEntryNum, x._2.valid)))
401aa2bcc31SzhanglyGit  io.robIdx.foreach(_               := robIdxVec)
402aa2bcc31SzhanglyGit
4037e471bf8SXuan Hu
404aa2bcc31SzhanglyGit  def EntriesConnect(in: CommonInBundle, out: CommonOutBundle, entryIdx: Int) = {
405aa2bcc31SzhanglyGit    in.flush                    := io.flush
406aa2bcc31SzhanglyGit    in.wakeUpFromWB             := io.wakeUpFromWB
407aa2bcc31SzhanglyGit    in.wakeUpFromIQ             := io.wakeUpFromIQ
408d88d4328SZiyue Zhang    in.vlFromIntIsZero          := io.vlFromIntIsZero
409d88d4328SZiyue Zhang    in.vlFromIntIsVlmax         := io.vlFromIntIsVlmax
410d88d4328SZiyue Zhang    in.vlFromVfIsZero           := io.vlFromVfIsZero
411d88d4328SZiyue Zhang    in.vlFromVfIsVlmax          := io.vlFromVfIsVlmax
412aa2bcc31SzhanglyGit    in.og0Cancel                := io.og0Cancel
413aa2bcc31SzhanglyGit    in.og1Cancel                := io.og1Cancel
414aa2bcc31SzhanglyGit    in.ldCancel                 := io.ldCancel
415aa2bcc31SzhanglyGit    in.deqSel                   := deqSelVec(entryIdx)
416aa2bcc31SzhanglyGit    in.deqPortIdxWrite          := deqPortIdxWriteVec(entryIdx)
417aa2bcc31SzhanglyGit    in.issueResp                := issueRespVec(entryIdx)
418aa2bcc31SzhanglyGit    if (params.isVecMemIQ) {
419aa2bcc31SzhanglyGit      in.fromLsq.get.sqDeqPtr   := io.vecMemIn.get.sqDeqPtr
420aa2bcc31SzhanglyGit      in.fromLsq.get.lqDeqPtr   := io.vecMemIn.get.lqDeqPtr
421aa2bcc31SzhanglyGit    }
422aa2bcc31SzhanglyGit    validVec(entryIdx)          := out.valid
423c0beb497Sxiaofeibao    issuedVec(entryIdx)         := out.issued
424aa2bcc31SzhanglyGit    canIssueVec(entryIdx)       := out.canIssue
425aa2bcc31SzhanglyGit    fuTypeVec(entryIdx)         := out.fuType
426aa2bcc31SzhanglyGit    robIdxVec(entryIdx)         := out.robIdx
427f57d73d6Ssinsanction    dataSourceVec(entryIdx)     := out.dataSources
428aa2bcc31SzhanglyGit    isFirstIssueVec(entryIdx)   := out.isFirstIssue
429aa2bcc31SzhanglyGit    entries(entryIdx)           := out.entry
430aa2bcc31SzhanglyGit    deqPortIdxReadVec(entryIdx) := out.deqPortIdxRead
431aa2bcc31SzhanglyGit    issueTimerVec(entryIdx)     := out.issueTimerRead
432eea4a3caSzhanglyGit    loadDependencyVec(entryIdx) := out.entry.bits.status.mergedLoadDependency
433ec49b127Ssinsanction    cancelBypassVec(entryIdx)   := out.cancelBypass
434f57d73d6Ssinsanction    exuSourceVec.foreach(_(entryIdx) := out.exuSources.get)
43528ac1c16Sxiaofeibao-xjtu    if (params.needFeedBackSqIdx || params.needFeedBackLqIdx) {
43638f78b5dSxiaofeibao-xjtu      sqIdxVec.get(entryIdx) := out.entry.bits.payload.sqIdx
43728ac1c16Sxiaofeibao-xjtu      lqIdxVec.get(entryIdx) := out.entry.bits.payload.lqIdx
438aa2bcc31SzhanglyGit    }
439a6938b17Ssinsanction    entryInValidVec(entryIdx)       := out.entryInValid
440a6938b17Ssinsanction    entryOutDeqValidVec(entryIdx)   := out.entryOutDeqValid
441a6938b17Ssinsanction    entryOutTransValidVec(entryIdx) := out.entryOutTransValid
442e3ef3537Ssinsanction    perfWakeupByWBVec(entryIdx)     := out.perfWakeupByWB
443e3ef3537Ssinsanction    if (params.hasIQWakeUp) {
444e3ef3537Ssinsanction      perfLdCancelVec.get(entryIdx)   := out.perfLdCancel.get
445e3ef3537Ssinsanction      perfOg0CancelVec.get(entryIdx)  := out.perfOg0Cancel.get
446e3ef3537Ssinsanction      perfWakeupByIQVec.get(entryIdx) := out.perfWakeupByIQ.get
447aa2bcc31SzhanglyGit    }
448aa2bcc31SzhanglyGit  }
449a6938b17Ssinsanction
45025df626eSgood-circle  io.vecLdIn.foreach(dontTouch(_))
451a6938b17Ssinsanction
452a6938b17Ssinsanction  // entries perf counter
453a6938b17Ssinsanction  // enq
454a6938b17Ssinsanction  for (i <- 0 until params.numEnq) {
455a6938b17Ssinsanction    XSPerfAccumulate(s"enqEntry_${i}_in_cnt", entryInValidVec(i))
456a6938b17Ssinsanction    XSPerfAccumulate(s"enqEntry_${i}_out_deq_cnt", entryOutDeqValidVec(i))
457a6938b17Ssinsanction    XSPerfAccumulate(s"enqEntry_${i}_out_trans_cnt", entryOutTransValidVec(i))
458a6938b17Ssinsanction  }
459a6938b17Ssinsanction  // simple
460a6938b17Ssinsanction  for (i <- 0 until params.numSimp) {
461a6938b17Ssinsanction    XSPerfAccumulate(s"simpEntry_${i}_in_cnt", entryInValidVec(i + params.numEnq))
462a6938b17Ssinsanction    XSPerfAccumulate(s"simpEntry_${i}_out_deq_cnt", entryOutDeqValidVec(i + params.numEnq))
463a6938b17Ssinsanction    XSPerfAccumulate(s"simpEntry_${i}_out_trans_cnt", entryOutTransValidVec(i + params.numEnq))
464a6938b17Ssinsanction  }
465a6938b17Ssinsanction  // complex
466a6938b17Ssinsanction  for (i <- 0 until params.numComp) {
467a6938b17Ssinsanction    XSPerfAccumulate(s"compEntry_${i}_in_cnt", entryInValidVec(i + params.numEnq + params.numSimp))
468a6938b17Ssinsanction    XSPerfAccumulate(s"compEntry_${i}_out_deq_cnt", entryOutDeqValidVec(i + params.numEnq + params.numSimp))
469a6938b17Ssinsanction    XSPerfAccumulate(s"compEntry_${i}_out_trans_cnt", entryOutTransValidVec(i + params.numEnq + params.numSimp))
470a6938b17Ssinsanction  }
471a6938b17Ssinsanction  // total
472a6938b17Ssinsanction  XSPerfAccumulate(s"enqEntry_all_in_cnt", PopCount(entryInValidVec.take(params.numEnq)))
473a6938b17Ssinsanction  XSPerfAccumulate(s"enqEntry_all_out_deq_cnt", PopCount(entryOutDeqValidVec.take(params.numEnq)))
474a6938b17Ssinsanction  XSPerfAccumulate(s"enqEntry_all_out_trans_cnt", PopCount(entryOutTransValidVec.take(params.numEnq)))
475e3ef3537Ssinsanction  for (srcIdx <- 0 until params.numRegSrc) {
476e3ef3537Ssinsanction    XSPerfAccumulate(s"enqEntry_all_wakeup_wb_src${srcIdx}_cnt", PopCount(perfWakeupByWBVec.take(params.numEnq).map(_(srcIdx))))
477d280e426Slewislzh    if (params.hasIQWakeUp) {
478e3ef3537Ssinsanction      XSPerfAccumulate(s"enqEntry_all_ldCancel_src${srcIdx}_cnt", PopCount(perfLdCancelVec.get.take(params.numEnq).map(_(srcIdx))))
479e3ef3537Ssinsanction      XSPerfAccumulate(s"enqEntry_all_og0Cancel_src${srcIdx}_cnt", PopCount(perfOg0CancelVec.get.take(params.numEnq).map(_(srcIdx))))
480e3ef3537Ssinsanction      for (iqIdx <- 0 until params.numWakeupFromIQ) {
481e3ef3537Ssinsanction        XSPerfAccumulate(s"enqEntry_all_wakeup_iq_from_exu${params.wakeUpSourceExuIdx(iqIdx)}_src${srcIdx}_cnt", PopCount(perfWakeupByIQVec.get.take(params.numEnq).map(_(srcIdx)(iqIdx))))
482e3ef3537Ssinsanction      }
483e3ef3537Ssinsanction    }
484d280e426Slewislzh  }
485a6938b17Ssinsanction
486a6938b17Ssinsanction  XSPerfAccumulate(s"othersEntry_all_in_cnt", PopCount(entryInValidVec.drop(params.numEnq)))
487a6938b17Ssinsanction  XSPerfAccumulate(s"othersEntry_all_out_deq_cnt", PopCount(entryOutDeqValidVec.drop(params.numEnq)))
488a6938b17Ssinsanction  XSPerfAccumulate(s"othersEntry_all_out_trans_cnt", PopCount(entryOutTransValidVec.drop(params.numEnq)))
4897e471bf8SXuan Hu
490e3ef3537Ssinsanction  for (srcIdx <- 0 until params.numRegSrc) {
491e3ef3537Ssinsanction    XSPerfAccumulate(s"othersEntry_all_wakeup_wb_src${srcIdx}_cnt", PopCount(perfWakeupByWBVec.drop(params.numEnq).map(_(srcIdx))))
492d280e426Slewislzh    if (params.hasIQWakeUp) {
493e3ef3537Ssinsanction      XSPerfAccumulate(s"othersEntry_all_ldCancel_src${srcIdx}_cnt", PopCount(perfLdCancelVec.get.drop(params.numEnq).map(_(srcIdx))))
494e3ef3537Ssinsanction      XSPerfAccumulate(s"othersEntry_all_og0Cancel_src${srcIdx}_cnt", PopCount(perfOg0CancelVec.get.drop(params.numEnq).map(_(srcIdx))))
495e3ef3537Ssinsanction      for (iqIdx <- 0 until params.numWakeupFromIQ) {
496e3ef3537Ssinsanction        XSPerfAccumulate(s"othersEntry_all_wakeup_iq_from_exu${params.wakeUpSourceExuIdx(iqIdx)}_src${srcIdx}_cnt", PopCount(perfWakeupByIQVec.get.drop(params.numEnq).map(_(srcIdx)(iqIdx))))
497e3ef3537Ssinsanction      }
498e3ef3537Ssinsanction    }
499e3ef3537Ssinsanction  }
500e3ef3537Ssinsanction
501e3ef3537Ssinsanction  for (t <- FuType.functionNameMap.keys) {
502e3ef3537Ssinsanction    val fuName = FuType.functionNameMap(t)
503e3ef3537Ssinsanction    if (params.getFuCfgs.map(_.fuType == t).reduce(_ | _) && params.getFuCfgs.size > 1) {
504e3ef3537Ssinsanction      for (srcIdx <- 0 until params.numRegSrc) {
505e3ef3537Ssinsanction        XSPerfAccumulate(s"allEntry_futype_${fuName}_wakeup_wb_src${srcIdx}_cnt", PopCount(perfWakeupByWBVec.zip(fuTypeVec).map{ case(x, fu) => x(srcIdx) && fu(t.id) }))
506e3ef3537Ssinsanction        if (params.hasIQWakeUp) {
507e3ef3537Ssinsanction          XSPerfAccumulate(s"allEntry_futype_${fuName}_ldCancel_src${srcIdx}_cnt", PopCount(perfLdCancelVec.get.zip(fuTypeVec).map{ case(x, fu) => x(srcIdx) && fu(t.id) }))
508e3ef3537Ssinsanction          XSPerfAccumulate(s"allEntry_futype_${fuName}_og0Cancel_src${srcIdx}_cnt", PopCount(perfOg0CancelVec.get.zip(fuTypeVec).map{ case(x, fu) => x(srcIdx) && fu(t.id) }))
509e3ef3537Ssinsanction          for (iqIdx <- 0 until params.numWakeupFromIQ) {
510e3ef3537Ssinsanction            XSPerfAccumulate(s"allEntry_futype_${fuName}_wakeup_iq_from_exu${params.wakeUpSourceExuIdx(iqIdx)}_src${srcIdx}_cnt", PopCount(perfWakeupByIQVec.get.zip(fuTypeVec).map{ case(x, fu) => x(srcIdx)(iqIdx) && fu(t.id) }))
511e3ef3537Ssinsanction          }
512e3ef3537Ssinsanction        }
513e3ef3537Ssinsanction      }
514e3ef3537Ssinsanction    }
515d280e426Slewislzh  }
516aa2bcc31SzhanglyGit}
517aa2bcc31SzhanglyGit
518aa2bcc31SzhanglyGitclass EntriesIO(implicit p: Parameters, params: IssueBlockParams) extends XSBundle {
519aa2bcc31SzhanglyGit  val flush               = Flipped(ValidIO(new Redirect))
520aa2bcc31SzhanglyGit  //enq
521aa2bcc31SzhanglyGit  val enq                 = Vec(params.numEnq, Flipped(ValidIO(new EntryBundle)))
522aa2bcc31SzhanglyGit  val og0Resp             = Vec(params.numDeq, Flipped(ValidIO(new EntryDeqRespBundle)))
523aa2bcc31SzhanglyGit  val og1Resp             = Vec(params.numDeq, Flipped(ValidIO(new EntryDeqRespBundle)))
52442b6cdf9Ssinsanction  val og2Resp             = OptionWrapper(params.needOg2Resp, Vec(params.numDeq, Flipped(ValidIO(new EntryDeqRespBundle))))
525aa2bcc31SzhanglyGit  //deq sel
526aa2bcc31SzhanglyGit  val deqReady            = Vec(params.numDeq, Input(Bool()))
527aa2bcc31SzhanglyGit  val deqSelOH            = Vec(params.numDeq, Flipped(ValidIO(UInt(params.numEntries.W))))
528aa2bcc31SzhanglyGit  val enqEntryOldestSel   = Vec(params.numDeq, Flipped(ValidIO(UInt(params.numEnq.W))))
52928607074Ssinsanction  val simpEntryOldestSel  = OptionWrapper(params.hasCompAndSimp, Vec(params.numDeq, Flipped(ValidIO(UInt(params.numSimp.W)))))
53028607074Ssinsanction  val compEntryOldestSel  = OptionWrapper(params.hasCompAndSimp, Vec(params.numDeq, Flipped(ValidIO(UInt(params.numComp.W)))))
53128607074Ssinsanction  val othersEntryOldestSel= OptionWrapper(params.isAllComp || params.isAllSimp, Vec(params.numDeq, Flipped(ValidIO(UInt((params.numEntries - params.numEnq).W)))))
532aa2bcc31SzhanglyGit  val subDeqRequest       = OptionWrapper(params.deqFuSame, Vec(params.numDeq, Input(UInt(params.numEntries.W))))
533aa2bcc31SzhanglyGit  val subDeqSelOH         = OptionWrapper(params.deqFuSame, Vec(params.numDeq, Input(UInt(params.numEntries.W))))
534aa2bcc31SzhanglyGit  // wakeup
535aa2bcc31SzhanglyGit  val wakeUpFromWB: MixedVec[ValidIO[IssueQueueWBWakeUpBundle]] = Flipped(params.genWBWakeUpSinkValidBundle)
536aa2bcc31SzhanglyGit  val wakeUpFromIQ: MixedVec[ValidIO[IssueQueueIQWakeUpBundle]] = Flipped(params.genIQWakeUpSinkValidBundle)
5379df83ee5Sxiaofeibao  val wakeUpFromWBDelayed: MixedVec[ValidIO[IssueQueueWBWakeUpBundle]] = Flipped(params.genWBWakeUpSinkValidBundle)
5389df83ee5Sxiaofeibao  val wakeUpFromIQDelayed: MixedVec[ValidIO[IssueQueueIQWakeUpBundle]] = Flipped(params.genIQWakeUpSinkValidBundle)
539d88d4328SZiyue Zhang  val vlFromIntIsZero     = Input(Bool())
540d88d4328SZiyue Zhang  val vlFromIntIsVlmax    = Input(Bool())
541d88d4328SZiyue Zhang  val vlFromVfIsZero      = Input(Bool())
542d88d4328SZiyue Zhang  val vlFromVfIsVlmax     = Input(Bool())
543be9ff987Ssinsanction  val og0Cancel           = Input(ExuVec())
544be9ff987Ssinsanction  val og1Cancel           = Input(ExuVec())
545aa2bcc31SzhanglyGit  val ldCancel            = Vec(backendParams.LdExuCnt, Flipped(new LoadCancelIO))
546aa2bcc31SzhanglyGit  //entries status
547aa2bcc31SzhanglyGit  val valid               = Output(UInt(params.numEntries.W))
548c0beb497Sxiaofeibao  val issued              = Output(UInt(params.numEntries.W))
549aa2bcc31SzhanglyGit  val canIssue            = Output(UInt(params.numEntries.W))
550aa2bcc31SzhanglyGit  val fuType              = Vec(params.numEntries, Output(FuType()))
551aa2bcc31SzhanglyGit  val dataSources         = Vec(params.numEntries, Vec(params.numRegSrc, Output(DataSource())))
552ec49b127Ssinsanction  val loadDependency      = Vec(params.numEntries, Vec(LoadPipelineWidth, UInt(LoadDependencyWidth.W)))
553f57d73d6Ssinsanction  val exuSources          = OptionWrapper(params.hasIQWakeUp, Vec(params.numEntries, Vec(params.numRegSrc, Output(ExuSource()))))
554aa2bcc31SzhanglyGit  //deq status
555aa2bcc31SzhanglyGit  val isFirstIssue        = Vec(params.numDeq, Output(Bool()))
556aa2bcc31SzhanglyGit  val deqEntry            = Vec(params.numDeq, ValidIO(new EntryBundle))
557aa2bcc31SzhanglyGit  val cancelDeqVec        = Vec(params.numDeq, Output(Bool()))
558e07131b2Ssinsanction
559e07131b2Ssinsanction  // load/hybird only
560e07131b2Ssinsanction  val fromLoad = OptionWrapper(params.isLdAddrIQ || params.isHyAddrIQ, new Bundle {
561e07131b2Ssinsanction    val finalIssueResp    = Vec(params.numDeq, Flipped(ValidIO(new EntryDeqRespBundle)))
562e07131b2Ssinsanction    val memAddrIssueResp  = Vec(params.numDeq, Flipped(ValidIO(new EntryDeqRespBundle)))
563e07131b2Ssinsanction  })
564aa2bcc31SzhanglyGit  // mem only
565e07131b2Ssinsanction  val fromMem = OptionWrapper(params.isMemAddrIQ, new Bundle {
566aa2bcc31SzhanglyGit    val slowResp          = Vec(params.numDeq, Flipped(ValidIO(new EntryDeqRespBundle)))
567d3372210SzhanglyGit    val fastResp          = Vec(params.numDeq, Flipped(ValidIO(new EntryDeqRespBundle)))
568e07131b2Ssinsanction  })
56999944b79Ssinsanction  // vec mem only
570aa2bcc31SzhanglyGit  val vecMemIn = OptionWrapper(params.isVecMemIQ, new Bundle {
571aa2bcc31SzhanglyGit    val sqDeqPtr          = Input(new SqPtr)
572aa2bcc31SzhanglyGit    val lqDeqPtr          = Input(new LqPtr)
573aa2bcc31SzhanglyGit  })
5747e471bf8SXuan Hu  val vecLdIn = OptionWrapper(params.isVecLduIQ, new Bundle {
5753bba894fSxiaofeibao    val finalIssueResp = Vec(params.numDeq, Flipped(ValidIO(new EntryDeqRespBundle)))
5767e471bf8SXuan Hu    val resp              = Vec(params.numDeq, Flipped(ValidIO(new EntryDeqRespBundle)))
5777e471bf8SXuan Hu  })
578aa2bcc31SzhanglyGit  val robIdx = OptionWrapper(params.isVecMemIQ, Output(Vec(params.numEntries, new RobPtr)))
579aa2bcc31SzhanglyGit
58028607074Ssinsanction  // trans
58128607074Ssinsanction  val simpEntryDeqSelVec = OptionWrapper(params.hasCompAndSimp, Vec(params.numEnq, Input(UInt(params.numSimp.W))))
58228607074Ssinsanction  val simpEntryEnqSelVec = OptionWrapper(params.hasCompAndSimp, Vec(params.numEnq, Output(UInt(params.numSimp.W))))
58328607074Ssinsanction  val compEntryEnqSelVec = OptionWrapper(params.hasCompAndSimp, Vec(params.numEnq, Output(UInt(params.numComp.W))))
58428607074Ssinsanction  val othersEntryEnqSelVec = OptionWrapper(params.isAllComp || params.isAllSimp, Vec(params.numEnq, Output(UInt((params.numEntries - params.numEnq).W))))
585aa2bcc31SzhanglyGit
586aa2bcc31SzhanglyGit  def wakeup = wakeUpFromWB ++ wakeUpFromIQ
5875db4956bSzhanglyGit}
588