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._ 24import xiangshan.backend.decode.ImmUnion 25import xiangshan.cache._ 26import xiangshan.cache.mmu.{TlbPtwIO, TlbReq, TlbResp, TlbCmd, TlbRequestIO, TLB} 27 28class LoadToLsqIO(implicit p: Parameters) extends XSBundle { 29 val loadIn = ValidIO(new LsPipelineBundle) 30 val ldout = Flipped(DecoupledIO(new ExuOutput)) 31 val loadDataForwarded = Output(Bool()) 32 val needReplayFromRS = Output(Bool()) 33 val forward = new PipeLoadForwardQueryIO 34} 35 36class LoadToLoadIO(implicit p: Parameters) extends XSBundle { 37 // load to load fast path is limited to ld (64 bit) used as vaddr src1 only 38 val data = UInt(XLEN.W) 39 val valid = Bool() 40} 41 42// Load Pipeline Stage 0 43// Generate addr, use addr to query DCache and DTLB 44class LoadUnit_S0(implicit p: Parameters) extends XSModule with HasDCacheParameters{ 45 val io = IO(new Bundle() { 46 val in = Flipped(Decoupled(new ExuInput)) 47 val out = Decoupled(new LsPipelineBundle) 48 val fastpath = Input(Vec(LoadPipelineWidth, new LoadToLoadIO)) 49 val dtlbReq = DecoupledIO(new TlbReq) 50 val dcacheReq = DecoupledIO(new DCacheWordReq) 51 val rsIdx = Input(UInt(log2Up(IssQueSize).W)) 52 val isFirstIssue = Input(Bool()) 53 val loadFastMatch = Input(UInt(exuParameters.LduCnt.W)) 54 }) 55 require(LoadPipelineWidth == exuParameters.LduCnt) 56 57 val s0_uop = io.in.bits.uop 58 val imm12 = WireInit(s0_uop.ctrl.imm(11,0)) 59 60 // slow vaddr from non-load insts 61 val slowpath_vaddr = io.in.bits.src(0) + SignExt(s0_uop.ctrl.imm(11,0), VAddrBits) 62 val slowpath_mask = genWmask(slowpath_vaddr, s0_uop.ctrl.fuOpType(1,0)) 63 64 // fast vaddr from load insts 65 val fastpath_vaddrs = WireInit(VecInit(List.tabulate(LoadPipelineWidth)(i => { 66 io.fastpath(i).data + SignExt(s0_uop.ctrl.imm(11,0), VAddrBits) 67 }))) 68 val fastpath_masks = WireInit(VecInit(List.tabulate(LoadPipelineWidth)(i => { 69 genWmask(fastpath_vaddrs(i), s0_uop.ctrl.fuOpType(1,0)) 70 }))) 71 val fastpath_vaddr = Mux1H(io.loadFastMatch, fastpath_vaddrs) 72 val fastpath_mask = Mux1H(io.loadFastMatch, fastpath_masks) 73 74 // select vaddr from 2 alus 75 val s0_vaddr = Mux(io.loadFastMatch.orR, fastpath_vaddr, slowpath_vaddr) 76 val s0_mask = Mux(io.loadFastMatch.orR, fastpath_mask, slowpath_mask) 77 XSPerfAccumulate("load_to_load_forward", io.loadFastMatch.orR && io.in.fire()) 78 79 val isSoftPrefetch = Wire(Bool()) 80 isSoftPrefetch := s0_uop.ctrl.isORI //it's a ORI but it exists in ldu, which means it's a softprefecth 81 val isSoftPrefetchRead = Wire(Bool()) 82 val isSoftPrefetchWrite = Wire(Bool()) 83 isSoftPrefetchRead := s0_uop.ctrl.isSoftPrefetchRead 84 isSoftPrefetchWrite := s0_uop.ctrl.isSoftPrefetchWrite 85 86 // query DTLB 87 io.dtlbReq.valid := io.in.valid 88 io.dtlbReq.bits.vaddr := s0_vaddr 89 io.dtlbReq.bits.cmd := TlbCmd.read 90 io.dtlbReq.bits.robIdx := s0_uop.robIdx 91 io.dtlbReq.bits.debug.pc := s0_uop.cf.pc 92 io.dtlbReq.bits.debug.isFirstIssue := io.isFirstIssue 93 94 // query DCache 95 io.dcacheReq.valid := io.in.valid 96 when (isSoftPrefetchRead) { 97 io.dcacheReq.bits.cmd := MemoryOpConstants.M_PFR 98 }.elsewhen (isSoftPrefetchWrite) { 99 io.dcacheReq.bits.cmd := MemoryOpConstants.M_PFW 100 }.otherwise { 101 io.dcacheReq.bits.cmd := MemoryOpConstants.M_XRD 102 } 103 io.dcacheReq.bits.addr := s0_vaddr 104 io.dcacheReq.bits.mask := s0_mask 105 io.dcacheReq.bits.data := DontCare 106 when(isSoftPrefetch) { 107 io.dcacheReq.bits.instrtype := SOFT_PREFETCH.U 108 }.otherwise { 109 io.dcacheReq.bits.instrtype := LOAD_SOURCE.U 110 } 111 112 // TODO: update cache meta 113 io.dcacheReq.bits.id := DontCare 114 115 val addrAligned = LookupTree(s0_uop.ctrl.fuOpType(1, 0), List( 116 "b00".U -> true.B, //b 117 "b01".U -> (s0_vaddr(0) === 0.U), //h 118 "b10".U -> (s0_vaddr(1, 0) === 0.U), //w 119 "b11".U -> (s0_vaddr(2, 0) === 0.U) //d 120 )) 121 122 io.out.valid := io.in.valid && io.dcacheReq.ready 123 124 io.out.bits := DontCare 125 io.out.bits.vaddr := s0_vaddr 126 io.out.bits.mask := s0_mask 127 io.out.bits.uop := s0_uop 128 io.out.bits.uop.cf.exceptionVec(loadAddrMisaligned) := !addrAligned 129 io.out.bits.rsIdx := io.rsIdx 130 io.out.bits.isFirstIssue := io.isFirstIssue 131 io.out.bits.isSoftPrefetch := isSoftPrefetch 132 133 io.in.ready := !io.in.valid || (io.out.ready && io.dcacheReq.ready) 134 135 XSDebug(io.dcacheReq.fire(), 136 p"[DCACHE LOAD REQ] pc ${Hexadecimal(s0_uop.cf.pc)}, vaddr ${Hexadecimal(s0_vaddr)}\n" 137 ) 138 XSPerfAccumulate("in_valid", io.in.valid) 139 XSPerfAccumulate("in_fire", io.in.fire) 140 XSPerfAccumulate("in_fire_first_issue", io.in.valid && io.isFirstIssue) 141 XSPerfAccumulate("stall_out", io.out.valid && !io.out.ready && io.dcacheReq.ready) 142 XSPerfAccumulate("stall_dcache", io.out.valid && io.out.ready && !io.dcacheReq.ready) 143 XSPerfAccumulate("addr_spec_success", io.out.fire() && s0_vaddr(VAddrBits-1, 12) === io.in.bits.src(0)(VAddrBits-1, 12)) 144 XSPerfAccumulate("addr_spec_failed", io.out.fire() && s0_vaddr(VAddrBits-1, 12) =/= io.in.bits.src(0)(VAddrBits-1, 12)) 145 XSPerfAccumulate("addr_spec_success_once", io.out.fire() && s0_vaddr(VAddrBits-1, 12) === io.in.bits.src(0)(VAddrBits-1, 12) && io.isFirstIssue) 146 XSPerfAccumulate("addr_spec_failed_once", io.out.fire() && s0_vaddr(VAddrBits-1, 12) =/= io.in.bits.src(0)(VAddrBits-1, 12) && io.isFirstIssue) 147} 148 149 150// Load Pipeline Stage 1 151// TLB resp (send paddr to dcache) 152class LoadUnit_S1(implicit p: Parameters) extends XSModule { 153 val io = IO(new Bundle() { 154 val in = Flipped(Decoupled(new LsPipelineBundle)) 155 val out = Decoupled(new LsPipelineBundle) 156 val dtlbResp = Flipped(DecoupledIO(new TlbResp)) 157 val dcachePAddr = Output(UInt(PAddrBits.W)) 158 val dcacheKill = Output(Bool()) 159 val fullForwardFast = Output(Bool()) 160 val sbuffer = new LoadForwardQueryIO 161 val lsq = new PipeLoadForwardQueryIO 162 }) 163 164 val isSoftPrefetch = io.in.bits.isSoftPrefetch 165 val actually_execpt = io.dtlbResp.bits.excp.pf.ld || io.dtlbResp.bits.excp.af.ld || io.out.bits.uop.cf.exceptionVec(loadAddrMisaligned) 166 val actually_mmio = !io.dtlbResp.bits.miss && io.dtlbResp.bits.mmio 167 168 val softprefecth_mmio = isSoftPrefetch && actually_mmio //TODO, fix it 169 val softprefecth_excep = isSoftPrefetch && actually_execpt //TODO, fix it 170 171 val s1_uop = io.in.bits.uop 172 val s1_paddr = io.dtlbResp.bits.paddr 173 val s1_exception = selectLoad(io.out.bits.uop.cf.exceptionVec, false).asUInt.orR // af & pf exception were modified below. 174 val s1_tlb_miss = io.dtlbResp.bits.miss 175 //val s1_mmio = !s1_tlb_miss && io.dtlbResp.bits.mmio 176 val s1_mmio = !isSoftPrefetch && actually_mmio 177 val s1_mask = io.in.bits.mask 178 179 io.out.bits := io.in.bits // forwardXX field will be updated in s1 180 181 io.dtlbResp.ready := true.B 182 183 // TOOD: PMA check 184 io.dcachePAddr := s1_paddr 185 //io.dcacheKill := s1_tlb_miss || s1_exception || s1_mmio 186 io.dcacheKill := s1_tlb_miss || actually_mmio || actually_execpt 187 188 // load forward query datapath 189 io.sbuffer.valid := io.in.valid && !(s1_exception || s1_tlb_miss) 190 io.sbuffer.vaddr := io.in.bits.vaddr 191 io.sbuffer.paddr := s1_paddr 192 io.sbuffer.uop := s1_uop 193 io.sbuffer.sqIdx := s1_uop.sqIdx 194 io.sbuffer.mask := s1_mask 195 io.sbuffer.pc := s1_uop.cf.pc // FIXME: remove it 196 197 io.lsq.valid := io.in.valid && !(s1_exception || s1_tlb_miss) 198 io.lsq.vaddr := io.in.bits.vaddr 199 io.lsq.paddr := s1_paddr 200 io.lsq.uop := s1_uop 201 io.lsq.sqIdx := s1_uop.sqIdx 202 io.lsq.sqIdxMask := DontCare // will be overwritten by sqIdxMask pre-generated in s0 203 io.lsq.mask := s1_mask 204 io.lsq.pc := s1_uop.cf.pc // FIXME: remove it 205 206 // Generate forwardMaskFast to wake up insts earlier 207 val forwardMaskFast = io.lsq.forwardMaskFast.asUInt | io.sbuffer.forwardMaskFast.asUInt 208 io.fullForwardFast := (~forwardMaskFast & s1_mask) === 0.U 209 210 io.out.valid := io.in.valid// && !s1_tlb_miss 211 io.out.bits.paddr := s1_paddr 212 io.out.bits.mmio := s1_mmio && !s1_exception 213 io.out.bits.tlbMiss := s1_tlb_miss 214 215 // current ori test will cause the case of ldest == 0, below will be modifeid in the future. 216 // af & pf exception were modified 217 io.out.bits.uop.cf.exceptionVec(loadPageFault) := !isSoftPrefetch && io.dtlbResp.bits.excp.pf.ld 218 io.out.bits.uop.cf.exceptionVec(loadAccessFault) := !isSoftPrefetch && io.dtlbResp.bits.excp.af.ld 219 220 io.out.bits.ptwBack := io.dtlbResp.bits.ptwBack 221 io.out.bits.rsIdx := io.in.bits.rsIdx 222 223 // soft prefetch stuff 224 io.out.bits.isSoftPrefetch := io.in.bits.isSoftPrefetch 225 io.out.bits.isSoftPreExcept := softprefecth_excep 226 io.out.bits.isSoftPremmio := softprefecth_mmio 227 228 io.in.ready := !io.in.valid || io.out.ready 229 230 XSPerfAccumulate("in_valid", io.in.valid) 231 XSPerfAccumulate("in_fire", io.in.fire) 232 XSPerfAccumulate("in_fire_first_issue", io.in.fire && io.in.bits.isFirstIssue) 233 XSPerfAccumulate("tlb_miss", io.in.fire && s1_tlb_miss) 234 XSPerfAccumulate("tlb_miss_first_issue", io.in.fire && s1_tlb_miss && io.in.bits.isFirstIssue) 235 XSPerfAccumulate("stall_out", io.out.valid && !io.out.ready) 236} 237 238// Load Pipeline Stage 2 239// DCache resp 240class LoadUnit_S2(implicit p: Parameters) extends XSModule with HasLoadHelper { 241 val io = IO(new Bundle() { 242 val in = Flipped(Decoupled(new LsPipelineBundle)) 243 val out = Decoupled(new LsPipelineBundle) 244 val rsFeedback = ValidIO(new RSFeedback) 245 val dcacheResp = Flipped(DecoupledIO(new DCacheWordResp)) 246 val lsq = new LoadForwardQueryIO 247 val sbuffer = new LoadForwardQueryIO 248 val dataForwarded = Output(Bool()) 249 val needReplayFromRS = Output(Bool()) 250 val fastpath = Output(new LoadToLoadIO) 251 }) 252 253 val s2_uop = io.in.bits.uop 254 val s2_mask = io.in.bits.mask 255 val s2_paddr = io.in.bits.paddr 256 val s2_tlb_miss = io.in.bits.tlbMiss 257 val s2_data_invalid = io.lsq.dataInvalid 258 val s2_exception = selectLoad(io.in.bits.uop.cf.exceptionVec, false).asUInt.orR 259 val s2_mmio = io.in.bits.mmio && !s2_exception 260 val s2_cache_miss = io.dcacheResp.bits.miss 261 val s2_cache_replay = io.dcacheResp.bits.replay 262 263 val s2_cache_miss_enter = io.dcacheResp.bits.miss_enter //missReq enter the mshr successfully 264 val isSoftPreExcept = io.in.bits.isSoftPreExcept 265 val isSoftPremmio = io.in.bits.isSoftPremmio 266 // val cnt = RegInit(127.U) 267 // cnt := cnt + io.in.valid.asUInt 268 // val s2_forward_fail = io.lsq.matchInvalid || io.sbuffer.matchInvalid || cnt === 0.U 269 270 val s2_forward_fail = io.lsq.matchInvalid || io.sbuffer.matchInvalid 271 272 // assert(!s2_forward_fail) 273 274 io.dcacheResp.ready := true.B 275 val dcacheShouldResp = !(s2_tlb_miss || s2_exception || s2_mmio) 276 assert(!(io.in.valid && (dcacheShouldResp && !io.dcacheResp.valid) && (!isSoftPreExcept) && (!isSoftPremmio)), "DCache response got lost") 277 278 // merge forward result 279 // lsq has higher priority than sbuffer 280 val forwardMask = Wire(Vec(8, Bool())) 281 val forwardData = Wire(Vec(8, UInt(8.W))) 282 283 val fullForward = (~forwardMask.asUInt & s2_mask) === 0.U && !io.lsq.dataInvalid 284 io.lsq := DontCare 285 io.sbuffer := DontCare 286 287 // generate XLEN/8 Muxs 288 for (i <- 0 until XLEN / 8) { 289 forwardMask(i) := io.lsq.forwardMask(i) || io.sbuffer.forwardMask(i) 290 forwardData(i) := Mux(io.lsq.forwardMask(i), io.lsq.forwardData(i), io.sbuffer.forwardData(i)) 291 } 292 293 XSDebug(io.out.fire(), "[FWD LOAD RESP] pc %x fwd %x(%b) + %x(%b)\n", 294 s2_uop.cf.pc, 295 io.lsq.forwardData.asUInt, io.lsq.forwardMask.asUInt, 296 io.in.bits.forwardData.asUInt, io.in.bits.forwardMask.asUInt 297 ) 298 299 // data merge 300 val rdataVec = VecInit((0 until XLEN / 8).map(j => 301 Mux(forwardMask(j), forwardData(j), io.dcacheResp.bits.data(8*(j+1)-1, 8*j)))) 302 val rdata = rdataVec.asUInt 303 val rdataSel = LookupTree(s2_paddr(2, 0), List( 304 "b000".U -> rdata(63, 0), 305 "b001".U -> rdata(63, 8), 306 "b010".U -> rdata(63, 16), 307 "b011".U -> rdata(63, 24), 308 "b100".U -> rdata(63, 32), 309 "b101".U -> rdata(63, 40), 310 "b110".U -> rdata(63, 48), 311 "b111".U -> rdata(63, 56) 312 )) 313 val rdataPartialLoad = rdataHelper(s2_uop, rdataSel) 314 315 io.out.valid := io.in.valid && !s2_tlb_miss && !s2_data_invalid 316 // Inst will be canceled in store queue / lsq, 317 // so we do not need to care about flush in load / store unit's out.valid 318 io.out.bits := io.in.bits 319 io.out.bits.data := rdataPartialLoad 320 // when exception occurs, set it to not miss and let it write back to rob (via int port) 321 if (EnableFastForward) { 322 when(io.in.bits.isSoftPrefetch) { 323 io.out.bits.miss := s2_cache_miss && !s2_exception && !s2_forward_fail && !fullForward && !s2_cache_miss_enter && !isSoftPreExcept && !isSoftPremmio 324 }.otherwise { 325 io.out.bits.miss := s2_cache_miss && !s2_exception && !s2_forward_fail && !fullForward 326 } 327 } else { 328 when(io.in.bits.isSoftPrefetch) { 329 io.out.bits.miss := s2_cache_miss && !s2_exception && !s2_forward_fail && !s2_cache_miss_enter && !isSoftPreExcept && !isSoftPremmio 330 }.otherwise { 331 io.out.bits.miss := s2_cache_miss && !s2_exception && !s2_forward_fail 332 } 333 } 334 io.out.bits.uop.ctrl.fpWen := io.in.bits.uop.ctrl.fpWen && !s2_exception 335 // if forward fail, replay this inst 336 io.out.bits.uop.ctrl.replayInst := s2_forward_fail && !s2_mmio 337 io.out.bits.mmio := s2_mmio 338 339 // For timing reasons, sometimes we can not let 340 // io.out.bits.miss := s2_cache_miss && !s2_exception && !fullForward 341 // We use io.dataForwarded instead. It means forward logic have prepared all data needed, 342 // and dcache query is no longer needed. 343 // Such inst will be writebacked from load queue. 344 io.dataForwarded := s2_cache_miss && fullForward && !s2_exception && !s2_forward_fail 345 // io.out.bits.forwardX will be send to lq 346 io.out.bits.forwardMask := forwardMask 347 // data retbrived from dcache is also included in io.out.bits.forwardData 348 io.out.bits.forwardData := rdataVec 349 350 io.in.ready := io.out.ready || !io.in.valid 351 352 353 // feedback tlb result to RS 354 io.rsFeedback.valid := io.in.valid 355 when (io.in.bits.isSoftPrefetch) { 356 io.rsFeedback.bits.hit := (!s2_tlb_miss && (!s2_cache_replay || s2_mmio || s2_exception || fullForward) && !s2_data_invalid) || s2_cache_miss_enter || isSoftPreExcept || isSoftPremmio 357 }.otherwise { 358 io.rsFeedback.bits.hit := !s2_tlb_miss && (!s2_cache_replay || s2_mmio || s2_exception || fullForward) && !s2_data_invalid 359 } 360 io.rsFeedback.bits.rsIdx := io.in.bits.rsIdx 361 io.rsFeedback.bits.flushState := io.in.bits.ptwBack 362 io.rsFeedback.bits.sourceType := Mux(s2_tlb_miss, RSFeedbackType.tlbMiss, 363 Mux(io.lsq.dataInvalid, 364 RSFeedbackType.dataInvalid, 365 RSFeedbackType.mshrFull 366 ) 367 ) 368 369 // s2_cache_replay is quite slow to generate, send it separately to LQ 370 io.needReplayFromRS := s2_cache_replay && !fullForward 371 372 // fast load to load forward 373 io.fastpath.valid := io.in.valid // for debug only 374 io.fastpath.data := rdata // raw data 375 376 377 XSDebug(io.out.fire(), "[DCACHE LOAD RESP] pc %x rdata %x <- D$ %x + fwd %x(%b)\n", 378 s2_uop.cf.pc, rdataPartialLoad, io.dcacheResp.bits.data, 379 forwardData.asUInt, forwardMask.asUInt 380 ) 381 382 XSPerfAccumulate("in_valid", io.in.valid) 383 XSPerfAccumulate("in_fire", io.in.fire) 384 XSPerfAccumulate("in_fire_first_issue", io.in.fire && io.in.bits.isFirstIssue) 385 XSPerfAccumulate("dcache_miss", io.in.fire && s2_cache_miss) 386 XSPerfAccumulate("dcache_miss_first_issue", io.in.fire && s2_cache_miss && io.in.bits.isFirstIssue) 387 XSPerfAccumulate("full_forward", io.in.valid && fullForward) 388 XSPerfAccumulate("dcache_miss_full_forward", io.in.valid && s2_cache_miss && fullForward) 389 XSPerfAccumulate("replay", io.rsFeedback.valid && !io.rsFeedback.bits.hit) 390 XSPerfAccumulate("replay_tlb_miss", io.rsFeedback.valid && !io.rsFeedback.bits.hit && s2_tlb_miss) 391 XSPerfAccumulate("replay_cache", io.rsFeedback.valid && !io.rsFeedback.bits.hit && !s2_tlb_miss && s2_cache_replay) 392 XSPerfAccumulate("stall_out", io.out.valid && !io.out.ready) 393} 394 395class LoadUnit(implicit p: Parameters) extends XSModule with HasLoadHelper { 396 val io = IO(new Bundle() { 397 val ldin = Flipped(Decoupled(new ExuInput)) 398 val ldout = Decoupled(new ExuOutput) 399 val redirect = Flipped(ValidIO(new Redirect)) 400 val flush = Input(Bool()) 401 val rsFeedback = ValidIO(new RSFeedback) 402 val rsIdx = Input(UInt(log2Up(IssQueSize).W)) 403 val isFirstIssue = Input(Bool()) 404 val dcache = new DCacheLoadIO 405 val sbuffer = new LoadForwardQueryIO 406 val lsq = new LoadToLsqIO 407 val fastUop = ValidIO(new MicroOp) // early wakeup signal generated in load_s1 408 409 val tlb = new TlbRequestIO 410 val fastpathOut = Output(new LoadToLoadIO) 411 val fastpathIn = Input(Vec(LoadPipelineWidth, new LoadToLoadIO)) 412 val loadFastMatch = Input(UInt(exuParameters.LduCnt.W)) 413 }) 414 415 val load_s0 = Module(new LoadUnit_S0) 416 val load_s1 = Module(new LoadUnit_S1) 417 val load_s2 = Module(new LoadUnit_S2) 418 419 load_s0.io.in <> io.ldin 420 load_s0.io.dtlbReq <> io.tlb.req 421 load_s0.io.dcacheReq <> io.dcache.req 422 load_s0.io.rsIdx := io.rsIdx 423 load_s0.io.isFirstIssue := io.isFirstIssue 424 load_s0.io.fastpath := io.fastpathIn 425 load_s0.io.loadFastMatch := io.loadFastMatch 426 427 PipelineConnect(load_s0.io.out, load_s1.io.in, true.B, load_s0.io.out.bits.uop.robIdx.needFlush(io.redirect, io.flush)) 428 429 load_s1.io.dtlbResp <> io.tlb.resp 430 io.dcache.s1_paddr <> load_s1.io.dcachePAddr 431 io.dcache.s1_kill <> load_s1.io.dcacheKill 432 load_s1.io.sbuffer <> io.sbuffer 433 load_s1.io.lsq <> io.lsq.forward 434 435 PipelineConnect(load_s1.io.out, load_s2.io.in, true.B, load_s1.io.out.bits.uop.robIdx.needFlush(io.redirect, io.flush)) 436 437 load_s2.io.dcacheResp <> io.dcache.resp 438 load_s2.io.lsq.forwardData <> io.lsq.forward.forwardData 439 load_s2.io.lsq.forwardMask <> io.lsq.forward.forwardMask 440 load_s2.io.lsq.forwardMaskFast <> io.lsq.forward.forwardMaskFast // should not be used in load_s2 441 load_s2.io.lsq.dataInvalid <> io.lsq.forward.dataInvalid 442 load_s2.io.lsq.matchInvalid <> io.lsq.forward.matchInvalid 443 load_s2.io.sbuffer.forwardData <> io.sbuffer.forwardData 444 load_s2.io.sbuffer.forwardMask <> io.sbuffer.forwardMask 445 load_s2.io.sbuffer.forwardMaskFast <> io.sbuffer.forwardMaskFast // should not be used in load_s2 446 load_s2.io.sbuffer.dataInvalid <> io.sbuffer.dataInvalid // always false 447 load_s2.io.sbuffer.matchInvalid <> io.sbuffer.matchInvalid 448 load_s2.io.dataForwarded <> io.lsq.loadDataForwarded 449 load_s2.io.fastpath <> io.fastpathOut 450 io.rsFeedback.bits := RegNext(load_s2.io.rsFeedback.bits) 451 io.rsFeedback.valid := RegNext(load_s2.io.rsFeedback.valid && !load_s2.io.out.bits.uop.robIdx.needFlush(io.redirect, io.flush)) 452 io.lsq.needReplayFromRS := load_s2.io.needReplayFromRS 453 454 // pre-calcuate sqIdx mask in s0, then send it to lsq in s1 for forwarding 455 val sqIdxMaskReg = RegNext(UIntToMask(load_s0.io.in.bits.uop.sqIdx.value, StoreQueueSize)) 456 io.lsq.forward.sqIdxMask := sqIdxMaskReg 457 458 // // use s2_hit_way to select data received in s1 459 // load_s2.io.dcacheResp.bits.data := Mux1H(RegNext(io.dcache.s1_hit_way), RegNext(io.dcache.s1_data)) 460 // assert(load_s2.io.dcacheResp.bits.data === io.dcache.resp.bits.data) 461 462 io.fastUop.valid := io.dcache.s1_hit_way.orR && // dcache hit 463 !io.dcache.s1_disable_fast_wakeup && // load fast wakeup should be disabled when dcache data read is not ready 464 load_s1.io.in.valid && // valid laod request 465 !load_s1.io.dcacheKill && // not mmio or tlb miss 466 !io.lsq.forward.dataInvalidFast // forward failed 467 io.fastUop.bits := load_s1.io.out.bits.uop 468 469 XSDebug(load_s0.io.out.valid, 470 p"S0: pc ${Hexadecimal(load_s0.io.out.bits.uop.cf.pc)}, lId ${Hexadecimal(load_s0.io.out.bits.uop.lqIdx.asUInt)}, " + 471 p"vaddr ${Hexadecimal(load_s0.io.out.bits.vaddr)}, mask ${Hexadecimal(load_s0.io.out.bits.mask)}\n") 472 XSDebug(load_s1.io.out.valid, 473 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}, " + 474 p"paddr ${Hexadecimal(load_s1.io.out.bits.paddr)}, mmio ${load_s1.io.out.bits.mmio}\n") 475 476 // writeback to LSQ 477 // Current dcache use MSHR 478 // Load queue will be updated at s2 for both hit/miss int/fp load 479 io.lsq.loadIn.valid := load_s2.io.out.valid 480 io.lsq.loadIn.bits := load_s2.io.out.bits 481 482 // write to rob and writeback bus 483 val s2_wb_valid = load_s2.io.out.valid && !load_s2.io.out.bits.miss && !load_s2.io.out.bits.mmio 484 485 // Int load, if hit, will be writebacked at s2 486 val hitLoadOut = Wire(Valid(new ExuOutput)) 487 hitLoadOut.valid := s2_wb_valid 488 hitLoadOut.bits.uop := load_s2.io.out.bits.uop 489 hitLoadOut.bits.data := load_s2.io.out.bits.data 490 hitLoadOut.bits.redirectValid := false.B 491 hitLoadOut.bits.redirect := DontCare 492 hitLoadOut.bits.debug.isMMIO := load_s2.io.out.bits.mmio 493 hitLoadOut.bits.debug.isPerfCnt := false.B 494 hitLoadOut.bits.debug.paddr := load_s2.io.out.bits.paddr 495 hitLoadOut.bits.fflags := DontCare 496 497 load_s2.io.out.ready := true.B 498 499 io.ldout.bits := Mux(hitLoadOut.valid, hitLoadOut.bits, io.lsq.ldout.bits) 500 io.ldout.valid := hitLoadOut.valid || io.lsq.ldout.valid 501 502 io.lsq.ldout.ready := !hitLoadOut.valid 503 504 when(io.ldout.fire()){ 505 XSDebug("ldout %x\n", io.ldout.bits.uop.cf.pc) 506 } 507} 508