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.ExceptionNO._ 25import xiangshan._ 26import xiangshan.backend.Bundles.{DynInst, MemExuInput, MemExuOutput} 27import xiangshan.backend.fu.PMPRespBundle 28import xiangshan.backend.fu.FuConfig._ 29import xiangshan.backend.ctrlblock.{DebugLsInfoBundle, LsTopdownInfo} 30import xiangshan.backend.rob.RobPtr 31import xiangshan.backend.ctrlblock.DebugLsInfoBundle 32import xiangshan.backend.fu.util.SdtrigExt 33 34import xiangshan.cache._ 35import xiangshan.cache.wpu.ReplayCarry 36import xiangshan.cache.mmu._ 37import xiangshan.mem.mdp._ 38 39class LoadToLsqReplayIO(implicit p: Parameters) extends XSBundle 40 with HasDCacheParameters 41 with HasTlbConst 42{ 43 // mshr refill index 44 val mshr_id = UInt(log2Up(cfg.nMissEntries).W) 45 // get full data from store queue and sbuffer 46 val full_fwd = Bool() 47 // wait for data from store inst's store queue index 48 val data_inv_sq_idx = new SqPtr 49 // wait for address from store queue index 50 val addr_inv_sq_idx = new SqPtr 51 // replay carry 52 val rep_carry = new ReplayCarry(nWays) 53 // data in last beat 54 val last_beat = Bool() 55 // replay cause 56 val cause = Vec(LoadReplayCauses.allCauses, Bool()) 57 // performance debug information 58 val debug = new PerfDebugInfo 59 // tlb hint 60 val tlb_id = UInt(log2Up(loadfiltersize).W) 61 val tlb_full = Bool() 62 63 // alias 64 def mem_amb = cause(LoadReplayCauses.C_MA) 65 def tlb_miss = cause(LoadReplayCauses.C_TM) 66 def fwd_fail = cause(LoadReplayCauses.C_FF) 67 def dcache_rep = cause(LoadReplayCauses.C_DR) 68 def dcache_miss = cause(LoadReplayCauses.C_DM) 69 def wpu_fail = cause(LoadReplayCauses.C_WF) 70 def bank_conflict = cause(LoadReplayCauses.C_BC) 71 def rar_nack = cause(LoadReplayCauses.C_RAR) 72 def raw_nack = cause(LoadReplayCauses.C_RAW) 73 def nuke = cause(LoadReplayCauses.C_NK) 74 def need_rep = cause.asUInt.orR 75} 76 77 78class LoadToLsqIO(implicit p: Parameters) extends XSBundle { 79 val ldin = DecoupledIO(new LqWriteBundle) 80 val uncache = Flipped(DecoupledIO(new MemExuOutput)) 81 val ld_raw_data = Input(new LoadDataFromLQBundle) 82 val forward = new PipeLoadForwardQueryIO 83 val stld_nuke_query = new LoadNukeQueryIO 84 val ldld_nuke_query = new LoadNukeQueryIO 85 val trigger = Flipped(new LqTriggerIO) 86} 87 88class LoadToLoadIO(implicit p: Parameters) extends XSBundle { 89 val valid = Bool() 90 val data = UInt(XLEN.W) // load to load fast path is limited to ld (64 bit) used as vaddr src1 only 91 val dly_ld_err = Bool() 92} 93 94class LoadUnitTriggerIO(implicit p: Parameters) extends XSBundle { 95 val tdata2 = Input(UInt(64.W)) 96 val matchType = Input(UInt(2.W)) 97 val tEnable = Input(Bool()) // timing is calculated before this 98 val addrHit = Output(Bool()) 99} 100 101class LoadUnit(implicit p: Parameters) extends XSModule 102 with HasLoadHelper 103 with HasPerfEvents 104 with HasDCacheParameters 105 with HasCircularQueuePtrHelper 106 with HasVLSUParameters 107 with SdtrigExt 108{ 109 val io = IO(new Bundle() { 110 // control 111 val redirect = Flipped(ValidIO(new Redirect)) 112 val csrCtrl = Flipped(new CustomCSRCtrlIO) 113 114 // int issue path 115 val ldin = Flipped(Decoupled(new MemExuInput)) 116 val ldout = Decoupled(new MemExuOutput) 117 118 // vec issue path 119 val vecldin = Flipped(Decoupled(new VecPipeBundle)) 120 val vecldout = Decoupled(new VecPipelineFeedbackIO(isVStore = false)) 121 122 // data path 123 val tlb = new TlbRequestIO(2) 124 val pmp = Flipped(new PMPRespBundle()) // arrive same to tlb now 125 val dcache = new DCacheLoadIO 126 val sbuffer = new LoadForwardQueryIO 127 val lsq = new LoadToLsqIO 128 val tl_d_channel = Input(new DcacheToLduForwardIO) 129 val forward_mshr = Flipped(new LduToMissqueueForwardIO) 130 val refill = Flipped(ValidIO(new Refill)) 131 val l2_hint = Input(Valid(new L2ToL1Hint)) 132 val tlb_hint = Flipped(new TlbHintReq) 133 // fast wakeup 134 // TODO: implement vector fast wakeup 135 val fast_uop = ValidIO(new DynInst) // early wakeup signal generated in load_s1, send to RS in load_s2 136 137 // trigger 138 val trigger = Vec(TriggerNum, new LoadUnitTriggerIO) 139 140 // prefetch 141 val prefetch_train = ValidIO(new LdPrefetchTrainBundle()) // provide prefetch info to sms 142 val prefetch_train_l1 = ValidIO(new LdPrefetchTrainBundle()) // provide prefetch info to stream & stride 143 val prefetch_req = Flipped(ValidIO(new L1PrefetchReq)) // hardware prefetch to l1 cache req 144 val canAcceptLowConfPrefetch = Output(Bool()) 145 val canAcceptHighConfPrefetch = Output(Bool()) 146 147 // load to load fast path 148 val l2l_fwd_in = Input(new LoadToLoadIO) 149 val l2l_fwd_out = Output(new LoadToLoadIO) 150 151 val ld_fast_match = Input(Bool()) 152 val ld_fast_fuOpType = Input(UInt()) 153 val ld_fast_imm = Input(UInt(12.W)) 154 155 // rs feedback 156 val wakeup = ValidIO(new DynInst) 157 val feedback_fast = ValidIO(new RSFeedback) // stage 2 158 val feedback_slow = ValidIO(new RSFeedback) // stage 3 159 val ldCancel = Output(new LoadCancelIO()) // use to cancel the uops waked by this load, and cancel load 160 161 // load ecc error 162 val s3_dly_ld_err = Output(Bool()) // Note that io.s3_dly_ld_err and io.lsq.s3_dly_ld_err is different 163 164 // schedule error query 165 val stld_nuke_query = Flipped(Vec(StorePipelineWidth, Valid(new StoreNukeQueryIO))) 166 167 // queue-based replay 168 val replay = Flipped(Decoupled(new LsPipelineBundle)) 169 val lq_rep_full = Input(Bool()) 170 171 // misc 172 val s2_ptr_chasing = Output(Bool()) // provide right pc for hw prefetch 173 174 // Load fast replay path 175 val fast_rep_in = Flipped(Decoupled(new LqWriteBundle)) 176 val fast_rep_out = Decoupled(new LqWriteBundle) 177 178 // Load RAR rollback 179 val rollback = Valid(new Redirect) 180 181 // perf 182 val debug_ls = Output(new DebugLsInfoBundle) 183 val lsTopdownInfo = Output(new LsTopdownInfo) 184 val correctMissTrain = Input(Bool()) 185 }) 186 187 val s1_ready, s2_ready, s3_ready = WireInit(false.B) 188 189 // Pipeline 190 // -------------------------------------------------------------------------------- 191 // stage 0 192 // -------------------------------------------------------------------------------- 193 // generate addr, use addr to query DCache and DTLB 194 val s0_valid = Wire(Bool()) 195 val s0_mmio_select = Wire(Bool()) 196 val s0_kill = Wire(Bool()) 197 val s0_can_go = s1_ready 198 val s0_fire = s0_valid && s0_can_go 199 val s0_mmio_fire = s0_mmio_select && s0_can_go 200 val s0_out = Wire(new LqWriteBundle) 201 202 // flow source bundle 203 class FlowSource extends Bundle { 204 val vaddr = UInt(VAddrBits.W) 205 val mask = UInt((VLEN/8).W) 206 val uop = new DynInst 207 val try_l2l = Bool() 208 val has_rob_entry = Bool() 209 val rsIdx = UInt(log2Up(MemIQSizeMax).W) 210 val rep_carry = new ReplayCarry(nWays) 211 val mshrid = UInt(log2Up(cfg.nMissEntries).W) 212 val isFirstIssue = Bool() 213 val fast_rep = Bool() 214 val ld_rep = Bool() 215 val l2l_fwd = Bool() 216 val prf = Bool() 217 val prf_rd = Bool() 218 val prf_wr = Bool() 219 val sched_idx = UInt(log2Up(LoadQueueReplaySize+1).W) 220 // Record the issue port idx of load issue queue. This signal is used by load cancel. 221 val deqPortIdx = UInt(log2Ceil(LoadPipelineWidth).W) 222 // vec only 223 val isvec = Bool() 224 val is128bit = Bool() 225 val uop_unit_stride_fof = Bool() 226 val reg_offset = UInt(vOffsetBits.W) 227 val vecActive = Bool() // 1: vector active element or scala mem operation, 0: vector not active element 228 val is_first_ele = Bool() 229 // val flowPtr = new VlflowPtr 230 val usSecondInv = Bool() 231 val mbIndex = UInt(vlmBindexBits.W) 232 } 233 val s0_sel_src = Wire(new FlowSource) 234 235 // load flow select/gen 236 // src0: super load replayed by LSQ (cache miss replay) (io.replay) 237 // src1: fast load replay (io.fast_rep_in) 238 // src2: mmio (io.lsq.uncache) 239 // src3: load replayed by LSQ (io.replay) 240 // src4: hardware prefetch from prefetchor (high confidence) (io.prefetch) 241 // NOTE: Now vec/int loads are sent from same RS 242 // A vec load will be splited into multiple uops, 243 // so as long as one uop is issued, 244 // the other uops should have higher priority 245 // src5: vec read from RS (io.vecldin) 246 // src6: int read / software prefetch first issue from RS (io.in) 247 // src7: load try pointchaising when no issued or replayed load (io.fastpath) 248 // src8: hardware prefetch from prefetchor (high confidence) (io.prefetch) 249 // priority: high to low 250 val s0_rep_stall = io.ldin.valid && isAfter(io.replay.bits.uop.robIdx, io.ldin.bits.uop.robIdx) 251 val s0_super_ld_rep_valid = io.replay.valid && io.replay.bits.forward_tlDchannel 252 val s0_ld_fast_rep_valid = io.fast_rep_in.valid 253 val s0_ld_mmio_valid = io.lsq.uncache.valid 254 val s0_ld_rep_valid = io.replay.valid && !io.replay.bits.forward_tlDchannel && !s0_rep_stall 255 val s0_high_conf_prf_valid = io.prefetch_req.valid && io.prefetch_req.bits.confidence > 0.U 256 val s0_vec_iss_valid = io.vecldin.valid 257 val s0_int_iss_valid = io.ldin.valid // int flow first issue or software prefetch 258 val s0_l2l_fwd_valid = io.l2l_fwd_in.valid 259 val s0_low_conf_prf_valid = io.prefetch_req.valid && io.prefetch_req.bits.confidence === 0.U 260 val s0_is128bit = is128Bit(io.vecldin.bits.alignedType) && io.vecldin.valid 261 dontTouch(s0_super_ld_rep_valid) 262 dontTouch(s0_ld_fast_rep_valid) 263 dontTouch(s0_ld_mmio_valid) 264 dontTouch(s0_ld_rep_valid) 265 dontTouch(s0_high_conf_prf_valid) 266 dontTouch(s0_vec_iss_valid) 267 dontTouch(s0_int_iss_valid) 268 dontTouch(s0_l2l_fwd_valid) 269 dontTouch(s0_low_conf_prf_valid) 270 271 // load flow source ready 272 val s0_super_ld_rep_ready = WireInit(true.B) 273 val s0_ld_fast_rep_ready = !s0_super_ld_rep_valid 274 val s0_ld_mmio_ready = !s0_super_ld_rep_valid && 275 !s0_ld_fast_rep_valid 276 val s0_ld_rep_ready = !s0_super_ld_rep_valid && 277 !s0_ld_fast_rep_valid && 278 !s0_ld_mmio_valid 279 val s0_high_conf_prf_ready = !s0_super_ld_rep_valid && 280 !s0_ld_fast_rep_valid && 281 !s0_ld_mmio_valid && 282 !s0_ld_rep_valid 283 284 val s0_vec_iss_ready = !s0_super_ld_rep_valid && 285 !s0_ld_fast_rep_valid && 286 !s0_ld_mmio_valid && 287 !s0_ld_rep_valid && 288 !s0_high_conf_prf_valid 289 290 val s0_int_iss_ready = !s0_super_ld_rep_valid && 291 !s0_ld_fast_rep_valid && 292 !s0_ld_mmio_valid && 293 !s0_ld_rep_valid && 294 !s0_high_conf_prf_valid && 295 !s0_vec_iss_valid 296 297 val s0_l2l_fwd_ready = !s0_super_ld_rep_valid && 298 !s0_ld_fast_rep_valid && 299 !s0_ld_mmio_valid && 300 !s0_ld_rep_valid && 301 !s0_high_conf_prf_valid && 302 !s0_int_iss_valid && 303 !s0_vec_iss_valid 304 305 val s0_low_conf_prf_ready = !s0_super_ld_rep_valid && 306 !s0_ld_fast_rep_valid && 307 !s0_ld_mmio_valid && 308 !s0_ld_rep_valid && 309 !s0_high_conf_prf_valid && 310 !s0_int_iss_valid && 311 !s0_vec_iss_valid && 312 !s0_l2l_fwd_valid 313 dontTouch(s0_super_ld_rep_ready) 314 dontTouch(s0_ld_fast_rep_ready) 315 dontTouch(s0_ld_mmio_ready) 316 dontTouch(s0_ld_rep_ready) 317 dontTouch(s0_high_conf_prf_ready) 318 dontTouch(s0_vec_iss_ready) 319 dontTouch(s0_int_iss_ready) 320 dontTouch(s0_l2l_fwd_ready) 321 dontTouch(s0_low_conf_prf_ready) 322 323 // load flow source select (OH) 324 val s0_super_ld_rep_select = s0_super_ld_rep_valid && s0_super_ld_rep_ready 325 val s0_ld_fast_rep_select = s0_ld_fast_rep_valid && s0_ld_fast_rep_ready 326 val s0_ld_mmio_select = s0_ld_mmio_valid && s0_ld_mmio_ready 327 val s0_ld_rep_select = s0_ld_rep_valid && s0_ld_rep_ready 328 val s0_hw_prf_select = s0_high_conf_prf_ready && s0_high_conf_prf_valid || 329 s0_low_conf_prf_ready && s0_low_conf_prf_valid 330 val s0_vec_iss_select = s0_vec_iss_ready && s0_vec_iss_valid 331 val s0_int_iss_select = s0_int_iss_ready && s0_int_iss_valid 332 val s0_l2l_fwd_select = s0_l2l_fwd_ready && s0_l2l_fwd_valid 333 dontTouch(s0_super_ld_rep_select) 334 dontTouch(s0_ld_fast_rep_select) 335 dontTouch(s0_ld_mmio_select) 336 dontTouch(s0_ld_rep_select) 337 dontTouch(s0_hw_prf_select) 338 dontTouch(s0_vec_iss_select) 339 dontTouch(s0_int_iss_select) 340 dontTouch(s0_l2l_fwd_select) 341 342 s0_valid := (s0_super_ld_rep_valid || 343 s0_ld_fast_rep_valid || 344 s0_ld_rep_valid || 345 s0_high_conf_prf_valid || 346 s0_vec_iss_valid || 347 s0_int_iss_valid || 348 s0_l2l_fwd_valid || 349 s0_low_conf_prf_valid) && !s0_ld_mmio_select && io.dcache.req.ready && !s0_kill 350 351 s0_mmio_select := s0_ld_mmio_select && !s0_kill 352 353 // which is S0's out is ready and dcache is ready 354 val s0_try_ptr_chasing = s0_l2l_fwd_select 355 val s0_do_try_ptr_chasing = s0_try_ptr_chasing && s0_can_go && io.dcache.req.ready 356 val s0_ptr_chasing_vaddr = io.l2l_fwd_in.data(5, 0) +& io.ld_fast_imm(5, 0) 357 val s0_ptr_chasing_canceled = WireInit(false.B) 358 s0_kill := s0_ptr_chasing_canceled 359 360 // prefetch related ctrl signal 361 io.canAcceptLowConfPrefetch := s0_low_conf_prf_ready 362 io.canAcceptHighConfPrefetch := s0_high_conf_prf_ready 363 364 // query DTLB 365 io.tlb.req.valid := s0_valid 366 io.tlb.req.bits.cmd := Mux(s0_sel_src.prf, 367 Mux(s0_sel_src.prf_wr, TlbCmd.write, TlbCmd.read), 368 TlbCmd.read 369 ) 370 io.tlb.req.bits.vaddr := Mux(s0_hw_prf_select, io.prefetch_req.bits.paddr, s0_sel_src.vaddr) 371 io.tlb.req.bits.size := Mux(s0_sel_src.isvec, io.vecldin.bits.alignedType(2,0), LSUOpType.size(s0_sel_src.uop.fuOpType)) // FIXME : currently not use, 128 bit load will error if use it 372 io.tlb.req.bits.kill := s0_kill 373 io.tlb.req.bits.memidx.is_ld := true.B 374 io.tlb.req.bits.memidx.is_st := false.B 375 io.tlb.req.bits.memidx.idx := s0_sel_src.uop.lqIdx.value 376 io.tlb.req.bits.debug.robIdx := s0_sel_src.uop.robIdx 377 io.tlb.req.bits.no_translate := s0_hw_prf_select // hw b.reqetch addr does not need to be translated 378 io.tlb.req.bits.debug.pc := s0_sel_src.uop.pc 379 io.tlb.req.bits.debug.isFirstIssue := s0_sel_src.isFirstIssue 380 381 // query DCache 382 io.dcache.req.valid := s0_valid 383 io.dcache.req.bits.cmd := Mux(s0_sel_src.prf_rd, 384 MemoryOpConstants.M_PFR, 385 Mux(s0_sel_src.prf_wr, MemoryOpConstants.M_PFW, MemoryOpConstants.M_XRD) 386 ) 387 io.dcache.req.bits.vaddr := s0_sel_src.vaddr 388 io.dcache.req.bits.mask := s0_sel_src.mask 389 io.dcache.req.bits.data := DontCare 390 io.dcache.req.bits.isFirstIssue := s0_sel_src.isFirstIssue 391 io.dcache.req.bits.instrtype := Mux(s0_sel_src.prf, DCACHE_PREFETCH_SOURCE.U, LOAD_SOURCE.U) 392 io.dcache.req.bits.debug_robIdx := s0_sel_src.uop.robIdx.value 393 io.dcache.req.bits.replayCarry := s0_sel_src.rep_carry 394 io.dcache.req.bits.id := DontCare // TODO: update cache meta 395 io.dcache.pf_source := Mux(s0_hw_prf_select, io.prefetch_req.bits.pf_source.value, L1_HW_PREFETCH_NULL) 396 io.dcache.is128Req := s0_is128bit && s0_vec_iss_select 397 398 // load flow priority mux 399 def fromNullSource(): FlowSource = { 400 val out = WireInit(0.U.asTypeOf(new FlowSource)) 401 out 402 } 403 404 def fromFastReplaySource(src: LqWriteBundle): FlowSource = { 405 val out = WireInit(0.U.asTypeOf(new FlowSource)) 406 out.vaddr := src.vaddr 407 out.mask := src.mask 408 out.uop := src.uop 409 out.try_l2l := false.B 410 out.has_rob_entry := src.hasROBEntry 411 out.rep_carry := src.rep_info.rep_carry 412 out.mshrid := src.rep_info.mshr_id 413 out.rsIdx := src.rsIdx 414 out.isFirstIssue := false.B 415 out.fast_rep := true.B 416 out.ld_rep := src.isLoadReplay 417 out.l2l_fwd := false.B 418 out.prf := LSUOpType.isPrefetch(src.uop.fuOpType) 419 out.prf_rd := src.uop.fuOpType === LSUOpType.prefetch_r 420 out.prf_wr := src.uop.fuOpType === LSUOpType.prefetch_w 421 out.sched_idx := src.schedIndex 422 out.isvec := src.isvec 423 out.is128bit := src.is128bit 424 out.uop_unit_stride_fof := src.uop_unit_stride_fof 425 out.reg_offset := src.reg_offset 426 out.vecActive := src.vecActive 427 out.is_first_ele := src.is_first_ele 428 out.usSecondInv := src.usSecondInv 429 out.mbIndex := src.mbIndex 430 out 431 } 432 433 // TODO: implement vector mmio 434 def fromMmioSource(src: MemExuOutput) = { 435 val out = WireInit(0.U.asTypeOf(new FlowSource)) 436 out.vaddr := 0.U 437 out.mask := 0.U 438 out.uop := src.uop 439 out.try_l2l := false.B 440 out.has_rob_entry := false.B 441 out.rsIdx := 0.U 442 out.rep_carry := 0.U.asTypeOf(out.rep_carry) 443 out.mshrid := 0.U 444 out.isFirstIssue := false.B 445 out.fast_rep := false.B 446 out.ld_rep := false.B 447 out.l2l_fwd := false.B 448 out.prf := false.B 449 out.prf_rd := false.B 450 out.prf_wr := false.B 451 out.sched_idx := 0.U 452 out.vecActive := true.B 453 out 454 } 455 456 def fromNormalReplaySource(src: LsPipelineBundle): FlowSource = { 457 val out = WireInit(0.U.asTypeOf(new FlowSource)) 458 out.vaddr := src.vaddr 459 out.mask := Mux(src.isvec, src.mask, genVWmask(src.vaddr, src.uop.fuOpType(1, 0))) 460 out.uop := src.uop 461 out.try_l2l := false.B 462 out.has_rob_entry := true.B 463 out.rsIdx := src.rsIdx 464 out.rep_carry := src.replayCarry 465 out.mshrid := src.mshrid 466 out.isFirstIssue := false.B 467 out.fast_rep := false.B 468 out.ld_rep := true.B 469 out.l2l_fwd := false.B 470 out.prf := LSUOpType.isPrefetch(src.uop.fuOpType) 471 out.prf_rd := src.uop.fuOpType === LSUOpType.prefetch_r 472 out.prf_wr := src.uop.fuOpType === LSUOpType.prefetch_w 473 out.sched_idx := src.schedIndex 474 out.isvec := src.isvec 475 out.is128bit := src.is128bit 476 out.uop_unit_stride_fof := src.uop_unit_stride_fof 477 out.reg_offset := src.reg_offset 478 out.vecActive := src.vecActive 479 out.is_first_ele := src.is_first_ele 480 out.usSecondInv := src.usSecondInv 481 out.mbIndex := src.mbIndex 482 out 483 } 484 485 // TODO: implement vector prefetch 486 def fromPrefetchSource(src: L1PrefetchReq): FlowSource = { 487 val out = WireInit(0.U.asTypeOf(new FlowSource)) 488 out.vaddr := src.getVaddr() 489 out.mask := 0.U 490 out.uop := DontCare 491 out.try_l2l := false.B 492 out.has_rob_entry := false.B 493 out.rsIdx := 0.U 494 out.rep_carry := 0.U.asTypeOf(out.rep_carry) 495 out.mshrid := 0.U 496 out.isFirstIssue := false.B 497 out.fast_rep := false.B 498 out.ld_rep := false.B 499 out.l2l_fwd := false.B 500 out.prf := true.B 501 out.prf_rd := !src.is_store 502 out.prf_wr := src.is_store 503 out.sched_idx := 0.U 504 out 505 } 506 507 def fromVecIssueSource(src: VecPipeBundle): FlowSource = { 508 val out = WireInit(0.U.asTypeOf(new FlowSource)) 509 out.vaddr := src.vaddr 510 out.mask := src.mask 511 out.uop := src.uop 512 out.try_l2l := false.B 513 out.has_rob_entry := true.B 514 // TODO: VLSU, implement vector feedback 515 out.rsIdx := 0.U 516 // TODO: VLSU, implement replay carry 517 out.rep_carry := 0.U.asTypeOf(out.rep_carry) 518 out.mshrid := 0.U 519 // TODO: VLSU, implement first issue 520// out.isFirstIssue := src.isFirstIssue 521 out.fast_rep := false.B 522 out.ld_rep := false.B 523 out.l2l_fwd := false.B 524 out.prf := false.B 525 out.prf_rd := false.B 526 out.prf_wr := false.B 527 out.sched_idx := 0.U 528 // Vector load interface 529 out.isvec := true.B 530 // vector loads only access a single element at a time, so 128-bit path is not used for now 531 out.is128bit := is128Bit(src.alignedType) 532 out.uop_unit_stride_fof := src.uop_unit_stride_fof 533 // out.rob_idx_valid := src.rob_idx_valid 534 // out.inner_idx := src.inner_idx 535 // out.rob_idx := src.rob_idx 536 out.reg_offset := src.reg_offset 537 // out.offset := src.offset 538 out.vecActive := src.vecActive 539 out.is_first_ele := src.is_first_ele 540 // out.flowPtr := src.flowPtr 541 out.usSecondInv := src.usSecondInv 542 out.mbIndex := src.mBIndex 543 out 544 } 545 546 def fromIntIssueSource(src: MemExuInput): FlowSource = { 547 val out = WireInit(0.U.asTypeOf(new FlowSource)) 548 out.vaddr := src.src(0) + SignExt(src.uop.imm(11, 0), VAddrBits) 549 out.mask := genVWmask(out.vaddr, src.uop.fuOpType(1,0)) 550 out.uop := src.uop 551 out.try_l2l := false.B 552 out.has_rob_entry := true.B 553 out.rsIdx := src.iqIdx 554 out.rep_carry := 0.U.asTypeOf(out.rep_carry) 555 out.mshrid := 0.U 556 out.isFirstIssue := true.B 557 out.fast_rep := false.B 558 out.ld_rep := false.B 559 out.l2l_fwd := false.B 560 out.prf := LSUOpType.isPrefetch(src.uop.fuOpType) 561 out.prf_rd := src.uop.fuOpType === LSUOpType.prefetch_r 562 out.prf_wr := src.uop.fuOpType === LSUOpType.prefetch_w 563 out.sched_idx := 0.U 564 out.vecActive := true.B // true for scala load 565 out 566 } 567 568 // TODO: implement vector l2l 569 def fromLoadToLoadSource(src: LoadToLoadIO): FlowSource = { 570 val out = WireInit(0.U.asTypeOf(new FlowSource)) 571 out.vaddr := Cat(src.data(XLEN-1, 6), s0_ptr_chasing_vaddr(5,0)) 572 out.mask := genVWmask(0.U, LSUOpType.ld) 573 // When there's no valid instruction from RS and LSQ, we try the load-to-load forwarding. 574 // Assume the pointer chasing is always ld. 575 out.uop.fuOpType := LSUOpType.ld 576 out.try_l2l := true.B 577 // we dont care out.isFirstIssue and out.rsIdx and s0_sqIdx in S0 when trying pointchasing 578 // because these signals will be updated in S1 579 out.has_rob_entry := false.B 580 out.rsIdx := 0.U 581 out.mshrid := 0.U 582 out.rep_carry := 0.U.asTypeOf(out.rep_carry) 583 out.isFirstIssue := true.B 584 out.fast_rep := false.B 585 out.ld_rep := false.B 586 out.l2l_fwd := true.B 587 out.prf := false.B 588 out.prf_rd := false.B 589 out.prf_wr := false.B 590 out.sched_idx := 0.U 591 out 592 } 593 594 // set default 595 val s0_src_selector = Seq( 596 s0_super_ld_rep_select, 597 s0_ld_fast_rep_select, 598 s0_ld_mmio_select, 599 s0_ld_rep_select, 600 s0_hw_prf_select, 601 s0_vec_iss_select, 602 s0_int_iss_select, 603 (if (EnableLoadToLoadForward) s0_l2l_fwd_select else true.B) 604 ) 605 val s0_src_format = Seq( 606 fromNormalReplaySource(io.replay.bits), 607 fromFastReplaySource(io.fast_rep_in.bits), 608 fromMmioSource(io.lsq.uncache.bits), 609 fromNormalReplaySource(io.replay.bits), 610 fromPrefetchSource(io.prefetch_req.bits), 611 fromVecIssueSource(io.vecldin.bits), 612 fromIntIssueSource(io.ldin.bits), 613 (if (EnableLoadToLoadForward) fromLoadToLoadSource(io.l2l_fwd_in) else fromNullSource()) 614 ) 615 s0_sel_src := ParallelPriorityMux(s0_src_selector, s0_src_format) 616 617 // address align check 618 val s0_addr_aligned = LookupTree(Mux(s0_sel_src.isvec, io.vecldin.bits.alignedType(1,0), s0_sel_src.uop.fuOpType(1, 0)), List( 619 "b00".U -> true.B, //b 620 "b01".U -> (s0_sel_src.vaddr(0) === 0.U), //h 621 "b10".U -> (s0_sel_src.vaddr(1, 0) === 0.U), //w 622 "b11".U -> (s0_sel_src.vaddr(2, 0) === 0.U) //d 623 )) 624 XSError(s0_sel_src.isvec && s0_sel_src.vaddr(3, 0) =/= 0.U && io.vecldin.bits.alignedType(2), "unit-stride 128 bit element is not aligned!") 625 626 // accept load flow if dcache ready (tlb is always ready) 627 // TODO: prefetch need writeback to loadQueueFlag 628 s0_out := DontCare 629 s0_out.rsIdx := s0_sel_src.rsIdx 630 s0_out.vaddr := s0_sel_src.vaddr 631 s0_out.mask := s0_sel_src.mask 632 s0_out.uop := s0_sel_src.uop 633 s0_out.isFirstIssue := s0_sel_src.isFirstIssue 634 s0_out.hasROBEntry := s0_sel_src.has_rob_entry 635 s0_out.isPrefetch := s0_sel_src.prf 636 s0_out.isHWPrefetch := s0_hw_prf_select 637 s0_out.isFastReplay := s0_sel_src.fast_rep 638 s0_out.isLoadReplay := s0_sel_src.ld_rep 639 s0_out.isFastPath := s0_sel_src.l2l_fwd 640 s0_out.mshrid := s0_sel_src.mshrid 641 s0_out.isvec := s0_sel_src.isvec 642 s0_out.is128bit := s0_sel_src.is128bit 643 s0_out.uop_unit_stride_fof := s0_sel_src.uop_unit_stride_fof 644 // s0_out.rob_idx_valid := s0_rob_idx_valid 645 // s0_out.inner_idx := s0_inner_idx 646 // s0_out.rob_idx := s0_rob_idx 647 s0_out.reg_offset := s0_sel_src.reg_offset 648 // s0_out.offset := s0_offset 649 s0_out.vecActive := s0_sel_src.vecActive 650 s0_out.usSecondInv := s0_sel_src.usSecondInv 651 s0_out.is_first_ele := s0_sel_src.is_first_ele 652 // s0_out.flowPtr := s0_sel_src.flowPtr 653 s0_out.uop.exceptionVec(loadAddrMisaligned) := !s0_addr_aligned && s0_sel_src.vecActive 654 s0_out.forward_tlDchannel := s0_super_ld_rep_select 655 when(io.tlb.req.valid && s0_sel_src.isFirstIssue) { 656 s0_out.uop.debugInfo.tlbFirstReqTime := GTimer() 657 }.otherwise{ 658 s0_out.uop.debugInfo.tlbFirstReqTime := s0_sel_src.uop.debugInfo.tlbFirstReqTime 659 } 660 s0_out.schedIndex := s0_sel_src.sched_idx 661 662 // load fast replay 663 io.fast_rep_in.ready := (s0_can_go && io.dcache.req.ready && s0_ld_fast_rep_ready) 664 665 // mmio 666 io.lsq.uncache.ready := s0_mmio_fire 667 668 // load flow source ready 669 // cache missed load has highest priority 670 // always accept cache missed load flow from load replay queue 671 io.replay.ready := (s0_can_go && io.dcache.req.ready && (s0_ld_rep_ready && !s0_rep_stall || s0_super_ld_rep_select)) 672 673 // accept load flow from rs when: 674 // 1) there is no lsq-replayed load 675 // 2) there is no fast replayed load 676 // 3) there is no high confidence prefetch request 677 io.vecldin.ready := s0_can_go && io.dcache.req.ready && s0_vec_iss_ready 678 io.ldin.ready := s0_can_go && io.dcache.req.ready && s0_int_iss_ready 679 680 // for hw prefetch load flow feedback, to be added later 681 // io.prefetch_in.ready := s0_hw_prf_select 682 683 // dcache replacement extra info 684 // TODO: should prefetch load update replacement? 685 io.dcache.replacementUpdated := Mux(s0_ld_rep_select || s0_super_ld_rep_select, io.replay.bits.replacementUpdated, false.B) 686 687 // load wakeup 688 // TODO: vector load wakeup? 689 io.wakeup.valid := s0_fire && (s0_super_ld_rep_select || s0_ld_fast_rep_select || s0_ld_rep_select || s0_int_iss_select) || s0_mmio_fire 690 io.wakeup.bits := s0_out.uop 691 692 XSDebug(io.dcache.req.fire, 693 p"[DCACHE LOAD REQ] pc ${Hexadecimal(s0_sel_src.uop.pc)}, vaddr ${Hexadecimal(s0_sel_src.vaddr)}\n" 694 ) 695 XSDebug(s0_valid, 696 p"S0: pc ${Hexadecimal(s0_out.uop.pc)}, lId ${Hexadecimal(s0_out.uop.lqIdx.asUInt)}, " + 697 p"vaddr ${Hexadecimal(s0_out.vaddr)}, mask ${Hexadecimal(s0_out.mask)}\n") 698 699 // Pipeline 700 // -------------------------------------------------------------------------------- 701 // stage 1 702 // -------------------------------------------------------------------------------- 703 // TLB resp (send paddr to dcache) 704 val s1_valid = RegInit(false.B) 705 val s1_in = Wire(new LqWriteBundle) 706 val s1_out = Wire(new LqWriteBundle) 707 val s1_kill = Wire(Bool()) 708 val s1_can_go = s2_ready 709 val s1_fire = s1_valid && !s1_kill && s1_can_go 710 val s1_vecActive = RegEnable(s0_out.vecActive, true.B, s0_fire) 711 val s1_vec_alignedType = RegEnable(io.vecldin.bits.alignedType, s0_fire) 712 val s1_vec_mBIndex = RegEnable(io.vecldin.bits.mBIndex, s0_fire) 713 714 s1_ready := !s1_valid || s1_kill || s2_ready 715 when (s0_fire) { s1_valid := true.B } 716 .elsewhen (s1_fire) { s1_valid := false.B } 717 .elsewhen (s1_kill) { s1_valid := false.B } 718 s1_in := RegEnable(s0_out, s0_fire) 719 720 val s1_fast_rep_dly_kill = RegNext(io.fast_rep_in.bits.lateKill) && s1_in.isFastReplay 721 val s1_fast_rep_dly_err = RegNext(io.fast_rep_in.bits.delayedLoadError) && s1_in.isFastReplay 722 val s1_l2l_fwd_dly_err = RegNext(io.l2l_fwd_in.dly_ld_err) && s1_in.isFastPath 723 val s1_dly_err = s1_fast_rep_dly_err || s1_l2l_fwd_dly_err 724 val s1_vaddr_hi = Wire(UInt()) 725 val s1_vaddr_lo = Wire(UInt()) 726 val s1_vaddr = Wire(UInt()) 727 val s1_paddr_dup_lsu = Wire(UInt()) 728 val s1_paddr_dup_dcache = Wire(UInt()) 729 val s1_exception = ExceptionNO.selectByFu(s1_out.uop.exceptionVec, LduCfg).asUInt.orR // af & pf exception were modified below. 730 val s1_tlb_miss = io.tlb.resp.bits.miss 731 val s1_prf = s1_in.isPrefetch 732 val s1_hw_prf = s1_in.isHWPrefetch 733 val s1_sw_prf = s1_prf && !s1_hw_prf 734 val s1_tlb_memidx = io.tlb.resp.bits.memidx 735 736 s1_vaddr_hi := s1_in.vaddr(VAddrBits - 1, 6) 737 s1_vaddr_lo := s1_in.vaddr(5, 0) 738 s1_vaddr := Cat(s1_vaddr_hi, s1_vaddr_lo) 739 s1_paddr_dup_lsu := io.tlb.resp.bits.paddr(0) 740 s1_paddr_dup_dcache := io.tlb.resp.bits.paddr(1) 741 742 when (s1_tlb_memidx.is_ld && io.tlb.resp.valid && !s1_tlb_miss && s1_tlb_memidx.idx === s1_in.uop.lqIdx.value) { 743 // printf("load idx = %d\n", s1_tlb_memidx.idx) 744 s1_out.uop.debugInfo.tlbRespTime := GTimer() 745 } 746 747 io.tlb.req_kill := s1_kill || s1_dly_err 748 io.tlb.resp.ready := true.B 749 750 io.dcache.s1_paddr_dup_lsu <> s1_paddr_dup_lsu 751 io.dcache.s1_paddr_dup_dcache <> s1_paddr_dup_dcache 752 io.dcache.s1_kill := s1_kill || s1_dly_err || s1_tlb_miss || s1_exception 753 754 // store to load forwarding 755 io.sbuffer.valid := s1_valid && !(s1_exception || s1_tlb_miss || s1_kill || s1_dly_err || s1_prf) 756 io.sbuffer.vaddr := s1_vaddr 757 io.sbuffer.paddr := s1_paddr_dup_lsu 758 io.sbuffer.uop := s1_in.uop 759 io.sbuffer.sqIdx := s1_in.uop.sqIdx 760 io.sbuffer.mask := s1_in.mask 761 io.sbuffer.pc := s1_in.uop.pc // FIXME: remove it 762 763 io.lsq.forward.valid := s1_valid && !(s1_exception || s1_tlb_miss || s1_kill || s1_dly_err || s1_prf) 764 io.lsq.forward.vaddr := s1_vaddr 765 io.lsq.forward.paddr := s1_paddr_dup_lsu 766 io.lsq.forward.uop := s1_in.uop 767 io.lsq.forward.sqIdx := s1_in.uop.sqIdx 768 io.lsq.forward.sqIdxMask := 0.U 769 io.lsq.forward.mask := s1_in.mask 770 io.lsq.forward.pc := s1_in.uop.pc // FIXME: remove it 771 772 // st-ld violation query 773 val s1_nuke_paddr_match = VecInit((0 until StorePipelineWidth).map(w => {Mux(s1_in.isvec && s1_in.is128bit, 774 s1_paddr_dup_lsu(PAddrBits-1, 4) === io.stld_nuke_query(w).bits.paddr(PAddrBits-1, 4), 775 s1_paddr_dup_lsu(PAddrBits-1, 3) === io.stld_nuke_query(w).bits.paddr(PAddrBits-1, 3))})) 776 val s1_nuke = VecInit((0 until StorePipelineWidth).map(w => { 777 io.stld_nuke_query(w).valid && // query valid 778 isAfter(s1_in.uop.robIdx, io.stld_nuke_query(w).bits.robIdx) && // older store 779 s1_nuke_paddr_match(w) && // paddr match 780 (s1_in.mask & io.stld_nuke_query(w).bits.mask).orR // data mask contain 781 })).asUInt.orR && !s1_tlb_miss 782 783 s1_out := s1_in 784 s1_out.vaddr := s1_vaddr 785 s1_out.paddr := s1_paddr_dup_lsu 786 s1_out.tlbMiss := s1_tlb_miss 787 s1_out.ptwBack := io.tlb.resp.bits.ptwBack 788 s1_out.rsIdx := s1_in.rsIdx 789 s1_out.rep_info.debug := s1_in.uop.debugInfo 790 s1_out.rep_info.nuke := s1_nuke && !s1_sw_prf 791 s1_out.delayedLoadError := s1_dly_err 792 793 when (!s1_dly_err) { 794 // current ori test will cause the case of ldest == 0, below will be modifeid in the future. 795 // af & pf exception were modified 796 s1_out.uop.exceptionVec(loadPageFault) := io.tlb.resp.bits.excp(0).pf.ld && s1_vecActive && !s1_tlb_miss 797 s1_out.uop.exceptionVec(loadAccessFault) := io.tlb.resp.bits.excp(0).af.ld && s1_vecActive && !s1_tlb_miss 798 } .otherwise { 799 s1_out.uop.exceptionVec(loadPageFault) := false.B 800 s1_out.uop.exceptionVec(loadAddrMisaligned) := false.B 801 s1_out.uop.exceptionVec(loadAccessFault) := s1_dly_err && s1_vecActive 802 } 803 804 // pointer chasing 805 val s1_try_ptr_chasing = RegNext(s0_do_try_ptr_chasing, false.B) 806 val s1_ptr_chasing_vaddr = RegEnable(s0_ptr_chasing_vaddr, s0_do_try_ptr_chasing) 807 val s1_fu_op_type_not_ld = WireInit(false.B) 808 val s1_not_fast_match = WireInit(false.B) 809 val s1_addr_mismatch = WireInit(false.B) 810 val s1_addr_misaligned = WireInit(false.B) 811 val s1_fast_mismatch = WireInit(false.B) 812 val s1_ptr_chasing_canceled = WireInit(false.B) 813 val s1_cancel_ptr_chasing = WireInit(false.B) 814 815 s1_kill := s1_fast_rep_dly_kill || 816 s1_cancel_ptr_chasing || 817 s1_in.uop.robIdx.needFlush(io.redirect) || 818 (s1_in.uop.robIdx.needFlush(RegNext(io.redirect)) && !RegNext(s0_try_ptr_chasing)) || 819 RegEnable(s0_kill, false.B, io.ldin.valid || io.vecldin.valid || io.replay.valid || io.l2l_fwd_in.valid || io.fast_rep_in.valid) 820 821 if (EnableLoadToLoadForward) { 822 // Sometimes, we need to cancel the load-load forwarding. 823 // These can be put at S0 if timing is bad at S1. 824 // Case 0: CACHE_SET(base + offset) != CACHE_SET(base) (lowest 6-bit addition has an overflow) 825 s1_addr_mismatch := s1_ptr_chasing_vaddr(6) || 826 RegEnable(io.ld_fast_imm(11, 6).orR, s0_do_try_ptr_chasing) 827 // Case 1: the address is not 64-bit aligned or the fuOpType is not LD 828 s1_addr_misaligned := s1_ptr_chasing_vaddr(2, 0).orR 829 s1_fu_op_type_not_ld := io.ldin.bits.uop.fuOpType =/= LSUOpType.ld 830 // Case 2: this load-load uop is cancelled 831 s1_ptr_chasing_canceled := !io.ldin.valid 832 // Case 3: fast mismatch 833 s1_fast_mismatch := RegEnable(!io.ld_fast_match, s0_do_try_ptr_chasing) 834 835 when (s1_try_ptr_chasing) { 836 s1_cancel_ptr_chasing := s1_addr_mismatch || 837 s1_addr_misaligned || 838 s1_fu_op_type_not_ld || 839 s1_ptr_chasing_canceled || 840 s1_fast_mismatch 841 842 s1_in.uop := io.ldin.bits.uop 843 s1_in.rsIdx := io.ldin.bits.iqIdx 844 s1_in.isFirstIssue := io.ldin.bits.isFirstIssue 845 s1_vaddr_lo := s1_ptr_chasing_vaddr(5, 0) 846 s1_paddr_dup_lsu := Cat(io.tlb.resp.bits.paddr(0)(PAddrBits - 1, 6), s1_vaddr_lo) 847 s1_paddr_dup_dcache := Cat(io.tlb.resp.bits.paddr(0)(PAddrBits - 1, 6), s1_vaddr_lo) 848 849 // recored tlb time when get the data to ensure the correctness of the latency calculation (although it should not record in here, because it does not use tlb) 850 s1_in.uop.debugInfo.tlbFirstReqTime := GTimer() 851 s1_in.uop.debugInfo.tlbRespTime := GTimer() 852 } 853 when (!s1_cancel_ptr_chasing) { 854 s0_ptr_chasing_canceled := s1_try_ptr_chasing && !io.replay.fire && !io.fast_rep_in.fire 855 when (s1_try_ptr_chasing) { 856 io.ldin.ready := true.B 857 } 858 } 859 } 860 861 // pre-calcuate sqIdx mask in s0, then send it to lsq in s1 for forwarding 862 val s1_sqIdx_mask = RegNext(UIntToMask(s0_out.uop.sqIdx.value, StoreQueueSize)) 863 // to enable load-load, sqIdxMask must be calculated based on ldin.uop 864 // If the timing here is not OK, load-load forwarding has to be disabled. 865 // Or we calculate sqIdxMask at RS?? 866 io.lsq.forward.sqIdxMask := s1_sqIdx_mask 867 if (EnableLoadToLoadForward) { 868 when (s1_try_ptr_chasing) { 869 io.lsq.forward.sqIdxMask := UIntToMask(io.ldin.bits.uop.sqIdx.value, StoreQueueSize) 870 } 871 } 872 873 io.forward_mshr.valid := s1_valid && s1_out.forward_tlDchannel 874 io.forward_mshr.mshrid := s1_out.mshrid 875 io.forward_mshr.paddr := s1_out.paddr 876 877 XSDebug(s1_valid, 878 p"S1: pc ${Hexadecimal(s1_out.uop.pc)}, lId ${Hexadecimal(s1_out.uop.lqIdx.asUInt)}, tlb_miss ${io.tlb.resp.bits.miss}, " + 879 p"paddr ${Hexadecimal(s1_out.paddr)}, mmio ${s1_out.mmio}\n") 880 881 // Pipeline 882 // -------------------------------------------------------------------------------- 883 // stage 2 884 // -------------------------------------------------------------------------------- 885 // s2: DCache resp 886 val s2_valid = RegInit(false.B) 887 val s2_in = Wire(new LqWriteBundle) 888 val s2_out = Wire(new LqWriteBundle) 889 val s2_kill = Wire(Bool()) 890 val s2_can_go = s3_ready 891 val s2_fire = s2_valid && !s2_kill && s2_can_go 892 val s2_vecActive = RegEnable(s1_out.vecActive, true.B, s1_fire) 893 val s2_isvec = RegEnable(s1_out.isvec, false.B, s1_fire) 894 val s2_vec_alignedType = RegEnable(s1_vec_alignedType, s1_fire) 895 val s2_vec_mBIndex = RegEnable(s1_vec_mBIndex, s1_fire) 896 897 s2_kill := s2_in.uop.robIdx.needFlush(io.redirect) 898 s2_ready := !s2_valid || s2_kill || s3_ready 899 when (s1_fire) { s2_valid := true.B } 900 .elsewhen (s2_fire) { s2_valid := false.B } 901 .elsewhen (s2_kill) { s2_valid := false.B } 902 s2_in := RegEnable(s1_out, s1_fire) 903 904 val s2_pmp = WireInit(io.pmp) 905 906 val s2_prf = s2_in.isPrefetch 907 val s2_hw_prf = s2_in.isHWPrefetch 908 909 // exception that may cause load addr to be invalid / illegal 910 // if such exception happen, that inst and its exception info 911 // will be force writebacked to rob 912 val s2_exception_vec = WireInit(s2_in.uop.exceptionVec) 913 when (!s2_in.delayedLoadError) { 914 s2_exception_vec(loadAccessFault) := (s2_in.uop.exceptionVec(loadAccessFault) || s2_pmp.ld || 915 (io.dcache.resp.bits.tag_error && RegNext(io.csrCtrl.cache_error_enable))) && s2_vecActive 916 } 917 918 // soft prefetch will not trigger any exception (but ecc error interrupt may 919 // be triggered) 920 when (!s2_in.delayedLoadError && (s2_prf || s2_in.tlbMiss)) { 921 s2_exception_vec := 0.U.asTypeOf(s2_exception_vec.cloneType) 922 } 923 val s2_exception = ExceptionNO.selectByFu(s2_exception_vec, LduCfg).asUInt.orR && s2_vecActive 924 925 val (s2_fwd_frm_d_chan, s2_fwd_data_frm_d_chan) = io.tl_d_channel.forward(s1_valid && s1_out.forward_tlDchannel, s1_out.mshrid, s1_out.paddr) 926 val (s2_fwd_data_valid, s2_fwd_frm_mshr, s2_fwd_data_frm_mshr) = io.forward_mshr.forward() 927 val s2_fwd_frm_d_chan_or_mshr = s2_fwd_data_valid && (s2_fwd_frm_d_chan || s2_fwd_frm_mshr) 928 929 // writeback access fault caused by ecc error / bus error 930 // * ecc data error is slow to generate, so we will not use it until load stage 3 931 // * in load stage 3, an extra signal io.load_error will be used to 932 val s2_actually_mmio = s2_pmp.mmio 933 val s2_mmio = !s2_prf && 934 s2_actually_mmio && 935 !s2_exception && 936 !s2_in.tlbMiss 937 938 val s2_full_fwd = Wire(Bool()) 939 val s2_mem_amb = s2_in.uop.storeSetHit && 940 io.lsq.forward.addrInvalid 941 942 val s2_tlb_miss = s2_in.tlbMiss 943 val s2_fwd_fail = io.lsq.forward.dataInvalid 944 val s2_dcache_miss = io.dcache.resp.bits.miss && 945 !s2_fwd_frm_d_chan_or_mshr && 946 !s2_full_fwd 947 948 val s2_mq_nack = io.dcache.s2_mq_nack && 949 !s2_fwd_frm_d_chan_or_mshr && 950 !s2_full_fwd 951 952 val s2_bank_conflict = io.dcache.s2_bank_conflict && 953 !s2_fwd_frm_d_chan_or_mshr && 954 !s2_full_fwd 955 956 val s2_wpu_pred_fail = io.dcache.s2_wpu_pred_fail && 957 !s2_fwd_frm_d_chan_or_mshr && 958 !s2_full_fwd 959 960 val s2_rar_nack = io.lsq.ldld_nuke_query.req.valid && 961 !io.lsq.ldld_nuke_query.req.ready 962 963 val s2_raw_nack = io.lsq.stld_nuke_query.req.valid && 964 !io.lsq.stld_nuke_query.req.ready 965 // st-ld violation query 966 // NeedFastRecovery Valid when 967 // 1. Fast recovery query request Valid. 968 // 2. Load instruction is younger than requestors(store instructions). 969 // 3. Physical address match. 970 // 4. Data contains. 971 val s2_nuke_paddr_match = VecInit((0 until StorePipelineWidth).map(w => {Mux(s2_in.isvec && s2_in.is128bit, 972 s2_in.paddr(PAddrBits-1, 4) === io.stld_nuke_query(w).bits.paddr(PAddrBits-1, 4), 973 s2_in.paddr(PAddrBits-1, 3) === io.stld_nuke_query(w).bits.paddr(PAddrBits-1, 3))})) 974 val s2_nuke = VecInit((0 until StorePipelineWidth).map(w => { 975 io.stld_nuke_query(w).valid && // query valid 976 isAfter(s2_in.uop.robIdx, io.stld_nuke_query(w).bits.robIdx) && // older store 977 s2_nuke_paddr_match(w) && // paddr match 978 (s2_in.mask & io.stld_nuke_query(w).bits.mask).orR // data mask contain 979 })).asUInt.orR && !s2_tlb_miss || s2_in.rep_info.nuke 980 981 val s2_cache_handled = io.dcache.resp.bits.handled 982 val s2_cache_tag_error = RegNext(io.csrCtrl.cache_error_enable) && 983 io.dcache.resp.bits.tag_error 984 985 val s2_troublem = !s2_exception && 986 !s2_mmio && 987 !s2_prf && 988 !s2_in.delayedLoadError 989 990 io.dcache.resp.ready := true.B 991 val s2_dcache_should_resp = !(s2_in.tlbMiss || s2_exception || s2_in.delayedLoadError || s2_mmio || s2_prf) 992 assert(!(s2_valid && (s2_dcache_should_resp && !io.dcache.resp.valid)), "DCache response got lost") 993 994 // fast replay require 995 val s2_dcache_fast_rep = (s2_mq_nack || !s2_dcache_miss && (s2_bank_conflict || s2_wpu_pred_fail)) 996 val s2_nuke_fast_rep = !s2_mq_nack && 997 !s2_dcache_miss && 998 !s2_bank_conflict && 999 !s2_wpu_pred_fail && 1000 !s2_rar_nack && 1001 !s2_raw_nack && 1002 s2_nuke 1003 1004 val s2_fast_rep = !s2_mem_amb && 1005 !s2_tlb_miss && 1006 !s2_fwd_fail && 1007 (s2_dcache_fast_rep || s2_nuke_fast_rep) && 1008 s2_troublem 1009 1010 // need allocate new entry 1011 val s2_can_query = !s2_mem_amb && 1012 !s2_tlb_miss && 1013 !s2_fwd_fail && 1014 s2_troublem 1015 1016 val s2_data_fwded = s2_dcache_miss && (s2_full_fwd || s2_cache_tag_error) 1017 1018 // ld-ld violation require 1019 io.lsq.ldld_nuke_query.req.valid := s2_valid && s2_can_query 1020 io.lsq.ldld_nuke_query.req.bits.uop := s2_in.uop 1021 io.lsq.ldld_nuke_query.req.bits.mask := s2_in.mask 1022 io.lsq.ldld_nuke_query.req.bits.paddr := s2_in.paddr 1023 io.lsq.ldld_nuke_query.req.bits.data_valid := Mux(s2_full_fwd || s2_fwd_data_valid, true.B, !s2_dcache_miss) 1024 1025 // st-ld violation require 1026 io.lsq.stld_nuke_query.req.valid := s2_valid && s2_can_query 1027 io.lsq.stld_nuke_query.req.bits.uop := s2_in.uop 1028 io.lsq.stld_nuke_query.req.bits.mask := s2_in.mask 1029 io.lsq.stld_nuke_query.req.bits.paddr := s2_in.paddr 1030 io.lsq.stld_nuke_query.req.bits.data_valid := Mux(s2_full_fwd || s2_fwd_data_valid, true.B, !s2_dcache_miss) 1031 1032 // merge forward result 1033 // lsq has higher priority than sbuffer 1034 val s2_fwd_mask = Wire(Vec((VLEN/8), Bool())) 1035 val s2_fwd_data = Wire(Vec((VLEN/8), UInt(8.W))) 1036 s2_full_fwd := ((~s2_fwd_mask.asUInt).asUInt & s2_in.mask) === 0.U && !io.lsq.forward.dataInvalid 1037 // generate XLEN/8 Muxs 1038 for (i <- 0 until VLEN / 8) { 1039 s2_fwd_mask(i) := io.lsq.forward.forwardMask(i) || io.sbuffer.forwardMask(i) 1040 s2_fwd_data(i) := Mux(io.lsq.forward.forwardMask(i), io.lsq.forward.forwardData(i), io.sbuffer.forwardData(i)) 1041 } 1042 1043 XSDebug(s2_fire, "[FWD LOAD RESP] pc %x fwd %x(%b) + %x(%b)\n", 1044 s2_in.uop.pc, 1045 io.lsq.forward.forwardData.asUInt, io.lsq.forward.forwardMask.asUInt, 1046 s2_in.forwardData.asUInt, s2_in.forwardMask.asUInt 1047 ) 1048 1049 // 1050 s2_out := s2_in 1051 s2_out.data := 0.U // data will be generated in load s3 1052 s2_out.uop.fpWen := s2_in.uop.fpWen && !s2_exception 1053 s2_out.mmio := s2_mmio 1054 s2_out.uop.flushPipe := false.B 1055 s2_out.uop.exceptionVec := s2_exception_vec 1056 s2_out.forwardMask := s2_fwd_mask 1057 s2_out.forwardData := s2_fwd_data 1058 s2_out.handledByMSHR := s2_cache_handled 1059 s2_out.miss := s2_dcache_miss && s2_troublem 1060 s2_out.feedbacked := io.feedback_fast.valid 1061 1062 // Generate replay signal caused by: 1063 // * st-ld violation check 1064 // * tlb miss 1065 // * dcache replay 1066 // * forward data invalid 1067 // * dcache miss 1068 s2_out.rep_info.mem_amb := s2_mem_amb && s2_troublem 1069 s2_out.rep_info.tlb_miss := s2_tlb_miss && s2_troublem 1070 s2_out.rep_info.fwd_fail := s2_fwd_fail && s2_troublem 1071 s2_out.rep_info.dcache_rep := s2_mq_nack && s2_troublem 1072 s2_out.rep_info.dcache_miss := s2_dcache_miss && s2_troublem 1073 s2_out.rep_info.bank_conflict := s2_bank_conflict && s2_troublem 1074 s2_out.rep_info.wpu_fail := s2_wpu_pred_fail && s2_troublem 1075 s2_out.rep_info.rar_nack := s2_rar_nack && s2_troublem 1076 s2_out.rep_info.raw_nack := s2_raw_nack && s2_troublem 1077 s2_out.rep_info.nuke := s2_nuke && s2_troublem 1078 s2_out.rep_info.full_fwd := s2_data_fwded 1079 s2_out.rep_info.data_inv_sq_idx := io.lsq.forward.dataInvalidSqIdx 1080 s2_out.rep_info.addr_inv_sq_idx := io.lsq.forward.addrInvalidSqIdx 1081 s2_out.rep_info.rep_carry := io.dcache.resp.bits.replayCarry 1082 s2_out.rep_info.mshr_id := io.dcache.resp.bits.mshr_id 1083 s2_out.rep_info.last_beat := s2_in.paddr(log2Up(refillBytes)) 1084 s2_out.rep_info.debug := s2_in.uop.debugInfo 1085 s2_out.rep_info.tlb_id := io.tlb_hint.id 1086 s2_out.rep_info.tlb_full := io.tlb_hint.full 1087 1088 // if forward fail, replay this inst from fetch 1089 val debug_fwd_fail_rep = s2_fwd_fail && !s2_troublem && !s2_in.tlbMiss 1090 // if ld-ld violation is detected, replay from this inst from fetch 1091 val debug_ldld_nuke_rep = false.B // s2_ldld_violation && !s2_mmio && !s2_is_prefetch && !s2_in.tlbMiss 1092 1093 // to be removed 1094 io.feedback_fast.valid := false.B 1095 io.feedback_fast.bits.hit := false.B 1096 io.feedback_fast.bits.flushState := s2_in.ptwBack 1097 io.feedback_fast.bits.robIdx := s2_in.uop.robIdx 1098 io.feedback_fast.bits.sourceType := RSFeedbackType.lrqFull 1099 io.feedback_fast.bits.dataInvalidSqIdx := DontCare 1100 1101 io.ldCancel.ld1Cancel := false.B 1102 1103 // fast wakeup 1104 io.fast_uop.valid := RegNext( 1105 !io.dcache.s1_disable_fast_wakeup && 1106 s1_valid && 1107 !s1_kill && 1108 !io.tlb.resp.bits.miss && 1109 !io.lsq.forward.dataInvalidFast 1110 ) && (s2_valid && !s2_out.rep_info.need_rep && !s2_mmio) && !s2_isvec 1111 io.fast_uop.bits := RegNext(s1_out.uop) 1112 1113 // 1114 io.s2_ptr_chasing := RegEnable(s1_try_ptr_chasing && !s1_cancel_ptr_chasing, false.B, s1_fire) 1115 1116 // RegNext prefetch train for better timing 1117 // ** Now, prefetch train is valid at load s3 ** 1118 io.prefetch_train.valid := RegNext(s2_valid && !s2_actually_mmio && !s2_in.tlbMiss) 1119 io.prefetch_train.bits.fromLsPipelineBundle(s2_in, latch = true) 1120 io.prefetch_train.bits.miss := RegNext(io.dcache.resp.bits.miss) // TODO: use trace with bank conflict? 1121 io.prefetch_train.bits.meta_prefetch := RegNext(io.dcache.resp.bits.meta_prefetch) 1122 io.prefetch_train.bits.meta_access := RegNext(io.dcache.resp.bits.meta_access) 1123 1124 io.prefetch_train_l1.valid := RegNext(s2_valid && !s2_actually_mmio) 1125 io.prefetch_train_l1.bits.fromLsPipelineBundle(s2_in, latch = true) 1126 io.prefetch_train_l1.bits.miss := RegNext(io.dcache.resp.bits.miss) 1127 io.prefetch_train_l1.bits.meta_prefetch := RegNext(io.dcache.resp.bits.meta_prefetch) 1128 io.prefetch_train_l1.bits.meta_access := RegNext(io.dcache.resp.bits.meta_access) 1129 if (env.FPGAPlatform){ 1130 io.dcache.s0_pc := DontCare 1131 io.dcache.s1_pc := DontCare 1132 io.dcache.s2_pc := DontCare 1133 }else{ 1134 io.dcache.s0_pc := s0_out.uop.pc 1135 io.dcache.s1_pc := s1_out.uop.pc 1136 io.dcache.s2_pc := s2_out.uop.pc 1137 } 1138 io.dcache.s2_kill := s2_pmp.ld || s2_actually_mmio || s2_kill 1139 1140 val s1_ld_left_fire = s1_valid && !s1_kill && s2_ready 1141 val s2_ld_valid_dup = RegInit(0.U(6.W)) 1142 s2_ld_valid_dup := 0x0.U(6.W) 1143 when (s1_ld_left_fire && !s1_out.isHWPrefetch) { s2_ld_valid_dup := 0x3f.U(6.W) } 1144 when (s1_kill || s1_out.isHWPrefetch) { s2_ld_valid_dup := 0x0.U(6.W) } 1145 assert(RegNext((s2_valid === s2_ld_valid_dup(0)) || RegNext(s1_out.isHWPrefetch))) 1146 1147 // Pipeline 1148 // -------------------------------------------------------------------------------- 1149 // stage 3 1150 // -------------------------------------------------------------------------------- 1151 // writeback and update load queue 1152 val s3_valid = RegNext(s2_valid && !s2_out.isHWPrefetch && !s2_out.uop.robIdx.needFlush(io.redirect)) 1153 val s3_in = RegEnable(s2_out, s2_fire) 1154 val s3_out = Wire(Valid(new MemExuOutput)) 1155 val s3_dcache_rep = RegEnable(s2_dcache_fast_rep && s2_troublem, false.B, s2_fire) 1156 val s3_ld_valid_dup = RegEnable(s2_ld_valid_dup, s2_fire) 1157 val s3_fast_rep = Wire(Bool()) 1158 val s3_troublem = RegNext(s2_troublem) 1159 val s3_kill = s3_in.uop.robIdx.needFlush(io.redirect) 1160 val s3_vecout = Wire(new OnlyVecExuOutput) 1161 val s3_vecActive = RegEnable(s2_out.vecActive, true.B, s2_fire) 1162 val s3_isvec = RegEnable(s2_out.isvec, false.B, s2_fire) 1163 val s3_vec_alignedType = RegEnable(s2_vec_alignedType, s2_fire) 1164 val s3_vec_mBIndex = RegEnable(s2_vec_mBIndex, s2_fire) 1165 val s3_mmio = Wire(chiselTypeOf(io.lsq.uncache)) 1166 dontTouch(s2_out) 1167 dontTouch(s1_out) 1168 // TODO: Fix vector load merge buffer nack 1169 val s3_vec_mb_nack = Wire(Bool()) 1170 s3_vec_mb_nack := false.B 1171 XSError(s3_valid && s3_vec_mb_nack, "Merge buffer should always accept vector loads!") 1172 1173 s3_ready := !s3_valid || s3_kill || io.ldout.ready 1174 s3_mmio.valid := RegNextN(io.lsq.uncache.valid, 3, Some(false.B)) 1175 s3_mmio.ready := RegNextN(io.lsq.uncache.ready, 3, Some(false.B)) 1176 s3_mmio.bits := RegNextN(io.lsq.uncache.bits, 3) 1177 1178 // forwrad last beat 1179 val (s3_fwd_frm_d_chan, s3_fwd_data_frm_d_chan) = io.tl_d_channel.forward(s2_valid && s2_out.forward_tlDchannel, s2_out.mshrid, s2_out.paddr) 1180 val s3_fwd_data_valid = RegEnable(s2_fwd_data_valid, false.B, s2_valid) 1181 val s3_fwd_frm_d_chan_valid = (s3_fwd_frm_d_chan && s3_fwd_data_valid && s3_in.handledByMSHR) 1182 val s3_fast_rep_canceled = io.replay.valid && io.replay.bits.forward_tlDchannel || !io.dcache.req.ready 1183 1184 // s3 load fast replay 1185 io.fast_rep_out.valid := s3_valid && s3_fast_rep && !s3_in.uop.robIdx.needFlush(io.redirect) 1186 io.fast_rep_out.bits := s3_in 1187 1188 io.lsq.ldin.valid := s3_valid && (!s3_fast_rep || s3_fast_rep_canceled) && !s3_in.feedbacked 1189 // TODO: check this --by hx 1190 // io.lsq.ldin.valid := s3_valid && (!s3_fast_rep || !io.fast_rep_out.ready) && !s3_in.feedbacked && !s3_in.lateKill 1191 io.lsq.ldin.bits := s3_in 1192 io.lsq.ldin.bits.miss := s3_in.miss && !s3_fwd_frm_d_chan_valid 1193 1194 /* <------- DANGEROUS: Don't change sequence here ! -------> */ 1195 io.lsq.ldin.bits.data_wen_dup := s3_ld_valid_dup.asBools 1196 io.lsq.ldin.bits.replacementUpdated := io.dcache.resp.bits.replacementUpdated 1197 io.lsq.ldin.bits.missDbUpdated := RegNext(s2_fire && s2_in.hasROBEntry && !s2_in.tlbMiss && !s2_in.missDbUpdated) 1198 1199 val s3_dly_ld_err = 1200 if (EnableAccurateLoadError) { 1201 io.dcache.resp.bits.error_delayed && RegNext(io.csrCtrl.cache_error_enable) && s3_troublem 1202 } else { 1203 WireInit(false.B) 1204 } 1205 io.s3_dly_ld_err := false.B // s3_dly_ld_err && s3_valid 1206 io.lsq.ldin.bits.dcacheRequireReplay := s3_dcache_rep 1207 io.fast_rep_out.bits.delayedLoadError := s3_dly_ld_err 1208 1209 val s3_vp_match_fail = RegNext(io.lsq.forward.matchInvalid || io.sbuffer.matchInvalid) && s3_troublem 1210 val s3_rep_frm_fetch = s3_vp_match_fail 1211 val s3_ldld_rep_inst = 1212 io.lsq.ldld_nuke_query.resp.valid && 1213 io.lsq.ldld_nuke_query.resp.bits.rep_frm_fetch && 1214 RegNext(io.csrCtrl.ldld_vio_check_enable) 1215 val s3_flushPipe = s3_ldld_rep_inst 1216 1217 val s3_rep_info = WireInit(s3_in.rep_info) 1218 s3_rep_info.dcache_miss := s3_in.rep_info.dcache_miss && !s3_fwd_frm_d_chan_valid 1219 val s3_sel_rep_cause = PriorityEncoderOH(s3_rep_info.cause.asUInt) 1220 1221 val s3_exception = ExceptionNO.selectByFu(s3_in.uop.exceptionVec, LduCfg).asUInt.orR && s3_vecActive 1222 when (s3_exception || s3_dly_ld_err || s3_rep_frm_fetch) { 1223 io.lsq.ldin.bits.rep_info.cause := 0.U.asTypeOf(s3_rep_info.cause.cloneType) 1224 } .otherwise { 1225 io.lsq.ldin.bits.rep_info.cause := VecInit(s3_sel_rep_cause.asBools) 1226 } 1227 1228 // Int load, if hit, will be writebacked at s3 1229 s3_out.valid := s3_valid && !io.lsq.ldin.bits.rep_info.need_rep && !s3_in.mmio 1230 s3_out.bits.uop := s3_in.uop 1231 s3_out.bits.uop.exceptionVec(loadAccessFault) := (s3_dly_ld_err || s3_in.uop.exceptionVec(loadAccessFault)) && s3_vecActive 1232 s3_out.bits.uop.flushPipe := false.B 1233 s3_out.bits.uop.replayInst := s3_rep_frm_fetch || s3_flushPipe 1234 s3_out.bits.data := s3_in.data 1235 s3_out.bits.debug.isMMIO := s3_in.mmio 1236 s3_out.bits.debug.isPerfCnt := false.B 1237 s3_out.bits.debug.paddr := s3_in.paddr 1238 s3_out.bits.debug.vaddr := s3_in.vaddr 1239 1240 // Vector load, writeback to merge buffer 1241 // TODO: Add assertion in merge buffer, merge buffer must accept vec load writeback 1242 s3_vecout.isvec := s3_isvec 1243 s3_vecout.vecdata := 0.U // Data will be assigned later 1244 s3_vecout.mask := s3_in.mask 1245 // s3_vecout.rob_idx_valid := s3_in.rob_idx_valid 1246 // s3_vecout.inner_idx := s3_in.inner_idx 1247 // s3_vecout.rob_idx := s3_in.rob_idx 1248 // s3_vecout.offset := s3_in.offset 1249 s3_vecout.reg_offset := s3_in.reg_offset 1250 s3_vecout.vecActive := s3_vecActive 1251 s3_vecout.is_first_ele := s3_in.is_first_ele 1252 // s3_vecout.uopQueuePtr := DontCare // uopQueuePtr is already saved in flow queue 1253 // s3_vecout.flowPtr := s3_in.flowPtr 1254 s3_vecout.elemIdx := DontCare // elemIdx is already saved in flow queue // TODO: 1255 s3_vecout.elemIdxInsideVd := DontCare 1256 val s3_usSecondInv = s3_in.usSecondInv 1257 1258 io.rollback.valid := s3_valid && (s3_rep_frm_fetch || s3_flushPipe) && !s3_exception 1259 io.rollback.bits := DontCare 1260 io.rollback.bits.isRVC := s3_out.bits.uop.preDecodeInfo.isRVC 1261 io.rollback.bits.robIdx := s3_out.bits.uop.robIdx 1262 io.rollback.bits.ftqIdx := s3_out.bits.uop.ftqPtr 1263 io.rollback.bits.ftqOffset := s3_out.bits.uop.ftqOffset 1264 io.rollback.bits.level := Mux(s3_rep_frm_fetch, RedirectLevel.flush, RedirectLevel.flushAfter) 1265 io.rollback.bits.cfiUpdate.target := s3_out.bits.uop.pc 1266 io.rollback.bits.debug_runahead_checkpoint_id := s3_out.bits.uop.debugInfo.runahead_checkpoint_id 1267 /* <------- DANGEROUS: Don't change sequence here ! -------> */ 1268 1269 io.lsq.ldin.bits.uop := s3_out.bits.uop 1270 1271 val s3_revoke = s3_exception || io.lsq.ldin.bits.rep_info.need_rep 1272 io.lsq.ldld_nuke_query.revoke := s3_revoke 1273 io.lsq.stld_nuke_query.revoke := s3_revoke 1274 1275 // feedback slow 1276 s3_fast_rep := RegNext(s2_fast_rep) 1277 1278 val s3_fb_no_waiting = !s3_in.isLoadReplay && 1279 (!(s3_fast_rep && !s3_fast_rep_canceled)) && 1280 !s3_in.feedbacked 1281 1282 // feedback: scalar load will send feedback to RS 1283 // vector load will send signal to VL Merge Buffer, then send feedback at granularity of uops 1284 io.feedback_slow.valid := s3_valid && s3_fb_no_waiting && !s3_isvec 1285 io.feedback_slow.bits.hit := !s3_rep_info.need_rep || io.lsq.ldin.ready 1286 io.feedback_slow.bits.flushState := s3_in.ptwBack 1287 io.feedback_slow.bits.robIdx := s3_in.uop.robIdx 1288 io.feedback_slow.bits.sourceType := RSFeedbackType.lrqFull 1289 io.feedback_slow.bits.dataInvalidSqIdx := DontCare 1290 1291 io.ldCancel.ld2Cancel := s3_valid && ( 1292 io.lsq.ldin.bits.rep_info.need_rep || // exe fail or 1293 s3_in.mmio // is mmio 1294 ) 1295 1296 val s3_ld_wb_meta = Mux(s3_valid, s3_out.bits, s3_mmio.bits) 1297 1298 // data from load queue refill 1299 val s3_ld_raw_data_frm_uncache = RegNextN(io.lsq.ld_raw_data, 3) 1300 val s3_merged_data_frm_uncache = s3_ld_raw_data_frm_uncache.mergedData() 1301 val s3_picked_data_frm_uncache = LookupTree(s3_ld_raw_data_frm_uncache.addrOffset, List( 1302 "b000".U -> s3_merged_data_frm_uncache(63, 0), 1303 "b001".U -> s3_merged_data_frm_uncache(63, 8), 1304 "b010".U -> s3_merged_data_frm_uncache(63, 16), 1305 "b011".U -> s3_merged_data_frm_uncache(63, 24), 1306 "b100".U -> s3_merged_data_frm_uncache(63, 32), 1307 "b101".U -> s3_merged_data_frm_uncache(63, 40), 1308 "b110".U -> s3_merged_data_frm_uncache(63, 48), 1309 "b111".U -> s3_merged_data_frm_uncache(63, 56) 1310 )) 1311 val s3_ld_data_frm_uncache = rdataHelper(s3_ld_raw_data_frm_uncache.uop, s3_picked_data_frm_uncache) 1312 1313 // data from dcache hit 1314 val s3_ld_raw_data_frm_cache = Wire(new LoadDataFromDcacheBundle) 1315 s3_ld_raw_data_frm_cache.respDcacheData := io.dcache.resp.bits.data_delayed 1316 s3_ld_raw_data_frm_cache.forwardMask := RegEnable(s2_fwd_mask, s2_valid) 1317 s3_ld_raw_data_frm_cache.forwardData := RegEnable(s2_fwd_data, s2_valid) 1318 s3_ld_raw_data_frm_cache.uop := RegEnable(s2_out.uop, s2_valid) 1319 s3_ld_raw_data_frm_cache.addrOffset := RegEnable(s2_out.paddr(3, 0), s2_valid) 1320 s3_ld_raw_data_frm_cache.forward_D := RegEnable(s2_fwd_frm_d_chan, false.B, s2_valid) || s3_fwd_frm_d_chan_valid 1321 s3_ld_raw_data_frm_cache.forwardData_D := Mux(s3_fwd_frm_d_chan_valid, s3_fwd_data_frm_d_chan, RegEnable(s2_fwd_data_frm_d_chan, s2_valid)) 1322 s3_ld_raw_data_frm_cache.forward_mshr := RegEnable(s2_fwd_frm_mshr, false.B, s2_valid) 1323 s3_ld_raw_data_frm_cache.forwardData_mshr := RegEnable(s2_fwd_data_frm_mshr, s2_valid) 1324 s3_ld_raw_data_frm_cache.forward_result_valid := RegEnable(s2_fwd_data_valid, false.B, s2_valid) 1325 1326 val s3_merged_data_frm_cache = s3_ld_raw_data_frm_cache.mergedData() 1327 val s3_picked_data_frm_cache = LookupTree(s3_ld_raw_data_frm_cache.addrOffset, List( 1328 "b0000".U -> s3_merged_data_frm_cache(63, 0), 1329 "b0001".U -> s3_merged_data_frm_cache(63, 8), 1330 "b0010".U -> s3_merged_data_frm_cache(63, 16), 1331 "b0011".U -> s3_merged_data_frm_cache(63, 24), 1332 "b0100".U -> s3_merged_data_frm_cache(63, 32), 1333 "b0101".U -> s3_merged_data_frm_cache(63, 40), 1334 "b0110".U -> s3_merged_data_frm_cache(63, 48), 1335 "b0111".U -> s3_merged_data_frm_cache(63, 56), 1336 "b1000".U -> s3_merged_data_frm_cache(127, 64), 1337 "b1001".U -> s3_merged_data_frm_cache(127, 72), 1338 "b1010".U -> s3_merged_data_frm_cache(127, 80), 1339 "b1011".U -> s3_merged_data_frm_cache(127, 88), 1340 "b1100".U -> s3_merged_data_frm_cache(127, 96), 1341 "b1101".U -> s3_merged_data_frm_cache(127, 104), 1342 "b1110".U -> s3_merged_data_frm_cache(127, 112), 1343 "b1111".U -> s3_merged_data_frm_cache(127, 120) 1344 )) 1345 val s3_ld_data_frm_cache = rdataHelper(s3_ld_raw_data_frm_cache.uop, s3_picked_data_frm_cache) 1346 1347 // FIXME: add 1 cycle delay ? 1348 // io.lsq.uncache.ready := !s3_valid 1349 io.ldout.bits := s3_ld_wb_meta 1350 io.ldout.bits.data := Mux(s3_valid, s3_ld_data_frm_cache, s3_ld_data_frm_uncache) 1351 io.ldout.valid := (s3_out.valid || (s3_mmio.valid && !s3_valid)) && !s3_vecout.isvec 1352 1353 // TODO: check this --hx 1354 // io.ldout.valid := s3_out.valid && !s3_out.bits.uop.robIdx.needFlush(io.redirect) && !s3_vecout.isvec || 1355 // io.lsq.uncache.valid && !io.lsq.uncache.bits.uop.robIdx.needFlush(io.redirect) && !s3_out.valid && !io.lsq.uncache.bits.isVls 1356 // io.ldout.bits.data := Mux(s3_out.valid, s3_ld_data_frm_cache, s3_ld_data_frm_uncache) 1357 // io.ldout.valid := s3_out.valid && !s3_out.bits.uop.robIdx.needFlush(io.redirect) || 1358 // s3_mmio.valid && !s3_mmio.bits.uop.robIdx.needFlush(io.redirect) && !s3_out.valid 1359 1360 // s3 load fast replay 1361 io.fast_rep_out.valid := s3_valid && s3_fast_rep 1362 io.fast_rep_out.bits := s3_in 1363 io.fast_rep_out.bits.lateKill := s3_rep_frm_fetch 1364 1365 val vecFeedback = s3_valid && s3_fb_no_waiting && s3_rep_info.need_rep && !io.lsq.ldin.ready && s3_isvec 1366 1367 // vector output 1368 io.vecldout.bits.alignedType.get := s3_vec_alignedType 1369 // vec feedback 1370 io.vecldout.bits.vecFeedback := vecFeedback 1371 // TODO: VLSU, uncache data logic 1372 val vecdata = rdataVecHelper(s3_vec_alignedType(1,0), s3_picked_data_frm_cache) 1373 io.vecldout.bits.vecdata.get := Mux(s3_in.is128bit, s3_merged_data_frm_cache, vecdata) 1374 // io.vecldout.bits.hit := 1375 io.vecldout.bits.isvec := s3_vecout.isvec 1376 io.vecldout.bits.elemIdx.get := s3_vecout.elemIdx 1377 io.vecldout.bits.elemIdxInsideVd.get := s3_vecout.elemIdxInsideVd 1378 io.vecldout.bits.mask.get := s3_vecout.mask 1379 io.vecldout.bits.reg_offset.get := s3_vecout.reg_offset 1380 io.vecldout.bits.usSecondInv := s3_usSecondInv 1381 io.vecldout.bits.mBIndex := s3_vec_mBIndex 1382 io.vecldout.bits.hit := !s3_rep_info.need_rep || io.lsq.ldin.ready 1383 io.vecldout.bits.sourceType := RSFeedbackType.lrqFull 1384 io.vecldout.bits.exceptionVec := s3_out.bits.uop.exceptionVec 1385 io.vecldout.bits.mmio := DontCare 1386 1387 io.vecldout.valid := s3_out.valid && !s3_out.bits.uop.robIdx.needFlush(io.redirect) && s3_vecout.isvec || 1388 // TODO: check this, why !io.lsq.uncache.bits.isVls before? 1389 io.lsq.uncache.valid && !io.lsq.uncache.bits.uop.robIdx.needFlush(io.redirect) && !s3_out.valid && io.lsq.uncache.bits.isVls 1390 //io.lsq.uncache.valid && !io.lsq.uncache.bits.uop.robIdx.needFlush(io.redirect) && !s3_out.valid && !io.lsq.uncache.bits.isVls 1391 1392 // fast load to load forward 1393 if (EnableLoadToLoadForward) { 1394 io.l2l_fwd_out.valid := s3_valid && !s3_in.mmio && !s3_rep_info.need_rep 1395 io.l2l_fwd_out.data := Mux(s3_in.vaddr(3), s3_merged_data_frm_cache(127, 64), s3_merged_data_frm_cache(63, 0)) 1396 io.l2l_fwd_out.dly_ld_err := s3_dly_ld_err || // ecc delayed error 1397 s3_ldld_rep_inst || 1398 s3_rep_frm_fetch 1399 } else { 1400 io.l2l_fwd_out.valid := false.B 1401 io.l2l_fwd_out.data := DontCare 1402 io.l2l_fwd_out.dly_ld_err := DontCare 1403 } 1404 1405 // trigger 1406 val last_valid_data = RegNext(RegEnable(io.ldout.bits.data, io.ldout.fire)) 1407 val hit_ld_addr_trig_hit_vec = Wire(Vec(TriggerNum, Bool())) 1408 val lq_ld_addr_trig_hit_vec = io.lsq.trigger.lqLoadAddrTriggerHitVec 1409 (0 until TriggerNum).map{i => { 1410 val tdata2 = RegNext(io.trigger(i).tdata2) 1411 val matchType = RegNext(io.trigger(i).matchType) 1412 val tEnable = RegNext(io.trigger(i).tEnable) 1413 1414 hit_ld_addr_trig_hit_vec(i) := TriggerCmp(RegNext(s2_out.vaddr), tdata2, matchType, tEnable) 1415 io.trigger(i).addrHit := Mux(s3_out.valid, hit_ld_addr_trig_hit_vec(i), lq_ld_addr_trig_hit_vec(i)) 1416 }} 1417 io.lsq.trigger.hitLoadAddrTriggerHitVec := hit_ld_addr_trig_hit_vec 1418 1419 // FIXME: please move this part to LoadQueueReplay 1420 io.debug_ls := DontCare 1421 1422 // Topdown 1423 io.lsTopdownInfo.s1.robIdx := s1_in.uop.robIdx.value 1424 io.lsTopdownInfo.s1.vaddr_valid := s1_valid && s1_in.hasROBEntry 1425 io.lsTopdownInfo.s1.vaddr_bits := s1_vaddr 1426 io.lsTopdownInfo.s2.robIdx := s2_in.uop.robIdx.value 1427 io.lsTopdownInfo.s2.paddr_valid := s2_fire && s2_in.hasROBEntry && !s2_in.tlbMiss 1428 io.lsTopdownInfo.s2.paddr_bits := s2_in.paddr 1429 io.lsTopdownInfo.s2.first_real_miss := io.dcache.resp.bits.real_miss 1430 io.lsTopdownInfo.s2.cache_miss_en := s2_fire && s2_in.hasROBEntry && !s2_in.tlbMiss && !s2_in.missDbUpdated 1431 1432 // perf cnt 1433 XSPerfAccumulate("s0_in_valid", io.ldin.valid) 1434 XSPerfAccumulate("s0_in_block", io.ldin.valid && !io.ldin.fire) 1435 XSPerfAccumulate("s0_in_fire_first_issue", s0_valid && s0_sel_src.isFirstIssue) 1436 XSPerfAccumulate("s0_lsq_fire_first_issue", io.replay.fire) 1437 XSPerfAccumulate("s0_ldu_fire_first_issue", io.ldin.fire && s0_sel_src.isFirstIssue) 1438 XSPerfAccumulate("s0_fast_replay_issue", io.fast_rep_in.fire) 1439 XSPerfAccumulate("s0_stall_out", s0_valid && !s0_can_go) 1440 XSPerfAccumulate("s0_stall_dcache", s0_valid && !io.dcache.req.ready) 1441 XSPerfAccumulate("s0_addr_spec_success", s0_fire && s0_sel_src.vaddr(VAddrBits-1, 12) === io.ldin.bits.src(0)(VAddrBits-1, 12)) 1442 XSPerfAccumulate("s0_addr_spec_failed", s0_fire && s0_sel_src.vaddr(VAddrBits-1, 12) =/= io.ldin.bits.src(0)(VAddrBits-1, 12)) 1443 XSPerfAccumulate("s0_addr_spec_success_once", s0_fire && s0_sel_src.vaddr(VAddrBits-1, 12) === io.ldin.bits.src(0)(VAddrBits-1, 12) && s0_sel_src.isFirstIssue) 1444 XSPerfAccumulate("s0_addr_spec_failed_once", s0_fire && s0_sel_src.vaddr(VAddrBits-1, 12) =/= io.ldin.bits.src(0)(VAddrBits-1, 12) && s0_sel_src.isFirstIssue) 1445 XSPerfAccumulate("s0_forward_tl_d_channel", s0_out.forward_tlDchannel) 1446 XSPerfAccumulate("s0_hardware_prefetch_fire", s0_fire && s0_hw_prf_select) 1447 XSPerfAccumulate("s0_software_prefetch_fire", s0_fire && s0_sel_src.prf && s0_int_iss_select) 1448 XSPerfAccumulate("s0_hardware_prefetch_blocked", io.prefetch_req.valid && !s0_hw_prf_select) 1449 XSPerfAccumulate("s0_hardware_prefetch_total", io.prefetch_req.valid) 1450 1451 XSPerfAccumulate("s1_in_valid", s1_valid) 1452 XSPerfAccumulate("s1_in_fire", s1_fire) 1453 XSPerfAccumulate("s1_in_fire_first_issue", s1_fire && s1_in.isFirstIssue) 1454 XSPerfAccumulate("s1_tlb_miss", s1_fire && s1_tlb_miss) 1455 XSPerfAccumulate("s1_tlb_miss_first_issue", s1_fire && s1_tlb_miss && s1_in.isFirstIssue) 1456 XSPerfAccumulate("s1_stall_out", s1_valid && !s1_can_go) 1457 XSPerfAccumulate("s1_dly_err", s1_valid && s1_fast_rep_dly_err) 1458 1459 XSPerfAccumulate("s2_in_valid", s2_valid) 1460 XSPerfAccumulate("s2_in_fire", s2_fire) 1461 XSPerfAccumulate("s2_in_fire_first_issue", s2_fire && s2_in.isFirstIssue) 1462 XSPerfAccumulate("s2_dcache_miss", s2_fire && io.dcache.resp.bits.miss) 1463 XSPerfAccumulate("s2_dcache_miss_first_issue", s2_fire && io.dcache.resp.bits.miss && s2_in.isFirstIssue) 1464 XSPerfAccumulate("s2_dcache_real_miss_first_issue", s2_fire && io.dcache.resp.bits.miss && s2_in.isFirstIssue) 1465 XSPerfAccumulate("s2_full_forward", s2_fire && s2_full_fwd) 1466 XSPerfAccumulate("s2_dcache_miss_full_forward", s2_fire && s2_dcache_miss) 1467 XSPerfAccumulate("s2_fwd_frm_d_can", s2_valid && s2_fwd_frm_d_chan) 1468 XSPerfAccumulate("s2_fwd_frm_d_chan_or_mshr", s2_valid && s2_fwd_frm_d_chan_or_mshr) 1469 XSPerfAccumulate("s2_stall_out", s2_fire && !s2_can_go) 1470 XSPerfAccumulate("s2_prefetch", s2_fire && s2_prf) 1471 XSPerfAccumulate("s2_prefetch_ignored", s2_fire && s2_prf && s2_mq_nack) // ignore prefetch for mshr full / miss req port conflict 1472 XSPerfAccumulate("s2_prefetch_miss", s2_fire && s2_prf && io.dcache.resp.bits.miss) // prefetch req miss in l1 1473 XSPerfAccumulate("s2_prefetch_hit", s2_fire && s2_prf && !io.dcache.resp.bits.miss) // prefetch req hit in l1 1474 XSPerfAccumulate("s2_prefetch_accept", s2_fire && s2_prf && io.dcache.resp.bits.miss && !s2_mq_nack) // prefetch a missed line in l1, and l1 accepted it 1475 XSPerfAccumulate("s2_forward_req", s2_fire && s2_in.forward_tlDchannel) 1476 XSPerfAccumulate("s2_successfully_forward_channel_D", s2_fire && s2_fwd_frm_d_chan && s2_fwd_data_valid) 1477 XSPerfAccumulate("s2_successfully_forward_mshr", s2_fire && s2_fwd_frm_mshr && s2_fwd_data_valid) 1478 1479 XSPerfAccumulate("s3_fwd_frm_d_chan", s3_valid && s3_fwd_frm_d_chan_valid) 1480 1481 XSPerfAccumulate("load_to_load_forward", s1_try_ptr_chasing && !s1_ptr_chasing_canceled) 1482 XSPerfAccumulate("load_to_load_forward_try", s1_try_ptr_chasing) 1483 XSPerfAccumulate("load_to_load_forward_fail", s1_cancel_ptr_chasing) 1484 XSPerfAccumulate("load_to_load_forward_fail_cancelled", s1_cancel_ptr_chasing && s1_ptr_chasing_canceled) 1485 XSPerfAccumulate("load_to_load_forward_fail_wakeup_mismatch", s1_cancel_ptr_chasing && !s1_ptr_chasing_canceled && s1_not_fast_match) 1486 XSPerfAccumulate("load_to_load_forward_fail_op_not_ld", s1_cancel_ptr_chasing && !s1_ptr_chasing_canceled && !s1_not_fast_match && s1_fu_op_type_not_ld) 1487 XSPerfAccumulate("load_to_load_forward_fail_addr_align", s1_cancel_ptr_chasing && !s1_ptr_chasing_canceled && !s1_not_fast_match && !s1_fu_op_type_not_ld && s1_addr_misaligned) 1488 XSPerfAccumulate("load_to_load_forward_fail_set_mismatch", s1_cancel_ptr_chasing && !s1_ptr_chasing_canceled && !s1_not_fast_match && !s1_fu_op_type_not_ld && !s1_addr_misaligned && s1_addr_mismatch) 1489 1490 // bug lyq: some signals in perfEvents are no longer suitable for the current MemBlock design 1491 // hardware performance counter 1492 val perfEvents = Seq( 1493 ("load_s0_in_fire ", s0_fire ), 1494 ("load_to_load_forward ", s1_fire && s1_try_ptr_chasing && !s1_ptr_chasing_canceled ), 1495 ("stall_dcache ", s0_valid && s0_can_go && !io.dcache.req.ready ), 1496 ("load_s1_in_fire ", s0_fire ), 1497 ("load_s1_tlb_miss ", s1_fire && io.tlb.resp.bits.miss ), 1498 ("load_s2_in_fire ", s1_fire ), 1499 ("load_s2_dcache_miss ", s2_fire && io.dcache.resp.bits.miss ), 1500 ) 1501 generatePerfEvent() 1502 1503 when(io.ldout.fire){ 1504 XSDebug("ldout %x\n", io.ldout.bits.uop.pc) 1505 } 1506 // end 1507}