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 xiangshan.backend.Bundles._ 23import xiangshan.backend.datapath.DataConfig._ 24import xiangshan.backend.datapath.WbArbiterParams 25import xiangshan.backend.datapath.WbConfig._ 26import xiangshan.backend.exu.ExeUnitParams 27import xiangshan.backend.fu.{FuConfig, FuType} 28import xiangshan.backend.issue._ 29import xiangshan.backend.regfile._ 30 31case class BackendParams( 32 schdParams : Map[SchedulerType, SchdBlockParams], 33 pregParams : Seq[PregParams], 34) { 35 def intSchdParams = schdParams.get(IntScheduler()) 36 def vfSchdParams = schdParams.get(VfScheduler()) 37 def memSchdParams = schdParams.get(MemScheduler()) 38 def allSchdParams: Seq[SchdBlockParams] = 39 (Seq(intSchdParams) :+ vfSchdParams :+ memSchdParams) 40 .filter(_.nonEmpty) 41 .map(_.get) 42 def allIssueParams: Seq[IssueBlockParams] = 43 allSchdParams.map(_.issueBlockParams).flatten 44 def allExuParams: Seq[ExeUnitParams] = 45 allIssueParams.map(_.exuBlockParams).flatten 46 47 def intPregParams: IntPregParams = pregParams.collectFirst { case x: IntPregParams => x }.get 48 def vfPregParams: VfPregParams = pregParams.collectFirst { case x: VfPregParams => x }.get 49 50 def numSrc : Int = allSchdParams.map(_.issueBlockParams.map(_.numSrc).max).max 51 def numRegSrc : Int = allSchdParams.map(_.issueBlockParams.map(_.numRegSrc).max).max 52 53 def AluCnt = allSchdParams.map(_.AluCnt).sum 54 def StaCnt = allSchdParams.map(_.StaCnt).sum 55 def StdCnt = allSchdParams.map(_.StdCnt).sum 56 def LduCnt = allSchdParams.map(_.LduCnt).sum 57 def LsExuCnt = StaCnt + LduCnt 58 def JmpCnt = allSchdParams.map(_.JmpCnt).sum 59 def BrhCnt = allSchdParams.map(_.BrhCnt).sum 60 def IqCnt = allSchdParams.map(_.issueBlockParams.length).sum 61 62 def numPcReadPort = allSchdParams.map(_.numPcReadPort).sum 63 64 def numIntWb = intPregParams.numWrite 65 def numVfWb = vfPregParams.numWrite 66 def numNoDataWB = allSchdParams.map(_.numNoDataWB).sum 67 def numExu = allSchdParams.map(_.numExu).sum 68 def numRfRead = 14 69 def numRfWrite = 8 70 def vconfigPort = 11 71 72 def numException = allExuParams.count(_.exceptionOut.nonEmpty) 73 74 def numRedirect = allSchdParams.map(_.numRedirect).sum 75 76 def genIntWriteBackBundle(implicit p: Parameters) = { 77 // Todo: limit write port 78 Seq.tabulate(numIntWb)(x => new RfWritePortWithConfig(IntData(), intPregParams.addrWidth)) 79 } 80 81 def genVfWriteBackBundle(implicit p: Parameters) = { 82 // Todo: limit write port 83 Seq.tabulate(numVfWb)(x => new RfWritePortWithConfig(VecData(), intPregParams.addrWidth)) 84 } 85 86 def genWriteBackBundles(implicit p: Parameters): Seq[RfWritePortWithConfig] = { 87 genIntWriteBackBundle ++ genVfWriteBackBundle 88 } 89 90 def genWrite2CtrlBundles(implicit p: Parameters): MixedVec[ValidIO[ExuOutput]] = { 91 MixedVec(allSchdParams.map(_.genExuOutputValidBundle.flatten).reduce(_ ++ _)) 92 } 93 94 def getIntWbArbiterParams: WbArbiterParams = { 95 val intWbCfgs: Seq[WbConfig] = allSchdParams.flatMap(_.getWbCfgs.flatten.flatten.filter(_.writeInt)) 96 datapath.WbArbiterParams(intWbCfgs, intPregParams) 97 } 98 99 def getVfWbArbiterParams: WbArbiterParams = { 100 val vfWbCfgs = allSchdParams.flatMap(_.getWbCfgs.flatten.flatten.filter(x => x.writeVec || x.writeFp)) 101 datapath.WbArbiterParams(vfWbCfgs, vfPregParams) 102 } 103} 104 105 106 107 108