1/*************************************************************************************** 2 * Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences 3 * Copyright (c) 2020-2021 Peng Cheng Laboratory 4 * 5 * XiangShan is licensed under Mulan PSL v2. 6 * You can use this software according to the terms and conditions of the Mulan PSL v2. 7 * You may obtain a copy of Mulan PSL v2 at: 8 * http://license.coscl.org.cn/MulanPSL2 9 * 10 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 11 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 12 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 13 * 14 * See the Mulan PSL v2 for more details. 15 ***************************************************************************************/ 16 17package xiangshan.backend 18 19import chipsalliance.rocketchip.config.Parameters 20import chisel3._ 21import chisel3.util._ 22import utils.MapUtils 23import xiangshan.backend.Bundles._ 24import xiangshan.backend.datapath.DataConfig._ 25import xiangshan.backend.datapath.{WakeUpConfig, WbArbiterParams} 26import xiangshan.backend.datapath.WbConfig._ 27import xiangshan.backend.datapath.RdConfig._ 28import xiangshan.backend.exu.ExeUnitParams 29import xiangshan.backend.fu.{FuConfig, FuType} 30import xiangshan.backend.issue._ 31import xiangshan.backend.regfile._ 32 33case class BackendParams( 34 schdParams : Map[SchedulerType, SchdBlockParams], 35 pregParams : Seq[PregParams], 36 iqWakeUpParams : Seq[WakeUpConfig], 37) { 38 39 configChecks 40 41 def intSchdParams = schdParams.get(IntScheduler()) 42 def vfSchdParams = schdParams.get(VfScheduler()) 43 def memSchdParams = schdParams.get(MemScheduler()) 44 def allSchdParams: Seq[SchdBlockParams] = 45 (Seq(intSchdParams) :+ vfSchdParams :+ memSchdParams) 46 .filter(_.nonEmpty) 47 .map(_.get) 48 def allIssueParams: Seq[IssueBlockParams] = 49 allSchdParams.map(_.issueBlockParams).flatten 50 def allExuParams: Seq[ExeUnitParams] = 51 allIssueParams.map(_.exuBlockParams).flatten 52 53 def intPregParams: IntPregParams = pregParams.collectFirst { case x: IntPregParams => x }.get 54 def vfPregParams: VfPregParams = pregParams.collectFirst { case x: VfPregParams => x }.get 55 def pregIdxWidth = pregParams.map(_.addrWidth).max 56 57 def numSrc : Int = allSchdParams.map(_.issueBlockParams.map(_.numSrc).max).max 58 def numRegSrc : Int = allSchdParams.map(_.issueBlockParams.map(_.numRegSrc).max).max 59 def numVecRegSrc: Int = allSchdParams.map(_.issueBlockParams.map(_.numVecSrc).max).max 60 61 62 def AluCnt = allSchdParams.map(_.AluCnt).sum 63 def StaCnt = allSchdParams.map(_.StaCnt).sum 64 def StdCnt = allSchdParams.map(_.StdCnt).sum 65 def LduCnt = allSchdParams.map(_.LduCnt).sum 66 def VlduCnt = allSchdParams.map(_.VlduCnt).sum 67 def LsExuCnt = StaCnt + LduCnt 68 def JmpCnt = allSchdParams.map(_.JmpCnt).sum 69 def BrhCnt = allSchdParams.map(_.BrhCnt).sum 70 def IqCnt = allSchdParams.map(_.issueBlockParams.length).sum 71 72 def numPcReadPort = allSchdParams.map(_.numPcReadPort).sum 73 74 def numIntWb = intPregParams.numWrite 75 def numVfWb = vfPregParams.numWrite 76 def numNoDataWB = allSchdParams.map(_.numNoDataWB).sum 77 def numExu = allSchdParams.map(_.numExu).sum 78 def numRfRead = 14 79 def numRfWrite = 8 80 def vconfigPort = 0 // Todo: remove it 81 82 def numException = allExuParams.count(_.exceptionOut.nonEmpty) 83 84 def numRedirect = allSchdParams.map(_.numRedirect).sum 85 86 def genIntWriteBackBundle(implicit p: Parameters) = { 87 // Todo: limit write port 88 Seq.tabulate(numIntWb)(x => new RfWritePortWithConfig(IntData(), intPregParams.addrWidth)) 89 } 90 91 def genVfWriteBackBundle(implicit p: Parameters) = { 92 // Todo: limit write port 93 Seq.tabulate(numVfWb)(x => new RfWritePortWithConfig(VecData(), intPregParams.addrWidth)) 94 } 95 96 def genWriteBackBundles(implicit p: Parameters): Seq[RfWritePortWithConfig] = { 97 genIntWriteBackBundle ++ genVfWriteBackBundle 98 } 99 100 def genWrite2CtrlBundles(implicit p: Parameters): MixedVec[ValidIO[ExuOutput]] = { 101 MixedVec(allSchdParams.map(_.genExuOutputValidBundle.flatten).reduce(_ ++ _)) 102 } 103 104 def getIntWbArbiterParams: WbArbiterParams = { 105 val intWbCfgs: Seq[WbConfig] = allSchdParams.flatMap(_.getWbCfgs.flatten.flatten.filter(_.writeInt)) 106 datapath.WbArbiterParams(intWbCfgs, intPregParams) 107 } 108 109 def getVfWbArbiterParams: WbArbiterParams = { 110 val vfWbCfgs = allSchdParams.flatMap(_.getWbCfgs.flatten.flatten.filter(x => x.writeVec || x.writeFp)) 111 datapath.WbArbiterParams(vfWbCfgs, vfPregParams) 112 } 113 114 def getExuIdx(name: String): Int = { 115 val exuParams = allExuParams 116 if (name != "WB") 117 exuParams.find(_.name == name).get.exuIdx 118 else 119 -1 120 } 121 122 def getExuName(idx: Int): String = { 123 val exuParams = allExuParams 124 exuParams(idx).name 125 } 126 127 def getIntWBExeGroup: Map[Int, Seq[ExeUnitParams]] = allExuParams.groupBy(x => x.getIntWBPort.getOrElse(IntWB(port = -1)).port).filter(_._1 != -1) 128 def getVfWBExeGroup: Map[Int, Seq[ExeUnitParams]] = allExuParams.groupBy(x => x.getVfWBPort.getOrElse(VfWB(port = -1)).port).filter(_._1 != -1) 129 130 def configChecks = { 131 // check 0 132 val maxPortSource = 2 133 134 allExuParams.map { 135 case exuParam => exuParam.wbPortConfigs.collectFirst { case x: IntWB => x } 136 }.filter(_.isDefined).groupBy(_.get.port).foreach { 137 case (wbPort, priorities) => assert(priorities.size <= maxPortSource, "There has " + priorities.size + " exu's " + "Int WBport is " + wbPort + ", but the maximum is " + maxPortSource + ".") 138 } 139 allExuParams.map { 140 case exuParam => exuParam.wbPortConfigs.collectFirst { case x: VfWB => x } 141 }.filter(_.isDefined).groupBy(_.get.port).foreach { 142 case (wbPort, priorities) => assert(priorities.size <= maxPortSource, "There has " + priorities.size + " exu's " + "Vf WBport is " + wbPort + ", but the maximum is " + maxPortSource + ".") 143 } 144 145 // check 1 146 val wbTypes = Seq(IntWB(), VfWB()) 147 val rdTypes = Seq(IntRD(), VfRD()) 148 for(wbType <- wbTypes){ 149 for(rdType <- rdTypes){ 150 allExuParams.map { 151 case exuParam => 152 val wbPortConfigs = exuParam.wbPortConfigs 153 val wbConfigs = wbType match{ 154 case _: IntWB => wbPortConfigs.collectFirst { case x: IntWB => x } 155 case _: VfWB => wbPortConfigs.collectFirst { case x: VfWB => x } 156 case _ => None 157 } 158 val rfReadPortConfigs = exuParam.rfrPortConfigs 159 val rdConfigs = rdType match{ 160 case _: IntRD => rfReadPortConfigs.flatten.filter(_.isInstanceOf[IntRD]) 161 case _: VfRD => rfReadPortConfigs.flatten.filter(_.isInstanceOf[VfRD]) 162 case _ => Seq() 163 } 164 (wbConfigs, rdConfigs) 165 }.filter(_._1.isDefined) 166 .sortBy(_._1.get.priority) 167 .groupBy(_._1.get.port).map { 168 case (_, intWbRdPairs) => 169 intWbRdPairs.map(_._2).flatten 170 }.map(rdCfgs => rdCfgs.groupBy(_.port).foreach { 171 case (_, rdCfgs) => 172 rdCfgs.zip(rdCfgs.drop(1)).foreach { case (cfg0, cfg1) => assert(cfg0.priority <= cfg1.priority) } 173 }) 174 } 175 } 176 } 177} 178 179 180 181 182