xref: /XiangShan/src/main/scala/xiangshan/mem/vector/VecBundle.scala (revision 4aa0028654716f3ef660f985eb6662c6c75b70d0)
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.rob.RobPtr
27
28class VLSBundle(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle {
29  val flowMask            = UInt(VLENB.W) // each bit for a flow
30  val byteMask            = UInt(VLENB.W) // each bit for a byte
31  val data                = UInt(VLEN.W)
32  // val fof            = Bool() // fof is only used for vector loads
33  val excp_eew_index      = UInt(elemIdxBits.W)
34  // val exceptionVec   = ExceptionVec() // uop has exceptionVec
35  val baseAddr            = UInt(VAddrBits.W)
36  val stride              = UInt(VLEN.W)
37  // val flow_counter = UInt(flowIdxBits.W)
38
39  // instruction decode result
40  val flowNum             = UInt(flowIdxBits.W) // # of flows in a uop
41  // val flowNumLog2 = UInt(log2Up(flowIdxBits).W) // log2(flowNum), for better timing of multiplication
42  val nfields             = UInt(fieldBits.W) // NFIELDS
43  val vm                  = Bool() // whether vector masking is enabled
44  val usWholeReg          = Bool() // unit-stride, whole register load
45  val usMaskReg           = Bool() // unit-stride, masked store/load
46  val eew                 = UInt(ewBits.W) // size of memory elements
47  val sew                 = UInt(ewBits.W)
48  val emul                = UInt(mulBits.W)
49  val lmul                = UInt(mulBits.W)
50  val vlmax               = UInt(elemIdxBits.W)
51  val instType            = UInt(3.W)
52  val vd_last_uop         = Bool()
53  val vd_first_uop        = Bool()
54
55  val indexedSrcMask     = UInt(VLENB.W)
56  val indexedSplitOffset  = UInt(flowIdxBits.W)
57  // Inst's uop
58  val uop                 = new DynInst
59
60  val fof                 = Bool()
61  val vdIdxInField        = UInt(log2Up(maxMUL).W)
62  val uopOffset           = UInt(VLEN.W)
63  val preIsSplit          = Bool() // if uop need split, only not Unit-Stride or not 128bit-aligned unit stride need split
64  val mBIndex             = if(isVStore) UInt(vsmBindexBits.W) else UInt(vlmBindexBits.W)
65
66  val alignedType         = UInt(alignTypeBits.W)
67}
68
69object VSFQFeedbackType {
70  val tlbMiss = 0.U(3.W)
71  val mshrFull = 1.U(3.W)
72  val dataInvalid = 2.U(3.W)
73  val bankConflict = 3.U(3.W)
74  val ldVioCheckRedo = 4.U(3.W)
75  val feedbackInvalid = 7.U(3.W)
76
77  def apply() = UInt(3.W)
78}
79
80class VSFQFeedback (implicit p: Parameters) extends XSBundle {
81  // val flowPtr = new VsFlowPtr
82  val hit   = Bool()
83  //val flushState = Bool()
84  val sourceType = VSFQFeedbackType()
85  //val dataInvalidSqIdx = new SqPtr
86  val paddr = UInt(PAddrBits.W)
87  val mmio = Bool()
88  val atomic = Bool()
89  val exceptionVec = ExceptionVec()
90}
91
92class VecPipelineFeedbackIO(isVStore: Boolean=false) (implicit p: Parameters) extends VLSUBundle {
93  val mBIndex              = if(isVStore) UInt(vsmBindexBits.W) else UInt(vlmBindexBits.W)
94  val hit                  = Bool()
95  val isvec                = Bool()
96  val flushState           = Bool()
97  val sourceType           = VSFQFeedbackType()
98  //val dataInvalidSqIdx = new SqPtr
99  //val paddr                = UInt(PAddrBits.W)
100  val mmio                 = Bool()
101  //val atomic               = Bool()
102  val exceptionVec         = ExceptionVec()
103  //val vec                  = new OnlyVecExuOutput
104   // feedback
105  val vecFeedback          = Bool()
106
107  val usSecondInv          = Bool() // only for unit stride, second flow is Invalid
108  val elemIdx              = UInt(elemIdxBits.W) // element index
109  val mask                 = UInt(VLENB.W)
110  val alignedType          = UInt(alignTypeBits.W)
111  // for load
112  val reg_offset           = OptionWrapper(!isVStore, UInt(vOffsetBits.W))
113  val elemIdxInsideVd      = OptionWrapper(!isVStore, UInt(elemIdxBits.W)) // element index in scope of vd
114  val vecdata              = OptionWrapper(!isVStore, UInt(VLEN.W))
115}
116
117class VecPipeBundle(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle {
118  val vaddr               = UInt(VAddrBits.W)
119  val mask                = UInt(VLENB.W)
120  val isvec               = Bool()
121  val uop_unit_stride_fof = Bool()
122  val reg_offset          = UInt(vOffsetBits.W)
123  val alignedType         = UInt(alignTypeBits.W)
124  val vecActive           = Bool() // 1: vector active element, 0: vector not active element
125  val is_first_ele        = Bool()
126  val isFirstIssue        = Bool()
127
128  val uop = new DynInst
129
130  val usSecondInv         = Bool() // only for unit stride, second flow is Invalid
131  val mBIndex             = if(isVStore) UInt(vsmBindexBits.W) else UInt(vlmBindexBits.W)
132  val elemIdx             = UInt(elemIdxBits.W)
133  val elemIdxInsideVd     = UInt(elemIdxBits.W) // only use in unit-stride
134}
135
136object VecFeedbacks {
137  // need to invalid lsq entry
138  val FLUSH  = 0
139  // merge buffer commits one uop
140  val COMMIT  = 1
141  // last uop of an inst, sq can commit
142  val LAST = 2
143  // total feedbacks
144  val allFeedbacks = 3
145}
146
147class MergeBufferReq(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
148  val mask                = UInt(VLENB.W)
149  val vaddr               = UInt(VAddrBits.W)
150  val flowNum             = UInt(flowIdxBits.W)
151  val uop                 = new DynInst
152  val data                = UInt(VLEN.W)
153  val vdIdx               = UInt(3.W)
154  val fof                 = Bool()
155  val vlmax               = UInt(elemIdxBits.W)
156  // val vdOffset            = UInt(vdOffset.W)
157}
158
159class MergeBufferResp(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
160  val mBIndex             = if(isVStore) UInt(vsmBindexBits.W) else UInt(vlmBindexBits.W)
161  val fail                = Bool()
162}
163
164class ToMergeBufferIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
165  val req                 = DecoupledIO(new MergeBufferReq(isVStore))
166  val resp                = Flipped(ValidIO(new MergeBufferResp(isVStore)))
167  // val issueInactive       = ValidIO
168}
169
170class FromSplitIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
171  val req                 = Flipped(DecoupledIO(new MergeBufferReq(isVStore)))
172  val resp                = ValidIO(new MergeBufferResp(isVStore))
173  // val issueInactive       = Flipped(ValidIO())
174}
175
176class FeedbackToSplitIO(implicit p: Parameters) extends VLSUBundle{
177  val elemWriteback       = Bool()
178}
179
180class FeedbackToLsqIO(implicit p: Parameters) extends VLSUBundle{
181  val robidx = new RobPtr
182  val uopidx = UopIdx()
183  val vaddr = UInt(VAddrBits.W)
184  val feedback = Vec(VecFeedbacks.allFeedbacks, Bool())
185    // for exception
186  val vstart           = UInt(elemIdxBits.W)
187  val vl               = UInt(elemIdxBits.W)
188
189  def isFlush  = feedback(VecFeedbacks.FLUSH)
190  def isCommit = feedback(VecFeedbacks.COMMIT)
191  def isLast = feedback(VecFeedbacks.LAST)
192}
193
194class VSplitIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
195  val redirect            = Flipped(ValidIO(new Redirect))
196  val in                  = if(isVStore) Flipped(Decoupled(new MemExuInput(isVector = true))) else Flipped(Decoupled(new MemExuInput(isVector = true))) // from iq
197  val toMergeBuffer       = new ToMergeBufferIO(isVStore) //to merge buffer req mergebuffer entry
198  val out                 = Decoupled(new VecPipeBundle(isVStore))// to scala pipeline
199  val vstd                = OptionWrapper(isVStore, Valid(new MemExuOutput(isVector = true)))
200}
201
202class VSplitPipelineIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
203  val redirect            = Flipped(ValidIO(new Redirect))
204  val in                  = Flipped(Decoupled(new MemExuInput(isVector = true)))
205  val toMergeBuffer       = new ToMergeBufferIO(isVStore) // req mergebuffer entry, inactive elem issue
206  val out                 = Decoupled(new VLSBundle())// to split buffer
207}
208
209class VSplitBufferIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
210  val redirect            = Flipped(ValidIO(new Redirect))
211  val in                  = Flipped(Decoupled(new VLSBundle()))
212  val out                 = Decoupled(new VecPipeBundle(isVStore))//to scala pipeline
213  val vstd                = OptionWrapper(isVStore, ValidIO(new MemExuOutput(isVector = true)))
214}
215
216class VMergeBufferIO(isVStore : Boolean=false)(implicit p: Parameters) extends VLSUBundle{
217  val redirect            = Flipped(ValidIO(new Redirect))
218  val fromPipeline        = if(isVStore) Vec(StorePipelineWidth, Flipped(DecoupledIO(new VecPipelineFeedbackIO(isVStore)))) else Vec(LoadPipelineWidth, Flipped(DecoupledIO(new VecPipelineFeedbackIO(isVStore))))
219  val fromSplit           = if(isVStore) Vec(VecStorePipelineWidth, new FromSplitIO) else Vec(VecLoadPipelineWidth, new FromSplitIO) // req mergebuffer entry, inactive elem issue
220  val uopWriteback        = if(isVStore) Vec(VSUopWritebackWidth, DecoupledIO(new MemExuOutput(isVector = true))) else Vec(VLUopWritebackWidth, DecoupledIO(new MemExuOutput(isVector = true)))
221  val toSplit             = if(isVStore) Vec(VecStorePipelineWidth, ValidIO(new FeedbackToSplitIO)) else Vec(VecLoadPipelineWidth, ValidIO(new FeedbackToSplitIO)) // for inorder inst
222  val toLsq               = if(isVStore) Vec(VSUopWritebackWidth, ValidIO(new FeedbackToLsqIO)) else Vec(VLUopWritebackWidth, ValidIO(new FeedbackToLsqIO)) // for lsq deq
223  val feedback            = if(isVStore) Vec(VSUopWritebackWidth, ValidIO(new RSFeedback(isVector = true))) else Vec(VLUopWritebackWidth, ValidIO(new RSFeedback(isVector = true)))//for rs replay
224}