Skip to content

Commit

Permalink
[rtl] change token size chaningSize -> 2 * chainingSize.
Browse files Browse the repository at this point in the history
  • Loading branch information
qinjun-li committed Nov 19, 2024
1 parent ccd98ad commit f41390a
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 79 deletions.
23 changes: 9 additions & 14 deletions t1/src/Lane.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class LaneProbe(parameter: LaneParameter) extends Bundle {
// @todo @Clo91eaf change to occupied for each slot.
val lastSlotOccupied: Bool = Bool()
val instructionFinished: UInt = UInt(parameter.chainingSize.W)
val instructionValid: UInt = UInt(parameter.chainingSize.W)
val instructionValid: UInt = UInt((2 * parameter.chainingSize).W)

val crossWriteProbe: Vec[ValidIO[LaneWriteProbe]] = Vec(2, Valid(new LaneWriteProbe(parameter.instructionIndexBits)))

Expand Down Expand Up @@ -275,9 +275,9 @@ class Lane(val parameter: LaneParameter) extends Module with SerializableModule[

/** for each instruction in the slot, response to top when instruction is finished in this lane. */
@public
val instructionFinished: UInt = IO(Output(UInt(parameter.chainingSize.W)))
val instructionFinished: UInt = IO(Output(UInt((2 * parameter.chainingSize).W)))
@public
val vxsatReport: UInt = IO(Output(UInt(parameter.chainingSize.W)))
val vxsatReport: UInt = IO(Output(UInt((2 * parameter.chainingSize).W)))

/** V0 update in the lane should also update [[T1.v0]] */
@public
Expand All @@ -300,15 +300,11 @@ class Lane(val parameter: LaneParameter) extends Module with SerializableModule[
* is finished.
*/
@public
val lsuLastReport: UInt = IO(Input(UInt(parameter.chainingSize.W)))

/** If lsu changes the mask group, you need to tell vrf */
@public
val lsuMaskGroupChange: UInt = IO(Input(UInt(parameter.chainingSize.W)))
val lsuLastReport: UInt = IO(Input(UInt((2 * parameter.chainingSize).W)))

/** for RaW, VRF should wait for buffer to be empty. */
@public
val loadDataInLSUWriteQueue: UInt = IO(Input(UInt(parameter.chainingSize.W)))
val loadDataInLSUWriteQueue: UInt = IO(Input(UInt((2 * parameter.chainingSize).W)))

/** How many dataPath will writ by instruction in this lane */
@public
Expand Down Expand Up @@ -512,14 +508,14 @@ class Lane(val parameter: LaneParameter) extends Module with SerializableModule[
val slot0EnqueueFire: Bool = Wire(Bool())

/** assert when a instruction is valid in the slot. */
val instructionValid: UInt = Wire(UInt(parameter.chainingSize.W))
val instructionValid: UInt = Wire(UInt((2 * parameter.chainingSize).W))
val instructionValidNext: UInt = RegNext(instructionValid, 0.U)

val vxsatResult: UInt = RegInit(0.U(parameter.chainingSize.W))
val vxsatResult: UInt = RegInit(0.U((2 * parameter.chainingSize).W))
vxsatReport := vxsatResult

// Overflow occurs
val vxsatEnq: Vec[UInt] = Wire(Vec(parameter.chainingSize, UInt(parameter.chainingSize.W)))
val vxsatEnq: Vec[UInt] = Wire(Vec(parameter.chainingSize, UInt((2 * parameter.chainingSize).W)))
// vxsatEnq and instructionFinished cannot happen at the same time
vxsatResult := (vxsatEnq.reduce(_ | _) | vxsatResult) & (~instructionFinished).asUInt

Expand Down Expand Up @@ -780,7 +776,7 @@ class Lane(val parameter: LaneParameter) extends Module with SerializableModule[
vxsatEnq(index) := Mux(
executionUnit.dataResponse.valid &&
(executionUnit.dataResponse.bits.clipFail ## executionUnit.dataResponse.bits.vxsat).orR,
UIntToOH(executionUnit.responseIndex(parameter.instructionIndexBits - 2, 0)),
indexToOH(executionUnit.responseIndex, parameter.chainingSize),
0.U(parameter.chainingSize.W)
)
AssertProperty(BoolSequence(!executionUnit.dequeue.valid || stage2.dequeue.valid))
Expand Down Expand Up @@ -1166,7 +1162,6 @@ class Lane(val parameter: LaneParameter) extends Module with SerializableModule[
// clear record by instructionFinished
vrf.instructionLastReport := instructionFinished
vrf.lsuLastReport := lsuLastReport
vrf.lsuMaskGroupChange := lsuMaskGroupChange
vrf.loadDataInLSUWriteQueue := loadDataInLSUWriteQueue
vrf.dataInLane := instructionValid
instructionFinished := (~instructionValid).asUInt & instructionValidNext
Expand Down
5 changes: 2 additions & 3 deletions t1/src/T1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ class T1(val parameter: T1Parameter)
lsu.offsetReadIndex(index) := lane.maskUnitRequest.bits.index

instructionFinished(index).zip(slots.map(_.record.instructionIndex)).foreach { case (d, f) =>
d := (UIntToOH(f(parameter.instructionIndexBits - 2, 0)) & lane.instructionFinished).orR
d := ohCheck(lane.instructionFinished, f, parameter.chainingSize)
}
vxsatReportVec(index) := lane.vxsatReport
lane.maskInput := maskUnit.laneMaskInput(index)
Expand All @@ -785,7 +785,6 @@ class T1(val parameter: T1Parameter)

lane.lsuLastReport := lsu.lastReport | maskUnit.lastReport

lane.lsuMaskGroupChange := lsu.lsuMaskGroupChange
lane.loadDataInLSUWriteQueue := lsu.dataInWriteQueue(index)
// 2 + 3 = 5
val rowWith: Int = log2Ceil(parameter.datapathWidth / 8) + log2Ceil(parameter.laneNumber)
Expand Down Expand Up @@ -977,7 +976,7 @@ class T1(val parameter: T1Parameter)
}
probeWire.instructionValid := maskAnd(
!slots.last.state.wMaskUnitLast && !slots.last.state.idle,
indexToOH(slots.last.record.instructionIndex, parameter.chainingSize * 2)
indexToOH(slots.last.record.instructionIndex, parameter.chainingSize)
).asUInt
probeWire.responseCounter := responseCounter
probeWire.laneProbes.zip(laneVec).foreach { case (p, l) => p := probe.read(l.laneProbe) }
Expand Down
4 changes: 1 addition & 3 deletions t1/src/laneStage/MaskedWrite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class MaskedWrite(parameter: LaneParameter) extends Module {
new VRFReadRequest(parameter.vrfParam.regNumBits, parameter.vrfOffsetBits, parameter.instructionIndexBits)
)
)
@public
val maskedWrite1H: UInt = IO(Output(UInt(parameter.chainingSize.W)))

/** VRF read result for each slot, 3 is for [[source1]] [[source2]] [[source3]]
*/
Expand Down Expand Up @@ -111,7 +109,7 @@ class MaskedWrite(parameter: LaneParameter) extends Module {
vrfReadPipe.enq.valid := readDataValid
vrfReadPipe.enq.bits := vrfReadResult

maskedWrite1H := dataInS3 | dataInS2 | dataInS1 | dataInQueue
val maskedWrite1H = dataInS3 | dataInS2 | dataInS1 | dataInQueue

val maskFill: UInt = FillInterleaved(8, s3Pipe.mask)
val readDataSelect = Mux(fwd3, s3BypassData, vrfReadPipe.deq.bits)
Expand Down
34 changes: 15 additions & 19 deletions t1/src/laneStage/SlotTokenManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ class SlotTokenManager(parameter: LaneParameter) extends Module {
val maskWriteDeq: ValidIO[UInt] = IO(Flipped(Valid(UInt(parameter.instructionIndexBits.W))))

@public
val instructionValid: UInt = IO(Output(UInt(parameter.chainingSize.W)))
val instructionValid: UInt = IO(Output(UInt((2 * parameter.chainingSize).W)))

@public
val dataInWritePipe: UInt = IO(Output(UInt(parameter.chainingSize.W)))
val dataInWritePipe: UInt = IO(Output(UInt((2 * parameter.chainingSize).W)))

@public
val maskUnitLastReport: UInt = IO(Input(UInt(parameter.chainingSize.W)))
val maskUnitLastReport: UInt = IO(Input(UInt((2 * parameter.chainingSize).W)))

def tokenUpdate(tokenData: Seq[UInt], enqWire: UInt, deqWire: UInt): UInt = {
tokenData.zipWithIndex.foreach { case (t, i) =>
Expand Down Expand Up @@ -140,7 +140,7 @@ class SlotTokenManager(parameter: LaneParameter) extends Module {
}

val instructionInSlot: UInt = enqReports.zipWithIndex.map { case (enqReport, slotIndex) =>
val writeToken: Seq[UInt] = Seq.tabulate(parameter.chainingSize)(_ => RegInit(0.U(tokenWith.W)))
val writeToken: Seq[UInt] = Seq.tabulate(parameter.chainingSize * 2)(_ => RegInit(0.U(tokenWith.W)))

val enqOH = indexToOH(enqReport.bits.instructionIndex, parameter.chainingSize)

Expand All @@ -157,22 +157,15 @@ class SlotTokenManager(parameter: LaneParameter) extends Module {
indexToOH(slotWriteReport(slotIndex).bits, parameter.chainingSize)
).asUInt

val writeEnqSelect: UInt = Wire(UInt(parameter.chainingSize.W))
val writeEnqSelect: UInt = Wire(UInt((2 * parameter.chainingSize).W))

val pendingSlotWrite = tokenUpdate(writeToken, writeEnqSelect, writeDoDeq)

if (slotIndex == 0) {
val responseToken: Seq[UInt] = Seq.tabulate(parameter.chainingSize)(_ => RegInit(0.U(tokenWith.W)))
val feedbackToken: Seq[UInt] = Seq.tabulate(parameter.chainingSize)(_ => RegInit(0.U(tokenWith.W)))
val crossWriteTokenLSB: Seq[UInt] = Seq.tabulate(parameter.chainingSize)(_ => RegInit(0.U(tokenWith.W)))
val crossWriteTokenMSB: Seq[UInt] = Seq.tabulate(parameter.chainingSize)(_ => RegInit(0.U(tokenWith.W)))

// Feedback is not accurate (index load/store may have already finished the instruction)
val responseIndexQueue =
Queue.io(UInt(parameter.instructionIndexBits.W), parameter.chainingSize + 1, flow = true)
responseIndexQueue.enq.valid := responseReport.valid
responseIndexQueue.enq.bits := responseReport.bits
responseIndexQueue.deq.ready := responseFeedbackReport.valid
val responseToken: Seq[UInt] = Seq.tabulate(2 * parameter.chainingSize)(_ => RegInit(0.U(tokenWith.W)))
val feedbackToken: Seq[UInt] = Seq.tabulate(2 * parameter.chainingSize)(_ => RegInit(0.U(tokenWith.W)))
val crossWriteTokenLSB: Seq[UInt] = Seq.tabulate(2 * parameter.chainingSize)(_ => RegInit(0.U(tokenWith.W)))
val crossWriteTokenMSB: Seq[UInt] = Seq.tabulate(2 * parameter.chainingSize)(_ => RegInit(0.U(tokenWith.W)))

// cross write update
val crossWriteDoEnq: UInt =
Expand Down Expand Up @@ -210,7 +203,7 @@ class SlotTokenManager(parameter: LaneParameter) extends Module {
}.reduce(_ | _)

// write pipe token
val writePipeToken: Seq[UInt] = Seq.tabulate(parameter.chainingSize)(_ => RegInit(0.U(tokenWith.W)))
val writePipeToken: Seq[UInt] = Seq.tabulate(2 * parameter.chainingSize)(_ => RegInit(0.U(tokenWith.W)))
val writePipeEnq: UInt =
maskAnd(writePipeEnqReport.valid, indexToOH(writePipeEnqReport.bits, parameter.chainingSize)).asUInt
val writePipeDeq: UInt =
Expand All @@ -219,8 +212,11 @@ class SlotTokenManager(parameter: LaneParameter) extends Module {
val instructionInWritePipe: UInt = tokenUpdate(writePipeToken, writePipeEnq, writePipeDeq)

// lsu & mask write token
val lsuWriteToken: Seq[UInt] = Seq.tabulate(parameter.chainingSize)(_ => RegInit(0.U(tokenWith.W)))
val maskWriteToken: Seq[UInt] = Seq.tabulate(parameter.chainingSize)(_ => RegInit(0.U(tokenWith.W)))
val lsuWriteToken: Seq[UInt] = Seq.tabulate(2 * parameter.chainingSize)(_ => RegInit(0.U(tokenWith.W)))
val maskWriteToken: Seq[UInt] = Seq.tabulate(2 * parameter.chainingSize)(_ => RegInit(0.U(tokenWith.W)))

val topWriteDoEnq: UInt =
maskAnd(topWriteEnq.valid, indexToOH(topWriteEnq.bits, parameter.chainingSize)).asUInt

val lsuWriteDoEnq: UInt =
maskAnd(topWriteEnq.valid && !fromMask, indexToOH(topWriteEnq.bits, parameter.chainingSize)).asUInt
Expand Down
38 changes: 9 additions & 29 deletions t1/src/lsu/LSU.scala
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class LSU(param: LSUParameter) extends Module {
)

@public
val dataInWriteQueue: Vec[UInt] = IO(Output(Vec(param.laneNumber, UInt(param.chainingSize.W))))
val dataInWriteQueue: Vec[UInt] = IO(Output(Vec(param.laneNumber, UInt((2 * param.chainingSize).W))))

/** the CSR interface from [[V]], CSR will be latched in MSHR. TODO: merge to [[LSURequest]]
*/
Expand All @@ -182,10 +182,7 @@ class LSU(param: LSUParameter) extends Module {

/** interface to [[V]], indicate a MSHR slots is finished, and corresponding instruction can commit. */
@public
val lastReport: UInt = IO(Output(UInt(param.chainingSize.W)))

@public
val lsuMaskGroupChange: UInt = IO(Output(UInt(param.chainingSize.W)))
val lastReport: UInt = IO(Output(UInt((2 * param.chainingSize).W)))

@public
val writeReadyForLsu: Bool = IO(Input(Bool()))
Expand Down Expand Up @@ -258,8 +255,6 @@ class LSU(param: LSUParameter) extends Module {

// write vrf
val otherTryToWrite: UInt = Mux(otherUnit.vrfWritePort.valid, otherUnit.status.targetLane, 0.U)
// Permission to enter the queue TODO: Investigate why this happens
val canEnterQueue: Vec[Bool] = Wire(Vec(param.laneNumber, Bool()))
// other 优先级更高
otherUnit.vrfWritePort.ready := (otherUnit.status.targetLane & VecInit(writeQueueVec.map(_.enq.ready)).asUInt).orR
writeQueueVec.zipWithIndex.foreach { case (write, index) =>
Expand Down Expand Up @@ -293,10 +288,10 @@ class LSU(param: LSUParameter) extends Module {
// The load unit becomes idle when it writes vrf for the last time.
maskAnd(
!loadUnit.status.idle || VecInit(loadUnit.vrfWritePort.map(_.valid)).asUInt.orR,
indexToOH(loadUnit.status.instructionIndex, 2 * param.chainingSize)
indexToOH(loadUnit.status.instructionIndex, param.chainingSize)
).asUInt |
maskAnd(!storeUnit.status.idle, indexToOH(storeUnit.status.instructionIndex, 2 * param.chainingSize)).asUInt |
maskAnd(!otherUnit.status.idle, indexToOH(otherUnit.status.instructionIndex, 2 * param.chainingSize)).asUInt
maskAnd(!storeUnit.status.idle, indexToOH(storeUnit.status.instructionIndex, param.chainingSize)).asUInt |
maskAnd(!otherUnit.status.idle, indexToOH(otherUnit.status.instructionIndex, param.chainingSize)).asUInt
}

vrfWritePort.zip(writeQueueVec).foreach { case (p, q) =>
Expand All @@ -308,18 +303,18 @@ class LSU(param: LSUParameter) extends Module {
val dataInMSHR: UInt =
Mux(
loadUnit.status.idle,
0.U(param.chainingSize.W),
0.U((2 * param.chainingSize).W),
indexToOH(loadUnit.status.instructionIndex, param.chainingSize)
) |
Mux(
otherUnit.status.idle || otherUnit.status.isStore,
0.U(param.chainingSize.W),
0.U((2 * param.chainingSize).W),
indexToOH(otherUnit.status.instructionIndex, param.chainingSize)
)

// Record whether there is data for the corresponding instruction in the queue
writeQueueVec.zip(dataInWriteQueue).zipWithIndex.foreach { case ((q, p), queueIndex) =>
val queueCount: Seq[UInt] = Seq.tabulate(param.chainingSize) { _ =>
writeQueueVec.zip(dataInWriteQueue).foreach { case (q, p) =>
val queueCount: Seq[UInt] = Seq.tabulate(2 * param.chainingSize) { _ =>
RegInit(0.U(log2Ceil(param.toVRFWriteQueueSize).W))
}
val enqOH: UInt = indexToOH(q.enq.bits.data.instructionIndex, param.chainingSize)
Expand All @@ -332,18 +327,6 @@ class LSU(param: LSUParameter) extends Module {
}
}
p := VecInit(queueCount.map(_ =/= 0.U)).asUInt | dataInMSHR
val dataTag = VecInit(Seq.tabulate(param.chainingSize) { _ =>
RegInit(false.B)
})
val nextTag = q.enq.bits.data.instructionIndex.asBools.last
val currentTag = (dataTag.asUInt & enqOH).orR
// same tage or nothing in queue
canEnterQueue(queueIndex) := (nextTag === currentTag) || !p
dataTag.zipWithIndex.foreach { case (d, i) =>
when(q.deq.fire && enqOH(i)) {
d := nextTag
}
}
}

val sourceQueue = Queue.io(UInt(param.mshrParam.sourceWidth.W), param.sourceQueueSize)
Expand Down Expand Up @@ -437,9 +420,6 @@ class LSU(param: LSUParameter) extends Module {
// gather last signal from all MSHR to notify LSU
lastReport :=
unitVec.map(m => Mux(m.status.last, indexToOH(m.status.instructionIndex, param.chainingSize), 0.U)).reduce(_ | _)
lsuMaskGroupChange := unitVec
.map(m => Mux(m.status.changeMaskGroup, indexToOH(m.status.instructionIndex, param.chainingSize), 0.U))
.reduce(_ | _)
tokenIO.offsetGroupRelease := otherUnit.offsetRelease.asUInt
loadUnit.writeReadyForLsu := writeReadyForLsu
storeUnit.vrfReadyToStore := vrfReadyToStore
Expand Down
2 changes: 1 addition & 1 deletion t1/src/mask/MaskUnit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class MaskUnit(parameter: T1Parameter) extends Module {
val writeRD: ValidIO[UInt] = IO(Valid(UInt(parameter.datapathWidth.W)))

@public
val lastReport: UInt = IO(Output(UInt(parameter.chainingSize.W)))
val lastReport: UInt = IO(Output(UInt((2 * parameter.chainingSize).W)))

// mask
@public
Expand Down
2 changes: 1 addition & 1 deletion t1/src/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ package object rtl {
}

def indexToOH(index: UInt, chainingSize: Int): UInt = {
UIntToOH(index(log2Ceil(chainingSize) - 1, 0))
UIntToOH(index(log2Ceil(chainingSize), 0))
}

def ohCheck(lastReport: UInt, index: UInt, chainingSize: Int): Bool = {
Expand Down
6 changes: 3 additions & 3 deletions t1/src/sequencer/T1TokenManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class T1TokenManager(parameter: T1Parameter) extends Module {
val issueAllow: Bool = IO(Output(Bool()))

@public
val instructionFinish: Vec[UInt] = IO(Vec(parameter.laneNumber, Input(UInt(parameter.chainingSize.W))))
val instructionFinish: Vec[UInt] = IO(Vec(parameter.laneNumber, Input(UInt((2 * parameter.chainingSize).W))))

@public
val v0WriteValid = IO(Output(UInt(parameter.chainingSize.W)))
val v0WriteValid = IO(Output(UInt((2 * parameter.chainingSize).W)))

@public
val maskUnitFree: Bool = IO(Input(Bool()))
Expand All @@ -42,7 +42,7 @@ class T1TokenManager(parameter: T1Parameter) extends Module {

// Boolean type token clear & set
def updateBooleanToken(set: UInt, clear: UInt): UInt = {
VecInit(Seq.tabulate(parameter.chainingSize) { chainingIndex =>
VecInit(Seq.tabulate(2 * parameter.chainingSize) { chainingIndex =>
val res = RegInit(false.B)
when(set(chainingIndex) || clear(chainingIndex)) {
res := set(chainingIndex)
Expand Down
10 changes: 4 additions & 6 deletions t1/src/vrf/VRF.scala
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,14 @@ class VRF(val parameter: VRFParam) extends Module with SerializableModule[VRFPar

/** similar to [[flush]]. */
@public
val instructionLastReport: UInt = IO(Input(UInt(parameter.chainingSize.W)))
val instructionLastReport: UInt = IO(Input(UInt((2 * parameter.chainingSize).W)))

@public
val lsuLastReport: UInt = IO(Input(UInt(parameter.chainingSize.W)))
val lsuLastReport: UInt = IO(Input(UInt((2 * parameter.chainingSize).W)))

@public
val dataInLane: UInt = IO(Input(UInt(parameter.chainingSize.W)))
val dataInLane: UInt = IO(Input(UInt((2 * parameter.chainingSize).W)))

@public
val lsuMaskGroupChange: UInt = IO(Input(UInt(parameter.chainingSize.W)))
@public
val writeReadyForLsu: Bool = IO(Output(Bool()))
@public
Expand All @@ -242,7 +240,7 @@ class VRF(val parameter: VRFParam) extends Module with SerializableModule[VRFPar

/** we can only chain LSU instructions, after [[LSU.writeQueueVec]] is cleared. */
@public
val loadDataInLSUWriteQueue: UInt = IO(Input(UInt(parameter.chainingSize.W)))
val loadDataInLSUWriteQueue: UInt = IO(Input(UInt((2 * parameter.chainingSize).W)))

@public
val vrfProbe = IO(Output(Probe(new VRFProbe(parameter), layers.Verification)))
Expand Down

0 comments on commit f41390a

Please sign in to comment.