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