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