xref: /XiangShan/src/main/scala/xiangshan/mem/vector/VecBundle.scala (revision 9e12e8edb26ee7dce62315a8f279ea9f61aa239d)
13952421bSweiding liu/***************************************************************************************
23952421bSweiding liu  * Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences
33952421bSweiding liu  * Copyright (c) 2020-2021 Peng Cheng Laboratory
43952421bSweiding liu  *
53952421bSweiding liu  * XiangShan is licensed under Mulan PSL v2.
63952421bSweiding liu  * You can use this software according to the terms and conditions of the Mulan PSL v2.
73952421bSweiding liu  * You may obtain a copy of Mulan PSL v2 at:
83952421bSweiding liu  *          http://license.coscl.org.cn/MulanPSL2
93952421bSweiding liu  *
103952421bSweiding liu  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
113952421bSweiding liu  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
123952421bSweiding liu  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
133952421bSweiding liu  *
143952421bSweiding liu  * See the Mulan PSL v2 for more details.
153952421bSweiding liu  ***************************************************************************************/
163952421bSweiding liu
173952421bSweiding liupackage xiangshan.mem
183952421bSweiding liu
193952421bSweiding liuimport org.chipsalliance.cde.config.Parameters
203952421bSweiding liuimport chisel3._
213952421bSweiding liuimport chisel3.util._
223952421bSweiding liuimport utils._
233952421bSweiding liuimport utility._
243952421bSweiding liuimport xiangshan._
253952421bSweiding liuimport xiangshan.backend.Bundles._
26726c5ee8SAnzoooooimport xiangshan.backend.fu.NewCSR.CsrTriggerBundle
273952421bSweiding liuimport xiangshan.backend.rob.RobPtr
2888884326Sweiding liuimport xiangshan.backend.fu.PMPRespBundle
29df3b4b92SAnzoooooimport xiangshan.backend.fu.vector.Bundles._
30*9e12e8edScz4eimport xiangshan.mem.Bundles._
3188884326Sweiding liuimport xiangshan.cache.mmu.{TlbCmd, TlbRequestIO}
3288884326Sweiding liuimport xiangshan.cache._
333952421bSweiding liu
3426af847eSgood-circleclass VLSBundle(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle {
353952421bSweiding liu  val flowMask            = UInt(VLENB.W) // each bit for a flow
363952421bSweiding liu  val byteMask            = UInt(VLENB.W) // each bit for a byte
373952421bSweiding liu  val data                = UInt(VLEN.W)
383952421bSweiding liu  // val fof            = Bool() // fof is only used for vector loads
393952421bSweiding liu  val excp_eew_index      = UInt(elemIdxBits.W)
403952421bSweiding liu  // val exceptionVec   = ExceptionVec() // uop has exceptionVec
41db6cfb5aSHaoyuan Feng  val baseAddr            = UInt(XLEN.W)
4216c2d8bbSAnzo  val uopAddr             = UInt(XLEN.W)
433952421bSweiding liu  val stride              = UInt(VLEN.W)
443952421bSweiding liu  // val flow_counter = UInt(flowIdxBits.W)
453952421bSweiding liu
463952421bSweiding liu  // instruction decode result
473952421bSweiding liu  val flowNum             = UInt(flowIdxBits.W) // # of flows in a uop
483952421bSweiding liu  // val flowNumLog2 = UInt(log2Up(flowIdxBits).W) // log2(flowNum), for better timing of multiplication
493952421bSweiding liu  val nfields             = UInt(fieldBits.W) // NFIELDS
503952421bSweiding liu  val vm                  = Bool() // whether vector masking is enabled
513952421bSweiding liu  val usWholeReg          = Bool() // unit-stride, whole register load
523952421bSweiding liu  val usMaskReg           = Bool() // unit-stride, masked store/load
53d73f3705SAnzo  val eew                 = VEew() // size of memory elements
543952421bSweiding liu  val sew                 = UInt(ewBits.W)
553952421bSweiding liu  val emul                = UInt(mulBits.W)
563952421bSweiding liu  val lmul                = UInt(mulBits.W)
573952421bSweiding liu  val vlmax               = UInt(elemIdxBits.W)
583952421bSweiding liu  val instType            = UInt(3.W)
593952421bSweiding liu  val vd_last_uop         = Bool()
603952421bSweiding liu  val vd_first_uop        = Bool()
6102ab9019SAnzooooo
62df3b4b92SAnzooooo  // Because the back-end needs to handle exceptions, it is necessary to retain the original NF.
63df3b4b92SAnzooooo  // So we choose to pass the original value in the pipeline and override it when out.
64df3b4b92SAnzooooo  val rawNf                = Nf()
6502ab9019SAnzooooo  val indexedSrcMask     = UInt(VLENB.W)
6602ab9019SAnzooooo  val indexedSplitOffset  = UInt(flowIdxBits.W)
673952421bSweiding liu  // Inst's uop
683952421bSweiding liu  val uop                 = new DynInst
693952421bSweiding liu
703952421bSweiding liu  val fof                 = Bool()
713952421bSweiding liu  val vdIdxInField        = UInt(log2Up(maxMUL).W)
723952421bSweiding liu  val uopOffset           = UInt(VLEN.W)
733952421bSweiding liu  val preIsSplit          = Bool() // if uop need split, only not Unit-Stride or not 128bit-aligned unit stride need split
7426af847eSgood-circle  val mBIndex             = if(isVStore) UInt(vsmBindexBits.W) else UInt(vlmBindexBits.W)
753952421bSweiding liu
763952421bSweiding liu  val alignedType         = UInt(alignTypeBits.W)
7781b02df5Sweiding liu  val indexVlMaxInVd      = UInt(elemIdxBits.W)
783771bdd2Sweiding liu
793771bdd2Sweiding liu  val usLowBitsAddr       = UInt((log2Up(maxMemByteNum)).W)
803771bdd2Sweiding liu  val usAligned128        = Bool()
81c8d442a6Sweiding liu  val usMask              = UInt((VLENB*2).W) // for unit-stride split
823952421bSweiding liu}
833952421bSweiding liu
843952421bSweiding liuobject VSFQFeedbackType {
853952421bSweiding liu  val tlbMiss = 0.U(3.W)
863952421bSweiding liu  val mshrFull = 1.U(3.W)
873952421bSweiding liu  val dataInvalid = 2.U(3.W)
883952421bSweiding liu  val bankConflict = 3.U(3.W)
893952421bSweiding liu  val ldVioCheckRedo = 4.U(3.W)
903952421bSweiding liu  val feedbackInvalid = 7.U(3.W)
913952421bSweiding liu
923952421bSweiding liu  def apply() = UInt(3.W)
933952421bSweiding liu}
943952421bSweiding liu
953952421bSweiding liuclass VSFQFeedback (implicit p: Parameters) extends XSBundle {
963952421bSweiding liu  // val flowPtr = new VsFlowPtr
973952421bSweiding liu  val hit   = Bool()
983952421bSweiding liu  //val flushState = Bool()
993952421bSweiding liu  val sourceType = VSFQFeedbackType()
1003952421bSweiding liu  //val dataInvalidSqIdx = new SqPtr
1013952421bSweiding liu  val paddr = UInt(PAddrBits.W)
1023952421bSweiding liu  val mmio = Bool()
1033952421bSweiding liu  val atomic = Bool()
1043952421bSweiding liu  val exceptionVec = ExceptionVec()
1053952421bSweiding liu}
1063952421bSweiding liu
1073952421bSweiding liuclass VecPipelineFeedbackIO(isVStore: Boolean=false) (implicit p: Parameters) extends VLSUBundle {
10826af847eSgood-circle  val mBIndex              = if(isVStore) UInt(vsmBindexBits.W) else UInt(vlmBindexBits.W)
1093952421bSweiding liu  val hit                  = Bool()
1103952421bSweiding liu  val isvec                = Bool()
111ebb914e7Sweiding liu  val flushState           = Bool()
1123952421bSweiding liu  val sourceType           = VSFQFeedbackType()
113506ca2a3SAnzooooo  val trigger              = TriggerAction()
1143952421bSweiding liu  //val dataInvalidSqIdx = new SqPtr
11526af847eSgood-circle  //val paddr                = UInt(PAddrBits.W)
116780e55f4SYanqin Li  val nc                   = Bool()
1173952421bSweiding liu  val mmio                 = Bool()
11826af847eSgood-circle  //val atomic               = Bool()
1193952421bSweiding liu  val exceptionVec         = ExceptionVec()
120da51a7acSAnzo  val hasException         = Bool() // Active
121db6cfb5aSHaoyuan Feng  val vaddr                = UInt(XLEN.W)
12246e9ee74SHaoyuan Feng  val vaNeedExt            = Bool()
123db6cfb5aSHaoyuan Feng  val gpaddr               = UInt(XLEN.W)
124ad415ae0SXiaokun-Pei  val isForVSnonLeafPTE    = Bool()
12541c5202dSAnzooooo  val vstart               = UInt(elemIdxBits.W)
126d0d2c22dSAnzooooo  val vecTriggerMask       = UInt((VLEN/8).W)
127d0d2c22dSAnzooooo
12826af847eSgood-circle  //val vec                  = new OnlyVecExuOutput
129b7618691Sweiding liu   // feedback
130b7618691Sweiding liu  val vecFeedback          = Bool()
1313952421bSweiding liu
1323952421bSweiding liu  val usSecondInv          = Bool() // only for unit stride, second flow is Invalid
13355178b77Sweiding liu  val elemIdx              = UInt(elemIdxBits.W) // element index
13455178b77Sweiding liu  val mask                 = UInt(VLENB.W)
13555178b77Sweiding liu  val alignedType          = UInt(alignTypeBits.W)
1363952421bSweiding liu  // for load
1373952421bSweiding liu  val reg_offset           = OptionWrapper(!isVStore, UInt(vOffsetBits.W))
1383952421bSweiding liu  val elemIdxInsideVd      = OptionWrapper(!isVStore, UInt(elemIdxBits.W)) // element index in scope of vd
1393952421bSweiding liu  val vecdata              = OptionWrapper(!isVStore, UInt(VLEN.W))
1403952421bSweiding liu}
1413952421bSweiding liu
14226af847eSgood-circleclass VecPipeBundle(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle {
143db6cfb5aSHaoyuan Feng  val vaddr               = UInt(XLEN.W)
144c0355297SAnzooooo  val basevaddr           = UInt(VAddrBits.W)
1453952421bSweiding liu  val mask                = UInt(VLENB.W)
1463952421bSweiding liu  val isvec               = Bool()
1473952421bSweiding liu  val uop_unit_stride_fof = Bool()
1483952421bSweiding liu  val reg_offset          = UInt(vOffsetBits.W)
1493952421bSweiding liu  val alignedType         = UInt(alignTypeBits.W)
1503952421bSweiding liu  val vecActive           = Bool() // 1: vector active element, 0: vector not active element
1513952421bSweiding liu  val is_first_ele        = Bool()
1523952421bSweiding liu  val isFirstIssue        = Bool()
1533952421bSweiding liu
1543952421bSweiding liu  val uop = new DynInst
1553952421bSweiding liu
1563952421bSweiding liu  val usSecondInv         = Bool() // only for unit stride, second flow is Invalid
15726af847eSgood-circle  val mBIndex             = if(isVStore) UInt(vsmBindexBits.W) else UInt(vlmBindexBits.W)
1583952421bSweiding liu  val elemIdx             = UInt(elemIdxBits.W)
15955178b77Sweiding liu  val elemIdxInsideVd     = UInt(elemIdxBits.W) // only use in unit-stride
1603952421bSweiding liu}
1613952421bSweiding liu
1623952421bSweiding liuobject VecFeedbacks {
1633952421bSweiding liu  // need to invalid lsq entry
1643952421bSweiding liu  val FLUSH  = 0
1653952421bSweiding liu  // merge buffer commits one uop
1663952421bSweiding liu  val COMMIT  = 1
1673952421bSweiding liu  // last uop of an inst, sq can commit
1683952421bSweiding liu  val LAST = 2
1693952421bSweiding liu  // total feedbacks
1703952421bSweiding liu  val allFeedbacks = 3
1713952421bSweiding liu}
1723952421bSweiding liu
17326af847eSgood-circleclass MergeBufferReq(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
1743952421bSweiding liu  val mask                = UInt(VLENB.W)
1753952421bSweiding liu  val vaddr               = UInt(VAddrBits.W)
1763952421bSweiding liu  val flowNum             = UInt(flowIdxBits.W)
1773952421bSweiding liu  val uop                 = new DynInst
1783952421bSweiding liu  val data                = UInt(VLEN.W)
1792e1c1560Sweiding liu  val vdIdx               = UInt(3.W)
18055178b77Sweiding liu  val fof                 = Bool()
18155178b77Sweiding liu  val vlmax               = UInt(elemIdxBits.W)
1823952421bSweiding liu  // val vdOffset            = UInt(vdOffset.W)
1833952421bSweiding liu}
1843952421bSweiding liu
18526af847eSgood-circleclass MergeBufferResp(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
18626af847eSgood-circle  val mBIndex             = if(isVStore) UInt(vsmBindexBits.W) else UInt(vlmBindexBits.W)
1873952421bSweiding liu  val fail                = Bool()
1883952421bSweiding liu}
1893952421bSweiding liu
19026af847eSgood-circleclass ToMergeBufferIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
19126af847eSgood-circle  val req                 = DecoupledIO(new MergeBufferReq(isVStore))
19226af847eSgood-circle  val resp                = Flipped(ValidIO(new MergeBufferResp(isVStore)))
1933952421bSweiding liu}
1943952421bSweiding liu
19526af847eSgood-circleclass FromSplitIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
19626af847eSgood-circle  val req                 = Flipped(DecoupledIO(new MergeBufferReq(isVStore)))
19726af847eSgood-circle  val resp                = ValidIO(new MergeBufferResp(isVStore))
1983952421bSweiding liu  // val issueInactive       = Flipped(ValidIO())
1993952421bSweiding liu}
2003952421bSweiding liu
2013952421bSweiding liuclass FeedbackToSplitIO(implicit p: Parameters) extends VLSUBundle{
2022d8a0b4aSAnzo  val threshold            = Bool()
2033952421bSweiding liu}
2043952421bSweiding liu
2053952421bSweiding liuclass FeedbackToLsqIO(implicit p: Parameters) extends VLSUBundle{
2063952421bSweiding liu  val robidx = new RobPtr
2073952421bSweiding liu  val uopidx = UopIdx()
208db6cfb5aSHaoyuan Feng  val vaddr = UInt(XLEN.W)
20946e9ee74SHaoyuan Feng  val vaNeedExt = Bool()
210a53daa0fSHaoyuan Feng  val gpaddr = UInt(GPAddrBits.W)
211ad415ae0SXiaokun-Pei  val isForVSnonLeafPTE = Bool()
2123952421bSweiding liu  val feedback = Vec(VecFeedbacks.allFeedbacks, Bool())
21355178b77Sweiding liu    // for exception
21455178b77Sweiding liu  val vstart           = UInt(elemIdxBits.W)
21555178b77Sweiding liu  val vl               = UInt(elemIdxBits.W)
2165dc0f712SAnzooooo  val exceptionVec     = ExceptionVec()
2173952421bSweiding liu
2183952421bSweiding liu  def isFlush  = feedback(VecFeedbacks.FLUSH)
2193952421bSweiding liu  def isCommit = feedback(VecFeedbacks.COMMIT)
2203952421bSweiding liu  def isLast = feedback(VecFeedbacks.LAST)
2213952421bSweiding liu}
2223952421bSweiding liu
223b240e1c0SAnzoooooclass storeMisaignIO(implicit p: Parameters) extends Bundle{
224b240e1c0SAnzooooo  val storePipeEmpty           = Input(Bool())
225b240e1c0SAnzooooo  val storeMisalignBufferEmpty = Input(Bool())
226b240e1c0SAnzooooo}
227b240e1c0SAnzooooo
2283952421bSweiding liuclass VSplitIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
2293952421bSweiding liu  val redirect            = Flipped(ValidIO(new Redirect))
23088884326Sweiding liu  val in                  = Flipped(Decoupled(new MemExuInput(isVector = true))) // from iq
23126af847eSgood-circle  val toMergeBuffer       = new ToMergeBufferIO(isVStore) //to merge buffer req mergebuffer entry
23226af847eSgood-circle  val out                 = Decoupled(new VecPipeBundle(isVStore))// to scala pipeline
23326af847eSgood-circle  val vstd                = OptionWrapper(isVStore, Valid(new MemExuOutput(isVector = true)))
234b240e1c0SAnzooooo  val vstdMisalign        = OptionWrapper(isVStore, new storeMisaignIO)
2352d8a0b4aSAnzo  val threshold            = OptionWrapper(!isVStore, Flipped(ValidIO(new LqPtr)))
2363952421bSweiding liu}
2373952421bSweiding liu
23826af847eSgood-circleclass VSplitPipelineIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
2393952421bSweiding liu  val redirect            = Flipped(ValidIO(new Redirect))
2403952421bSweiding liu  val in                  = Flipped(Decoupled(new MemExuInput(isVector = true)))
24126af847eSgood-circle  val toMergeBuffer       = new ToMergeBufferIO(isVStore) // req mergebuffer entry, inactive elem issue
2423952421bSweiding liu  val out                 = Decoupled(new VLSBundle())// to split buffer
2433952421bSweiding liu}
2443952421bSweiding liu
2453952421bSweiding liuclass VSplitBufferIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
2463952421bSweiding liu  val redirect            = Flipped(ValidIO(new Redirect))
2473952421bSweiding liu  val in                  = Flipped(Decoupled(new VLSBundle()))
24826af847eSgood-circle  val out                 = Decoupled(new VecPipeBundle(isVStore))//to scala pipeline
24926af847eSgood-circle  val vstd                = OptionWrapper(isVStore, ValidIO(new MemExuOutput(isVector = true)))
250b240e1c0SAnzooooo  val vstdMisalign        = OptionWrapper(isVStore, new storeMisaignIO)
2513952421bSweiding liu}
2523952421bSweiding liu
2533952421bSweiding liuclass VMergeBufferIO(isVStore : Boolean=false)(implicit p: Parameters) extends VLSUBundle{
2543952421bSweiding liu  val redirect            = Flipped(ValidIO(new Redirect))
2555f52d26fSweiding liu  val fromPipeline        = if(isVStore) Vec(StorePipelineWidth, Flipped(DecoupledIO(new VecPipelineFeedbackIO(isVStore)))) else Vec(LoadPipelineWidth, Flipped(DecoupledIO(new VecPipelineFeedbackIO(isVStore))))
256b7618691Sweiding liu  val fromSplit           = if(isVStore) Vec(VecStorePipelineWidth, new FromSplitIO) else Vec(VecLoadPipelineWidth, new FromSplitIO) // req mergebuffer entry, inactive elem issue
25771f042adSAnzooooo  val uopWriteback        = if(isVStore) Vec(VSUopWritebackWidth, DecoupledIO(new MemExuOutput(isVector = true))) else Vec(VLUopWritebackWidth, DecoupledIO(new MemExuOutput(isVector = true)))
2582d8a0b4aSAnzo  val toSplit             = OptionWrapper(!isVStore, new FeedbackToSplitIO())
25971f042adSAnzooooo  val toLsq               = if(isVStore) Vec(VSUopWritebackWidth, ValidIO(new FeedbackToLsqIO)) else Vec(VLUopWritebackWidth, ValidIO(new FeedbackToLsqIO)) // for lsq deq
26071f042adSAnzooooo  val feedback            = if(isVStore) Vec(VSUopWritebackWidth, ValidIO(new RSFeedback(isVector = true))) else Vec(VLUopWritebackWidth, ValidIO(new RSFeedback(isVector = true)))//for rs replay
261b240e1c0SAnzooooo
262b240e1c0SAnzooooo  val fromMisalignBuffer  = OptionWrapper(isVStore, Flipped(new StoreMaBufToVecStoreMergeBufferIO))
2633952421bSweiding liu}
26488884326Sweiding liu
26588884326Sweiding liuclass VSegmentUnitIO(implicit p: Parameters) extends VLSUBundle{
26688884326Sweiding liu  val in                  = Flipped(Decoupled(new MemExuInput(isVector = true))) // from iq
26788884326Sweiding liu  val uopwriteback        = DecoupledIO(new MemExuOutput(isVector = true)) // writeback data
268fe518d28Sweiding liu  val rdcache             = new DCacheLoadIO // read dcache port
269fe518d28Sweiding liu  val sbuffer             = Decoupled(new DCacheWordReqWithVaddrAndPfFlag)
2706edb1480SAnzooooo  val vecDifftestInfo     = Decoupled(new DynInst) // to sbuffer
27188884326Sweiding liu  val dtlb                = new TlbRequestIO(2)
27288884326Sweiding liu  val pmpResp             = Flipped(new PMPRespBundle())
27388884326Sweiding liu  val flush_sbuffer       = new SbufferFlushBundle
27488884326Sweiding liu  val feedback            = ValidIO(new RSFeedback(isVector = true))
27588884326Sweiding liu  val redirect            = Flipped(ValidIO(new Redirect))
276c41a9f78Slwd  val exceptionInfo       = ValidIO(new FeedbackToLsqIO)
277726c5ee8SAnzooooo  //trigger
278726c5ee8SAnzooooo  val fromCsrTrigger      = Input(new CsrTriggerBundle)
27988884326Sweiding liu}
280df3b4b92SAnzooooo
281df3b4b92SAnzoooooclass VfofDataBuffIO(implicit p: Parameters) extends VLSUBundle{
282df3b4b92SAnzooooo  val redirect            = Flipped(ValidIO(new Redirect))
283df3b4b92SAnzooooo  val in                  = Vec(VecLoadPipelineWidth, Flipped(Decoupled(new MemExuInput(isVector=true))))
284df3b4b92SAnzooooo  val mergeUopWriteback   = Vec(VLUopWritebackWidth, Flipped(DecoupledIO(new MemExuOutput(isVector=true))))
285df3b4b92SAnzooooo
286df3b4b92SAnzooooo  val uopWriteback        = DecoupledIO(new MemExuOutput(isVector = true))
287df3b4b92SAnzooooo}
288