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