Skip to content

Commit 8db5748

Browse files
ChrisqcwxTakehana
andauthored
refactor: remove inst, pc, vaddr in inst info (#283)
* refactor: remove pc, inst, idxInBlock signal in inst info port * refactor: remove vaddr from inst info * fix: excp vaddr assign error in addrTrans * fix: no initialize error in addr trans * feat: optimize register usage in DCache * fix connection error --------- Co-authored-by: Takehana <cowpowermax@pm.me>
1 parent f371eb7 commit 8db5748

20 files changed

+135
-168
lines changed

src/src/CoreCpuTop.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import spec.Param.isDiffTest
1616
import control.Cu
1717
import pmu.Pmu
1818
import pmu.bundles.PmuNdPort
19+
import spec.ExeInst
1920

2021
class CoreCpuTop extends Module {
2122
val io = IO(new Bundle {
@@ -220,6 +221,7 @@ class CoreCpuTop extends Module {
220221

221222
exePassWbStage_1.io.peer.get.csrReadPort.get <> csr.io.readPorts(0)
222223
exePassWbStage_1.io.peer.get.stableCounterReadPort.get <> stableCounter.io
224+
exePassWbStage_1.io.peer.get.robQueryPcPort.get <> rob.io.queryPcPort
223225
assert(Param.loadStoreIssuePipelineIndex == 0)
224226
exePassWbStages.zipWithIndex.foreach {
225227
case (exe, idx) =>
@@ -300,8 +302,10 @@ class CoreCpuTop extends Module {
300302
cu.io.branchExe := exePassWbStages(Param.jumpBranchPipelineIndex - 1).io.peer.get.branchSetPort.get
301303
cu.io.redirectFromDecode := instQueue.io.redirectRequest
302304

303-
cu.io.csrFlushRequest := csr.io.csrFlushRequest
304-
cu.io.csrWriteInfo := csrScoreBoard.io.csrWritePort
305+
cu.io.csrFlushRequest := csr.io.csrFlushRequest
306+
cu.io.csrWriteInfo := csrScoreBoard.io.csrWritePort
307+
cu.io.majorPc := commitStage.io.majorPc
308+
cu.io.exceptionVirtAddr := addrTransStage.io.peer.get.exceptionVirtAddr
305309

306310
// CSR
307311
csr.io.writePorts.zip(cu.io.csrWritePorts).foreach {
@@ -322,8 +326,8 @@ class CoreCpuTop extends Module {
322326
csr.io.hardwareInterrupt := io.intrpt
323327

324328
// Debug ports
325-
io.debug0_wb.pc := commitStage.io.ins(0).bits.instInfo.pc
326-
io.debug0_wb.inst := commitStage.io.ins(0).bits.instInfo.inst
329+
io.debug0_wb.pc := commitStage.io.ins(0).bits.fetchInfo.pcAddr
330+
io.debug0_wb.inst := commitStage.io.ins(0).bits.fetchInfo.inst
327331
io.debug0_wb.rf.wen := VecInit(
328332
Seq.fill(4)(
329333
commitStage.io.gprWritePorts(0).en && commitStage.io.ins(0).bits.instInfo.isValid && commitStage.io

src/src/control/Cu.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import spec.Param.isDiffTest
1010
import spec.{Csr, ExeInst, Param}
1111
import frontend.bundles.CuCommitFtqNdPort
1212
import frontend.bundles.QueryPcBundle
13+
import spec.Width
1314

1415
// Note. Exception只从第0个提交
1516
class Cu(
@@ -21,6 +22,7 @@ class Cu(
2122
// `WbStage` -> `Cu` -> `Regfile`
2223
val gprWritePassThroughPorts = new PassThroughPort(Vec(commitNum, new RfWriteNdPort))
2324
val instInfoPorts = Input(Vec(commitNum, new InstInfoNdPort))
25+
val majorPc = Input(UInt(Width.Reg.data))
2426
// `Cu` -> `Csr`, 软件写
2527
val csrWritePorts = Output(Vec(writeNum, new CsrWriteNdPort))
2628
// `Cu` -> `Csr`, 硬件写
@@ -49,6 +51,8 @@ class Cu(
4951
val ftqPort = Output(new CuCommitFtqNdPort)
5052
val queryPcPort = Flipped(new QueryPcBundle)
5153

54+
val exceptionVirtAddr = Input(UInt(Width.Mem.addr))
55+
5256
val isDbarFinish = Output(Bool())
5357

5458
val difftest = if (isDiffTest) {
@@ -65,7 +69,7 @@ class Cu(
6569
// Values
6670
val majorInstInfo = io.instInfoPorts.head
6771
io.queryPcPort.ftqId := majorInstInfo.ftqInfo.ftqId
68-
val majorPc: UInt = WireDefault(io.queryPcPort.pc + (majorInstInfo.ftqInfo.idxInBlock << 2))
72+
val majorPc = io.majorPc // : UInt = WireDefault(io.queryPcPort.pc + (majorInstInfo.ftqInfo.idxInBlock << 2))
6973
val isException = (majorInstInfo.exceptionPos =/= ExceptionPos.none) && majorInstInfo.isValid
7074

7175
// Write GPR
@@ -159,7 +163,7 @@ class Cu(
159163
io.csrMessage.badVAddrSet.en := true.B
160164
io.csrMessage.badVAddrSet.addr := Mux(
161165
majorInstInfo.exceptionPos === ExceptionPos.backend,
162-
majorInstInfo.vaddr,
166+
io.exceptionVirtAddr,
163167
majorPc
164168
)
165169
}

src/src/frontend/fetch/InstResStage.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class InstResStage
4141

4242
out.enqInfos.zipWithIndex.foreach {
4343
case (infoBundle, index) =>
44-
infoBundle.bits.pcAddr := selectedIn.ftqBlock.startPc + index.asUInt(Width.Mem.addr) * 4.U
45-
infoBundle.bits.ftqInfo.idxInBlock := index.U
44+
infoBundle.bits.pcAddr := selectedIn.ftqBlock.startPc + index.asUInt(Width.Mem.addr) * 4.U
45+
// infoBundle.bits.ftqInfo.idxInBlock := index.U
4646
if (Param.fetchInstMaxNum == 1) {
4747
infoBundle.bits.inst := peer.memRes.read.dataVec(0)
4848
infoBundle.valid := true.B

src/src/memory/DCache.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ class DCache(
231231
val writeData = UInt(Width.Mem.data)
232232
val writeMask = UInt(Width.Mem.data)
233233
val isWrite = Bool()
234-
val writeDataLine = Vec(Param.Count.DCache.dataPerLine, UInt(Width.Mem.data))
235234
}))
236235
lastReg := lastReg // Fallback: Keep data
237236
lastReg.isWrite := false.B
@@ -326,7 +325,7 @@ class DCache(
326325
lastReg.memAddr(Width.Mem._addr - 1, Param.Width.DCache._byteOffset)
327326
val lastQueryIndex = queryIndexFromMemAddr(lastReg.memAddr)
328327
when(isLastMatched && lastReg.isWrite) {
329-
selectedDataLine := lastReg.writeDataLine
328+
selectedDataLine := lastReg.dataLine
330329
}
331330
when(lastQueryIndex === queryIndex) {
332331
statusTagLines.zipWithIndex.foreach {
@@ -341,7 +340,6 @@ class DCache(
341340
lastReg.memAddr := reqMemAddr
342341
lastReg.statusTagLines := statusTagLines
343342
lastReg.setIndex := setIndex
344-
lastReg.dataLine := selectedDataLine
345343
lastReg.writeData := reqWriteData
346344
lastReg.writeMask := reqWriteMask
347345

@@ -376,7 +374,7 @@ class DCache(
376374
case (data, index) =>
377375
Mux(index.U === dataIndex, newData, data)
378376
}))
379-
lastReg.writeDataLine := writeDataLine
377+
lastReg.dataLine := writeDataLine
380378

381379
// Set dirty bit
382380
writeStatusTag.isDirty := true.B
@@ -442,7 +440,7 @@ class DCache(
442440
lastReg.setIndex := refillSetIndex
443441
lastReg.dataLine := toDataLine(dataLines(refillSetIndex))
444442
when(lastReg.isWrite && refillSetIndex === lastReg.setIndex && queryIndex === lastQueryIndex) {
445-
lastReg.dataLine := lastReg.writeDataLine
443+
lastReg.dataLine := lastReg.dataLine
446444
}
447445

448446
// Init refill state regs

src/src/pipeline/commit/CommitStage.scala

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import pipeline.dispatch.bundles.ScoreboardChangeNdPort
1010
import spec.Param.isDiffTest
1111
import spec._
1212
import pmu.bundles.PmuBranchPredictNdPort
13+
import pipeline.dispatch.bundles.FetchInstInfoBundle
14+
import pipeline.commit.bundles.PcInstBundle
1315

1416
class WbNdPort extends Bundle {
1517
val gprWrite = new RfWriteNdPort
@@ -20,17 +22,26 @@ object WbNdPort {
2022
def default = 0.U.asTypeOf(new WbNdPort)
2123
}
2224

25+
class CommitNdPort extends Bundle {
26+
val gprWrite = new RfWriteNdPort
27+
val instInfo = new InstInfoNdPort
28+
val fetchInfo = new PcInstBundle
29+
}
30+
31+
object CommitNdPort {
32+
def default = 0.U.asTypeOf(new CommitNdPort)
33+
}
34+
2335
class CommitStage(
2436
commitNum: Int = Param.commitNum)
2537
extends Module {
2638
val io = IO(new Bundle {
27-
val ins = Vec(commitNum, Flipped(Decoupled(new WbNdPort)))
39+
val ins = Vec(commitNum, Flipped(Decoupled(new CommitNdPort)))
2840

2941
// `CommitStage` -> `Cu` NO delay
30-
val gprWritePorts = Output(Vec(commitNum, new RfWriteNdPort))
31-
32-
// `AddrTransStage` -> `CommitStage` -> `Cu` NO delay
42+
val gprWritePorts = Output(Vec(commitNum, new RfWriteNdPort))
3343
val cuInstInfoPorts = Output(Vec(commitNum, new InstInfoNdPort))
44+
val majorPc = Output(UInt(Width.Reg.data))
3445

3546
val pmu_branchInfo = if (Param.usePmu) Some(Output(new PmuBranchPredictNdPort)) else None
3647

@@ -79,6 +90,7 @@ class CommitStage(
7990
dstGprWrite := inBit.gprWrite
8091
dstGprWrite.en := in.valid && in.ready && inBit.gprWrite.en
8192
}
93+
io.majorPc := inBits.head.fetchInfo.pcAddr
8294

8395
io.pmu_branchInfo match {
8496
case None =>
@@ -97,14 +109,14 @@ class CommitStage(
97109
io.difftest match {
98110
case Some(dt) =>
99111
dt.valid := RegNext(inBits(0).instInfo.isValid && io.ins(0).valid && io.ins(0).ready, false.B) // && nextCommit)
100-
dt.pc := RegNext(inBits(0).instInfo.pc, 0.U)
101-
dt.instr := RegNext(inBits(0).instInfo.inst, 0.U)
112+
dt.pc := RegNext(inBits(0).fetchInfo.pcAddr, 0.U)
113+
dt.instr := RegNext(inBits(0).fetchInfo.inst, 0.U)
102114
dt.wen := RegNext(inBits(0).gprWrite.en, false.B)
103115
dt.wdest := RegNext(inBits(0).gprWrite.addr, 0.U)
104116
dt.wdata := RegNext(inBits(0).gprWrite.data, 0.U)
105117
dt.csr_rstat := RegNext(
106-
inBits(0).instInfo.inst(31, 24) === Inst._2RI14.csr_ &&
107-
inBits(0).instInfo.inst(23, 10) === "h5".U,
118+
inBits(0).fetchInfo.inst(31, 24) === Inst._2RI14.csr_ &&
119+
inBits(0).fetchInfo.inst(23, 10) === "h5".U,
108120
false.B
109121
) && io.ins(0).valid && io.ins(0).ready
110122
dt.ld_en := RegNext(inBits(0).instInfo.load.get.en, false.B)
@@ -127,8 +139,8 @@ class CommitStage(
127139

128140
if (commitNum == 2) {
129141
dt.valid_1 := RegNext(inBits(1).instInfo.isValid && io.ins(1).valid && io.ins(1).ready, false.B)
130-
dt.instr_1 := RegNext(inBits(1).instInfo.inst, 0.U)
131-
dt.pc_1 := RegNext(inBits(1).instInfo.pc, 0.U)
142+
dt.instr_1 := RegNext(inBits(1).fetchInfo.inst, 0.U)
143+
dt.pc_1 := RegNext(inBits(1).fetchInfo.pcAddr, 0.U)
132144
dt.wen_1 := RegNext(inBits(1).gprWrite.en, false.B)
133145
dt.wdest_1 := RegNext(inBits(1).gprWrite.addr, 0.U)
134146
dt.wdata_1 := RegNext(inBits(1).gprWrite.data, 0.U)

src/src/pipeline/commit/bundles/InstInfoNdPort.scala

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@ import pipeline.dispatch.bundles.FtqInfoBundle
1111

1212
class InstInfoNdPort extends Bundle {
1313
val isValid = Bool()
14-
val pc = UInt(Width.Reg.data)
15-
val inst = UInt(Width.Reg.data)
1614
val exceptionPos = ExceptionPos()
1715
val exceptionRecord = UInt(Csr.ExceptionIndex.width)
1816
val isStore = Bool()
19-
val vaddr = UInt(Width.Mem.addr)
2017
val needRefetch = Bool()
2118
val isCsrWrite = Bool()
22-
val branchSuccess = Bool()
2319

2420
val exeOp = UInt(Param.Width.exeOp)
2521
val robId = UInt(Param.Width.Rob.id)
@@ -48,7 +44,6 @@ object InstInfoNdPort {
4844
instInfo.isTlb := false.B
4945
instInfo.isStore := false.B
5046
instInfo.forbidParallelCommit := false.B
51-
instInfo.branchSuccess := false.B
5247

5348
if (isDiffTest) {
5449
instInfo.load.get.en := false.B
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package pipeline.commit.bundles
2+
import chisel3._
3+
import spec._
4+
5+
class PcInstBundle extends Bundle {
6+
val pcAddr = UInt(Width.Reg.data)
7+
val inst = UInt(Width.Reg.data)
8+
}

src/src/pipeline/dispatch/NewDispatchStage.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class NewDispatchStage(
9595
}
9696
}
9797

98-
// dontcare if input valid
98+
// dontcare if input not valid
9999
val dispatchMap = WireDefault(VecInit(Seq.fill(issueNum)(VecInit(Seq.fill(pipelineNum)(false.B)))))
100100
val srcEns = WireDefault(VecInit(dispatchMap.map(_.reduceTree(_ || _))))
101101
val dstEns = WireDefault(dispatchMap.reduce { (a, b) =>

src/src/pipeline/dispatch/NewRenameStage.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ class NewRenameStage(
123123
case (dst, src) =>
124124
dst := src
125125
}
126+
req.bits.fetchInfo := in.fetchInfo
126127
}
127128

128129
// -> reservation station

src/src/pipeline/dispatch/bundles/FtqInfoBundle.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import chisel3.util.log2Ceil
88
class FtqInfoBundle extends Bundle {
99
val isLastInBlock = Bool()
1010
val ftqId = UInt(Param.BPU.Width.id)
11-
val idxInBlock = UInt(log2Ceil(Param.fetchInstMaxNum).W)
11+
// val idxInBlock = UInt(log2Ceil(Param.fetchInstMaxNum).W)
1212
val predictBranch = Bool()
1313
}
1414

0 commit comments

Comments
 (0)