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