xref: /XiangShan/src/main/scala/xiangshan/mem/vector/VecBundle.scala (revision b0480352c0e4f9e58fed6ca0cead80a684089673)
1/***************************************************************************************
2  * Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences
3  * Copyright (c) 2020-2021 Peng Cheng Laboratory
4  *
5  * XiangShan is licensed under Mulan PSL v2.
6  * You can use this software according to the terms and conditions of the Mulan PSL v2.
7  * You may obtain a copy of Mulan PSL v2 at:
8  *          http://license.coscl.org.cn/MulanPSL2
9  *
10  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13  *
14  * See the Mulan PSL v2 for more details.
15  ***************************************************************************************/
16
17package xiangshan.mem
18
19import org.chipsalliance.cde.config.Parameters
20import chisel3._
21import chisel3.util._
22import utils._
23import utility._
24import xiangshan._
25import xiangshan.backend.Bundles._
26import xiangshan.backend.fu.NewCSR.CsrTriggerBundle
27import xiangshan.backend.rob.RobPtr
28import xiangshan.backend.fu.PMPRespBundle
29import xiangshan.backend.fu.vector.Bundles.VEew
30import xiangshan.cache.mmu.{TlbCmd, TlbRequestIO}
31import xiangshan.cache._
32
33class VLSBundle(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle {
34  val flowMask            = UInt(VLENB.W) // each bit for a flow
35  val byteMask            = UInt(VLENB.W) // each bit for a byte
36  val data                = UInt(VLEN.W)
37  // val fof            = Bool() // fof is only used for vector loads
38  val excp_eew_index      = UInt(elemIdxBits.W)
39  // val exceptionVec   = ExceptionVec() // uop has exceptionVec
40  val baseAddr            = UInt(XLEN.W)
41  val stride              = UInt(VLEN.W)
42  // val flow_counter = UInt(flowIdxBits.W)
43
44  // instruction decode result
45  val flowNum             = UInt(flowIdxBits.W) // # of flows in a uop
46  // val flowNumLog2 = UInt(log2Up(flowIdxBits).W) // log2(flowNum), for better timing of multiplication
47  val nfields             = UInt(fieldBits.W) // NFIELDS
48  val vm                  = Bool() // whether vector masking is enabled
49  val usWholeReg          = Bool() // unit-stride, whole register load
50  val usMaskReg           = Bool() // unit-stride, masked store/load
51  val eew                 = VEew() // size of memory elements
52  val sew                 = UInt(ewBits.W)
53  val emul                = UInt(mulBits.W)
54  val lmul                = UInt(mulBits.W)
55  val vlmax               = UInt(elemIdxBits.W)
56  val instType            = UInt(3.W)
57  val vd_last_uop         = Bool()
58  val vd_first_uop        = Bool()
59
60  val indexedSrcMask     = UInt(VLENB.W)
61  val indexedSplitOffset  = UInt(flowIdxBits.W)
62  // Inst's uop
63  val uop                 = new DynInst
64
65  val fof                 = Bool()
66  val vdIdxInField        = UInt(log2Up(maxMUL).W)
67  val uopOffset           = UInt(VLEN.W)
68  val preIsSplit          = Bool() // if uop need split, only not Unit-Stride or not 128bit-aligned unit stride need split
69  val mBIndex             = if(isVStore) UInt(vsmBindexBits.W) else UInt(vlmBindexBits.W)
70
71  val alignedType         = UInt(alignTypeBits.W)
72  val indexVlMaxInVd      = UInt(elemIdxBits.W)
73
74  val usLowBitsAddr       = UInt((log2Up(maxMemByteNum)).W)
75  val usAligned128        = Bool()
76  val usMask              = UInt((VLENB*2).W) // for unit-stride split
77}
78
79object VSFQFeedbackType {
80  val tlbMiss = 0.U(3.W)
81  val mshrFull = 1.U(3.W)
82  val dataInvalid = 2.U(3.W)
83  val bankConflict = 3.U(3.W)
84  val ldVioCheckRedo = 4.U(3.W)
85  val feedbackInvalid = 7.U(3.W)
86
87  def apply() = UInt(3.W)
88}
89
90class VSFQFeedback (implicit p: Parameters) extends XSBundle {
91  // val flowPtr = new VsFlowPtr
92  val hit   = Bool()
93  //val flushState = Bool()
94  val sourceType = VSFQFeedbackType()
95  //val dataInvalidSqIdx = new SqPtr
96  val paddr = UInt(PAddrBits.W)
97  val mmio = Bool()
98  val atomic = Bool()
99  val exceptionVec = ExceptionVec()
100}
101
102class VecPipelineFeedbackIO(isVStore: Boolean=false) (implicit p: Parameters) extends VLSUBundle {
103  val mBIndex              = if(isVStore) UInt(vsmBindexBits.W) else UInt(vlmBindexBits.W)
104  val hit                  = Bool()
105  val isvec                = Bool()
106  val flushState           = Bool()
107  val sourceType           = VSFQFeedbackType()
108  val trigger              = TriggerAction()
109  //val dataInvalidSqIdx = new SqPtr
110  //val paddr                = UInt(PAddrBits.W)
111  val mmio                 = Bool()
112  //val atomic               = Bool()
113  val exceptionVec         = ExceptionVec()
114  val vaddr                = UInt(XLEN.W)
115  val vaNeedExt          = Bool()
116  val gpaddr               = UInt(XLEN.W)
117  val isForVSnonLeafPTE    = Bool()
118  val vecVaddrOffset       = UInt(VAddrBits.W)
119  val vecTriggerMask       = UInt((VLEN/8).W)
120
121  //val vec                  = new OnlyVecExuOutput
122   // feedback
123  val vecFeedback          = Bool()
124
125  val usSecondInv          = Bool() // only for unit stride, second flow is Invalid
126  val elemIdx              = UInt(elemIdxBits.W) // element index
127  val mask                 = UInt(VLENB.W)
128  val alignedType          = UInt(alignTypeBits.W)
129  // for load
130  val reg_offset           = OptionWrapper(!isVStore, UInt(vOffsetBits.W))
131  val elemIdxInsideVd      = OptionWrapper(!isVStore, UInt(elemIdxBits.W)) // element index in scope of vd
132  val vecdata              = OptionWrapper(!isVStore, UInt(VLEN.W))
133}
134
135class VecPipeBundle(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle {
136  val vaddr               = UInt(XLEN.W)
137  val basevaddr           = UInt(VAddrBits.W)
138  val mask                = UInt(VLENB.W)
139  val isvec               = Bool()
140  val uop_unit_stride_fof = Bool()
141  val reg_offset          = UInt(vOffsetBits.W)
142  val alignedType         = UInt(alignTypeBits.W)
143  val vecActive           = Bool() // 1: vector active element, 0: vector not active element
144  val is_first_ele        = Bool()
145  val isFirstIssue        = Bool()
146
147  val uop = new DynInst
148
149  val usSecondInv         = Bool() // only for unit stride, second flow is Invalid
150  val mBIndex             = if(isVStore) UInt(vsmBindexBits.W) else UInt(vlmBindexBits.W)
151  val elemIdx             = UInt(elemIdxBits.W)
152  val elemIdxInsideVd     = UInt(elemIdxBits.W) // only use in unit-stride
153}
154
155object VecFeedbacks {
156  // need to invalid lsq entry
157  val FLUSH  = 0
158  // merge buffer commits one uop
159  val COMMIT  = 1
160  // last uop of an inst, sq can commit
161  val LAST = 2
162  // total feedbacks
163  val allFeedbacks = 3
164}
165
166class MergeBufferReq(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
167  val mask                = UInt(VLENB.W)
168  val vaddr               = UInt(VAddrBits.W)
169  val flowNum             = UInt(flowIdxBits.W)
170  val uop                 = new DynInst
171  val data                = UInt(VLEN.W)
172  val vdIdx               = UInt(3.W)
173  val fof                 = Bool()
174  val vlmax               = UInt(elemIdxBits.W)
175  // val vdOffset            = UInt(vdOffset.W)
176}
177
178class MergeBufferResp(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
179  val mBIndex             = if(isVStore) UInt(vsmBindexBits.W) else UInt(vlmBindexBits.W)
180  val fail                = Bool()
181}
182
183class ToMergeBufferIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
184  val req                 = DecoupledIO(new MergeBufferReq(isVStore))
185  val resp                = Flipped(ValidIO(new MergeBufferResp(isVStore)))
186  // val issueInactive       = ValidIO
187}
188
189class FromSplitIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
190  val req                 = Flipped(DecoupledIO(new MergeBufferReq(isVStore)))
191  val resp                = ValidIO(new MergeBufferResp(isVStore))
192  // val issueInactive       = Flipped(ValidIO())
193}
194
195class FeedbackToSplitIO(implicit p: Parameters) extends VLSUBundle{
196  val elemWriteback       = Bool()
197}
198
199class FeedbackToLsqIO(implicit p: Parameters) extends VLSUBundle{
200  val robidx = new RobPtr
201  val uopidx = UopIdx()
202  val vaddr = UInt(XLEN.W)
203  val vaNeedExt = Bool()
204  val gpaddr = UInt(GPAddrBits.W)
205  val isForVSnonLeafPTE = Bool()
206  val feedback = Vec(VecFeedbacks.allFeedbacks, Bool())
207    // for exception
208  val vstart           = UInt(elemIdxBits.W)
209  val vl               = UInt(elemIdxBits.W)
210  val exceptionVec     = ExceptionVec()
211
212  def isFlush  = feedback(VecFeedbacks.FLUSH)
213  def isCommit = feedback(VecFeedbacks.COMMIT)
214  def isLast = feedback(VecFeedbacks.LAST)
215}
216
217class VSplitIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
218  val redirect            = Flipped(ValidIO(new Redirect))
219  val in                  = Flipped(Decoupled(new MemExuInput(isVector = true))) // from iq
220  val toMergeBuffer       = new ToMergeBufferIO(isVStore) //to merge buffer req mergebuffer entry
221  val out                 = Decoupled(new VecPipeBundle(isVStore))// to scala pipeline
222  val vstd                = OptionWrapper(isVStore, Valid(new MemExuOutput(isVector = true)))
223}
224
225class VSplitPipelineIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
226  val redirect            = Flipped(ValidIO(new Redirect))
227  val in                  = Flipped(Decoupled(new MemExuInput(isVector = true)))
228  val toMergeBuffer       = new ToMergeBufferIO(isVStore) // req mergebuffer entry, inactive elem issue
229  val out                 = Decoupled(new VLSBundle())// to split buffer
230}
231
232class VSplitBufferIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
233  val redirect            = Flipped(ValidIO(new Redirect))
234  val in                  = Flipped(Decoupled(new VLSBundle()))
235  val out                 = Decoupled(new VecPipeBundle(isVStore))//to scala pipeline
236  val vstd                = OptionWrapper(isVStore, ValidIO(new MemExuOutput(isVector = true)))
237}
238
239class VMergeBufferIO(isVStore : Boolean=false)(implicit p: Parameters) extends VLSUBundle{
240  val redirect            = Flipped(ValidIO(new Redirect))
241  val fromPipeline        = if(isVStore) Vec(StorePipelineWidth, Flipped(DecoupledIO(new VecPipelineFeedbackIO(isVStore)))) else Vec(LoadPipelineWidth, Flipped(DecoupledIO(new VecPipelineFeedbackIO(isVStore))))
242  val fromSplit           = if(isVStore) Vec(VecStorePipelineWidth, new FromSplitIO) else Vec(VecLoadPipelineWidth, new FromSplitIO) // req mergebuffer entry, inactive elem issue
243  val uopWriteback        = if(isVStore) Vec(VSUopWritebackWidth, DecoupledIO(new MemExuOutput(isVector = true))) else Vec(VLUopWritebackWidth, DecoupledIO(new MemExuOutput(isVector = true)))
244  val toSplit             = if(isVStore) Vec(VecStorePipelineWidth, ValidIO(new FeedbackToSplitIO)) else Vec(VecLoadPipelineWidth, ValidIO(new FeedbackToSplitIO)) // for inorder inst
245  val toLsq               = if(isVStore) Vec(VSUopWritebackWidth, ValidIO(new FeedbackToLsqIO)) else Vec(VLUopWritebackWidth, ValidIO(new FeedbackToLsqIO)) // for lsq deq
246  val feedback            = if(isVStore) Vec(VSUopWritebackWidth, ValidIO(new RSFeedback(isVector = true))) else Vec(VLUopWritebackWidth, ValidIO(new RSFeedback(isVector = true)))//for rs replay
247}
248
249class VSegmentUnitIO(implicit p: Parameters) extends VLSUBundle{
250  val in                  = Flipped(Decoupled(new MemExuInput(isVector = true))) // from iq
251  val uopwriteback        = DecoupledIO(new MemExuOutput(isVector = true)) // writeback data
252  val rdcache             = new DCacheLoadIO // read dcache port
253  val sbuffer             = Decoupled(new DCacheWordReqWithVaddrAndPfFlag)
254  val vecDifftestInfo     = Decoupled(new DynInst) // to sbuffer
255  val dtlb                = new TlbRequestIO(2)
256  val pmpResp             = Flipped(new PMPRespBundle())
257  val flush_sbuffer       = new SbufferFlushBundle
258  val feedback            = ValidIO(new RSFeedback(isVector = true))
259  val redirect            = Flipped(ValidIO(new Redirect))
260  val exceptionInfo       = ValidIO(new FeedbackToLsqIO)
261  //trigger
262  val fromCsrTrigger      = Input(new CsrTriggerBundle)
263}