xref: /XiangShan/src/main/scala/xiangshan/mem/vector/VecBundle.scala (revision 26af847e669bb208507278eafc6ebe52f03b0d19)
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
102  val usSecondInv          = Bool() // only for unit stride, second flow is Invalid
103  // for load
104  val reg_offset           = OptionWrapper(!isVStore, UInt(vOffsetBits.W))
105  val elemIdx              = OptionWrapper(!isVStore, UInt(elemIdxBits.W)) // element index
106  val elemIdxInsideVd      = OptionWrapper(!isVStore, UInt(elemIdxBits.W)) // element index in scope of vd
107  val vecdata              = OptionWrapper(!isVStore, UInt(VLEN.W))
108  val mask                 = OptionWrapper(!isVStore, UInt(VLENB.W))
109  val alignedType          = OptionWrapper(!isVStore, UInt(alignTypeBits.W))
110}
111
112class VecPipeBundle(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle {
113  val vaddr               = UInt(VAddrBits.W)
114  val mask                = UInt(VLENB.W)
115  val isvec               = Bool()
116  val uop_unit_stride_fof = Bool()
117  val reg_offset          = UInt(vOffsetBits.W)
118  val alignedType         = UInt(alignTypeBits.W)
119  val vecActive           = Bool() // 1: vector active element, 0: vector not active element
120  val is_first_ele        = Bool()
121  val isFirstIssue        = Bool()
122
123  val uop = new DynInst
124
125  val usSecondInv         = Bool() // only for unit stride, second flow is Invalid
126  val mBIndex             = if(isVStore) UInt(vsmBindexBits.W) else UInt(vlmBindexBits.W)
127  val elemIdx             = UInt(elemIdxBits.W)
128}
129
130object VecFeedbacks {
131  // need to invalid lsq entry
132  val FLUSH  = 0
133  // merge buffer commits one uop
134  val COMMIT  = 1
135  // last uop of an inst, sq can commit
136  val LAST = 2
137  // total feedbacks
138  val allFeedbacks = 3
139}
140
141class MergeBufferReq(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
142  val mask                = UInt(VLENB.W)
143  val vaddr               = UInt(VAddrBits.W)
144  val flowNum             = UInt(flowIdxBits.W)
145  val uop                 = new DynInst
146  val data                = UInt(VLEN.W)
147  // val vdOffset            = UInt(vdOffset.W)
148}
149
150class MergeBufferResp(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
151  val mBIndex             = if(isVStore) UInt(vsmBindexBits.W) else UInt(vlmBindexBits.W)
152  val fail                = Bool()
153}
154
155class ToMergeBufferIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
156  val req                 = DecoupledIO(new MergeBufferReq(isVStore))
157  val resp                = Flipped(ValidIO(new MergeBufferResp(isVStore)))
158  // val issueInactive       = ValidIO
159}
160
161class FromSplitIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
162  val req                 = Flipped(DecoupledIO(new MergeBufferReq(isVStore)))
163  val resp                = ValidIO(new MergeBufferResp(isVStore))
164  // val issueInactive       = Flipped(ValidIO())
165}
166
167class FeedbackToSplitIO(implicit p: Parameters) extends VLSUBundle{
168  val elemWriteback       = Bool()
169}
170
171class FeedbackToLsqIO(implicit p: Parameters) extends VLSUBundle{
172  val robidx = new RobPtr
173  val uopidx = UopIdx()
174  val vaddr = UInt(VAddrBits.W)
175  val feedback = Vec(VecFeedbacks.allFeedbacks, Bool())
176
177  def isFlush  = feedback(VecFeedbacks.FLUSH)
178  def isCommit = feedback(VecFeedbacks.COMMIT)
179  def isLast = feedback(VecFeedbacks.LAST)
180}
181
182class VSplitIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
183  val redirect            = Flipped(ValidIO(new Redirect))
184  val in                  = if(isVStore) Flipped(Decoupled(new MemExuInput(isVector = true))) else Flipped(Decoupled(new MemExuInput(isVector = true))) // from iq
185  val toMergeBuffer       = new ToMergeBufferIO(isVStore) //to merge buffer req mergebuffer entry
186  val out                 = Decoupled(new VecPipeBundle(isVStore))// to scala pipeline
187  val vstd                = OptionWrapper(isVStore, Valid(new MemExuOutput(isVector = true)))
188}
189
190class VSplitPipelineIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
191  val redirect            = Flipped(ValidIO(new Redirect))
192  val in                  = Flipped(Decoupled(new MemExuInput(isVector = true)))
193  val toMergeBuffer       = new ToMergeBufferIO(isVStore) // req mergebuffer entry, inactive elem issue
194  val out                 = Decoupled(new VLSBundle())// to split buffer
195}
196
197class VSplitBufferIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{
198  val redirect            = Flipped(ValidIO(new Redirect))
199  val in                  = Flipped(Decoupled(new VLSBundle()))
200  val out                 = Decoupled(new VecPipeBundle(isVStore))//to scala pipeline
201  val vstd                = OptionWrapper(isVStore, ValidIO(new MemExuOutput(isVector = true)))
202}
203
204class VMergeBufferIO(isVStore : Boolean=false)(implicit p: Parameters) extends VLSUBundle{
205  val redirect            = Flipped(ValidIO(new Redirect))
206  val fromPipeline        = if(isVStore) Vec(StorePipelineWidth, Flipped(DecoupledIO(new VecPipelineFeedbackIO(isVStore)))) else Vec(LoadPipelineWidth, Flipped(DecoupledIO(new VecPipelineFeedbackIO(isVStore))))
207  val fromSplit           = if(isVStore) Vec(StorePipelineWidth, new FromSplitIO) else Vec(LoadPipelineWidth, new FromSplitIO) // req mergebuffer entry, inactive elem issue
208  val uopWriteback        = Vec(UopWritebackWidth, DecoupledIO(new MemExuOutput(isVector = true)))
209  val toSplit             = if(isVStore) Vec(StorePipelineWidth, ValidIO(new FeedbackToSplitIO)) else Vec(LoadPipelineWidth, ValidIO(new FeedbackToSplitIO)) // for inorder inst
210  val toLsq               = Vec(UopWritebackWidth, ValidIO(new FeedbackToLsqIO)) // for lsq deq
211  val feedback            = ValidIO(new RSFeedback)//for rs replay
212}