xref: /XiangShan/src/main/scala/xiangshan/mem/vector/VecCommon.scala (revision b1e920234888fd3e5463ceb2a99c9bdca087f585)
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._
27
28/**
29  * Common used parameters or functions in vlsu
30  */
31trait VLSUConstants {
32  val VLEN = 128
33  def VLENB = VLEN/8
34  def vOffsetBits = log2Up(VLENB) // bits-width to index offset inside a vector reg
35
36  def alignTypes = 4 // eew/sew = 1/2/4/8
37  def alignTypeBits = log2Up(alignTypes)
38  def maxMUL = 8
39  def maxFields = 8
40  /**
41    * In the most extreme cases like a segment indexed instruction, eew=64, emul=8, sew=8, lmul=1,
42    * and nf=8, each data reg is mapped with 8 index regs and there are 8 data regs in total,
43    * each for a field. Therefore an instruction can be divided into 64 uops at most.
44    */
45  def maxUopNum = maxMUL * maxFields // 64
46  def maxFlowNum = 16
47  def maxElemNum = maxMUL * maxFlowNum // 128
48  // def uopIdxBits = log2Up(maxUopNum) // to index uop inside an robIdx
49  def elemIdxBits = log2Up(maxElemNum) + 1 // to index which element in an instruction
50  def flowIdxBits = log2Up(maxFlowNum) + 1 // to index which flow in a uop
51  def fieldBits = log2Up(maxFields) + 1 // 4-bits to indicate 1~8
52
53  def ewBits = 3 // bits-width of EEW/SEW
54  def mulBits = 3 // bits-width of emul/lmul
55
56  def getSlice(data: UInt, i: Int, alignBits: Int): UInt = {
57    require(data.getWidth >= (i+1) * alignBits)
58    data((i+1) * alignBits - 1, i * alignBits)
59  }
60
61  def getByte(data: UInt, i: Int = 0) = getSlice(data, i, 8)
62  def getHalfWord(data: UInt, i: Int = 0) = getSlice(data, i, 16)
63  def getWord(data: UInt, i: Int = 0) = getSlice(data, i, 32)
64  def getDoubleWord(data: UInt, i: Int = 0) = getSlice(data, i, 64)
65}
66
67trait HasVLSUParameters extends HasXSParameter with VLSUConstants {
68  override val VLEN = coreParams.VLEN
69  def isUnitStride(instType: UInt) = instType(1, 0) === "b00".U
70  def isStrided(instType: UInt) = instType(1, 0) === "b10".U
71  def isIndexed(instType: UInt) = instType(0) === "b1".U
72  def isNotIndexed(instType: UInt) = instType(0) === "b0".U
73  def isSegment(instType: UInt) = instType(2) === "b1".U
74
75  def mergeDataWithMask(oldData: UInt, newData: UInt, mask: UInt): Vec[UInt] = {
76    require(oldData.getWidth == newData.getWidth)
77    require(oldData.getWidth == mask.getWidth * 8)
78    VecInit(mask.asBools.zipWithIndex.map { case (en, i) =>
79      Mux(en, getByte(newData, i), getByte(oldData, i))
80    })
81  }
82
83  // def asBytes(data: UInt) = {
84  //   require(data.getWidth % 8 == 0)
85  //   (0 until data.getWidth/8).map(i => getByte(data, i))
86  // }
87
88  def mergeDataWithElemIdx(
89    oldData: UInt,
90    newData: Seq[UInt],
91    alignedType: UInt,
92    elemIdx: Seq[UInt],
93    valids: Seq[Bool]
94  ): UInt = {
95    require(newData.length == elemIdx.length)
96    require(newData.length == valids.length)
97    LookupTree(alignedType, List(
98      "b00".U -> VecInit(elemIdx.map(e => UIntToOH(e(3, 0)).asBools).transpose.zipWithIndex.map { case (selVec, i) =>
99        ParallelPosteriorityMux(
100          true.B +: selVec.zip(valids).map(x => x._1 && x._2),
101          getByte(oldData, i) +: newData.map(getByte(_))
102        )}).asUInt,
103      "b01".U -> VecInit(elemIdx.map(e => UIntToOH(e(2, 0)).asBools).transpose.zipWithIndex.map { case (selVec, i) =>
104        ParallelPosteriorityMux(
105          true.B +: selVec.zip(valids).map(x => x._1 && x._2),
106          getHalfWord(oldData, i) +: newData.map(getHalfWord(_))
107        )}).asUInt,
108      "b10".U -> VecInit(elemIdx.map(e => UIntToOH(e(1, 0)).asBools).transpose.zipWithIndex.map { case (selVec, i) =>
109        ParallelPosteriorityMux(
110          true.B +: selVec.zip(valids).map(x => x._1 && x._2),
111          getWord(oldData, i) +: newData.map(getWord(_))
112        )}).asUInt,
113      "b11".U -> VecInit(elemIdx.map(e => UIntToOH(e(0)).asBools).transpose.zipWithIndex.map { case (selVec, i) =>
114        ParallelPosteriorityMux(
115          true.B +: selVec.zip(valids).map(x => x._1 && x._2),
116          getDoubleWord(oldData, i) +: newData.map(getDoubleWord(_))
117        )}).asUInt
118    ))
119  }
120
121  def mergeDataWithElemIdx(oldData: UInt, newData: UInt, alignedType: UInt, elemIdx: UInt): UInt = {
122    mergeDataWithElemIdx(oldData, Seq(newData), alignedType, Seq(elemIdx), Seq(true.B))
123  }
124}
125abstract class VLSUModule(implicit p: Parameters) extends XSModule
126  with HasVLSUParameters
127  with HasCircularQueuePtrHelper
128abstract class VLSUBundle(implicit p: Parameters) extends XSBundle
129  with HasVLSUParameters
130
131class VLSUBundleWithMicroOp(implicit p: Parameters) extends VLSUBundle {
132  val uop = new DynInst
133}
134
135class OnlyVecExuOutput(implicit p: Parameters) extends VLSUBundle {
136  val isvec = Bool()
137  val vecdata = UInt(VLEN.W)
138  val mask = UInt(VLENB.W)
139  // val rob_idx_valid = Vec(2, Bool())
140  // val inner_idx = Vec(2, UInt(3.W))
141  // val rob_idx = Vec(2, new RobPtr)
142  // val offset = Vec(2, UInt(4.W))
143  val reg_offset = UInt(vOffsetBits.W)
144  val exp = Bool()
145  val is_first_ele = Bool()
146  val elemIdx = UInt(elemIdxBits.W) // element index
147  val elemIdxInsideVd = UInt(elemIdxBits.W) // element index in scope of vd
148  val uopQueuePtr = new VluopPtr
149  val flowPtr = new VlflowPtr
150}
151
152class VecExuOutput(implicit p: Parameters) extends MemExuOutput with HasVLSUParameters {
153  val vec = new OnlyVecExuOutput
154}
155
156class VecStoreExuOutput(implicit p: Parameters) extends MemExuOutput with HasVLSUParameters {
157  val elemIdx = UInt(elemIdxBits.W)
158  val uopQueuePtr = new VsUopPtr
159}
160
161class VecUopBundle(implicit p: Parameters) extends VLSUBundleWithMicroOp {
162  val flowMask       = UInt(VLENB.W) // each bit for a flow
163  val byteMask       = UInt(VLENB.W) // each bit for a byte
164  val data           = UInt(VLEN.W)
165  // val fof            = Bool() // fof is only used for vector loads
166  val excp_eew_index = UInt(elemIdxBits.W)
167  // val exceptionVec   = ExceptionVec() // uop has exceptionVec
168  val baseAddr = UInt(VAddrBits.W)
169  val stride = UInt(VLEN.W)
170  val flow_counter = UInt(flowIdxBits.W)
171
172  // instruction decode result
173  val flowNum = UInt(flowIdxBits.W) // # of flows in a uop
174  // val flowNumLog2 = UInt(log2Up(flowIdxBits).W) // log2(flowNum), for better timing of multiplication
175  val nfields = UInt(fieldBits.W) // NFIELDS
176  val vm = Bool() // whether vector masking is enabled
177  val usWholeReg = Bool() // unit-stride, whole register load
178  val usMaskReg = Bool() // unit-stride, masked store/load
179  val eew = UInt(ewBits.W) // size of memory elements
180  val sew = UInt(ewBits.W)
181  val emul = UInt(mulBits.W)
182  val lmul = UInt(mulBits.W)
183  val vlmax = UInt(elemIdxBits.W)
184  val instType = UInt(3.W)
185  val vd_last_uop = Bool()
186  val vd_first_uop = Bool()
187}
188
189class VecFlowBundle(implicit p: Parameters) extends VLSUBundleWithMicroOp {
190  val vaddr             = UInt(VAddrBits.W)
191  val mask              = UInt(VLENB.W)
192  val alignedType       = UInt(alignTypeBits.W)
193  val exp               = Bool()
194  val elemIdx           = UInt(elemIdxBits.W)
195  val is_first_ele      = Bool()
196}
197
198object MulNum {
199  def apply (mul: UInt): UInt = { //mul means emul or lmul
200    (LookupTree(mul,List(
201      "b101".U -> 1.U , // 1/8
202      "b110".U -> 1.U , // 1/4
203      "b111".U -> 1.U , // 1/2
204      "b000".U -> 1.U , // 1
205      "b001".U -> 2.U , // 2
206      "b010".U -> 4.U , // 4
207      "b011".U -> 8.U   // 8
208    )))}
209}
210/**
211  * when emul is greater than or equal to 1, this means the entire register needs to be written;
212  * otherwise, only write the specified number of bytes */
213object MulDataSize {
214  def apply (mul: UInt): UInt = { //mul means emul or lmul
215    (LookupTree(mul,List(
216      "b101".U -> 2.U  , // 1/8
217      "b110".U -> 4.U  , // 1/4
218      "b111".U -> 8.U  , // 1/2
219      "b000".U -> 16.U , // 1
220      "b001".U -> 16.U , // 2
221      "b010".U -> 16.U , // 4
222      "b011".U -> 16.U   // 8
223    )))}
224}
225
226object OneRegNum {
227  def apply (eew: UInt): UInt = { //mul means emul or lmul
228    (LookupTree(eew,List(
229      "b000".U -> 16.U , // 1
230      "b101".U -> 8.U , // 2
231      "b110".U -> 4.U , // 4
232      "b111".U -> 2.U   // 8
233    )))}
234}
235
236//index inst read data byte
237object SewDataSize {
238  def apply (sew: UInt): UInt = {
239    (LookupTree(sew,List(
240      "b000".U -> 1.U , // 1
241      "b001".U -> 2.U , // 2
242      "b010".U -> 4.U , // 4
243      "b011".U -> 8.U   // 8
244    )))}
245}
246
247// strided inst read data byte
248object EewDataSize {
249  def apply (eew: UInt): UInt = {
250    (LookupTree(eew,List(
251      "b000".U -> 1.U , // 1
252      "b101".U -> 2.U , // 2
253      "b110".U -> 4.U , // 4
254      "b111".U -> 8.U   // 8
255    )))}
256}
257
258object loadDataSize {
259  def apply (instType: UInt, emul: UInt, eew: UInt, sew: UInt): UInt = {
260    (LookupTree(instType,List(
261      "b000".U ->  MulDataSize(emul), // unit-stride
262      "b010".U ->  EewDataSize(eew)  , // strided
263      "b001".U ->  SewDataSize(sew)  , // indexed-unordered
264      "b011".U ->  SewDataSize(sew)  , // indexed-ordered
265      "b100".U ->  EewDataSize(eew)  , // segment unit-stride
266      "b110".U ->  EewDataSize(eew)  , // segment strided
267      "b101".U ->  SewDataSize(sew)  , // segment indexed-unordered
268      "b111".U ->  SewDataSize(sew)    // segment indexed-ordered
269    )))}
270}
271
272object storeDataSize {
273  def apply (instType: UInt, eew: UInt, sew: UInt): UInt = {
274    (LookupTree(instType,List(
275      "b000".U ->  EewDataSize(eew)  , // unit-stride, do not use
276      "b010".U ->  EewDataSize(eew)  , // strided
277      "b001".U ->  SewDataSize(sew)  , // indexed-unordered
278      "b011".U ->  SewDataSize(sew)  , // indexed-ordered
279      "b100".U ->  EewDataSize(eew)  , // segment unit-stride
280      "b110".U ->  EewDataSize(eew)  , // segment strided
281      "b101".U ->  SewDataSize(sew)  , // segment indexed-unordered
282      "b111".U ->  SewDataSize(sew)    // segment indexed-ordered
283    )))}
284}
285
286object GenVecStoreMask {
287  def apply (instType: UInt, eew: UInt, sew: UInt): UInt = {
288    val mask = Wire(UInt(16.W))
289    mask := UIntToOH(storeDataSize(instType = instType, eew = eew, sew = sew)) - 1.U
290    mask
291  }
292}
293
294/**
295  * these are used to obtain immediate addresses for  index instruction */
296object EewEq8 {
297  def apply(index:UInt, flow_inner_idx: UInt): UInt = {
298    (LookupTree(flow_inner_idx,List(
299      0.U  -> index(7 ,0   ),
300      1.U  -> index(15,8   ),
301      2.U  -> index(23,16  ),
302      3.U  -> index(31,24  ),
303      4.U  -> index(39,32  ),
304      5.U  -> index(47,40  ),
305      6.U  -> index(55,48  ),
306      7.U  -> index(63,56  ),
307      8.U  -> index(71,64  ),
308      9.U  -> index(79,72  ),
309      10.U -> index(87,80  ),
310      11.U -> index(95,88  ),
311      12.U -> index(103,96 ),
312      13.U -> index(111,104),
313      14.U -> index(119,112),
314      15.U -> index(127,120)
315    )))}
316}
317
318object EewEq16 {
319  def apply(index: UInt, flow_inner_idx: UInt): UInt = {
320    (LookupTree(flow_inner_idx, List(
321      0.U -> index(15, 0),
322      1.U -> index(31, 16),
323      2.U -> index(47, 32),
324      3.U -> index(63, 48),
325      4.U -> index(79, 64),
326      5.U -> index(95, 80),
327      6.U -> index(111, 96),
328      7.U -> index(127, 112)
329    )))}
330}
331
332object EewEq32 {
333  def apply(index: UInt, flow_inner_idx: UInt): UInt = {
334    (LookupTree(flow_inner_idx, List(
335      0.U -> index(31, 0),
336      1.U -> index(63, 32),
337      2.U -> index(95, 64),
338      3.U -> index(127, 96)
339    )))}
340}
341
342object EewEq64 {
343  def apply (index: UInt, flow_inner_idx: UInt): UInt = {
344    (LookupTree(flow_inner_idx, List(
345      0.U -> index(63, 0),
346      1.U -> index(127, 64)
347    )))}
348}
349
350object IndexAddr {
351  def apply (index: UInt, flow_inner_idx: UInt, eew: UInt): UInt = {
352    (LookupTree(eew,List(
353      "b000".U -> EewEq8 (index = index, flow_inner_idx = flow_inner_idx ), // Imm is 1 Byte // TODO: index maybe cross register
354      "b101".U -> EewEq16(index = index, flow_inner_idx = flow_inner_idx ), // Imm is 2 Byte
355      "b110".U -> EewEq32(index = index, flow_inner_idx = flow_inner_idx ), // Imm is 4 Byte
356      "b111".U -> EewEq64(index = index, flow_inner_idx = flow_inner_idx )  // Imm is 8 Byte
357    )))}
358}
359
360object Log2Num {
361  def apply (num: UInt): UInt = {
362    (LookupTree(num,List(
363      16.U -> 4.U,
364      8.U  -> 3.U,
365      4.U  -> 2.U,
366      2.U  -> 1.U,
367      1.U  -> 0.U
368    )))}
369}
370
371object GenUopIdxInField {
372  def apply (instType: UInt, emul: UInt, lmul: UInt, uopIdx: UInt): UInt = {
373    val isIndexed = instType(0)
374    val mulInField = Mux(
375      isIndexed,
376      Mux(lmul.asSInt > emul.asSInt, lmul, emul),
377      emul
378    )
379    LookupTree(mulInField, List(
380      "b101".U -> 0.U,
381      "b110".U -> 0.U,
382      "b111".U -> 0.U,
383      "b000".U -> 0.U,
384      "b001".U -> uopIdx(0),
385      "b010".U -> uopIdx(1, 0),
386      "b011".U -> uopIdx(2, 0)
387    ))
388  }
389}
390
391//eew decode
392object EewLog2 extends VLSUConstants {
393  // def apply (eew: UInt): UInt = {
394  //   (LookupTree(eew,List(
395  //     "b000".U -> "b000".U , // 1
396  //     "b101".U -> "b001".U , // 2
397  //     "b110".U -> "b010".U , // 4
398  //     "b111".U -> "b011".U   // 8
399  //   )))}
400  def apply(eew: UInt): UInt = ZeroExt(eew(1, 0), ewBits)
401}
402
403/**
404  * unit-stride instructions don't use this method;
405  * other instructions generate realFlowNum by EmulDataSize >> eew(1,0),
406  * EmulDataSize means the number of bytes that need to be written to the register,
407  * eew(1,0) means the number of bytes written at once*/
408object GenRealFlowNum {
409  def apply (instType: UInt, emul: UInt, lmul: UInt, eew: UInt, sew: UInt): UInt = {
410    (LookupTree(instType,List(
411      "b000".U ->  (MulDataSize(emul) >> eew(1,0)).asUInt, // store use, load do not use
412      "b010".U ->  (MulDataSize(emul) >> eew(1,0)).asUInt, // strided
413      "b001".U ->  Mux(emul.asSInt > lmul.asSInt, (MulDataSize(emul) >> eew(1,0)).asUInt, (MulDataSize(lmul) >> sew(1,0)).asUInt), // indexed-unordered
414      "b011".U ->  Mux(emul.asSInt > lmul.asSInt, (MulDataSize(emul) >> eew(1,0)).asUInt, (MulDataSize(lmul) >> sew(1,0)).asUInt), // indexed-ordered
415      "b100".U ->  (MulDataSize(emul) >> eew(1,0)).asUInt, // segment unit-stride
416      "b110".U ->  (MulDataSize(emul) >> eew(1,0)).asUInt, // segment strided
417      "b101".U ->  Mux(emul.asSInt > lmul.asSInt, (MulDataSize(emul) >> eew(1,0)).asUInt, (MulDataSize(lmul) >> sew(1,0)).asUInt), // segment indexed-unordered
418      "b111".U ->  Mux(emul.asSInt > lmul.asSInt, (MulDataSize(emul) >> eew(1,0)).asUInt, (MulDataSize(lmul) >> sew(1,0)).asUInt)  // segment indexed-ordered
419    )))}
420}
421
422/**
423  * GenRealFlowLog2 = Log2(GenRealFlowNum)
424  */
425object GenRealFlowLog2 extends VLSUConstants {
426  def apply(instType: UInt, emul: UInt, lmul: UInt, eew: UInt, sew: UInt): UInt = {
427    val emulLog2 = Mux(emul.asSInt >= 0.S, 0.U, emul)
428    val lmulLog2 = Mux(lmul.asSInt >= 0.S, 0.U, lmul)
429    val eewRealFlowLog2 = emulLog2 + log2Up(VLENB).U - eew(1, 0)
430    val sewRealFlowLog2 = lmulLog2 + log2Up(VLENB).U - sew(1, 0)
431    (LookupTree(instType, List(
432      "b000".U -> eewRealFlowLog2, // unit-stride
433      "b010".U -> eewRealFlowLog2, // strided
434      "b001".U -> Mux(emul.asSInt > lmul.asSInt, eewRealFlowLog2, sewRealFlowLog2), // indexed-unordered
435      "b011".U -> Mux(emul.asSInt > lmul.asSInt, eewRealFlowLog2, sewRealFlowLog2), // indexed-ordered
436      "b100".U -> eewRealFlowLog2, // segment unit-stride
437      "b110".U -> eewRealFlowLog2, // segment strided
438      "b101".U -> Mux(emul.asSInt > lmul.asSInt, eewRealFlowLog2, sewRealFlowLog2), // segment indexed-unordered
439      "b111".U -> Mux(emul.asSInt > lmul.asSInt, eewRealFlowLog2, sewRealFlowLog2), // segment indexed-ordered
440    )))
441  }
442}
443
444/**
445  * GenElemIdx generals an element index within an instruction, given a certain uopIdx and a known flowIdx
446  * inside the uop.
447  */
448object GenElemIdx extends VLSUConstants {
449  def apply(instType: UInt, emul: UInt, lmul: UInt, eew: UInt, sew: UInt,
450    uopIdx: UInt, flowIdx: UInt): UInt = {
451    val isIndexed = instType(0).asBool
452    val eewUopFlowsLog2 = Mux(emul.asSInt > 0.S, 0.U, emul) + log2Up(VLENB).U - eew(1, 0)
453    val sewUopFlowsLog2 = Mux(lmul.asSInt > 0.S, 0.U, lmul) + log2Up(VLENB).U - sew(1, 0)
454    val uopFlowsLog2 = Mux(
455      isIndexed,
456      Mux(emul.asSInt > lmul.asSInt, eewUopFlowsLog2, sewUopFlowsLog2),
457      eewUopFlowsLog2
458    )
459    LookupTree(uopFlowsLog2, List(
460      0.U -> uopIdx,
461      1.U -> uopIdx ## flowIdx(0),
462      2.U -> uopIdx ## flowIdx(1, 0),
463      3.U -> uopIdx ## flowIdx(2, 0),
464      4.U -> uopIdx ## flowIdx(3, 0)
465    ))
466  }
467}
468
469/**
470  * GenVLMAX calculates VLMAX, which equals MUL * ew
471  */
472object GenVLMAXLog2 extends VLSUConstants {
473  def apply(lmul: UInt, sew: UInt): UInt = lmul + log2Up(VLENB).U - sew
474}
475object GenVLMAX {
476  def apply(lmul: UInt, sew: UInt): UInt = 1.U << GenVLMAXLog2(lmul, sew)
477}
478
479object GenUSWholeRegVL extends VLSUConstants {
480  def apply(nfields: UInt, eew: UInt): UInt = {
481    LookupTree(eew(1, 0), List(
482      "b00".U -> (nfields << (log2Up(VLENB) - 0)),
483      "b01".U -> (nfields << (log2Up(VLENB) - 1)),
484      "b10".U -> (nfields << (log2Up(VLENB) - 2)),
485      "b11".U -> (nfields << (log2Up(VLENB) - 3))
486    ))
487  }
488}
489object GenUSWholeEmul extends VLSUConstants{
490  def apply(nf: UInt): UInt={
491    LookupTree(nf,List(
492      "b000".U -> "b000".U(mulBits.W),
493      "b001".U -> "b001".U(mulBits.W),
494      "b011".U -> "b010".U(mulBits.W),
495      "b111".U -> "b011".U(mulBits.W)
496    ))
497  }
498}
499
500
501object GenUSMaskRegVL extends VLSUConstants {
502  def apply(vl: UInt): UInt = {
503    (vl >> 3.U)
504  }
505}
506
507object GenUopByteMask {
508  def apply(flowMask: UInt, alignedType: UInt): UInt = {
509    LookupTree(alignedType, List(
510      "b00".U -> flowMask,
511      "b01".U -> FillInterleaved(2, flowMask),
512      "b10".U -> FillInterleaved(4, flowMask),
513      "b11".U -> FillInterleaved(8, flowMask)
514    ))
515  }
516}
517
518object GenVdIdxInField extends VLSUConstants {
519  def apply(instType: UInt, emul: UInt, lmul: UInt, uopIdx: UInt): UInt = {
520    val vdIdx = Wire(UInt(log2Up(maxMUL).W))
521    when (instType(1,0) === "b00".U || instType(1,0) === "b10".U || lmul.asSInt > emul.asSInt) {
522      // Unit-stride or Strided, or indexed with lmul >= emul
523      vdIdx := uopIdx
524    }.otherwise {
525      // Indexed with lmul <= emul
526      val multiple = emul - lmul
527      val uopIdxWidth = uopIdx.getWidth
528      vdIdx := LookupTree(multiple, List(
529        0.U -> uopIdx,
530        1.U -> (uopIdx >> 1),
531        2.U -> (uopIdx >> 2),
532        3.U -> (uopIdx >> 3)
533      ))
534    }
535    vdIdx
536  }
537}
538