Parameters.scala 15.0 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 26
import xiangshan.cache.prefetch._
import huancun.{CacheParameters, HCCacheParameters}
27
import xiangshan.frontend.{BIM, BasePredictor, BranchPredictionResp, FTB, FakePredictor, ICacheParameters, MicroBTB, RAS, Tage, ITTage, Tage_SC}
28
import xiangshan.cache.mmu.{TLBParameters, L2TLBParameters}
29
import freechips.rocketchip.diplomacy.AddressSet
30
import system.SoCParamsKey
31
import scala.math.min
J
Jiawei Lin 已提交
32 33 34

case object XSTileKey extends Field[Seq[XSCoreParameters]]

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
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 已提交
50
  HasCustomCSRCacheOp: Boolean = true,
51
  FetchWidth: Int = 8,
52
  AsidLength: Int = 16,
53 54 55 56 57
  EnableBPU: Boolean = true,
  EnableBPD: Boolean = true,
  EnableRAS: Boolean = true,
  EnableLB: Boolean = false,
  EnableLoop: Boolean = true,
58
  EnableSC: Boolean = true,
59 60 61
  EnbaleTlbDebug: Boolean = false,
  EnableJal: Boolean = false,
  EnableUBTB: Boolean = true,
L
Lingrui98 已提交
62
  HistoryLength: Int = 256,
63
  PathHistoryLength: Int = 16,
64 65 66
  BtbSize: Int = 2048,
  JbtacSize: Int = 1024,
  JbtacBanks: Int = 8,
67
  RasSize: Int = 32,
68 69 70
  CacheLineSize: Int = 512,
  UBtbWays: Int = 16,
  BtbWays: Int = 2,
71 72 73 74 75 76 77
  TageTableInfos: Seq[Tuple3[Int,Int,Int]] =
  //       Sets  Hist   Tag
    Seq(( 128*8,    2,    7),
        ( 128*8,    4,    7),
        ( 256*8,    8,    8),
        ( 256*8,   16,    8),
        ( 128*8,   32,    9),
78
        ( 128*8,   65,    9)),
L
Lingrui98 已提交
79
  TageBanks: Int = 2,
80 81
  ITTageTableInfos: Seq[Tuple3[Int,Int,Int]] =
  //      Sets  Hist   Tag
82 83 84 85 86 87
    Seq(( 512,    0,    0),
        ( 256,    4,    8),
        ( 256,    8,    8),
        ( 512,   12,    8),
        ( 512,   16,    8),
        ( 512,   32,    8)),
88 89 90 91
  SCNRows: Int = 1024,
  SCNTables: Int = 6,
  SCCtrBits: Int = 6,
  numBr: Int = 2,
92 93
  branchPredictor: Function2[BranchPredictionResp, Parameters, Tuple2[Seq[BasePredictor], BranchPredictionResp]] =
    ((resp_in: BranchPredictionResp, p: Parameters) => {
Z
zoujr 已提交
94 95 96 97 98 99 100
      // 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))
      val bim = Module(new BIM()(p))
101
      val tage = Module(new Tage_SC()(p))
L
Lingrui98 已提交
102
      val ras = Module(new RAS()(p))
103
      val ittage = Module(new ITTage()(p))
L
Lingrui98 已提交
104
      // val tage = Module(new Tage()(p))
Z
zoujr 已提交
105
      // val fake = Module(new FakePredictor()(p))
Z
zoujr 已提交
106 107

      // val preds = Seq(loop, tage, btb, ubtb, bim)
108
      val preds = Seq(bim, ubtb, tage, ftb, ittage, ras)
Z
zoujr 已提交
109 110 111 112 113 114 115
      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
L
Lingrui98 已提交
116
      bim.io.in.bits.resp_in(0)  := resp_in
117 118 119
      ubtb.io.in.bits.resp_in(0) := bim.io.out.resp
      tage.io.in.bits.resp_in(0) := ubtb.io.out.resp
      ftb.io.in.bits.resp_in(0)  := tage.io.out.resp
120 121
      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 已提交
122

L
Lingrui98 已提交
123
      (preds, ras.io.out.resp)
Z
zoujr 已提交
124
    }),
125 126 127 128
  IBufSize: Int = 48,
  DecodeWidth: Int = 6,
  RenameWidth: Int = 6,
  CommitWidth: Int = 6,
L
Lingrui98 已提交
129
  FtqSize: Int = 64,
130 131
  EnableLoadFastWakeUp: Boolean = true, // NOTE: not supported now, make it false
  IssQueSize: Int = 16,
132
  NRPhyRegs: Int = 192,
133 134 135 136
  NRIntReadPorts: Int = 14,
  NRIntWritePorts: Int = 8,
  NRFpReadPorts: Int = 14,
  NRFpWritePorts: Int = 8,
137 138
  LoadQueueSize: Int = 80,
  StoreQueueSize: Int = 64,
139
  RobSize: Int = 256,
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
  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,
162
  StoreBufferThreshold: Int = 7,
163
  EnableFastForward: Boolean = true,
164
  EnableLdVioCheckAfterReset: Boolean = true,
165
  RefillSize: Int = 512,
166
  MMUAsidLen: Int = 16, // max is 16, 0 is not supported now
167 168 169 170 171
  itlbParameters: TLBParameters = TLBParameters(
    name = "itlb",
    fetchi = true,
    useDmode = false,
    sameCycle = true,
172
    normalNWays = 32,
173
    normalReplacer = Some("plru"),
174
    superNWays = 4,
175 176 177 178 179 180 181 182 183 184 185
    superReplacer = Some("plru"),
    shouldBlock = true
  ),
  ldtlbParameters: TLBParameters = TLBParameters(
    name = "ldtlb",
    normalNSets = 128,
    normalNWays = 1,
    normalAssociative = "sa",
    normalReplacer = Some("setplru"),
    superNWays = 8,
    normalAsVictim = true,
186 187
    outReplace = true,
    saveLevel = true
188 189 190 191 192 193 194 195 196
  ),
  sttlbParameters: TLBParameters = TLBParameters(
    name = "sttlb",
    normalNSets = 128,
    normalNWays = 1,
    normalAssociative = "sa",
    normalReplacer = Some("setplru"),
    superNWays = 8,
    normalAsVictim = true,
197 198
    outReplace = true,
    saveLevel = true
199
  ),
200
  refillBothTlb: Boolean = false,
201 202 203 204 205 206
  btlbParameters: TLBParameters = TLBParameters(
    name = "btlb",
    normalNSets = 1,
    normalNWays = 64,
    superNWays = 4,
  ),
207
  l2tlbParameters: L2TLBParameters = L2TLBParameters(),
L
Lemover 已提交
208
  NumPMP: Int = 16, // 0 or 16 or 64
209
  NumPMA: Int = 16,
210
  NumPerfCounters: Int = 16,
211 212 213 214 215 216
  icacheParameters: ICacheParameters = ICacheParameters(
    tagECC = Some("parity"),
    dataECC = Some("parity"),
    replacer = Some("setplru"),
    nMissEntries = 2
  ),
J
Jiawei Lin 已提交
217
  dcacheParametersOpt: Option[DCacheParameters] = Some(DCacheParameters(
218 219 220 221
    tagECC = Some("secded"),
    dataECC = Some("secded"),
    replacer = Some("setplru"),
    nMissEntries = 16,
W
William Wang 已提交
222 223
    nProbeEntries = 8,
    nReleaseEntries = 18
J
Jiawei Lin 已提交
224 225
  )),
  L2CacheParamsOpt: Option[HCCacheParameters] = Some(HCCacheParameters(
226 227 228 229 230
    name = "l2",
    level = 2,
    ways = 8,
    sets = 1024, // default 512KB L2
    prefetch = Some(huancun.prefetch.BOPParameters())
J
Jiawei Lin 已提交
231
  )),
J
Jiawei Lin 已提交
232
  L2NBanks: Int = 1,
233
  usePTWRepeater: Boolean = false,
J
Jiawei Lin 已提交
234
  softPTW: Boolean = false // dpi-c debug only
235 236
){
  val loadExuConfigs = Seq.fill(exuParameters.LduCnt)(LdExeUnitCfg)
237
  val storeExuConfigs = Seq.fill(exuParameters.StuCnt)(StaExeUnitCfg) ++ Seq.fill(exuParameters.StuCnt)(StdExeUnitCfg)
238

239
  val intExuConfigs = (Seq.fill(exuParameters.AluCnt)(AluExeUnitCfg) ++
240
    Seq.fill(exuParameters.MduCnt)(MulDivExeUnitCfg) :+ JumpCSRExeUnitCfg)
241 242 243 244 245 246 247 248 249 250 251 252

  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
(
253 254
  FPGAPlatform: Boolean = false,
  EnableDifftest: Boolean = false,
255
  AlwaysBasicDiff: Boolean = true,
256
  EnableDebug: Boolean = false,
257 258 259 260 261 262 263 264
  EnablePerfDebug: Boolean = true,
  UseDRAMSim: Boolean = false
)

trait HasXSParameter {

  implicit val p: Parameters

265 266
  val PAddrBits = p(SoCParamsKey).PAddrBits // PAddrBits is Phyical Memory addr bits

267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
  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
282
  val AsidLength = coreParams.AsidLength
283 284 285 286
  val AddrBytes = AddrBits / 8 // unused
  val DataBits = XLEN
  val DataBytes = DataBits / 8
  val HasFPU = coreParams.HasFPU
Z
zhanglinjuan 已提交
287
  val HasCustomCSRCacheOp = coreParams.HasCustomCSRCacheOp
288 289 290 291 292 293 294 295 296 297
  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
298
  val PathHistoryLength = coreParams.PathHistoryLength
299 300 301 302 303 304 305
  val BtbSize = coreParams.BtbSize
  // val BtbWays = 4
  val BtbBanks = PredictWidth
  // val BtbSets = BtbSize / BtbWays
  val JbtacSize = coreParams.JbtacSize
  val JbtacBanks = coreParams.JbtacBanks
  val RasSize = coreParams.RasSize
Z
zoujr 已提交
306

307 308
  def getBPDComponents(resp_in: BranchPredictionResp, p: Parameters) = {
    coreParams.branchPredictor(resp_in, p)
Z
zoujr 已提交
309
  }
310 311 312 313 314 315 316
  val numBr = coreParams.numBr
  val TageTableInfos = coreParams.TageTableInfos


  val BankTageTableInfos = (0 until numBr).map(i =>
    TageTableInfos.map{ case (s, h, t) => (s/(1 << i), h, t) }
  )
L
Lingrui98 已提交
317
  val TageBanks = coreParams.TageBanks
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
  val SCNRows = coreParams.SCNRows
  val SCCtrBits = coreParams.SCCtrBits
  val BankSCHistLens = BankTageTableInfos.map(info => 0 :: info.map{ case (_,h,_) => h}.toList)
  val BankSCNTables = Seq.fill(numBr)(coreParams.SCNTables)

  val BankSCTableInfos = (BankSCNTables zip BankSCHistLens).map {
    case (ntable, histlens) =>
      Seq.fill(ntable)((SCNRows, SCCtrBits)) zip histlens map {case ((n, cb), h) => (n, cb, h)}
  }
  val ITTageTableInfos = coreParams.ITTageTableInfos
  type FoldedHistoryInfo = Tuple2[Int, Int]
  val foldedGHistInfos =
    (BankTageTableInfos.flatMap(_.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]()
    }.reduce(_++_)).toSet ++
    BankSCTableInfos.flatMap(_.map{ case (nRows, _, h) =>
      if (h > 0)
L
Lingrui98 已提交
338
        Set((h, min(log2Ceil(nRows/TageBanks), h)))
339 340 341 342 343 344 345 346 347
      else
        Set[FoldedHistoryInfo]()
    }.reduce(_++_)).toSet ++
    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]()
    }.reduce(_++_)).toList
Z
zoujr 已提交
348

349 350 351 352 353 354 355 356 357 358 359 360 361 362
  val CacheLineSize = coreParams.CacheLineSize
  val CacheLineHalfWord = CacheLineSize / 16
  val ExtHistoryLength = HistoryLength + 64
  val UBtbWays = coreParams.UBtbWays
  val BtbWays = coreParams.BtbWays
  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 已提交
363
  val RobSize = coreParams.RobSize
364
  val IntRefCounterWidth = log2Ceil(RobSize)
365 366 367 368 369
  val LoadQueueSize = coreParams.LoadQueueSize
  val StoreQueueSize = coreParams.StoreQueueSize
  val dpParams = coreParams.dpParams
  val exuParameters = coreParams.exuParameters
  val NRMemReadPorts = exuParameters.LduCnt + 2 * exuParameters.StuCnt
370 371 372 373
  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
374 375 376
  val LoadPipelineWidth = coreParams.LoadPipelineWidth
  val StorePipelineWidth = coreParams.StorePipelineWidth
  val StoreBufferSize = coreParams.StoreBufferSize
377
  val StoreBufferThreshold = coreParams.StoreBufferThreshold
378
  val EnableFastForward = coreParams.EnableFastForward
W
William Wang 已提交
379
  val EnableLdVioCheckAfterReset = coreParams.EnableLdVioCheckAfterReset
380
  val RefillSize = coreParams.RefillSize
381
  val asidLen = coreParams.MMUAsidLen
382
  val BTLBWidth = coreParams.LoadPipelineWidth + coreParams.StorePipelineWidth
383
  val refillBothTlb = coreParams.refillBothTlb
384 385 386 387
  val itlbParams = coreParams.itlbParameters
  val ldtlbParams = coreParams.ldtlbParameters
  val sttlbParams = coreParams.sttlbParameters
  val btlbParams = coreParams.btlbParameters
388
  val l2tlbParams = coreParams.l2tlbParameters
L
Lemover 已提交
389
  val NumPMP = coreParams.NumPMP
390
  val NumPMA = coreParams.NumPMA
L
Lemover 已提交
391
  val PlatformGrain: Int = log2Up(coreParams.RefillSize/8) // set PlatformGrain to avoid itlb, dtlb, ptw size conflict
392 393
  val NumPerfCounters = coreParams.NumPerfCounters

394 395 396 397 398
  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 + 
              (exuParameters.FmiscDivSqrtCnt+1)/2 + (exuParameters.LduCnt+1)/2 +
              ((exuParameters.StuCnt+1)/2) + ((exuParameters.StuCnt+1)/2) 

399 400 401
  val instBytes = if (HasCExtension) 2 else 4
  val instOffsetBits = log2Ceil(instBytes)

402
  val icacheParameters = coreParams.icacheParameters
J
Jiawei Lin 已提交
403
  val dcacheParameters = coreParams.dcacheParametersOpt.getOrElse(DCacheParameters())
404 405 406 407 408 409

  val LRSCCycles = 100

  // cache hierarchy configurations
  val l1BusDataWidth = 256

410 411 412 413 414 415 416 417 418 419 420 421 422
  // 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
423

424 425 426 427
  val loadExuConfigs = coreParams.loadExuConfigs
  val storeExuConfigs = coreParams.storeExuConfigs

  val intExuConfigs = coreParams.intExuConfigs
428

429
  val fpExuConfigs = coreParams.fpExuConfigs
430

431
  val exuConfigs = coreParams.exuConfigs
432

433 434 435 436 437 438 439 440 441
  val PCntIncrStep: Int = 6
  val numPCntHc: Int = 25
  val numPCntPtw: Int = 19

  val numCSRPCntFrontend = 8
  val numCSRPCntCtrl     = 8
  val numCSRPCntLsu      = 8
  val numCSRPCntHc       = 5
  val print_perfcounter  = false
442
}