xref: /XiangShan/src/main/scala/xiangshan/mem/vector/VMergeBuffer.scala (revision b240e1c0b814b1d9044e4438496d374cddde66fa)
1/***************************************************************************************
2  * Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences
3  * Copyright (c) 2020-2021 Peng Cheng Laboratory
4  *
5  * XiangShan is licensed under Mulan PSL v2.
6  * You can use this software according to the terms and conditions of the Mulan PSL v2.
7  * You may obtain a copy of Mulan PSL v2 at:
8  *          http://license.coscl.org.cn/MulanPSL2
9  *
10  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13  *
14  * See the Mulan PSL v2 for more details.
15  ***************************************************************************************/
16
17package xiangshan.mem
18
19import org.chipsalliance.cde.config.Parameters
20import chisel3._
21import chisel3.util._
22import utils._
23import utility._
24import xiangshan._
25import xiangshan.backend.rob.RobPtr
26import xiangshan.backend.Bundles._
27import xiangshan.ExceptionNO._
28import xiangshan.mem._
29import xiangshan.backend.fu.FuType
30import xiangshan.backend.fu.FuConfig._
31import xiangshan.backend.datapath.NewPipelineConnect
32import freechips.rocketchip.diplomacy.BufferParams
33import xiangshan.backend.fu.vector.Bundles.VType
34
35class MBufferBundle(implicit p: Parameters) extends VLSUBundle{
36  val data             = UInt(VLEN.W)
37  val mask             = UInt(VLENB.W)
38  val flowNum          = UInt(flowIdxBits.W)
39  val exceptionVec     = ExceptionVec()
40  val uop              = new DynInst
41  // val vdOffset         = UInt(vOffsetBits.W)
42  val sourceType       = VSFQFeedbackType()
43  val flushState       = Bool()
44  val vdIdx            = UInt(3.W)
45  val elemIdx          = UInt(elemIdxBits.W) // element index
46  // for exception
47  val vstart           = UInt(elemIdxBits.W)
48  val vl               = UInt(elemIdxBits.W)
49  val vaNeedExt        = Bool()
50  val vaddr            = UInt(XLEN.W)
51  val gpaddr           = UInt(GPAddrBits.W)
52  val isForVSnonLeafPTE= Bool()
53  val fof              = Bool()
54  val vlmax            = UInt(elemIdxBits.W)
55
56  def allReady(): Bool = (flowNum === 0.U)
57}
58
59abstract class BaseVMergeBuffer(isVStore: Boolean=false)(implicit p: Parameters) extends VLSUModule{
60  val io = IO(new VMergeBufferIO(isVStore))
61
62  // freeliset: store valid entries index.
63  // +---+---+--------------+-----+-----+
64  // | 0 | 1 |      ......  | n-2 | n-1 |
65  // +---+---+--------------+-----+-----+
66  val freeList: FreeList
67  val uopSize: Int
68  val enqWidth = io.fromSplit.length
69  val deqWidth = io.uopWriteback.length
70  val pipeWidth = io.fromPipeline.length
71  lazy val fuCfg = if (isVStore) VstuCfg else VlduCfg
72
73  def EnqConnect(source: MergeBufferReq, sink: MBufferBundle) = {
74    sink.data         := source.data
75    sink.mask         := source.mask
76    sink.flowNum      := source.flowNum
77    sink.exceptionVec := ExceptionNO.selectByFu(0.U.asTypeOf(ExceptionVec()), fuCfg)
78    sink.uop          := source.uop
79    sink.sourceType   := 0.U.asTypeOf(VSFQFeedbackType())
80    sink.flushState   := false.B
81    sink.vdIdx        := source.vdIdx
82    sink.elemIdx      := Fill(elemIdxBits, 1.U)
83    sink.fof          := source.fof
84    sink.vlmax        := source.vlmax
85    sink.vl           := source.uop.vpu.vl
86    sink.vaddr        := source.vaddr
87    sink.vstart       := 0.U
88  }
89  def DeqConnect(source: MBufferBundle): MemExuOutput = {
90    val sink               = WireInit(0.U.asTypeOf(new MemExuOutput(isVector = true)))
91    sink.data             := source.data
92    sink.mask.get         := source.mask
93    sink.uop              := source.uop
94    sink.uop.exceptionVec := ExceptionNO.selectByFu(source.exceptionVec, fuCfg)
95    sink.uop.vpu.vmask    := source.mask
96    sink.debug            := 0.U.asTypeOf(new DebugBundle)
97    sink.vdIdxInField.get := source.vdIdx // Mgu needs to use this.
98    sink.vdIdx.get        := source.vdIdx
99    sink.uop.vpu.vstart   := source.vstart
100    sink.uop.vpu.vl       := source.vl
101    sink
102  }
103  def ToLsqConnect(source: MBufferBundle): FeedbackToLsqIO = {
104    val sink                                 = WireInit(0.U.asTypeOf(new FeedbackToLsqIO))
105    val hasExp                               = ExceptionNO.selectByFu(source.exceptionVec, fuCfg).asUInt.orR
106    sink.robidx                             := source.uop.robIdx
107    sink.uopidx                             := source.uop.uopIdx
108    sink.feedback(VecFeedbacks.COMMIT)      := !hasExp
109    sink.feedback(VecFeedbacks.FLUSH)       := hasExp
110    sink.feedback(VecFeedbacks.LAST)        := true.B
111    sink.vstart                             := source.vstart // TODO: if lsq need vl for fof?
112    sink.vaddr                              := source.vaddr
113    sink.vaNeedExt                          := source.vaNeedExt
114    sink.gpaddr                             := source.gpaddr
115    sink.isForVSnonLeafPTE                  := source.isForVSnonLeafPTE
116    sink.vl                                 := source.vl
117    sink.exceptionVec                       := ExceptionNO.selectByFu(source.exceptionVec, fuCfg)
118    sink
119  }
120
121
122  val entries      = Reg(Vec(uopSize, new MBufferBundle))
123  val needCancel   = WireInit(VecInit(Seq.fill(uopSize)(false.B)))
124  val allocated    = RegInit(VecInit(Seq.fill(uopSize)(false.B)))
125  val freeMaskVec  = WireInit(VecInit(Seq.fill(uopSize)(false.B)))
126  val uopFinish    = RegInit(VecInit(Seq.fill(uopSize)(false.B)))
127  val needRSReplay = RegInit(VecInit(Seq.fill(uopSize)(false.B)))
128  // enq, from splitPipeline
129  // val allowEnqueue =
130  val cancelEnq    = io.fromSplit.map(_.req.bits.uop.robIdx.needFlush(io.redirect))
131  val canEnqueue   = io.fromSplit.map(_.req.valid)
132  val needEnqueue  = (0 until enqWidth).map{i =>
133    canEnqueue(i) && !cancelEnq(i)
134  }
135
136  val freeCount    = uopSize.U - freeList.io.validCount
137
138  for ((enq, i) <- io.fromSplit.zipWithIndex){
139    freeList.io.doAllocate(i) := false.B
140
141    freeList.io.allocateReq(i) := true.B
142
143    val offset    = PopCount(needEnqueue.take(i))
144    val canAccept = freeList.io.canAllocate(offset)
145    val enqIndex  = freeList.io.allocateSlot(offset)
146    enq.req.ready := freeCount >= (i + 1).U // for better timing
147
148    when(needEnqueue(i) && enq.req.ready){
149      freeList.io.doAllocate(i) := true.B
150      // enqueue
151      allocated(enqIndex)       := true.B
152      uopFinish(enqIndex)       := false.B
153      needRSReplay(enqIndex)    := false.B
154
155      EnqConnect(enq.req.bits, entries(enqIndex))// initial entry
156    }
157
158    enq.resp.bits.mBIndex := enqIndex
159    enq.resp.bits.fail    := false.B
160    enq.resp.valid        := freeCount >= (i + 1).U // for better timing
161  }
162
163  //redirect
164  for (i <- 0 until uopSize){
165    needCancel(i) := entries(i).uop.robIdx.needFlush(io.redirect) && allocated(i)
166    when (needCancel(i)) {
167      allocated(i)   := false.B
168      freeMaskVec(i) := true.B
169      uopFinish(i)   := false.B
170      needRSReplay(i):= false.B
171    }
172  }
173  freeList.io.free := freeMaskVec.asUInt
174  //pipelineWriteback
175  // handle the situation where multiple ports are going to write the same uop queue entry
176  // select the oldest exception and count the flownum of the pipeline writeback.
177  val mergePortMatrix        = Wire(Vec(pipeWidth, Vec(pipeWidth, Bool())))
178  val mergedByPrevPortVec    = Wire(Vec(pipeWidth, Bool()))
179  (0 until pipeWidth).map{case i => (0 until pipeWidth).map{case j =>
180    mergePortMatrix(i)(j) := (j == i).B ||
181      (j > i).B &&
182      io.fromPipeline(j).bits.mBIndex === io.fromPipeline(i).bits.mBIndex &&
183      io.fromPipeline(j).valid
184  }}
185  (0 until pipeWidth).map{case i =>
186    mergedByPrevPortVec(i) := (i != 0).B && Cat((0 until i).map(j =>
187      io.fromPipeline(j).bits.mBIndex === io.fromPipeline(i).bits.mBIndex &&
188      io.fromPipeline(j).valid)).orR
189  }
190
191  if (backendParams.debugEn){
192    dontTouch(mergePortMatrix)
193    dontTouch(mergedByPrevPortVec)
194  }
195
196  // for exception, select exception, when multi port writeback exception, we need select oldest one
197  def selectOldest[T <: VecPipelineFeedbackIO](valid: Seq[Bool], bits: Seq[T], sel: Seq[UInt]): (Seq[Bool], Seq[T], Seq[UInt]) = {
198    assert(valid.length == bits.length)
199    assert(valid.length == sel.length)
200    if (valid.length == 0 || valid.length == 1) {
201      (valid, bits, sel)
202    } else if (valid.length == 2) {
203      val res = Seq.fill(2)(Wire(ValidIO(chiselTypeOf(bits(0)))))
204      for (i <- res.indices) {
205        res(i).valid := valid(i)
206        res(i).bits := bits(i)
207      }
208      val oldest = Mux(valid(0) && valid(1),
209        Mux(sel(0) < sel(1),
210            res(0), res(1)),
211        Mux(valid(0) && !valid(1), res(0), res(1)))
212
213      val oldidx = Mux(valid(0) && valid(1),
214        Mux(sel(0) < sel(1),
215          sel(0), sel(1)),
216        Mux(valid(0) && !valid(1), sel(0), sel(1)))
217      (Seq(oldest.valid), Seq(oldest.bits), Seq(oldidx))
218    } else {
219      val left  = selectOldest(valid.take(valid.length / 2), bits.take(bits.length / 2), sel.take(sel.length / 2))
220      val right = selectOldest(valid.takeRight(valid.length - (valid.length / 2)), bits.takeRight(bits.length - (bits.length / 2)), sel.takeRight(sel.length - (sel.length / 2)))
221      selectOldest(left._1 ++ right._1, left._2 ++ right._2, left._3 ++ right._3)
222    }
223  }
224
225  val pipeValid        = io.fromPipeline.map(_.valid)
226  val pipeBits         = io.fromPipeline.map(_.bits)
227  val wbElemIdx        = pipeBits.map(_.elemIdx)
228  val wbMbIndex        = pipeBits.map(_.mBIndex)
229  val wbElemIdxInField = wbElemIdx.zip(wbMbIndex).map(x => x._1 & (entries(x._2).vlmax - 1.U))
230
231  val portHasExcp       = pipeBits.zip(mergePortMatrix).map{case (port, v) =>
232    (0 until pipeWidth).map{case i =>
233      val pipeHasExcep = ExceptionNO.selectByFu(port.exceptionVec, fuCfg).asUInt.orR
234      (v(i) && ((pipeHasExcep && io.fromPipeline(i).bits.mask.orR) || TriggerAction.isDmode(port.trigger))) // this port have exception or merged port have exception
235    }.reduce(_ || _)
236  }
237
238  for((pipewb, i) <- io.fromPipeline.zipWithIndex){
239    val entry               = entries(wbMbIndex(i))
240    val entryVeew           = entry.uop.vpu.veew
241    val entryIsUS           = LSUOpType.isAllUS(entry.uop.fuOpType)
242    val entryHasException   = ExceptionNO.selectByFu(entry.exceptionVec, fuCfg).asUInt.orR
243    val entryExcp           = entryHasException && entry.mask.orR
244    val entryVaddr          = entry.vaddr
245    val entryVstart         = entry.vstart
246    val entryElemIdx        = entry.elemIdx
247
248    val sel                    = selectOldest(mergePortMatrix(i), pipeBits, wbElemIdxInField)
249    val selPort                = sel._2
250    val selElemInfield         = selPort(0).elemIdx & (entries(wbMbIndex(i)).vlmax - 1.U)
251    val selExceptionVec        = selPort(0).exceptionVec
252    val selVaddr               = selPort(0).vaddr
253    val selElemIdx             = selPort(0).elemIdx
254
255    val isUSFirstUop           = !selPort(0).elemIdx.orR
256    // Only the first unaligned uop of unit-stride needs to be offset.
257    // When unaligned, the lowest bit of mask is 0.
258    //  example: 16'b1111_1111_1111_0000
259    val firstUnmask            = genVFirstUnmask(selPort(0).mask).asUInt
260    val vaddrOffset            = Mux(entryIsUS, firstUnmask, 0.U)
261    val vaddr                  = selVaddr + vaddrOffset
262    val vstart                 = Mux(entryIsUS, selPort(0).vstart, selElemInfield)
263
264    // select oldest port to raise exception
265    when((((entryElemIdx >= selElemIdx) && entryExcp && portHasExcp(i)) || (!entryExcp && portHasExcp(i))) && pipewb.valid && !mergedByPrevPortVec(i)) {
266      entry.uop.trigger     := selPort(0).trigger
267      entry.elemIdx         := selElemIdx
268      when(!entry.fof || vstart === 0.U){
269        // For fof loads, if element 0 raises an exception, vl is not modified, and the trap is taken.
270        entry.vstart       := vstart
271        entry.exceptionVec := ExceptionNO.selectByFu(selExceptionVec, fuCfg)
272        entry.vaddr        := vaddr
273        entry.vaNeedExt    := selPort(0).vaNeedExt
274        entry.gpaddr       := selPort(0).gpaddr
275        entry.isForVSnonLeafPTE := selPort(0).isForVSnonLeafPTE
276      }.otherwise{
277        entry.uop.vpu.vta  := VType.tu
278        entry.vl           := Mux(entry.vl < vstart, entry.vl, vstart)
279      }
280    }
281  }
282
283  // for pipeline writeback
284  for((pipewb, i) <- io.fromPipeline.zipWithIndex){
285    val wbIndex          = pipewb.bits.mBIndex
286    val flowNumOffset    = Mux(pipewb.bits.usSecondInv,
287                               2.U,
288                               PopCount(mergePortMatrix(i)))
289    val sourceTypeNext   = entries(wbIndex).sourceType | pipewb.bits.sourceType
290    val hasExp           = ExceptionNO.selectByFu(pipewb.bits.exceptionVec, fuCfg).asUInt.orR
291
292    // if is VLoad, need latch 1 cycle to merge data. only flowNum and wbIndex need to latch
293    val latchWbValid     = if(isVStore) pipewb.valid else RegNext(pipewb.valid)
294    val latchWbIndex     = if(isVStore) wbIndex      else RegEnable(wbIndex, pipewb.valid)
295    val latchFlowNum     = if(isVStore) flowNumOffset else RegEnable(flowNumOffset, pipewb.valid)
296    val latchMergeByPre  = if(isVStore) mergedByPrevPortVec(i) else RegEnable(mergedByPrevPortVec(i), pipewb.valid)
297    when(latchWbValid && !latchMergeByPre){
298      entries(latchWbIndex).flowNum := entries(latchWbIndex).flowNum - latchFlowNum
299    }
300
301    when(pipewb.valid){
302      entries(wbIndex).sourceType   := sourceTypeNext
303      entries(wbIndex).flushState   := pipewb.bits.flushState
304    }
305    when(pipewb.valid && !pipewb.bits.hit){
306      needRSReplay(wbIndex) := true.B
307    }
308    pipewb.ready := true.B
309    XSError((entries(latchWbIndex).flowNum - latchFlowNum > entries(latchWbIndex).flowNum) && latchWbValid && !latchMergeByPre, s"entry: $latchWbIndex, FlowWriteback overflow!!\n")
310    XSError(!allocated(latchWbIndex) && latchWbValid, s"entry: $latchWbIndex, Writeback error flow!!\n")
311  }
312  // for inorder mem asscess
313  io.toSplit := DontCare
314
315  //uopwriteback(deq)
316  for (i <- 0 until uopSize){
317    when(allocated(i) && entries(i).allReady() && !needCancel(i)){
318      uopFinish(i) := true.B
319    }
320  }
321   val selPolicy = SelectOne("circ", uopFinish, deqWidth) // select one entry to deq
322   private val pipelineOut              = Wire(Vec(deqWidth, DecoupledIO(new MemExuOutput(isVector = true))))
323   private val writeBackOut             = Wire(Vec(deqWidth, DecoupledIO(new MemExuOutput(isVector = true))))
324   private val writeBackOutExceptionVec = writeBackOut.map(_.bits.uop.exceptionVec)
325   for(((port, lsqport), i) <- (pipelineOut zip io.toLsq).zipWithIndex){
326    val canGo    = port.ready
327    val (selValid, selOHVec) = selPolicy.getNthOH(i + 1)
328    val entryIdx = OHToUInt(selOHVec)
329    val selEntry = entries(entryIdx)
330    val selAllocated = allocated(entryIdx)
331    val selFire  = selValid && canGo
332    when(selFire){
333      freeMaskVec(entryIdx) := selAllocated
334      allocated(entryIdx)   := false.B
335      uopFinish(entryIdx)   := false.B
336      needRSReplay(entryIdx):= false.B
337    }
338    //writeback connect
339    port.valid   := selFire && selAllocated && !needRSReplay(entryIdx) && !selEntry.uop.robIdx.needFlush(io.redirect)
340    port.bits    := DeqConnect(selEntry)
341    //to lsq
342    lsqport.bits := ToLsqConnect(selEntry) // when uopwriteback, free MBuffer entry, write to lsq
343    lsqport.valid:= selFire && selAllocated && !needRSReplay(entryIdx)
344    //to RS
345    val feedbackOut                       = WireInit(0.U.asTypeOf(io.feedback(i).bits)).suggestName(s"feedbackOut_${i}")
346    val feedbackValid                     = selFire && selAllocated
347    feedbackOut.hit                      := !needRSReplay(entryIdx)
348    feedbackOut.robIdx                   := selEntry.uop.robIdx
349    feedbackOut.sourceType               := selEntry.sourceType
350    feedbackOut.flushState               := selEntry.flushState
351    feedbackOut.dataInvalidSqIdx         := DontCare
352    feedbackOut.sqIdx                    := selEntry.uop.sqIdx
353    feedbackOut.lqIdx                    := selEntry.uop.lqIdx
354
355    io.feedback(i).valid                 := RegNext(feedbackValid)
356    io.feedback(i).bits                  := RegEnable(feedbackOut, feedbackValid)
357
358    NewPipelineConnect(
359      port, writeBackOut(i), writeBackOut(i).fire,
360      Mux(port.fire,
361        selEntry.uop.robIdx.needFlush(io.redirect),
362        writeBackOut(i).bits.uop.robIdx.needFlush(io.redirect)),
363      Option(s"VMergebufferPipelineConnect${i}")
364    )
365     io.uopWriteback(i)                  <> writeBackOut(i)
366     io.uopWriteback(i).bits.uop.exceptionVec := ExceptionNO.selectByFu(writeBackOutExceptionVec(i), fuCfg)
367   }
368
369  QueuePerf(uopSize, freeList.io.validCount, freeList.io.validCount === 0.U)
370}
371
372class VLMergeBufferImp(implicit p: Parameters) extends BaseVMergeBuffer(isVStore=false){
373  override lazy val uopSize = VlMergeBufferSize
374  println(s"VLMergeBuffer Size: ${VlMergeBufferSize}")
375  override lazy val freeList = Module(new FreeList(
376    size = uopSize,
377    allocWidth = VecLoadPipelineWidth,
378    freeWidth = deqWidth,
379    enablePreAlloc = false,
380    moduleName = "VLoad MergeBuffer freelist"
381  ))
382
383  //merge data
384  val flowWbElemIdx     = Wire(Vec(pipeWidth, UInt(elemIdxBits.W)))
385  val flowWbElemIdxInVd = Wire(Vec(pipeWidth, UInt(elemIdxBits.W)))
386  val pipewbValidReg    = Wire(Vec(pipeWidth, Bool()))
387  val wbIndexReg        = Wire(Vec(pipeWidth, UInt(vlmBindexBits.W)))
388  val mergeDataReg      = Wire(Vec(pipeWidth, UInt(VLEN.W)))
389
390  val maskWithexceptionMask = io.fromPipeline.map{ x=>
391    Mux(
392      TriggerAction.isExp(x.bits.trigger) || TriggerAction.isDmode(x.bits.trigger),
393      ~x.bits.vecTriggerMask,
394      Fill(x.bits.mask.getWidth, !ExceptionNO.selectByFuAndUnSelect(x.bits.exceptionVec, fuCfg, Seq(breakPoint)).asUInt.orR)
395    ).asUInt & x.bits.mask
396  }
397
398  for((pipewb, i) <- io.fromPipeline.zipWithIndex){
399    /** step0 **/
400    val wbIndex = pipewb.bits.mBIndex
401    val alignedType = pipewb.bits.alignedType
402    val elemIdxInsideVd = pipewb.bits.elemIdxInsideVd
403    flowWbElemIdx(i) := pipewb.bits.elemIdx
404    flowWbElemIdxInVd(i) := elemIdxInsideVd.get
405
406    val oldData = PriorityMux(Seq(
407      (pipewbValidReg(0) && (wbIndexReg(0) === wbIndex)) -> mergeDataReg(0),
408      (pipewbValidReg(1) && (wbIndexReg(1) === wbIndex)) -> mergeDataReg(1),
409      (pipewbValidReg(2) && (wbIndexReg(2) === wbIndex)) -> mergeDataReg(2),
410      true.B                                             -> entries(wbIndex).data // default use entries_data
411    ))
412    val mergedData = mergeDataWithElemIdx(
413      oldData = oldData,
414      newData = io.fromPipeline.map(_.bits.vecdata.get),
415      alignedType = alignedType(1,0),
416      elemIdx = flowWbElemIdxInVd,
417      valids = mergePortMatrix(i)
418    )
419    /* this only for unit-stride load data merge
420     * cycle0: broden 128-bits to 256-bits (max 6 to 1)
421     * cycle1: select 128-bits data from 256-bits (16 to 1)
422     */
423    val (brodenMergeData, brodenMergeMask)     = mergeDataByIndex(
424      data    = io.fromPipeline.map(_.bits.vecdata.get).drop(i),
425      mask    = maskWithexceptionMask.drop(i),
426      index   = io.fromPipeline(i).bits.elemIdxInsideVd.get,
427      valids  = mergePortMatrix(i).drop(i)
428    )
429    /** step1 **/
430    pipewbValidReg(i)      := RegNext(pipewb.valid)
431    wbIndexReg(i)          := RegEnable(wbIndex, pipewb.valid)
432    mergeDataReg(i)        := RegEnable(mergedData, pipewb.valid) // for not Unit-stride
433    val brodenMergeDataReg  = RegEnable(brodenMergeData, pipewb.valid) // only for Unit-stride
434    val brodenMergeMaskReg  = RegEnable(brodenMergeMask, pipewb.valid)
435    val mergedByPrevPortReg = RegEnable(mergedByPrevPortVec(i), pipewb.valid)
436    val regOffsetReg        = RegEnable(pipewb.bits.reg_offset.get, pipewb.valid) // only for Unit-stride
437    val isusMerge           = RegEnable(alignedType(2), pipewb.valid)
438
439    val usSelData           = Mux1H(UIntToOH(regOffsetReg), (0 until VLENB).map{case i => getNoAlignedSlice(brodenMergeDataReg, i, 128)})
440    val usSelMask           = Mux1H(UIntToOH(regOffsetReg), (0 until VLENB).map{case i => brodenMergeMaskReg(16 + i - 1, i)})
441    val usMergeData         = mergeDataByByte(entries(wbIndexReg(i)).data, usSelData, usSelMask)
442    when(pipewbValidReg(i) && !mergedByPrevPortReg){
443      entries(wbIndexReg(i)).data := Mux(isusMerge, usMergeData, mergeDataReg(i)) // if aligned(2) == 1, is Unit-Stride inst
444    }
445  }
446}
447
448class VSMergeBufferImp(implicit p: Parameters) extends BaseVMergeBuffer(isVStore=true){
449  override lazy val uopSize = VsMergeBufferSize
450  println(s"VSMergeBuffer Size: ${VsMergeBufferSize}")
451  override lazy val freeList = Module(new FreeList(
452    size = uopSize,
453    allocWidth = VecStorePipelineWidth,
454    freeWidth = deqWidth,
455    enablePreAlloc = false,
456    moduleName = "VStore MergeBuffer freelist"
457  ))
458  override def DeqConnect(source: MBufferBundle): MemExuOutput = {
459    val sink               = Wire(new MemExuOutput(isVector = true))
460    sink.data             := DontCare
461    sink.mask.get         := DontCare
462    sink.uop              := source.uop
463    sink.uop.exceptionVec := source.exceptionVec
464    sink.debug            := 0.U.asTypeOf(new DebugBundle)
465    sink.vdIdxInField.get := DontCare
466    sink.vdIdx.get        := DontCare
467    sink.isFromLoadUnit   := DontCare
468    sink.uop.vpu.vstart   := source.vstart
469    sink
470  }
471
472  // from misalignBuffer flush
473  when(io.fromMisalignBuffer.get.flush){
474    needRSReplay(io.fromMisalignBuffer.get.mbIndex) := true.B
475  }
476}
477