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 chipsalliance.rocketchip.config.Parameters 20import chisel3._ 21import chisel3.util._ 22import utils._ 23import xiangshan.ExceptionNO._ 24import xiangshan._ 25import xiangshan.backend.fu.PMPRespBundle 26import xiangshan.cache._ 27import xiangshan.cache.mmu.{TlbCmd, TlbReq, TlbRequestIO, TlbResp} 28 29class LoadToLsqIO(implicit p: Parameters) extends XSBundle { 30 val loadIn = ValidIO(new LqWriteBundle) 31 val loadPaddrIn = ValidIO(new LqPaddrWriteBundle) 32 val ldout = Flipped(DecoupledIO(new ExuOutput)) 33 val ldRawData = Input(new LoadDataFromLQBundle) 34 val s2_load_data_forwarded = Output(Bool()) 35 val s3_delayed_load_error = Output(Bool()) 36 val s2_dcache_require_replay = Output(Bool()) 37 val s3_replay_from_fetch = Output(Bool()) // update uop.ctrl.replayInst in load queue in s3 38 val forward = new PipeLoadForwardQueryIO 39 val loadViolationQuery = new LoadViolationQueryIO 40 val trigger = Flipped(new LqTriggerIO) 41} 42 43class LoadToLoadIO(implicit p: Parameters) extends XSBundle { 44 // load to load fast path is limited to ld (64 bit) used as vaddr src1 only 45 val data = UInt(XLEN.W) 46 val valid = Bool() 47} 48 49class LoadUnitTriggerIO(implicit p: Parameters) extends XSBundle { 50 val tdata2 = Input(UInt(64.W)) 51 val matchType = Input(UInt(2.W)) 52 val tEnable = Input(Bool()) // timing is calculated before this 53 val addrHit = Output(Bool()) 54 val lastDataHit = Output(Bool()) 55} 56 57// Load Pipeline Stage 0 58// Generate addr, use addr to query DCache and DTLB 59class LoadUnit_S0(implicit p: Parameters) extends XSModule with HasDCacheParameters{ 60 val io = IO(new Bundle() { 61 val in = Flipped(Decoupled(new ExuInput)) 62 val out = Decoupled(new LsPipelineBundle) 63 val dtlbReq = DecoupledIO(new TlbReq) 64 val dcacheReq = DecoupledIO(new DCacheWordReq) 65 val rsIdx = Input(UInt(log2Up(IssQueSize).W)) 66 val isFirstIssue = Input(Bool()) 67 val fastpath = Input(new LoadToLoadIO) 68 val s0_kill = Input(Bool()) 69 }) 70 require(LoadPipelineWidth == exuParameters.LduCnt) 71 72 val imm12 = io.in.bits.uop.ctrl.imm(11, 0) 73 val s0_vaddr = WireInit(io.in.bits.src(0) + SignExt(imm12, VAddrBits)) 74 val s0_mask = WireInit(genWmask(s0_vaddr, io.in.bits.uop.ctrl.fuOpType(1,0))) 75 val s0_uop = WireInit(io.in.bits.uop) 76 77 if (EnableLoadToLoadForward) { 78 // When there's no valid instruction from RS, we try the load-to-load forwarding. 79 when (!io.in.valid) { 80 s0_vaddr := io.fastpath.data 81 // Assume the pointer chasing is always ld. 82 s0_uop.ctrl.fuOpType := LSUOpType.ld 83 s0_mask := genWmask(0.U, LSUOpType.ld) 84 } 85 } 86 87 val isSoftPrefetch = LSUOpType.isPrefetch(s0_uop.ctrl.fuOpType) 88 val isSoftPrefetchRead = s0_uop.ctrl.fuOpType === LSUOpType.prefetch_r 89 val isSoftPrefetchWrite = s0_uop.ctrl.fuOpType === LSUOpType.prefetch_w 90 91 // query DTLB 92 io.dtlbReq.valid := io.in.valid || io.fastpath.valid 93 io.dtlbReq.bits.vaddr := s0_vaddr 94 io.dtlbReq.bits.cmd := TlbCmd.read 95 io.dtlbReq.bits.size := LSUOpType.size(s0_uop.ctrl.fuOpType) 96 io.dtlbReq.bits.kill := DontCare 97 io.dtlbReq.bits.debug.robIdx := s0_uop.robIdx 98 io.dtlbReq.bits.debug.pc := s0_uop.cf.pc 99 io.dtlbReq.bits.debug.isFirstIssue := io.isFirstIssue 100 101 // query DCache 102 io.dcacheReq.valid := io.in.valid || io.fastpath.valid 103 when (isSoftPrefetchRead) { 104 io.dcacheReq.bits.cmd := MemoryOpConstants.M_PFR 105 }.elsewhen (isSoftPrefetchWrite) { 106 io.dcacheReq.bits.cmd := MemoryOpConstants.M_PFW 107 }.otherwise { 108 io.dcacheReq.bits.cmd := MemoryOpConstants.M_XRD 109 } 110 io.dcacheReq.bits.addr := s0_vaddr 111 io.dcacheReq.bits.mask := s0_mask 112 io.dcacheReq.bits.data := DontCare 113 when(isSoftPrefetch) { 114 io.dcacheReq.bits.instrtype := SOFT_PREFETCH.U 115 }.otherwise { 116 io.dcacheReq.bits.instrtype := LOAD_SOURCE.U 117 } 118 119 // TODO: update cache meta 120 io.dcacheReq.bits.id := DontCare 121 122 val addrAligned = LookupTree(s0_uop.ctrl.fuOpType(1, 0), List( 123 "b00".U -> true.B, //b 124 "b01".U -> (s0_vaddr(0) === 0.U), //h 125 "b10".U -> (s0_vaddr(1, 0) === 0.U), //w 126 "b11".U -> (s0_vaddr(2, 0) === 0.U) //d 127 )) 128 129 io.out.valid := (io.in.valid || io.fastpath.valid) && io.dcacheReq.ready && !io.s0_kill 130 131 io.out.bits := DontCare 132 io.out.bits.vaddr := s0_vaddr 133 io.out.bits.mask := s0_mask 134 io.out.bits.uop := s0_uop 135 io.out.bits.uop.cf.exceptionVec(loadAddrMisaligned) := !addrAligned 136 io.out.bits.rsIdx := io.rsIdx 137 io.out.bits.isFirstIssue := io.isFirstIssue 138 io.out.bits.isSoftPrefetch := isSoftPrefetch 139 140 io.in.ready := !io.in.valid || (io.out.ready && io.dcacheReq.ready) 141 142 XSDebug(io.dcacheReq.fire, 143 p"[DCACHE LOAD REQ] pc ${Hexadecimal(s0_uop.cf.pc)}, vaddr ${Hexadecimal(s0_vaddr)}\n" 144 ) 145 XSPerfAccumulate("in_valid", io.in.valid) 146 XSPerfAccumulate("in_fire", io.in.fire) 147 XSPerfAccumulate("in_fire_first_issue", io.in.valid && io.isFirstIssue) 148 XSPerfAccumulate("stall_out", io.out.valid && !io.out.ready && io.dcacheReq.ready) 149 XSPerfAccumulate("stall_dcache", io.out.valid && io.out.ready && !io.dcacheReq.ready) 150 XSPerfAccumulate("addr_spec_success", io.out.fire && s0_vaddr(VAddrBits-1, 12) === io.in.bits.src(0)(VAddrBits-1, 12)) 151 XSPerfAccumulate("addr_spec_failed", io.out.fire && s0_vaddr(VAddrBits-1, 12) =/= io.in.bits.src(0)(VAddrBits-1, 12)) 152 XSPerfAccumulate("addr_spec_success_once", io.out.fire && s0_vaddr(VAddrBits-1, 12) === io.in.bits.src(0)(VAddrBits-1, 12) && io.isFirstIssue) 153 XSPerfAccumulate("addr_spec_failed_once", io.out.fire && s0_vaddr(VAddrBits-1, 12) =/= io.in.bits.src(0)(VAddrBits-1, 12) && io.isFirstIssue) 154} 155 156 157// Load Pipeline Stage 1 158// TLB resp (send paddr to dcache) 159class LoadUnit_S1(implicit p: Parameters) extends XSModule { 160 val io = IO(new Bundle() { 161 val in = Flipped(Decoupled(new LsPipelineBundle)) 162 val s1_kill = Input(Bool()) 163 val out = Decoupled(new LsPipelineBundle) 164 val dtlbResp = Flipped(DecoupledIO(new TlbResp(2))) 165 val lsuPAddr = Output(UInt(PAddrBits.W)) 166 val dcachePAddr = Output(UInt(PAddrBits.W)) 167 val dcacheKill = Output(Bool()) 168 val dcacheBankConflict = Input(Bool()) 169 val fullForwardFast = Output(Bool()) 170 val sbuffer = new LoadForwardQueryIO 171 val lsq = new PipeLoadForwardQueryIO 172 val loadViolationQueryReq = Decoupled(new LoadViolationQueryReq) 173 val rsFeedback = ValidIO(new RSFeedback) 174 val csrCtrl = Flipped(new CustomCSRCtrlIO) 175 val needLdVioCheckRedo = Output(Bool()) 176 }) 177 178 val s1_uop = io.in.bits.uop 179 val s1_paddr_dup_lsu = io.dtlbResp.bits.paddr(0) 180 val s1_paddr_dup_dcache = io.dtlbResp.bits.paddr(1) 181 // af & pf exception were modified below. 182 val s1_exception = ExceptionNO.selectByFu(io.out.bits.uop.cf.exceptionVec, lduCfg).asUInt.orR 183 val s1_tlb_miss = io.dtlbResp.bits.miss 184 val s1_mask = io.in.bits.mask 185 val s1_bank_conflict = io.dcacheBankConflict 186 187 io.out.bits := io.in.bits // forwardXX field will be updated in s1 188 189 io.dtlbResp.ready := true.B 190 191 io.lsuPAddr := s1_paddr_dup_lsu 192 io.dcachePAddr := s1_paddr_dup_dcache 193 //io.dcacheKill := s1_tlb_miss || s1_exception || s1_mmio 194 io.dcacheKill := s1_tlb_miss || s1_exception || io.s1_kill 195 // load forward query datapath 196 io.sbuffer.valid := io.in.valid && !(s1_exception || s1_tlb_miss || io.s1_kill) 197 io.sbuffer.vaddr := io.in.bits.vaddr 198 io.sbuffer.paddr := s1_paddr_dup_lsu 199 io.sbuffer.uop := s1_uop 200 io.sbuffer.sqIdx := s1_uop.sqIdx 201 io.sbuffer.mask := s1_mask 202 io.sbuffer.pc := s1_uop.cf.pc // FIXME: remove it 203 204 io.lsq.valid := io.in.valid && !(s1_exception || s1_tlb_miss || io.s1_kill) 205 io.lsq.vaddr := io.in.bits.vaddr 206 io.lsq.paddr := s1_paddr_dup_lsu 207 io.lsq.uop := s1_uop 208 io.lsq.sqIdx := s1_uop.sqIdx 209 io.lsq.sqIdxMask := DontCare // will be overwritten by sqIdxMask pre-generated in s0 210 io.lsq.mask := s1_mask 211 io.lsq.pc := s1_uop.cf.pc // FIXME: remove it 212 213 // ld-ld violation query 214 io.loadViolationQueryReq.valid := io.in.valid && !(s1_exception || s1_tlb_miss || io.s1_kill) 215 io.loadViolationQueryReq.bits.paddr := s1_paddr_dup_lsu 216 io.loadViolationQueryReq.bits.uop := s1_uop 217 218 // Generate forwardMaskFast to wake up insts earlier 219 val forwardMaskFast = io.lsq.forwardMaskFast.asUInt | io.sbuffer.forwardMaskFast.asUInt 220 io.fullForwardFast := ((~forwardMaskFast).asUInt & s1_mask) === 0.U 221 222 // Generate feedback signal caused by: 223 // * dcache bank conflict 224 // * need redo ld-ld violation check 225 val needLdVioCheckRedo = io.loadViolationQueryReq.valid && 226 !io.loadViolationQueryReq.ready && 227 RegNext(io.csrCtrl.ldld_vio_check_enable) 228 io.needLdVioCheckRedo := needLdVioCheckRedo 229 io.rsFeedback.valid := io.in.valid && (s1_bank_conflict || needLdVioCheckRedo) && !io.s1_kill 230 io.rsFeedback.bits.hit := false.B // we have found s1_bank_conflict / re do ld-ld violation check 231 io.rsFeedback.bits.rsIdx := io.in.bits.rsIdx 232 io.rsFeedback.bits.flushState := io.in.bits.ptwBack 233 io.rsFeedback.bits.sourceType := Mux(s1_bank_conflict, RSFeedbackType.bankConflict, RSFeedbackType.ldVioCheckRedo) 234 io.rsFeedback.bits.dataInvalidSqIdx := DontCare 235 236 // if replay is detected in load_s1, 237 // load inst will be canceled immediately 238 io.out.valid := io.in.valid && !io.rsFeedback.valid && !io.s1_kill 239 io.out.bits.paddr := s1_paddr_dup_lsu 240 io.out.bits.tlbMiss := s1_tlb_miss 241 242 // current ori test will cause the case of ldest == 0, below will be modifeid in the future. 243 // af & pf exception were modified 244 io.out.bits.uop.cf.exceptionVec(loadPageFault) := io.dtlbResp.bits.excp(0).pf.ld 245 io.out.bits.uop.cf.exceptionVec(loadAccessFault) := io.dtlbResp.bits.excp(0).af.ld 246 247 io.out.bits.ptwBack := io.dtlbResp.bits.ptwBack 248 io.out.bits.rsIdx := io.in.bits.rsIdx 249 250 io.out.bits.isSoftPrefetch := io.in.bits.isSoftPrefetch 251 252 io.in.ready := !io.in.valid || io.out.ready 253 254 XSPerfAccumulate("in_valid", io.in.valid) 255 XSPerfAccumulate("in_fire", io.in.fire) 256 XSPerfAccumulate("in_fire_first_issue", io.in.fire && io.in.bits.isFirstIssue) 257 XSPerfAccumulate("tlb_miss", io.in.fire && s1_tlb_miss) 258 XSPerfAccumulate("tlb_miss_first_issue", io.in.fire && s1_tlb_miss && io.in.bits.isFirstIssue) 259 XSPerfAccumulate("stall_out", io.out.valid && !io.out.ready) 260} 261 262// Load Pipeline Stage 2 263// DCache resp 264class LoadUnit_S2(implicit p: Parameters) extends XSModule with HasLoadHelper { 265 val io = IO(new Bundle() { 266 val in = Flipped(Decoupled(new LsPipelineBundle)) 267 val out = Decoupled(new LsPipelineBundle) 268 val rsFeedback = ValidIO(new RSFeedback) 269 val dcacheResp = Flipped(DecoupledIO(new DCacheWordResp)) 270 val pmpResp = Flipped(new PMPRespBundle()) 271 val lsq = new LoadForwardQueryIO 272 val dataInvalidSqIdx = Input(UInt()) 273 val sbuffer = new LoadForwardQueryIO 274 val dataForwarded = Output(Bool()) 275 val s2_dcache_require_replay = Output(Bool()) 276 val fullForward = Output(Bool()) 277 val fastpath = Output(new LoadToLoadIO) 278 val dcache_kill = Output(Bool()) 279 val s3_delayed_load_error = Output(Bool()) 280 val loadViolationQueryResp = Flipped(Valid(new LoadViolationQueryResp)) 281 val csrCtrl = Flipped(new CustomCSRCtrlIO) 282 val sentFastUop = Input(Bool()) 283 val static_pm = Input(Valid(Bool())) // valid for static, bits for mmio 284 val s2_can_replay_from_fetch = Output(Bool()) // dirty code 285 val loadDataFromDcache = Output(new LoadDataFromDcacheBundle) 286 }) 287 288 val pmp = WireInit(io.pmpResp) 289 when (io.static_pm.valid) { 290 pmp.ld := false.B 291 pmp.st := false.B 292 pmp.instr := false.B 293 pmp.mmio := io.static_pm.bits 294 } 295 296 val s2_is_prefetch = io.in.bits.isSoftPrefetch 297 298 // exception that may cause load addr to be invalid / illegal 299 // 300 // if such exception happen, that inst and its exception info 301 // will be force writebacked to rob 302 val s2_exception_vec = WireInit(io.in.bits.uop.cf.exceptionVec) 303 s2_exception_vec(loadAccessFault) := io.in.bits.uop.cf.exceptionVec(loadAccessFault) || pmp.ld 304 // soft prefetch will not trigger any exception (but ecc error interrupt may be triggered) 305 when (s2_is_prefetch) { 306 s2_exception_vec := 0.U.asTypeOf(s2_exception_vec.cloneType) 307 } 308 val s2_exception = ExceptionNO.selectByFu(s2_exception_vec, lduCfg).asUInt.orR 309 310 // writeback access fault caused by ecc error / bus error 311 // 312 // * ecc data error is slow to generate, so we will not use it until load stage 3 313 // * in load stage 3, an extra signal io.load_error will be used to 314 315 // now cache ecc error will raise an access fault 316 // at the same time, error info (including error paddr) will be write to 317 // an customized CSR "CACHE_ERROR" 318 if (EnableAccurateLoadError) { 319 io.s3_delayed_load_error := io.dcacheResp.bits.error_delayed && 320 io.csrCtrl.cache_error_enable && 321 RegNext(io.out.valid) 322 } else { 323 io.s3_delayed_load_error := false.B 324 } 325 326 val actually_mmio = pmp.mmio 327 val s2_uop = io.in.bits.uop 328 val s2_mask = io.in.bits.mask 329 val s2_paddr = io.in.bits.paddr 330 val s2_tlb_miss = io.in.bits.tlbMiss 331 val s2_mmio = !s2_is_prefetch && actually_mmio && !s2_exception 332 val s2_cache_miss = io.dcacheResp.bits.miss 333 val s2_cache_replay = io.dcacheResp.bits.replay 334 val s2_cache_tag_error = io.dcacheResp.bits.tag_error 335 val s2_forward_fail = io.lsq.matchInvalid || io.sbuffer.matchInvalid 336 val s2_ldld_violation = io.loadViolationQueryResp.valid && 337 io.loadViolationQueryResp.bits.have_violation && 338 RegNext(io.csrCtrl.ldld_vio_check_enable) 339 val s2_data_invalid = io.lsq.dataInvalid && !s2_ldld_violation && !s2_exception 340 341 io.dcache_kill := pmp.ld || pmp.mmio // move pmp resp kill to outside 342 io.dcacheResp.ready := true.B 343 val dcacheShouldResp = !(s2_tlb_miss || s2_exception || s2_mmio || s2_is_prefetch) 344 assert(!(io.in.valid && (dcacheShouldResp && !io.dcacheResp.valid)), "DCache response got lost") 345 346 // merge forward result 347 // lsq has higher priority than sbuffer 348 val forwardMask = Wire(Vec(8, Bool())) 349 val forwardData = Wire(Vec(8, UInt(8.W))) 350 351 val fullForward = ((~forwardMask.asUInt).asUInt & s2_mask) === 0.U && !io.lsq.dataInvalid 352 io.lsq := DontCare 353 io.sbuffer := DontCare 354 io.fullForward := fullForward 355 356 // generate XLEN/8 Muxs 357 for (i <- 0 until XLEN / 8) { 358 forwardMask(i) := io.lsq.forwardMask(i) || io.sbuffer.forwardMask(i) 359 forwardData(i) := Mux(io.lsq.forwardMask(i), io.lsq.forwardData(i), io.sbuffer.forwardData(i)) 360 } 361 362 XSDebug(io.out.fire, "[FWD LOAD RESP] pc %x fwd %x(%b) + %x(%b)\n", 363 s2_uop.cf.pc, 364 io.lsq.forwardData.asUInt, io.lsq.forwardMask.asUInt, 365 io.in.bits.forwardData.asUInt, io.in.bits.forwardMask.asUInt 366 ) 367 368 // data merge 369 val rdataVec = VecInit((0 until XLEN / 8).map(j => 370 Mux(forwardMask(j), forwardData(j), io.dcacheResp.bits.data(8*(j+1)-1, 8*j)) 371 )) // s2_rdataVec will be write to load queue 372 val rdata = rdataVec.asUInt 373 val rdataSel = LookupTree(s2_paddr(2, 0), List( 374 "b000".U -> rdata(63, 0), 375 "b001".U -> rdata(63, 8), 376 "b010".U -> rdata(63, 16), 377 "b011".U -> rdata(63, 24), 378 "b100".U -> rdata(63, 32), 379 "b101".U -> rdata(63, 40), 380 "b110".U -> rdata(63, 48), 381 "b111".U -> rdata(63, 56) 382 )) 383 val rdataPartialLoad = rdataHelper(s2_uop, rdataSel) // s2_rdataPartialLoad is not used 384 385 io.out.valid := io.in.valid && !s2_tlb_miss && !s2_data_invalid 386 // Inst will be canceled in store queue / lsq, 387 // so we do not need to care about flush in load / store unit's out.valid 388 io.out.bits := io.in.bits 389 // io.out.bits.data := rdataPartialLoad 390 io.out.bits.data := 0.U // data will be generated in load_s3 391 // when exception occurs, set it to not miss and let it write back to rob (via int port) 392 if (EnableFastForward) { 393 io.out.bits.miss := s2_cache_miss && 394 !s2_exception && 395 !fullForward && 396 !s2_is_prefetch 397 } else { 398 io.out.bits.miss := s2_cache_miss && 399 !s2_exception && 400 !s2_is_prefetch 401 } 402 io.out.bits.uop.ctrl.fpWen := io.in.bits.uop.ctrl.fpWen && !s2_exception 403 404 io.loadDataFromDcache.dcacheData := io.dcacheResp.bits.data 405 io.loadDataFromDcache.forwardMask := forwardMask 406 io.loadDataFromDcache.forwardData := forwardData 407 io.loadDataFromDcache.uop := io.out.bits.uop 408 io.loadDataFromDcache.addrOffset := s2_paddr(2, 0) 409 410 io.s2_can_replay_from_fetch := !s2_mmio && !s2_is_prefetch && !s2_tlb_miss 411 // if forward fail, replay this inst from fetch 412 val debug_forwardFailReplay = s2_forward_fail && !s2_mmio && !s2_is_prefetch && !s2_tlb_miss 413 // if ld-ld violation is detected, replay from this inst from fetch 414 val debug_ldldVioReplay = s2_ldld_violation && !s2_mmio && !s2_is_prefetch && !s2_tlb_miss 415 // io.out.bits.uop.ctrl.replayInst := false.B 416 417 io.out.bits.mmio := s2_mmio 418 io.out.bits.uop.ctrl.flushPipe := s2_mmio && io.sentFastUop 419 io.out.bits.uop.cf.exceptionVec := s2_exception_vec // cache error not included 420 421 // For timing reasons, sometimes we can not let 422 // io.out.bits.miss := s2_cache_miss && !s2_exception && !fullForward 423 // We use io.dataForwarded instead. It means: 424 // 1. Forward logic have prepared all data needed, 425 // and dcache query is no longer needed. 426 // 2. ... or data cache tag error is detected, this kind of inst 427 // will not update miss queue. That is to say, if miss, that inst 428 // may not be refilled 429 // Such inst will be writebacked from load queue. 430 io.dataForwarded := s2_cache_miss && !s2_exception && 431 (fullForward || io.csrCtrl.cache_error_enable && s2_cache_tag_error) 432 // io.out.bits.forwardX will be send to lq 433 io.out.bits.forwardMask := forwardMask 434 // data retrived from dcache is also included in io.out.bits.forwardData 435 io.out.bits.forwardData := rdataVec 436 437 io.in.ready := io.out.ready || !io.in.valid 438 439 // feedback tlb result to RS 440 io.rsFeedback.valid := io.in.valid 441 val s2_need_replay_from_rs = Wire(Bool()) 442 if (EnableFastForward) { 443 s2_need_replay_from_rs := 444 s2_tlb_miss || // replay if dtlb miss 445 s2_cache_replay && !s2_is_prefetch && !s2_mmio && !s2_exception && !fullForward || // replay if dcache miss queue full / busy 446 s2_data_invalid && !s2_is_prefetch // replay if store to load forward data is not ready 447 } else { 448 // Note that if all parts of data are available in sq / sbuffer, replay required by dcache will not be scheduled 449 s2_need_replay_from_rs := 450 s2_tlb_miss || // replay if dtlb miss 451 s2_cache_replay && !s2_is_prefetch && !s2_mmio && !s2_exception && !io.dataForwarded || // replay if dcache miss queue full / busy 452 s2_data_invalid && !s2_is_prefetch // replay if store to load forward data is not ready 453 } 454 io.rsFeedback.bits.hit := !s2_need_replay_from_rs 455 io.rsFeedback.bits.rsIdx := io.in.bits.rsIdx 456 io.rsFeedback.bits.flushState := io.in.bits.ptwBack 457 // feedback source priority: tlbMiss > dataInvalid > mshrFull 458 // general case priority: tlbMiss > exception (include forward_fail / ldld_violation) > mmio > dataInvalid > mshrFull > normal miss / hit 459 io.rsFeedback.bits.sourceType := Mux(s2_tlb_miss, RSFeedbackType.tlbMiss, 460 Mux(s2_data_invalid, 461 RSFeedbackType.dataInvalid, 462 RSFeedbackType.mshrFull 463 ) 464 ) 465 io.rsFeedback.bits.dataInvalidSqIdx.value := io.dataInvalidSqIdx 466 io.rsFeedback.bits.dataInvalidSqIdx.flag := DontCare 467 468 // s2_cache_replay is quite slow to generate, send it separately to LQ 469 if (EnableFastForward) { 470 io.s2_dcache_require_replay := s2_cache_replay && !fullForward 471 } else { 472 io.s2_dcache_require_replay := s2_cache_replay && 473 !io.rsFeedback.bits.hit && 474 !io.dataForwarded && 475 !s2_is_prefetch && 476 io.out.bits.miss 477 } 478 479 // fast load to load forward 480 io.fastpath.valid := RegNext(io.out.valid) // for debug only 481 io.fastpath.data := RegNext(rdata) // fastpath is for ld only 482 483 XSDebug(io.out.fire, "[DCACHE LOAD RESP] pc %x rdata %x <- D$ %x + fwd %x(%b)\n", 484 s2_uop.cf.pc, rdataPartialLoad, io.dcacheResp.bits.data, 485 forwardData.asUInt, forwardMask.asUInt 486 ) 487 488 XSPerfAccumulate("in_valid", io.in.valid) 489 XSPerfAccumulate("in_fire", io.in.fire) 490 XSPerfAccumulate("in_fire_first_issue", io.in.fire && io.in.bits.isFirstIssue) 491 XSPerfAccumulate("dcache_miss", io.in.fire && s2_cache_miss) 492 XSPerfAccumulate("dcache_miss_first_issue", io.in.fire && s2_cache_miss && io.in.bits.isFirstIssue) 493 XSPerfAccumulate("full_forward", io.in.valid && fullForward) 494 XSPerfAccumulate("dcache_miss_full_forward", io.in.valid && s2_cache_miss && fullForward) 495 XSPerfAccumulate("replay", io.rsFeedback.valid && !io.rsFeedback.bits.hit) 496 XSPerfAccumulate("replay_tlb_miss", io.rsFeedback.valid && !io.rsFeedback.bits.hit && s2_tlb_miss) 497 XSPerfAccumulate("replay_cache", io.rsFeedback.valid && !io.rsFeedback.bits.hit && !s2_tlb_miss && s2_cache_replay) 498 XSPerfAccumulate("stall_out", io.out.valid && !io.out.ready) 499 XSPerfAccumulate("replay_from_fetch_forward", io.out.valid && debug_forwardFailReplay) 500 XSPerfAccumulate("replay_from_fetch_load_vio", io.out.valid && debug_ldldVioReplay) 501} 502 503class LoadUnit(implicit p: Parameters) extends XSModule 504 with HasLoadHelper 505 with HasPerfEvents 506 with HasDCacheParameters 507{ 508 val io = IO(new Bundle() { 509 val ldin = Flipped(Decoupled(new ExuInput)) 510 val ldout = Decoupled(new ExuOutput) 511 val redirect = Flipped(ValidIO(new Redirect)) 512 val feedbackSlow = ValidIO(new RSFeedback) 513 val feedbackFast = ValidIO(new RSFeedback) 514 val rsIdx = Input(UInt(log2Up(IssQueSize).W)) 515 val isFirstIssue = Input(Bool()) 516 val dcache = new DCacheLoadIO 517 val sbuffer = new LoadForwardQueryIO 518 val lsq = new LoadToLsqIO 519 val refill = Flipped(ValidIO(new Refill)) 520 val fastUop = ValidIO(new MicroOp) // early wakeup signal generated in load_s1, send to RS in load_s2 521 val trigger = Vec(3, new LoadUnitTriggerIO) 522 523 val tlb = new TlbRequestIO(2) 524 val pmp = Flipped(new PMPRespBundle()) // arrive same to tlb now 525 526 val fastpathOut = Output(new LoadToLoadIO) 527 val fastpathIn = Input(new LoadToLoadIO) 528 val loadFastMatch = Input(Bool()) 529 val loadFastImm = Input(UInt(12.W)) 530 531 val s3_delayed_load_error = Output(Bool()) // load ecc error 532 // Note that io.s3_delayed_load_error and io.lsq.s3_delayed_load_error is different 533 534 val csrCtrl = Flipped(new CustomCSRCtrlIO) 535 }) 536 537 val load_s0 = Module(new LoadUnit_S0) 538 val load_s1 = Module(new LoadUnit_S1) 539 val load_s2 = Module(new LoadUnit_S2) 540 541 // load s0 542 load_s0.io.in <> io.ldin 543 load_s0.io.dtlbReq <> io.tlb.req 544 load_s0.io.dcacheReq <> io.dcache.req 545 load_s0.io.rsIdx := io.rsIdx 546 load_s0.io.isFirstIssue := io.isFirstIssue 547 load_s0.io.fastpath := io.fastpathIn 548 load_s0.io.s0_kill := false.B 549 val s0_tryPointerChasing = !io.ldin.valid && io.fastpathIn.valid 550 val s0_pointerChasingVAddr = io.fastpathIn.data(5, 0) +& io.loadFastImm(5, 0) 551 552 val s1_data = PipelineConnect(load_s0.io.out, load_s1.io.in, true.B, 553 load_s0.io.out.bits.uop.robIdx.needFlush(io.redirect) && !s0_tryPointerChasing).get 554 555 // load s1 556 load_s1.io.dtlbResp <> io.tlb.resp 557 io.dcache.s1_paddr_dup_lsu <> load_s1.io.lsuPAddr 558 io.dcache.s1_paddr_dup_dcache <> load_s1.io.dcachePAddr 559 io.dcache.s1_kill := load_s1.io.dcacheKill 560 load_s1.io.sbuffer <> io.sbuffer 561 load_s1.io.lsq <> io.lsq.forward 562 load_s1.io.loadViolationQueryReq <> io.lsq.loadViolationQuery.req 563 load_s1.io.dcacheBankConflict <> io.dcache.s1_bank_conflict 564 load_s1.io.csrCtrl <> io.csrCtrl 565 566 val s0_doTryPointerChasing = s0_tryPointerChasing && load_s0.io.in.ready && load_s0.io.dcacheReq.ready 567 val s1_tryPointerChasing = RegNext(s0_doTryPointerChasing, false.B) 568 val s1_pointerChasingVAddr = RegEnable(s0_pointerChasingVAddr, s0_doTryPointerChasing) 569 val cancelPointerChasing = WireInit(false.B) 570 if (EnableLoadToLoadForward) { 571 // Sometimes, we need to cancel the load-load forwarding. 572 // These can be put at S0 if timing is bad at S1. 573 // Case 0: CACHE_SET(base + offset) != CACHE_SET(base) (lowest 6-bit addition has an overflow) 574 val addressMisMatch = s1_pointerChasingVAddr(6) || RegEnable(io.loadFastImm(11, 6).orR, s0_doTryPointerChasing) 575 // Case 1: the address is not 64-bit aligned or the fuOpType is not LD 576 val addressNotAligned = s1_pointerChasingVAddr(2, 0).orR 577 val fuOpTypeIsNotLd = io.ldin.bits.uop.ctrl.fuOpType =/= LSUOpType.ld 578 // Case 2: this is not a valid load-load pair 579 val notFastMatch = RegEnable(!io.loadFastMatch, s0_tryPointerChasing) 580 // Case 3: this load-load uop is cancelled 581 val isCancelled = !io.ldin.valid 582 when (s1_tryPointerChasing) { 583 cancelPointerChasing := addressMisMatch || addressNotAligned || fuOpTypeIsNotLd || notFastMatch || isCancelled 584 load_s1.io.in.bits.uop := io.ldin.bits.uop 585 val spec_vaddr = s1_data.vaddr 586 val vaddr = Cat(spec_vaddr(VAddrBits - 1, 6), s1_pointerChasingVAddr(5, 3), 0.U(3.W)) 587 load_s1.io.in.bits.vaddr := vaddr 588 load_s1.io.in.bits.rsIdx := io.rsIdx 589 load_s1.io.in.bits.isFirstIssue := io.isFirstIssue 590 // We need to replace vaddr(5, 3). 591 for (d <- 0 until 2) { 592 val spec_paddr = io.tlb.resp.bits.paddr(d) 593 load_s1.io.dtlbResp.bits.paddr(d) := Cat(spec_paddr(PAddrBits - 1, 6), s1_pointerChasingVAddr(5, 3), 0.U(3.W)) 594 } 595 } 596 when (cancelPointerChasing) { 597 load_s1.io.s1_kill := true.B 598 }.otherwise { 599 load_s0.io.s0_kill := s1_tryPointerChasing 600 when (s1_tryPointerChasing) { 601 io.ldin.ready := true.B 602 } 603 } 604 605 XSPerfAccumulate("load_to_load_forward", s1_tryPointerChasing && !cancelPointerChasing) 606 XSPerfAccumulate("load_to_load_forward_try", s1_tryPointerChasing) 607 XSPerfAccumulate("load_to_load_forward_fail", cancelPointerChasing) 608 XSPerfAccumulate("load_to_load_forward_fail_cancelled", cancelPointerChasing && isCancelled) 609 XSPerfAccumulate("load_to_load_forward_fail_wakeup_mismatch", cancelPointerChasing && !isCancelled && notFastMatch) 610 XSPerfAccumulate("load_to_load_forward_fail_op_not_ld", 611 cancelPointerChasing && !isCancelled && !notFastMatch && fuOpTypeIsNotLd) 612 XSPerfAccumulate("load_to_load_forward_fail_addr_align", 613 cancelPointerChasing && !isCancelled && !notFastMatch && !fuOpTypeIsNotLd && addressNotAligned) 614 XSPerfAccumulate("load_to_load_forward_fail_set_mismatch", 615 cancelPointerChasing && !isCancelled && !notFastMatch && !fuOpTypeIsNotLd && !addressNotAligned && addressMisMatch) 616 } 617 PipelineConnect(load_s1.io.out, load_s2.io.in, true.B, 618 load_s1.io.out.bits.uop.robIdx.needFlush(io.redirect) || cancelPointerChasing) 619 620 // provide paddr for lq 621 io.lsq.loadPaddrIn.valid := load_s1.io.out.valid 622 io.lsq.loadPaddrIn.bits.lqIdx := load_s1.io.out.bits.uop.lqIdx 623 io.lsq.loadPaddrIn.bits.paddr := load_s1.io.lsuPAddr 624 625 // load s2 626 io.dcache.s2_kill := load_s2.io.dcache_kill // to kill mmio resp which are redirected 627 load_s2.io.dcacheResp <> io.dcache.resp 628 load_s2.io.pmpResp <> io.pmp 629 load_s2.io.static_pm := RegNext(io.tlb.resp.bits.static_pm) 630 load_s2.io.lsq.forwardData <> io.lsq.forward.forwardData 631 load_s2.io.lsq.forwardMask <> io.lsq.forward.forwardMask 632 load_s2.io.lsq.forwardMaskFast <> io.lsq.forward.forwardMaskFast // should not be used in load_s2 633 load_s2.io.lsq.dataInvalid <> io.lsq.forward.dataInvalid 634 load_s2.io.lsq.matchInvalid <> io.lsq.forward.matchInvalid 635 load_s2.io.sbuffer.forwardData <> io.sbuffer.forwardData 636 load_s2.io.sbuffer.forwardMask <> io.sbuffer.forwardMask 637 load_s2.io.sbuffer.forwardMaskFast <> io.sbuffer.forwardMaskFast // should not be used in load_s2 638 load_s2.io.sbuffer.dataInvalid <> io.sbuffer.dataInvalid // always false 639 load_s2.io.sbuffer.matchInvalid <> io.sbuffer.matchInvalid 640 load_s2.io.dataForwarded <> io.lsq.s2_load_data_forwarded 641 load_s2.io.fastpath <> io.fastpathOut 642 load_s2.io.dataInvalidSqIdx := io.lsq.forward.dataInvalidSqIdx // provide dataInvalidSqIdx to make wakeup faster 643 load_s2.io.loadViolationQueryResp <> io.lsq.loadViolationQuery.resp 644 load_s2.io.csrCtrl <> io.csrCtrl 645 load_s2.io.sentFastUop := io.fastUop.valid 646 647 // feedback bank conflict / ld-vio check struct hazard to rs 648 io.feedbackFast.bits := RegNext(load_s1.io.rsFeedback.bits) 649 io.feedbackFast.valid := RegNext(load_s1.io.rsFeedback.valid && !load_s1.io.out.bits.uop.robIdx.needFlush(io.redirect)) 650 651 // pre-calcuate sqIdx mask in s0, then send it to lsq in s1 for forwarding 652 val sqIdxMaskReg = RegNext(UIntToMask(load_s0.io.in.bits.uop.sqIdx.value, StoreQueueSize)) 653 // to enable load-load, sqIdxMask must be calculated based on ldin.uop 654 // If the timing here is not OK, load-load forwarding has to be disabled. 655 // Or we calculate sqIdxMask at RS?? 656 io.lsq.forward.sqIdxMask := sqIdxMaskReg 657 if (EnableLoadToLoadForward) { 658 when (s1_tryPointerChasing) { 659 io.lsq.forward.sqIdxMask := UIntToMask(io.ldin.bits.uop.sqIdx.value, StoreQueueSize) 660 } 661 } 662 663 // // use s2_hit_way to select data received in s1 664 // load_s2.io.dcacheResp.bits.data := Mux1H(RegNext(io.dcache.s1_hit_way), RegNext(io.dcache.s1_data)) 665 // assert(load_s2.io.dcacheResp.bits.data === io.dcache.resp.bits.data) 666 667 // now io.fastUop.valid is sent to RS in load_s2 668 val s2_dcache_hit = io.dcache.s2_hit // dcache hit dup in lsu side 669 670 io.fastUop.valid := RegNext( 671 !io.dcache.s1_disable_fast_wakeup && // load fast wakeup should be disabled when dcache data read is not ready 672 load_s1.io.in.valid && // valid load request 673 !load_s1.io.s1_kill && // killed by load-load forwarding 674 !load_s1.io.dtlbResp.bits.fast_miss && // not mmio or tlb miss, pf / af not included here 675 !io.lsq.forward.dataInvalidFast // forward failed 676 ) && 677 !RegNext(load_s1.io.needLdVioCheckRedo) && // load-load violation check: load paddr cam struct hazard 678 !RegNext(load_s1.io.out.bits.uop.robIdx.needFlush(io.redirect)) && 679 s2_dcache_hit // dcache hit in lsu side 680 681 io.fastUop.bits := RegNext(load_s1.io.out.bits.uop) 682 683 XSDebug(load_s0.io.out.valid, 684 p"S0: pc ${Hexadecimal(load_s0.io.out.bits.uop.cf.pc)}, lId ${Hexadecimal(load_s0.io.out.bits.uop.lqIdx.asUInt)}, " + 685 p"vaddr ${Hexadecimal(load_s0.io.out.bits.vaddr)}, mask ${Hexadecimal(load_s0.io.out.bits.mask)}\n") 686 XSDebug(load_s1.io.out.valid, 687 p"S1: pc ${Hexadecimal(load_s1.io.out.bits.uop.cf.pc)}, lId ${Hexadecimal(load_s1.io.out.bits.uop.lqIdx.asUInt)}, tlb_miss ${io.tlb.resp.bits.miss}, " + 688 p"paddr ${Hexadecimal(load_s1.io.out.bits.paddr)}, mmio ${load_s1.io.out.bits.mmio}\n") 689 690 // writeback to LSQ 691 // Current dcache use MSHR 692 // Load queue will be updated at s2 for both hit/miss int/fp load 693 io.lsq.loadIn.valid := load_s2.io.out.valid 694 // generate LqWriteBundle from LsPipelineBundle 695 io.lsq.loadIn.bits.fromLsPipelineBundle(load_s2.io.out.bits) 696 // generate duplicated load queue data wen 697 val load_s2_valid_vec = RegInit(0.U(6.W)) 698 val load_s2_leftFire = load_s1.io.out.valid && load_s2.io.in.ready 699 load_s2_valid_vec := 0x0.U(6.W) 700 when (load_s2_leftFire) { load_s2_valid_vec := 0x3f.U(6.W)} 701 when (load_s1.io.out.bits.uop.robIdx.needFlush(io.redirect)) { load_s2_valid_vec := 0x0.U(6.W) } 702 assert(RegNext(load_s2.io.in.valid === load_s2_valid_vec(0))) 703 io.lsq.loadIn.bits.lq_data_wen_dup := load_s2_valid_vec.asBools() 704 705 // s2_dcache_require_replay signal will be RegNexted, then used in s3 706 io.lsq.s2_dcache_require_replay := load_s2.io.s2_dcache_require_replay 707 708 // write to rob and writeback bus 709 val s2_wb_valid = load_s2.io.out.valid && !load_s2.io.out.bits.miss && !load_s2.io.out.bits.mmio 710 711 // Int load, if hit, will be writebacked at s2 712 val hitLoadOut = Wire(Valid(new ExuOutput)) 713 hitLoadOut.valid := s2_wb_valid 714 hitLoadOut.bits.uop := load_s2.io.out.bits.uop 715 hitLoadOut.bits.data := load_s2.io.out.bits.data 716 hitLoadOut.bits.redirectValid := false.B 717 hitLoadOut.bits.redirect := DontCare 718 hitLoadOut.bits.debug.isMMIO := load_s2.io.out.bits.mmio 719 hitLoadOut.bits.debug.isPerfCnt := false.B 720 hitLoadOut.bits.debug.paddr := load_s2.io.out.bits.paddr 721 hitLoadOut.bits.debug.vaddr := load_s2.io.out.bits.vaddr 722 hitLoadOut.bits.fflags := DontCare 723 724 load_s2.io.out.ready := true.B 725 726 // load s3 727 val s3_load_wb_meta_reg = RegNext(Mux(hitLoadOut.valid, hitLoadOut.bits, io.lsq.ldout.bits)) 728 729 // data from load queue refill 730 val s3_loadDataFromLQ = RegEnable(io.lsq.ldRawData, io.lsq.ldout.valid) 731 val s3_rdataLQ = s3_loadDataFromLQ.mergedData() 732 val s3_rdataSelLQ = LookupTree(s3_loadDataFromLQ.addrOffset, List( 733 "b000".U -> s3_rdataLQ(63, 0), 734 "b001".U -> s3_rdataLQ(63, 8), 735 "b010".U -> s3_rdataLQ(63, 16), 736 "b011".U -> s3_rdataLQ(63, 24), 737 "b100".U -> s3_rdataLQ(63, 32), 738 "b101".U -> s3_rdataLQ(63, 40), 739 "b110".U -> s3_rdataLQ(63, 48), 740 "b111".U -> s3_rdataLQ(63, 56) 741 )) 742 val s3_rdataPartialLoadLQ = rdataHelper(s3_loadDataFromLQ.uop, s3_rdataSelLQ) 743 744 // data from dcache hit 745 val s3_loadDataFromDcache = RegEnable(load_s2.io.loadDataFromDcache, load_s2.io.in.valid) 746 val s3_rdataDcache = s3_loadDataFromDcache.mergedData() 747 val s3_rdataSelDcache = LookupTree(s3_loadDataFromDcache.addrOffset, List( 748 "b000".U -> s3_rdataDcache(63, 0), 749 "b001".U -> s3_rdataDcache(63, 8), 750 "b010".U -> s3_rdataDcache(63, 16), 751 "b011".U -> s3_rdataDcache(63, 24), 752 "b100".U -> s3_rdataDcache(63, 32), 753 "b101".U -> s3_rdataDcache(63, 40), 754 "b110".U -> s3_rdataDcache(63, 48), 755 "b111".U -> s3_rdataDcache(63, 56) 756 )) 757 val s3_rdataPartialLoadDcache = rdataHelper(s3_loadDataFromDcache.uop, s3_rdataSelDcache) 758 759 io.ldout.bits := s3_load_wb_meta_reg 760 io.ldout.bits.data := Mux(RegNext(hitLoadOut.valid), s3_rdataPartialLoadDcache, s3_rdataPartialLoadLQ) 761 io.ldout.valid := RegNext(hitLoadOut.valid) && !RegNext(load_s2.io.out.bits.uop.robIdx.needFlush(io.redirect)) || 762 RegNext(io.lsq.ldout.valid) && !RegNext(io.lsq.ldout.bits.uop.robIdx.needFlush(io.redirect)) && !RegNext(hitLoadOut.valid) 763 764 io.ldout.bits.uop.cf.exceptionVec(loadAccessFault) := s3_load_wb_meta_reg.uop.cf.exceptionVec(loadAccessFault) || 765 RegNext(hitLoadOut.valid) && load_s2.io.s3_delayed_load_error 766 767 // feedback tlb miss / dcache miss queue full 768 io.feedbackSlow.bits := RegNext(load_s2.io.rsFeedback.bits) 769 io.feedbackSlow.valid := RegNext(load_s2.io.rsFeedback.valid && !load_s2.io.out.bits.uop.robIdx.needFlush(io.redirect)) 770 // If replay is reported at load_s1, inst will be canceled (will not enter load_s2), 771 // in that case: 772 // * replay should not be reported twice 773 assert(!(RegNext(io.feedbackFast.valid) && io.feedbackSlow.valid)) 774 // * io.fastUop.valid should not be reported 775 assert(!RegNext(io.feedbackFast.valid && io.fastUop.valid)) 776 777 val s3_forward_fail = RegNext(io.lsq.forward.matchInvalid || io.sbuffer.matchInvalid) 778 val s3_ldld_violation = RegNext( 779 io.lsq.loadViolationQuery.resp.valid && 780 io.lsq.loadViolationQuery.resp.bits.have_violation && 781 RegNext(io.csrCtrl.ldld_vio_check_enable) 782 ) 783 val s3_need_replay_from_fetch = s3_forward_fail || s3_ldld_violation 784 val s3_can_replay_from_fetch = RegEnable(load_s2.io.s2_can_replay_from_fetch, load_s2.io.out.valid) 785 when (RegNext(load_s2.io.out.valid)) { 786 io.ldout.bits.uop.ctrl.replayInst := s3_need_replay_from_fetch 787 } 788 789 io.lsq.s3_delayed_load_error := load_s2.io.s3_delayed_load_error 790 io.lsq.s3_replay_from_fetch := s3_need_replay_from_fetch && s3_can_replay_from_fetch 791 792 // s3_delayed_load_error path is not used for now, as we writeback load result in load_s3 793 // but we keep this path for future use 794 io.s3_delayed_load_error := false.B 795 796 io.lsq.ldout.ready := !hitLoadOut.valid 797 798 when(io.feedbackSlow.valid && !io.feedbackSlow.bits.hit){ 799 // when need replay from rs, inst should not be writebacked to rob 800 assert(RegNext(!hitLoadOut.valid)) 801 assert(RegNext(!io.lsq.loadIn.valid) || RegNext(load_s2.io.s2_dcache_require_replay)) 802 } 803 804 val lastValidData = RegEnable(io.ldout.bits.data, io.ldout.fire) 805 val hitLoadAddrTriggerHitVec = Wire(Vec(3, Bool())) 806 val lqLoadAddrTriggerHitVec = io.lsq.trigger.lqLoadAddrTriggerHitVec 807 (0 until 3).map{i => { 808 val tdata2 = io.trigger(i).tdata2 809 val matchType = io.trigger(i).matchType 810 val tEnable = io.trigger(i).tEnable 811 812 hitLoadAddrTriggerHitVec(i) := TriggerCmp(load_s2.io.out.bits.vaddr, tdata2, matchType, tEnable) 813 io.trigger(i).addrHit := Mux(hitLoadOut.valid, hitLoadAddrTriggerHitVec(i), lqLoadAddrTriggerHitVec(i)) 814 io.trigger(i).lastDataHit := TriggerCmp(lastValidData, tdata2, matchType, tEnable) 815 }} 816 io.lsq.trigger.hitLoadAddrTriggerHitVec := hitLoadAddrTriggerHitVec 817 818 val perfEvents = Seq( 819 ("load_s0_in_fire ", load_s0.io.in.fire ), 820 ("load_to_load_forward ", load_s1.io.out.valid && s1_tryPointerChasing && !cancelPointerChasing ), 821 ("stall_dcache ", load_s0.io.out.valid && load_s0.io.out.ready && !load_s0.io.dcacheReq.ready ), 822 ("load_s1_in_fire ", load_s1.io.in.fire ), 823 ("load_s1_tlb_miss ", load_s1.io.in.fire && load_s1.io.dtlbResp.bits.miss ), 824 ("load_s2_in_fire ", load_s2.io.in.fire ), 825 ("load_s2_dcache_miss ", load_s2.io.in.fire && load_s2.io.dcacheResp.bits.miss ), 826 ("load_s2_replay ", load_s2.io.rsFeedback.valid && !load_s2.io.rsFeedback.bits.hit ), 827 ("load_s2_replay_tlb_miss ", load_s2.io.rsFeedback.valid && !load_s2.io.rsFeedback.bits.hit && load_s2.io.in.bits.tlbMiss ), 828 ("load_s2_replay_cache ", load_s2.io.rsFeedback.valid && !load_s2.io.rsFeedback.bits.hit && !load_s2.io.in.bits.tlbMiss && load_s2.io.dcacheResp.bits.miss), 829 ) 830 generatePerfEvent() 831 832 when(io.ldout.fire){ 833 XSDebug("ldout %x\n", io.ldout.bits.uop.cf.pc) 834 } 835} 836