xref: /XiangShan/src/main/scala/xiangshan/backend/fu/vector/VecPipedFuncUnit.scala (revision 26af847e669bb208507278eafc6ebe52f03b0d19)
1package xiangshan.backend.fu.vector
2
3import org.chipsalliance.cde.config.Parameters
4import chisel3._
5import chisel3.util._
6import xiangshan._
7import xiangshan.backend.fu.FuConfig.VialuCfg
8import xiangshan.backend.fu.vector.Bundles.VConfig
9import xiangshan.backend.fu.vector.utils.ScalaDupToVector
10import xiangshan.backend.fu.{FuConfig, FuncUnit, HasPipelineReg}
11import yunsuan.VialuFixType
12
13trait VecFuncUnitAlias { this: FuncUnit =>
14  protected val inCtrl  = io.in.bits.ctrl
15  protected val inData  = io.in.bits.data
16  protected val vecCtrl = inCtrl.vpu.get
17
18  protected val vill    = vecCtrl.vill
19  protected val vma     = vecCtrl.vma
20  protected val vta     = vecCtrl.vta
21  protected val vsew    = vecCtrl.vsew
22  protected val vlmul   = vecCtrl.vlmul
23  protected val vm      = vecCtrl.vm
24  protected val vstart  = vecCtrl.vstart
25
26  protected val frm     = io.frm.getOrElse(0.U(3.W))
27  protected val vxrm    = io.vxrm.getOrElse(0.U(3.W))
28  protected val instRm  = inCtrl.fpu.getOrElse(0.U.asTypeOf(new FPUCtrlSignals)).rm
29  protected val rm      = Mux(vecCtrl.fpu.isFpToVecInst && instRm =/= "b111".U, instRm, frm)
30  protected val vuopIdx = vecCtrl.vuopIdx
31  protected val nf      = 0.U  // No need to handle nf in vector arith unit
32
33  protected val fuOpType  = inCtrl.fuOpType
34  protected val isNarrow  = vecCtrl.isNarrow
35  protected val isExt     = vecCtrl.isExt
36  protected val isMove    = vecCtrl.isMove
37  // swap vs1 and vs2, used by vrsub, etc
38  protected val isReverse = vecCtrl.isReverse
39
40  protected val allMaskTrue = VecInit(Seq.fill(VLEN)(true.B)).asUInt
41  protected val allMaskFalse = VecInit(Seq.fill(VLEN)(false.B)).asUInt
42
43  // vadc.vv, vsbc.vv need this
44  protected val needClearMask: Bool = if(cfg == VialuCfg) VialuFixType.needClearMask(inCtrl.fuOpType) else false.B
45
46  // There is no difference between control-dependency or data-dependency for function unit,
47  // but spliting these in ctrl or data bundles is easy to coding.
48  protected val srcMask: UInt = if(!cfg.maskWakeUp) inCtrl.vpu.get.vmask else {
49    MuxCase(inData.getSrcMask, Seq(
50      needClearMask -> allMaskFalse,
51      vm -> allMaskTrue
52    ))
53  }
54  protected val srcVConfig: VConfig = if(!cfg.vconfigWakeUp) inCtrl.vpu.get.vconfig else inData.getSrcVConfig.asTypeOf(new VConfig)
55  protected val vl = srcVConfig.vl
56}
57
58class VecPipedFuncUnit(cfg: FuConfig)(implicit p: Parameters) extends FuncUnit(cfg)
59  with HasPipelineReg
60  with VecFuncUnitAlias
61{
62  private val src0 = inData.src(0)
63  private val src1 = WireInit(inData.src(1)) // vs2 only
64  if(cfg == FuConfig.VfaluCfg){
65    val vs2Fold = Wire(UInt(VLEN.W))
66    vs2Fold := Mux1H(
67      Seq(
68        vecCtrl.fpu.isFoldTo1_2 -> inData.src(1)(VLEN/1-1, VLEN/2),
69        vecCtrl.fpu.isFoldTo1_4 -> inData.src(1)(VLEN/2-1, VLEN/4),
70        vecCtrl.fpu.isFoldTo1_8 -> inData.src(1)(VLEN/4-1, VLEN/8),
71      )
72    )
73    src1 := Mux(vecCtrl.fpu.isFoldTo1_2 || vecCtrl.fpu.isFoldTo1_4 || vecCtrl.fpu.isFoldTo1_8, vs2Fold, inData.src(1))
74  }
75  protected val vs2 = src1
76  protected val vs1 = src0
77  protected val oldVd = inData.src(2)
78
79  protected val outCtrl     = ctrlVec.last
80  protected val outData     = dataVec.last
81
82  protected val outVecCtrl  = outCtrl.vpu.get
83  protected val outVm       = outVecCtrl.vm
84
85  // vadc.vv, vsbc.vv need this
86  protected val outNeedClearMask: Bool = if(cfg == VialuCfg) VialuFixType.needClearMask(outCtrl.fuOpType) else false.B
87  protected val outVConfig  = if(!cfg.vconfigWakeUp) outCtrl.vpu.get.vconfig else outData.getSrcVConfig.asTypeOf(new VConfig)
88  protected val outVl       = outVConfig.vl
89  protected val outVstart   = outVecCtrl.vstart
90  protected val outOldVd    = outData.src(2)
91  // There is no difference between control-dependency or data-dependency for function unit,
92  // but spliting these in ctrl or data bundles is easy to coding.
93  protected val outSrcMask: UInt = if (!cfg.maskWakeUp) outCtrl.vpu.get.vmask else {
94    MuxCase(
95      outData.getSrcMask, Seq(
96        outNeedClearMask -> allMaskFalse,
97        outVm -> allMaskTrue
98      )
99    )
100  }
101
102  override def latency: Int = cfg.latency.latencyVal.get
103
104}
105