Skip to content

Commit 52f391f

Browse files
committed
feat(difftest): replace ArchReg and Writeback with PhyRegState
This change refactors Difftest interfaces, replacing the previous ArchReg and WriteBack with PhyRegState and ArchRenameTable. By default, Difftest still extracts PhyReg and RenameTable into ArchReg on the hardware side, so that the extra multi-read area is accounted for within Difftest. When acceleration is enabled, this extraction is deferred to the software side, eliminating the extra hardware area overhead. Since 128-bit ArchVecReg are now treated as two 64-bit registers in Difftest, we add corresponding register splitting in XiangShan. The address indexs (InstrCommit.otherwpdest and RenameTable) are also converted from `index` to `2*index` and `2*index + 1` for reg splitting. Note XiangShan separates V0 and Vf register files. When mering the two regfiles and renameTable for Difftest, the indexs of Vf must add offset of V0RegSize to ensure correct indexing.
1 parent e888253 commit 52f391f

File tree

8 files changed

+133
-166
lines changed

8 files changed

+133
-166
lines changed

src/main/scala/xiangshan/backend/Backend.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,6 @@ class BackendInlinedImp(override val wrapper: BackendInlined)(implicit p: Parame
369369
// for fpIQ write int regfile arbiter
370370
intRegion.io.fromFpIQ.get <> fpRegion.io.fpIQOut.get
371371

372-
intRegion.io.diffIntRat.foreach(_ := ctrlBlock.io.diff_int_rat.get)
373-
fpRegion.io.diffFpRat.foreach(_ := ctrlBlock.io.diff_fp_rat.get)
374-
vecRegion.io.diffVecRat.foreach(_ := ctrlBlock.io.diff_vec_rat.get)
375-
vecRegion.io.diffV0Rat.foreach(_ := ctrlBlock.io.diff_v0_rat.get)
376372
vecRegion.io.diffVlRat.foreach(_ := ctrlBlock.io.diff_vl_rat.get)
377373
vecRegion.io.fromVecExcpMod.get.r := vecExcpMod.o.toVPRF.r
378374
vecRegion.io.fromVecExcpMod.get.w := vecExcpMod.o.toVPRF.w

src/main/scala/xiangshan/backend/CtrlBlock.scala

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ class CtrlBlockImp(
649649
memCtrl.io.mdpFlodPcVec := mdpFlodPcVec
650650
memCtrl.io.dispatchLFSTio <> dispatch.io.lfst
651651

652+
rat.io.hartId := io.fromTop.hartId
652653
rat.io.redirect := s1_s3_redirect.valid
653654
rat.io.rabCommits := rob.io.rabCommits
654655
rat.io.diffCommits.foreach(_ := rob.io.diffCommits.get)
@@ -809,10 +810,6 @@ class CtrlBlockImp(
809810
// rob to mem block
810811
io.robio.lsq <> rob.io.lsq
811812

812-
io.diff_int_rat.foreach(_ := rat.io.diff_int_rat.get)
813-
io.diff_fp_rat .foreach(_ := rat.io.diff_fp_rat.get)
814-
io.diff_vec_rat.foreach(_ := rat.io.diff_vec_rat.get)
815-
io.diff_v0_rat .foreach(_ := rat.io.diff_v0_rat.get)
816813
io.diff_vl_rat .foreach(_ := rat.io.diff_vl_rat.get)
817814

818815
rob.io.debug_ls := io.robio.debug_ls
@@ -1006,10 +1003,6 @@ class CtrlBlockIO()(implicit p: Parameters, params: BackendParams) extends XSBun
10061003
val lsdqFull = Bool()
10071004
}
10081005
})
1009-
val diff_int_rat = if (params.basicDebugEn) Some(Vec(32, Output(UInt(PhyRegIdxWidth.W)))) else None
1010-
val diff_fp_rat = if (params.basicDebugEn) Some(Vec(32, Output(UInt(PhyRegIdxWidth.W)))) else None
1011-
val diff_vec_rat = if (params.basicDebugEn) Some(Vec(31, Output(UInt(PhyRegIdxWidth.W)))) else None
1012-
val diff_v0_rat = if (params.basicDebugEn) Some(Vec(1, Output(UInt(PhyRegIdxWidth.W)))) else None
10131006
val diff_vl_rat = if (params.basicDebugEn) Some(Vec(1, Output(UInt(PhyRegIdxWidth.W)))) else None
10141007

10151008
val sqCanAccept = Input(Bool())

src/main/scala/xiangshan/backend/Region.scala

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,6 @@ class Region(val params: SchdBlockParams)(implicit p: Parameters) extends XSModu
533533
dataPath.io.fromIntWb := wbDataPath.io.toIntPreg
534534
dataPath.io.fromPcTargetMem <> io.fromPcTargetMem.get
535535
dataPath.io.fromBypassNetwork := bypassNetwork.io.toDataPath
536-
dataPath.io.diffIntRat.foreach(_ := io.diffIntRat.get)
537536

538537
bypassNetwork.io.fromDataPath.int <> dataPath.io.toIntExu
539538
bypassNetwork.io.fromDataPath.immInfo := dataPath.io.og1ImmInfo
@@ -656,7 +655,6 @@ class Region(val params: SchdBlockParams)(implicit p: Parameters) extends XSModu
656655
io.fpToIntIQResp.get := dataPath.io.toIntIQ
657656
dataPath.io.fromFpWb := wbDataPath.io.toFpPreg
658657
dataPath.io.fromBypassNetwork <> bypassNetwork.io.toDataPath
659-
dataPath.io.diffFpRat.foreach(_ := io.diffFpRat.get)
660658
io.toFpPreg := wbDataPath.io.toFpPreg
661659
bypassNetwork.io.fromDataPath.fp <> dataPath.io.toFpExu
662660

@@ -774,8 +772,6 @@ class Region(val params: SchdBlockParams)(implicit p: Parameters) extends XSModu
774772
dataPath.io.fromV0Wb := wbDataPath.io.toV0Preg
775773
dataPath.io.fromVlWb := wbDataPath.io.toVlPreg
776774
dataPath.io.fromBypassNetwork <> bypassNetwork.io.toDataPath
777-
dataPath.io.diffVecRat.foreach(_ := io.diffVecRat.get)
778-
dataPath.io.diffV0Rat.foreach(_ := io.diffV0Rat.get)
779775
dataPath.io.diffVlRat.foreach(_ := io.diffVlRat.get)
780776

781777
dataPath.io.fromVecExcpMod.foreach(_ := io.fromVecExcpMod.get)
@@ -995,10 +991,6 @@ class RegionIO(val params: SchdBlockParams)(implicit p: Parameters) extends XSBu
995991
val flush = Flipped(ValidIO(new Redirect))
996992
val ldCancel = Vec(backendParams.LduCnt, Flipped(new LoadCancelIO))
997993
val fromPcTargetMem = Option.when(params.isIntSchd)(Flipped(new PcToDataPathIO(backendParams)))
998-
val diffIntRat = Option.when(params.isIntSchd)(Input(Vec(32, UInt(params.pregIdxWidth.W))))
999-
val diffFpRat = Option.when(params.isFpSchd)(Input(Vec(32, UInt(params.pregIdxWidth.W))))
1000-
val diffVecRat = Option.when(params.isVecSchd)(Input(Vec(31, UInt(params.pregIdxWidth.W))))
1001-
val diffV0Rat = Option.when(params.isVecSchd)(Input(Vec(1, UInt(log2Up(V0PhyRegs).W))))
1002994
val diffVlRat = Option.when(params.isVecSchd)(Input(Vec(1, UInt(log2Up(VlPhyRegs).W))))
1003995
val diffVl = Option.when(params.isVecSchd)(Output(UInt(VlData().dataWidth.W)))
1004996
val vlWriteBackInfoIn = new Bundle {

src/main/scala/xiangshan/backend/datapath/DataPath.scala

Lines changed: 41 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package xiangshan.backend.datapath
33
import org.chipsalliance.cde.config.Parameters
44
import chisel3._
55
import chisel3.util._
6-
import difftest.{DiffArchFpRegState, DiffArchIntRegState, DiffArchVecRegState, DifftestModule}
6+
import difftest._
77
import freechips.rocketchip.diplomacy.{LazyModule, LazyModuleImp}
88
import utility._
99
import utils.SeqUtils._
@@ -265,38 +265,29 @@ class DataPath(implicit p: Parameters, params: BackendParams, param: SchdBlockPa
265265
io.fromPcTargetMem.fromDataPathFtqPtr := pcReadFtqPtr
266266
io.fromPcTargetMem.fromDataPathFtqOffset := pcReadFtqOffset
267267

268-
private val intDiffRead: Option[(Vec[UInt], Vec[UInt])] =
269-
OptionWrapper(backendParams.basicDebugEn && param.isIntSchd, (Wire(Vec(32, UInt(intSchdParams.pregIdxWidth.W))), Wire(Vec(32, UInt(XLEN.W)))))
270-
private val fpDiffRead: Option[(Vec[UInt], Vec[UInt])] =
271-
OptionWrapper(backendParams.basicDebugEn && param.isFpSchd, (Wire(Vec(32, UInt(fpSchdParams.pregIdxWidth.W))), Wire(Vec(32, UInt(XLEN.W)))))
272-
private val vfDiffRead: Option[(Vec[UInt], Vec[UInt])] =
273-
OptionWrapper(backendParams.basicDebugEn && param.isVecSchd, (Wire(Vec(31, UInt(vecSchdParams.pregIdxWidth.W))), Wire(Vec(31, UInt(VLEN.W)))))
274-
private val v0DiffRead: Option[(Vec[UInt], Vec[UInt])] =
275-
OptionWrapper(backendParams.basicDebugEn && param.isVecSchd, (Wire(Vec(1, UInt(log2Up(V0PhyRegs).W))), Wire(Vec(1, UInt(V0Data().dataWidth.W)))))
268+
private val intDiffReadData: Option[Vec[UInt]] =
269+
OptionWrapper(backendParams.basicDebugEn && param.isIntSchd, Wire(Vec(intSchdParams.numPregs, UInt(XLEN.W))))
270+
private val fpDiffReadData: Option[Vec[UInt]] =
271+
OptionWrapper(backendParams.basicDebugEn && param.isFpSchd, Wire(Vec(fpSchdParams.numPregs, UInt(XLEN.W))))
272+
private val vfDiffReadData: Option[Vec[UInt]] =
273+
OptionWrapper(backendParams.basicDebugEn && param.isVecSchd, Wire(Vec(vecSchdParams.numPregs, UInt(VLEN.W))))
274+
private val v0DiffReadData: Option[Vec[UInt]] =
275+
OptionWrapper(backendParams.basicDebugEn && param.isVecSchd, Wire(Vec(V0PhyRegs, UInt(V0Data().dataWidth.W))))
276276
private val vlDiffRead: Option[(Vec[UInt], Vec[UInt])] =
277277
OptionWrapper(backendParams.basicDebugEn && param.isVecSchd, (Wire(Vec(1, UInt(log2Up(VlPhyRegs).W))), Wire(Vec(1, UInt(VlData().dataWidth.W)))))
278278

279-
private val fpDiffReadData: Option[Vec[UInt]] =
280-
OptionWrapper(backendParams.basicDebugEn && param.isFpSchd, Wire(Vec(32, UInt(XLEN.W))))
279+
private val vecDiffNumPregs = 2 * (V0PhyRegs + vecSchdParams.numPregs)
281280
private val vecDiffReadData: Option[Vec[UInt]] =
282-
OptionWrapper(backendParams.basicDebugEn && param.isVecSchd, Wire(Vec(64, UInt(64.W)))) // v0 = Cat(Vec(1), Vec(0))
281+
OptionWrapper(backendParams.basicDebugEn && param.isVecSchd, Wire(Vec(vecDiffNumPregs, UInt(64.W)))) // v0 = Cat(Vec(1), Vec(0))
283282
private val vlDiffReadData: Option[UInt] =
284283
OptionWrapper(backendParams.basicDebugEn && param.isVecSchd, Wire(UInt(VlData().dataWidth.W)))
285284

286-
287-
fpDiffReadData.foreach(_ := fpDiffRead
288-
.get._2
289-
.slice(0, 32)
290-
.map(_(63, 0))
291-
) // fp only used [63, 0]
292-
vecDiffReadData.foreach(_ :=
293-
v0DiffRead
294-
.get._2
295-
.slice(0, 1)
296-
.map(x => Seq(x(63, 0), x(127, 64))).flatten ++
297-
vfDiffRead
298-
.get._2
299-
.slice(0, 31)
285+
vecDiffReadData.foreach(_ :=
286+
v0DiffReadData
287+
.get
288+
.map(x => Seq(x(63, 0), x(127, 64))).flatten ++
289+
vfDiffReadData
290+
.get
300291
.map(x => Seq(x(63, 0), x(127, 64))).flatten
301292
)
302293
vlDiffReadData.foreach(_ := vlDiffRead
@@ -307,32 +298,44 @@ class DataPath(implicit p: Parameters, params: BackendParams, param: SchdBlockPa
307298
if (param.isIntSchd) {
308299
IntRegFileSplit("IntRegFile", intSchdParams.numPregs, splitNum, intRfRaddr, intRfRdata.get, intRfWen, intRfWaddr, intRfWdata,
309300
bankNum = 1,
310-
debugReadAddr = intDiffRead.map(_._1),
311-
debugReadData = intDiffRead.map(_._2)
301+
debugAllRData = intDiffReadData
312302
)
303+
if (env.AlwaysBasicDiff || env.EnableDifftest) {
304+
// Delay of PhyRegFile should be same as RenameTable
305+
val difftest = DifftestModule(new DiffPhyIntRegState(intSchdParams.numPregs), delay = 2)
306+
difftest.coreid := io.hartId
307+
difftest.value := intDiffReadData.get
308+
}
313309
}
314310
else if (param.isFpSchd) {
315311
FpRegFileSplit("FpRegFile", fpSchdParams.numPregs, splitNum, fpRfRaddr, fpRfRdata.get, fpRfWen, fpRfWaddr, fpRfWdata,
316312
bankNum = 1,
317-
debugReadAddr = fpDiffRead.map(_._1),
318-
debugReadData = fpDiffRead.map(_._2)
313+
debugAllRData = fpDiffReadData
319314
)
315+
if (env.AlwaysBasicDiff || env.EnableDifftest) {
316+
val difftest = DifftestModule(new DiffPhyFpRegState(fpSchdParams.numPregs), delay = 2)
317+
difftest.coreid := io.hartId
318+
difftest.value := fpDiffReadData.get
319+
}
320320
}
321321
else {
322322
VfRegFile("VfRegFile", vecSchdParams.numPregs, splitNum, vfRfRaddr, vfRfRdata.get, vfRfWen, vfRfWaddr, vfRfWdata,
323-
debugReadAddr = vfDiffRead.map(_._1),
324-
debugReadData = vfDiffRead.map(_._2)
323+
debugAllRData = vfDiffReadData
325324
)
326325
VfRegFile("V0RegFile", V0PhyRegs, v0RfSplitNum, v0RfRaddr, v0RfRdata.get, v0RfWen, v0RfWaddr, v0RfWdata,
327-
debugReadAddr = v0DiffRead.map(_._1),
328-
debugReadData = v0DiffRead.map(_._2)
326+
debugAllRData = v0DiffReadData
329327
)
330328
FpRegFile("VlRegFile", VlPhyRegs, vlRfRaddr, vlRfRdata.get, vlRfWen, vlRfWaddr, vlRfWdata,
331329
bankNum = 1,
332330
isVlRegfile = true,
333331
debugReadAddr = vlDiffRead.map(_._1),
334332
debugReadData = vlDiffRead.map(_._2)
335333
)
334+
if (env.AlwaysBasicDiff || env.EnableDifftest) {
335+
val difftest = DifftestModule(new DiffPhyVecRegState(vecDiffNumPregs), delay = 2)
336+
difftest.coreid := io.hartId
337+
difftest.value := vecDiffReadData.get
338+
}
336339
}
337340

338341
intRfWaddr := io.fromIntWb.map(x => RegEnable(x.addr, x.wen)).toSeq
@@ -398,30 +401,15 @@ class DataPath(implicit p: Parameters, params: BackendParams, param: SchdBlockPa
398401
vlRfRaddr(portIdx) := 0.U
399402
}
400403

401-
402-
intDiffRead.foreach { case (addr, _) =>
403-
addr := io.diffIntRat.get
404-
}
405-
406-
fpDiffRead.foreach { case (addr, _) =>
407-
addr := io.diffFpRat.get
408-
}
409-
410-
vfDiffRead.foreach { case (addr, _) =>
411-
addr := io.diffVecRat.get
412-
}
413-
v0DiffRead.foreach { case (addr, _) =>
414-
addr := io.diffV0Rat.get
415-
}
416404
vlDiffRead.foreach { case (addr, _) =>
417405
addr := io.diffVlRat.get
418406
}
419407

420408
println(s"[DataPath] " +
421-
s"has intDiffRead: ${intDiffRead.nonEmpty}, " +
422-
s"has fpDiffRead: ${fpDiffRead.nonEmpty}, " +
423-
s"has vecDiffRead: ${vfDiffRead.nonEmpty}, " +
424-
s"has v0DiffRead: ${v0DiffRead.nonEmpty}, " +
409+
s"has intDiffRead: ${intDiffReadData.nonEmpty}, " +
410+
s"has fpDiffRead: ${fpDiffReadData.nonEmpty}, " +
411+
s"has vecDiffRead: ${vfDiffReadData.nonEmpty}, " +
412+
s"has v0DiffRead: ${v0DiffReadData.nonEmpty}, " +
425413
s"has vlDiffRead: ${vlDiffRead.nonEmpty}")
426414

427415
// regcache
@@ -713,25 +701,6 @@ class DataPath(implicit p: Parameters, params: BackendParams, param: SchdBlockPa
713701
}
714702
}
715703

716-
if (env.AlwaysBasicDiff || env.EnableDifftest) {
717-
val delayedCnt = 2
718-
if (param.isIntSchd) {
719-
val difftestArchIntRegState = DifftestModule(new DiffArchIntRegState, delay = delayedCnt)
720-
difftestArchIntRegState.coreid := io.hartId
721-
difftestArchIntRegState.value := intDiffRead.get._2
722-
}
723-
if (param.isFpSchd) {
724-
val difftestArchFpRegState = DifftestModule(new DiffArchFpRegState, delay = delayedCnt)
725-
difftestArchFpRegState.coreid := io.hartId
726-
difftestArchFpRegState.value := fpDiffReadData.get
727-
}
728-
if (param.isVecSchd) {
729-
val difftestArchVecRegState = DifftestModule(new DiffArchVecRegState, delay = delayedCnt)
730-
difftestArchVecRegState.coreid := io.hartId
731-
difftestArchVecRegState.value := vecDiffReadData.get
732-
}
733-
}
734-
735704
val int_regcache_size = 48
736705
val int_regcache_tag = RegInit(VecInit(Seq.fill(int_regcache_size)(0.U(intSchdParams.pregIdxWidth.W))))
737706
val int_regcache_enqPtr = RegInit(0.U(log2Up(int_regcache_size).W))
@@ -980,10 +949,6 @@ class DataPathIO()(implicit p: Parameters, params: BackendParams, param: SchdBlo
980949
Output(UInt(RegCacheIdxWidth.W))
981950
)
982951

983-
val diffIntRat = if (params.basicDebugEn && param.isIntSchd) Some(Input(Vec(32, UInt(intSchdParams.pregIdxWidth.W)))) else None
984-
val diffFpRat = if (params.basicDebugEn && param.isFpSchd) Some(Input(Vec(32, UInt(fpSchdParams.pregIdxWidth.W)))) else None
985-
val diffVecRat = if (params.basicDebugEn && param.isVecSchd) Some(Input(Vec(31, UInt(vecSchdParams.pregIdxWidth.W)))) else None
986-
val diffV0Rat = if (params.basicDebugEn && param.isVecSchd) Some(Input(Vec(1, UInt(log2Up(V0PhyRegs).W)))) else None
987952
val diffVlRat = if (params.basicDebugEn && param.isVecSchd) Some(Input(Vec(1, UInt(log2Up(VlPhyRegs).W)))) else None
988953
val diffVl = if (params.basicDebugEn && param.isVecSchd) Some(Output(UInt(VlData().dataWidth.W))) else None
989954

src/main/scala/xiangshan/backend/datapath/WbArbiter.scala

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package xiangshan.backend.datapath
33
import org.chipsalliance.cde.config.Parameters
44
import chisel3._
55
import chisel3.util._
6-
import difftest.{DiffFpWriteback, DiffIntWriteback, DiffVecV0Writeback, DiffVecWriteback, DifftestModule}
76
import utility.XSError
87
import xiangshan.backend.BackendParams
98
import xiangshan.backend.Bundles.{ExuOutput, WriteBackBundle}
@@ -396,49 +395,6 @@ class WbDataPath(params: BackendParams, schdParams: SchdBlockParams)(implicit p:
396395
sink.bits := source.bits
397396
source.ready := true.B
398397
}
399-
400-
// difftest
401-
if (env.EnableDifftest || env.AlwaysBasicDiff) {
402-
intWbArbiterOut.foreach(out => {
403-
val difftest = DifftestModule(new DiffIntWriteback(IntPhyRegs))
404-
difftest.coreid := io.fromTop.hartId
405-
difftest.valid := out.fire && out.bits.rfWen
406-
difftest.address := out.bits.pdest
407-
difftest.data := out.bits.data
408-
})
409-
}
410-
411-
if (env.EnableDifftest || env.AlwaysBasicDiff) {
412-
fpWbArbiterOut.foreach(out => {
413-
val difftest = DifftestModule(new DiffFpWriteback(FpPhyRegs))
414-
difftest.coreid := io.fromTop.hartId
415-
difftest.valid := out.fire // all fp instr will write fp rf
416-
difftest.address := out.bits.pdest
417-
difftest.data := out.bits.data
418-
})
419-
}
420-
421-
if (env.EnableDifftest || env.AlwaysBasicDiff) {
422-
vfWbArbiterOut.foreach(out => {
423-
val difftest = DifftestModule(new DiffVecWriteback(VfPhyRegs))
424-
difftest.coreid := io.fromTop.hartId
425-
difftest.valid := out.fire
426-
difftest.address := out.bits.pdest
427-
difftest.data(0) := out.bits.data(63, 0)
428-
difftest.data(1) := out.bits.data(127, 64)
429-
})
430-
}
431-
432-
if (env.EnableDifftest || env.AlwaysBasicDiff) {
433-
v0WbArbiterOut.foreach(out => {
434-
val difftest = DifftestModule(new DiffVecV0Writeback(V0PhyRegs))
435-
difftest.coreid := io.fromTop.hartId
436-
difftest.valid := out.fire
437-
difftest.address := out.bits.pdest
438-
difftest.data(0) := out.bits.data(63, 0)
439-
difftest.data(1) := out.bits.data(127, 64)
440-
})
441-
}
442398
}
443399

444400

0 commit comments

Comments
 (0)