Skip to content

Commit

Permalink
ICache: add valid to getBankSel() to prevent fake assertion-fails
Browse files Browse the repository at this point in the history
  • Loading branch information
ngc7331 committed Jun 19, 2024
1 parent 63f7f8b commit 6e529e5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
10 changes: 3 additions & 7 deletions src/main/scala/xiangshan/frontend/icache/ICache.scala
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,11 @@ trait HasICacheParameters extends HasL1CacheParameters with HasInstrMMIOConst wi
codes.asTypeOf(UInt(ICacheCodeBits.W))
}

def getBankSel(blkOffset: UInt):Vec[UInt] = {
def getBankSel(blkOffset: UInt, valid: Bool = true.B): Vec[UInt] = {
val bankIdxLow = Cat(0.U(1.W), blkOffset) >> log2Ceil(blockBytes/ICacheDataBanks)
val bankIdxHigh = (Cat(0.U(1.W), blkOffset) + 32.U) >> log2Ceil(blockBytes/ICacheDataBanks)
val bankSel = VecInit((0 until ICacheDataBanks * 2).map(i => (i.U >= bankIdxLow) && (i.U <= bankIdxHigh)))
/* FIXME: when blkOffset is invalid, it can be anything and causing fake assertion-fails
* maybe it's better to do this assert outside getBankSel(), or pass a valid signal here
* the current solution is ensuring blkOffset is valid by defaulting it to 0.U
*/
assert(PopCount(bankSel) === ICacheBankVisitNum.U, "The number of bank visits must be %d, but bankSel=0x%x", ICacheBankVisitNum.U, bankSel.asUInt)
assert(!valid || PopCount(bankSel) === ICacheBankVisitNum.U, "The number of bank visits must be %d, but bankSel=0x%x", ICacheBankVisitNum.U, bankSel.asUInt)
bankSel.asTypeOf(UInt((ICacheDataBanks * 2).W)).asTypeOf(Vec(2, UInt(ICacheDataBanks.W)))
}

Expand Down Expand Up @@ -337,7 +333,7 @@ class ICacheDataArray(implicit p: Parameters) extends ICacheArray
val writeDatas = io.write.bits.data.asTypeOf(Vec(ICacheDataBanks, UInt(ICacheDataBits.W)))
val writeEntries = writeDatas.map(ICacheDataEntry(_).asUInt)

val bankSel = getBankSel(io.read(0).bits.blkOffset)
val bankSel = getBankSel(io.read(0).bits.blkOffset, io.read(0).valid)
val lineSel = getLineSel(io.read(0).bits.blkOffset)
val waymasks = io.read(0).bits.wayMask
val masks = Wire(Vec(nWays, Vec(ICacheDataBanks, Bool())))
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/xiangshan/frontend/icache/ICacheMainPipe.scala
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ class ICacheMainPipe(implicit p: Parameters) extends ICacheModule
* report data parity error
******************************************************************************
*/
val s2_bankSel = getBankSel(s2_req_offset)
val s2_bankSel = getBankSel(s2_req_offset, s2_valid)
val s2_bank_errors = (0 until ICacheDataBanks).map(i => (encode(s2_datas(i)) =/= s2_codes(i)))
val s2_parity_errors = (0 until PortNumber).map(port => (0 until ICacheDataBanks).map(bank =>
s2_bank_errors(bank) && s2_bankSel(port)(bank).asBool).reduce(_||_) && s2_SRAMhits(port))
Expand Down Expand Up @@ -522,7 +522,7 @@ class ICacheMainPipe(implicit p: Parameters) extends ICacheModule
diffMainPipeOut.coreid := io.hartId
diffMainPipeOut.index := (3 + i).U

val bankSel = getBankSel(s2_req_offset).reduce(_|_)
val bankSel = getBankSel(s2_req_offset, s2_valid).reduce(_|_)
val lineSel = getLineSel(s2_req_offset)

diffMainPipeOut.valid := s2_fire && bankSel(i).asBool && Mux(lineSel(i), !discards(1), !discards(0))
Expand Down

0 comments on commit 6e529e5

Please sign in to comment.