-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
779 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2022 Jiuyang Liu <liu@jiuyang.me> | ||
|
||
package org.chipsalliance.t1.rtl | ||
|
||
import chisel3._ | ||
import chisel3.util._ | ||
|
||
class CompressInput(parameter: T1Parameter) extends Bundle { | ||
val vm: Bool = Bool() | ||
val eew: UInt = UInt(2.W) | ||
val uop: UInt = UInt(3.W) | ||
val readFromScalar: UInt = UInt(parameter.datapathWidth.W) | ||
val source1: UInt = UInt((parameter.laneNumber * parameter.datapathWidth).W) | ||
val source2: UInt = UInt((parameter.laneNumber * parameter.datapathWidth).W) | ||
val groupCounter: UInt = UInt(parameter.laneParam.groupNumberBits.W) | ||
val lastCompress: Bool = Bool() | ||
} | ||
|
||
class CompressOutput(parameter: T1Parameter) extends Bundle { | ||
val data: UInt = UInt((parameter.laneNumber * parameter.datapathWidth).W) | ||
val mask: UInt = UInt((parameter.laneNumber * parameter.datapathWidth / 8).W) | ||
val compressValid: Bool = Bool() | ||
} | ||
|
||
class MaskCompress(parameter: T1Parameter) extends Module { | ||
val in: CompressInput = IO(Input(new CompressInput(parameter))) | ||
val out: CompressOutput = IO(Input(new CompressOutput(parameter))) | ||
val newInstruction: Bool = IO(Input(Bool())) | ||
|
||
val maskSize: Int = parameter.laneNumber * parameter.datapathWidth / 8 | ||
|
||
// Source1 alignment | ||
val source1Aligned: UInt = Wire(UInt(maskSize.W)) | ||
// TODO: Align and align in advance | ||
source1Aligned := in.source1 | ||
val compress = in.uop === "b001".U | ||
val viota = in.uop === "b000".U | ||
val mv = in.uop === "b101".U | ||
|
||
val eew1H: UInt = UIntToOH(in.eew)(2, 0) | ||
val compressInit: UInt = RegInit(0.U(log2Ceil(parameter.vLen).W)) | ||
val compressVec: Vec[UInt] = Wire(Vec(maskSize, UInt(compressInit.getWidth.W))) | ||
val compressMaskVec: Seq[Bool] = source1Aligned.asBools | ||
val compressCount: UInt = compressMaskVec.zipWithIndex.foldLeft(compressInit) { | ||
case (pre, (mask, index)) => | ||
compressVec(index) := pre | ||
pre + mask | ||
} | ||
// todo: compress update | ||
compressInit := Mux(newInstruction, 0.U, compressCount) | ||
|
||
val viotaResult: UInt = Mux1H(eew1H, | ||
Seq(1, 2, 4).map { eew => | ||
VecInit(Seq.tabulate(parameter.laneNumber) { index => | ||
// data width: eew * 8, data path 32, need [4 / eew] element | ||
val dataSize = 4 / eew | ||
val res: Seq[UInt] = Seq.tabulate(dataSize) { i => | ||
compressVec(dataSize * index + i)(eew * 8 - 1, 0) | ||
} | ||
// each data path | ||
VecInit(res).asUInt | ||
}).asUInt | ||
} | ||
) | ||
val viotaMask: UInt = Mux1H(eew1H, | ||
Seq(1, 2, 4).map { eew => | ||
VecInit(Seq.tabulate(parameter.laneNumber) { index => | ||
val dataSize = 4 / eew | ||
val res: Seq[UInt] = Seq.tabulate(dataSize) { i => | ||
Fill(eew, compressMaskVec(dataSize * index + i)) | ||
} | ||
// 4 bit mask | ||
VecInit(res).asUInt | ||
}).asUInt | ||
} | ||
) | ||
|
||
val tailCount = compressInit | ||
val compressDataReg = RegInit(0.U((parameter.laneNumber * parameter.datapathWidth).W)) | ||
val compressDataVec = Seq(1, 2, 4).map { eew => | ||
VecInit(Seq.tabulate(parameter.laneNumber * 2) { index => | ||
val useTail = index.U < tailCount | ||
val tailData = cutUInt(compressDataReg, eew)(index) | ||
val maskSize = 4 * parameter.laneNumber / eew | ||
val hitReq = Seq.tabulate(maskSize)( maskIndex => compressVec(maskIndex) === index.U ) | ||
val selectReqData = Mux1H( | ||
hitReq, | ||
cutUInt(in.source2, eew) | ||
) | ||
Mux(useTail, tailData, selectReqData) | ||
}).asUInt | ||
} | ||
val compressResult: UInt = Mux1H(eew1H, compressDataVec) | ||
|
||
// todo: connect & update compressInit | ||
val compressTailMask = Wire(UInt(out.mask.getWidth.W)) | ||
val compressTailValid = Wire(Bool()) | ||
|
||
val mvMask = Mux1H(eew1H, Seq(1.U, 3.U, 15.U)) | ||
val mvData = Mux1H( | ||
eew1H, | ||
Seq( | ||
in.readFromScalar(7, 0), | ||
in.readFromScalar(15, 0), | ||
in.readFromScalar | ||
) | ||
) | ||
|
||
out.mask := Mux1H(Seq( | ||
compress -> compressResult, | ||
viota -> viotaResult, | ||
mv -> mvData, | ||
)) | ||
|
||
// todo: compressMask | ||
out.mask := Mux1H(Seq( | ||
compress -> compressTailMask, | ||
viota -> viotaMask, | ||
mv -> mvMask, | ||
)) | ||
|
||
// todo | ||
out.compressValid := false.B | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2022 Jiuyang Liu <liu@jiuyang.me> | ||
|
||
package org.chipsalliance.t1.rtl | ||
|
||
import chisel3._ | ||
import chisel3.util._ | ||
|
||
class ExtendInput(parameter: T1Parameter) extends Bundle { | ||
val eew: UInt = UInt(2.W) | ||
val uop: UInt = UInt(3.W) | ||
val source2: UInt = UInt((parameter.laneNumber * parameter.datapathWidth).W) | ||
val groupCounter: UInt = UInt(parameter.laneParam.groupNumberBits.W) | ||
} | ||
|
||
class MaskExtend(parameter: T1Parameter) extends Module { | ||
val in: ExtendInput = IO(Input(new ExtendInput(parameter))) | ||
val out: UInt = IO(Output(UInt(parameter.datapathWidth.W))) | ||
|
||
val eew1H: UInt = UIntToOH(in.eew)(2, 0) | ||
|
||
val isMaskDestination: Bool = in.uop.andR | ||
val maskDestinationResult: UInt = Mux1H( | ||
eew1H, | ||
Seq(4, 2, 1).map { groupSize => | ||
VecInit(cutUInt(in.source2, groupSize). | ||
grouped(parameter.laneNumber).toSeq. | ||
transpose.map(a => VecInit(a).asUInt)).asUInt | ||
} | ||
) | ||
|
||
// extend | ||
val sign: Bool = in.uop(0) | ||
// extend ratio | ||
// todo: Currently only vf2 and vf4 | ||
val extendRatio: Bool = in.uop(1) | ||
|
||
// select source2 | ||
// extendRatio: 0 -> vf2; 1-> vf4 | ||
val source2: UInt = Mux( | ||
extendRatio, | ||
Mux1H( | ||
UIntToOH(in.groupCounter(1, 0)), | ||
cutUInt(in.source2, parameter.laneNumber * parameter.datapathWidth / 4) | ||
), | ||
Mux1H( | ||
UIntToOH(in.groupCounter(0)), | ||
cutUInt(in.source2, parameter.laneNumber * parameter.datapathWidth / 2) | ||
) | ||
) | ||
|
||
val extendResult: UInt = Mux1H(eew1H(2, 1), Seq(2, 4).map{ dataWidth => | ||
Mux1H(UIntToOH(extendRatio), Seq(2, 4).map { ratio => | ||
val resWidth = dataWidth * 8 | ||
val sourceWidth = resWidth / ratio | ||
VecInit(cutUInt(source2, sourceWidth).map { sourceData => | ||
Fill(resWidth - sourceWidth, sourceData(sourceWidth - 1) && sign) ## sourceData | ||
}).asUInt | ||
}) | ||
}) | ||
|
||
out := Mux(isMaskDestination, maskDestinationResult, extendResult) | ||
} |
Oops, something went wrong.