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 mmio = Bool() 115 //val atomic = Bool() 116 val exceptionVec = ExceptionVec() 117 val vaddr = UInt(XLEN.W) 118 val vaNeedExt = Bool() 119 val gpaddr = UInt(XLEN.W) 120 val isForVSnonLeafPTE = Bool() 121 val vstart = UInt(elemIdxBits.W) 122 val vecTriggerMask = UInt((VLEN/8).W) 123 124 //val vec = new OnlyVecExuOutput 125 // feedback 126 val vecFeedback = Bool() 127 128 val usSecondInv = Bool() // only for unit stride, second flow is Invalid 129 val elemIdx = UInt(elemIdxBits.W) // element index 130 val mask = UInt(VLENB.W) 131 val alignedType = UInt(alignTypeBits.W) 132 // for load 133 val reg_offset = OptionWrapper(!isVStore, UInt(vOffsetBits.W)) 134 val elemIdxInsideVd = OptionWrapper(!isVStore, UInt(elemIdxBits.W)) // element index in scope of vd 135 val vecdata = OptionWrapper(!isVStore, UInt(VLEN.W)) 136} 137 138class VecPipeBundle(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle { 139 val vaddr = UInt(XLEN.W) 140 val basevaddr = UInt(VAddrBits.W) 141 val mask = UInt(VLENB.W) 142 val isvec = Bool() 143 val uop_unit_stride_fof = Bool() 144 val reg_offset = UInt(vOffsetBits.W) 145 val alignedType = UInt(alignTypeBits.W) 146 val vecActive = Bool() // 1: vector active element, 0: vector not active element 147 val is_first_ele = Bool() 148 val isFirstIssue = Bool() 149 150 val uop = new DynInst 151 152 val usSecondInv = Bool() // only for unit stride, second flow is Invalid 153 val mBIndex = if(isVStore) UInt(vsmBindexBits.W) else UInt(vlmBindexBits.W) 154 val elemIdx = UInt(elemIdxBits.W) 155 val elemIdxInsideVd = UInt(elemIdxBits.W) // only use in unit-stride 156} 157 158object VecFeedbacks { 159 // need to invalid lsq entry 160 val FLUSH = 0 161 // merge buffer commits one uop 162 val COMMIT = 1 163 // last uop of an inst, sq can commit 164 val LAST = 2 165 // total feedbacks 166 val allFeedbacks = 3 167} 168 169class MergeBufferReq(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{ 170 val mask = UInt(VLENB.W) 171 val vaddr = UInt(VAddrBits.W) 172 val flowNum = UInt(flowIdxBits.W) 173 val uop = new DynInst 174 val data = UInt(VLEN.W) 175 val vdIdx = UInt(3.W) 176 val fof = Bool() 177 val vlmax = UInt(elemIdxBits.W) 178 // val vdOffset = UInt(vdOffset.W) 179} 180 181class MergeBufferResp(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{ 182 val mBIndex = if(isVStore) UInt(vsmBindexBits.W) else UInt(vlmBindexBits.W) 183 val fail = Bool() 184} 185 186class ToMergeBufferIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{ 187 val req = DecoupledIO(new MergeBufferReq(isVStore)) 188 val resp = Flipped(ValidIO(new MergeBufferResp(isVStore))) 189 // val issueInactive = ValidIO 190} 191 192class FromSplitIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{ 193 val req = Flipped(DecoupledIO(new MergeBufferReq(isVStore))) 194 val resp = ValidIO(new MergeBufferResp(isVStore)) 195 // val issueInactive = Flipped(ValidIO()) 196} 197 198class FeedbackToSplitIO(implicit p: Parameters) extends VLSUBundle{ 199 val elemWriteback = Bool() 200} 201 202class FeedbackToLsqIO(implicit p: Parameters) extends VLSUBundle{ 203 val robidx = new RobPtr 204 val uopidx = UopIdx() 205 val vaddr = UInt(XLEN.W) 206 val vaNeedExt = Bool() 207 val gpaddr = UInt(GPAddrBits.W) 208 val isForVSnonLeafPTE = Bool() 209 val feedback = Vec(VecFeedbacks.allFeedbacks, Bool()) 210 // for exception 211 val vstart = UInt(elemIdxBits.W) 212 val vl = UInt(elemIdxBits.W) 213 val exceptionVec = ExceptionVec() 214 215 def isFlush = feedback(VecFeedbacks.FLUSH) 216 def isCommit = feedback(VecFeedbacks.COMMIT) 217 def isLast = feedback(VecFeedbacks.LAST) 218} 219 220class VSplitIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{ 221 val redirect = Flipped(ValidIO(new Redirect)) 222 val in = Flipped(Decoupled(new MemExuInput(isVector = true))) // from iq 223 val toMergeBuffer = new ToMergeBufferIO(isVStore) //to merge buffer req mergebuffer entry 224 val out = Decoupled(new VecPipeBundle(isVStore))// to scala pipeline 225 val vstd = OptionWrapper(isVStore, Valid(new MemExuOutput(isVector = true))) 226} 227 228class VSplitPipelineIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{ 229 val redirect = Flipped(ValidIO(new Redirect)) 230 val in = Flipped(Decoupled(new MemExuInput(isVector = true))) 231 val toMergeBuffer = new ToMergeBufferIO(isVStore) // req mergebuffer entry, inactive elem issue 232 val out = Decoupled(new VLSBundle())// to split buffer 233} 234 235class VSplitBufferIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{ 236 val redirect = Flipped(ValidIO(new Redirect)) 237 val in = Flipped(Decoupled(new VLSBundle())) 238 val out = Decoupled(new VecPipeBundle(isVStore))//to scala pipeline 239 val vstd = OptionWrapper(isVStore, ValidIO(new MemExuOutput(isVector = true))) 240} 241 242class VMergeBufferIO(isVStore : Boolean=false)(implicit p: Parameters) extends VLSUBundle{ 243 val redirect = Flipped(ValidIO(new Redirect)) 244 val fromPipeline = if(isVStore) Vec(StorePipelineWidth, Flipped(DecoupledIO(new VecPipelineFeedbackIO(isVStore)))) else Vec(LoadPipelineWidth, Flipped(DecoupledIO(new VecPipelineFeedbackIO(isVStore)))) 245 val fromSplit = if(isVStore) Vec(VecStorePipelineWidth, new FromSplitIO) else Vec(VecLoadPipelineWidth, new FromSplitIO) // req mergebuffer entry, inactive elem issue 246 val uopWriteback = if(isVStore) Vec(VSUopWritebackWidth, DecoupledIO(new MemExuOutput(isVector = true))) else Vec(VLUopWritebackWidth, DecoupledIO(new MemExuOutput(isVector = true))) 247 val toSplit = if(isVStore) Vec(VecStorePipelineWidth, ValidIO(new FeedbackToSplitIO)) else Vec(VecLoadPipelineWidth, ValidIO(new FeedbackToSplitIO)) // for inorder inst 248 val toLsq = if(isVStore) Vec(VSUopWritebackWidth, ValidIO(new FeedbackToLsqIO)) else Vec(VLUopWritebackWidth, ValidIO(new FeedbackToLsqIO)) // for lsq deq 249 val feedback = if(isVStore) Vec(VSUopWritebackWidth, ValidIO(new RSFeedback(isVector = true))) else Vec(VLUopWritebackWidth, ValidIO(new RSFeedback(isVector = true)))//for rs replay 250} 251 252class VSegmentUnitIO(implicit p: Parameters) extends VLSUBundle{ 253 val in = Flipped(Decoupled(new MemExuInput(isVector = true))) // from iq 254 val uopwriteback = DecoupledIO(new MemExuOutput(isVector = true)) // writeback data 255 val rdcache = new DCacheLoadIO // read dcache port 256 val sbuffer = Decoupled(new DCacheWordReqWithVaddrAndPfFlag) 257 val vecDifftestInfo = Decoupled(new DynInst) // to sbuffer 258 val dtlb = new TlbRequestIO(2) 259 val pmpResp = Flipped(new PMPRespBundle()) 260 val flush_sbuffer = new SbufferFlushBundle 261 val feedback = ValidIO(new RSFeedback(isVector = true)) 262 val redirect = Flipped(ValidIO(new Redirect)) 263 val exceptionInfo = ValidIO(new FeedbackToLsqIO) 264 //trigger 265 val fromCsrTrigger = Input(new CsrTriggerBundle) 266} 267 268class VfofDataBuffIO(implicit p: Parameters) extends VLSUBundle{ 269 val redirect = Flipped(ValidIO(new Redirect)) 270 val in = Vec(VecLoadPipelineWidth, Flipped(Decoupled(new MemExuInput(isVector=true)))) 271 val mergeUopWriteback = Vec(VLUopWritebackWidth, Flipped(DecoupledIO(new MemExuOutput(isVector=true)))) 272 273 val uopWriteback = DecoupledIO(new MemExuOutput(isVector = true)) 274}