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