Skip to content

Commit

Permalink
fix(CSR, Trace): remove reg isXRetFlag in CSR
Browse files Browse the repository at this point in the history
 * remove useless reg `isXRetFlag` in CSR.scala
 * fix update of itype for xret instruction
  • Loading branch information
wissygh committed Dec 10, 2024
1 parent 1ca30e1 commit bf0e7a6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
9 changes: 1 addition & 8 deletions src/main/scala/xiangshan/backend/fu/wrapper/CSR.scala
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,6 @@ class CSR(cfg: FuConfig)(implicit p: Parameters) extends FuncUnit(cfg)

val isXRet = valid && func === CSROpType.jmp && !isEcall && !isEbreak

// ctrl block will use theses later for flush // Todo: optimize isXRetFlag's DelayN
val isXRetFlag = RegInit(false.B)
isXRetFlag := Mux1H(Seq(
DelayN(flush, 5) -> false.B,
isXRet -> true.B,
))

flushPipe := csrMod.io.out.bits.flushPipe

// tlb
Expand Down Expand Up @@ -306,7 +299,7 @@ class CSR(cfg: FuConfig)(implicit p: Parameters) extends FuncUnit(cfg)
csrOut.vpu.vstart := csrMod.io.status.vecState.vstart.asUInt
csrOut.vpu.vxrm := csrMod.io.status.vecState.vxrm.asUInt

csrOut.isXRet := RegEnable(isXRetFlag, false.B, io.in.fire)
csrOut.isXRet := isXRet

csrOut.trapTarget := csrMod.io.out.bits.targetPc
csrOut.interrupt := csrMod.io.status.interrupt
Expand Down
25 changes: 14 additions & 11 deletions src/main/scala/xiangshan/backend/rob/Rob.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1038,11 +1038,7 @@ class RobImp(override val wrapper: Rob)(implicit p: Parameters, params: BackendP

// trace
val taken = branchWBs.map(writeback => writeback.valid && writeback.bits.robIdx.value === i.U && writeback.bits.redirect.get.bits.cfiUpdate.taken).reduce(_ || _)
val xret = csrWBs.map(writeback => writeback.valid && writeback.bits.robIdx.value === i.U && io.csr.isXRet).reduce(_ || _)

when(robEntries(i).valid && xret){
robEntries(i).traceBlockInPipe.itype := Itype.ExpIntReturn
}.elsewhen(robEntries(i).valid && Itype.isBranchType(robEntries(i).traceBlockInPipe.itype) && taken){
when(robEntries(i).valid && Itype.isBranchType(robEntries(i).traceBlockInPipe.itype) && taken){
// BranchType code(notaken itype = 4) must be correctly replaced!
robEntries(i).traceBlockInPipe.itype := Itype.Taken
}
Expand Down Expand Up @@ -1106,10 +1102,7 @@ class RobImp(override val wrapper: Rob)(implicit p: Parameters, params: BackendP

// trace
val taken = branchWBs.map(writeback => writeback.valid && writeback.bits.robIdx.value === needUpdateRobIdx(i) && writeback.bits.redirect.get.bits.cfiUpdate.taken).reduce(_ || _)
val xret = csrWBs.map(writeback => writeback.valid && writeback.bits.robIdx.value === needUpdateRobIdx(i) && io.csr.isXRet).reduce(_ || _)
when(robBanksRdata(i).valid && xret){
needUpdate(i).traceBlockInPipe.itype := Itype.ExpIntReturn
}.elsewhen(robBanksRdata(i).valid && Itype.isBranchType(robBanksRdata(i).traceBlockInPipe.itype) && taken){
when(robBanksRdata(i).valid && Itype.isBranchType(robBanksRdata(i).traceBlockInPipe.itype) && taken){
// BranchType code(notaken itype = 4) must be correctly replaced!
needUpdate(i).traceBlockInPipe.itype := Itype.Taken
}
Expand Down Expand Up @@ -1239,16 +1232,26 @@ class RobImp(override val wrapper: Rob)(implicit p: Parameters, params: BackendP
val traceBlocks = io.trace.traceCommitInfo.blocks
val traceBlockInPipe = io.trace.traceCommitInfo.blocks.map(_.bits.tracePipe)

// The reg 'isTraceXret' only for trace xret instructions. xret only occor in block(0).
val isTraceXret = RegInit(false.B)
when(io.csr.isXRet){
isTraceXret := true.B
}.elsewhen(isTraceXret && io.commits.isCommit && io.commits.commitValid(0)){
isTraceXret := false.B
}

for (i <- 0 until CommitWidth) {
traceBlocks(i).bits.ftqIdx.foreach(_ := rawInfo(i).ftqIdx)
traceBlocks(i).bits.ftqOffset.foreach(_ := rawInfo(i).ftqOffset)
traceBlockInPipe(i).itype := rawInfo(i).traceBlockInPipe.itype
traceBlockInPipe(i).iretire := rawInfo(i).traceBlockInPipe.iretire
traceBlockInPipe(i).ilastsize := rawInfo(i).traceBlockInPipe.ilastsize
traceValids(i) := io.commits.isCommit && io.commits.commitValid(i)
// exception only occor block(0).
// exception/xret only occor in block(0).
if(i == 0) {
when(io.exception.valid){
when(isTraceXret && io.commits.isCommit && io.commits.commitValid(0)){ // trace xret
traceBlocks(i).bits.tracePipe.itype := Itype.ExpIntReturn
}.elsewhen(io.exception.valid){ // trace exception
traceBlocks(i).bits.tracePipe.itype := Mux(io.exception.bits.isInterrupt,
Itype.Interrupt,
Itype.Exception
Expand Down

0 comments on commit bf0e7a6

Please sign in to comment.