xref: /XiangShan/src/main/scala/xiangshan/backend/fu/wrapper/VPPU.scala (revision 643734bb561535e33ba254ba6475f4e4c271a6f4)
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, srcMask)
40
41  // io alias
42  private val opcode = VpermType.getOpcode(fuOpType)
43
44  // modules
45  private val typeMod = Module(new VPermSrcTypeModule)
46  private val vperms = Module(new Permutation)
47
48  /**
49    * [[typeMod]]'s in connection
50    */
51  typeMod.io.in.fuOpType := fuOpType
52  typeMod.io.in.vsew := vsew
53  typeMod.io.in.isReverse := isReverse
54  typeMod.io.in.isExt := isExt
55  typeMod.io.in.isDstMask := vecCtrl.isDstMask
56  typeMod.io.in.isMove := isMove
57
58  /**
59    * [[vperms]]'s in connection
60    */
61  vperms.io match {
62    case subIO =>
63      subIO.in.valid            := io.in.valid
64      subIO.in.bits.opcode.op   := opcode
65      subIO.in.bits.info.vm     := vm
66      subIO.in.bits.info.ma     := vma
67      subIO.in.bits.info.ta     := vta
68      subIO.in.bits.info.vlmul  := vlmul
69      subIO.in.bits.info.vl     := srcVConfig.vl
70      subIO.in.bits.info.vstart := vstart
71      subIO.in.bits.info.uopIdx := vuopIdx
72      subIO.in.bits.info.vxrm   := vxrm
73      subIO.in.bits.srcType(0)  := typeMod.io.out.vs2Type
74      subIO.in.bits.srcType(1)  := typeMod.io.out.vs1Type
75      subIO.in.bits.vdType      := typeMod.io.out.vdType
76      subIO.in.bits.vs1         := vs1
77      subIO.in.bits.vs2         := vs2
78      subIO.in.bits.old_vd      := oldVd
79      subIO.in.bits.mask        := mask
80  }
81
82  io.out.bits.res.data := vperms.io.out.vd
83  io.out.bits.res.vxsat.foreach(_ := vperms.io.out.vxsat)
84}
85