Skip to content

Commit

Permalink
Backend&MemBlock: feedback use sqidx instead of robidx and uopidx for…
Browse files Browse the repository at this point in the history
… fix timing (#3172)
  • Loading branch information
xiaofeibao-xjtu committed Jul 10, 2024
1 parent e6ac7fe commit 38f78b5
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/xiangshan/Bundle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ class RSFeedback(isVector: Boolean = false)(implicit p: Parameters) extends XSBu
val flushState = Bool()
val sourceType = RSFeedbackType()
val dataInvalidSqIdx = new SqPtr
val uopIdx = OptionWrapper(isVector, UopIdx())
val sqIdx = new SqPtr
}

class MemRSFeedbackIO(isVector: Boolean = false)(implicit p: Parameters) extends XSBundle {
Expand Down
7 changes: 6 additions & 1 deletion src/main/scala/xiangshan/backend/Backend.scala
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ class BackendImp(override val wrapper: Backend)(implicit p: Parameters) extends
memScheduler.io.loadFinalIssueResp(i)(j).bits.resp := RespType.block
memScheduler.io.loadFinalIssueResp(i)(j).bits.robIdx := toMem(i)(j).bits.robIdx
memScheduler.io.loadFinalIssueResp(i)(j).bits.uopIdx.foreach(_ := toMem(i)(j).bits.vpu.get.vuopIdx)
memScheduler.io.loadFinalIssueResp(i)(j).bits.sqIdx.foreach(_ := toMem(i)(j).bits.sqIdx.get)
}

NewPipelineConnect(
Expand All @@ -556,6 +557,7 @@ class BackendImp(override val wrapper: Backend)(implicit p: Parameters) extends
memScheduler.io.memAddrIssueResp(i)(j).valid := toMem(i)(j).fire && FuType.isLoad(toMem(i)(j).bits.fuType)
memScheduler.io.memAddrIssueResp(i)(j).bits.fuType := toMem(i)(j).bits.fuType
memScheduler.io.memAddrIssueResp(i)(j).bits.robIdx := toMem(i)(j).bits.robIdx
memScheduler.io.memAddrIssueResp(i)(j).bits.sqIdx.foreach(_ := toMem(i)(j).bits.sqIdx.get)
memScheduler.io.memAddrIssueResp(i)(j).bits.resp := RespType.success // for load inst, firing at toMem means issuing successfully
}

Expand All @@ -566,9 +568,12 @@ class BackendImp(override val wrapper: Backend)(implicit p: Parameters) extends
resp.bits.fuType := toMem(i)(j).bits.fuType
resp.bits.robIdx := toMem(i)(j).bits.robIdx
resp.bits.uopIdx.get := toMem(i)(j).bits.vpu.get.vuopIdx
resp.bits.sqIdx.get := toMem(i)(j).bits.sqIdx.get
resp.bits.resp := RespType.success
}
dontTouch(memScheduler.io.vecLoadIssueResp(i)(j))
if (backendParams.debugEn){
dontTouch(memScheduler.io.vecLoadIssueResp(i)(j))
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/scala/xiangshan/backend/datapath/DataPath.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import xiangshan.backend.Bundles._
import xiangshan.backend.decode.ImmUnion
import xiangshan.backend.datapath.DataConfig._
import xiangshan.backend.datapath.RdConfig._
import xiangshan.backend.issue.{ImmExtractor, IntScheduler, MemScheduler, VfScheduler, FpScheduler}
import xiangshan.backend.issue.{FpScheduler, ImmExtractor, IntScheduler, MemScheduler, VfScheduler}
import xiangshan.backend.issue.EntryBundles._
import xiangshan.backend.regfile._
import xiangshan.backend.PcToDataPathIO
import xiangshan.backend.fu.FuType.is0latency
import xiangshan.mem.SqPtr

class DataPath(params: BackendParams)(implicit p: Parameters) extends LazyModule {
override def shouldBeInlined: Boolean = false
Expand Down Expand Up @@ -547,6 +548,7 @@ class DataPathImp(override val wrapper: DataPath)(implicit p: Parameters, params
og0resp.valid := og0FailedVec2(iqIdx)(iuIdx)
og0resp.bits.robIdx := fromIQ(iqIdx)(iuIdx).bits.common.robIdx
og0resp.bits.uopIdx.foreach(_ := fromIQ(iqIdx)(iuIdx).bits.common.vpu.get.vuopIdx)
og0resp.bits.sqIdx.foreach(_ := 0.U.asTypeOf(new SqPtr))
og0resp.bits.resp := RespType.block
og0resp.bits.fuType := fromIQ(iqIdx)(iuIdx).bits.common.fuType

Expand All @@ -555,6 +557,7 @@ class DataPathImp(override val wrapper: DataPath)(implicit p: Parameters, params
og1resp.valid := s1_toExuValid(iqIdx)(iuIdx)
og1resp.bits.robIdx := s1_toExuData(iqIdx)(iuIdx).robIdx
og1resp.bits.uopIdx.foreach(_ := s1_toExuData(iqIdx)(iuIdx).vpu.get.vuopIdx)
og1resp.bits.sqIdx.foreach(_ := 0.U.asTypeOf(new SqPtr))
// respType: fuIdle ->IQ entry clear
// fuUncertain ->IQ entry no action
// fuBusy ->IQ entry issued set false, then re-issue
Expand Down
14 changes: 6 additions & 8 deletions src/main/scala/xiangshan/backend/issue/Entries.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Entries(implicit p: Parameters, params: IssueBlockParams) extends XSModule
val fuTypeVec = Wire(Vec(params.numEntries, FuType()))
val isFirstIssueVec = Wire(Vec(params.numEntries, Bool()))
val issueTimerVec = Wire(Vec(params.numEntries, UInt(2.W)))
val uopIdxVec = OptionWrapper(params.isVecMemIQ, Wire(Vec(params.numEntries, UopIdx())))
val sqIdxVec = OptionWrapper(params.needFeedBackSqIdx, Wire(Vec(params.numEntries, new SqPtr())))
//src status
val dataSourceVec = Wire(Vec(params.numEntries, Vec(params.numRegSrc, DataSource())))
val loadDependencyVec = Wire(Vec(params.numEntries, Vec(LoadPipelineWidth, UInt(LoadDependencyWidth.W))))
Expand Down Expand Up @@ -268,13 +268,13 @@ class Entries(implicit p: Parameters, params: IssueBlockParams) extends XSModule
}

//issueRespVec
if (params.isVecMemIQ) {
if (params.needFeedBackSqIdx) {
// vector memory IQ
issueRespVec.lazyZip(robIdxVec.lazyZip(uopIdxVec.get)).lazyZip(issueTimerVec.lazyZip(deqPortIdxReadVec)).foreach { case (issueResp, (robIdx, uopIdx), (issueTimer, deqPortIdx)) =>
issueRespVec.lazyZip(sqIdxVec.get).lazyZip(issueTimerVec.lazyZip(deqPortIdxReadVec)).foreach { case (issueResp, sqIdx, (issueTimer, deqPortIdx)) =>
val respInDatapath = resps(issueTimer(0))(deqPortIdx)
val respAfterDatapath = Wire(chiselTypeOf(respInDatapath))
val hitRespsVec = VecInit(memEtyResps.map(x =>
x.valid && x.bits.robIdx === robIdx && x.bits.uopIdx.get === uopIdx
x.valid && (x.bits.sqIdx.get === sqIdx)
).toSeq)
respAfterDatapath.valid := hitRespsVec.reduce(_ | _)
respAfterDatapath.bits := (if (memEtyResps.size == 1) memEtyResps.head.bits
Expand Down Expand Up @@ -406,7 +406,6 @@ class Entries(implicit p: Parameters, params: IssueBlockParams) extends XSModule
io.compEntryEnqSelVec.foreach(_ := finalCompTransSelVec.get.zip(compEnqVec.get).map(x => x._1 & Fill(CompEntryNum, x._2.valid)))
io.othersEntryEnqSelVec.foreach(_ := finalOthersTransSelVec.get.zip(enqEntryTransVec).map(x => x._1 & Fill(OthersEntryNum, x._2.valid)))
io.robIdx.foreach(_ := robIdxVec)
io.uopIdx.foreach(_ := uopIdxVec.get)


def EntriesConnect(in: CommonInBundle, out: CommonOutBundle, entryIdx: Int) = {
Expand Down Expand Up @@ -439,8 +438,8 @@ class Entries(implicit p: Parameters, params: IssueBlockParams) extends XSModule
if (params.hasIQWakeUp) {
srcWakeUpL1ExuOHVec.get(entryIdx) := out.srcWakeUpL1ExuOH.get
}
if (params.isVecMemIQ) {
uopIdxVec.get(entryIdx) := out.uopIdx.get
if (params.isVecMemIQ || params.isStAddrIQ) {
sqIdxVec.get(entryIdx) := out.entry.bits.payload.sqIdx
}
entryInValidVec(entryIdx) := out.entryInValid
entryOutDeqValidVec(entryIdx) := out.entryOutDeqValid
Expand Down Expand Up @@ -576,7 +575,6 @@ class EntriesIO(implicit p: Parameters, params: IssueBlockParams) extends XSBund
val resp = Vec(params.numDeq, Flipped(ValidIO(new EntryDeqRespBundle)))
})
val robIdx = OptionWrapper(params.isVecMemIQ, Output(Vec(params.numEntries, new RobPtr)))
val uopIdx = OptionWrapper(params.isVecMemIQ, Output(Vec(params.numEntries, UopIdx())))

// trans
val simpEntryDeqSelVec = OptionWrapper(params.hasCompAndSimp, Vec(params.numEnq, Input(UInt(params.numSimp.W))))
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/xiangshan/backend/issue/EntryBundles.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ object EntryBundles extends HasCircularQueuePtrHelper {
val numLsElem = NumLsElem()
}

class EntryDeqRespBundle(implicit p: Parameters, params: IssueBlockParams) extends Bundle {
class EntryDeqRespBundle(implicit p: Parameters, params: IssueBlockParams) extends XSBundle {
val robIdx = new RobPtr
val resp = RespType()
val fuType = FuType()
val uopIdx = OptionWrapper(params.isVecMemIQ, Output(UopIdx()))
val sqIdx = OptionWrapper(params.needFeedBackSqIdx, new SqPtr())
}

object RespType {
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/xiangshan/backend/issue/IssueBlockParams.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ case class IssueBlockParams(

def isVecMemIQ: Boolean = isVecLduIQ || isVecStuIQ

def needFeedBackSqIdx: Boolean = isVecMemIQ || isStAddrIQ

def numExu: Int = exuBlockParams.count(!_.fakeUnit)

def numIntSrc: Int = exuBlockParams.map(_.numIntSrc).max
Expand Down
9 changes: 7 additions & 2 deletions src/main/scala/xiangshan/backend/issue/IssueQueue.scala
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ class IssueQueueImp(override val wrapper: IssueQueue)(implicit p: Parameters, va
deqResp.valid := finalDeqSelValidVec(i)
deqResp.bits.resp := RespType.success
deqResp.bits.robIdx := DontCare
deqResp.bits.sqIdx.foreach(_ := DontCare)
deqResp.bits.fuType := deqBeforeDly(i).bits.common.fuType
deqResp.bits.uopIdx.foreach(_ := DontCare)
}
Expand Down Expand Up @@ -1048,13 +1049,15 @@ class IssueQueueMemAddrImp(override val wrapper: IssueQueue)(implicit p: Paramet
entries.io.fromMem.get.slowResp.zipWithIndex.foreach { case (slowResp, i) =>
slowResp.valid := memIO.feedbackIO(i).feedbackSlow.valid
slowResp.bits.robIdx := memIO.feedbackIO(i).feedbackSlow.bits.robIdx
slowResp.bits.sqIdx.foreach( _ := memIO.feedbackIO(i).feedbackSlow.bits.sqIdx)
slowResp.bits.resp := Mux(memIO.feedbackIO(i).feedbackSlow.bits.hit, RespType.success, RespType.block)
slowResp.bits.fuType := DontCare
}

entries.io.fromMem.get.fastResp.zipWithIndex.foreach { case (fastResp, i) =>
fastResp.valid := memIO.feedbackIO(i).feedbackFast.valid
fastResp.bits.robIdx := memIO.feedbackIO(i).feedbackFast.bits.robIdx
fastResp.bits.sqIdx.foreach( _ := memIO.feedbackIO(i).feedbackFast.bits.sqIdx)
fastResp.bits.resp := Mux(memIO.feedbackIO(i).feedbackFast.bits.hit, RespType.success, RespType.block)
fastResp.bits.fuType := DontCare
}
Expand Down Expand Up @@ -1126,17 +1129,19 @@ class IssueQueueVecMemImp(override val wrapper: IssueQueue)(implicit p: Paramete
entries.io.fromMem.get.slowResp.zipWithIndex.foreach { case (slowResp, i) =>
slowResp.valid := memIO.feedbackIO(i).feedbackSlow.valid
slowResp.bits.robIdx := memIO.feedbackIO(i).feedbackSlow.bits.robIdx
slowResp.bits.sqIdx.get := memIO.feedbackIO(i).feedbackSlow.bits.sqIdx
slowResp.bits.resp := Mux(memIO.feedbackIO(i).feedbackSlow.bits.hit, RespType.success, RespType.block)
slowResp.bits.fuType := DontCare
slowResp.bits.uopIdx.get := memIO.feedbackIO(i).feedbackSlow.bits.uopIdx.get
slowResp.bits.uopIdx.get := DontCare
}

entries.io.fromMem.get.fastResp.zipWithIndex.foreach { case (fastResp, i) =>
fastResp.valid := memIO.feedbackIO(i).feedbackFast.valid
fastResp.bits.robIdx := memIO.feedbackIO(i).feedbackFast.bits.robIdx
fastResp.bits.sqIdx.get := memIO.feedbackIO(i).feedbackFast.bits.sqIdx
fastResp.bits.resp := Mux(memIO.feedbackIO(i).feedbackFast.bits.hit, RespType.success, RespType.block)
fastResp.bits.fuType := DontCare
fastResp.bits.uopIdx.get := memIO.feedbackIO(i).feedbackFast.bits.uopIdx.get
fastResp.bits.uopIdx.get := DontCare
}

entries.io.vecMemIn.get.sqDeqPtr := memIO.sqDeqPtr.get
Expand Down
3 changes: 0 additions & 3 deletions src/main/scala/xiangshan/mem/MemCommon.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ class LsPipelineBundle(implicit p: Parameters) extends XSBundle
val af = Bool()
val mmio = Bool()
val atomic = Bool()
val rsIdx = UInt(log2Up(MemIQSizeMax).W)

val forwardMask = Vec(VLEN/8, Bool())
val forwardData = Vec(VLEN/8, UInt(8.W))
Expand Down Expand Up @@ -166,7 +165,6 @@ class LdPrefetchTrainBundle(implicit p: Parameters) extends LsPipelineBundle {
if (latch) ptwBack := RegEnable(input.ptwBack, enable) else ptwBack := input.ptwBack
if (latch) af := RegEnable(input.af, enable) else af := input.af
if (latch) mmio := RegEnable(input.mmio, enable) else mmio := input.mmio
if (latch) rsIdx := RegEnable(input.rsIdx, enable) else rsIdx := input.rsIdx
if (latch) forwardMask := RegEnable(input.forwardMask, enable) else forwardMask := input.forwardMask
if (latch) forwardData := RegEnable(input.forwardData, enable) else forwardData := input.forwardData
if (latch) isPrefetch := RegEnable(input.isPrefetch, enable) else isPrefetch := input.isPrefetch
Expand Down Expand Up @@ -242,7 +240,6 @@ class LqWriteBundle(implicit p: Parameters) extends LsPipelineBundle {
if(latch) ptwBack := RegEnable(input.ptwBack, enable) else ptwBack := input.ptwBack
if(latch) mmio := RegEnable(input.mmio, enable) else mmio := input.mmio
if(latch) atomic := RegEnable(input.atomic, enable) else atomic := input.atomic
if(latch) rsIdx := RegEnable(input.rsIdx, enable) else rsIdx := input.rsIdx
if(latch) forwardMask := RegEnable(input.forwardMask, enable) else forwardMask := input.forwardMask
if(latch) forwardData := RegEnable(input.forwardData, enable) else forwardData := input.forwardData
if(latch) isPrefetch := RegEnable(input.isPrefetch, enable) else isPrefetch := input.isPrefetch
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/xiangshan/mem/pipeline/AtomicsUnit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class AtomicsUnit(implicit p: Parameters) extends XSModule
io.feedbackSlow.valid := GatedValidRegNext(GatedValidRegNext(io.in.valid))
io.feedbackSlow.bits.hit := true.B
io.feedbackSlow.bits.robIdx := RegEnable(io.in.bits.uop.robIdx, io.in.valid)
io.feedbackSlow.bits.sqIdx := RegEnable(io.in.bits.uop.sqIdx, io.in.valid)
io.feedbackSlow.bits.flushState := DontCare
io.feedbackSlow.bits.sourceType := DontCare
io.feedbackSlow.bits.dataInvalidSqIdx := DontCare
Expand Down
11 changes: 0 additions & 11 deletions src/main/scala/xiangshan/mem/pipeline/HybridUnit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ class HybridUnit(implicit p: Parameters) extends XSModule
val s0_mask = Wire(UInt((VLEN/8).W))
val s0_uop = Wire(new DynInst)
val s0_has_rob_entry = Wire(Bool())
val s0_rsIdx = Wire(UInt(log2Up(MemIQSizeMax).W))
val s0_mshrid = Wire(UInt())
val s0_try_l2l = Wire(Bool())
val s0_rep_carry = Wire(new ReplayCarry(nWays))
Expand Down Expand Up @@ -352,7 +351,6 @@ class HybridUnit(implicit p: Parameters) extends XSModule
s0_uop := 0.U.asTypeOf(new DynInst)
s0_try_l2l := false.B
s0_has_rob_entry := false.B
s0_rsIdx := 0.U
s0_rep_carry := 0.U.asTypeOf(s0_rep_carry.cloneType)
s0_mshrid := 0.U
s0_isFirstIssue := false.B
Expand All @@ -373,7 +371,6 @@ class HybridUnit(implicit p: Parameters) extends XSModule
s0_has_rob_entry := src.hasROBEntry
s0_rep_carry := src.rep_info.rep_carry
s0_mshrid := src.rep_info.mshr_id
s0_rsIdx := src.rsIdx
s0_isFirstIssue := false.B
s0_fast_rep := true.B
s0_ld_rep := src.isLoadReplay
Expand All @@ -390,7 +387,6 @@ class HybridUnit(implicit p: Parameters) extends XSModule
s0_uop := src.uop
s0_try_l2l := false.B
s0_has_rob_entry := true.B
s0_rsIdx := src.rsIdx
s0_rep_carry := src.replayCarry
s0_mshrid := src.mshrid
s0_isFirstIssue := false.B
Expand All @@ -409,7 +405,6 @@ class HybridUnit(implicit p: Parameters) extends XSModule
s0_uop := DontCare
s0_try_l2l := false.B
s0_has_rob_entry := false.B
s0_rsIdx := 0.U
s0_rep_carry := 0.U.asTypeOf(s0_rep_carry.cloneType)
s0_mshrid := 0.U
s0_isFirstIssue := false.B
Expand All @@ -428,7 +423,6 @@ class HybridUnit(implicit p: Parameters) extends XSModule
s0_uop := src.uop
s0_try_l2l := false.B
s0_has_rob_entry := true.B
s0_rsIdx := src.iqIdx
s0_rep_carry := 0.U.asTypeOf(s0_rep_carry.cloneType)
s0_mshrid := 0.U
s0_isFirstIssue := true.B
Expand All @@ -448,7 +442,6 @@ class HybridUnit(implicit p: Parameters) extends XSModule
s0_uop := src.uop
s0_try_l2l := false.B
s0_has_rob_entry := true.B
s0_rsIdx := 0.U
s0_rep_carry := 0.U.asTypeOf(s0_rep_carry.cloneType)
s0_mshrid := 0.U
// s0_isFirstIssue := src.isFirstIssue
Expand Down Expand Up @@ -476,7 +469,6 @@ class HybridUnit(implicit p: Parameters) extends XSModule
// we dont care s0_isFirstIssue and s0_rsIdx and s0_sqIdx in S0 when trying pointchasing
// because these signals will be updated in S1
s0_has_rob_entry := false.B
s0_rsIdx := 0.U
s0_mshrid := 0.U
s0_rep_carry := 0.U.asTypeOf(s0_rep_carry.cloneType)
s0_isFirstIssue := true.B
Expand Down Expand Up @@ -516,7 +508,6 @@ class HybridUnit(implicit p: Parameters) extends XSModule
// accept load flow if dcache ready (tlb is always ready)
// TODO: prefetch need writeback to loadQueueFlag
s0_out := DontCare
s0_out.rsIdx := s0_rsIdx
s0_out.vaddr := s0_vaddr
s0_out.mask := s0_mask
s0_out.uop := s0_uop
Expand Down Expand Up @@ -695,7 +686,6 @@ class HybridUnit(implicit p: Parameters) extends XSModule
s1_out.paddr := s1_paddr_dup_lsu
s1_out.tlbMiss := s1_tlb_miss
s1_out.ptwBack := io.tlb.resp.bits.ptwBack
s1_out.rsIdx := s1_in.rsIdx
s1_out.rep_info.debug := s1_in.uop.debugInfo
s1_out.rep_info.nuke := s1_nuke && !s1_sw_prf
s1_out.lateKill := s1_late_kill
Expand Down Expand Up @@ -751,7 +741,6 @@ class HybridUnit(implicit p: Parameters) extends XSModule
s1_cancel_ptr_chasing := s1_addr_mismatch || s1_addr_misaligned || s1_ptr_chasing_canceled

s1_in.uop := io.lsin.bits.uop
s1_in.rsIdx := io.lsin.bits.iqIdx
s1_in.isFirstIssue := io.lsin.bits.isFirstIssue
s1_vaddr_lo := s1_ptr_chasing_vaddr(5, 0)
s1_paddr_dup_lsu := Cat(io.tlb.resp.bits.paddr(0)(PAddrBits - 1, 6), s1_vaddr_lo)
Expand Down
Loading

0 comments on commit 38f78b5

Please sign in to comment.