1package xiangshan.backend.issue 2 3import org.chipsalliance.cde.config.Parameters 4import chisel3._ 5import chisel3.util._ 6import utility.HasCircularQueuePtrHelper 7import utils._ 8import xiangshan._ 9import xiangshan.backend.Bundles._ 10import xiangshan.backend.datapath.DataConfig.VAddrData 11import xiangshan.backend.datapath.DataSource 12import xiangshan.backend.fu.FuType 13import xiangshan.backend.fu.vector.Utils.NOnes 14import xiangshan.backend.rob.RobPtr 15import xiangshan.mem.{LqPtr, MemWaitUpdateReq, SqPtr} 16import xiangshan.backend.issue.EntryBundles._ 17 18class Entries(implicit p: Parameters, params: IssueBlockParams) extends XSModule { 19 override def desiredName: String = params.getEntryName 20 21 require(params.numEnq <= 2, "number of enq should be no more than 2") 22 23 private val EnqEntryNum = params.numEnq 24 private val OthersEntryNum = params.numEntries - params.numEnq 25 private val SimpEntryNum = params.numSimp 26 private val CompEntryNum = params.numComp 27 val io = IO(new EntriesIO) 28 29 // only memAddrIQ use it 30 val memEtyResps: MixedVec[ValidIO[EntryDeqRespBundle]] = { 31 if (params.isLdAddrIQ && !params.isStAddrIQ) //LDU 32 MixedVecInit(io.og0Resp ++ io.og1Resp ++ io.finalIssueResp.get ++ io.memAddrIssueResp.get) 33 else if (params.isLdAddrIQ && params.isStAddrIQ || params.isHyAddrIQ) //HYU 34 MixedVecInit(io.og0Resp ++ io.og1Resp ++ io.finalIssueResp.get ++ io.memAddrIssueResp.get ++ io.fromMem.get.fastResp ++ io.fromMem.get.slowResp) 35 else if (params.isMemAddrIQ) //STU 36 MixedVecInit(io.og0Resp ++ io.og1Resp ++ io.fromMem.get.slowResp) 37 else MixedVecInit(Seq()) 38 } 39 40 val resps: Vec[Vec[ValidIO[EntryDeqRespBundle]]] = VecInit(io.og0Resp, io.og1Resp, 0.U.asTypeOf(io.og0Resp)) 41 42 //Module 43 val enqEntries = Seq.fill(EnqEntryNum)(Module(EnqEntry(isComp = true)(p, params))) 44 val othersEntriesSimp = Seq.fill(SimpEntryNum)(Module(OthersEntry(isComp = false)(p, params))) 45 val othersEntriesComp = Seq.fill(CompEntryNum)(Module(OthersEntry(isComp = true)(p, params))) 46 val othersEntries = othersEntriesSimp ++ othersEntriesComp 47 val othersTransPolicy = OptionWrapper(params.isAllComp || params.isAllSimp, Module(new EnqPolicy)) 48 val simpTransPolicy = OptionWrapper(params.hasCompAndSimp, Module(new EnqPolicy)) 49 val compTransPolicy = OptionWrapper(params.hasCompAndSimp, Module(new EnqPolicy)) 50 51 //Wire 52 //entries status 53 val entries = Wire(Vec(params.numEntries, ValidIO(new EntryBundle))) 54 val robIdxVec = Wire(Vec(params.numEntries, new RobPtr)) 55 val validVec = Wire(Vec(params.numEntries, Bool())) 56 val canIssueVec = Wire(Vec(params.numEntries, Bool())) 57 val fuTypeVec = Wire(Vec(params.numEntries, FuType())) 58 val isFirstIssueVec = Wire(Vec(params.numEntries, Bool())) 59 val issueTimerVec = Wire(Vec(params.numEntries, UInt(2.W))) 60 //src status 61 val dataSourceVec = Wire(Vec(params.numEntries, Vec(params.numRegSrc, DataSource()))) 62 val loadDependencyVec = Wire(Vec(params.numEntries, Vec(LoadPipelineWidth, UInt(3.W)))) 63 val srcLoadDependencyVec= Wire(Vec(params.numEntries, Vec(params.numRegSrc, Vec(LoadPipelineWidth, UInt(3.W))))) 64 val srcTimerVec = OptionWrapper(params.hasIQWakeUp, Wire(Vec(params.numEntries, Vec(params.numRegSrc, UInt(3.W))))) 65 val srcWakeUpL1ExuOHVec = OptionWrapper(params.hasIQWakeUp, Wire(Vec(params.numEntries, Vec(params.numRegSrc, ExuVec())))) 66 //deq sel 67 val deqSelVec = Wire(Vec(params.numEntries, Bool())) 68 val issueRespVec = Wire(Vec(params.numEntries, ValidIO(new EntryDeqRespBundle))) 69 val deqPortIdxWriteVec = Wire(Vec(params.numEntries, UInt(1.W))) 70 val deqPortIdxReadVec = Wire(Vec(params.numEntries, UInt(1.W))) 71 //trans sel 72 val othersEntryEnqReadyVec = Wire(Vec(OthersEntryNum, Bool())) 73 val othersEntryEnqVec = Wire(Vec(OthersEntryNum, Valid(new EntryBundle))) 74 val enqEntryTransVec = Wire(Vec(EnqEntryNum, Valid(new EntryBundle))) 75 val simpEntryTransVec = OptionWrapper(params.hasCompAndSimp, Wire(Vec(SimpEntryNum, Valid(new EntryBundle)))) 76 val compEnqVec = OptionWrapper(params.hasCompAndSimp, Wire(Vec(EnqEntryNum, Valid(new EntryBundle)))) 77 78 val enqCanTrans2Simp = OptionWrapper(params.hasCompAndSimp, Wire(Bool())) 79 val enqCanTrans2Comp = OptionWrapper(params.hasCompAndSimp, Wire(Bool())) 80 val simpCanTrans2Comp = OptionWrapper(params.hasCompAndSimp, Wire(Vec(EnqEntryNum, Bool()))) 81 val simpTransSelVec = OptionWrapper(params.hasCompAndSimp, Wire(Vec(EnqEntryNum, Valid(UInt(SimpEntryNum.W))))) 82 val compTransSelVec = OptionWrapper(params.hasCompAndSimp, Wire(Vec(EnqEntryNum, Valid(UInt(CompEntryNum.W))))) 83 val finalSimpTransSelVec = OptionWrapper(params.hasCompAndSimp, Wire(Vec(EnqEntryNum, UInt(SimpEntryNum.W)))) 84 val finalCompTransSelVec = OptionWrapper(params.hasCompAndSimp, Wire(Vec(EnqEntryNum, UInt(CompEntryNum.W)))) 85 86 val enqCanTrans2Others = OptionWrapper(params.isAllComp || params.isAllSimp, Wire(Bool())) 87 val othersTransSelVec = OptionWrapper(params.isAllComp || params.isAllSimp, Wire(Vec(EnqEntryNum, Valid(UInt(OthersEntryNum.W))))) 88 val finalOthersTransSelVec = OptionWrapper(params.isAllComp || params.isAllSimp, Wire(Vec(EnqEntryNum, UInt(OthersEntryNum.W)))) 89 90 val simpEntryEnqReadyVec = othersEntryEnqReadyVec.take(SimpEntryNum) 91 val compEntryEnqReadyVec = othersEntryEnqReadyVec.takeRight(CompEntryNum) 92 val simpEntryEnqVec = othersEntryEnqVec.take(SimpEntryNum) 93 val compEntryEnqVec = othersEntryEnqVec.takeRight(CompEntryNum) 94 //debug 95 val cancelVec = OptionWrapper(params.hasIQWakeUp, Wire(Vec(params.numEntries, Bool()))) 96 val entryInValidVec = Wire(Vec(params.numEntries, Bool())) 97 val entryOutDeqValidVec = Wire(Vec(params.numEntries, Bool())) 98 val entryOutTransValidVec = Wire(Vec(params.numEntries, Bool())) 99 //cancel bypass 100 val cancelBypassVec = Wire(Vec(params.numEntries, Bool())) 101 val uopIdxVec = OptionWrapper(params.isVecMemIQ, Wire(Vec(params.numEntries, UopIdx()))) 102 103 104 //enqEntries 105 enqEntries.zipWithIndex.foreach { case (enqEntry, entryIdx) => 106 enqEntry.io.commonIn.enq := io.enq(entryIdx) 107 enqEntry.io.commonIn.transSel := (if (params.isAllComp || params.isAllSimp) enqCanTrans2Others.get && othersTransSelVec.get(entryIdx).valid 108 else enqCanTrans2Simp.get && simpTransSelVec.get(entryIdx).valid || enqCanTrans2Comp.get && compTransSelVec.get(entryIdx).valid) 109 EntriesConnect(enqEntry.io.commonIn, enqEntry.io.commonOut, entryIdx) 110 enqEntry.io.enqDelayWakeUpFromWB := RegNext(io.wakeUpFromWB) 111 enqEntry.io.enqDelayWakeUpFromIQ := RegNext(io.wakeUpFromIQ) 112 enqEntry.io.enqDelayOg0Cancel := RegNext(io.og0Cancel.asUInt) 113 enqEntry.io.enqDelayLdCancel := RegNext(io.ldCancel) 114 enqEntryTransVec(entryIdx) := enqEntry.io.commonOut.transEntry 115 // TODO: move it into EntriesConnect 116 if (params.isVecMemIQ) { 117 enqEntry.io.commonIn.fromLsq.get.sqDeqPtr := io.vecMemIn.get.sqDeqPtr 118 enqEntry.io.commonIn.fromLsq.get.lqDeqPtr := io.vecMemIn.get.lqDeqPtr 119 } 120 } 121 //othersEntries 122 othersEntries.zipWithIndex.foreach { case (othersEntry, entryIdx) => 123 othersEntry.io.commonIn.enq := othersEntryEnqVec(entryIdx) 124 othersEntry.io.commonIn.transSel := (if (params.hasCompAndSimp && (entryIdx < SimpEntryNum)) 125 io.simpEntryDeqSelVec.get.zip(simpCanTrans2Comp.get).map(x => x._1(entryIdx) && x._2).reduce(_ | _) 126 else false.B) 127 EntriesConnect(othersEntry.io.commonIn, othersEntry.io.commonOut, entryIdx + EnqEntryNum) 128 othersEntryEnqReadyVec(entryIdx) := othersEntry.io.commonOut.enqReady 129 if (params.hasCompAndSimp && (entryIdx < SimpEntryNum)) { 130 simpEntryTransVec.get(entryIdx) := othersEntry.io.commonOut.transEntry 131 } 132 if (params.isVecMemIQ) { 133 othersEntry.io.commonIn.fromLsq.get.sqDeqPtr := io.vecMemIn.get.sqDeqPtr 134 othersEntry.io.commonIn.fromLsq.get.lqDeqPtr := io.vecMemIn.get.lqDeqPtr 135 } 136 } 137 138 139 deqSelVec.zip(deqPortIdxWriteVec).zipWithIndex.foreach { case ((deqSel, deqPortIdxWrite), i) => 140 val deqVec = io.deqSelOH.zip(io.deqReady).map(x => x._1.valid && x._1.bits(i) && x._2) 141 deqPortIdxWrite := OHToUInt(deqVec) 142 deqSel := deqVec.reduce(_ | _) 143 } 144 145 146 if (params.isAllComp || params.isAllSimp) { 147 //transPolicy 148 othersTransPolicy.get.io.canEnq := othersEntryEnqReadyVec.asUInt 149 enqCanTrans2Others.get := PopCount(validVec.take(EnqEntryNum)) <= PopCount(othersEntryEnqReadyVec) 150 othersTransSelVec.get(0).valid := othersTransPolicy.get.io.enqSelOHVec(0).valid && validVec(0) 151 othersTransSelVec.get(0).bits := othersTransPolicy.get.io.enqSelOHVec(0).bits 152 // Todo: comments why enqTransSelVec(1).valid relies on validVec(0) 153 if (params.numEnq == 2) { 154 othersTransSelVec.get(1).valid := Mux(!validVec(0), othersTransPolicy.get.io.enqSelOHVec(0).valid, othersTransPolicy.get.io.enqSelOHVec(1).valid) 155 othersTransSelVec.get(1).bits := Mux(!validVec(0), othersTransPolicy.get.io.enqSelOHVec(0).bits, othersTransPolicy.get.io.enqSelOHVec(1).bits) 156 } 157 158 finalOthersTransSelVec.get.zip(othersTransSelVec.get).zipWithIndex.foreach { case ((finalOH, selOH), enqIdx) => 159 finalOH := Fill(OthersEntryNum, enqCanTrans2Others.get && selOH.valid) & selOH.bits 160 } 161 162 //othersEntryEnq 163 othersEntryEnqVec.zipWithIndex.foreach { case (othersEntryEnq, othersIdx) => 164 val othersEnqOH = finalOthersTransSelVec.get.map(_(othersIdx)) 165 if (othersEnqOH.size == 1) 166 othersEntryEnq := Mux(othersEnqOH.head, enqEntryTransVec.head, 0.U.asTypeOf(enqEntryTransVec.head)) 167 else 168 othersEntryEnq := Mux1H(othersEnqOH, enqEntryTransVec) 169 } 170 } 171 else { 172 //transPolicy 173 simpTransPolicy.get.io.canEnq := VecInit(simpEntryEnqReadyVec).asUInt 174 compTransPolicy.get.io.canEnq := VecInit(validVec.takeRight(CompEntryNum).map(!_)).asUInt 175 176 enqCanTrans2Comp.get := PopCount(validVec.take(EnqEntryNum)) <= PopCount(validVec.takeRight(CompEntryNum).map(!_)) && !validVec.drop(EnqEntryNum).take(SimpEntryNum).reduce(_ || _) 177 enqCanTrans2Simp.get := !enqCanTrans2Comp.get && PopCount(validVec.take(EnqEntryNum)) <= PopCount(simpEntryEnqReadyVec) 178 simpCanTrans2Comp.get.zipWithIndex.foreach { case (canTrans, idx) => 179 canTrans := !enqCanTrans2Comp.get && PopCount(validVec.takeRight(CompEntryNum).map(!_)) >= (idx + 1).U 180 } 181 182 simpTransSelVec.get(0).valid := simpTransPolicy.get.io.enqSelOHVec(0).valid && validVec(0) 183 simpTransSelVec.get(0).bits := simpTransPolicy.get.io.enqSelOHVec(0).bits 184 compTransSelVec.get(0).valid := compTransPolicy.get.io.enqSelOHVec(0).valid && validVec(0) 185 compTransSelVec.get(0).bits := compTransPolicy.get.io.enqSelOHVec(0).bits 186 if (params.numEnq == 2) { 187 simpTransSelVec.get(1).valid := Mux(!validVec(0), simpTransPolicy.get.io.enqSelOHVec(0).valid, simpTransPolicy.get.io.enqSelOHVec(1).valid) 188 simpTransSelVec.get(1).bits := Mux(!validVec(0), simpTransPolicy.get.io.enqSelOHVec(0).bits, simpTransPolicy.get.io.enqSelOHVec(1).bits) 189 compTransSelVec.get(1).valid := Mux(!validVec(0), compTransPolicy.get.io.enqSelOHVec(0).valid, compTransPolicy.get.io.enqSelOHVec(1).valid) 190 compTransSelVec.get(1).bits := Mux(!validVec(0), compTransPolicy.get.io.enqSelOHVec(0).bits, compTransPolicy.get.io.enqSelOHVec(1).bits) 191 } 192 193 finalSimpTransSelVec.get.zip(simpTransSelVec.get).zipWithIndex.foreach { case ((finalOH, selOH), enqIdx) => 194 finalOH := Fill(SimpEntryNum, enqCanTrans2Simp.get && selOH.valid) & selOH.bits 195 } 196 finalCompTransSelVec.get.zip(compTransSelVec.get).zip(compTransPolicy.get.io.enqSelOHVec).zipWithIndex.foreach { 197 case (((finalOH, selOH), origSelOH), enqIdx) => 198 finalOH := Mux(enqCanTrans2Comp.get, Fill(CompEntryNum, selOH.valid) & selOH.bits, Fill(CompEntryNum, origSelOH.valid) & origSelOH.bits) 199 } 200 201 //othersEntryEnq 202 simpEntryEnqVec.zipWithIndex.foreach { case (simpEntryEnq, simpIdx) => 203 val simpEnqOH = finalSimpTransSelVec.get.map(_(simpIdx)) 204 // shit Mux1H directly returns in(0) if the seq has only 1 elements 205 if (simpEnqOH.size == 1) 206 simpEntryEnq := Mux(simpEnqOH.head, enqEntryTransVec.head, 0.U.asTypeOf(enqEntryTransVec.head)) 207 else 208 simpEntryEnq := Mux1H(simpEnqOH, enqEntryTransVec) 209 } 210 211 compEnqVec.get.zip(enqEntryTransVec).zip(io.simpEntryDeqSelVec.get).foreach { case ((compEnq, enqEntry), deqSel) => 212 compEnq := Mux(enqCanTrans2Comp.get, enqEntry, Mux1H(deqSel, simpEntryTransVec.get)) 213 } 214 compEntryEnqVec.zipWithIndex.foreach { case (compEntryEnq, compIdx) => 215 val compEnqOH = finalCompTransSelVec.get.map(_(compIdx)) 216 // shit Mux1H directly returns in(0) if the seq has only 1 elements 217 if (compEnqOH.size == 1) 218 compEntryEnq := Mux(compEnqOH.head, compEnqVec.get.head, 0.U.asTypeOf(compEnqVec.get.head)) 219 else 220 compEntryEnq := Mux1H(compEnqOH, compEnqVec.get) 221 } 222 223 assert(PopCount(simpEntryEnqVec.map(_.valid)) <= params.numEnq.U, "the number of simpEntryEnq is more than numEnq\n") 224 assert(PopCount(compEntryEnqVec.map(_.valid)) <= params.numEnq.U, "the number of compEntryEnq is more than numEnq\n") 225 } 226 227 if(backendParams.debugEn) { 228 dontTouch(othersEntryEnqVec) 229 } 230 231 //issueRespVec 232 if (params.isVecMemIQ) { 233 // vector memory IQ 234 issueRespVec.zip(robIdxVec).zip(uopIdxVec.get).foreach { case ((issueResp, robIdx), uopIdx) => 235 val hitRespsVec = VecInit(resps.flatten.map(x => 236 x.valid && x.bits.robIdx === robIdx && x.bits.uopIdx.get === uopIdx 237 )) 238 issueResp.valid := hitRespsVec.reduce(_ | _) 239 issueResp.bits := Mux1H(hitRespsVec, resps.flatten.map(_.bits)) 240 } 241 } else if (params.isMemAddrIQ) { 242 // scalar memory IQ 243 issueRespVec.zip(robIdxVec).foreach { case (issueResp, robIdx) => 244 val hitRespsVec = VecInit(memEtyResps.map(x => x.valid && (x.bits.robIdx === robIdx)).toSeq) 245 issueResp.valid := hitRespsVec.reduce(_ | _) 246 issueResp.bits := Mux1H(hitRespsVec, memEtyResps.map(_.bits).toSeq) 247 } 248 } 249 else { 250 issueRespVec.zip(issueTimerVec).zip(deqPortIdxReadVec).foreach { case ((issueResp, issueTimer), deqPortIdx) => 251 val Resp = resps(issueTimer)(deqPortIdx) 252 issueResp := Resp 253 } 254 } 255 256 //deq 257 val enqEntryOldest = Wire(Vec(params.numDeq, ValidIO(new EntryBundle))) 258 val simpEntryOldest = OptionWrapper(params.hasCompAndSimp, Wire(Vec(params.numDeq, ValidIO(new EntryBundle)))) 259 val compEntryOldest = OptionWrapper(params.hasCompAndSimp, Wire(Vec(params.numDeq, ValidIO(new EntryBundle)))) 260 val othersEntryOldest = OptionWrapper(params.isAllComp || params.isAllSimp, Wire(Vec(params.numDeq, ValidIO(new EntryBundle)))) 261 val enqEntryOldestCancel = Wire(Vec(params.numDeq, Bool())) 262 val simpEntryOldestCancel = OptionWrapper(params.hasCompAndSimp, Wire(Vec(params.numDeq, Bool()))) 263 val compEntryOldestCancel = OptionWrapper(params.hasCompAndSimp, Wire(Vec(params.numDeq, Bool()))) 264 val othersEntryOldestCancel = OptionWrapper(params.isAllComp || params.isAllSimp, Wire(Vec(params.numDeq, Bool()))) 265 266 io.enqEntryOldestSel.zipWithIndex.map { case (sel, deqIdx) => 267 enqEntryOldest(deqIdx) := Mux1H(sel.bits, entries.take(EnqEntryNum)) 268 enqEntryOldestCancel(deqIdx) := Mux1H(sel.bits, cancelBypassVec.take(EnqEntryNum)) 269 } 270 271 if (params.isAllComp || params.isAllSimp) { 272 io.othersEntryOldestSel.get.zipWithIndex.map { case (sel, deqIdx) => 273 othersEntryOldest.get(deqIdx) := Mux1H(sel.bits, entries.drop(EnqEntryNum)) 274 othersEntryOldestCancel.get(deqIdx) := Mux1H(sel.bits, cancelBypassVec.drop(EnqEntryNum)) 275 } 276 } 277 else { 278 io.simpEntryOldestSel.get.zipWithIndex.map { case (sel, deqIdx) => 279 simpEntryOldest.get(deqIdx) := Mux1H(sel.bits, entries.drop(EnqEntryNum).take(SimpEntryNum)) 280 simpEntryOldestCancel.get(deqIdx) := Mux1H(sel.bits, cancelBypassVec.drop(EnqEntryNum).take(SimpEntryNum)) 281 } 282 io.compEntryOldestSel.get.zipWithIndex.map { case (sel, deqIdx) => 283 compEntryOldest.get(deqIdx) := Mux1H(sel.bits, entries.drop(EnqEntryNum).takeRight(CompEntryNum)) 284 compEntryOldestCancel.get(deqIdx) := Mux1H(sel.bits, cancelBypassVec.drop(EnqEntryNum).takeRight(CompEntryNum)) 285 } 286 } 287 288 if (params.deqFuSame) { 289 val subDeqPolicyEntryVec = Wire(Vec(params.numDeq, ValidIO(new EntryBundle))) 290 val subDeqPolicyValidVec = Wire(Vec(params.numDeq, Bool())) 291 val subDeqPolicyCancelBypassVec = Wire(Vec(params.numDeq, Bool())) 292 293 subDeqPolicyValidVec(0) := PopCount(io.subDeqRequest.get(0)) >= 1.U 294 subDeqPolicyValidVec(1) := PopCount(io.subDeqRequest.get(0)) >= 2.U 295 296 if (params.isAllComp || params.isAllSimp) { 297 subDeqPolicyEntryVec(0) := PriorityMux(io.subDeqRequest.get(0), entries) 298 subDeqPolicyEntryVec(1) := PriorityMux(Reverse(io.subDeqRequest.get(0)), entries.reverse) 299 subDeqPolicyCancelBypassVec(0) := PriorityMux(io.subDeqRequest.get(0), cancelBypassVec) 300 subDeqPolicyCancelBypassVec(1) := PriorityMux(Reverse(io.subDeqRequest.get(0)), cancelBypassVec.reverse) 301 302 io.deqEntry(0) := Mux(io.othersEntryOldestSel.get(0).valid, othersEntryOldest.get(0), subDeqPolicyEntryVec(1)) 303 io.deqEntry(1) := subDeqPolicyEntryVec(0) 304 io.cancelDeqVec(0) := Mux(io.othersEntryOldestSel.get(0).valid, othersEntryOldestCancel.get(0), subDeqPolicyCancelBypassVec(1)) 305 io.cancelDeqVec(1) := subDeqPolicyCancelBypassVec(0) 306 } 307 else { 308 subDeqPolicyEntryVec(0) := PriorityMux(Reverse(io.subDeqRequest.get(0)), entries.reverse) 309 subDeqPolicyEntryVec(1) := PriorityMux(io.subDeqRequest.get(0), entries) 310 subDeqPolicyCancelBypassVec(0) := PriorityMux(Reverse(io.subDeqRequest.get(0)), cancelBypassVec.reverse) 311 subDeqPolicyCancelBypassVec(1) := PriorityMux(io.subDeqRequest.get(0), cancelBypassVec) 312 313 io.deqEntry(0) := Mux(io.compEntryOldestSel.get(0).valid, 314 compEntryOldest.get(0), 315 Mux(io.simpEntryOldestSel.get(0).valid, simpEntryOldest.get(0), subDeqPolicyEntryVec(1))) 316 io.deqEntry(1) := subDeqPolicyEntryVec(0) 317 io.cancelDeqVec(0) := Mux(io.compEntryOldestSel.get(0).valid, 318 compEntryOldestCancel.get(0), 319 Mux(io.simpEntryOldestSel.get(0).valid, simpEntryOldestCancel.get(0), subDeqPolicyCancelBypassVec(1))) 320 io.cancelDeqVec(1) := subDeqPolicyCancelBypassVec(0) 321 } 322 323 when (subDeqPolicyValidVec(0)) { 324 assert(Mux1H(io.subDeqSelOH.get(0), entries).bits.status.robIdx === subDeqPolicyEntryVec(0).bits.status.robIdx, "subDeqSelOH(0) is not the same\n") 325 } 326 when (subDeqPolicyValidVec(1)) { 327 assert(Mux1H(io.subDeqSelOH.get(1), entries).bits.status.robIdx === subDeqPolicyEntryVec(1).bits.status.robIdx, "subDeqSelOH(1) is not the same\n") 328 } 329 } 330 else { 331 if (params.isAllComp || params.isAllSimp) { 332 io.othersEntryOldestSel.get.zipWithIndex.foreach { case (sel, i) => 333 io.deqEntry(i) := Mux(sel.valid, othersEntryOldest.get(i), enqEntryOldest(i)) 334 io.cancelDeqVec(i) := Mux(sel.valid, othersEntryOldestCancel.get(i), enqEntryOldestCancel(i)) 335 } 336 } 337 else { 338 io.compEntryOldestSel.get.zip(io.simpEntryOldestSel.get).zipWithIndex.foreach { case ((compSel, simpSel), i) => 339 io.deqEntry(i) := Mux(compSel.valid, 340 compEntryOldest.get(i), 341 Mux(simpSel.valid, simpEntryOldest.get(i), enqEntryOldest(i))) 342 io.cancelDeqVec(i) := Mux(compSel.valid, 343 compEntryOldestCancel.get(i), 344 Mux(simpSel.valid, simpEntryOldestCancel.get(i), enqEntryOldestCancel(i))) 345 } 346 } 347 } 348 349 if (params.hasIQWakeUp) { 350 cancelBypassVec.zip(srcWakeUpL1ExuOHVec.get).zip(srcTimerVec.get).zip(srcLoadDependencyVec).foreach{ case (((cancelBypass: Bool, l1ExuOH: Vec[Vec[Bool]]), srcTimer: Vec[UInt]), srcLoadDependency: Vec[Vec[UInt]]) => 351 val cancelByOg0 = l1ExuOH.zip(srcTimer).map { 352 case(exuOH, srcTimer) => 353 (exuOH.asUInt & io.og0Cancel.asUInt).orR && srcTimer === 1.U 354 }.reduce(_ | _) 355 val cancelByLd = srcLoadDependency.map(x => LoadShouldCancel(Some(x), io.ldCancel)).reduce(_ | _) 356 cancelBypass := cancelByOg0 || cancelByLd 357 } 358 } else { 359 cancelBypassVec.zip(srcLoadDependencyVec).foreach { case (cancelBypass, srcLoadDependency) => 360 val cancelByLd = srcLoadDependency.map(x => LoadShouldCancel(Some(x), io.ldCancel)).reduce(_ | _) 361 cancelBypass := cancelByLd 362 } 363 } 364 365 io.valid := validVec.asUInt 366 io.canIssue := canIssueVec.asUInt 367 io.fuType := fuTypeVec 368 io.dataSources := dataSourceVec 369 io.srcWakeUpL1ExuOH.foreach(_ := srcWakeUpL1ExuOHVec.get.map(x => VecInit(x.map(_.asUInt)))) 370 io.srcTimer.foreach(_ := srcTimerVec.get) 371 io.loadDependency := loadDependencyVec 372 io.isFirstIssue.zipWithIndex.foreach{ case (isFirstIssue, deqIdx) => 373 isFirstIssue := io.deqSelOH(deqIdx).valid && Mux1H(io.deqSelOH(deqIdx).bits, isFirstIssueVec) 374 } 375 io.simpEntryEnqSelVec.foreach(_ := finalSimpTransSelVec.get.zip(enqEntryTransVec).map(x => x._1 & Fill(SimpEntryNum, x._2.valid))) 376 io.compEntryEnqSelVec.foreach(_ := finalCompTransSelVec.get.zip(compEnqVec.get).map(x => x._1 & Fill(CompEntryNum, x._2.valid))) 377 io.othersEntryEnqSelVec.foreach(_ := finalOthersTransSelVec.get.zip(enqEntryTransVec).map(x => x._1 & Fill(OthersEntryNum, x._2.valid))) 378 io.robIdx.foreach(_ := robIdxVec) 379 io.uopIdx.foreach(_ := uopIdxVec.get) 380 io.rsFeedback := 0.U.asTypeOf(io.rsFeedback) //should be removed 381 io.cancel.foreach(_ := cancelVec.get) //for debug 382 383 def EntriesConnect(in: CommonInBundle, out: CommonOutBundle, entryIdx: Int) = { 384 in.flush := io.flush 385 in.wakeUpFromWB := io.wakeUpFromWB 386 in.wakeUpFromIQ := io.wakeUpFromIQ 387 in.og0Cancel := io.og0Cancel 388 in.og1Cancel := io.og1Cancel 389 in.ldCancel := io.ldCancel 390 in.deqSel := deqSelVec(entryIdx) 391 in.deqPortIdxWrite := deqPortIdxWriteVec(entryIdx) 392 in.issueResp := issueRespVec(entryIdx) 393 if (params.isMemAddrIQ) { 394 in.fromMem.get.stIssuePtr := io.fromMem.get.stIssuePtr 395 in.fromMem.get.memWaitUpdateReq := io.fromMem.get.memWaitUpdateReq 396 } 397 if (params.isVecMemIQ) { 398 in.fromLsq.get.sqDeqPtr := io.vecMemIn.get.sqDeqPtr 399 in.fromLsq.get.lqDeqPtr := io.vecMemIn.get.lqDeqPtr 400 } 401 validVec(entryIdx) := out.valid 402 canIssueVec(entryIdx) := out.canIssue 403 fuTypeVec(entryIdx) := out.fuType 404 robIdxVec(entryIdx) := out.robIdx 405 dataSourceVec(entryIdx) := out.dataSource 406 isFirstIssueVec(entryIdx) := out.isFirstIssue 407 entries(entryIdx) := out.entry 408 deqPortIdxReadVec(entryIdx) := out.deqPortIdxRead 409 issueTimerVec(entryIdx) := out.issueTimerRead 410 srcLoadDependencyVec(entryIdx) := out.srcLoadDependency 411 loadDependencyVec(entryIdx) := out.entry.bits.status.mergedLoadDependency 412 if (params.hasIQWakeUp) { 413 srcWakeUpL1ExuOHVec.get(entryIdx) := out.srcWakeUpL1ExuOH.get 414 srcTimerVec.get(entryIdx) := out.srcTimer.get 415 cancelVec.get(entryIdx) := out.cancel.get 416 } 417 if (params.isVecMemIQ) { 418 uopIdxVec.get(entryIdx) := out.uopIdx.get 419 } 420 entryInValidVec(entryIdx) := out.entryInValid 421 entryOutDeqValidVec(entryIdx) := out.entryOutDeqValid 422 entryOutTransValidVec(entryIdx) := out.entryOutTransValid 423 } 424 425 // entries perf counter 426 // enq 427 for (i <- 0 until params.numEnq) { 428 XSPerfAccumulate(s"enqEntry_${i}_in_cnt", entryInValidVec(i)) 429 XSPerfAccumulate(s"enqEntry_${i}_out_deq_cnt", entryOutDeqValidVec(i)) 430 XSPerfAccumulate(s"enqEntry_${i}_out_trans_cnt", entryOutTransValidVec(i)) 431 } 432 // simple 433 for (i <- 0 until params.numSimp) { 434 XSPerfAccumulate(s"simpEntry_${i}_in_cnt", entryInValidVec(i + params.numEnq)) 435 XSPerfAccumulate(s"simpEntry_${i}_out_deq_cnt", entryOutDeqValidVec(i + params.numEnq)) 436 XSPerfAccumulate(s"simpEntry_${i}_out_trans_cnt", entryOutTransValidVec(i + params.numEnq)) 437 } 438 // complex 439 for (i <- 0 until params.numComp) { 440 XSPerfAccumulate(s"compEntry_${i}_in_cnt", entryInValidVec(i + params.numEnq + params.numSimp)) 441 XSPerfAccumulate(s"compEntry_${i}_out_deq_cnt", entryOutDeqValidVec(i + params.numEnq + params.numSimp)) 442 XSPerfAccumulate(s"compEntry_${i}_out_trans_cnt", entryOutTransValidVec(i + params.numEnq + params.numSimp)) 443 } 444 // total 445 XSPerfAccumulate(s"enqEntry_all_in_cnt", PopCount(entryInValidVec.take(params.numEnq))) 446 XSPerfAccumulate(s"enqEntry_all_out_deq_cnt", PopCount(entryOutDeqValidVec.take(params.numEnq))) 447 XSPerfAccumulate(s"enqEntry_all_out_trans_cnt", PopCount(entryOutTransValidVec.take(params.numEnq))) 448 449 XSPerfAccumulate(s"othersEntry_all_in_cnt", PopCount(entryInValidVec.drop(params.numEnq))) 450 XSPerfAccumulate(s"othersEntry_all_out_deq_cnt", PopCount(entryOutDeqValidVec.drop(params.numEnq))) 451 XSPerfAccumulate(s"othersEntry_all_out_trans_cnt", PopCount(entryOutTransValidVec.drop(params.numEnq))) 452} 453 454class EntriesIO(implicit p: Parameters, params: IssueBlockParams) extends XSBundle { 455 val flush = Flipped(ValidIO(new Redirect)) 456 //enq 457 val enq = Vec(params.numEnq, Flipped(ValidIO(new EntryBundle))) 458 val og0Resp = Vec(params.numDeq, Flipped(ValidIO(new EntryDeqRespBundle))) 459 val og1Resp = Vec(params.numDeq, Flipped(ValidIO(new EntryDeqRespBundle))) 460 val finalIssueResp = OptionWrapper(params.LdExuCnt > 0, Vec(params.numDeq, Flipped(ValidIO(new EntryDeqRespBundle)))) 461 val memAddrIssueResp = OptionWrapper(params.LdExuCnt > 0, Vec(params.numDeq, Flipped(ValidIO(new EntryDeqRespBundle)))) 462 //deq sel 463 val deqReady = Vec(params.numDeq, Input(Bool())) 464 val deqSelOH = Vec(params.numDeq, Flipped(ValidIO(UInt(params.numEntries.W)))) 465 val enqEntryOldestSel = Vec(params.numDeq, Flipped(ValidIO(UInt(params.numEnq.W)))) 466 val simpEntryOldestSel = OptionWrapper(params.hasCompAndSimp, Vec(params.numDeq, Flipped(ValidIO(UInt(params.numSimp.W))))) 467 val compEntryOldestSel = OptionWrapper(params.hasCompAndSimp, Vec(params.numDeq, Flipped(ValidIO(UInt(params.numComp.W))))) 468 val othersEntryOldestSel= OptionWrapper(params.isAllComp || params.isAllSimp, Vec(params.numDeq, Flipped(ValidIO(UInt((params.numEntries - params.numEnq).W))))) 469 val subDeqRequest = OptionWrapper(params.deqFuSame, Vec(params.numDeq, Input(UInt(params.numEntries.W)))) 470 val subDeqSelOH = OptionWrapper(params.deqFuSame, Vec(params.numDeq, Input(UInt(params.numEntries.W)))) 471 // wakeup 472 val wakeUpFromWB: MixedVec[ValidIO[IssueQueueWBWakeUpBundle]] = Flipped(params.genWBWakeUpSinkValidBundle) 473 val wakeUpFromIQ: MixedVec[ValidIO[IssueQueueIQWakeUpBundle]] = Flipped(params.genIQWakeUpSinkValidBundle) 474 val og0Cancel = Input(ExuOH(backendParams.numExu)) 475 val og1Cancel = Input(ExuOH(backendParams.numExu)) 476 val ldCancel = Vec(backendParams.LdExuCnt, Flipped(new LoadCancelIO)) 477 //entries status 478 val valid = Output(UInt(params.numEntries.W)) 479 val canIssue = Output(UInt(params.numEntries.W)) 480 val fuType = Vec(params.numEntries, Output(FuType())) 481 val dataSources = Vec(params.numEntries, Vec(params.numRegSrc, Output(DataSource()))) 482 val loadDependency = Vec(params.numEntries, Vec(LoadPipelineWidth, UInt(3.W))) 483 val srcWakeUpL1ExuOH = OptionWrapper(params.hasIQWakeUp, Vec(params.numEntries, Vec(params.numRegSrc, Output(ExuOH())))) 484 val srcTimer = OptionWrapper(params.hasIQWakeUp, Vec(params.numEntries, Vec(params.numRegSrc, Output(UInt(3.W))))) 485 //deq status 486 val isFirstIssue = Vec(params.numDeq, Output(Bool())) 487 val deqEntry = Vec(params.numDeq, ValidIO(new EntryBundle)) 488 val cancelDeqVec = Vec(params.numDeq, Output(Bool())) 489 // mem only 490 val fromMem = if (params.isMemAddrIQ) Some(new Bundle { 491 val stIssuePtr = Input(new SqPtr) 492 val memWaitUpdateReq = Flipped(new MemWaitUpdateReq) 493 val slowResp = Vec(params.numDeq, Flipped(ValidIO(new EntryDeqRespBundle))) 494 val fastResp = Vec(params.numDeq, Flipped(ValidIO(new EntryDeqRespBundle))) 495 }) else None 496 val vecMemIn = OptionWrapper(params.isVecMemIQ, new Bundle { 497 val sqDeqPtr = Input(new SqPtr) 498 val lqDeqPtr = Input(new LqPtr) 499 }) 500 501 val robIdx = OptionWrapper(params.isVecMemIQ, Output(Vec(params.numEntries, new RobPtr))) 502 val uopIdx = OptionWrapper(params.isVecMemIQ, Output(Vec(params.numEntries, UopIdx()))) 503 504 val rsFeedback = Output(Vec(5, Bool())) 505 // trans 506 val simpEntryDeqSelVec = OptionWrapper(params.hasCompAndSimp, Vec(params.numEnq, Input(UInt(params.numSimp.W)))) 507 val simpEntryEnqSelVec = OptionWrapper(params.hasCompAndSimp, Vec(params.numEnq, Output(UInt(params.numSimp.W)))) 508 val compEntryEnqSelVec = OptionWrapper(params.hasCompAndSimp, Vec(params.numEnq, Output(UInt(params.numComp.W)))) 509 val othersEntryEnqSelVec = OptionWrapper(params.isAllComp || params.isAllSimp, Vec(params.numEnq, Output(UInt((params.numEntries - params.numEnq).W)))) 510 511 // debug 512 val cancel = OptionWrapper(params.hasIQWakeUp, Output(Vec(params.numEntries, Bool()))) 513 514 def wakeup = wakeUpFromWB ++ wakeUpFromIQ 515} 516