xref: /XiangShan/src/main/scala/xiangshan/backend/exu/ExeUnitParams.scala (revision 602c81c352f33c6bbac0d52c7da77017ab7298ec)
1package xiangshan.backend.exu
2
3import chipsalliance.rocketchip.config.Parameters
4import chisel3._
5import chisel3.util._
6import xiangshan.backend.Bundles.{ExuInput, ExuOutput}
7import xiangshan.backend.datapath.DataConfig.DataConfig
8import xiangshan.backend.datapath.RdConfig._
9import xiangshan.backend.datapath.WbConfig.{FpWB, IntWB, WbConfig}
10import xiangshan.backend.fu.{FuConfig, FuType}
11import xiangshan.backend.issue.{IntScheduler, SchedulerType, VfScheduler}
12
13case class ExeUnitParams(
14  fuConfigs     : Seq[FuConfig],
15  wbPortConfigs : Seq[WbConfig],
16  rfrPortConfigs: Seq[Seq[RdConfig]],
17)(
18  implicit
19  val schdType: SchedulerType,
20) {
21  val numIntSrc: Int = fuConfigs.map(_.numIntSrc).max
22  val numFpSrc: Int = fuConfigs.map(_.numFpSrc).max
23  val numVecSrc: Int = fuConfigs.map(_.numVecSrc).max
24  val numVfSrc: Int = fuConfigs.map(_.numVfSrc).max
25  val numRegSrc: Int = fuConfigs.map(_.numRegSrc).max
26  val numSrc: Int = fuConfigs.map(_.numSrc).max
27  val dataBitsMax: Int = fuConfigs.map(_.dataBits).max
28  val readIntRf: Boolean = numIntSrc > 0
29  val readFpRf: Boolean = numFpSrc > 0
30  val readVecRf: Boolean = numVecSrc > 0
31  val writeIntRf: Boolean = fuConfigs.map(_.writeIntRf).reduce(_ || _)
32  val writeFpRf: Boolean = fuConfigs.map(_.writeFpRf).reduce(_ || _)
33  val writeVecRf: Boolean = fuConfigs.map(_.writeVecRf).reduce(_ || _)
34  val writeVfRf: Boolean = writeFpRf || writeVecRf
35  val writeFflags: Boolean = fuConfigs.map(_.writeFflags).reduce(_ || _)
36  val writeVxsat: Boolean = fuConfigs.map(_.writeVxsat).reduce(_ || _)
37  val hasNoDataWB: Boolean = fuConfigs.map(_.hasNoDataWB).reduce(_ || _)
38  val hasRedirect: Boolean = fuConfigs.map(_.hasRedirect).reduce(_ || _)
39  val hasPredecode: Boolean = fuConfigs.map(_.hasPredecode).reduce(_ || _)
40  val exceptionOut: Seq[Int] = fuConfigs.map(_.exceptionOut).reduce(_ ++ _).distinct.sorted
41  val hasLoadError: Boolean = fuConfigs.map(_.hasLoadError).reduce(_ || _)
42  val flushPipe: Boolean = fuConfigs.map(_.flushPipe).reduce(_ || _)
43  val replayInst: Boolean = fuConfigs.map(_.replayInst).reduce(_ || _)
44  val trigger: Boolean = fuConfigs.map(_.trigger).reduce(_ || _)
45  val needExceptionGen: Boolean = exceptionOut.nonEmpty || flushPipe || replayInst || trigger
46  val needPc: Boolean = fuConfigs.map(_.needPc).reduce(_ || _)
47  val needSrcFrm: Boolean = fuConfigs.map(_.needSrcFrm).reduce(_ || _)
48  val needFPUCtrl: Boolean = fuConfigs.map(_.needFPUCtrl).reduce(_ || _)
49  val needVPUCtrl: Boolean = fuConfigs.map(_.needVecCtrl).reduce(_ || _)
50  val wbPregIdxWidth = if (wbPortConfigs.nonEmpty) wbPortConfigs.map(_.pregIdxWidth).max else 0
51
52  protected val latencyCertain = fuConfigs.map(x => x.latency.latencyVal.nonEmpty).reduce(_&&_)
53  val fuLatencyMap = if (latencyCertain) Some(fuConfigs.map(y => (y.fuType, y.latency.latencyVal.get))) else None
54  val latencyValMax = fuLatencyMap.map(x => x.map(_._2).max)
55
56  def hasCSR: Boolean = fuConfigs.map(_.isCsr).reduce(_ || _)
57
58  def hasFence: Boolean = fuConfigs.map(_.isFence).reduce(_ || _)
59
60  def hasBrhFu = fuConfigs.map(_.fuType == FuType.brh).reduce(_ || _)
61
62  def hasJmpFu = fuConfigs.map(_.fuType == FuType.jmp).reduce(_ || _)
63
64  def hasLoadFu = fuConfigs.map(_.fuType == FuType.ldu).reduce(_ || _)
65
66  def hasStoreAddrFu = fuConfigs.map(_.name == "sta").reduce(_ || _)
67
68  def hasStdFu = fuConfigs.map(_.name == "std").reduce(_ || _)
69
70  def hasMemAddrFu = hasLoadFu || hasStoreAddrFu
71
72  def getSrcDataType(srcIdx: Int): Set[DataConfig] = {
73    fuConfigs.map(_.getSrcDataType(srcIdx)).reduce(_ ++ _)
74  }
75
76  def immType: Set[UInt] = fuConfigs.map(x => x.immType).reduce(_ ++ _)
77
78  def getWBSource: SchedulerType = {
79    schdType
80  }
81
82  def hasCrossWb: Boolean = {
83    schdType match {
84      case IntScheduler() => writeFpRf || writeVecRf
85      case VfScheduler() => writeIntRf
86      case _ => false
87    }
88  }
89
90  def canAccept(fuType: UInt): Bool = {
91    Cat(fuConfigs.map(_.fuType.U === fuType)).orR
92  }
93
94  def hasUncertainLatency: Boolean = fuConfigs.map(_.latency.latencyVal.isEmpty).reduce(_ || _)
95
96  def getIntWBPort = {
97    wbPortConfigs.collectFirst {
98      case x: IntWB => x
99    }
100  }
101
102  def getFpWBPort = {
103    wbPortConfigs.collectFirst {
104      case x: FpWB => x
105    }
106  }
107
108  def getRfReadDataCfgSet: Seq[Set[DataConfig]] = {
109    val fuSrcsCfgSet: Seq[Seq[Set[DataConfig]]] = fuConfigs.map(_.getRfReadDataCfgSet)
110    val alignedFuSrcsCfgSet: Seq[Seq[Set[DataConfig]]] = fuSrcsCfgSet.map(x => x ++ Seq.fill(numRegSrc - x.length)(Set[DataConfig]()))
111
112    val exuSrcsCfgSet = alignedFuSrcsCfgSet.reduce((x, y) => (x zip y).map { case (cfg1, cfg2) => cfg1 union cfg2 })
113
114    exuSrcsCfgSet
115  }
116
117  def genExuModule(implicit p: Parameters): ExeUnit = {
118    new ExeUnit(this)
119  }
120
121  def genExuInputBundle(implicit p: Parameters): ExuInput = {
122    new ExuInput(this)
123  }
124
125  def genExuOutputBundle(implicit p: Parameters): ExuOutput = {
126    new ExuOutput(this)
127  }
128}
129