Skip to content

Commit 08eb498

Browse files
committed
fix(difftest): add mask for RefillEvent and remove idtfr
After #3051, we have supported low-power read (read only 5 out of 8 8B-banks) in ICacheDataArray, and in V3, it was further modified to dynamically compute the mask based on the taken branch location. Though, previous DiffRefillEvent does not support masked comparison, instead it checks entire 512bit, so it will fail if we enable checks on cacheid >=3 (OpenXiangShan/difftest#712). As we're refactoring ICache recently, we need this check to ensure the refactored code is working properly. This commit removes unused idtfr and introduces masked refill-check, each mask bit controls comparison of 8B data. Co-authored-by: ngc7331 <ngc7331@outlook.com> fix refill
1 parent 7a64d71 commit 08eb498

File tree

4 files changed

+23
-25
lines changed

4 files changed

+23
-25
lines changed

src/main/scala/xiangshan/cache/dcache/mainpipe/MissQueue.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,7 @@ class MissQueue(edge: TLEdgeOut, reqNum: Int)(implicit p: Parameters) extends DC
12971297
difftest.valid := io.refill_to_ldq.valid && io.refill_to_ldq.bits.hasdata && io.refill_to_ldq.bits.refill_done
12981298
difftest.addr := io.refill_to_ldq.bits.addr
12991299
difftest.data := io.refill_to_ldq.bits.data_raw.asTypeOf(difftest.data)
1300-
difftest.idtfr := DontCare
1300+
difftest.mask := VecInit.fill(difftest.mask.getWidth)(true.B).asUInt
13011301
}
13021302

13031303
// Perf count

src/main/scala/xiangshan/cache/mmu/L2TLB.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ class L2TLBImp(outer: L2TLB)(implicit p: Parameters) extends PtwModule(outer) wi
553553
difftest.valid := cache.io.refill.valid
554554
difftest.addr := difftest_ptw_addr(RegEnable(mem.d.bits.source, mem.d.valid))
555555
difftest.data := refill_data.asTypeOf(difftest.data)
556-
difftest.idtfr := DontCare
556+
difftest.mask := VecInit.fill(difftest.mask.getWidth)(true.B).asUInt
557557
}
558558

559559
if (env.EnableDifftest) {

src/main/scala/xiangshan/frontend/icache/ICacheMainPipe.scala

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -643,29 +643,27 @@ class ICacheMainPipe(implicit p: Parameters) extends ICacheModule with HasICache
643643
******************************************************************************
644644
*/
645645
if (env.EnableDifftest) {
646-
val discards = (0 until PortNumber).map { i =>
647-
ExceptionType.hasException(toIFU.bits.exception(i)) ||
648-
toIFU.bits.pmp_mmio(i) ||
649-
Pbmt.isUncache(toIFU.bits.itlb_pbmt(i))
650-
}
651-
val blkPaddrAll = s2_req_paddr.map(addr => (addr(PAddrBits - 1, blockOffBits) << blockOffBits).asUInt)
652-
(0 until ICacheDataBanks).foreach { i =>
653-
val diffMainPipeOut = DifftestModule(new DiffRefillEvent, dontCare = true)
654-
diffMainPipeOut.coreid := io.hartId
655-
diffMainPipeOut.index := (3 + i).U
656-
657-
val bankSel = getBankSel(s2_req_offset, s2_valid).reduce(_ | _)
658-
val lineSel = getLineSel(s2_req_offset)
659-
660-
diffMainPipeOut.valid := s2_fire && bankSel(i).asBool && Mux(lineSel(i), !discards(1), !discards(0))
661-
diffMainPipeOut.addr := Mux(
662-
lineSel(i),
663-
blkPaddrAll(1) + (i.U << log2Ceil(blockBytes / ICacheDataBanks)).asUInt,
664-
blkPaddrAll(0) + (i.U << log2Ceil(blockBytes / ICacheDataBanks)).asUInt
646+
val bankSel = getBankSel(s2_req_offset, s2_valid)
647+
648+
// do difftest for each fetched cache line
649+
s2_req_paddr.zipWithIndex.foreach { case (pa, i) =>
650+
val difftest = DifftestModule(new DiffRefillEvent, dontCare = true)
651+
difftest.coreid := io.hartId
652+
difftest.index := (3 + i).U // magic number 3/4: ICache MainPipe refill test
653+
654+
difftest.valid := s2_fire && !(
655+
ExceptionType.hasException(toIFU.bits.exception(i)) ||
656+
toIFU.bits.pmp_mmio(i) ||
657+
Pbmt.isUncache(toIFU.bits.itlb_pbmt(i))
665658
)
666-
667-
diffMainPipeOut.data := s2_datas(i).asTypeOf(diffMainPipeOut.data)
668-
diffMainPipeOut.idtfr := DontCare
659+
difftest.addr := Cat(pa(PAddrBits - 1, blockOffBits), 0.U(blockOffBits.W))
660+
difftest.data := s2_datas.asTypeOf(difftest.data)
661+
// NOTE: each mask bit controls (512bit / difftest.mask.getWidth) (currently 64bit) comparison
662+
// this only works for DataBanks <= difftest.mask.getWidth (and isPow2)
663+
difftest.mask := VecInit((0 until difftest.mask.getWidth).map { j =>
664+
// the j-th mask locates in (j / (difftest.mask.getWidth / DataBanks)) bank
665+
bankSel(i)(j / (difftest.mask.getWidth / ICacheDataBanks))
666+
}).asUInt
669667
}
670668
}
671669
}

src/main/scala/xiangshan/frontend/icache/ICacheMissUnit.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,6 @@ class ICacheMissUnit(edge: TLEdgeOut)(implicit p: Parameters) extends ICacheModu
476476
difftest.valid := write_sram_valid
477477
difftest.addr := Cat(mshr_resp.blkPaddr, 0.U(blockOffBits.W))
478478
difftest.data := respDataReg.asTypeOf(difftest.data)
479-
difftest.idtfr := DontCare
479+
difftest.mask := VecInit.fill(difftest.mask.getWidth)(true.B).asUInt
480480
}
481481
}

0 commit comments

Comments
 (0)