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} 71 72object VSFQFeedbackType { 73 val tlbMiss = 0.U(3.W) 74 val mshrFull = 1.U(3.W) 75 val dataInvalid = 2.U(3.W) 76 val bankConflict = 3.U(3.W) 77 val ldVioCheckRedo = 4.U(3.W) 78 val feedbackInvalid = 7.U(3.W) 79 80 def apply() = UInt(3.W) 81} 82 83class VSFQFeedback (implicit p: Parameters) extends XSBundle { 84 // val flowPtr = new VsFlowPtr 85 val hit = Bool() 86 //val flushState = Bool() 87 val sourceType = VSFQFeedbackType() 88 //val dataInvalidSqIdx = new SqPtr 89 val paddr = UInt(PAddrBits.W) 90 val mmio = Bool() 91 val atomic = Bool() 92 val exceptionVec = ExceptionVec() 93} 94 95class VecPipelineFeedbackIO(isVStore: Boolean=false) (implicit p: Parameters) extends VLSUBundle { 96 val mBIndex = if(isVStore) UInt(vsmBindexBits.W) else UInt(vlmBindexBits.W) 97 val hit = Bool() 98 val isvec = Bool() 99 val flushState = Bool() 100 val sourceType = VSFQFeedbackType() 101 //val dataInvalidSqIdx = new SqPtr 102 //val paddr = UInt(PAddrBits.W) 103 val mmio = Bool() 104 //val atomic = Bool() 105 val exceptionVec = ExceptionVec() 106 val vaddr = UInt(VAddrBits.W) 107 //val vec = new OnlyVecExuOutput 108 // feedback 109 val vecFeedback = Bool() 110 111 val usSecondInv = Bool() // only for unit stride, second flow is Invalid 112 val elemIdx = UInt(elemIdxBits.W) // element index 113 val mask = UInt(VLENB.W) 114 val alignedType = UInt(alignTypeBits.W) 115 // for load 116 val reg_offset = OptionWrapper(!isVStore, UInt(vOffsetBits.W)) 117 val elemIdxInsideVd = OptionWrapper(!isVStore, UInt(elemIdxBits.W)) // element index in scope of vd 118 val vecdata = OptionWrapper(!isVStore, UInt(VLEN.W)) 119} 120 121class VecPipeBundle(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle { 122 val vaddr = UInt(VAddrBits.W) 123 val mask = UInt(VLENB.W) 124 val isvec = Bool() 125 val uop_unit_stride_fof = Bool() 126 val reg_offset = UInt(vOffsetBits.W) 127 val alignedType = UInt(alignTypeBits.W) 128 val vecActive = Bool() // 1: vector active element, 0: vector not active element 129 val is_first_ele = Bool() 130 val isFirstIssue = Bool() 131 132 val uop = new DynInst 133 134 val usSecondInv = Bool() // only for unit stride, second flow is Invalid 135 val mBIndex = if(isVStore) UInt(vsmBindexBits.W) else UInt(vlmBindexBits.W) 136 val elemIdx = UInt(elemIdxBits.W) 137 val elemIdxInsideVd = UInt(elemIdxBits.W) // only use in unit-stride 138} 139 140object VecFeedbacks { 141 // need to invalid lsq entry 142 val FLUSH = 0 143 // merge buffer commits one uop 144 val COMMIT = 1 145 // last uop of an inst, sq can commit 146 val LAST = 2 147 // total feedbacks 148 val allFeedbacks = 3 149} 150 151class MergeBufferReq(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{ 152 val mask = UInt(VLENB.W) 153 val vaddr = UInt(VAddrBits.W) 154 val flowNum = UInt(flowIdxBits.W) 155 val uop = new DynInst 156 val data = UInt(VLEN.W) 157 val vdIdx = UInt(3.W) 158 val fof = Bool() 159 val vlmax = UInt(elemIdxBits.W) 160 // val vdOffset = UInt(vdOffset.W) 161} 162 163class MergeBufferResp(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{ 164 val mBIndex = if(isVStore) UInt(vsmBindexBits.W) else UInt(vlmBindexBits.W) 165 val fail = Bool() 166} 167 168class ToMergeBufferIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{ 169 val req = DecoupledIO(new MergeBufferReq(isVStore)) 170 val resp = Flipped(ValidIO(new MergeBufferResp(isVStore))) 171 // val issueInactive = ValidIO 172} 173 174class FromSplitIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{ 175 val req = Flipped(DecoupledIO(new MergeBufferReq(isVStore))) 176 val resp = ValidIO(new MergeBufferResp(isVStore)) 177 // val issueInactive = Flipped(ValidIO()) 178} 179 180class FeedbackToSplitIO(implicit p: Parameters) extends VLSUBundle{ 181 val elemWriteback = Bool() 182} 183 184class FeedbackToLsqIO(implicit p: Parameters) extends VLSUBundle{ 185 val robidx = new RobPtr 186 val uopidx = UopIdx() 187 val vaddr = UInt(VAddrBits.W) 188 val feedback = Vec(VecFeedbacks.allFeedbacks, Bool()) 189 // for exception 190 val vstart = UInt(elemIdxBits.W) 191 val vl = UInt(elemIdxBits.W) 192 val exceptionVec = ExceptionVec() 193 194 def isFlush = feedback(VecFeedbacks.FLUSH) 195 def isCommit = feedback(VecFeedbacks.COMMIT) 196 def isLast = feedback(VecFeedbacks.LAST) 197} 198 199class VSplitIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{ 200 val redirect = Flipped(ValidIO(new Redirect)) 201 val in = Flipped(Decoupled(new MemExuInput(isVector = true))) // from iq 202 val toMergeBuffer = new ToMergeBufferIO(isVStore) //to merge buffer req mergebuffer entry 203 val out = Decoupled(new VecPipeBundle(isVStore))// to scala pipeline 204 val vstd = OptionWrapper(isVStore, Valid(new MemExuOutput(isVector = true))) 205} 206 207class VSplitPipelineIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{ 208 val redirect = Flipped(ValidIO(new Redirect)) 209 val in = Flipped(Decoupled(new MemExuInput(isVector = true))) 210 val toMergeBuffer = new ToMergeBufferIO(isVStore) // req mergebuffer entry, inactive elem issue 211 val out = Decoupled(new VLSBundle())// to split buffer 212} 213 214class VSplitBufferIO(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUBundle{ 215 val redirect = Flipped(ValidIO(new Redirect)) 216 val in = Flipped(Decoupled(new VLSBundle())) 217 val out = Decoupled(new VecPipeBundle(isVStore))//to scala pipeline 218 val vstd = OptionWrapper(isVStore, ValidIO(new MemExuOutput(isVector = true))) 219} 220 221class VMergeBufferIO(isVStore : Boolean=false)(implicit p: Parameters) extends VLSUBundle{ 222 val redirect = Flipped(ValidIO(new Redirect)) 223 val fromPipeline = if(isVStore) Vec(StorePipelineWidth, Flipped(DecoupledIO(new VecPipelineFeedbackIO(isVStore)))) else Vec(LoadPipelineWidth, Flipped(DecoupledIO(new VecPipelineFeedbackIO(isVStore)))) 224 val fromSplit = if(isVStore) Vec(VecStorePipelineWidth, new FromSplitIO) else Vec(VecLoadPipelineWidth, new FromSplitIO) // req mergebuffer entry, inactive elem issue 225 val uopWriteback = if(isVStore) Vec(VSUopWritebackWidth, DecoupledIO(new MemExuOutput(isVector = true))) else Vec(VLUopWritebackWidth, DecoupledIO(new MemExuOutput(isVector = true))) 226 val toSplit = if(isVStore) Vec(VecStorePipelineWidth, ValidIO(new FeedbackToSplitIO)) else Vec(VecLoadPipelineWidth, ValidIO(new FeedbackToSplitIO)) // for inorder inst 227 val toLsq = if(isVStore) Vec(VSUopWritebackWidth, ValidIO(new FeedbackToLsqIO)) else Vec(VLUopWritebackWidth, ValidIO(new FeedbackToLsqIO)) // for lsq deq 228 val feedback = if(isVStore) Vec(VSUopWritebackWidth, ValidIO(new RSFeedback(isVector = true))) else Vec(VLUopWritebackWidth, ValidIO(new RSFeedback(isVector = true)))//for rs replay 229} 230 231class VSegmentUnitIO(implicit p: Parameters) extends VLSUBundle{ 232 val in = Flipped(Decoupled(new MemExuInput(isVector = true))) // from iq 233 val uopwriteback = DecoupledIO(new MemExuOutput(isVector = true)) // writeback data 234 val rdcache = new DCacheLoadIO // read dcache port 235 val sbuffer = Decoupled(new DCacheWordReqWithVaddrAndPfFlag) 236 val dtlb = new TlbRequestIO(2) 237 val pmpResp = Flipped(new PMPRespBundle()) 238 val flush_sbuffer = new SbufferFlushBundle 239 val feedback = ValidIO(new RSFeedback(isVector = true)) 240 val redirect = Flipped(ValidIO(new Redirect)) 241 val exceptionInfo = ValidIO(new FeedbackToLsqIO) 242}