xref: /XiangShan/src/main/scala/xiangshan/backend/fu/wrapper/VPPU.scala (revision f7063a43ab34da917ba6c670d21871314340c550)
1package xiangshan.backend.fu.wrapper
2
3import org.chipsalliance.cde.config.Parameters
4import chisel3._
5import chisel3.util._
6import utils.XSError
7import xiangshan.backend.fu.FuConfig
8import xiangshan.backend.fu.vector.Bundles.VSew
9import xiangshan.backend.fu.vector.utils.VecDataSplitModule
10import xiangshan.backend.fu.vector.{Mgu, Utils, VecPipedFuncUnit, VecSrcTypeModule}
11import xiangshan.SrcType
12import yunsuan.encoding.Opcode.VimacOpcode
13import yunsuan.encoding.{VdType, Vs1IntType, Vs2IntType}
14import yunsuan.{OpType, VpermType}
15import yunsuan.vector.perm.Permutation
16
17class VPermSrcTypeModule extends VecSrcTypeModule {
18  private val srcVdType = Wire(new Bundle{
19    val srcType2 = UInt(4.W)
20    val srcType1 = UInt(4.W)
21    val vdType = UInt(4.W)
22  })
23  srcVdType := VpermType.getSrcVdType(fuOpType, vsew).asTypeOf(srcVdType.cloneType)
24
25  io.out.illegal := false.B
26  io.out.vs2Type := srcVdType.srcType2
27  io.out.vs1Type := srcVdType.srcType1
28  io.out.vdType  := srcVdType.vdType
29}
30
31class VPPU(cfg: FuConfig)(implicit p: Parameters) extends VecPipedFuncUnit(cfg) {
32  XSError(io.in.valid && io.in.bits.ctrl.fuOpType === VpermType.dummy, "VpermType OpType not supported")
33
34  // params alias
35  private val dataWidth = cfg.dataBits
36  private val dataWidthOfDataModule = 64
37  private val numVecModule = dataWidth / dataWidthOfDataModule
38  private val vppuNeedClearMask = (VpermType.vcompress === io.in.bits.ctrl.fuOpType) && (vuopIdx(log2Up(MaxUopSize)-1,1) === 0.U)
39  private val mask = Mux(vppuNeedClearMask, 0.U, io.in.bits.data.src(3))
40  private val isVmvnr = VpermType.isVmvnr(io.in.bits.ctrl.fuOpType)
41  private val emul = VpermType.getEmulVmvnr(io.in.bits.ctrl.fuOpType)
42  // io alias
43  private val opcode = VpermType.getOpcode(fuOpType)
44
45  // modules
46  private val typeMod = Module(new VPermSrcTypeModule)
47  private val vperms = Module(new Permutation)
48
49  /**
50    * [[typeMod]]'s in connection
51    */
52  typeMod.io.in.fuOpType := fuOpType
53  typeMod.io.in.vsew := vsew
54  typeMod.io.in.isReverse := isReverse
55  typeMod.io.in.isExt := isExt
56  typeMod.io.in.isDstMask := vecCtrl.isDstMask
57  typeMod.io.in.isMove := isMove
58
59  /**
60    * [[vperms]]'s in connection
61    */
62  vperms.io match {
63    case subIO =>
64      subIO.in.valid            := io.in.valid
65      subIO.in.bits.opcode.op   := opcode
66      subIO.in.bits.info.vm     := vm
67      subIO.in.bits.info.ma     := vma
68      subIO.in.bits.info.ta     := vta
69      subIO.in.bits.info.vlmul  := Mux(isVmvnr, emul, vlmul)
70      subIO.in.bits.info.vl     := srcVConfig.vl
71      subIO.in.bits.info.vstart := vstart
72      subIO.in.bits.info.uopIdx := vuopIdx
73      subIO.in.bits.info.vxrm   := vxrm
74      subIO.in.bits.srcType(0)  := typeMod.io.out.vs2Type
75      subIO.in.bits.srcType(1)  := typeMod.io.out.vs1Type
76      subIO.in.bits.vdType      := typeMod.io.out.vdType
77      subIO.in.bits.vs1         := vs1
78      subIO.in.bits.vs2         := vs2
79      subIO.in.bits.old_vd      := oldVd
80      subIO.in.bits.mask        := mask
81  }
82
83  io.out.bits.res.data := vperms.io.out.vd
84  io.out.bits.res.vxsat.foreach(_ := vperms.io.out.vxsat)
85}
86