xref: /XiangShan/src/main/scala/xiangshan/mem/vector/VecBundle.scala (revision 881e32f5b63c435bafbaf5dc1d792ffcc9ea103e)
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._
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 uopAddr             = UInt(XLEN.W)
42  val stride              = UInt(VLEN.W)
43  // val flow_counter = UInt(flowIdxBits.W)
44
45  // instruction decode result
46  val flowNum             = UInt(flowIdxBits.W) // # of flows in a uop
47  // val flowNumLog2 = UInt(log2Up(flowIdxBits).W) // log2(flowNum), for better timing of multiplication
48  val nfields             = UInt(fieldBits.W) // NFIELDS
49  val vm                  = Bool() // whether vector masking is enabled
50  val usWholeReg          = Bool() // unit-stride, whole register load
51  val usMaskReg           = Bool() // unit-stride, masked store/load
52  val eew                 = VEew() // size of memory elements
53  val sew                 = UInt(ewBits.W)
54  val emul                = UInt(mulBits.W)
55  val lmul                = UInt(mulBits.W)
56  val vlmax               = UInt(elemIdxBits.W)
57  val instType            = UInt(3.W)
58  val vd_last_uop         = Bool()
59  val vd_first_uop        = Bool()
60
61  // Because the back-end needs to handle exceptions, it is necessary to retain the original NF.
62  // So we choose to pass the original value in the pipeline and override it when out.
63  val rawNf                = Nf()
64  val indexedSrcMask     = UInt(VLENB.W)
65  val indexedSplitOffset  = UInt(flowIdxBits.W)
66  // Inst's uop
67  val uop                 = new DynInst
68
69  val fof                 = Bool()
70  val vdIdxInField        = UInt(log2Up(maxMUL).W)
71  val uopOffset           = UInt(VLEN.W)
72  val preIsSplit          = Bool() // if uop need split, only not Unit-Stride or not 128bit-aligned unit stride need split
73  val mBIndex             = if(isVStore) UInt(vsmBindexBits.W) else UInt(vlmBindexBits.W)
74
75  val alignedType         = UInt(alignTypeBits.W)
76  val indexVlMaxInVd      = UInt(elemIdxBits.W)
77
78  val usLowBitsAddr       = UInt((log2Up(maxMemByteNum)).W)
79  val usAligned128        = Bool()
80  val usMask              = UInt((VLENB*2).W) // for unit-stride split
81}
82
83object VSFQFeedbackType {
84  val tlbMiss = 0.U(3.W)
85  val mshrFull = 1.U(3.W)
86  val dataInvalid = 2.U(3.W)
87  val bankConflict = 3.U(3.W)
88  val ldVioCheckRedo = 4.U(3.W)
89  val feedbackInvalid = 7.U(3.W)
90
91  def apply() = UInt(3.W)
92}
93
94class VSFQFeedback (implicit p: Parameters) extends XSBundle {
95  // val flowPtr = new VsFlowPtr
96  val hit   = Bool()
97  //val flushState = Bool()
98  val sourceType = VSFQFeedbackType()
99  //val dataInvalidSqIdx = new SqPtr
100  val paddr = UInt(PAddrBits.W)
101  val mmio = Bool()
102  val atomic = Bool()
103  val exceptionVec = ExceptionVec()
104}
105
106class VecPipelineFeedbackIO(isVStore: Boolean=false) (implicit p: Parameters) extends VLSUBundle {
107  val mBIndex              = if(isVStore) UInt(vsmBindexBits.W) else UInt(vlmBindexBits.W)
108  val hit                  = Bool()
109  val isvec                = Bool()
110  val flushState           = Bool()
111  val sourceType           = VSFQFeedbackType()
112  val trigger              = TriggerAction()
113  //val dataInvalidSqIdx = new SqPtr
114  //val paddr                = UInt(PAddrBits.W)
115  val nc                   = Bool()
116  val mmio                 = Bool()
117  //val atomic               = Bool()
118  val exceptionVec         = ExceptionVec()
119  val hasException         = Bool() // Active
120  val vaddr                = UInt(XLEN.W)
121  val vaNeedExt            = Bool()
122  val gpaddr               = UInt(XLEN.W)
123  val isForVSnonLeafPTE    = Bool()
124  val vstart               = UInt(elemIdxBits.W)
125  val vecTriggerMask       = UInt((VLEN/8).W)
126
127  //val vec                  = new OnlyVecExuOutput
128   // feedback
129  val vecFeedback          = Bool()
130
131  val usSecondInv          = Bool() // only for unit stride, second flow is Invalid
132  val elemIdx              = UInt(elemIdxBits.W) // element index
133  val mask                 = UInt(VLENB.W)
134  val alignedType          = UInt(alignTypeBits.W)
135  // for load
136  val reg_offset           = OptionWrapper(!isVStore, UInt(vOffsetBits.W))
137  val elemIdxInsideVd      = OptionWrapper(!isVStore, UInt(elemIdxBits.W)) // element index in scope of vd
138  val vecdata              = OptionWrapper(!isVStore, UInt(VLEN.W))
139}
140
141class VecPipeBundle(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle {
142  val vaddr               = UInt(XLEN.W)
143  val basevaddr           = UInt(VAddrBits.W)
144  val mask                = UInt(VLENB.W)
145  val isvec               = Bool()
146  val uop_unit_stride_fof = Bool()
147  val reg_offset          = UInt(vOffsetBits.W)
148  val alignedType         = UInt(alignTypeBits.W)
149  val vecActive           = Bool() // 1: vector active element, 0: vector not active element
150  val is_first_ele        = Bool()
151  val isFirstIssue        = Bool()
152
153  val uop = new DynInst
154
155  val usSecondInv         = Bool() // only for unit stride, second flow is Invalid
156  val mBIndex             = if(isVStore) UInt(vsmBindexBits.W) else UInt(vlmBindexBits.W)
157  val elemIdx             = UInt(elemIdxBits.W)
158  val elemIdxInsideVd     = UInt(elemIdxBits.W) // only use in unit-stride
159}
160
161object VecFeedbacks {
162  // need to invalid lsq entry
163  val FLUSH  = 0
164  // merge buffer commits one uop
165  val COMMIT  = 1
166  // last uop of an inst, sq can commit
167  val LAST = 2
168  // total feedbacks
169  val allFeedbacks = 3
170}
171
172class MergeBufferReq(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
173  val mask                = UInt(VLENB.W)
174  val vaddr               = UInt(VAddrBits.W)
175  val flowNum             = UInt(flowIdxBits.W)
176  val uop                 = new DynInst
177  val data                = UInt(VLEN.W)
178  val vdIdx               = UInt(3.W)
179  val fof                 = Bool()
180  val vlmax               = UInt(elemIdxBits.W)
181  // val vdOffset            = UInt(vdOffset.W)
182}
183
184class MergeBufferResp(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
185  val mBIndex             = if(isVStore) UInt(vsmBindexBits.W) else UInt(vlmBindexBits.W)
186  val fail                = Bool()
187}
188
189class ToMergeBufferIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
190  val req                 = DecoupledIO(new MergeBufferReq(isVStore))
191  val resp                = Flipped(ValidIO(new MergeBufferResp(isVStore)))
192}
193
194class FromSplitIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
195  val req                 = Flipped(DecoupledIO(new MergeBufferReq(isVStore)))
196  val resp                = ValidIO(new MergeBufferResp(isVStore))
197  // val issueInactive       = Flipped(ValidIO())
198}
199
200class FeedbackToSplitIO(implicit p: Parameters) extends VLSUBundle{
201  val threshold            = Bool()
202}
203
204class FeedbackToLsqIO(implicit p: Parameters) extends VLSUBundle{
205  val robidx = new RobPtr
206  val uopidx = UopIdx()
207  val vaddr = UInt(XLEN.W)
208  val vaNeedExt = Bool()
209  val gpaddr = UInt(GPAddrBits.W)
210  val isForVSnonLeafPTE = Bool()
211  val feedback = Vec(VecFeedbacks.allFeedbacks, Bool())
212    // for exception
213  val vstart           = UInt(elemIdxBits.W)
214  val vl               = UInt(elemIdxBits.W)
215  val exceptionVec     = ExceptionVec()
216
217  def isFlush  = feedback(VecFeedbacks.FLUSH)
218  def isCommit = feedback(VecFeedbacks.COMMIT)
219  def isLast = feedback(VecFeedbacks.LAST)
220}
221
222class storeMisaignIO(implicit p: Parameters) extends Bundle{
223  val storePipeEmpty           = Input(Bool())
224  val storeMisalignBufferEmpty = Input(Bool())
225}
226
227class VSplitIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
228  val redirect            = Flipped(ValidIO(new Redirect))
229  val in                  = Flipped(Decoupled(new MemExuInput(isVector = true))) // from iq
230  val toMergeBuffer       = new ToMergeBufferIO(isVStore) //to merge buffer req mergebuffer entry
231  val out                 = Decoupled(new VecPipeBundle(isVStore))// to scala pipeline
232  val vstd                = OptionWrapper(isVStore, Valid(new MemExuOutput(isVector = true)))
233  val vstdMisalign        = OptionWrapper(isVStore, new storeMisaignIO)
234  val threshold            = OptionWrapper(!isVStore, Flipped(ValidIO(new LqPtr)))
235}
236
237class VSplitPipelineIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
238  val redirect            = Flipped(ValidIO(new Redirect))
239  val in                  = Flipped(Decoupled(new MemExuInput(isVector = true)))
240  val toMergeBuffer       = new ToMergeBufferIO(isVStore) // req mergebuffer entry, inactive elem issue
241  val out                 = Decoupled(new VLSBundle())// to split buffer
242}
243
244class VSplitBufferIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
245  val redirect            = Flipped(ValidIO(new Redirect))
246  val in                  = Flipped(Decoupled(new VLSBundle()))
247  val out                 = Decoupled(new VecPipeBundle(isVStore))//to scala pipeline
248  val vstd                = OptionWrapper(isVStore, ValidIO(new MemExuOutput(isVector = true)))
249  val vstdMisalign        = OptionWrapper(isVStore, new storeMisaignIO)
250}
251
252class VMergeBufferIO(isVStore : Boolean=false)(implicit p: Parameters) extends VLSUBundle{
253  val redirect            = Flipped(ValidIO(new Redirect))
254  val fromPipeline        = if(isVStore) Vec(StorePipelineWidth, Flipped(DecoupledIO(new VecPipelineFeedbackIO(isVStore)))) else Vec(LoadPipelineWidth, Flipped(DecoupledIO(new VecPipelineFeedbackIO(isVStore))))
255  val fromSplit           = if(isVStore) Vec(VecStorePipelineWidth, new FromSplitIO) else Vec(VecLoadPipelineWidth, new FromSplitIO) // req mergebuffer entry, inactive elem issue
256  val uopWriteback        = if(isVStore) Vec(VSUopWritebackWidth, DecoupledIO(new MemExuOutput(isVector = true))) else Vec(VLUopWritebackWidth, DecoupledIO(new MemExuOutput(isVector = true)))
257  val toSplit             = OptionWrapper(!isVStore, new FeedbackToSplitIO())
258  val toLsq               = if(isVStore) Vec(VSUopWritebackWidth, ValidIO(new FeedbackToLsqIO)) else Vec(VLUopWritebackWidth, ValidIO(new FeedbackToLsqIO)) // for lsq deq
259  val feedback            = if(isVStore) Vec(VSUopWritebackWidth, ValidIO(new RSFeedback(isVector = true))) else Vec(VLUopWritebackWidth, ValidIO(new RSFeedback(isVector = true)))//for rs replay
260
261  val fromMisalignBuffer  = OptionWrapper(isVStore, Flipped(new StoreMaBufToVecStoreMergeBufferIO))
262}
263
264class VSegmentUnitIO(implicit p: Parameters) extends VLSUBundle{
265  val in                  = Flipped(Decoupled(new MemExuInput(isVector = true))) // from iq
266  val uopwriteback        = DecoupledIO(new MemExuOutput(isVector = true)) // writeback data
267  val rdcache             = new DCacheLoadIO // read dcache port
268  val sbuffer             = Decoupled(new DCacheWordReqWithVaddrAndPfFlag)
269  val vecDifftestInfo     = Decoupled(new DynInst) // to sbuffer
270  val dtlb                = new TlbRequestIO(2)
271  val pmpResp             = Flipped(new PMPRespBundle())
272  val flush_sbuffer       = new SbufferFlushBundle
273  val feedback            = ValidIO(new RSFeedback(isVector = true))
274  val redirect            = Flipped(ValidIO(new Redirect))
275  val exceptionInfo       = ValidIO(new FeedbackToLsqIO)
276  //trigger
277  val fromCsrTrigger      = Input(new CsrTriggerBundle)
278}
279
280class VfofDataBuffIO(implicit p: Parameters) extends VLSUBundle{
281  val redirect            = Flipped(ValidIO(new Redirect))
282  val in                  = Vec(VecLoadPipelineWidth, Flipped(Decoupled(new MemExuInput(isVector=true))))
283  val mergeUopWriteback   = Vec(VLUopWritebackWidth, Flipped(DecoupledIO(new MemExuOutput(isVector=true))))
284
285  val uopWriteback        = DecoupledIO(new MemExuOutput(isVector = true))
286}