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