未验证 提交 4cf16877 编写于 作者: Y Yinan Xu 提交者: GitHub

Merge branch 'master' into l2_support_outer_probe

......@@ -210,8 +210,11 @@ class Backend extends XSModule
roq.io.dp1Req <> dispatch.io.toRoq
dispatch.io.roqIdxs <> roq.io.roqIdxs
io.mem.dp1Req <> dispatch.io.toLsroq
dispatch.io.commits <> roq.io.commits
dispatch.io.lsIdxs <> io.mem.lsIdxs
dispatch.io.dequeueRoqIndex.valid := roq.io.commitRoqIndex.valid || io.mem.oldestStore.valid
// store writeback must be after commit roqIdx
dispatch.io.dequeueRoqIndex.bits := Mux(io.mem.oldestStore.valid, io.mem.oldestStore.bits, roq.io.commitRoqIndex.bits)
intRf.io.readPorts <> dispatch.io.readIntRf
fpRf.io.readPorts <> dispatch.io.readFpRf ++ issueQueues.flatMap(_.io.readFpRf)
......
......@@ -36,7 +36,7 @@ class Dispatch extends XSModule {
val toLsroq = Vec(RenameWidth, DecoupledIO(new MicroOp))
// get LsIdx
val lsIdxs = Input(Vec(RenameWidth, new LSIdx))
val commits = Input(Vec(CommitWidth, Valid(new RoqCommit)))
val dequeueRoqIndex = Input(Valid(new RoqPtr))
// read regfile
val readIntRf = Vec(NRIntReadPorts, Flipped(new RfReadPort))
val readFpRf = Vec(NRFpReadPorts - exuParameters.StuCnt, Flipped(new RfReadPort))
......@@ -80,30 +80,21 @@ class Dispatch extends XSModule {
// dispatch queue: queue uops and dispatch them to different reservation stations or issue queues
// it may cancel the uops
intDq.io.redirect <> io.redirect
intDq.io.commits <> io.commits
intDq.io.commits.zip(io.commits).map { case (dqCommit, commit) =>
dqCommit.valid := commit.valid && dqCommit.bits.uop.ctrl.commitType === CommitType.INT
}
intDq.io.dequeueRoqIndex <> io.dequeueRoqIndex
intDq.io.replayPregReq.zipWithIndex.map { case(replay, i) =>
io.replayPregReq(i) <> replay
}
intDq.io.otherWalkDone := !fpDq.io.inReplayWalk && !lsDq.io.inReplayWalk
fpDq.io.redirect <> io.redirect
fpDq.io.commits <> io.commits
fpDq.io.commits.zip(io.commits).map { case (dqCommit, commit) =>
dqCommit.valid := commit.valid && dqCommit.bits.uop.ctrl.commitType === CommitType.FP
}
fpDq.io.dequeueRoqIndex <> io.dequeueRoqIndex
fpDq.io.replayPregReq.zipWithIndex.map { case(replay, i) =>
io.replayPregReq(i + dpParams.IntDqReplayWidth) <> replay
}
fpDq.io.otherWalkDone := !intDq.io.inReplayWalk && !lsDq.io.inReplayWalk
lsDq.io.redirect <> io.redirect
lsDq.io.commits <> io.commits
lsDq.io.commits.zip(io.commits).map { case (dqCommit, commit) =>
dqCommit.valid := commit.valid && CommitType.isLoadStore(dqCommit.bits.uop.ctrl.commitType)
}
lsDq.io.dequeueRoqIndex <> io.dequeueRoqIndex
lsDq.io.replayPregReq.zipWithIndex.map { case(replay, i) =>
io.replayPregReq(i + dpParams.IntDqReplayWidth + dpParams.FpDqReplayWidth) <> replay
}
......
......@@ -4,13 +4,13 @@ import chisel3._
import chisel3.util._
import utils._
import xiangshan.backend.decode.SrcType
import xiangshan.{MicroOp, Redirect, ReplayPregReq, RoqCommit, XSBundle, XSModule}
import xiangshan._
import xiangshan.backend.roq.RoqPtr
class DispatchQueueIO(enqnum: Int, deqnum: Int, replayWidth: Int) extends XSBundle {
val enq = Vec(enqnum, Flipped(DecoupledIO(new MicroOp)))
val deq = Vec(deqnum, DecoupledIO(new MicroOp))
val commits = Input(Vec(CommitWidth, Valid(new RoqCommit)))
val dequeueRoqIndex = Input(Valid(new RoqPtr))
val redirect = Flipped(ValidIO(new Redirect))
val replayPregReq = Output(Vec(replayWidth, new ReplayPregReq))
val inReplayWalk = Output(Bool())
......@@ -89,14 +89,17 @@ class DispatchQueue(size: Int, enqnum: Int, deqnum: Int, replayWidth: Int) exten
}
// commit: from s_dispatched to s_invalid
val numCommit = PopCount(io.commits.map(commit => !commit.bits.isWalk && commit.valid))
val commitBits = (1.U((CommitWidth+1).W) << numCommit).asUInt() - 1.U
for (i <- 0 until CommitWidth) {
when (commitBits(i)) {
stateEntries(commitIndex(i)) := s_invalid
XSError(stateEntries(commitIndex(i)) =/= s_dispatched, "state of the commit entry is not s_dispatched\n")
val needDequeue = Wire(Vec(size, Bool()))
val deqRoqIdx = io.dequeueRoqIndex.bits
for (i <- 0 until size) {
needDequeue(i) := stateEntries(i) === s_dispatched && io.dequeueRoqIndex.valid && !isAfter(uopEntries(i).roqIdx, deqRoqIdx) && dispatchedMask(i)
when (needDequeue(i)) {
stateEntries(i) := s_invalid
}
XSInfo(needDequeue(i), p"dispatched entry($i)(pc = ${Hexadecimal(uopEntries(i).cf.pc)}) " +
p"roqIndex 0x${Hexadecimal(uopEntries(i).roqIdx.asUInt)} " +
p"left dispatch queue with deqRoqIndex 0x${Hexadecimal(io.dequeueRoqIndex.bits.asUInt)}\n")
}
// redirect: cancel uops currently in the queue
......@@ -107,14 +110,15 @@ class DispatchQueue(size: Int, enqnum: Int, deqnum: Int, replayWidth: Int) exten
val needCancel = Wire(Vec(size, Bool()))
for (i <- 0 until size) {
roqNeedFlush(i) := uopEntries(i.U).roqIdx.needFlush(io.redirect)
needCancel(i) := stateEntries(i) =/= s_invalid && ((roqNeedFlush(i) && mispredictionValid) || exceptionValid || flushPipeValid)
needCancel(i) := stateEntries(i) =/= s_invalid && ((roqNeedFlush(i) && mispredictionValid) || exceptionValid || flushPipeValid) && !needDequeue(i)
when (needCancel(i)) {
stateEntries(i) := s_invalid
}
XSInfo(needCancel(i), p"valid entry($i)(pc = ${Hexadecimal(uopEntries(i.U).cf.pc)}) " +
p"roqIndex ${uopEntries(i.U).roqIdx} " +
p"cancelled with redirect roqIndex ${io.redirect.bits.roqIdx}\n")
XSInfo(needCancel(i), p"valid entry($i)(pc = ${Hexadecimal(uopEntries(i).cf.pc)}) " +
p"roqIndex 0x${Hexadecimal(uopEntries(i).roqIdx.asUInt)} " +
p"cancelled with redirect roqIndex 0x${Hexadecimal(io.redirect.bits.roqIdx.asUInt)}\n")
}
// replay: from s_dispatched to s_valid
......@@ -253,7 +257,7 @@ class DispatchQueue(size: Int, enqnum: Int, deqnum: Int, replayWidth: Int) exten
Mux(inReplayWalk, dispatchPtr - dispatchReplayStep, dispatchPtr + numDeq))
)
headPtr := Mux(exceptionValid, 0.U.asTypeOf(new CircularQueuePtr(size)), headPtr + numCommit)
headPtr := Mux(exceptionValid, 0.U.asTypeOf(new CircularQueuePtr(size)), headPtr + PopCount(needDequeue))
/**
* Part 4: set output and input
......
......@@ -149,7 +149,6 @@ class ReservationStation
val tailAdd = tailAll + 1.U
val tailSub = tailAll - 1.U
tailAll := Mux(tailKeep, tailAll, Mux(tailInc, tailAdd, tailSub))
assert(tailAll < 9.U)
// Select to Dequeue
val deqSel = if (fifo) 0.U else PriorityEncoder(idValidQue & srcIdRdy) //may not need idx, just need oneHot, idx by IdQue's idx
val deqSelIq = idQue(deqSel)
......@@ -250,7 +249,6 @@ class ReservationStation
) // Note: direct by IQue's idx, different from deqSel
io.numExist := Mux(tailAll === iqSize.U, (iqSize-1).U, tailAll)
assert(tailAll < 9.U)
//-----------------------------------------
// Issue with No Delay
......@@ -437,4 +435,4 @@ class ReservationStation
)
}
}
}
\ No newline at end of file
}
......@@ -38,6 +38,7 @@ class Roq extends XSModule with HasCircularQueuePtrHelper {
val exeWbResults = Vec(exuParameters.ExuCnt + 1, Flipped(ValidIO(new ExuOutput)))
val commits = Vec(CommitWidth, Valid(new RoqCommit))
val bcommit = Output(UInt(BrTagWidth.W))
val commitRoqIndex = Output(Valid(new RoqPtr))
val roqDeqPtr = Output(new RoqPtr)
})
......@@ -253,6 +254,9 @@ class Roq extends XSModule with HasCircularQueuePtrHelper {
}
val retireCounter = Mux(state === s_idle, commitCnt, 0.U)
XSInfo(retireCounter > 0.U, "retired %d insts\n", retireCounter)
val commitOffset = PriorityEncoder((validCommit :+ false.B).map(!_))
io.commitRoqIndex.valid := io.commits(0).valid && !io.commits(0).bits.isWalk
io.commitRoqIndex.bits := deqPtrExt + commitOffset
// commit branch to brq
io.bcommit := PopCount(cfiCommitVec)
......
......@@ -77,6 +77,7 @@ class MemToBackendIO extends XSBundle {
val commits = Flipped(Vec(CommitWidth, Valid(new RoqCommit)))
val dp1Req = Vec(RenameWidth, Flipped(DecoupledIO(new MicroOp)))
val lsIdxs = Output(Vec(RenameWidth, new LSIdx))
val oldestStore = Output(Valid(new RoqPtr))
val roqDeqPtr = Input(new RoqPtr)
}
......@@ -145,6 +146,7 @@ class Memend extends XSModule {
lsroq.io.stout <> io.backend.stout
lsroq.io.commits <> io.backend.commits
lsroq.io.dp1Req <> io.backend.dp1Req
lsroq.io.oldestStore <> io.backend.oldestStore
lsroq.io.lsIdxs <> io.backend.lsIdxs
lsroq.io.brqRedirect := io.backend.redirect
lsroq.io.roqDeqPtr := io.backend.roqDeqPtr
......
......@@ -29,6 +29,7 @@ class LsqWrappper extends XSModule with HasDCacheParameters with NeedImpl {
val dcache = new DCacheLineIO
val uncache = new DCacheWordIO
val roqDeqPtr = Input(new RoqPtr)
val oldestStore = Output(Valid(new RoqPtr))
})
if(EnableUnifiedLSQ){
......@@ -47,6 +48,7 @@ class LsqWrappper extends XSModule with HasDCacheParameters with NeedImpl {
lsroq.io.dcache <> io.dcache
lsroq.io.uncache <> io.uncache
lsroq.io.roqDeqPtr <> io.roqDeqPtr
lsroq.io.oldestStore <> io.oldestStore
(0 until RenameWidth).map(i => {
io.lsIdxs(i).lsroqIdx := lsroq.io.lsroqIdxs(i)
})
......@@ -74,6 +76,7 @@ class LsqWrappper extends XSModule with HasDCacheParameters with NeedImpl {
storeQueue.io.stout <> io.stout
storeQueue.io.commits <> io.commits
storeQueue.io.roqDeqPtr <> io.roqDeqPtr
storeQueue.io.oldestStore <> io.oldestStore
loadQueue.io.forward <> io.forward
storeQueue.io.forward <> io.forward // overlap forwardMask & forwardData, DO NOT CHANGE SEQUENCE
......
......@@ -300,14 +300,6 @@ class LoadQueue extends XSModule with HasDCacheParameters with HasCircularQueueP
}
})
// move tailPtr
// allocatedMask: dequeuePtr can go to the next 1-bit
val allocatedMask = VecInit((0 until LoadQueueSize).map(i => allocated(i) || !enqDeqMask(i)))
// find the first one from deqPtr (ringBufferTail)
val nextTail1 = getFirstOneWithFlag(allocatedMask, tailMask, ringBufferTailExtended.flag)
val nextTail = Mux(Cat(allocatedMask).orR, nextTail1, ringBufferHeadExtended)
ringBufferTailExtended := nextTail
// When load commited, mark it as !allocated, this entry will be recycled later
(0 until CommitWidth).map(i => {
when(loadCommit(i)) {
......@@ -315,6 +307,8 @@ class LoadQueue extends XSModule with HasDCacheParameters with HasCircularQueueP
XSDebug("load commit %d: idx %d %x\n", i.U, mcommitIdx(i), uop(mcommitIdx(i)).cf.pc)
}
})
// move tailPtr
ringBufferTailExtended := ringBufferTailExtended + PopCount(loadCommit)
// rollback check
val rollback = Wire(Vec(StorePipelineWidth, Valid(new Redirect)))
......
......@@ -21,7 +21,6 @@ object SqPtr extends HasXSParameter {
}
}
// Store Queue
class StoreQueue extends XSModule with HasDCacheParameters with HasCircularQueuePtrHelper {
val io = IO(new Bundle() {
......@@ -36,6 +35,7 @@ class StoreQueue extends XSModule with HasDCacheParameters with HasCircularQueue
val uncache = new DCacheWordIO
val roqDeqPtr = Input(new RoqPtr)
// val refill = Flipped(Valid(new DCacheLineReq ))
val oldestStore = Output(Valid(new RoqPtr))
})
val uop = Reg(Vec(StoreQueueSize, new MicroOp))
......@@ -125,9 +125,6 @@ class StoreQueue extends XSModule with HasDCacheParameters with HasCircularQueue
}
})
// writeback up to 2 store insts to CDB
// choose the first two valid store requests from deqPtr
def getFirstOne(mask: Vec[Bool], startMask: UInt) = {
val length = mask.length
val highBits = (0 until length).map(i => mask(i) & ~startMask(i))
......@@ -156,9 +153,16 @@ class StoreQueue extends XSModule with HasDCacheParameters with HasCircularQueue
(selValid, selVec)
}
val storeWbSelVec = VecInit((0 until StoreQueueSize).map(i => {
allocated(i) && valid(i) && !writebacked(i)
}))
// select the last writebacked instruction
val validStoreVec = VecInit((0 until StoreQueueSize).map(i => !(allocated(i) && valid(i))))
val storeNotValid = SqPtr(false.B, getFirstOne(validStoreVec, tailMask))
val storeValidIndex = (storeNotValid - 1.U).value
io.oldestStore.valid := allocated(ringBufferTailExtended.value) && valid(ringBufferTailExtended.value) && !commited(storeValidIndex)
io.oldestStore.bits := uop(storeValidIndex).roqIdx
// writeback up to 2 store insts to CDB
// choose the first two valid store requests from deqPtr
val storeWbSelVec = VecInit((0 until StoreQueueSize).map(i => allocated(i) && valid(i) && !writebacked(i)))
val (storeWbValid, storeWbSel) = selectFirstTwo(storeWbSelVec, tailMask)
(0 until StorePipelineWidth).map(i => {
......@@ -176,15 +180,6 @@ class StoreQueue extends XSModule with HasDCacheParameters with HasCircularQueue
}
})
// remove retired insts from sq, add retired store to sbuffer
// move tailPtr
// allocatedMask: dequeuePtr can go to the next 1-bit
val allocatedMask = VecInit((0 until StoreQueueSize).map(i => allocated(i) || !enqDeqMask(i)))
// find the first one from deqPtr (ringBufferTail)
val nextTail1 = getFirstOneWithFlag(allocatedMask, tailMask, ringBufferTailExtended.flag)
val nextTail = Mux(Cat(allocatedMask).orR, nextTail1, ringBufferHeadExtended)
ringBufferTailExtended := nextTail
// load forward query
// check over all lq entries and forward data from the first matched store
......@@ -246,13 +241,13 @@ class StoreQueue extends XSModule with HasDCacheParameters with HasCircularQueue
}
})
// remove retired insts from sq, add retired store to sbuffer
val storeCommitSelVec = VecInit((0 until StoreQueueSize).map(i => {
allocated(i) && commited(i)
}))
val (storeCommitValid, storeCommitSel) = selectFirstTwo(storeCommitSelVec, tailMask)
// get no more than 2 commited store from storeCommitedQueue
// send selected store inst to sbuffer
val dequeueValid = Wire(Vec(2, Bool()))
(0 until 2).map(i => {
val ptr = storeCommitSel(i)
val mmio = data(ptr).mmio
......@@ -268,11 +263,14 @@ class StoreQueue extends XSModule with HasDCacheParameters with HasCircularQueue
io.sbuffer(i).bits.meta.mask := data(ptr).mask
// update sq meta if store inst is send to sbuffer
when(storeCommitValid(i) && (mmio || io.sbuffer(i).ready)) {
dequeueValid(i) := storeCommitValid(i) && (mmio || io.sbuffer(i).ready)
when (dequeueValid(i)) {
allocated(ptr) := false.B
}
})
// move tailPtr
ringBufferTailExtended := ringBufferTailExtended + PopCount(dequeueValid)
// Memory mapped IO / other uncached operations
// setup misc mem access req
......
......@@ -32,6 +32,7 @@ class Lsroq extends XSModule with HasDCacheParameters with HasCircularQueuePtrHe
val io = IO(new Bundle() {
val dp1Req = Vec(RenameWidth, Flipped(DecoupledIO(new MicroOp)))
val lsroqIdxs = Output(Vec(RenameWidth, UInt(LsroqIdxWidth.W)))
val oldestStore = Output(Valid(new RoqPtr))
val brqRedirect = Input(Valid(new Redirect))
val loadIn = Vec(LoadPipelineWidth, Flipped(Valid(new LsPipelineBundle)))
val storeIn = Vec(StorePipelineWidth, Flipped(Valid(new LsPipelineBundle)))
......@@ -163,7 +164,12 @@ class Lsroq extends XSModule with HasDCacheParameters with HasCircularQueuePtrHe
pending(io.loadIn(i).bits.uop.lsroqIdx) := io.loadIn(i).bits.mmio
}
})
// find first store req that has not been writebacked
val storeNotWritebacked = VecInit((0 until LsroqSize).map(i => store(i) && !writebacked(i)))
val firstStore = getFirstOne(storeNotWritebacked, tailMask)
io.oldestStore.valid := false.B
io.oldestStore.bits := DontCare
// writeback store
(0 until StorePipelineWidth).map(i => {
when(io.storeIn(i).fire()) {
......@@ -178,16 +184,20 @@ class Lsroq extends XSModule with HasDCacheParameters with HasCircularQueuePtrHe
store(io.storeIn(i).bits.uop.lsroqIdx) := true.B
pending(io.storeIn(i).bits.uop.lsroqIdx) := io.storeIn(i).bits.mmio
XSInfo("store write to lsroq idx %d pc 0x%x vaddr %x paddr %x data %x miss %x mmio %x roll %x exc %x\n",
io.storeIn(i).bits.uop.lsroqIdx(InnerLsroqIdxWidth - 1, 0),
io.storeIn(i).bits.uop.cf.pc,
io.storeIn(i).bits.vaddr,
io.storeIn(i).bits.paddr,
io.storeIn(i).bits.data,
io.storeIn(i).bits.miss,
io.storeIn(i).bits.mmio,
io.storeIn(i).bits.rollback,
io.storeIn(i).bits.uop.cf.exceptionVec.asUInt
io.storeIn(i).bits.uop.lsroqIdx(InnerLsroqIdxWidth - 1, 0),
io.storeIn(i).bits.uop.cf.pc,
io.storeIn(i).bits.vaddr,
io.storeIn(i).bits.paddr,
io.storeIn(i).bits.data,
io.storeIn(i).bits.miss,
io.storeIn(i).bits.mmio,
io.storeIn(i).bits.rollback,
io.storeIn(i).bits.uop.cf.exceptionVec.asUInt
)
when (io.storeIn(i).bits.uop.lsroqIdx(InnerLsroqIdxWidth - 1, 0) === firstStore) {
io.oldestStore.valid := true.B
io.oldestStore.bits := io.storeIn(i).bits.uop.roqIdx
}
}
})
......
......@@ -74,6 +74,7 @@ Emulator::Emulator(int argc, const char *argv[]):
cycles(0), hascommit(0), trapCode(STATE_RUNNING)
{
args = parse_args(argc, argv);
printf("Emu compiled at %s, %s UTC\n", __DATE__, __TIME__);
// srand
srand(args.seed);
......
......@@ -100,7 +100,6 @@ void init_ram(const char *img) {
assert(0);
}
printf("Emu compiled at %s, %s\n", __DATE__, __TIME__);
printf("The image is %s\n", img);
fseek(fp, 0, SEEK_END);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册