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