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