xref: /XiangShan/src/main/scala/xiangshan/backend/fu/wrapper/VFMA.scala (revision efdf5c1caace6dcbe273d851d5fa0ecbf398c689)
1package xiangshan.backend.fu.wrapper
2
3import chipsalliance.rocketchip.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 yunsuan.VfpuType
12import yunsuan.encoding.Opcode.VimacOpcode
13import yunsuan.encoding.{VdType, Vs1IntType, Vs2IntType}
14import yunsuan.{OpType, VimacType}
15import yunsuan.vector.VectorFloatFMA
16import yunsuan.vector.mac.VIMac64b
17
18class VFMA(cfg: FuConfig)(implicit p: Parameters) extends VecPipedFuncUnit(cfg) {
19  XSError(io.in.valid && io.in.bits.ctrl.fuOpType === VfpuType.dummy, "Vfalu OpType not supported")
20
21  // params alias
22  private val dataWidth = cfg.dataBits
23  private val dataWidthOfDataModule = 64
24  private val numVecModule = dataWidth / dataWidthOfDataModule
25
26  // io alias
27  private val opcode  = fuOpType(3,0)
28  private val resWiden  = fuOpType(4)
29
30  // modules
31  private val vfmas = Seq.fill(numVecModule)(Module(new VectorFloatFMA))
32  private val vs2Split = Module(new VecDataSplitModule(dataWidth, dataWidthOfDataModule))
33  private val vs1Split = Module(new VecDataSplitModule(dataWidth, dataWidthOfDataModule))
34  private val oldVdSplit  = Module(new VecDataSplitModule(dataWidth, dataWidthOfDataModule))
35//  private val mgu = Module(new Mgu(dataWidth))
36
37  /**
38    * In connection of [[vs2Split]], [[vs1Split]] and [[oldVdSplit]]
39    */
40  vs2Split.io.inVecData := vs2
41  vs1Split.io.inVecData := vs1
42  oldVdSplit.io.inVecData := oldVd
43
44  /**
45    * [[vfmas]]'s in connection
46    */
47  // Vec(vs2(31,0), vs2(63,32), vs2(95,64), vs2(127,96)) ==>
48  // Vec(
49  //   Cat(vs2(95,64),  vs2(31,0)),
50  //   Cat(vs2(127,96), vs2(63,32)),
51  // )
52  private val vs2GroupedVec: Vec[UInt] = VecInit(vs2Split.io.outVec32b.zipWithIndex.groupBy(_._2 % 2).map(x => x._1 -> x._2.map(_._1)).values.map(x => Cat(x.reverse)).toSeq)
53  private val vs1GroupedVec: Vec[UInt] = VecInit(vs1Split.io.outVec32b.zipWithIndex.groupBy(_._2 % 2).map(x => x._1 -> x._2.map(_._1)).values.map(x => Cat(x.reverse)).toSeq)
54
55  vfmas.zipWithIndex.foreach {
56    case (mod, i) =>
57      mod.io.fp_a         := vs2Split.io.outVec64b(i)
58      mod.io.fp_b         := vs1Split.io.outVec64b(i)
59      mod.io.fp_c         := oldVdSplit.io.outVec64b(i)
60      mod.io.widen_a      := Cat(vs2Split.io.outVec32b(i+numVecModule), vs2Split.io.outVec32b(i))
61      mod.io.widen_b      := Cat(vs1Split.io.outVec32b(i+numVecModule), vs1Split.io.outVec32b(i))
62      mod.io.frs1         := 0.U     // already vf -> vv
63      mod.io.is_frs1      := false.B // already vf -> vv
64      mod.io.uop_idx      := vuopIdx(0)
65      mod.io.is_vec       := true.B // Todo
66      mod.io.round_mode   := frm
67      mod.io.fp_format    := vsew
68      mod.io.res_widening := resWiden
69      mod.io.op_code      := opcode
70  }
71  io.out.bits.res.data := vfmas.map(_.io.fp_result).reduceRight(Cat(_,_))
72  val allFFlagsEn = Wire(Vec(4*numVecModule,Bool()))
73  allFFlagsEn.foreach(en => en := true.B) // Todo
74  val allFFlags = vfmas.map(_.io.fflags).reduceRight(Cat(_,_)).asTypeOf(Vec(4*numVecModule,UInt(5.W)))
75  val outFFlags = allFFlagsEn.zip(allFFlags).map{
76    case(en,fflags) => Mux(en, fflags, 0.U(5.W))
77  }.reduce(_ | _)
78  io.out.bits.res.fflags.get := outFFlags//vfmas.map(_.io.fflags).reduceRight(_ | _).asTypeOf(Vec(4,UInt(5.W))).reduce(_ | _)
79}
80