Parameters.scala 15.4 KB
Newer Older
L
Lemover 已提交
1 2
/***************************************************************************************
* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences
Y
Yinan Xu 已提交
3
* Copyright (c) 2020-2021 Peng Cheng Laboratory
L
Lemover 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16
*
* XiangShan is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*          http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*
* See the Mulan PSL v2 for more details.
***************************************************************************************/

17 18 19 20 21 22 23
package xiangshan

import chipsalliance.rocketchip.config.{Field, Parameters}
import chisel3._
import chisel3.util._
import xiangshan.backend.exu._
import xiangshan.backend.dispatch.DispatchParameters
24
import xiangshan.cache.DCacheParameters
25
import xiangshan.cache.prefetch._
26 27
import xiangshan.frontend.{BIM, BasePredictor, BranchPredictionResp, FTB, FakePredictor, MicroBTB, RAS, Tage, ITTage, Tage_SC}
import xiangshan.frontend.icache.ICacheParameters
28
import xiangshan.cache.mmu.{L2TLBParameters, TLBParameters}
29
import freechips.rocketchip.diplomacy.AddressSet
30
import system.SoCParamsKey
31 32
import huancun._
import huancun.debug._
33
import scala.math.min
J
Jiawei Lin 已提交
34 35 36

case object XSTileKey extends Field[Seq[XSCoreParameters]]

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
case object XSCoreParamsKey extends Field[XSCoreParameters]

case class XSCoreParameters
(
  HasPrefetch: Boolean = false,
  HartId: Int = 0,
  XLEN: Int = 64,
  HasMExtension: Boolean = true,
  HasCExtension: Boolean = true,
  HasDiv: Boolean = true,
  HasICache: Boolean = true,
  HasDCache: Boolean = true,
  AddrBits: Int = 64,
  VAddrBits: Int = 39,
  HasFPU: Boolean = true,
Z
zhanglinjuan 已提交
52
  HasCustomCSRCacheOp: Boolean = true,
53
  FetchWidth: Int = 8,
54
  AsidLength: Int = 16,
55 56 57 58 59
  EnableBPU: Boolean = true,
  EnableBPD: Boolean = true,
  EnableRAS: Boolean = true,
  EnableLB: Boolean = false,
  EnableLoop: Boolean = true,
60
  EnableSC: Boolean = true,
61 62 63
  EnbaleTlbDebug: Boolean = false,
  EnableJal: Boolean = false,
  EnableUBTB: Boolean = true,
64
  UbtbGHRLength: Int = 4,
65
  // HistoryLength: Int = 512,
66
  EnableGHistDiff: Boolean = true,
67
  UbtbSize: Int = 256,
68
  FtbSize: Int = 2048,
69
  RasSize: Int = 32,
70
  CacheLineSize: Int = 512,
71
  FtbWays: Int = 4,
72 73
  TageTableInfos: Seq[Tuple3[Int,Int,Int]] =
  //       Sets  Hist   Tag
L
Lingrui98 已提交
74 75 76 77 78 79 80 81 82 83 84 85
    // Seq(( 2048,    2,    8),
    //     ( 2048,    9,    8),
    //     ( 2048,   13,    8),
    //     ( 2048,   20,    8),
    //     ( 2048,   26,    8),
    //     ( 2048,   44,    8),
    //     ( 2048,   73,    8),
    //     ( 2048,  256,    8)),
    Seq(( 4096,    8,    8),
        ( 4096,   13,    8),
        ( 4096,   32,    8),
        ( 4096,  119,    8)),
86 87
  ITTageTableInfos: Seq[Tuple3[Int,Int,Int]] =
  //      Sets  Hist   Tag
L
Lingrui98 已提交
88
    Seq(( 256,    4,    9),
89
        ( 256,    8,    9),
L
Lingrui98 已提交
90
        ( 512,   13,    9),
91
        ( 512,   16,    9),
92
        ( 512,   32,    9)),
93 94
  SCNRows: Int = 512,
  SCNTables: Int = 4,
95
  SCCtrBits: Int = 6,
96
  SCHistLens: Seq[Int] = Seq(0, 4, 10, 16),
97
  numBr: Int = 2,
98 99
  branchPredictor: Function2[BranchPredictionResp, Parameters, Tuple2[Seq[BasePredictor], BranchPredictionResp]] =
    ((resp_in: BranchPredictionResp, p: Parameters) => {
Z
zoujr 已提交
100 101 102 103 104 105
      // val loop = Module(new LoopPredictor)
      // val tage = (if(EnableBPD) { if (EnableSC) Module(new Tage_SC)
      //                             else          Module(new Tage) }
      //             else          { Module(new FakeTage) })
      val ftb = Module(new FTB()(p))
      val ubtb = Module(new MicroBTB()(p))
106
      // val bim = Module(new BIM()(p))
107
      val tage = Module(new Tage_SC()(p))
L
Lingrui98 已提交
108
      val ras = Module(new RAS()(p))
109
      val ittage = Module(new ITTage()(p))
L
Lingrui98 已提交
110
      // val tage = Module(new Tage()(p))
Z
zoujr 已提交
111
      // val fake = Module(new FakePredictor()(p))
Z
zoujr 已提交
112 113

      // val preds = Seq(loop, tage, btb, ubtb, bim)
114
      val preds = Seq(ubtb, tage, ftb, ittage, ras)
Z
zoujr 已提交
115 116 117 118 119 120 121
      preds.map(_.io := DontCare)

      // ubtb.io.resp_in(0)  := resp_in
      // bim.io.resp_in(0)   := ubtb.io.resp
      // btb.io.resp_in(0)   := bim.io.resp
      // tage.io.resp_in(0)  := btb.io.resp
      // loop.io.resp_in(0)  := tage.io.resp
122
      ubtb.io.in.bits.resp_in(0) := resp_in
123 124
      tage.io.in.bits.resp_in(0) := ubtb.io.out.resp
      ftb.io.in.bits.resp_in(0)  := tage.io.out.resp
125 126
      ittage.io.in.bits.resp_in(0)  := ftb.io.out.resp
      ras.io.in.bits.resp_in(0) := ittage.io.out.resp
Y
Yinan Xu 已提交
127

L
Lingrui98 已提交
128
      (preds, ras.io.out.resp)
Z
zoujr 已提交
129
    }),
130 131 132 133
  IBufSize: Int = 48,
  DecodeWidth: Int = 6,
  RenameWidth: Int = 6,
  CommitWidth: Int = 6,
L
Lingrui98 已提交
134
  FtqSize: Int = 64,
135 136
  EnableLoadFastWakeUp: Boolean = true, // NOTE: not supported now, make it false
  IssQueSize: Int = 16,
137
  NRPhyRegs: Int = 192,
138 139
  LoadQueueSize: Int = 80,
  StoreQueueSize: Int = 64,
140
  RobSize: Int = 256,
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
  dpParams: DispatchParameters = DispatchParameters(
    IntDqSize = 16,
    FpDqSize = 16,
    LsDqSize = 16,
    IntDqDeqWidth = 4,
    FpDqDeqWidth = 4,
    LsDqDeqWidth = 4
  ),
  exuParameters: ExuParameters = ExuParameters(
    JmpCnt = 1,
    AluCnt = 4,
    MulCnt = 0,
    MduCnt = 2,
    FmacCnt = 4,
    FmiscCnt = 2,
    FmiscDivSqrtCnt = 0,
    LduCnt = 2,
    StuCnt = 2
  ),
  LoadPipelineWidth: Int = 2,
  StorePipelineWidth: Int = 2,
  StoreBufferSize: Int = 16,
163
  StoreBufferThreshold: Int = 7,
164
  EnsbufferWidth: Int = 2,
165
  EnableLoadToLoadForward: Boolean = false,
W
William Wang 已提交
166
  EnableFastForward: Boolean = false,
167
  EnableLdVioCheckAfterReset: Boolean = true,
168 169
  EnableSoftPrefetchAfterReset: Boolean = true,
  EnableCacheErrorAfterReset: Boolean = true,
170
  EnableAccurateLoadError: Boolean = true,
171
  MMUAsidLen: Int = 16, // max is 16, 0 is not supported now
172 173 174 175
  itlbParameters: TLBParameters = TLBParameters(
    name = "itlb",
    fetchi = true,
    useDmode = false,
J
Jay 已提交
176 177
    sameCycle = false,
    missSameCycle = true,
178
    normalNWays = 32,
179
    normalReplacer = Some("plru"),
180
    superNWays = 4,
181 182 183 184 185 186 187 188 189 190 191
    superReplacer = Some("plru"),
    shouldBlock = true
  ),
  ldtlbParameters: TLBParameters = TLBParameters(
    name = "ldtlb",
    normalNSets = 128,
    normalNWays = 1,
    normalAssociative = "sa",
    normalReplacer = Some("setplru"),
    superNWays = 8,
    normalAsVictim = true,
192
    outReplace = true,
193
    partialStaticPMP = true,
194
    saveLevel = true
195 196 197 198 199 200 201 202 203
  ),
  sttlbParameters: TLBParameters = TLBParameters(
    name = "sttlb",
    normalNSets = 128,
    normalNWays = 1,
    normalAssociative = "sa",
    normalReplacer = Some("setplru"),
    superNWays = 8,
    normalAsVictim = true,
204
    outReplace = true,
205
    partialStaticPMP = true,
206
    saveLevel = true
207
  ),
208
  refillBothTlb: Boolean = false,
209 210 211 212 213 214
  btlbParameters: TLBParameters = TLBParameters(
    name = "btlb",
    normalNSets = 1,
    normalNWays = 64,
    superNWays = 4,
  ),
215
  l2tlbParameters: L2TLBParameters = L2TLBParameters(),
216
  NumPerfCounters: Int = 16,
217 218 219 220
  icacheParameters: ICacheParameters = ICacheParameters(
    tagECC = Some("parity"),
    dataECC = Some("parity"),
    replacer = Some("setplru"),
221
    nMissEntries = 2,
222
    nProbeEntries = 2,
223 224
    nPrefetchEntries = 2,
    hasPrefetch = true,
225
  ),
J
Jiawei Lin 已提交
226
  dcacheParametersOpt: Option[DCacheParameters] = Some(DCacheParameters(
227 228 229 230
    tagECC = Some("secded"),
    dataECC = Some("secded"),
    replacer = Some("setplru"),
    nMissEntries = 16,
W
William Wang 已提交
231 232
    nProbeEntries = 8,
    nReleaseEntries = 18
J
Jiawei Lin 已提交
233 234
  )),
  L2CacheParamsOpt: Option[HCCacheParameters] = Some(HCCacheParameters(
235 236 237 238 239
    name = "l2",
    level = 2,
    ways = 8,
    sets = 1024, // default 512KB L2
    prefetch = Some(huancun.prefetch.BOPParameters())
J
Jiawei Lin 已提交
240
  )),
J
Jiawei Lin 已提交
241
  L2NBanks: Int = 1,
242
  usePTWRepeater: Boolean = false,
J
Jiawei Lin 已提交
243
  softPTW: Boolean = false // dpi-c debug only
244
){
245 246 247
  val allHistLens = SCHistLens ++ ITTageTableInfos.map(_._2) ++ TageTableInfos.map(_._2) :+ UbtbGHRLength
  val HistoryLength = allHistLens.max + numBr * FtqSize + 9 // 256 for the predictor configs now

248
  val loadExuConfigs = Seq.fill(exuParameters.LduCnt)(LdExeUnitCfg)
249
  val storeExuConfigs = Seq.fill(exuParameters.StuCnt)(StaExeUnitCfg) ++ Seq.fill(exuParameters.StuCnt)(StdExeUnitCfg)
250

251
  val intExuConfigs = (Seq.fill(exuParameters.AluCnt)(AluExeUnitCfg) ++
252
    Seq.fill(exuParameters.MduCnt)(MulDivExeUnitCfg) :+ JumpCSRExeUnitCfg)
253 254 255 256 257 258 259 260 261 262 263 264

  val fpExuConfigs =
    Seq.fill(exuParameters.FmacCnt)(FmacExeUnitCfg) ++
      Seq.fill(exuParameters.FmiscCnt)(FmiscExeUnitCfg)

  val exuConfigs: Seq[ExuConfig] = intExuConfigs ++ fpExuConfigs ++ loadExuConfigs ++ storeExuConfigs
}

case object DebugOptionsKey extends Field[DebugOptions]

case class DebugOptions
(
265 266
  FPGAPlatform: Boolean = false,
  EnableDifftest: Boolean = false,
267
  AlwaysBasicDiff: Boolean = true,
268
  EnableDebug: Boolean = false,
269 270 271 272 273 274 275 276
  EnablePerfDebug: Boolean = true,
  UseDRAMSim: Boolean = false
)

trait HasXSParameter {

  implicit val p: Parameters

277 278
  val PAddrBits = p(SoCParamsKey).PAddrBits // PAddrBits is Phyical Memory addr bits

279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
  val coreParams = p(XSCoreParamsKey)
  val env = p(DebugOptionsKey)

  val XLEN = coreParams.XLEN
  val minFLen = 32
  val fLen = 64
  def xLen = XLEN

  val HasMExtension = coreParams.HasMExtension
  val HasCExtension = coreParams.HasCExtension
  val HasDiv = coreParams.HasDiv
  val HasIcache = coreParams.HasICache
  val HasDcache = coreParams.HasDCache
  val AddrBits = coreParams.AddrBits // AddrBits is used in some cases
  val VAddrBits = coreParams.VAddrBits // VAddrBits is Virtual Memory addr bits
294
  val AsidLength = coreParams.AsidLength
295 296 297 298
  val AddrBytes = AddrBits / 8 // unused
  val DataBits = XLEN
  val DataBytes = DataBits / 8
  val HasFPU = coreParams.HasFPU
Z
zhanglinjuan 已提交
299
  val HasCustomCSRCacheOp = coreParams.HasCustomCSRCacheOp
300 301 302 303 304 305 306 307 308 309
  val FetchWidth = coreParams.FetchWidth
  val PredictWidth = FetchWidth * (if (HasCExtension) 2 else 1)
  val EnableBPU = coreParams.EnableBPU
  val EnableBPD = coreParams.EnableBPD // enable backing predictor(like Tage) in BPUStage3
  val EnableRAS = coreParams.EnableRAS
  val EnableLB = coreParams.EnableLB
  val EnableLoop = coreParams.EnableLoop
  val EnableSC = coreParams.EnableSC
  val EnbaleTlbDebug = coreParams.EnbaleTlbDebug
  val HistoryLength = coreParams.HistoryLength
310
  val EnableGHistDiff = coreParams.EnableGHistDiff
311
  val UbtbGHRLength = coreParams.UbtbGHRLength
312 313 314
  val UbtbSize = coreParams.UbtbSize
  val FtbSize = coreParams.FtbSize
  val FtbWays = coreParams.FtbWays
315
  val RasSize = coreParams.RasSize
Z
zoujr 已提交
316

317 318
  def getBPDComponents(resp_in: BranchPredictionResp, p: Parameters) = {
    coreParams.branchPredictor(resp_in, p)
Z
zoujr 已提交
319
  }
320 321
  val numBr = coreParams.numBr
  val TageTableInfos = coreParams.TageTableInfos
L
Lingrui98 已提交
322
  val TageBanks = coreParams.numBr
323 324
  val SCNRows = coreParams.SCNRows
  val SCCtrBits = coreParams.SCCtrBits
L
Lingrui98 已提交
325 326
  val SCHistLens = coreParams.SCHistLens
  val SCNTables = coreParams.SCNTables
327

L
Lingrui98 已提交
328 329
  val SCTableInfos = Seq.fill(SCNTables)((SCNRows, SCCtrBits)) zip SCHistLens map {
    case ((n, cb), h) => (n, cb, h)
330 331 332 333
  }
  val ITTageTableInfos = coreParams.ITTageTableInfos
  type FoldedHistoryInfo = Tuple2[Int, Int]
  val foldedGHistInfos =
334
    (TageTableInfos.map{ case (nRows, h, t) =>
335
      if (h > 0)
336
        Set((h, min(log2Ceil(nRows/numBr), h)), (h, min(h, t)), (h, min(h, t-1)))
337 338
      else
        Set[FoldedHistoryInfo]()
339
    }.reduce(_++_).toSet ++
L
Lingrui98 已提交
340
    SCTableInfos.map{ case (nRows, _, h) =>
341
      if (h > 0)
L
Lingrui98 已提交
342
        Set((h, min(log2Ceil(nRows/TageBanks), h)))
343 344
      else
        Set[FoldedHistoryInfo]()
L
Lingrui98 已提交
345
    }.reduce(_++_).toSet ++
346 347 348 349 350
    ITTageTableInfos.map{ case (nRows, h, t) =>
      if (h > 0)
        Set((h, min(log2Ceil(nRows), h)), (h, min(h, t)), (h, min(h, t-1)))
      else
        Set[FoldedHistoryInfo]()
351 352 353
    }.reduce(_++_) ++
      Set[FoldedHistoryInfo]((UbtbGHRLength, log2Ceil(UbtbSize)))
    ).toList
354 355
  

Z
zoujr 已提交
356

357 358 359 360 361 362 363 364 365 366 367 368
  val CacheLineSize = coreParams.CacheLineSize
  val CacheLineHalfWord = CacheLineSize / 16
  val ExtHistoryLength = HistoryLength + 64
  val IBufSize = coreParams.IBufSize
  val DecodeWidth = coreParams.DecodeWidth
  val RenameWidth = coreParams.RenameWidth
  val CommitWidth = coreParams.CommitWidth
  val FtqSize = coreParams.FtqSize
  val IssQueSize = coreParams.IssQueSize
  val EnableLoadFastWakeUp = coreParams.EnableLoadFastWakeUp
  val NRPhyRegs = coreParams.NRPhyRegs
  val PhyRegIdxWidth = log2Up(NRPhyRegs)
Y
Yinan Xu 已提交
369
  val RobSize = coreParams.RobSize
370
  val IntRefCounterWidth = log2Ceil(RobSize)
371 372 373 374 375
  val LoadQueueSize = coreParams.LoadQueueSize
  val StoreQueueSize = coreParams.StoreQueueSize
  val dpParams = coreParams.dpParams
  val exuParameters = coreParams.exuParameters
  val NRMemReadPorts = exuParameters.LduCnt + 2 * exuParameters.StuCnt
376 377 378 379
  val NRIntReadPorts = 2 * exuParameters.AluCnt + NRMemReadPorts
  val NRIntWritePorts = exuParameters.AluCnt + exuParameters.MduCnt + exuParameters.LduCnt
  val NRFpReadPorts = 3 * exuParameters.FmacCnt + exuParameters.StuCnt
  val NRFpWritePorts = exuParameters.FpExuCnt + exuParameters.LduCnt
380 381 382
  val LoadPipelineWidth = coreParams.LoadPipelineWidth
  val StorePipelineWidth = coreParams.StorePipelineWidth
  val StoreBufferSize = coreParams.StoreBufferSize
383
  val StoreBufferThreshold = coreParams.StoreBufferThreshold
384
  val EnsbufferWidth = coreParams.EnsbufferWidth
385
  val EnableLoadToLoadForward = coreParams.EnableLoadToLoadForward
386
  val EnableFastForward = coreParams.EnableFastForward
W
William Wang 已提交
387
  val EnableLdVioCheckAfterReset = coreParams.EnableLdVioCheckAfterReset
388 389
  val EnableSoftPrefetchAfterReset = coreParams.EnableSoftPrefetchAfterReset
  val EnableCacheErrorAfterReset = coreParams.EnableCacheErrorAfterReset
390
  val EnableAccurateLoadError = coreParams.EnableAccurateLoadError
391
  val asidLen = coreParams.MMUAsidLen
392
  val BTLBWidth = coreParams.LoadPipelineWidth + coreParams.StorePipelineWidth
393
  val refillBothTlb = coreParams.refillBothTlb
394 395 396 397
  val itlbParams = coreParams.itlbParameters
  val ldtlbParams = coreParams.ldtlbParameters
  val sttlbParams = coreParams.sttlbParameters
  val btlbParams = coreParams.btlbParameters
398
  val l2tlbParams = coreParams.l2tlbParameters
399 400
  val NumPerfCounters = coreParams.NumPerfCounters

401 402
  val NumRs = (exuParameters.JmpCnt+1)/2 + (exuParameters.AluCnt+1)/2 + (exuParameters.MulCnt+1)/2 +
              (exuParameters.MduCnt+1)/2 + (exuParameters.FmacCnt+1)/2 +  + (exuParameters.FmiscCnt+1)/2 +
403
              (exuParameters.FmiscDivSqrtCnt+1)/2 + (exuParameters.LduCnt+1)/2 +
404
              (exuParameters.StuCnt+1)/2 + (exuParameters.StuCnt+1)/2
405

406 407 408
  val instBytes = if (HasCExtension) 2 else 4
  val instOffsetBits = log2Ceil(instBytes)

409
  val icacheParameters = coreParams.icacheParameters
J
Jiawei Lin 已提交
410
  val dcacheParameters = coreParams.dcacheParametersOpt.getOrElse(DCacheParameters())
411

412 413 414 415 416
  // dcache block cacheline when lr for LRSCCycles - LRSCBackOff cycles
  // for constrained LR/SC loop 
  val LRSCCycles = 64
  // for lr storm
  val LRSCBackOff = 8
417 418 419 420

  // cache hierarchy configurations
  val l1BusDataWidth = 256

421 422 423 424 425 426 427 428 429 430 431 432 433
  // load violation predict
  val ResetTimeMax2Pow = 20 //1078576
  val ResetTimeMin2Pow = 10 //1024
  // wait table parameters
  val WaitTableSize = 1024
  val MemPredPCWidth = log2Up(WaitTableSize)
  val LWTUse2BitCounter = true
  // store set parameters
  val SSITSize = WaitTableSize
  val LFSTSize = 32
  val SSIDWidth = log2Up(LFSTSize)
  val LFSTWidth = 4
  val StoreSetEnable = true // LWT will be disabled if SS is enabled
434

435 436 437 438
  val loadExuConfigs = coreParams.loadExuConfigs
  val storeExuConfigs = coreParams.storeExuConfigs

  val intExuConfigs = coreParams.intExuConfigs
439

440
  val fpExuConfigs = coreParams.fpExuConfigs
441

442
  val exuConfigs = coreParams.exuConfigs
443

444 445 446 447 448 449 450 451
  val PCntIncrStep: Int = 6
  val numPCntHc: Int = 25
  val numPCntPtw: Int = 19

  val numCSRPCntFrontend = 8
  val numCSRPCntCtrl     = 8
  val numCSRPCntLsu      = 8
  val numCSRPCntHc       = 5
452
}