Parameters.scala 23.5 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
package xiangshan

import chipsalliance.rocketchip.config.{Field, Parameters}
import chisel3._
import chisel3.util._
X
Xuan Hu 已提交
22 23
import huancun._
import system.SoCParamsKey
X
Xuan Hu 已提交
24 25
import xiangshan.backend.datapath.RdConfig._
import xiangshan.backend.datapath.WbConfig._
26
import xiangshan.backend.dispatch.DispatchParameters
X
Xuan Hu 已提交
27 28 29 30 31
import xiangshan.backend.exu.ExeUnitParams
import xiangshan.backend.fu.FuConfig._
import xiangshan.backend.issue.{IntScheduler, IssueBlockParams, MemScheduler, SchdBlockParams, SchedulerType, VfScheduler}
import xiangshan.backend.regfile.{IntPregParams, PregParams, VfPregParams}
import xiangshan.backend.BackendParams
32
import xiangshan.cache.DCacheParameters
33
import xiangshan.cache.prefetch._
L
Lingrui98 已提交
34
import xiangshan.frontend.{BasePredictor, BranchPredictionResp, FTB, FakePredictor, RAS, Tage, ITTage, Tage_SC, FauFTB}
35
import xiangshan.frontend.icache.ICacheParameters
X
Xuan Hu 已提交
36 37
import xiangshan.cache.mmu.{L2TLBParameters, TLBParameters}
import xiangshan.frontend._
38
import xiangshan.frontend.icache.ICacheParameters
X
Xuan Hu 已提交
39

40
import freechips.rocketchip.diplomacy.AddressSet
41
import system.SoCParamsKey
42 43
import huancun._
import huancun.debug._
W
wakafa 已提交
44
import coupledL2._
X
Xuan Hu 已提交
45
import xiangshan.backend.datapath.WakeUpConfig
L
LinJiawei 已提交
46 47
import xiangshan.mem.prefetch.{PrefetcherParams, SMSParams}

48
import scala.math.min
J
Jiawei Lin 已提交
49 50 51

case object XSTileKey extends Field[Seq[XSCoreParameters]]

52 53 54 55 56 57 58
case object XSCoreParamsKey extends Field[XSCoreParameters]

case class XSCoreParameters
(
  HasPrefetch: Boolean = false,
  HartId: Int = 0,
  XLEN: Int = 64,
59
  VLEN: Int = 128,
F
fdy 已提交
60
  ELEN: Int = 64,
61 62 63 64 65 66 67 68
  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
Ziyue Zhang 已提交
69
  HasVPU: Boolean = true,
Z
zhanglinjuan 已提交
70
  HasCustomCSRCacheOp: Boolean = true,
71
  FetchWidth: Int = 8,
72
  AsidLength: Int = 16,
73 74 75 76 77
  EnableBPU: Boolean = true,
  EnableBPD: Boolean = true,
  EnableRAS: Boolean = true,
  EnableLB: Boolean = false,
  EnableLoop: Boolean = true,
78
  EnableSC: Boolean = true,
79 80
  EnbaleTlbDebug: Boolean = false,
  EnableJal: Boolean = false,
81
  EnableFauFTB: Boolean = true,
82
  UbtbGHRLength: Int = 4,
83
  // HistoryLength: Int = 512,
84
  EnableGHistDiff: Boolean = true,
85
  EnableCommitGHistDiff: Boolean = true,
86
  UbtbSize: Int = 256,
87
  FtbSize: Int = 2048,
88
  RasSize: Int = 32,
89
  CacheLineSize: Int = 512,
90
  FtbWays: Int = 4,
91 92
  TageTableInfos: Seq[Tuple3[Int,Int,Int]] =
  //       Sets  Hist   Tag
L
Lingrui98 已提交
93 94 95 96 97 98 99 100 101 102 103 104
    // 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)),
105 106
  ITTageTableInfos: Seq[Tuple3[Int,Int,Int]] =
  //      Sets  Hist   Tag
L
Lingrui98 已提交
107
    Seq(( 256,    4,    9),
108
        ( 256,    8,    9),
L
Lingrui98 已提交
109
        ( 512,   13,    9),
110
        ( 512,   16,    9),
111
        ( 512,   32,    9)),
112 113
  SCNRows: Int = 512,
  SCNTables: Int = 4,
114
  SCCtrBits: Int = 6,
115
  SCHistLens: Seq[Int] = Seq(0, 4, 10, 16),
116
  numBr: Int = 2,
117 118
  branchPredictor: Function2[BranchPredictionResp, Parameters, Tuple2[Seq[BasePredictor], BranchPredictionResp]] =
    ((resp_in: BranchPredictionResp, p: Parameters) => {
Z
zoujr 已提交
119
      val ftb = Module(new FTB()(p))
L
Lingrui98 已提交
120
      val ubtb =Module(new FauFTB()(p))
121
      // val bim = Module(new BIM()(p))
122
      val tage = Module(new Tage_SC()(p))
L
Lingrui98 已提交
123
      val ras = Module(new RAS()(p))
124
      val ittage = Module(new ITTage()(p))
125
      val preds = Seq(ubtb, tage, ftb, ittage, ras)
Z
zoujr 已提交
126 127 128 129 130 131 132
      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
133
      ubtb.io.in.bits.resp_in(0) := resp_in
L
Lingrui98 已提交
134 135 136 137
      tage.io.in.bits.resp_in(0) := ubtb.io.out
      ftb.io.in.bits.resp_in(0)  := tage.io.out
      ittage.io.in.bits.resp_in(0)  := ftb.io.out
      ras.io.in.bits.resp_in(0) := ittage.io.out
Y
Yinan Xu 已提交
138

L
Lingrui98 已提交
139
      (preds, ras.io.out)
Z
zoujr 已提交
140
    }),
141 142 143 144
  IBufSize: Int = 48,
  DecodeWidth: Int = 6,
  RenameWidth: Int = 6,
  CommitWidth: Int = 6,
145
  MaxUopSize: Int = 65,
L
Lingrui98 已提交
146
  FtqSize: Int = 64,
147
  EnableLoadFastWakeUp: Boolean = true, // NOTE: not supported now, make it false
F
fdy 已提交
148
  IntLogicRegs: Int = 32,
F
fdy 已提交
149
  FpLogicRegs: Int = 33,
150 151
  VecLogicRegs: Int = 32 + 1 + 15, // 15: tmp, 1: vconfig
  VCONFIG_IDX: Int = 32,
152
  NRPhyRegs: Int = 192,
153 154 155 156 157 158 159
  VirtualLoadQueueSize: Int = 80,
  LoadQueueRARSize: Int = 80,
  LoadQueueRAWSize: Int = 64, // NOTE: make sure that LoadQueueRAWSize is power of 2.
  RollbackGroupSize: Int = 8,
  LoadQueueReplaySize: Int = 80,
  LoadUncacheBufferSize: Int = 20,
  LoadQueueNWriteBanks: Int = 8, // NOTE: make sure that LoadQueueRARSize/LoadQueueRAWSize is divided by LoadQueueNWriteBanks
160
  StoreQueueSize: Int = 64,
161 162
  StoreQueueNWriteBanks: Int = 8, // NOTE: make sure that StoreQueueSize is divided by StoreQueueNWriteBanks
  StoreQueueForwardWithMask: Boolean = true,
W
William Wang 已提交
163
  VlsQueueSize: Int = 8,
164
  RobSize: Int = 256,
F
fdy 已提交
165
  RabSize: Int = 256,
166 167 168 169
  dpParams: DispatchParameters = DispatchParameters(
    IntDqSize = 16,
    FpDqSize = 16,
    LsDqSize = 16,
X
Xuan Hu 已提交
170 171 172
    IntDqDeqWidth = 6,
    FpDqDeqWidth = 6,
    LsDqDeqWidth = 6,
173
  ),
X
Xuan Hu 已提交
174
  intPreg: PregParams = IntPregParams(
175 176 177
    numEntries = 192,
    numRead = None,
    numWrite = None,
178
  ),
X
Xuan Hu 已提交
179
  vfPreg: VfPregParams = VfPregParams(
180 181 182
    numEntries = 192,
    numRead = None,
    numWrite = None,
X
Xuan Hu 已提交
183
  ),
L
LinJiawei 已提交
184
  prefetcher: Option[PrefetcherParams] = Some(SMSParams()),
185 186
  LoadPipelineWidth: Int = 2,
  StorePipelineWidth: Int = 2,
W
William Wang 已提交
187 188 189
  VecMemSrcInWidth: Int = 2,
  VecMemInstWbWidth: Int = 1,
  VecMemDispatchWidth: Int = 1,
190
  StoreBufferSize: Int = 16,
191
  StoreBufferThreshold: Int = 7,
192
  EnsbufferWidth: Int = 2,
193
  UncacheBufferSize: Int = 4,
194
  EnableLoadToLoadForward: Boolean = true,
W
William Wang 已提交
195
  EnableFastForward: Boolean = false,
196
  EnableLdVioCheckAfterReset: Boolean = true,
197 198
  EnableSoftPrefetchAfterReset: Boolean = true,
  EnableCacheErrorAfterReset: Boolean = true,
199
  EnableDCacheWPU: Boolean = false,
200
  EnableAccurateLoadError: Boolean = true,
201
  EnableUncacheWriteOutstanding: Boolean = false,
202
  MMUAsidLen: Int = 16, // max is 16, 0 is not supported now
203
  ReSelectLen: Int = 7, // load replay queue replay select counter len
204 205 206 207
  itlbParameters: TLBParameters = TLBParameters(
    name = "itlb",
    fetchi = true,
    useDmode = false,
208
    normalNWays = 32,
209
    normalReplacer = Some("plru"),
210
    superNWays = 4,
211
    superReplacer = Some("plru")
212
  ),
213 214
  itlbPortNum: Int = 2 + ICacheParameters().prefetchPipeNum + 1,
  ipmpPortNum: Int = 2 + ICacheParameters().prefetchPipeNum + 1,
215 216
  ldtlbParameters: TLBParameters = TLBParameters(
    name = "ldtlb",
217
    normalNSets = 64,
218 219 220
    normalNWays = 1,
    normalAssociative = "sa",
    normalReplacer = Some("setplru"),
221
    superNWays = 16,
222
    normalAsVictim = true,
223
    outReplace = false,
224
    partialStaticPMP = true,
225
    outsideRecvFlush = true,
226
    saveLevel = true
227 228 229
  ),
  sttlbParameters: TLBParameters = TLBParameters(
    name = "sttlb",
230
    normalNSets = 64,
231 232 233
    normalNWays = 1,
    normalAssociative = "sa",
    normalReplacer = Some("setplru"),
234
    superNWays = 16,
235
    normalAsVictim = true,
236
    outReplace = false,
237
    partialStaticPMP = true,
238
    outsideRecvFlush = true,
239
    saveLevel = true
240
  ),
241 242 243 244 245 246 247 248 249 250 251 252 253
  pftlbParameters: TLBParameters = TLBParameters(
    name = "pftlb",
    normalNSets = 64,
    normalNWays = 1,
    normalAssociative = "sa",
    normalReplacer = Some("setplru"),
    superNWays = 16,
    normalAsVictim = true,
    outReplace = false,
    partialStaticPMP = true,
    outsideRecvFlush = true,
    saveLevel = true
  ),
254
  refillBothTlb: Boolean = false,
255 256 257 258 259 260
  btlbParameters: TLBParameters = TLBParameters(
    name = "btlb",
    normalNSets = 1,
    normalNWays = 64,
    superNWays = 4,
  ),
261
  l2tlbParameters: L2TLBParameters = L2TLBParameters(),
262
  NumPerfCounters: Int = 16,
263 264 265 266
  icacheParameters: ICacheParameters = ICacheParameters(
    tagECC = Some("parity"),
    dataECC = Some("parity"),
    replacer = Some("setplru"),
267
    nMissEntries = 2,
268
    nProbeEntries = 2,
269
    nPrefetchEntries = 12,
270
    nPrefBufferEntries = 64,
271
    hasPrefetch = true,
272
  ),
J
Jiawei Lin 已提交
273
  dcacheParametersOpt: Option[DCacheParameters] = Some(DCacheParameters(
274 275 276 277
    tagECC = Some("secded"),
    dataECC = Some("secded"),
    replacer = Some("setplru"),
    nMissEntries = 16,
W
William Wang 已提交
278 279
    nProbeEntries = 8,
    nReleaseEntries = 18
J
Jiawei Lin 已提交
280
  )),
W
wakafa 已提交
281
  L2CacheParamsOpt: Option[L2Param] = Some(L2Param(
282 283 284
    name = "l2",
    ways = 8,
    sets = 1024, // default 512KB L2
W
wakafa 已提交
285
    prefetch = Some(coupledL2.prefetch.PrefetchReceiverParams())
J
Jiawei Lin 已提交
286
  )),
J
Jiawei Lin 已提交
287
  L2NBanks: Int = 1,
288
  usePTWRepeater: Boolean = false,
H
Haoyuan Feng 已提交
289 290
  softTLB: Boolean = false, // dpi-c l1tlb debug only
  softPTW: Boolean = false, // dpi-c l2tlb debug only
291
  softPTWDelay: Int = 1
292
){
293 294
  def vlWidth = log2Up(VLEN) + 1

295 296 297
  val allHistLens = SCHistLens ++ ITTageTableInfos.map(_._2) ++ TageTableInfos.map(_._2) :+ UbtbGHRLength
  val HistoryLength = allHistLens.max + numBr * FtqSize + 9 // 256 for the predictor configs now

298
  val intSchdParams = {
X
Xuan Hu 已提交
299 300
    implicit val schdType: SchedulerType = IntScheduler()
    SchdBlockParams(Seq(
301
      IssueBlockParams(Seq(
302 303
        ExeUnitParams("IEX0", Seq(AluCfg), Seq(IntWB(port = 0, 0)), Seq(Seq(IntRD(0, 0)), Seq(IntRD(1, 0)))),
        ExeUnitParams("IEX1", Seq(AluCfg), Seq(IntWB(port = 1, 0)), Seq(Seq(IntRD(2, 0)), Seq(IntRD(3, 0)))),
304
      ), numEntries = 8, numEnq = 2),
X
Xuan Hu 已提交
305
      IssueBlockParams(Seq(
306 307
        ExeUnitParams("IEX2", Seq(AluCfg, MulCfg, BkuCfg), Seq(IntWB(port = 2, 0)), Seq(Seq(IntRD(4, 0)), Seq(IntRD(5, 0)))),
        ExeUnitParams("IEX3", Seq(AluCfg, MulCfg, BkuCfg), Seq(IntWB(port = 3, 0)), Seq(Seq(IntRD(6, 0)), Seq(IntRD(7, 0)))),
308
      ), numEntries = 8, numEnq = 2),
X
Xuan Hu 已提交
309
      IssueBlockParams(Seq(
310 311
        ExeUnitParams("BJU0", Seq(BrhCfg, JmpCfg, CsrCfg, FenceCfg), Seq(IntWB(port = 4, 0)), Seq(Seq(IntRD(8, 0)), Seq(IntRD(9, 0)))),
        ExeUnitParams("BJU1", Seq(BrhCfg), Seq(), Seq(Seq(IntRD(2, 1)), Seq(IntRD(3, 1)))),
312
      ), numEntries = 8, numEnq = 2),
X
Xuan Hu 已提交
313
      IssueBlockParams(Seq(
314
        ExeUnitParams("IMISC0", Seq(VSetRiWiCfg, I2fCfg, VSetRiWvfCfg), Seq(IntWB(port = 4, 1), VfWB(4, 0)), Seq(Seq(IntRD(8, 1)), Seq(IntRD(9, 1)))),
315
      ), numEntries = 8, numEnq = 2),
X
Xuan Hu 已提交
316
      IssueBlockParams(Seq(
317
        ExeUnitParams("IDIV0", Seq(DivCfg), Seq(IntWB(port = 5, 1)), Seq(Seq(IntRD(6, Int.MaxValue)), Seq(IntRD(7, Int.MaxValue)))),
318
      ), numEntries = 8, numEnq = 2),
X
Xuan Hu 已提交
319 320 321 322 323 324 325 326
    ),
      numPregs = intPreg.numEntries,
      numDeqOutside = 0,
      schdType = schdType,
      rfDataWidth = intPreg.dataCfg.dataWidth,
      numUopIn = dpParams.IntDqDeqWidth,
    )
  }
327
  val vfSchdParams = {
X
Xuan Hu 已提交
328 329
    implicit val schdType: SchedulerType = VfScheduler()
    SchdBlockParams(Seq(
X
xiaofeibao-xjtu 已提交
330
      IssueBlockParams(Seq(
331
        ExeUnitParams("FEX0", Seq(FmacCfg), Seq(VfWB(port = 0, 0)), Seq(Seq(VfRD(1, 0)), Seq(VfRD(2, 0)), Seq(VfRD(3, 0)))),
332
        ExeUnitParams("FEX1", Seq(FmacCfg), Seq(VfWB(port = 1, 0)), Seq(Seq(VfRD(4, 0)), Seq(VfRD(5, 0)), Seq(VfRD(6, 0)))),
333
      ), numEntries = 8, numEnq = 2),
X
xiaofeibao-xjtu 已提交
334
      IssueBlockParams(Seq(
335
        ExeUnitParams("FEX2", Seq(FDivSqrtCfg), Seq(VfWB(port = 2, 0)), Seq(Seq(VfRD(11, 0)), Seq(VfRD(12, 0)))),
336
        ExeUnitParams("FEX3", Seq(F2fCfg, F2iCfg, VSetRvfWvfCfg), Seq(VfWB(port = 3, 0), IntWB(port = 5, 0)), Seq(Seq(VfRD(7, 0)), Seq(VfRD(8, 0)))),
337
      ), numEntries = 8, numEnq = 2),
X
xiaofeibao-xjtu 已提交
338
      IssueBlockParams(Seq(
339 340
        ExeUnitParams("VEX0", Seq(VialuCfg, VimacCfg, VppuCfg, VipuCfg), Seq(VfWB(port = 4, 0)), Seq(Seq(VfRD(1, 0)), Seq(VfRD(2, 0)), Seq(VfRD(3, 0)), Seq(VfRD(4, 0)), Seq(VfRD(5, 0)))),
        ExeUnitParams("VEX1", Seq(VfaluCfg, VfmaCfg), Seq(VfWB(port = 5, 0)), Seq(Seq(VfRD(7, 0)), Seq(VfRD(8, 0)), Seq(VfRD(9, 0)), Seq(VfRD(10, 0)), Seq(VfRD(11, 0)))),
341
      ), numEntries = 8, numEnq = 2),
342
      IssueBlockParams(Seq(
343
        ExeUnitParams("VEX3", Seq(VfdivCfg), Seq(VfWB(port = 5, 0)), Seq(Seq(VfRD(7, 0)), Seq(VfRD(8, 0)), Seq(VfRD(9, 0)), Seq(VfRD(10, 0)), Seq(VfRD(11, 0)))),
344
      ), numEntries = 8, numEnq = 2),
X
Xuan Hu 已提交
345 346 347 348 349 350 351 352
    ),
      numPregs = vfPreg.numEntries,
      numDeqOutside = 0,
      schdType = schdType,
      rfDataWidth = vfPreg.dataCfg.dataWidth,
      numUopIn = dpParams.FpDqDeqWidth,
    )
  }
353 354

  val memSchdParams = {
X
Xuan Hu 已提交
355 356 357 358 359
    implicit val schdType: SchedulerType = MemScheduler()
    val rfDataWidth = 64

    SchdBlockParams(Seq(
      IssueBlockParams(Seq(
360 361
        ExeUnitParams("LDU0", Seq(LduCfg), Seq(IntWB(6, 0), VfWB(6, 0)), Seq(Seq(IntRD(10, 0)))),
        ExeUnitParams("LDU1", Seq(LduCfg), Seq(IntWB(7, 0), VfWB(7, 0)), Seq(Seq(IntRD(11, 0)))),
362
      ), numEntries = 8, numEnq = 2),
X
Xuan Hu 已提交
363
      IssueBlockParams(Seq(
364 365
        ExeUnitParams("STA0", Seq(StaCfg, MouCfg), Seq(IntWB(6, 1)), Seq(Seq(IntRD(12, 0)))),
        ExeUnitParams("STA1", Seq(StaCfg, MouCfg), Seq(IntWB(7, 1)), Seq(Seq(IntRD(13, 0)))),
366
      ), numEntries = 8, numEnq = 2),
X
Xuan Hu 已提交
367
      IssueBlockParams(Seq(
368
        ExeUnitParams("STD0", Seq(StdCfg, MoudCfg), Seq(), Seq(Seq(IntRD(8, Int.MaxValue), VfRD(12, Int.MaxValue)))),
369 370
        ExeUnitParams("STD1", Seq(StdCfg, MoudCfg), Seq(), Seq(Seq(IntRD(9, Int.MaxValue), VfRD(10, Int.MaxValue)))),
      ), numEntries = 8, numEnq = 2),
Z
zhanglyGit 已提交
371
      IssueBlockParams(Seq(
X
xiaofeibao-xjtu 已提交
372 373
        ExeUnitParams("VLDU0", Seq(VlduCfg), Seq(VfWB(6, 1)), Seq(Seq(VfRD(0, 0)), Seq(VfRD(1, 0)), Seq(VfRD(2, 0)), Seq(VfRD(3, 0)), Seq(VfRD(4, 0)))),
        ExeUnitParams("VLDU1", Seq(VlduCfg), Seq(VfWB(7, 1)), Seq(Seq(VfRD(5, 0)), Seq(VfRD(6, 0)), Seq(VfRD(7, 0)), Seq(VfRD(8, 0)), Seq(VfRD(9, 0)))),
374
      ), numEntries = 8, numEnq = 2),
X
Xuan Hu 已提交
375
    ),
X
Xuan Hu 已提交
376
      numPregs = intPreg.numEntries max vfPreg.numEntries,
X
Xuan Hu 已提交
377 378 379 380 381 382
      numDeqOutside = 0,
      schdType = schdType,
      rfDataWidth = rfDataWidth,
      numUopIn = dpParams.LsDqDeqWidth,
    )
  }
383

X
Xuan Hu 已提交
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
  def PregIdxWidthMax = intPreg.addrWidth max vfPreg.addrWidth

  def iqWakeUpParams = {
    Seq(
      WakeUpConfig("IEX0" -> "IEX0"),
      WakeUpConfig("IEX0" -> "IEX1"),
      WakeUpConfig("IEX1" -> "IEX0"),
      WakeUpConfig("IEX1" -> "IEX1"),
      WakeUpConfig("IEX0" -> "BJU0"),
      WakeUpConfig("IEX0" -> "BJU1"),
      WakeUpConfig("IEX1" -> "BJU0"),
      WakeUpConfig("IEX1" -> "BJU1"),
      WakeUpConfig("IEX0" -> "LDU0"),
      WakeUpConfig("IEX0" -> "LDU1"),
      WakeUpConfig("IEX1" -> "LDU0"),
      WakeUpConfig("IEX1" -> "LDU1"),
      WakeUpConfig("IEX0" -> "STA0"),
      WakeUpConfig("IEX0" -> "STA1"),
      WakeUpConfig("IEX1" -> "STA0"),
      WakeUpConfig("IEX1" -> "STA1"),
404 405 406 407 408
      WakeUpConfig("IMISC0" -> "FEX0"),
      WakeUpConfig("IMISC0" -> "FEX1"),
      WakeUpConfig("IMISC0" -> "FEX2"),
      WakeUpConfig("IMISC0" -> "FEX3"),
      WakeUpConfig("IMISC0" -> "FEX4"),
409 410 411 412
      WakeUpConfig("FEX3" -> "FEX0"),
      WakeUpConfig("FEX3" -> "FEX1"),
      WakeUpConfig("FEX3" -> "FEX2"),
      WakeUpConfig("FEX3" -> "FEX3"),
X
Xuan Hu 已提交
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
    )
  }

  def backendParams: BackendParams = backend.BackendParams(
    Map(
      IntScheduler() -> intSchdParams,
      VfScheduler() -> vfSchdParams,
      MemScheduler() -> memSchdParams,
    ),
    Seq(
      intPreg,
      vfPreg,
    ),
    iqWakeUpParams,
  )
428 429 430 431 432 433
}

case object DebugOptionsKey extends Field[DebugOptions]

case class DebugOptions
(
434 435
  FPGAPlatform: Boolean = false,
  EnableDifftest: Boolean = false,
436
  AlwaysBasicDiff: Boolean = true,
437
  EnableDebug: Boolean = false,
438
  EnablePerfDebug: Boolean = true,
439
  UseDRAMSim: Boolean = false,
Maxpicca's avatar
Maxpicca 已提交
440
  EnableConstantin: Boolean = false,
441
  EnableTopDown: Boolean = false
442 443 444 445 446 447
)

trait HasXSParameter {

  implicit val p: Parameters

448 449
  val PAddrBits = p(SoCParamsKey).PAddrBits // PAddrBits is Phyical Memory addr bits

450 451 452 453
  val coreParams = p(XSCoreParamsKey)
  val env = p(DebugOptionsKey)

  val XLEN = coreParams.XLEN
454
  val VLEN = coreParams.VLEN
F
fdy 已提交
455
  val ELEN = coreParams.ELEN
456 457 458 459 460 461 462 463 464 465 466
  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
467
  val AsidLength = coreParams.AsidLength
468
  val ReSelectLen = coreParams.ReSelectLen
469 470 471 472
  val AddrBytes = AddrBits / 8 // unused
  val DataBits = XLEN
  val DataBytes = DataBits / 8
  val HasFPU = coreParams.HasFPU
Z
Ziyue Zhang 已提交
473
  val HasVPU = coreParams.HasVPU
Z
zhanglinjuan 已提交
474
  val HasCustomCSRCacheOp = coreParams.HasCustomCSRCacheOp
475 476 477 478 479 480 481 482 483 484
  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
485
  val EnableGHistDiff = coreParams.EnableGHistDiff
486
  val EnableCommitGHistDiff = coreParams.EnableCommitGHistDiff
487
  val UbtbGHRLength = coreParams.UbtbGHRLength
488
  val UbtbSize = coreParams.UbtbSize
489
  val EnableFauFTB = coreParams.EnableFauFTB
490 491
  val FtbSize = coreParams.FtbSize
  val FtbWays = coreParams.FtbWays
492
  val RasSize = coreParams.RasSize
Z
zoujr 已提交
493

494 495
  def getBPDComponents(resp_in: BranchPredictionResp, p: Parameters) = {
    coreParams.branchPredictor(resp_in, p)
Z
zoujr 已提交
496
  }
497 498
  val numBr = coreParams.numBr
  val TageTableInfos = coreParams.TageTableInfos
L
Lingrui98 已提交
499
  val TageBanks = coreParams.numBr
500 501
  val SCNRows = coreParams.SCNRows
  val SCCtrBits = coreParams.SCCtrBits
L
Lingrui98 已提交
502 503
  val SCHistLens = coreParams.SCHistLens
  val SCNTables = coreParams.SCNTables
504

L
Lingrui98 已提交
505 506
  val SCTableInfos = Seq.fill(SCNTables)((SCNRows, SCCtrBits)) zip SCHistLens map {
    case ((n, cb), h) => (n, cb, h)
507 508 509 510
  }
  val ITTageTableInfos = coreParams.ITTageTableInfos
  type FoldedHistoryInfo = Tuple2[Int, Int]
  val foldedGHistInfos =
511
    (TageTableInfos.map{ case (nRows, h, t) =>
512
      if (h > 0)
513
        Set((h, min(log2Ceil(nRows/numBr), h)), (h, min(h, t)), (h, min(h, t-1)))
514 515
      else
        Set[FoldedHistoryInfo]()
516
    }.reduce(_++_).toSet ++
L
Lingrui98 已提交
517
    SCTableInfos.map{ case (nRows, _, h) =>
518
      if (h > 0)
L
Lingrui98 已提交
519
        Set((h, min(log2Ceil(nRows/TageBanks), h)))
520 521
      else
        Set[FoldedHistoryInfo]()
L
Lingrui98 已提交
522
    }.reduce(_++_).toSet ++
523 524 525 526 527
    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]()
528 529 530
    }.reduce(_++_) ++
      Set[FoldedHistoryInfo]((UbtbGHRLength, log2Ceil(UbtbSize)))
    ).toList
531

532

Z
zoujr 已提交
533

534 535 536 537 538 539 540
  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
F
fdy 已提交
541
  val MaxUopSize = coreParams.MaxUopSize
542 543
  val FtqSize = coreParams.FtqSize
  val EnableLoadFastWakeUp = coreParams.EnableLoadFastWakeUp
F
fdy 已提交
544 545 546
  val IntLogicRegs = coreParams.IntLogicRegs
  val FpLogicRegs = coreParams.FpLogicRegs
  val VecLogicRegs = coreParams.VecLogicRegs
X
Xuan Hu 已提交
547
  val VCONFIG_IDX = coreParams.VCONFIG_IDX
548 549 550
  val IntPhyRegs = coreParams.intPreg.numEntries
  val VfPhyRegs = coreParams.vfPreg.numEntries
  val PhyRegIdxWidth = log2Up(IntPhyRegs) max log2Up(VfPhyRegs)
Y
Yinan Xu 已提交
551
  val RobSize = coreParams.RobSize
F
fdy 已提交
552
  val RabSize = coreParams.RabSize
553
  val IntRefCounterWidth = log2Ceil(RobSize)
554 555 556 557 558 559
  val VirtualLoadQueueSize = coreParams.VirtualLoadQueueSize
  val LoadQueueRARSize = coreParams.LoadQueueRARSize
  val LoadQueueRAWSize = coreParams.LoadQueueRAWSize
  val RollbackGroupSize = coreParams.RollbackGroupSize
  val LoadQueueReplaySize = coreParams.LoadQueueReplaySize
  val LoadUncacheBufferSize = coreParams.LoadUncacheBufferSize
560
  val LoadQueueNWriteBanks = coreParams.LoadQueueNWriteBanks
561
  val StoreQueueSize = coreParams.StoreQueueSize
562
  val StoreQueueNWriteBanks = coreParams.StoreQueueNWriteBanks
563
  val StoreQueueForwardWithMask = coreParams.StoreQueueForwardWithMask
W
William Wang 已提交
564
  val VlsQueueSize = coreParams.VlsQueueSize
565
  val dpParams = coreParams.dpParams
X
Xuan Hu 已提交
566 567

  def backendParams: BackendParams = coreParams.backendParams
568 569
  def MemIQSizeMax = backendParams.memSchdParams.get.issueBlockParams.map(_.numEntries).max
  def IQSizeMax = backendParams.allSchdParams.map(_.issueBlockParams.map(_.numEntries).max).max
570 571
  val LoadPipelineWidth = coreParams.LoadPipelineWidth
  val StorePipelineWidth = coreParams.StorePipelineWidth
W
William Wang 已提交
572 573 574
  val VecMemSrcInWidth = coreParams.VecMemSrcInWidth
  val VecMemInstWbWidth = coreParams.VecMemInstWbWidth
  val VecMemDispatchWidth = coreParams.VecMemDispatchWidth
575
  val StoreBufferSize = coreParams.StoreBufferSize
576
  val StoreBufferThreshold = coreParams.StoreBufferThreshold
577
  val EnsbufferWidth = coreParams.EnsbufferWidth
578
  val UncacheBufferSize = coreParams.UncacheBufferSize
579
  val EnableLoadToLoadForward = coreParams.EnableLoadToLoadForward
580
  val EnableFastForward = coreParams.EnableFastForward
W
William Wang 已提交
581
  val EnableLdVioCheckAfterReset = coreParams.EnableLdVioCheckAfterReset
582 583
  val EnableSoftPrefetchAfterReset = coreParams.EnableSoftPrefetchAfterReset
  val EnableCacheErrorAfterReset = coreParams.EnableCacheErrorAfterReset
584
  val EnableDCacheWPU = coreParams.EnableDCacheWPU
585
  val EnableAccurateLoadError = coreParams.EnableAccurateLoadError
586
  val EnableUncacheWriteOutstanding = coreParams.EnableUncacheWriteOutstanding
587
  val asidLen = coreParams.MMUAsidLen
588
  val BTLBWidth = coreParams.LoadPipelineWidth + coreParams.StorePipelineWidth
589
  val refillBothTlb = coreParams.refillBothTlb
590 591 592
  val itlbParams = coreParams.itlbParameters
  val ldtlbParams = coreParams.ldtlbParameters
  val sttlbParams = coreParams.sttlbParameters
593
  val pftlbParams = coreParams.pftlbParameters
594
  val btlbParams = coreParams.btlbParameters
595
  val l2tlbParams = coreParams.l2tlbParameters
596 597 598 599 600
  val NumPerfCounters = coreParams.NumPerfCounters

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

601
  val icacheParameters = coreParams.icacheParameters
J
Jiawei Lin 已提交
602
  val dcacheParameters = coreParams.dcacheParametersOpt.getOrElse(DCacheParameters())
603

604
  // dcache block cacheline when lr for LRSCCycles - LRSCBackOff cycles
605
  // for constrained LR/SC loop
606 607 608
  val LRSCCycles = 64
  // for lr storm
  val LRSCBackOff = 8
609 610 611 612

  // cache hierarchy configurations
  val l1BusDataWidth = 256

613 614 615 616 617 618 619 620 621 622 623 624 625
  // 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
626 627
  val LFSTEnable = false

628 629 630 631 632 633 634 635
  val PCntIncrStep: Int = 6
  val numPCntHc: Int = 25
  val numPCntPtw: Int = 19

  val numCSRPCntFrontend = 8
  val numCSRPCntCtrl     = 8
  val numCSRPCntLsu      = 8
  val numCSRPCntHc       = 5
636 637 638

  // source stages of cancel signal to issue queues
  val cancelStages = Seq("IS", "OG0", "OG1")
639
}