xref: /XiangShan/src/main/scala/xiangshan/mem/Bundles.scala (revision c41f725a91c55e75c95c55b4bb0d2649f43e4c83)
1/***************************************************************************************
2* Copyright (c) 2024 Beijing Institute of Open Source Chip (BOSC)
3* Copyright (c) 2020-2024 Institute of Computing Technology, Chinese Academy of Sciences
4* Copyright (c) 2020-2021 Peng Cheng Laboratory
5*
6* XiangShan is licensed under Mulan PSL v2.
7* You can use this software according to the terms and conditions of the Mulan PSL v2.
8* You may obtain a copy of Mulan PSL v2 at:
9*          http://license.coscl.org.cn/MulanPSL2
10*
11* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
12* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
13* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
14*
15* See the Mulan PSL v2 for more details.
16***************************************************************************************/
17
18package xiangshan.mem
19
20
21import org.chipsalliance.cde.config.Parameters
22import chisel3._
23import chisel3.util._
24import utility._
25import utils._
26import xiangshan._
27import xiangshan.backend.Bundles._
28import xiangshan.backend.rob.RobPtr
29import xiangshan.backend.fu.FenceToSbuffer
30import xiangshan.backend.fu.vector.Bundles._
31import xiangshan.backend.Bundles._
32import xiangshan.mem.prefetch.PrefetchReqBundle
33import xiangshan.cache._
34import xiangshan.cache.wpu.ReplayCarry
35import xiangshan.cache.mmu._
36import math._
37
38object Bundles {
39
40  class LsPipelineBundle(implicit p: Parameters) extends XSBundle
41    with HasDCacheParameters
42    with HasVLSUParameters {
43    val uop = new DynInst
44    val vaddr = UInt(VAddrBits.W)
45    // For exception vaddr generate
46    val fullva = UInt(XLEN.W)
47    val vaNeedExt = Bool()
48    val isHyper = Bool()
49    val paddr = UInt(PAddrBits.W)
50    val gpaddr = UInt(XLEN.W)
51    val isForVSnonLeafPTE = Bool()
52    // val func = UInt(6.W)
53    val mask = UInt((VLEN/8).W)
54    val data = UInt((VLEN+1).W)
55    val wlineflag = Bool() // store write the whole cache line
56
57    val miss = Bool()
58    val tlbMiss = Bool()
59    val ptwBack = Bool()
60    val af = Bool()
61    val nc = Bool()
62    val mmio = Bool()
63    val memBackTypeMM = Bool() // 1: main memory, 0: IO
64    val atomic = Bool()
65    val hasException = Bool()
66
67    val forwardMask = Vec(VLEN/8, Bool())
68    val forwardData = Vec(VLEN/8, UInt(8.W))
69
70    // prefetch
71    val isPrefetch = Bool()
72    val isHWPrefetch = Bool()
73    def isSWPrefetch = isPrefetch && !isHWPrefetch
74
75    // misalignBuffer
76    val isFrmMisAlignBuf = Bool()
77
78    // vector
79    val isvec = Bool()
80    val isLastElem = Bool()
81    val is128bit = Bool()
82    val uop_unit_stride_fof = Bool()
83    val usSecondInv = Bool()
84    val elemIdx = UInt(elemIdxBits.W)
85    val alignedType = UInt(alignTypeBits.W)
86    val mbIndex = UInt(max(vlmBindexBits, vsmBindexBits).W)
87    // val rob_idx_valid = Vec(2,Bool())
88    // val inner_idx = Vec(2,UInt(3.W))
89    // val rob_idx = Vec(2,new RobPtr)
90    val reg_offset = UInt(vOffsetBits.W)
91    val elemIdxInsideVd = UInt(elemIdxBits.W)
92    // val offset = Vec(2,UInt(4.W))
93    val vecActive = Bool() // 1: vector active element or scala mem operation, 0: vector not active element
94    val is_first_ele = Bool()
95    val vecBaseVaddr = UInt(VAddrBits.W)
96    val vecVaddrOffset = UInt(VAddrBits.W)
97    val vecTriggerMask = UInt((VLEN/8).W)
98    // val flowPtr = new VlflowPtr() // VLFlowQueue ptr
99    // val sflowPtr = new VsFlowPtr() // VSFlowQueue ptr
100
101    // For debug usage
102    val isFirstIssue = Bool()
103    val hasROBEntry = Bool()
104
105    // For load replay
106    val isLoadReplay = Bool()
107    val isFastPath = Bool()
108    val isFastReplay = Bool()
109    val replayCarry = new ReplayCarry(nWays)
110
111    // For dcache miss load
112    val mshrid = UInt(log2Up(cfg.nMissEntries).W)
113    val handledByMSHR = Bool()
114    val replacementUpdated = Bool()
115    val missDbUpdated = Bool()
116
117    val forward_tlDchannel = Bool()
118    val dcacheRequireReplay = Bool()
119    val delayedLoadError = Bool()
120    val lateKill = Bool()
121    val feedbacked = Bool()
122    val ldCancel = ValidUndirectioned(UInt(log2Ceil(LoadPipelineWidth).W))
123    // loadQueueReplay index.
124    val schedIndex = UInt(log2Up(LoadQueueReplaySize).W)
125    // hardware prefetch and fast replay no need to query tlb
126    val tlbNoQuery = Bool()
127
128    // misalign
129    val isMisalign          = Bool()
130    val isFinalSplit        = Bool()
131    val misalignWith16Byte  = Bool()
132    val misalignNeedWakeUp  = Bool()
133    val updateAddrValid     = Bool()
134  }
135
136  class LdPrefetchTrainBundle(implicit p: Parameters) extends LsPipelineBundle {
137    val meta_prefetch = UInt(L1PfSourceBits.W)
138    val meta_access = Bool()
139
140    def fromLsPipelineBundle(input: LsPipelineBundle, latch: Boolean = false, enable: Bool = true.B) = {
141      if (latch) vaddr := RegEnable(input.vaddr, enable) else vaddr := input.vaddr
142      if (latch) fullva := RegEnable(input.fullva, enable) else fullva := input.fullva
143      if (latch) vaNeedExt := RegEnable(input.vaNeedExt, enable) else vaNeedExt := input.vaNeedExt
144      if (latch) isHyper := RegEnable(input.isHyper, enable) else isHyper := input.isHyper
145      if (latch) paddr := RegEnable(input.paddr, enable) else paddr := input.paddr
146      if (latch) gpaddr := RegEnable(input.gpaddr, enable) else gpaddr := input.gpaddr
147      if (latch) isForVSnonLeafPTE := RegEnable(input.isForVSnonLeafPTE, enable) else isForVSnonLeafPTE := input.isForVSnonLeafPTE
148      if (latch) mask := RegEnable(input.mask, enable) else mask := input.mask
149      if (latch) data := RegEnable(input.data, enable) else data := input.data
150      if (latch) uop := RegEnable(input.uop, enable) else uop := input.uop
151      if (latch) wlineflag := RegEnable(input.wlineflag, enable) else wlineflag := input.wlineflag
152      if (latch) miss := RegEnable(input.miss, enable) else miss := input.miss
153      if (latch) tlbMiss := RegEnable(input.tlbMiss, enable) else tlbMiss := input.tlbMiss
154      if (latch) ptwBack := RegEnable(input.ptwBack, enable) else ptwBack := input.ptwBack
155      if (latch) af := RegEnable(input.af, enable) else af := input.af
156      if (latch) nc := RegEnable(input.nc, enable) else nc := input.nc
157      if (latch) mmio := RegEnable(input.mmio, enable) else mmio := input.mmio
158      if (latch) memBackTypeMM := RegEnable(input.memBackTypeMM, enable) else memBackTypeMM := input.memBackTypeMM
159      if (latch) forwardMask := RegEnable(input.forwardMask, enable) else forwardMask := input.forwardMask
160      if (latch) forwardData := RegEnable(input.forwardData, enable) else forwardData := input.forwardData
161      if (latch) isPrefetch := RegEnable(input.isPrefetch, enable) else isPrefetch := input.isPrefetch
162      if (latch) isHWPrefetch := RegEnable(input.isHWPrefetch, enable) else isHWPrefetch := input.isHWPrefetch
163      if (latch) isFrmMisAlignBuf := RegEnable(input.isFrmMisAlignBuf, enable) else isFrmMisAlignBuf := input.isFrmMisAlignBuf
164      if (latch) isFirstIssue := RegEnable(input.isFirstIssue, enable) else isFirstIssue := input.isFirstIssue
165      if (latch) hasROBEntry := RegEnable(input.hasROBEntry, enable) else hasROBEntry := input.hasROBEntry
166      if (latch) dcacheRequireReplay := RegEnable(input.dcacheRequireReplay, enable) else dcacheRequireReplay := input.dcacheRequireReplay
167      if (latch) schedIndex := RegEnable(input.schedIndex, enable) else schedIndex := input.schedIndex
168      if (latch) tlbNoQuery := RegEnable(input.tlbNoQuery, enable) else tlbNoQuery := input.tlbNoQuery
169      if (latch) isvec               := RegEnable(input.isvec, enable)               else isvec               := input.isvec
170      if (latch) isLastElem          := RegEnable(input.isLastElem, enable)          else isLastElem          := input.isLastElem
171      if (latch) is128bit            := RegEnable(input.is128bit, enable)            else is128bit            := input.is128bit
172      if (latch) vecActive           := RegEnable(input.vecActive, enable)           else vecActive           := input.vecActive
173      if (latch) is_first_ele        := RegEnable(input.is_first_ele, enable)        else is_first_ele        := input.is_first_ele
174      if (latch) uop_unit_stride_fof := RegEnable(input.uop_unit_stride_fof, enable) else uop_unit_stride_fof := input.uop_unit_stride_fof
175      if (latch) usSecondInv         := RegEnable(input.usSecondInv, enable)         else usSecondInv         := input.usSecondInv
176      if (latch) reg_offset          := RegEnable(input.reg_offset, enable)          else reg_offset          := input.reg_offset
177      if (latch) elemIdx             := RegEnable(input.elemIdx, enable)             else elemIdx             := input.elemIdx
178      if (latch) alignedType         := RegEnable(input.alignedType, enable)         else alignedType         := input.alignedType
179      if (latch) mbIndex             := RegEnable(input.mbIndex, enable)             else mbIndex             := input.mbIndex
180      if (latch) elemIdxInsideVd     := RegEnable(input.elemIdxInsideVd, enable)     else elemIdxInsideVd     := input.elemIdxInsideVd
181      if (latch) vecBaseVaddr        := RegEnable(input.vecBaseVaddr, enable)        else vecBaseVaddr        := input.vecBaseVaddr
182      if (latch) vecVaddrOffset      := RegEnable(input.vecVaddrOffset, enable)      else vecVaddrOffset      := input.vecVaddrOffset
183      if (latch) vecTriggerMask      := RegEnable(input.vecTriggerMask, enable)      else vecTriggerMask      := input.vecTriggerMask
184      // if (latch) flowPtr             := RegEnable(input.flowPtr, enable)             else flowPtr             := input.flowPtr
185      // if (latch) sflowPtr            := RegEnable(input.sflowPtr, enable)            else sflowPtr            := input.sflowPtr
186
187      meta_prefetch := DontCare
188      meta_access := DontCare
189      forward_tlDchannel := DontCare
190      mshrid := DontCare
191      replayCarry := DontCare
192      atomic := DontCare
193      isLoadReplay := DontCare
194      isFastPath := DontCare
195      isFastReplay := DontCare
196      handledByMSHR := DontCare
197      replacementUpdated := DontCare
198      missDbUpdated := DontCare
199      delayedLoadError := DontCare
200      lateKill := DontCare
201      feedbacked := DontCare
202      ldCancel := DontCare
203    }
204
205    def asPrefetchReqBundle(): PrefetchReqBundle = {
206      val res = Wire(new PrefetchReqBundle)
207      res.vaddr       := this.vaddr
208      res.paddr       := this.paddr
209      res.pc          := this.uop.pc
210      res.miss        := this.miss
211      res.pfHitStream := isFromStream(this.meta_prefetch)
212
213      res
214    }
215  }
216
217  class StPrefetchTrainBundle(implicit p: Parameters) extends LdPrefetchTrainBundle {}
218
219  class LqWriteBundle(implicit p: Parameters) extends LsPipelineBundle {
220    // load inst replay informations
221    val rep_info = new LoadToLsqReplayIO
222    // queue entry data, except flag bits, will be updated if writeQueue is true,
223    // valid bit in LqWriteBundle will be ignored
224    val data_wen_dup = Vec(6, Bool()) // dirty reg dup
225
226
227    def fromLsPipelineBundle(input: LsPipelineBundle, latch: Boolean = false, enable: Bool = true.B) = {
228      if(latch) vaddr := RegEnable(input.vaddr, enable) else vaddr := input.vaddr
229      if(latch) fullva := RegEnable(input.fullva, enable) else fullva := input.fullva
230      if(latch) vaNeedExt := RegEnable(input.vaNeedExt, enable) else vaNeedExt := input.vaNeedExt
231      if(latch) isHyper := RegEnable(input.isHyper, enable) else isHyper := input.isHyper
232      if(latch) paddr := RegEnable(input.paddr, enable) else paddr := input.paddr
233      if(latch) gpaddr := RegEnable(input.gpaddr, enable) else gpaddr := input.gpaddr
234      if(latch) isForVSnonLeafPTE := RegEnable(input.isForVSnonLeafPTE, enable) else isForVSnonLeafPTE := input.isForVSnonLeafPTE
235      if(latch) mask := RegEnable(input.mask, enable) else mask := input.mask
236      if(latch) data := RegEnable(input.data, enable) else data := input.data
237      if(latch) uop := RegEnable(input.uop, enable) else uop := input.uop
238      if(latch) wlineflag := RegEnable(input.wlineflag, enable) else wlineflag := input.wlineflag
239      if(latch) miss := RegEnable(input.miss, enable) else miss := input.miss
240      if(latch) tlbMiss := RegEnable(input.tlbMiss, enable) else tlbMiss := input.tlbMiss
241      if(latch) ptwBack := RegEnable(input.ptwBack, enable) else ptwBack := input.ptwBack
242      if(latch) mmio := RegEnable(input.mmio, enable) else mmio := input.mmio
243      if(latch) atomic := RegEnable(input.atomic, enable) else atomic := input.atomic
244      if(latch) forwardMask := RegEnable(input.forwardMask, enable) else forwardMask := input.forwardMask
245      if(latch) forwardData := RegEnable(input.forwardData, enable) else forwardData := input.forwardData
246      if(latch) isPrefetch := RegEnable(input.isPrefetch, enable) else isPrefetch := input.isPrefetch
247      if(latch) isHWPrefetch := RegEnable(input.isHWPrefetch, enable) else isHWPrefetch := input.isHWPrefetch
248      if(latch) isFrmMisAlignBuf := RegEnable(input.isFrmMisAlignBuf, enable) else isFrmMisAlignBuf := input.isFrmMisAlignBuf
249      if(latch) isFirstIssue := RegEnable(input.isFirstIssue, enable) else isFirstIssue := input.isFirstIssue
250      if(latch) hasROBEntry := RegEnable(input.hasROBEntry, enable) else hasROBEntry := input.hasROBEntry
251      if(latch) isLoadReplay := RegEnable(input.isLoadReplay, enable) else isLoadReplay := input.isLoadReplay
252      if(latch) isFastPath := RegEnable(input.isFastPath, enable) else isFastPath := input.isFastPath
253      if(latch) isFastReplay := RegEnable(input.isFastReplay, enable) else isFastReplay := input.isFastReplay
254      if(latch) mshrid := RegEnable(input.mshrid, enable) else mshrid := input.mshrid
255      if(latch) forward_tlDchannel := RegEnable(input.forward_tlDchannel, enable) else forward_tlDchannel := input.forward_tlDchannel
256      if(latch) replayCarry := RegEnable(input.replayCarry, enable) else replayCarry := input.replayCarry
257      if(latch) dcacheRequireReplay := RegEnable(input.dcacheRequireReplay, enable) else dcacheRequireReplay := input.dcacheRequireReplay
258      if(latch) schedIndex := RegEnable(input.schedIndex, enable) else schedIndex := input.schedIndex
259      if(latch) handledByMSHR := RegEnable(input.handledByMSHR, enable) else handledByMSHR := input.handledByMSHR
260      if(latch) replacementUpdated := RegEnable(input.replacementUpdated, enable) else replacementUpdated := input.replacementUpdated
261      if(latch) missDbUpdated := RegEnable(input.missDbUpdated, enable) else missDbUpdated := input.missDbUpdated
262      if(latch) delayedLoadError := RegEnable(input.delayedLoadError, enable) else delayedLoadError := input.delayedLoadError
263      if(latch) lateKill := RegEnable(input.lateKill, enable) else lateKill := input.lateKill
264      if(latch) feedbacked := RegEnable(input.feedbacked, enable) else feedbacked := input.feedbacked
265      if(latch) isvec               := RegEnable(input.isvec, enable)               else isvec               := input.isvec
266      if(latch) is128bit            := RegEnable(input.is128bit, enable)            else is128bit            := input.is128bit
267      if(latch) vecActive           := RegEnable(input.vecActive, enable)           else vecActive           := input.vecActive
268      if(latch) uop_unit_stride_fof := RegEnable(input.uop_unit_stride_fof, enable) else uop_unit_stride_fof := input.uop_unit_stride_fof
269      if(latch) reg_offset          := RegEnable(input.reg_offset, enable)          else reg_offset          := input.reg_offset
270      if(latch) mbIndex             := RegEnable(input.mbIndex, enable)             else mbIndex             := input.mbIndex
271      if(latch) elemIdxInsideVd     := RegEnable(input.elemIdxInsideVd, enable)     else elemIdxInsideVd     := input.elemIdxInsideVd
272
273      rep_info := DontCare
274      data_wen_dup := DontCare
275    }
276  }
277
278  class SqWriteBundle(implicit p: Parameters) extends LsPipelineBundle {
279    val need_rep = Bool()
280  }
281
282  class LoadForwardQueryIO(implicit p: Parameters) extends XSBundle {
283    val vaddr = Output(UInt(VAddrBits.W))
284    val paddr = Output(UInt(PAddrBits.W))
285    val mask = Output(UInt((VLEN/8).W))
286    val uop = Output(new DynInst) // for replay
287    val pc = Output(UInt(VAddrBits.W)) //for debug
288    val valid = Output(Bool())
289
290    val forwardMaskFast = Input(Vec((VLEN/8), Bool())) // resp to load_s1
291    val forwardMask = Input(Vec((VLEN/8), Bool())) // resp to load_s2
292    val forwardData = Input(Vec((VLEN/8), UInt(8.W))) // resp to load_s2
293
294    // val lqIdx = Output(UInt(LoadQueueIdxWidth.W))
295    val sqIdx = Output(new SqPtr)
296
297    // dataInvalid suggests store to load forward found forward should happen,
298    // but data is not available for now. If dataInvalid, load inst should
299    // be replayed from RS. Feedback type should be RSFeedbackType.dataInvalid
300    val dataInvalid = Input(Bool()) // Addr match, but data is not valid for now
301
302    // matchInvalid suggests in store to load forward logic, paddr cam result does
303    // to equal to vaddr cam result. If matchInvalid, a microarchitectural exception
304    // should be raised to flush SQ and committed sbuffer.
305    val matchInvalid = Input(Bool()) // resp to load_s2
306
307    // addrInvalid suggests store to load forward found forward should happen,
308    // but address (SSID) is not available for now. If addrInvalid, load inst should
309    // be replayed from RS. Feedback type should be RSFeedbackType.addrInvalid
310    val addrInvalid = Input(Bool())
311  }
312
313  // LoadForwardQueryIO used in load pipeline
314  //
315  // Difference between PipeLoadForwardQueryIO and LoadForwardQueryIO:
316  // PipeIO use predecoded sqIdxMask for better forward timing
317  class PipeLoadForwardQueryIO(implicit p: Parameters) extends LoadForwardQueryIO {
318    // val sqIdx = Output(new SqPtr) // for debug, should not be used in pipeline for timing reasons
319    // sqIdxMask is calcuated in earlier stage for better timing
320    val sqIdxMask = Output(UInt(StoreQueueSize.W))
321
322    // dataInvalid: addr match, but data is not valid for now
323    val dataInvalidFast = Input(Bool()) // resp to load_s1
324    // val dataInvalid = Input(Bool()) // resp to load_s2
325    val dataInvalidSqIdx = Input(new SqPtr) // resp to load_s2, sqIdx
326    val addrInvalidSqIdx = Input(new SqPtr) // resp to load_s2, sqIdx
327  }
328
329  // Query load queue for ld-ld violation
330  //
331  // Req should be send in load_s1
332  // Resp will be generated 1 cycle later
333  //
334  // Note that query req may be !ready, as dcache is releasing a block
335  // If it happens, a replay from rs is needed.
336  class LoadNukeQueryReq(implicit p: Parameters) extends XSBundle { // provide lqIdx
337    val uop = new DynInst
338    // mask: load's data mask.
339    val mask = UInt((VLEN/8).W)
340
341    // paddr: load's paddr.
342    val paddr      = UInt(PAddrBits.W)
343    // dataInvalid: load data is invalid.
344    val data_valid = Bool()
345    // nc: is NC access
346    val is_nc = Bool()
347  }
348
349  class LoadNukeQueryResp(implicit p: Parameters) extends XSBundle {
350    // rep_frm_fetch: ld-ld violation check success, replay from fetch.
351    val rep_frm_fetch = Bool()
352  }
353
354  class LoadNukeQueryIO(implicit p: Parameters) extends XSBundle {
355    val req    = Decoupled(new LoadNukeQueryReq)
356    val resp   = Flipped(Valid(new LoadNukeQueryResp))
357    val revoke = Output(Bool())
358  }
359
360  class StoreNukeQueryIO(implicit p: Parameters) extends XSBundle {
361    //  robIdx: Requestor's (a store instruction) rob index for match logic.
362    val robIdx = new RobPtr
363
364    //  paddr: requestor's (a store instruction) physical address for match logic.
365    val paddr  = UInt(PAddrBits.W)
366
367    //  mask: requestor's (a store instruction) data width mask for match logic.
368    val mask = UInt((VLEN/8).W)
369
370    // matchLine: if store is vector 128-bits, load unit need to compare 128-bits vaddr.
371    val matchLine = Bool()
372  }
373
374  class StoreMaBufToSqControlIO(implicit p: Parameters) extends XSBundle {
375    // from storeMisalignBuffer to storeQueue, control it's sbuffer write
376    val toStoreQueue = Output(new XSBundle {
377      // This entry is a cross page
378      val crossPageWithHit = Bool()
379      val crossPageCanDeq  = Bool()
380      // High page Paddr
381      val paddr = UInt(PAddrBits.W)
382
383      val withSameUop = Bool()
384    })
385    // from storeQueue to storeMisalignBuffer, provide detail info of this store
386    val toStoreMisalignBuffer = Input(new XSBundle {
387      val sqPtr = new SqPtr
388      val doDeq = Bool()
389
390      val uop = new DynInst()
391    })
392  }
393
394  class StoreMaBufToVecStoreMergeBufferIO(implicit p: Parameters)  extends VLSUBundle{
395    val mbIndex = Output(UInt(vsmBindexBits.W))
396    val flush   = Output(Bool())
397  }
398
399  // Store byte valid mask write bundle
400  //
401  // Store byte valid mask write to SQ takes 2 cycles
402  class StoreMaskBundle(implicit p: Parameters) extends XSBundle {
403    val sqIdx = new SqPtr
404    val mask = UInt((VLEN/8).W)
405  }
406
407  class LoadDataFromDcacheBundle(implicit p: Parameters) extends DCacheBundle {
408    // old dcache: optimize data sram read fanout
409    // val bankedDcacheData = Vec(DCacheBanks, UInt(64.W))
410    // val bank_oh = UInt(DCacheBanks.W)
411
412    // new dcache
413    val respDcacheData = UInt(VLEN.W)
414    val forwardMask = Vec(VLEN/8, Bool())
415    val forwardData = Vec(VLEN/8, UInt(8.W))
416    val uop = new DynInst // for data selection, only fwen and fuOpType are used
417    val addrOffset = UInt(4.W) // for data selection
418
419    // forward tilelink D channel
420    val forward_D = Bool()
421    val forwardData_D = Vec(VLEN/8, UInt(8.W))
422
423    // forward mshr data
424    val forward_mshr = Bool()
425    val forwardData_mshr = Vec(VLEN/8, UInt(8.W))
426
427    val forward_result_valid = Bool()
428
429    def mergeTLData(): UInt = {
430      // merge TL D or MSHR data at load s2
431      val dcache_data = respDcacheData
432      val use_D = forward_D && forward_result_valid
433      val use_mshr = forward_mshr && forward_result_valid
434      Mux(
435        use_D || use_mshr,
436        Mux(
437          use_D,
438          forwardData_D.asUInt,
439          forwardData_mshr.asUInt
440        ),
441        dcache_data
442      )
443    }
444
445    def mergeLsqFwdData(dcacheData: UInt): UInt = {
446      // merge dcache and lsq forward data at load s3
447      val rdataVec = VecInit((0 until VLEN / 8).map(j =>
448        Mux(forwardMask(j), forwardData(j), dcacheData(8*(j+1)-1, 8*j))
449      ))
450      rdataVec.asUInt
451    }
452  }
453
454  // Load writeback data from load queue (refill)
455  class LoadDataFromLQBundle(implicit p: Parameters) extends XSBundle {
456    val lqData = UInt(64.W) // load queue has merged data
457    val uop = new DynInst // for data selection, only fwen and fuOpType are used
458    val addrOffset = UInt(3.W) // for data selection
459
460    def mergedData(): UInt = {
461      lqData
462    }
463  }
464
465  // Bundle for load / store wait waking up
466  class MemWaitUpdateReq(implicit p: Parameters) extends XSBundle {
467    val robIdx = Vec(backendParams.StaExuCnt, ValidIO(new RobPtr))
468    val sqIdx = Vec(backendParams.StdCnt, ValidIO(new SqPtr))
469  }
470
471}
472