xref: /XiangShan/src/main/scala/xiangshan/mem/lsqueue/StoreQueue.scala (revision 643734bb561535e33ba254ba6475f4e4c271a6f4)
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 chisel3._
20import chisel3.util._
21import difftest._
22import difftest.common.DifftestMem
23import org.chipsalliance.cde.config.Parameters
24import utility._
25import utils._
26import xiangshan._
27import xiangshan.cache._
28import xiangshan.cache.{DCacheLineIO, DCacheWordIO, MemoryOpConstants}
29import xiangshan.backend._
30import xiangshan.backend.rob.{RobLsqIO, RobPtr}
31import xiangshan.backend.Bundles.{DynInst, MemExuOutput}
32
33class SqPtr(implicit p: Parameters) extends CircularQueuePtr[SqPtr](
34  p => p(XSCoreParamsKey).StoreQueueSize
35){
36}
37
38object SqPtr {
39  def apply(f: Bool, v: UInt)(implicit p: Parameters): SqPtr = {
40    val ptr = Wire(new SqPtr)
41    ptr.flag := f
42    ptr.value := v
43    ptr
44  }
45}
46
47class SqEnqIO(implicit p: Parameters) extends MemBlockBundle {
48  val canAccept = Output(Bool())
49  val lqCanAccept = Input(Bool())
50  val needAlloc = Vec(LSQEnqWidth, Input(Bool()))
51  val req = Vec(LSQEnqWidth, Flipped(ValidIO(new DynInst)))
52  val resp = Vec(LSQEnqWidth, Output(new SqPtr))
53}
54
55class DataBufferEntry (implicit p: Parameters)  extends DCacheBundle {
56  val addr   = UInt(PAddrBits.W)
57  val vaddr  = UInt(VAddrBits.W)
58  val data   = UInt(VLEN.W)
59  val mask   = UInt((VLEN/8).W)
60  val wline = Bool()
61  val sqPtr  = new SqPtr
62  val prefetch = Bool()
63}
64
65// Store Queue
66class StoreQueue(implicit p: Parameters) extends XSModule
67  with HasDCacheParameters with HasCircularQueuePtrHelper with HasPerfEvents {
68  val io = IO(new Bundle() {
69    val hartId = Input(UInt(8.W))
70    val enq = new SqEnqIO
71    val brqRedirect = Flipped(ValidIO(new Redirect))
72    val storeAddrIn = Vec(StorePipelineWidth, Flipped(Valid(new LsPipelineBundle))) // store addr, data is not included
73    val vecStoreAddrIn = Vec(StorePipelineWidth, Flipped(Valid(new LsPipelineBundle))) // vec store addr, data is not include
74    val storeAddrInRe = Vec(StorePipelineWidth, Input(new LsPipelineBundle())) // store more mmio and exception
75    val storeDataIn = Vec(StorePipelineWidth, Flipped(Valid(new MemExuOutput))) // store data, send to sq from rs
76    val storeMaskIn = Vec(StorePipelineWidth, Flipped(Valid(new StoreMaskBundle))) // store mask, send to sq from rs
77    val sbuffer = Vec(EnsbufferWidth, Decoupled(new DCacheWordReqWithVaddrAndPfFlag)) // write committed store to sbuffer
78    val uncacheOutstanding = Input(Bool())
79    val mmioStout = DecoupledIO(new MemExuOutput) // writeback uncached store
80    val forward = Vec(LoadPipelineWidth, Flipped(new PipeLoadForwardQueryIO))
81    val rob = Flipped(new RobLsqIO)
82    val uncache = new UncacheWordIO
83    // val refill = Flipped(Valid(new DCacheLineReq ))
84    val exceptionAddr = new ExceptionAddrIO
85    val sqEmpty = Output(Bool())
86    val stAddrReadySqPtr = Output(new SqPtr)
87    val stAddrReadyVec = Output(Vec(StoreQueueSize, Bool()))
88    val stDataReadySqPtr = Output(new SqPtr)
89    val stDataReadyVec = Output(Vec(StoreQueueSize, Bool()))
90    val stIssuePtr = Output(new SqPtr)
91    val sqDeqPtr = Output(new SqPtr)
92    val sqFull = Output(Bool())
93    val sqCancelCnt = Output(UInt(log2Up(StoreQueueSize + 1).W))
94    val sqDeq = Output(UInt(log2Ceil(EnsbufferWidth + 1).W))
95    val force_write = Output(Bool())
96    val vecStoreRetire = Flipped(ValidIO(new SqPtr))
97  })
98
99  println("StoreQueue: size:" + StoreQueueSize)
100
101  // data modules
102  val uop = Reg(Vec(StoreQueueSize, new DynInst))
103  // val data = Reg(Vec(StoreQueueSize, new LsqEntry))
104  val dataModule = Module(new SQDataModule(
105    numEntries = StoreQueueSize,
106    numRead = EnsbufferWidth,
107    numWrite = StorePipelineWidth,
108    numForward = LoadPipelineWidth
109  ))
110  dataModule.io := DontCare
111  val paddrModule = Module(new SQAddrModule(
112    dataWidth = PAddrBits,
113    numEntries = StoreQueueSize,
114    numRead = EnsbufferWidth,
115    numWrite = StorePipelineWidth,
116    numForward = LoadPipelineWidth
117  ))
118  paddrModule.io := DontCare
119  val vaddrModule = Module(new SQAddrModule(
120    dataWidth = VAddrBits,
121    numEntries = StoreQueueSize,
122    numRead = EnsbufferWidth + 1, // sbuffer + badvaddr 1 (TODO)
123    numWrite = StorePipelineWidth,
124    numForward = LoadPipelineWidth
125  ))
126  vaddrModule.io := DontCare
127  val dataBuffer = Module(new DatamoduleResultBuffer(new DataBufferEntry))
128  val debug_paddr = Reg(Vec(StoreQueueSize, UInt((PAddrBits).W)))
129  val debug_vaddr = Reg(Vec(StoreQueueSize, UInt((VAddrBits).W)))
130  val debug_data = Reg(Vec(StoreQueueSize, UInt((XLEN).W)))
131
132  // state & misc
133  val allocated = RegInit(VecInit(List.fill(StoreQueueSize)(false.B))) // sq entry has been allocated
134  val addrvalid = RegInit(VecInit(List.fill(StoreQueueSize)(false.B))) // non-mmio addr is valid
135  val datavalid = RegInit(VecInit(List.fill(StoreQueueSize)(false.B))) // non-mmio data is valid
136  val allvalid  = VecInit((0 until StoreQueueSize).map(i => addrvalid(i) && datavalid(i))) // non-mmio data & addr is valid
137  val committed = Reg(Vec(StoreQueueSize, Bool())) // inst has been committed by rob
138  val pending = Reg(Vec(StoreQueueSize, Bool())) // mmio pending: inst is an mmio inst, it will not be executed until it reachs the end of rob
139  val mmio = Reg(Vec(StoreQueueSize, Bool())) // mmio: inst is an mmio inst
140  val atomic = Reg(Vec(StoreQueueSize, Bool()))
141  val prefetch = RegInit(VecInit(List.fill(StoreQueueSize)(false.B))) // need prefetch when committing this store to sbuffer?
142  val vec = Reg(Vec(StoreQueueSize, Bool()))
143  val vecAddrvalid = Reg(Vec(StoreQueueSize, Bool())) // TODO
144
145  // ptr
146  val enqPtrExt = RegInit(VecInit((0 until io.enq.req.length).map(_.U.asTypeOf(new SqPtr))))
147  val rdataPtrExt = RegInit(VecInit((0 until EnsbufferWidth).map(_.U.asTypeOf(new SqPtr))))
148  val deqPtrExt = RegInit(VecInit((0 until EnsbufferWidth).map(_.U.asTypeOf(new SqPtr))))
149  val cmtPtrExt = RegInit(VecInit((0 until CommitWidth).map(_.U.asTypeOf(new SqPtr))))
150  val addrReadyPtrExt = RegInit(0.U.asTypeOf(new SqPtr))
151  val dataReadyPtrExt = RegInit(0.U.asTypeOf(new SqPtr))
152  val validCounter = RegInit(0.U(log2Ceil(VirtualLoadQueueSize + 1).W))
153
154  val enqPtr = enqPtrExt(0).value
155  val deqPtr = deqPtrExt(0).value
156  val cmtPtr = cmtPtrExt(0).value
157
158  val validCount = distanceBetween(enqPtrExt(0), deqPtrExt(0))
159  val allowEnqueue = validCount <= (StoreQueueSize - StorePipelineWidth).U
160
161  val deqMask = UIntToMask(deqPtr, StoreQueueSize)
162  val enqMask = UIntToMask(enqPtr, StoreQueueSize)
163
164  val commitCount = RegNext(io.rob.scommit)
165
166  // store can be committed by ROB
167  io.rob.mmio := DontCare
168  io.rob.uop := DontCare
169
170  // Read dataModule
171  assert(EnsbufferWidth <= 2)
172  // rdataPtrExtNext and rdataPtrExtNext+1 entry will be read from dataModule
173  val rdataPtrExtNext = WireInit(Mux(dataBuffer.io.enq(1).fire,
174    VecInit(rdataPtrExt.map(_ + 2.U)),
175    Mux(dataBuffer.io.enq(0).fire || io.mmioStout.fire || io.vecStoreRetire.valid,
176      VecInit(rdataPtrExt.map(_ + 1.U)),
177      rdataPtrExt
178    )
179  ))
180
181  // deqPtrExtNext traces which inst is about to leave store queue
182  //
183  // io.sbuffer(i).fire is RegNexted, as sbuffer data write takes 2 cycles.
184  // Before data write finish, sbuffer is unable to provide store to load
185  // forward data. As an workaround, deqPtrExt and allocated flag update
186  // is delayed so that load can get the right data from store queue.
187  //
188  // Modify deqPtrExtNext and io.sqDeq with care!
189  val deqPtrExtNext = Mux(RegNext(io.sbuffer(1).fire),
190    VecInit(deqPtrExt.map(_ + 2.U)),
191    Mux(RegNext(io.sbuffer(0).fire) || io.mmioStout.fire || io.vecStoreRetire.valid,
192      VecInit(deqPtrExt.map(_ + 1.U)),
193      deqPtrExt
194    )
195  )
196  io.sqDeq := RegNext(Mux(RegNext(io.sbuffer(1).fire), 2.U,
197    Mux(RegNext(io.sbuffer(0).fire) || io.mmioStout.fire || io.vecStoreRetire.valid, 1.U, 0.U)
198  ))
199  assert(!RegNext(RegNext(io.sbuffer(0).fire) && io.mmioStout.fire))
200
201  for (i <- 0 until EnsbufferWidth) {
202    dataModule.io.raddr(i) := rdataPtrExtNext(i).value
203    paddrModule.io.raddr(i) := rdataPtrExtNext(i).value
204    vaddrModule.io.raddr(i) := rdataPtrExtNext(i).value
205  }
206
207  // no inst will be committed 1 cycle before tval update
208  vaddrModule.io.raddr(EnsbufferWidth) := (cmtPtrExt(0) + commitCount).value
209
210  /**
211    * Enqueue at dispatch
212    *
213    * Currently, StoreQueue only allows enqueue when #emptyEntries > EnqWidth
214    */
215  io.enq.canAccept := allowEnqueue
216  val canEnqueue = io.enq.req.map(_.valid)
217  val enqCancel = io.enq.req.map(_.bits.robIdx.needFlush(io.brqRedirect))
218  for (i <- 0 until io.enq.req.length) {
219    val offset = if (i == 0) 0.U else PopCount(io.enq.needAlloc.take(i))
220    val sqIdx = enqPtrExt(offset)
221    val index = io.enq.req(i).bits.sqIdx.value
222    when (canEnqueue(i) && !enqCancel(i)) {
223      uop(index) := io.enq.req(i).bits
224      // NOTE: the index will be used when replay
225      uop(index).sqIdx := sqIdx
226      allocated(index) := true.B
227      datavalid(index) := false.B
228      addrvalid(index) := false.B
229      committed(index) := false.B
230      pending(index) := false.B
231      prefetch(index) := false.B
232      mmio(index) := false.B
233      vec(index) := io.enq.req(i).bits.instr(6, 0) === "b0100111".U // TODO
234      vecAddrvalid(index) := false.B//TODO
235
236      XSError(!io.enq.canAccept || !io.enq.lqCanAccept, s"must accept $i\n")
237      XSError(index =/= sqIdx.value, s"must be the same entry $i\n")
238    }
239    io.enq.resp(i) := sqIdx
240  }
241  XSDebug(p"(ready, valid): ${io.enq.canAccept}, ${Binary(Cat(io.enq.req.map(_.valid)))}\n")
242
243  /**
244    * Update addr/dataReadyPtr when issue from rs
245    */
246  // update issuePtr
247  val IssuePtrMoveStride = 4
248  require(IssuePtrMoveStride >= 2)
249
250  val addrReadyLookupVec = (0 until IssuePtrMoveStride).map(addrReadyPtrExt + _.U)
251  val addrReadyLookup = addrReadyLookupVec.map(ptr => allocated(ptr.value) && (mmio(ptr.value) || addrvalid(ptr.value) || (vec(ptr.value) && vecAddrvalid(ptr.value))) && ptr =/= enqPtrExt(0))
252  val nextAddrReadyPtr = addrReadyPtrExt + PriorityEncoder(VecInit(addrReadyLookup.map(!_) :+ true.B))
253  addrReadyPtrExt := nextAddrReadyPtr
254
255  (0 until StoreQueueSize).map(i => {
256    io.stAddrReadyVec(i) := RegNext(allocated(i) && (mmio(i) || addrvalid(i)))
257  })
258
259  when (io.brqRedirect.valid) {
260    addrReadyPtrExt := Mux(
261      isAfter(cmtPtrExt(0), deqPtrExt(0)),
262      cmtPtrExt(0),
263      deqPtrExtNext(0) // for mmio insts, deqPtr may be ahead of cmtPtr
264    )
265  }
266
267  io.stAddrReadySqPtr := addrReadyPtrExt
268
269  // update
270  val dataReadyLookupVec = (0 until IssuePtrMoveStride).map(dataReadyPtrExt + _.U)
271  val dataReadyLookup = dataReadyLookupVec.map(ptr => allocated(ptr.value) && (mmio(ptr.value) || datavalid(ptr.value) || vec(ptr.value)) && ptr =/= enqPtrExt(0)) // TODO : flag of vector store data valid not add yet
272  val nextDataReadyPtr = dataReadyPtrExt + PriorityEncoder(VecInit(dataReadyLookup.map(!_) :+ true.B))
273  dataReadyPtrExt := nextDataReadyPtr
274
275  (0 until StoreQueueSize).map(i => {
276    io.stDataReadyVec(i) := RegNext(allocated(i) && (mmio(i) || datavalid(i)))
277  })
278
279  when (io.brqRedirect.valid) {
280    dataReadyPtrExt := Mux(
281      isAfter(cmtPtrExt(0), deqPtrExt(0)),
282      cmtPtrExt(0),
283      deqPtrExtNext(0) // for mmio insts, deqPtr may be ahead of cmtPtr
284    )
285  }
286
287  io.stDataReadySqPtr := dataReadyPtrExt
288  io.stIssuePtr := enqPtrExt(0)
289  io.sqDeqPtr := deqPtrExt(0)
290
291  /**
292    * Writeback store from store units
293    *
294    * Most store instructions writeback to regfile in the previous cycle.
295    * However,
296    *   (1) For an mmio instruction with exceptions, we need to mark it as addrvalid
297    * (in this way it will trigger an exception when it reaches ROB's head)
298    * instead of pending to avoid sending them to lower level.
299    *   (2) For an mmio instruction without exceptions, we mark it as pending.
300    * When the instruction reaches ROB's head, StoreQueue sends it to uncache channel.
301    * Upon receiving the response, StoreQueue writes back the instruction
302    * through arbiter with store units. It will later commit as normal.
303    */
304
305  // Write addr to sq
306  for (i <- 0 until StorePipelineWidth) {
307    paddrModule.io.wen(i) := false.B
308    vaddrModule.io.wen(i) := false.B
309    dataModule.io.mask.wen(i) := false.B
310    val stWbIndex = io.storeAddrIn(i).bits.uop.sqIdx.value
311    when (io.storeAddrIn(i).fire) {
312      val addr_valid = !io.storeAddrIn(i).bits.miss
313      addrvalid(stWbIndex) := addr_valid //!io.storeAddrIn(i).bits.mmio
314      // pending(stWbIndex) := io.storeAddrIn(i).bits.mmio
315
316      paddrModule.io.waddr(i) := stWbIndex
317      paddrModule.io.wdata(i) := io.storeAddrIn(i).bits.paddr
318      paddrModule.io.wmask(i) := io.storeAddrIn(i).bits.mask
319      paddrModule.io.wlineflag(i) := io.storeAddrIn(i).bits.wlineflag
320      paddrModule.io.wen(i) := true.B
321
322      vaddrModule.io.waddr(i) := stWbIndex
323      vaddrModule.io.wdata(i) := io.storeAddrIn(i).bits.vaddr
324      vaddrModule.io.wmask(i) := io.storeAddrIn(i).bits.mask
325      vaddrModule.io.wlineflag(i) := io.storeAddrIn(i).bits.wlineflag
326      vaddrModule.io.wen(i) := true.B
327
328      debug_paddr(paddrModule.io.waddr(i)) := paddrModule.io.wdata(i)
329
330      // mmio(stWbIndex) := io.storeAddrIn(i).bits.mmio
331
332      uop(stWbIndex) := io.storeAddrIn(i).bits.uop
333      uop(stWbIndex).debugInfo := io.storeAddrIn(i).bits.uop.debugInfo
334      XSInfo("store addr write to sq idx %d pc 0x%x miss:%d vaddr %x paddr %x mmio %x\n",
335        io.storeAddrIn(i).bits.uop.sqIdx.value,
336        io.storeAddrIn(i).bits.uop.pc,
337        io.storeAddrIn(i).bits.miss,
338        io.storeAddrIn(i).bits.vaddr,
339        io.storeAddrIn(i).bits.paddr,
340        io.storeAddrIn(i).bits.mmio
341      )
342    }
343
344    // re-replinish mmio, for pma/pmp will get mmio one cycle later
345    val storeAddrInFireReg = RegNext(io.storeAddrIn(i).fire && !io.storeAddrIn(i).bits.miss)
346    val stWbIndexReg = RegNext(stWbIndex)
347    when (storeAddrInFireReg) {
348      pending(stWbIndexReg) := io.storeAddrInRe(i).mmio
349      mmio(stWbIndexReg) := io.storeAddrInRe(i).mmio
350      atomic(stWbIndexReg) := io.storeAddrInRe(i).atomic
351    }
352    // dcache miss info (one cycle later than storeIn)
353    // if dcache report a miss in sta pipeline, this store will trigger a prefetch when committing to sbuffer (if EnableAtCommitMissTrigger)
354    when (storeAddrInFireReg) {
355      prefetch(stWbIndexReg) := io.storeAddrInRe(i).miss
356    }
357
358    when(vaddrModule.io.wen(i)){
359      debug_vaddr(vaddrModule.io.waddr(i)) := vaddrModule.io.wdata(i)
360    }
361    // TODO :  When lastElem issue to stu, set vector store addr ready
362    val vecStWbIndex = io.vecStoreAddrIn(i).bits.uop.sqIdx.value
363    when(io.vecStoreAddrIn(i).fire){
364      vecAddrvalid(vecStWbIndex) := !io.vecStoreAddrIn(i).bits.miss && io.vecStoreAddrIn(i).bits.isLastElem
365    }
366  }
367
368  // Write data to sq
369  // Now store data pipeline is actually 2 stages
370  for (i <- 0 until StorePipelineWidth) {
371    dataModule.io.data.wen(i) := false.B
372    val stWbIndex = io.storeDataIn(i).bits.uop.sqIdx.value
373    // sq data write takes 2 cycles:
374    // sq data write s0
375    when (io.storeDataIn(i).fire) {
376      // send data write req to data module
377      dataModule.io.data.waddr(i) := stWbIndex
378      dataModule.io.data.wdata(i) := Mux(io.storeDataIn(i).bits.uop.fuOpType === LSUOpType.cbo_zero,
379        0.U,
380        genWdata(io.storeDataIn(i).bits.data, io.storeDataIn(i).bits.uop.fuOpType(1,0))
381      )
382      dataModule.io.data.wen(i) := true.B
383
384      debug_data(dataModule.io.data.waddr(i)) := dataModule.io.data.wdata(i)
385
386      XSInfo("store data write to sq idx %d pc 0x%x data %x -> %x\n",
387        io.storeDataIn(i).bits.uop.sqIdx.value,
388        io.storeDataIn(i).bits.uop.pc,
389        io.storeDataIn(i).bits.data,
390        dataModule.io.data.wdata(i)
391      )
392    }
393    // sq data write s1
394    when (
395      RegNext(io.storeDataIn(i).fire)
396      // && !RegNext(io.storeDataIn(i).bits.uop).robIdx.needFlush(io.brqRedirect)
397    ) {
398      datavalid(RegNext(stWbIndex)) := true.B
399    }
400  }
401
402  // Write mask to sq
403  for (i <- 0 until StorePipelineWidth) {
404    // sq mask write s0
405    when (io.storeMaskIn(i).fire) {
406      // send data write req to data module
407      dataModule.io.mask.waddr(i) := io.storeMaskIn(i).bits.sqIdx.value
408      dataModule.io.mask.wdata(i) := io.storeMaskIn(i).bits.mask
409      dataModule.io.mask.wen(i) := true.B
410    }
411  }
412
413  /**
414    * load forward query
415    *
416    * Check store queue for instructions that is older than the load.
417    * The response will be valid at the next cycle after req.
418    */
419  // check over all lq entries and forward data from the first matched store
420  for (i <- 0 until LoadPipelineWidth) {
421    // Compare deqPtr (deqPtr) and forward.sqIdx, we have two cases:
422    // (1) if they have the same flag, we need to check range(tail, sqIdx)
423    // (2) if they have different flags, we need to check range(tail, VirtualLoadQueueSize) and range(0, sqIdx)
424    // Forward1: Mux(same_flag, range(tail, sqIdx), range(tail, VirtualLoadQueueSize))
425    // Forward2: Mux(same_flag, 0.U,                   range(0, sqIdx)    )
426    // i.e. forward1 is the target entries with the same flag bits and forward2 otherwise
427    val differentFlag = deqPtrExt(0).flag =/= io.forward(i).sqIdx.flag
428    val forwardMask = io.forward(i).sqIdxMask
429    // all addrvalid terms need to be checked
430    val addrValidVec = WireInit(VecInit((0 until StoreQueueSize).map(i => addrvalid(i) && allocated(i))))
431    val dataValidVec = WireInit(VecInit((0 until StoreQueueSize).map(i => datavalid(i))))
432    val allValidVec  = WireInit(VecInit((0 until StoreQueueSize).map(i => addrvalid(i) && datavalid(i) && allocated(i))))
433
434    val storeSetHitVec =
435      if (LFSTEnable) {
436        WireInit(VecInit((0 until StoreQueueSize).map(j => io.forward(i).uop.loadWaitBit && uop(j).robIdx === io.forward(i).uop.waitForRobIdx)))
437      } else {
438        WireInit(VecInit((0 until StoreQueueSize).map(j => uop(j).storeSetHit && uop(j).ssid === io.forward(i).uop.ssid)))
439      }
440
441    val forwardMask1 = Mux(differentFlag, ~deqMask, deqMask ^ forwardMask)
442    val forwardMask2 = Mux(differentFlag, forwardMask, 0.U(StoreQueueSize.W))
443    val canForward1 = forwardMask1 & allValidVec.asUInt
444    val canForward2 = forwardMask2 & allValidVec.asUInt
445    val needForward = Mux(differentFlag, ~deqMask | forwardMask, deqMask ^ forwardMask)
446
447    XSDebug(p"$i f1 ${Binary(canForward1)} f2 ${Binary(canForward2)} " +
448      p"sqIdx ${io.forward(i).sqIdx} pa ${Hexadecimal(io.forward(i).paddr)}\n"
449    )
450
451    // do real fwd query (cam lookup in load_s1)
452    dataModule.io.needForward(i)(0) := canForward1 & vaddrModule.io.forwardMmask(i).asUInt
453    dataModule.io.needForward(i)(1) := canForward2 & vaddrModule.io.forwardMmask(i).asUInt
454
455    vaddrModule.io.forwardMdata(i) := io.forward(i).vaddr
456    vaddrModule.io.forwardDataMask(i) := io.forward(i).mask
457    paddrModule.io.forwardMdata(i) := io.forward(i).paddr
458    paddrModule.io.forwardDataMask(i) := io.forward(i).mask
459
460
461    // vaddr cam result does not equal to paddr cam result
462    // replay needed
463    // val vpmaskNotEqual = ((paddrModule.io.forwardMmask(i).asUInt ^ vaddrModule.io.forwardMmask(i).asUInt) & needForward) =/= 0.U
464    // val vaddrMatchFailed = vpmaskNotEqual && io.forward(i).valid
465    val vpmaskNotEqual = (
466      (RegNext(paddrModule.io.forwardMmask(i).asUInt) ^ RegNext(vaddrModule.io.forwardMmask(i).asUInt)) &
467      RegNext(needForward) &
468      RegNext(addrValidVec.asUInt)
469    ) =/= 0.U
470    val vaddrMatchFailed = vpmaskNotEqual && RegNext(io.forward(i).valid)
471    when (vaddrMatchFailed) {
472      XSInfo("vaddrMatchFailed: pc %x pmask %x vmask %x\n",
473        RegNext(io.forward(i).uop.pc),
474        RegNext(needForward & paddrModule.io.forwardMmask(i).asUInt),
475        RegNext(needForward & vaddrModule.io.forwardMmask(i).asUInt)
476      );
477    }
478    XSPerfAccumulate("vaddr_match_failed", vpmaskNotEqual)
479    XSPerfAccumulate("vaddr_match_really_failed", vaddrMatchFailed)
480
481    // Fast forward mask will be generated immediately (load_s1)
482    io.forward(i).forwardMaskFast := dataModule.io.forwardMaskFast(i)
483
484    // Forward result will be generated 1 cycle later (load_s2)
485    io.forward(i).forwardMask := dataModule.io.forwardMask(i)
486    io.forward(i).forwardData := dataModule.io.forwardData(i)
487    // If addr match, data not ready, mark it as dataInvalid
488    // load_s1: generate dataInvalid in load_s1 to set fastUop
489    val dataInvalidMask1 = (addrValidVec.asUInt & ~dataValidVec.asUInt & vaddrModule.io.forwardMmask(i).asUInt & forwardMask1.asUInt)
490    val dataInvalidMask2 = (addrValidVec.asUInt & ~dataValidVec.asUInt & vaddrModule.io.forwardMmask(i).asUInt & forwardMask2.asUInt)
491    val dataInvalidMask = dataInvalidMask1 | dataInvalidMask2
492    io.forward(i).dataInvalidFast := dataInvalidMask.orR
493
494    // make chisel happy
495    val dataInvalidMask1Reg = Wire(UInt(StoreQueueSize.W))
496    dataInvalidMask1Reg := RegNext(dataInvalidMask1)
497    // make chisel happy
498    val dataInvalidMask2Reg = Wire(UInt(StoreQueueSize.W))
499    dataInvalidMask2Reg := RegNext(dataInvalidMask2)
500    val dataInvalidMaskReg = dataInvalidMask1Reg | dataInvalidMask2Reg
501
502    // If SSID match, address not ready, mark it as addrInvalid
503    // load_s2: generate addrInvalid
504    val addrInvalidMask1 = (~addrValidVec.asUInt & storeSetHitVec.asUInt & forwardMask1.asUInt)
505    val addrInvalidMask2 = (~addrValidVec.asUInt & storeSetHitVec.asUInt & forwardMask2.asUInt)
506    // make chisel happy
507    val addrInvalidMask1Reg = Wire(UInt(StoreQueueSize.W))
508    addrInvalidMask1Reg := RegNext(addrInvalidMask1)
509    // make chisel happy
510    val addrInvalidMask2Reg = Wire(UInt(StoreQueueSize.W))
511    addrInvalidMask2Reg := RegNext(addrInvalidMask2)
512    val addrInvalidMaskReg = addrInvalidMask1Reg | addrInvalidMask2Reg
513
514    // load_s2
515    io.forward(i).dataInvalid := RegNext(io.forward(i).dataInvalidFast)
516    // check if vaddr forward mismatched
517    io.forward(i).matchInvalid := vaddrMatchFailed
518
519    // data invalid sq index
520    // check whether false fail
521    // check flag
522    val s2_differentFlag = RegNext(differentFlag)
523    val s2_enqPtrExt = RegNext(enqPtrExt(0))
524    val s2_deqPtrExt = RegNext(deqPtrExt(0))
525
526    // addr invalid sq index
527    // make chisel happy
528    val addrInvalidMaskRegWire = Wire(UInt(StoreQueueSize.W))
529    addrInvalidMaskRegWire := addrInvalidMaskReg
530    val addrInvalidFlag = addrInvalidMaskRegWire.orR
531    val hasInvalidAddr = (~addrValidVec.asUInt & needForward).orR
532
533    val addrInvalidSqIdx1 = OHToUInt(Reverse(PriorityEncoderOH(Reverse(addrInvalidMask1Reg))))
534    val addrInvalidSqIdx2 = OHToUInt(Reverse(PriorityEncoderOH(Reverse(addrInvalidMask2Reg))))
535    val addrInvalidSqIdx = Mux(addrInvalidMask2Reg.orR, addrInvalidSqIdx2, addrInvalidSqIdx1)
536
537    // store-set content management
538    //                +-----------------------+
539    //                | Search a SSID for the |
540    //                |    load operation     |
541    //                +-----------------------+
542    //                           |
543    //                           V
544    //                 +-------------------+
545    //                 | load wait strict? |
546    //                 +-------------------+
547    //                           |
548    //                           V
549    //               +----------------------+
550    //            Set|                      |Clean
551    //               V                      V
552    //  +------------------------+   +------------------------------+
553    //  | Waiting for all older  |   | Wait until the corresponding |
554    //  |   stores operations    |   | older store operations       |
555    //  +------------------------+   +------------------------------+
556
557
558
559    when (RegNext(io.forward(i).uop.loadWaitStrict)) {
560      io.forward(i).addrInvalidSqIdx := RegNext(io.forward(i).uop.sqIdx - 1.U)
561    } .elsewhen (addrInvalidFlag) {
562      io.forward(i).addrInvalidSqIdx.flag := Mux(!s2_differentFlag || addrInvalidSqIdx >= s2_deqPtrExt.value, s2_deqPtrExt.flag, s2_enqPtrExt.flag)
563      io.forward(i).addrInvalidSqIdx.value := addrInvalidSqIdx
564    } .otherwise {
565      // may be store inst has been written to sbuffer already.
566      io.forward(i).addrInvalidSqIdx := RegNext(io.forward(i).uop.sqIdx)
567    }
568    io.forward(i).addrInvalid := Mux(RegNext(io.forward(i).uop.loadWaitStrict), RegNext(hasInvalidAddr), addrInvalidFlag)
569
570    // data invalid sq index
571    // make chisel happy
572    val dataInvalidMaskRegWire = Wire(UInt(StoreQueueSize.W))
573    dataInvalidMaskRegWire := dataInvalidMaskReg
574    val dataInvalidFlag = dataInvalidMaskRegWire.orR
575
576    val dataInvalidSqIdx1 = OHToUInt(Reverse(PriorityEncoderOH(Reverse(dataInvalidMask1Reg))))
577    val dataInvalidSqIdx2 = OHToUInt(Reverse(PriorityEncoderOH(Reverse(dataInvalidMask2Reg))))
578    val dataInvalidSqIdx = Mux(dataInvalidMask2Reg.orR, dataInvalidSqIdx2, dataInvalidSqIdx1)
579
580    when (dataInvalidFlag) {
581      io.forward(i).dataInvalidSqIdx.flag := Mux(!s2_differentFlag || dataInvalidSqIdx >= s2_deqPtrExt.value, s2_deqPtrExt.flag, s2_enqPtrExt.flag)
582      io.forward(i).dataInvalidSqIdx.value := dataInvalidSqIdx
583    } .otherwise {
584      // may be store inst has been written to sbuffer already.
585      io.forward(i).dataInvalidSqIdx := RegNext(io.forward(i).uop.sqIdx)
586    }
587  }
588
589  /**
590    * Memory mapped IO / other uncached operations
591    *
592    * States:
593    * (1) writeback from store units: mark as pending
594    * (2) when they reach ROB's head, they can be sent to uncache channel
595    * (3) response from uncache channel: mark as datavalidmask.wen
596    * (4) writeback to ROB (and other units): mark as writebacked
597    * (5) ROB commits the instruction: same as normal instructions
598    */
599  //(2) when they reach ROB's head, they can be sent to uncache channel
600  val s_idle :: s_req :: s_resp :: s_wb :: s_wait :: Nil = Enum(5)
601  val uncacheState = RegInit(s_idle)
602  switch(uncacheState) {
603    is(s_idle) {
604      when(RegNext(io.rob.pendingst && pending(deqPtr) && allocated(deqPtr) && datavalid(deqPtr) && addrvalid(deqPtr))) {
605        uncacheState := s_req
606      }
607    }
608    is(s_req) {
609      when (io.uncache.req.fire) {
610        when (io.uncacheOutstanding) {
611          uncacheState := s_wb
612        } .otherwise {
613          uncacheState := s_resp
614        }
615      }
616    }
617    is(s_resp) {
618      when(io.uncache.resp.fire) {
619        uncacheState := s_wb
620      }
621    }
622    is(s_wb) {
623      when (io.mmioStout.fire) {
624        uncacheState := s_wait
625      }
626    }
627    is(s_wait) {
628      when(commitCount > 0.U) {
629        uncacheState := s_idle // ready for next mmio
630      }
631    }
632  }
633  io.uncache.req.valid := uncacheState === s_req
634
635  io.uncache.req.bits := DontCare
636  io.uncache.req.bits.cmd  := MemoryOpConstants.M_XWR
637  io.uncache.req.bits.addr := paddrModule.io.rdata(0) // data(deqPtr) -> rdata(0)
638  io.uncache.req.bits.data := shiftDataToLow(paddrModule.io.rdata(0), dataModule.io.rdata(0).data)
639  io.uncache.req.bits.mask := shiftMaskToLow(paddrModule.io.rdata(0), dataModule.io.rdata(0).mask)
640
641  // CBO op type check can be delayed for 1 cycle,
642  // as uncache op will not start in s_idle
643  val cbo_mmio_addr = paddrModule.io.rdata(0) >> 2 << 2 // clear lowest 2 bits for op
644  val cbo_mmio_op = 0.U //TODO
645  val cbo_mmio_data = cbo_mmio_addr | cbo_mmio_op
646  when(RegNext(LSUOpType.isCbo(uop(deqPtr).fuOpType))){
647    io.uncache.req.bits.addr := DontCare // TODO
648    io.uncache.req.bits.data := paddrModule.io.rdata(0)
649    io.uncache.req.bits.mask := DontCare // TODO
650  }
651
652  io.uncache.req.bits.atomic := atomic(RegNext(rdataPtrExtNext(0)).value)
653
654  when(io.uncache.req.fire){
655    // mmio store should not be committed until uncache req is sent
656    pending(deqPtr) := false.B
657
658    XSDebug(
659      p"uncache req: pc ${Hexadecimal(uop(deqPtr).pc)} " +
660      p"addr ${Hexadecimal(io.uncache.req.bits.addr)} " +
661      p"data ${Hexadecimal(io.uncache.req.bits.data)} " +
662      p"op ${Hexadecimal(io.uncache.req.bits.cmd)} " +
663      p"mask ${Hexadecimal(io.uncache.req.bits.mask)}\n"
664    )
665  }
666
667  // (3) response from uncache channel: mark as datavalid
668  io.uncache.resp.ready := true.B
669
670  // (4) writeback to ROB (and other units): mark as writebacked
671  io.mmioStout.valid := uncacheState === s_wb
672  io.mmioStout.bits.uop := uop(deqPtr)
673  io.mmioStout.bits.uop.sqIdx := deqPtrExt(0)
674  io.mmioStout.bits.data := shiftDataToLow(paddrModule.io.rdata(0), dataModule.io.rdata(0).data) // dataModule.io.rdata.read(deqPtr)
675  io.mmioStout.bits.debug.isMMIO := true.B
676  io.mmioStout.bits.debug.paddr := DontCare
677  io.mmioStout.bits.debug.isPerfCnt := false.B
678  io.mmioStout.bits.debug.vaddr := DontCare
679  // Remove MMIO inst from store queue after MMIO request is being sent
680  // That inst will be traced by uncache state machine
681  when (io.mmioStout.fire) {
682    allocated(deqPtr) := false.B
683  }
684
685  /**
686    * ROB commits store instructions (mark them as committed)
687    *
688    * (1) When store commits, mark it as committed.
689    * (2) They will not be cancelled and can be sent to lower level.
690    */
691  XSError(uncacheState =/= s_idle && uncacheState =/= s_wait && commitCount > 0.U,
692   "should not commit instruction when MMIO has not been finished\n")
693  for (i <- 0 until CommitWidth) {
694    when (commitCount > i.U) { // MMIO inst is not in progress
695      if(i == 0){
696        // MMIO inst should not update committed flag
697        // Note that commit count has been delayed for 1 cycle
698        when(uncacheState === s_idle){
699          committed(cmtPtrExt(0).value) := true.B
700        }
701      } else {
702        committed(cmtPtrExt(i).value) := true.B
703      }
704    }
705  }
706  cmtPtrExt := cmtPtrExt.map(_ + commitCount)
707
708  // committed stores will not be cancelled and can be sent to lower level.
709  // remove retired insts from sq, add retired store to sbuffer
710
711  // Read data from data module
712  // As store queue grows larger and larger, time needed to read data from data
713  // module keeps growing higher. Now we give data read a whole cycle.
714
715  // Vector stores are written to sbuffer by vector store flow queue rather than sq
716  XSError(io.vecStoreRetire.valid && !vec(rdataPtrExt(0).value), "Vector store flow queue is trying to retire a scalar store")
717  XSError(io.vecStoreRetire.valid && !allocated(rdataPtrExt(0).value), "Vector store flow queue is trying to retire an invalid entry")
718  XSError(io.vecStoreRetire.valid && vec(rdataPtrExt(0).value) && !vecAddrvalid(rdataPtrExt(0).value), "Vector store is trying to retire without write last element!")
719  when (io.vecStoreRetire.valid) {
720    assert(io.vecStoreRetire.bits === rdataPtrExt(0))
721    vec(rdataPtrExt(0).value) := false.B
722    vecAddrvalid(rdataPtrExt(0).value) := false.B
723    allocated(rdataPtrExt(0).value) := false.B
724  }
725
726  val mmioStall = mmio(rdataPtrExt(0).value)
727  val vecStall = vec(rdataPtrExt(0).value)
728  for (i <- 0 until EnsbufferWidth) {
729    val ptr = rdataPtrExt(i).value
730    dataBuffer.io.enq(i).valid := allocated(ptr) && committed(ptr) && !mmioStall && !vecStall
731    // Note that store data/addr should both be valid after store's commit
732    assert(!dataBuffer.io.enq(i).valid || allvalid(ptr))
733    dataBuffer.io.enq(i).bits.addr     := paddrModule.io.rdata(i)
734    dataBuffer.io.enq(i).bits.vaddr    := vaddrModule.io.rdata(i)
735    dataBuffer.io.enq(i).bits.data     := dataModule.io.rdata(i).data
736    dataBuffer.io.enq(i).bits.mask     := dataModule.io.rdata(i).mask
737    dataBuffer.io.enq(i).bits.wline    := paddrModule.io.rlineflag(i)
738    dataBuffer.io.enq(i).bits.sqPtr    := rdataPtrExt(i)
739    dataBuffer.io.enq(i).bits.prefetch := prefetch(ptr)
740  }
741
742  // Send data stored in sbufferReqBitsReg to sbuffer
743  for (i <- 0 until EnsbufferWidth) {
744    io.sbuffer(i).valid := dataBuffer.io.deq(i).valid
745    dataBuffer.io.deq(i).ready := io.sbuffer(i).ready
746    // Write line request should have all 1 mask
747    assert(!(io.sbuffer(i).valid && io.sbuffer(i).bits.wline && !io.sbuffer(i).bits.mask.andR))
748    io.sbuffer(i).bits := DontCare
749    io.sbuffer(i).bits.cmd   := MemoryOpConstants.M_XWR
750    io.sbuffer(i).bits.addr  := dataBuffer.io.deq(i).bits.addr
751    io.sbuffer(i).bits.vaddr := dataBuffer.io.deq(i).bits.vaddr
752    io.sbuffer(i).bits.data  := dataBuffer.io.deq(i).bits.data
753    io.sbuffer(i).bits.mask  := dataBuffer.io.deq(i).bits.mask
754    io.sbuffer(i).bits.wline := dataBuffer.io.deq(i).bits.wline
755    io.sbuffer(i).bits.prefetch := dataBuffer.io.deq(i).bits.prefetch
756
757    // io.sbuffer(i).fire is RegNexted, as sbuffer data write takes 2 cycles.
758    // Before data write finish, sbuffer is unable to provide store to load
759    // forward data. As an workaround, deqPtrExt and allocated flag update
760    // is delayed so that load can get the right data from store queue.
761    val ptr = dataBuffer.io.deq(i).bits.sqPtr.value
762    when (RegNext(io.sbuffer(i).fire)) {
763      allocated(RegEnable(ptr, io.sbuffer(i).fire)) := false.B
764      XSDebug("sbuffer "+i+" fire: ptr %d\n", ptr)
765    }
766  }
767  (1 until EnsbufferWidth).foreach(i => when(io.sbuffer(i).fire) { assert(io.sbuffer(i - 1).fire) })
768  if (coreParams.dcacheParametersOpt.isEmpty) {
769    for (i <- 0 until EnsbufferWidth) {
770      val ptr = deqPtrExt(i).value
771      val ram = DifftestMem(64L * 1024 * 1024 * 1024, 8)
772      val wen = allocated(ptr) && committed(ptr) && !mmio(ptr)
773      val waddr = ((paddrModule.io.rdata(i) - "h80000000".U) >> 3).asUInt
774      val wdata = Mux(paddrModule.io.rdata(i)(3), dataModule.io.rdata(i).data(127, 64), dataModule.io.rdata(i).data(63, 0))
775      val wmask = Mux(paddrModule.io.rdata(i)(3), dataModule.io.rdata(i).mask(15, 8), dataModule.io.rdata(i).mask(7, 0))
776      when (wen) {
777        ram.write(waddr, wdata.asTypeOf(Vec(8, UInt(8.W))), wmask.asBools)
778      }
779    }
780  }
781
782  // Read vaddr for mem exception
783  io.exceptionAddr.vaddr := vaddrModule.io.rdata(EnsbufferWidth)
784
785  // misprediction recovery / exception redirect
786  // invalidate sq term using robIdx
787  val needCancel = Wire(Vec(StoreQueueSize, Bool()))
788  for (i <- 0 until StoreQueueSize) {
789    needCancel(i) := uop(i).robIdx.needFlush(io.brqRedirect) && allocated(i) && !committed(i)
790    when (needCancel(i)) {
791      allocated(i) := false.B
792    }
793  }
794
795 /**
796* update pointers
797**/
798  val lastEnqCancel = PopCount(RegNext(VecInit(canEnqueue.zip(enqCancel).map(x => x._1 && x._2)))) // 1 cycle after redirect
799  val lastCycleCancelCount = PopCount(RegNext(needCancel)) // 1 cycle after redirect
800  val lastCycleRedirect = RegNext(io.brqRedirect.valid) // 1 cycle after redirect
801  val enqNumber = Mux(!lastCycleRedirect&&io.enq.canAccept && io.enq.lqCanAccept, PopCount(io.enq.req.map(_.valid)), 0.U) // 1 cycle after redirect
802
803  val lastlastCycleRedirect=RegNext(lastCycleRedirect)// 2 cycle after redirect
804  val redirectCancelCount = RegEnable(lastCycleCancelCount + lastEnqCancel, lastCycleRedirect) // 2 cycle after redirect
805
806  when (lastlastCycleRedirect) {
807    // we recover the pointers in 2 cycle after redirect for better timing
808    enqPtrExt := VecInit(enqPtrExt.map(_ - redirectCancelCount))
809  }.otherwise {
810    // lastCycleRedirect.valid or nornal case
811    // when lastCycleRedirect.valid, enqNumber === 0.U, enqPtrExt will not change
812    enqPtrExt := VecInit(enqPtrExt.map(_ + enqNumber))
813  }
814  assert(!(lastCycleRedirect && enqNumber =/= 0.U))
815
816  deqPtrExt := deqPtrExtNext
817  rdataPtrExt := rdataPtrExtNext
818
819  // val dequeueCount = Mux(io.sbuffer(1).fire, 2.U, Mux(io.sbuffer(0).fire || io.mmioStout.fire, 1.U, 0.U))
820
821  // If redirect at T0, sqCancelCnt is at T2
822  io.sqCancelCnt := redirectCancelCount
823  val ForceWriteUpper = Wire(UInt(log2Up(StoreQueueSize + 1).W))
824  ForceWriteUpper := Constantin.createRecord("ForceWriteUpper_"+p(XSCoreParamsKey).HartId.toString(), initValue = 60.U)
825  val ForceWriteLower = Wire(UInt(log2Up(StoreQueueSize + 1).W))
826  ForceWriteLower := Constantin.createRecord("ForceWriteLower_"+p(XSCoreParamsKey).HartId.toString(), initValue = 55.U)
827
828  val valid_cnt = PopCount(allocated)
829  io.force_write := RegNext(Mux(valid_cnt >= ForceWriteUpper, true.B, valid_cnt >= ForceWriteLower && io.force_write), init = false.B)
830
831  // io.sqempty will be used by sbuffer
832  // We delay it for 1 cycle for better timing
833  // When sbuffer need to check if it is empty, the pipeline is blocked, which means delay io.sqempty
834  // for 1 cycle will also promise that sq is empty in that cycle
835  io.sqEmpty := RegNext(
836    enqPtrExt(0).value === deqPtrExt(0).value &&
837    enqPtrExt(0).flag === deqPtrExt(0).flag
838  )
839  // perf counter
840  QueuePerf(StoreQueueSize, validCount, !allowEnqueue)
841  io.sqFull := !allowEnqueue
842  XSPerfAccumulate("mmioCycle", uncacheState =/= s_idle) // lq is busy dealing with uncache req
843  XSPerfAccumulate("mmioCnt", io.uncache.req.fire)
844  XSPerfAccumulate("mmio_wb_success", io.mmioStout.fire)
845  XSPerfAccumulate("mmio_wb_blocked", io.mmioStout.valid && !io.mmioStout.ready)
846  XSPerfAccumulate("validEntryCnt", distanceBetween(enqPtrExt(0), deqPtrExt(0)))
847  XSPerfAccumulate("cmtEntryCnt", distanceBetween(cmtPtrExt(0), deqPtrExt(0)))
848  XSPerfAccumulate("nCmtEntryCnt", distanceBetween(enqPtrExt(0), cmtPtrExt(0)))
849
850  val perfValidCount = distanceBetween(enqPtrExt(0), deqPtrExt(0))
851  val perfEvents = Seq(
852    ("mmioCycle      ", uncacheState =/= s_idle),
853    ("mmioCnt        ", io.uncache.req.fire),
854    ("mmio_wb_success", io.mmioStout.fire),
855    ("mmio_wb_blocked", io.mmioStout.valid && !io.mmioStout.ready),
856    ("stq_1_4_valid  ", (perfValidCount < (StoreQueueSize.U/4.U))),
857    ("stq_2_4_valid  ", (perfValidCount > (StoreQueueSize.U/4.U)) & (perfValidCount <= (StoreQueueSize.U/2.U))),
858    ("stq_3_4_valid  ", (perfValidCount > (StoreQueueSize.U/2.U)) & (perfValidCount <= (StoreQueueSize.U*3.U/4.U))),
859    ("stq_4_4_valid  ", (perfValidCount > (StoreQueueSize.U*3.U/4.U))),
860  )
861  generatePerfEvent()
862
863  // debug info
864  XSDebug("enqPtrExt %d:%d deqPtrExt %d:%d\n", enqPtrExt(0).flag, enqPtr, deqPtrExt(0).flag, deqPtr)
865
866  def PrintFlag(flag: Bool, name: String): Unit = {
867    when(flag) {
868      XSDebug(false, true.B, name)
869    }.otherwise {
870      XSDebug(false, true.B, " ")
871    }
872  }
873
874  for (i <- 0 until StoreQueueSize) {
875    XSDebug(i + ": pc %x va %x pa %x data %x ",
876      uop(i).pc,
877      debug_vaddr(i),
878      debug_paddr(i),
879      debug_data(i)
880    )
881    PrintFlag(allocated(i), "a")
882    PrintFlag(allocated(i) && addrvalid(i), "a")
883    PrintFlag(allocated(i) && datavalid(i), "d")
884    PrintFlag(allocated(i) && committed(i), "c")
885    PrintFlag(allocated(i) && pending(i), "p")
886    PrintFlag(allocated(i) && mmio(i), "m")
887    XSDebug(false, true.B, "\n")
888  }
889
890}
891