Skip to content

Commit

Permalink
fix(csr, gate): add valid signal gate in csr
Browse files Browse the repository at this point in the history
  • Loading branch information
sinceforYy committed Dec 2, 2024
1 parent e490f9a commit 3f2fc2e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/main/scala/xiangshan/backend/fu/NewCSR/NewCSR.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import xiangshan.backend.fu.NewCSR.CSRDefines._
import xiangshan.backend.fu.NewCSR.CSREnumTypeImplicitCast._
import xiangshan.backend.fu.NewCSR.CSREvents.{CSREvents, DretEventSinkBundle, EventUpdatePrivStateOutput, MNretEventSinkBundle, MretEventSinkBundle, SretEventSinkBundle, TargetPCBundle, TrapEntryDEventSinkBundle, TrapEntryEventInput, TrapEntryHSEventSinkBundle, TrapEntryMEventSinkBundle, TrapEntryMNEventSinkBundle, TrapEntryVSEventSinkBundle}
import xiangshan.backend.fu.fpu.Bundles.Frm
import xiangshan.backend.fu.util.CSRConst
import xiangshan.backend.fu.util._
import xiangshan.backend.fu.vector.Bundles.{Vl, Vstart, Vxrm, Vxsat}
import xiangshan.backend.fu.wrapper.CSRToDecode
import xiangshan.backend.rob.RobPtr
Expand Down Expand Up @@ -292,7 +292,7 @@ class NewCSR(implicit val p: Parameters) extends Module
val legalMNret = permitMod.io.out.hasLegalMNret
val legalDret = permitMod.io.out.hasLegalDret

private val wenLegalReg = GatedValidRegNext(wenLegal)
private val wenLegalReg = GatedValidSignal(wenLegal)

var csrRwMap: SeqMap[Int, (CSRAddrWriteBundle[_], UInt)] =
machineLevelCSRMap ++
Expand Down Expand Up @@ -544,8 +544,8 @@ class NewCSR(implicit val p: Parameters) extends Module
// Todo: move RegNext from ROB to CSR
m.robCommit.instNum := io.fromRob.commit.instNum
m.robCommit.fflags := RegNextWithEnable(io.fromRob.commit.fflags)
m.robCommit.fsDirty := GatedValidRegNext(io.fromRob.commit.fsDirty)
m.robCommit.vsDirty := GatedValidRegNext(io.fromRob.commit.vsDirty)
m.robCommit.fsDirty := GatedValidSignal(io.fromRob.commit.fsDirty)
m.robCommit.vsDirty := GatedValidSignal(io.fromRob.commit.vsDirty)
m.robCommit.vxsat := RegNextWithEnable(io.fromRob.commit.vxsat)
m.robCommit.vtype := RegNextWithEnable(io.fromRob.commit.vtype)
m.robCommit.vl := RegNext (io.fromRob.commit.vl)
Expand Down Expand Up @@ -1258,9 +1258,9 @@ class NewCSR(implicit val p: Parameters) extends Module
toAIA.vsClaim := vstopei.w.wen

// tlb
io.tlb.satpASIDChanged := GatedValidRegNext(satp.w.wen && satp .regOut.ASID =/= satp.w.wdataFields.ASID)
io.tlb.vsatpASIDChanged := GatedValidRegNext(vsatp.w.wen && vsatp.regOut.ASID =/= vsatp.w.wdataFields.ASID)
io.tlb.hgatpVMIDChanged := GatedValidRegNext(hgatp.w.wen && hgatp.regOut.VMID =/= hgatp.w.wdataFields.VMID)
io.tlb.satpASIDChanged := GatedValidSignal(satp.w.wen && satp .regOut.ASID =/= satp.w.wdataFields.ASID)
io.tlb.vsatpASIDChanged := GatedValidSignal(vsatp.w.wen && vsatp.regOut.ASID =/= vsatp.w.wdataFields.ASID)
io.tlb.hgatpVMIDChanged := GatedValidSignal(hgatp.w.wen && hgatp.regOut.VMID =/= hgatp.w.wdataFields.VMID)
io.tlb.satp := satp.rdata
io.tlb.vsatp := vsatp.rdata
io.tlb.hgatp := hgatp.rdata
Expand Down
13 changes: 13 additions & 0 deletions src/main/scala/xiangshan/backend/fu/util/ClockGatedReg.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package xiangshan.backend.fu.util

import chisel3._
import chisel3.util._


object GatedValidSignal {
def apply(next: Bool): Bool = {
val last = Wire(Bool())
last := RegEnable(next, next || last)
last
}
}

0 comments on commit 3f2fc2e

Please sign in to comment.