Skip to content

Commit

Permalink
tage: use extra reset for sram
Browse files Browse the repository at this point in the history
  • Loading branch information
poemonsense authored and Lingrui98 committed Nov 9, 2022
1 parent 48a6271 commit 6661216
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
25 changes: 20 additions & 5 deletions src/main/scala/utils/SRAMTemplate.scala
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,16 @@ class SRAMWriteBus[T <: Data](private val gen: T, val set: Int, val way: Int = 1
}
}

class SRAMTemplate[T <: Data](gen: T, set: Int, way: Int = 1,
shouldReset: Boolean = false, holdRead: Boolean = false, singlePort: Boolean = false, bypassWrite: Boolean = false) extends Module {
class SRAMTemplate[T <: Data](
gen: T, set: Int, way: Int = 1, singlePort: Boolean = false,
shouldReset: Boolean = false, extraReset: Boolean = false,
holdRead: Boolean = false, bypassWrite: Boolean = false
) extends Module {
val io = IO(new Bundle {
val r = Flipped(new SRAMReadBus(gen, set, way))
val w = Flipped(new SRAMWriteBus(gen, set, way))
})
val extra_reset = if (extraReset) Some(IO(Input(Bool()))) else None

val wordType = UInt(gen.getWidth.W)
val array = SyncReadMem(set, Vec(way, wordType))
Expand All @@ -105,6 +109,11 @@ class SRAMTemplate[T <: Data](gen: T, set: Int, way: Int = 1,
val _resetState = RegInit(true.B)
val (_resetSet, resetFinish) = Counter(_resetState, set)
when (resetFinish) { _resetState := false.B }
if (extra_reset.isDefined) {
when (extra_reset.get) {
_resetState := true.B
}
}

resetState := _resetState
resetSet := _resetSet
Expand Down Expand Up @@ -151,11 +160,13 @@ class SRAMTemplate[T <: Data](gen: T, set: Int, way: Int = 1,
}

class FoldedSRAMTemplate[T <: Data](gen: T, set: Int, width: Int = 4, way: Int = 1,
shouldReset: Boolean = false, holdRead: Boolean = false, singlePort: Boolean = false, bypassWrite: Boolean = false) extends Module {
shouldReset: Boolean = false, extraReset: Boolean = false,
holdRead: Boolean = false, singlePort: Boolean = false, bypassWrite: Boolean = false) extends Module {
val io = IO(new Bundle {
val r = Flipped(new SRAMReadBus(gen, set, way))
val w = Flipped(new SRAMWriteBus(gen, set, way))
})
val extra_reset = if (extraReset) Some(IO(Input(Bool()))) else None
// |<----- setIdx ----->|
// | ridx | width | way |

Expand All @@ -165,7 +176,11 @@ class FoldedSRAMTemplate[T <: Data](gen: T, set: Int, width: Int = 4, way: Int =

val nRows = set / width

val array = Module(new SRAMTemplate(gen, set=nRows, way=width*way, shouldReset=shouldReset, holdRead=holdRead, singlePort=singlePort))
val array = Module(new SRAMTemplate(gen, set=nRows, way=width*way,
shouldReset=shouldReset, extraReset=extraReset, holdRead=holdRead, singlePort=singlePort))
if (array.extra_reset.isDefined) {
array.extra_reset.get := extra_reset.get
}

io.r.req.ready := array.io.r.req.ready
io.w.req.ready := array.io.w.req.ready
Expand Down Expand Up @@ -205,7 +220,7 @@ class SRAMTemplateWithArbiter[T <: Data](nRead: Int, gen: T, set: Int, way: Int
val w = Flipped(new SRAMWriteBus(gen, set, way))
})

val ram = Module(new SRAMTemplate(gen, set, way, shouldReset, holdRead = false, singlePort = true))
val ram = Module(new SRAMTemplate(gen, set, way, shouldReset = shouldReset, holdRead = false, singlePort = true))
ram.io.w <> io.w

val readArb = Module(new Arbiter(chiselTypeOf(io.r(0).req.bits), nRead))
Expand Down
5 changes: 2 additions & 3 deletions src/main/scala/xiangshan/frontend/Tage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,8 @@ class TageTable
// val s1_pc = io.req.bits.pc
val req_unhashed_idx = getUnhashedIdx(io.req.bits.pc)

val us = withReset(reset.asBool || io.update.reset_u.reduce(_||_)) {
Module(new FoldedSRAMTemplate(Bool(), set=nRowsPerBr, width=uFoldedWidth, way=numBr, shouldReset=true, holdRead=true, singlePort=true))
}
val us = Module(new FoldedSRAMTemplate(Bool(), set=nRowsPerBr, width=uFoldedWidth, way=numBr, shouldReset=true, extraReset=true, holdRead=true, singlePort=true))
us.extra_reset.get := io.update.reset_u.reduce(_||_)


val table_banks = Seq.fill(nBanks)(
Expand Down

0 comments on commit 6661216

Please sign in to comment.