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 wbPregIdxWidth = if (wbPortConfigs.nonEmpty) wbPortConfigs.map(_.pregIdxWidth).max else 0 50 51 protected val latencyCertain = fuConfigs.map(x => x.latency.latencyVal.nonEmpty).reduce(_&&_) 52 val fuLatencyMap = if (latencyCertain) Some(fuConfigs.map(y => (y.fuType, y.latency.latencyVal.get))) else None 53 val latencyValMax = fuLatencyMap.map(x => x.map(_._2).max) 54 55 def hasCSR: Boolean = fuConfigs.map(_.isCsr).reduce(_ || _) 56 57 def hasFence: Boolean = fuConfigs.map(_.isFence).reduce(_ || _) 58 59 def hasBrhFu = fuConfigs.map(_.fuType == FuType.brh).reduce(_ || _) 60 61 def hasJmpFu = fuConfigs.map(_.fuType == FuType.jmp).reduce(_ || _) 62 63 def hasLoadFu = fuConfigs.map(_.fuType == FuType.ldu).reduce(_ || _) 64 65 def hasStoreAddrFu = fuConfigs.map(_.name == "sta").reduce(_ || _) 66 67 def hasStdFu = fuConfigs.map(_.name == "std").reduce(_ || _) 68 69 def hasMemAddrFu = hasLoadFu || hasStoreAddrFu 70 71 def getSrcDataType(srcIdx: Int): Set[DataConfig] = { 72 fuConfigs.map(_.getSrcDataType(srcIdx)).reduce(_ ++ _) 73 } 74 75 def immType: Set[UInt] = fuConfigs.map(x => x.immType).reduce(_ ++ _) 76 77 def getWBSource: SchedulerType = { 78 schdType 79 } 80 81 def hasCrossWb: Boolean = { 82 schdType match { 83 case IntScheduler() => writeFpRf || writeVecRf 84 case VfScheduler() => writeIntRf 85 case _ => false 86 } 87 } 88 89 def canAccept(fuType: UInt): Bool = { 90 Cat(fuConfigs.map(_.fuType.U === fuType)).orR 91 } 92 93 def hasUncertainLatency: Boolean = fuConfigs.map(_.latency.latencyVal.isEmpty).reduce(_ || _) 94 95 def getIntWBPort = { 96 wbPortConfigs.collectFirst { 97 case x: IntWB => x 98 } 99 } 100 101 def getFpWBPort = { 102 wbPortConfigs.collectFirst { 103 case x: FpWB => x 104 } 105 } 106 107 def getRfReadDataCfgSet: Seq[Set[DataConfig]] = { 108 val fuSrcsCfgSet: Seq[Seq[Set[DataConfig]]] = fuConfigs.map(_.getRfReadDataCfgSet) 109 val alignedFuSrcsCfgSet: Seq[Seq[Set[DataConfig]]] = fuSrcsCfgSet.map(x => x ++ Seq.fill(numRegSrc - x.length)(Set[DataConfig]())) 110 111 val exuSrcsCfgSet = alignedFuSrcsCfgSet.reduce((x, y) => (x zip y).map { case (cfg1, cfg2) => cfg1 union cfg2 }) 112 113 exuSrcsCfgSet 114 } 115 116 def genExuModule(implicit p: Parameters): ExeUnit = { 117 new ExeUnit(this) 118 } 119 120 def genExuInputBundle(implicit p: Parameters): ExuInput = { 121 new ExuInput(this) 122 } 123 124 def genExuOutputBundle(implicit p: Parameters): ExuOutput = { 125 new ExuOutput(this) 126 } 127} 128