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