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 18 19import org.chipsalliance.cde.config.{Field, Parameters} 20import chisel3._ 21import chisel3.util._ 22import huancun._ 23import system.SoCParamsKey 24import xiangshan.backend.datapath.RdConfig._ 25import xiangshan.backend.datapath.WbConfig._ 26import xiangshan.backend.dispatch.DispatchParameters 27import xiangshan.backend.exu.ExeUnitParams 28import xiangshan.backend.fu.FuConfig._ 29import xiangshan.backend.issue.{IntScheduler, IssueBlockParams, MemScheduler, SchdBlockParams, SchedulerType, VfScheduler, FpScheduler} 30import xiangshan.backend.regfile.{IntPregParams, PregParams, VfPregParams, FakeIntPregParams, FpPregParams} 31import xiangshan.backend.BackendParams 32import xiangshan.cache.DCacheParameters 33import xiangshan.cache.prefetch._ 34import xiangshan.frontend.{BasePredictor, BranchPredictionResp, FTB, FakePredictor, RAS, Tage, ITTage, Tage_SC, FauFTB} 35import xiangshan.frontend.icache.ICacheParameters 36import xiangshan.cache.mmu.{L2TLBParameters, TLBParameters} 37import xiangshan.frontend._ 38import xiangshan.frontend.icache.ICacheParameters 39 40import freechips.rocketchip.diplomacy.AddressSet 41import freechips.rocketchip.tile.MaxHartIdBits 42import system.SoCParamsKey 43import huancun._ 44import huancun.debug._ 45import xiangshan.cache.wpu.WPUParameters 46import coupledL2._ 47import xiangshan.backend.datapath.WakeUpConfig 48import xiangshan.mem.prefetch.{PrefetcherParams, SMSParams} 49 50import scala.math.min 51 52case object XSTileKey extends Field[Seq[XSCoreParameters]] 53 54case object XSCoreParamsKey extends Field[XSCoreParameters] 55 56case class XSCoreParameters 57( 58 HasPrefetch: Boolean = false, 59 HartId: Int = 0, 60 XLEN: Int = 64, 61 VLEN: Int = 128, 62 ELEN: Int = 64, 63 HSXLEN: Int = 64, 64 HasMExtension: Boolean = true, 65 HasCExtension: Boolean = true, 66 HasHExtension: Boolean = true, 67 HasDiv: Boolean = true, 68 HasICache: Boolean = true, 69 HasDCache: Boolean = true, 70 AddrBits: Int = 64, 71 VAddrBits: Int = 39, 72 GPAddrBits: Int = 41, 73 HasFPU: Boolean = true, 74 HasVPU: Boolean = true, 75 HasCustomCSRCacheOp: Boolean = true, 76 FetchWidth: Int = 8, 77 AsidLength: Int = 16, 78 VmidLength: Int = 14, 79 EnableBPU: Boolean = true, 80 EnableBPD: Boolean = true, 81 EnableRAS: Boolean = true, 82 EnableLB: Boolean = false, 83 EnableLoop: Boolean = true, 84 EnableSC: Boolean = true, 85 EnbaleTlbDebug: Boolean = false, 86 EnableClockGate: Boolean = true, 87 EnableJal: Boolean = false, 88 EnableFauFTB: Boolean = true, 89 UbtbGHRLength: Int = 4, 90 // HistoryLength: Int = 512, 91 EnableGHistDiff: Boolean = true, 92 EnableCommitGHistDiff: Boolean = true, 93 UbtbSize: Int = 256, 94 FtbSize: Int = 2048, 95 RasSize: Int = 16, 96 RasSpecSize: Int = 32, 97 RasCtrSize: Int = 3, 98 CacheLineSize: Int = 512, 99 FtbWays: Int = 4, 100 TageTableInfos: Seq[Tuple3[Int,Int,Int]] = 101 // Sets Hist Tag 102 Seq(( 4096, 8, 8), 103 ( 4096, 13, 8), 104 ( 4096, 32, 8), 105 ( 4096, 119, 8)), 106 ITTageTableInfos: Seq[Tuple3[Int,Int,Int]] = 107 // Sets Hist Tag 108 Seq(( 256, 4, 9), 109 ( 256, 8, 9), 110 ( 512, 13, 9), 111 ( 512, 16, 9), 112 ( 512, 32, 9)), 113 SCNRows: Int = 512, 114 SCNTables: Int = 4, 115 SCCtrBits: Int = 6, 116 SCHistLens: Seq[Int] = Seq(0, 4, 10, 16), 117 numBr: Int = 2, 118 branchPredictor: (BranchPredictionResp, Parameters) => Tuple2[Seq[BasePredictor], BranchPredictionResp] = 119 (resp_in: BranchPredictionResp, p: Parameters) => { 120 val ftb = Module(new FTB()(p)) 121 val uftb = Module(new FauFTB()(p)) 122 val tage = Module(new Tage_SC()(p)) 123 val ras = Module(new RAS()(p)) 124 val ittage = Module(new ITTage()(p)) 125 val preds = Seq(uftb, tage, ftb, ittage, ras) 126 preds.map(_.io := DontCare) 127 128 uftb.io.in.bits.resp_in(0) := resp_in 129 tage.io.in.bits.resp_in(0) := uftb.io.out 130 ftb.io.in.bits.resp_in(0) := tage.io.out 131 ittage.io.in.bits.resp_in(0) := ftb.io.out 132 ras.io.in.bits.resp_in(0) := ittage.io.out 133 134 (preds, ras.io.out) 135 }, 136 ICacheECCForceError: Boolean = false, 137 IBufSize: Int = 48, 138 IBufNBank: Int = 6, // IBuffer bank amount, should divide IBufSize 139 DecodeWidth: Int = 6, 140 RenameWidth: Int = 6, 141 CommitWidth: Int = 8, 142 RobCommitWidth: Int = 8, 143 RabCommitWidth: Int = 6, 144 MaxUopSize: Int = 65, 145 EnableRenameSnapshot: Boolean = true, 146 RenameSnapshotNum: Int = 4, 147 FtqSize: Int = 64, 148 EnableLoadFastWakeUp: Boolean = true, // NOTE: not supported now, make it false 149 IntLogicRegs: Int = 32, 150 FpLogicRegs: Int = 32 + 1 + 1, // 1: I2F, 1: stride 151 VecLogicRegs: Int = 32 + 1 + 15, // 15: tmp, 1: vconfig 152 VCONFIG_IDX: Int = 32, 153 NRPhyRegs: Int = 192, 154 VirtualLoadQueueSize: Int = 72, 155 LoadQueueRARSize: Int = 72, 156 LoadQueueRAWSize: Int = 64, // NOTE: make sure that LoadQueueRAWSize is power of 2. 157 RollbackGroupSize: Int = 8, 158 LoadQueueReplaySize: Int = 72, 159 LoadUncacheBufferSize: Int = 20, 160 LoadQueueNWriteBanks: Int = 8, // NOTE: make sure that LoadQueueRARSize/LoadQueueRAWSize is divided by LoadQueueNWriteBanks 161 StoreQueueSize: Int = 64, 162 StoreQueueNWriteBanks: Int = 8, // NOTE: make sure that StoreQueueSize is divided by StoreQueueNWriteBanks 163 StoreQueueForwardWithMask: Boolean = true, 164 VlsQueueSize: Int = 8, 165 RobSize: Int = 160, 166 RabSize: Int = 256, 167 VTypeBufferSize: Int = 64, // used to reorder vtype 168 IssueQueueSize: Int = 24, 169 IssueQueueCompEntrySize: Int = 16, 170 dpParams: DispatchParameters = DispatchParameters( 171 IntDqSize = 16, 172 FpDqSize = 16, 173 LsDqSize = 18, 174 IntDqDeqWidth = 8, 175 FpDqDeqWidth = 6, 176 VecDqDeqWidth = 6, 177 LsDqDeqWidth = 6, 178 ), 179 intPreg: PregParams = IntPregParams( 180 numEntries = 224, 181 numRead = None, 182 numWrite = None, 183 ), 184 fpPreg: PregParams = FpPregParams( 185 numEntries = 192, 186 numRead = None, 187 numWrite = None, 188 ), 189 vfPreg: VfPregParams = VfPregParams( 190 numEntries = 128, 191 numRead = None, 192 numWrite = None, 193 ), 194 prefetcher: Option[PrefetcherParams] = Some(SMSParams()), 195 LoadPipelineWidth: Int = 3, 196 StorePipelineWidth: Int = 2, 197 VecLoadPipelineWidth: Int = 2, 198 VecStorePipelineWidth: Int = 2, 199 VecMemSrcInWidth: Int = 2, 200 VecMemInstWbWidth: Int = 1, 201 VecMemDispatchWidth: Int = 1, 202 StoreBufferSize: Int = 16, 203 StoreBufferThreshold: Int = 7, 204 EnsbufferWidth: Int = 2, 205 LoadDependencyWidth: Int = 2, 206 // ============ VLSU ============ 207 UsQueueSize: Int = 8, 208 VlFlowSize: Int = 32, 209 VlUopSize: Int = 32, 210 VsFlowL1Size: Int = 128, 211 VsFlowL2Size: Int = 32, 212 VsUopSize: Int = 32, 213 // ============================== 214 UncacheBufferSize: Int = 4, 215 EnableLoadToLoadForward: Boolean = false, 216 EnableFastForward: Boolean = true, 217 EnableLdVioCheckAfterReset: Boolean = true, 218 EnableSoftPrefetchAfterReset: Boolean = true, 219 EnableCacheErrorAfterReset: Boolean = true, 220 EnableAccurateLoadError: Boolean = true, 221 EnableUncacheWriteOutstanding: Boolean = false, 222 EnableStorePrefetchAtIssue: Boolean = false, 223 EnableStorePrefetchAtCommit: Boolean = false, 224 EnableAtCommitMissTrigger: Boolean = true, 225 EnableStorePrefetchSMS: Boolean = false, 226 EnableStorePrefetchSPB: Boolean = false, 227 MMUAsidLen: Int = 16, // max is 16, 0 is not supported now 228 MMUVmidLen: Int = 14, 229 ReSelectLen: Int = 7, // load replay queue replay select counter len 230 iwpuParameters: WPUParameters = WPUParameters( 231 enWPU = false, 232 algoName = "mmru", 233 isICache = true, 234 ), 235 dwpuParameters: WPUParameters = WPUParameters( 236 enWPU = false, 237 algoName = "mmru", 238 enCfPred = false, 239 isICache = false, 240 ), 241 itlbParameters: TLBParameters = TLBParameters( 242 name = "itlb", 243 fetchi = true, 244 useDmode = false, 245 NWays = 48, 246 ), 247 itlbPortNum: Int = 2 + ICacheParameters().prefetchPipeNum + 1, 248 ipmpPortNum: Int = 2 + ICacheParameters().prefetchPipeNum + 1, 249 ldtlbParameters: TLBParameters = TLBParameters( 250 name = "ldtlb", 251 NWays = 48, 252 outReplace = false, 253 partialStaticPMP = true, 254 outsideRecvFlush = true, 255 saveLevel = true 256 ), 257 sttlbParameters: TLBParameters = TLBParameters( 258 name = "sttlb", 259 NWays = 48, 260 outReplace = false, 261 partialStaticPMP = true, 262 outsideRecvFlush = true, 263 saveLevel = true 264 ), 265 hytlbParameters: TLBParameters = TLBParameters( 266 name = "hytlb", 267 NWays = 48, 268 outReplace = false, 269 partialStaticPMP = true, 270 outsideRecvFlush = true, 271 saveLevel = true 272 ), 273 pftlbParameters: TLBParameters = TLBParameters( 274 name = "pftlb", 275 NWays = 48, 276 outReplace = false, 277 partialStaticPMP = true, 278 outsideRecvFlush = true, 279 saveLevel = true 280 ), 281 l2ToL1tlbParameters: TLBParameters = TLBParameters( 282 name = "l2tlb", 283 NWays = 48, 284 outReplace = false, 285 partialStaticPMP = true, 286 outsideRecvFlush = true, 287 saveLevel = true 288 ), 289 refillBothTlb: Boolean = false, 290 btlbParameters: TLBParameters = TLBParameters( 291 name = "btlb", 292 NWays = 48, 293 ), 294 l2tlbParameters: L2TLBParameters = L2TLBParameters(), 295 NumPerfCounters: Int = 16, 296 icacheParameters: ICacheParameters = ICacheParameters( 297 tagECC = Some("parity"), 298 dataECC = Some("parity"), 299 replacer = Some("setplru"), 300 nMissEntries = 2, 301 nProbeEntries = 2, 302 nPrefetchEntries = 12, 303 nPrefBufferEntries = 32, 304 ), 305 dcacheParametersOpt: Option[DCacheParameters] = Some(DCacheParameters( 306 tagECC = Some("secded"), 307 dataECC = Some("secded"), 308 replacer = Some("setplru"), 309 nMissEntries = 16, 310 nProbeEntries = 8, 311 nReleaseEntries = 18, 312 nMaxPrefetchEntry = 6, 313 )), 314 L2CacheParamsOpt: Option[L2Param] = Some(L2Param( 315 name = "l2", 316 ways = 8, 317 sets = 1024, // default 512KB L2 318 prefetch = Some(coupledL2.prefetch.PrefetchReceiverParams()) 319 )), 320 L2NBanks: Int = 1, 321 usePTWRepeater: Boolean = false, 322 softTLB: Boolean = false, // dpi-c l1tlb debug only 323 softPTW: Boolean = false, // dpi-c l2tlb debug only 324 softPTWDelay: Int = 1 325){ 326 def vlWidth = log2Up(VLEN) + 1 327 328 val allHistLens = SCHistLens ++ ITTageTableInfos.map(_._2) ++ TageTableInfos.map(_._2) :+ UbtbGHRLength 329 val HistoryLength = allHistLens.max + numBr * FtqSize + 9 // 256 for the predictor configs now 330 331 val intSchdParams = { 332 implicit val schdType: SchedulerType = IntScheduler() 333 SchdBlockParams(Seq( 334 IssueBlockParams(Seq( 335 ExeUnitParams("ALU0", Seq(AluCfg, MulCfg, BkuCfg), Seq(IntWB(port = 0, 0)), Seq(Seq(IntRD(0, 0)), Seq(IntRD(1, 0))), true, 2), 336 ExeUnitParams("BJU0", Seq(BrhCfg, JmpCfg), Seq(IntWB(port = 4, 0)), Seq(Seq(IntRD(8, 0)), Seq(IntRD(7, 1))), true, 2), 337 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 338 IssueBlockParams(Seq( 339 ExeUnitParams("ALU1", Seq(AluCfg, MulCfg, BkuCfg), Seq(IntWB(port = 1, 0)), Seq(Seq(IntRD(2, 0)), Seq(IntRD(3, 0))), true, 2), 340 ExeUnitParams("BJU1", Seq(BrhCfg, JmpCfg), Seq(IntWB(port = 2, 1)), Seq(Seq(IntRD(9, 0)), Seq(IntRD(5, 1))), true, 2), 341 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 342 IssueBlockParams(Seq( 343 ExeUnitParams("ALU2", Seq(AluCfg), Seq(IntWB(port = 2, 0)), Seq(Seq(IntRD(4, 0)), Seq(IntRD(5, 0))), true, 2), 344 ExeUnitParams("BJU2", Seq(BrhCfg, JmpCfg, I2fCfg, VSetRiWiCfg, VSetRiWvfCfg, CsrCfg, FenceCfg, I2vCfg), Seq(IntWB(port = 3, 1), FpWB(port = 4, 0), VfWB(5, 1)), Seq(Seq(IntRD(10, 0)), Seq(IntRD(3, 1)))), 345 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 346 IssueBlockParams(Seq( 347 ExeUnitParams("ALU3", Seq(AluCfg), Seq(IntWB(port = 3, 0)), Seq(Seq(IntRD(6, 0)), Seq(IntRD(7, 0))), true, 2), 348 ExeUnitParams("BJU3", Seq(DivCfg), Seq(IntWB(port = 4, 1)), Seq(Seq(IntRD(11, 0)), Seq(IntRD(1, 1)))), 349 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 350 ), 351 numPregs = intPreg.numEntries, 352 numDeqOutside = 0, 353 schdType = schdType, 354 rfDataWidth = intPreg.dataCfg.dataWidth, 355 numUopIn = dpParams.IntDqDeqWidth, 356 ) 357 } 358 359 val fpSchdParams = { 360 implicit val schdType: SchedulerType = FpScheduler() 361 SchdBlockParams(Seq( 362 IssueBlockParams(Seq( 363 ExeUnitParams("FEX0", Seq(FaluCfg, FcvtCfg, F2vCfg), Seq(FpWB(port = 0, 0), IntWB(port = 0, 1), VfWB(port = 1, 0)), Seq(Seq(FpRD(0, 0)), Seq(FpRD(1, 0)))), 364 ExeUnitParams("FEX1", Seq(FmacCfg), Seq(FpWB(port = 1, 0)), Seq(Seq(FpRD(2, 0)), Seq(FpRD(3, 0)), Seq(FpRD(4, 0)))), 365 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 366 IssueBlockParams(Seq( 367 ExeUnitParams("FEX2", Seq(FaluCfg), Seq(FpWB(port = 2, 0), IntWB(port = 0, 2)), Seq(Seq(FpRD(5, 0)), Seq(FpRD(6, 0)))), 368 ExeUnitParams("FEX3", Seq(FmacCfg), Seq(FpWB(port = 3, 0)), Seq(Seq(FpRD(7, 0)), Seq(FpRD(8, 0)), Seq(FpRD(9, 0)))), 369 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 370 IssueBlockParams(Seq( 371 ExeUnitParams("FEX4", Seq(FdivCfg), Seq(FpWB(port = 4, 0)), Seq(Seq(FpRD(10, 0)), Seq(FpRD(11, 0)))), 372 ExeUnitParams("FEX5", Seq(FdivCfg), Seq(FpWB(port = 5, 0)), Seq(Seq(FpRD(12, 0)), Seq(FpRD(13, 0)))), 373 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 374 ), 375 numPregs = fpPreg.numEntries, 376 numDeqOutside = 0, 377 schdType = schdType, 378 rfDataWidth = fpPreg.dataCfg.dataWidth, 379 numUopIn = dpParams.VecDqDeqWidth, 380 ) 381 } 382 383 val vfSchdParams = { 384 implicit val schdType: SchedulerType = VfScheduler() 385 SchdBlockParams(Seq( 386 IssueBlockParams(Seq( 387 ExeUnitParams("VFEX0", Seq(VfmaCfg, VialuCfg, VimacCfg, VppuCfg), Seq(VfWB(port = 4, 0)), Seq(Seq(VfRD(0, 0)), Seq(VfRD(1, 0)), Seq(VfRD(2, 0)), Seq(VfRD(3, 0)), Seq(VfRD(4, 0)))), 388 ExeUnitParams("VFEX1", Seq(VfaluCfg, VfcvtCfg, VipuCfg, VSetRvfWvfCfg), Seq(VfWB(port = 5, 0), IntWB(port = 2, 2)), Seq(Seq(VfRD(5, 0)), Seq(VfRD(6, 0)), Seq(VfRD(7, 0)), Seq(VfRD(8, 0)), Seq(VfRD(9, 0)))), 389 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 390 IssueBlockParams(Seq( 391 ExeUnitParams("VFEX2", Seq(VfmaCfg, VialuCfg), Seq(VfWB(port = 6, 0)), Seq(Seq(VfRD(7, 1)), Seq(VfRD(8, 1)), Seq(VfRD(9, 1)), Seq(VfRD(5, 1)), Seq(VfRD(6, 1)))), 392 ExeUnitParams("VFEX3", Seq(VfaluCfg, VfcvtCfg), Seq(VfWB(port = 7, 0), IntWB(port = 3, 2)), Seq(Seq(VfRD(3, 1)), Seq(VfRD(4, 1)), Seq(VfRD(0, 1)), Seq(VfRD(1, 1)), Seq(VfRD(2, 1)))), 393 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 394 IssueBlockParams(Seq( 395 ExeUnitParams("VFEX4", Seq(VfdivCfg, VidivCfg), Seq(VfWB(port = 2, 0)), Seq(Seq(VfRD(3, 2)), Seq(VfRD(4, 2)), Seq(VfRD(0, 2)), Seq(VfRD(1, 2)), Seq(VfRD(2, 2)))), 396 ExeUnitParams("VFEX5", Seq(VfdivCfg, VidivCfg), Seq(VfWB(port = 3, 0)), Seq(Seq(VfRD(8, 2)), Seq(VfRD(9, 2)), Seq(VfRD(5, 2)), Seq(VfRD(6, 2)), Seq(VfRD(7, 2)))), 397 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 398 ), 399 numPregs = vfPreg.numEntries, 400 numDeqOutside = 0, 401 schdType = schdType, 402 rfDataWidth = vfPreg.dataCfg.dataWidth, 403 numUopIn = dpParams.VecDqDeqWidth, 404 ) 405 } 406 407 val memSchdParams = { 408 implicit val schdType: SchedulerType = MemScheduler() 409 val rfDataWidth = 64 410 411 SchdBlockParams(Seq( 412 IssueBlockParams(Seq( 413 ExeUnitParams("STA0", Seq(StaCfg, MouCfg), Seq(FakeIntWB()), Seq(Seq(IntRD(8, 1)))), 414 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 415 IssueBlockParams(Seq( 416 ExeUnitParams("STA1", Seq(StaCfg, MouCfg), Seq(FakeIntWB()), Seq(Seq(IntRD(9, 1)))), 417 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 418 IssueBlockParams(Seq( 419 ExeUnitParams("LDU0", Seq(LduCfg), Seq(IntWB(5, 0), FpWB(0, 0)), Seq(Seq(IntRD(12, 0))), true, 2), 420 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 421 IssueBlockParams(Seq( 422 ExeUnitParams("LDU1", Seq(LduCfg), Seq(IntWB(6, 0), FpWB(1, 0)), Seq(Seq(IntRD(13, 0))), true, 2), 423 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 424 IssueBlockParams(Seq( 425 ExeUnitParams("LDU2", Seq(LduCfg), Seq(IntWB(7, 0), FpWB(2, 0)), Seq(Seq(IntRD(14, 0))), true, 2), 426 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 427 IssueBlockParams(Seq( 428 ExeUnitParams("VLSU0", Seq(VlduCfg, VstuCfg), Seq(VfWB(0, 0)), Seq(Seq(VfRD(10, 0)), Seq(VfRD(11, 0)), Seq(VfRD(12, 0)), Seq(VfRD(13, 0)), Seq(VfRD(14, 0)))), 429 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 430 IssueBlockParams(Seq( 431 ExeUnitParams("STD0", Seq(StdCfg, MoudCfg), Seq(), Seq(Seq(IntRD(10, 1), VfRD(12, Int.MaxValue)))), 432 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 433 IssueBlockParams(Seq( 434 ExeUnitParams("STD1", Seq(StdCfg, MoudCfg), Seq(), Seq(Seq(IntRD(11, 1), VfRD(13, Int.MaxValue)))), 435 ), numEntries = IssueQueueSize, numEnq = 2, numComp = IssueQueueCompEntrySize), 436 ), 437 numPregs = intPreg.numEntries max vfPreg.numEntries, 438 numDeqOutside = 0, 439 schdType = schdType, 440 rfDataWidth = rfDataWidth, 441 numUopIn = dpParams.LsDqDeqWidth, 442 ) 443 } 444 445 def PregIdxWidthMax = intPreg.addrWidth max vfPreg.addrWidth 446 447 def iqWakeUpParams = { 448 Seq( 449 WakeUpConfig( 450 Seq("ALU0", "ALU1", "ALU2", "ALU3", "LDU0", "LDU1", "LDU2") -> 451 Seq("ALU0", "BJU0", "ALU1", "BJU1", "ALU2", "BJU2", "ALU3", "BJU3", "LDU0", "LDU1", "LDU2", "STA0", "STA1", "STD0", "STD1") 452 ), 453 WakeUpConfig( 454 Seq("VFEX0", "VFEX1", "VFEX2", "VFEX3") -> 455 Seq("VFEX0", "VFEX1", "VFEX2", "VFEX3", "VFEX4", "VFEX5") 456 ), 457 WakeUpConfig( 458 Seq("VFEX0", "VFEX1", "VFEX2", "VFEX3") -> 459 Seq("STD0", "STD1") 460 ), 461 ).flatten 462 } 463 464 def fakeIntPreg = FakeIntPregParams(intPreg.numEntries, intPreg.numRead, intPreg.numWrite) 465 466 val backendParams: BackendParams = backend.BackendParams( 467 Map( 468 IntScheduler() -> intSchdParams, 469 FpScheduler() -> fpSchdParams, 470 VfScheduler() -> vfSchdParams, 471 MemScheduler() -> memSchdParams, 472 ), 473 Seq( 474 intPreg, 475 fpPreg, 476 vfPreg, 477 fakeIntPreg 478 ), 479 iqWakeUpParams, 480 ) 481} 482 483case object DebugOptionsKey extends Field[DebugOptions] 484 485case class DebugOptions 486( 487 FPGAPlatform: Boolean = false, 488 EnableDifftest: Boolean = false, 489 AlwaysBasicDiff: Boolean = true, 490 EnableDebug: Boolean = false, 491 EnablePerfDebug: Boolean = true, 492 UseDRAMSim: Boolean = false, 493 EnableConstantin: Boolean = false, 494 EnableChiselDB: Boolean = false, 495 AlwaysBasicDB: Boolean = true, 496 EnableTopDown: Boolean = false, 497 EnableRollingDB: Boolean = false 498) 499 500trait HasXSParameter { 501 502 implicit val p: Parameters 503 504 def PAddrBits = p(SoCParamsKey).PAddrBits // PAddrBits is Phyical Memory addr bits 505 506 def coreParams = p(XSCoreParamsKey) 507 def env = p(DebugOptionsKey) 508 509 def XLEN = coreParams.XLEN 510 def VLEN = coreParams.VLEN 511 def ELEN = coreParams.ELEN 512 def HSXLEN = coreParams.HSXLEN 513 val minFLen = 32 514 val fLen = 64 515 def hartIdLen = p(MaxHartIdBits) 516 val xLen = XLEN 517 518 def HasMExtension = coreParams.HasMExtension 519 def HasCExtension = coreParams.HasCExtension 520 def HasHExtension = coreParams.HasHExtension 521 def HasDiv = coreParams.HasDiv 522 def HasIcache = coreParams.HasICache 523 def HasDcache = coreParams.HasDCache 524 def AddrBits = coreParams.AddrBits // AddrBits is used in some cases 525 def GPAddrBits = coreParams.GPAddrBits 526 def VAddrBits = { 527 if(HasHExtension){ 528 coreParams.GPAddrBits 529 }else{ 530 coreParams.VAddrBits 531 } 532 } // VAddrBits is Virtual Memory addr bits 533 534 def AsidLength = coreParams.AsidLength 535 def VmidLength = coreParams.VmidLength 536 def ReSelectLen = coreParams.ReSelectLen 537 def AddrBytes = AddrBits / 8 // unused 538 def DataBits = XLEN 539 def DataBytes = DataBits / 8 540 def VDataBytes = VLEN / 8 541 def HasFPU = coreParams.HasFPU 542 def HasVPU = coreParams.HasVPU 543 def HasCustomCSRCacheOp = coreParams.HasCustomCSRCacheOp 544 def FetchWidth = coreParams.FetchWidth 545 def PredictWidth = FetchWidth * (if (HasCExtension) 2 else 1) 546 def EnableBPU = coreParams.EnableBPU 547 def EnableBPD = coreParams.EnableBPD // enable backing predictor(like Tage) in BPUStage3 548 def EnableRAS = coreParams.EnableRAS 549 def EnableLB = coreParams.EnableLB 550 def EnableLoop = coreParams.EnableLoop 551 def EnableSC = coreParams.EnableSC 552 def EnbaleTlbDebug = coreParams.EnbaleTlbDebug 553 def HistoryLength = coreParams.HistoryLength 554 def EnableGHistDiff = coreParams.EnableGHistDiff 555 def EnableCommitGHistDiff = coreParams.EnableCommitGHistDiff 556 def EnableClockGate = coreParams.EnableClockGate 557 def UbtbGHRLength = coreParams.UbtbGHRLength 558 def UbtbSize = coreParams.UbtbSize 559 def EnableFauFTB = coreParams.EnableFauFTB 560 def FtbSize = coreParams.FtbSize 561 def FtbWays = coreParams.FtbWays 562 def RasSize = coreParams.RasSize 563 def RasSpecSize = coreParams.RasSpecSize 564 def RasCtrSize = coreParams.RasCtrSize 565 566 def getBPDComponents(resp_in: BranchPredictionResp, p: Parameters) = { 567 coreParams.branchPredictor(resp_in, p) 568 } 569 def numBr = coreParams.numBr 570 def TageTableInfos = coreParams.TageTableInfos 571 def TageBanks = coreParams.numBr 572 def SCNRows = coreParams.SCNRows 573 def SCCtrBits = coreParams.SCCtrBits 574 def SCHistLens = coreParams.SCHistLens 575 def SCNTables = coreParams.SCNTables 576 577 def SCTableInfos = Seq.fill(SCNTables)((SCNRows, SCCtrBits)) zip SCHistLens map { 578 case ((n, cb), h) => (n, cb, h) 579 } 580 def ITTageTableInfos = coreParams.ITTageTableInfos 581 type FoldedHistoryInfo = Tuple2[Int, Int] 582 def foldedGHistInfos = 583 (TageTableInfos.map{ case (nRows, h, t) => 584 if (h > 0) 585 Set((h, min(log2Ceil(nRows/numBr), h)), (h, min(h, t)), (h, min(h, t-1))) 586 else 587 Set[FoldedHistoryInfo]() 588 }.reduce(_++_).toSet ++ 589 SCTableInfos.map{ case (nRows, _, h) => 590 if (h > 0) 591 Set((h, min(log2Ceil(nRows/TageBanks), h))) 592 else 593 Set[FoldedHistoryInfo]() 594 }.reduce(_++_).toSet ++ 595 ITTageTableInfos.map{ case (nRows, h, t) => 596 if (h > 0) 597 Set((h, min(log2Ceil(nRows), h)), (h, min(h, t)), (h, min(h, t-1))) 598 else 599 Set[FoldedHistoryInfo]() 600 }.reduce(_++_) ++ 601 Set[FoldedHistoryInfo]((UbtbGHRLength, log2Ceil(UbtbSize))) 602 ).toList 603 604 605 606 def CacheLineSize = coreParams.CacheLineSize 607 def CacheLineHalfWord = CacheLineSize / 16 608 def ExtHistoryLength = HistoryLength + 64 609 def ICacheECCForceError = coreParams.ICacheECCForceError 610 def IBufSize = coreParams.IBufSize 611 def IBufNBank = coreParams.IBufNBank 612 def backendParams: BackendParams = coreParams.backendParams 613 def DecodeWidth = coreParams.DecodeWidth 614 def RenameWidth = coreParams.RenameWidth 615 def CommitWidth = coreParams.CommitWidth 616 def RobCommitWidth = coreParams.RobCommitWidth 617 def RabCommitWidth = coreParams.RabCommitWidth 618 def MaxUopSize = coreParams.MaxUopSize 619 def EnableRenameSnapshot = coreParams.EnableRenameSnapshot 620 def RenameSnapshotNum = coreParams.RenameSnapshotNum 621 def FtqSize = coreParams.FtqSize 622 def EnableLoadFastWakeUp = coreParams.EnableLoadFastWakeUp 623 def IntLogicRegs = coreParams.IntLogicRegs 624 def FpLogicRegs = coreParams.FpLogicRegs 625 def VecLogicRegs = coreParams.VecLogicRegs 626 def VCONFIG_IDX = coreParams.VCONFIG_IDX 627 def IntPhyRegs = coreParams.intPreg.numEntries 628 def FpPhyRegs = coreParams.fpPreg.numEntries 629 def VfPhyRegs = coreParams.vfPreg.numEntries 630 def MaxPhyPregs = IntPhyRegs max VfPhyRegs 631 def PhyRegIdxWidth = log2Up(IntPhyRegs) max log2Up(VfPhyRegs) 632 def RobSize = coreParams.RobSize 633 def RabSize = coreParams.RabSize 634 def VTypeBufferSize = coreParams.VTypeBufferSize 635 def IntRefCounterWidth = log2Ceil(RobSize) 636 def LSQEnqWidth = coreParams.dpParams.LsDqDeqWidth 637 def LSQLdEnqWidth = LSQEnqWidth min backendParams.numLoadDp 638 def LSQStEnqWidth = LSQEnqWidth min backendParams.numStoreDp 639 def VirtualLoadQueueSize = coreParams.VirtualLoadQueueSize 640 def LoadQueueRARSize = coreParams.LoadQueueRARSize 641 def LoadQueueRAWSize = coreParams.LoadQueueRAWSize 642 def RollbackGroupSize = coreParams.RollbackGroupSize 643 def LoadQueueReplaySize = coreParams.LoadQueueReplaySize 644 def LoadUncacheBufferSize = coreParams.LoadUncacheBufferSize 645 def LoadQueueNWriteBanks = coreParams.LoadQueueNWriteBanks 646 def StoreQueueSize = coreParams.StoreQueueSize 647 def StoreQueueNWriteBanks = coreParams.StoreQueueNWriteBanks 648 def StoreQueueForwardWithMask = coreParams.StoreQueueForwardWithMask 649 def VlsQueueSize = coreParams.VlsQueueSize 650 def dpParams = coreParams.dpParams 651 652 def MemIQSizeMax = backendParams.memSchdParams.get.issueBlockParams.map(_.numEntries).max 653 def IQSizeMax = backendParams.allSchdParams.map(_.issueBlockParams.map(_.numEntries).max).max 654 655 def NumRedirect = backendParams.numRedirect 656 def BackendRedirectNum = NumRedirect + 2 //2: ldReplay + Exception 657 def FtqRedirectAheadNum = NumRedirect 658 def LoadPipelineWidth = coreParams.LoadPipelineWidth 659 def StorePipelineWidth = coreParams.StorePipelineWidth 660 def VecLoadPipelineWidth = coreParams.VecLoadPipelineWidth 661 def VecStorePipelineWidth = coreParams.VecStorePipelineWidth 662 def VecMemSrcInWidth = coreParams.VecMemSrcInWidth 663 def VecMemInstWbWidth = coreParams.VecMemInstWbWidth 664 def VecMemDispatchWidth = coreParams.VecMemDispatchWidth 665 def StoreBufferSize = coreParams.StoreBufferSize 666 def StoreBufferThreshold = coreParams.StoreBufferThreshold 667 def EnsbufferWidth = coreParams.EnsbufferWidth 668 def LoadDependencyWidth = coreParams.LoadDependencyWidth 669 def UsQueueSize = coreParams.UsQueueSize 670 def VlFlowSize = coreParams.VlFlowSize 671 def VlUopSize = coreParams.VlUopSize 672 def VsFlowL1Size = coreParams.VsFlowL1Size 673 def VsFlowL2Size = coreParams.VsFlowL2Size 674 def VsUopSize = coreParams.VsUopSize 675 def UncacheBufferSize = coreParams.UncacheBufferSize 676 def EnableLoadToLoadForward = coreParams.EnableLoadToLoadForward 677 def EnableFastForward = coreParams.EnableFastForward 678 def EnableLdVioCheckAfterReset = coreParams.EnableLdVioCheckAfterReset 679 def EnableSoftPrefetchAfterReset = coreParams.EnableSoftPrefetchAfterReset 680 def EnableCacheErrorAfterReset = coreParams.EnableCacheErrorAfterReset 681 def EnableAccurateLoadError = coreParams.EnableAccurateLoadError 682 def EnableUncacheWriteOutstanding = coreParams.EnableUncacheWriteOutstanding 683 def EnableStorePrefetchAtIssue = coreParams.EnableStorePrefetchAtIssue 684 def EnableStorePrefetchAtCommit = coreParams.EnableStorePrefetchAtCommit 685 def EnableAtCommitMissTrigger = coreParams.EnableAtCommitMissTrigger 686 def EnableStorePrefetchSMS = coreParams.EnableStorePrefetchSMS 687 def EnableStorePrefetchSPB = coreParams.EnableStorePrefetchSPB 688 require(LoadPipelineWidth == backendParams.LdExuCnt, "LoadPipelineWidth must be equal exuParameters.LduCnt!") 689 require(StorePipelineWidth == backendParams.StaCnt, "StorePipelineWidth must be equal exuParameters.StuCnt!") 690 def Enable3Load3Store = (LoadPipelineWidth == 3 && StorePipelineWidth == 3) 691 def asidLen = coreParams.MMUAsidLen 692 def vmidLen = coreParams.MMUVmidLen 693 def BTLBWidth = coreParams.LoadPipelineWidth + coreParams.StorePipelineWidth 694 def refillBothTlb = coreParams.refillBothTlb 695 def iwpuParam = coreParams.iwpuParameters 696 def dwpuParam = coreParams.dwpuParameters 697 def itlbParams = coreParams.itlbParameters 698 def ldtlbParams = coreParams.ldtlbParameters 699 def sttlbParams = coreParams.sttlbParameters 700 def hytlbParams = coreParams.hytlbParameters 701 def pftlbParams = coreParams.pftlbParameters 702 def l2ToL1Params = coreParams.l2ToL1tlbParameters 703 def btlbParams = coreParams.btlbParameters 704 def l2tlbParams = coreParams.l2tlbParameters 705 def NumPerfCounters = coreParams.NumPerfCounters 706 707 def instBytes = if (HasCExtension) 2 else 4 708 def instOffsetBits = log2Ceil(instBytes) 709 710 def icacheParameters = coreParams.icacheParameters 711 def dcacheParameters = coreParams.dcacheParametersOpt.getOrElse(DCacheParameters()) 712 713 // dcache block cacheline when lr for LRSCCycles - LRSCBackOff cycles 714 // for constrained LR/SC loop 715 def LRSCCycles = 64 716 // for lr storm 717 def LRSCBackOff = 8 718 719 // cache hierarchy configurations 720 def l1BusDataWidth = 256 721 722 // load violation predict 723 def ResetTimeMax2Pow = 20 //1078576 724 def ResetTimeMin2Pow = 10 //1024 725 // wait table parameters 726 def WaitTableSize = 1024 727 def MemPredPCWidth = log2Up(WaitTableSize) 728 def LWTUse2BitCounter = true 729 // store set parameters 730 def SSITSize = WaitTableSize 731 def LFSTSize = 32 732 def SSIDWidth = log2Up(LFSTSize) 733 def LFSTWidth = 4 734 def StoreSetEnable = true // LWT will be disabled if SS is enabled 735 def LFSTEnable = true 736 737 def PCntIncrStep: Int = 6 738 def numPCntHc: Int = 25 739 def numPCntPtw: Int = 19 740 741 def numCSRPCntFrontend = 8 742 def numCSRPCntCtrl = 8 743 def numCSRPCntLsu = 8 744 def numCSRPCntHc = 5 745 def printEventCoding = true 746 747 // Parameters for Sdtrig extension 748 protected def TriggerNum = 4 749 protected def TriggerChainMaxLength = 2 750} 751