xref: /XiangShan/src/main/scala/xiangshan/Parameters.scala (revision 2f8507198271d39a53f28fef3cd5898453974b6c)
1/***************************************************************************************
2* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences
3*
4* XiangShan is licensed under Mulan PSL v2.
5* You can use this software according to the terms and conditions of the Mulan PSL v2.
6* You may obtain a copy of Mulan PSL v2 at:
7*          http://license.coscl.org.cn/MulanPSL2
8*
9* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
10* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
11* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
12*
13* See the Mulan PSL v2 for more details.
14***************************************************************************************/
15
16package xiangshan
17
18import chipsalliance.rocketchip.config.{Field, Parameters}
19import chisel3._
20import chisel3.util._
21import xiangshan.backend.exu._
22import xiangshan.backend.fu._
23import xiangshan.backend.fu.fpu._
24import xiangshan.backend.dispatch.DispatchParameters
25import xiangshan.cache.{DCacheParameters, L1plusCacheParameters}
26import xiangshan.cache.prefetch.{BOPParameters, L1plusPrefetcherParameters, L2PrefetcherParameters, StreamPrefetchParameters}
27import xiangshan.frontend.{BIM, ICacheParameters ,BasePredictor, BranchPredictionResp, FTB, MicroBTB}
28
29case object XSCoreParamsKey extends Field[XSCoreParameters]
30
31case class XSCoreParameters
32(
33  HasPrefetch: Boolean = false,
34  HartId: Int = 0,
35  XLEN: Int = 64,
36  HasMExtension: Boolean = true,
37  HasCExtension: Boolean = true,
38  HasDiv: Boolean = true,
39  HasICache: Boolean = true,
40  HasDCache: Boolean = true,
41  AddrBits: Int = 64,
42  VAddrBits: Int = 39,
43  PAddrBits: Int = 40,
44  HasFPU: Boolean = true,
45  FetchWidth: Int = 8,
46  EnableBPU: Boolean = true,
47  EnableBPD: Boolean = true,
48  EnableRAS: Boolean = true,
49  EnableLB: Boolean = false,
50  EnableLoop: Boolean = true,
51  EnableSC: Boolean = true,
52  EnbaleTlbDebug: Boolean = false,
53  EnableJal: Boolean = false,
54  EnableUBTB: Boolean = true,
55  HistoryLength: Int = 64,
56  BtbSize: Int = 2048,
57  JbtacSize: Int = 1024,
58  JbtacBanks: Int = 8,
59  RasSize: Int = 16,
60  CacheLineSize: Int = 512,
61  UBtbWays: Int = 16,
62  BtbWays: Int = 2,
63  branchPredictor: Function2[BranchPredictionResp, Parameters, Tuple2[Seq[BasePredictor], BranchPredictionResp]] =
64    ((resp_in: BranchPredictionResp, p: Parameters) => {
65      // val loop = Module(new LoopPredictor)
66      // val tage = (if(EnableBPD) { if (EnableSC) Module(new Tage_SC)
67      //                             else          Module(new Tage) }
68      //             else          { Module(new FakeTage) })
69      val ftb = Module(new FTB()(p))
70      val ubtb = Module(new MicroBTB()(p))
71      val bim = Module(new BIM()(p))
72      // val fake = Module(new FakePredictor())
73
74      // val preds = Seq(loop, tage, btb, ubtb, bim)
75      val preds = Seq(ftb, ubtb, bim)
76      preds.map(_.io := DontCare)
77
78      // ubtb.io.resp_in(0)  := resp_in
79      // bim.io.resp_in(0)   := ubtb.io.resp
80      // btb.io.resp_in(0)   := bim.io.resp
81      // tage.io.resp_in(0)  := btb.io.resp
82      // loop.io.resp_in(0)  := tage.io.resp
83      ubtb.io.in.bits.resp_in(0)     := resp_in
84      bim.io.in.bits.resp_in(0)      := ubtb.io.out.bits.resp
85      ftb.io.in.bits.resp_in(0)      := bim.io.out.bits.resp
86
87      (preds, ftb.io.out.bits.resp)
88    }),
89
90
91  EnableL1plusPrefetcher: Boolean = true,
92  IBufSize: Int = 48,
93  DecodeWidth: Int = 6,
94  RenameWidth: Int = 6,
95  CommitWidth: Int = 6,
96  BrqSize: Int = 32,
97  FtqSize: Int = 48,
98  EnableLoadFastWakeUp: Boolean = true, // NOTE: not supported now, make it false
99  IssQueSize: Int = 16,
100  NRPhyRegs: Int = 160,
101  NRIntReadPorts: Int = 14,
102  NRIntWritePorts: Int = 8,
103  NRFpReadPorts: Int = 14,
104  NRFpWritePorts: Int = 8,
105  LoadQueueSize: Int = 64,
106  StoreQueueSize: Int = 48,
107  RoqSize: Int = 192,
108  dpParams: DispatchParameters = DispatchParameters(
109    IntDqSize = 16,
110    FpDqSize = 16,
111    LsDqSize = 16,
112    IntDqDeqWidth = 4,
113    FpDqDeqWidth = 4,
114    LsDqDeqWidth = 4
115  ),
116  exuParameters: ExuParameters = ExuParameters(
117    JmpCnt = 1,
118    AluCnt = 4,
119    MulCnt = 0,
120    MduCnt = 2,
121    FmacCnt = 4,
122    FmiscCnt = 2,
123    FmiscDivSqrtCnt = 0,
124    LduCnt = 2,
125    StuCnt = 2
126  ),
127  LoadPipelineWidth: Int = 2,
128  StorePipelineWidth: Int = 2,
129  StoreBufferSize: Int = 16,
130  StoreBufferThreshold: Int = 7,
131  RefillSize: Int = 512,
132  TlbEntrySize: Int = 32,
133  TlbSPEntrySize: Int = 4,
134  PtwL3EntrySize: Int = 4096, //(256 * 16) or 512
135  PtwSPEntrySize: Int = 16,
136  PtwL1EntrySize: Int = 16,
137  PtwL2EntrySize: Int = 2048, //(256 * 8)
138  PtwMissQueueSize: Int = 8,
139  NumPerfCounters: Int = 16,
140  icacheParameters: ICacheParameters = ICacheParameters(
141    tagECC = Some("parity"),
142    dataECC = Some("parity"),
143    replacer = Some("setplru"),
144    nMissEntries = 2
145  ),
146  l1plusCacheParameters: L1plusCacheParameters = L1plusCacheParameters(
147    tagECC = Some("secded"),
148    dataECC = Some("secded"),
149    replacer = Some("setplru"),
150    nMissEntries = 8
151  ),
152  dcacheParameters: DCacheParameters = DCacheParameters(
153    tagECC = Some("secded"),
154    dataECC = Some("secded"),
155    replacer = Some("setplru"),
156    nMissEntries = 16,
157    nProbeEntries = 16,
158    nReleaseEntries = 16,
159    nStoreReplayEntries = 16
160  ),
161  L2Size: Int = 512 * 1024, // 512KB
162  L2NWays: Int = 8,
163  usePTWRepeater: Boolean = false,
164  useFakePTW: Boolean = false,
165  useFakeDCache: Boolean = false,
166  useFakeL1plusCache: Boolean = false,
167  useFakeL2Cache: Boolean = false
168){
169  val loadExuConfigs = Seq.fill(exuParameters.LduCnt)(LdExeUnitCfg)
170  val storeExuConfigs = Seq.fill(exuParameters.StuCnt)(StExeUnitCfg)
171
172  val intExuConfigs = JumpExeUnitCfg +: (
173    Seq.fill(exuParameters.MduCnt)(MulDivExeUnitCfg) ++
174      Seq.fill(exuParameters.AluCnt)(AluExeUnitCfg)
175    )
176
177  val fpExuConfigs =
178    Seq.fill(exuParameters.FmacCnt)(FmacExeUnitCfg) ++
179      Seq.fill(exuParameters.FmiscCnt)(FmiscExeUnitCfg)
180
181  val exuConfigs: Seq[ExuConfig] = intExuConfigs ++ fpExuConfigs ++ loadExuConfigs ++ storeExuConfigs
182}
183
184case object DebugOptionsKey extends Field[DebugOptions]
185
186case class DebugOptions
187(
188  FPGAPlatform: Boolean = true,
189  EnableDebug: Boolean = true,
190  EnablePerfDebug: Boolean = true,
191  UseDRAMSim: Boolean = false
192)
193
194trait HasXSParameter {
195
196  implicit val p: Parameters
197
198  val coreParams = p(XSCoreParamsKey)
199  val env = p(DebugOptionsKey)
200
201  val XLEN = coreParams.XLEN
202  val hardId = coreParams.HartId
203  val minFLen = 32
204  val fLen = 64
205  def xLen = XLEN
206
207  val HasMExtension = coreParams.HasMExtension
208  val HasCExtension = coreParams.HasCExtension
209  val HasDiv = coreParams.HasDiv
210  val HasIcache = coreParams.HasICache
211  val HasDcache = coreParams.HasDCache
212  val AddrBits = coreParams.AddrBits // AddrBits is used in some cases
213  val VAddrBits = coreParams.VAddrBits // VAddrBits is Virtual Memory addr bits
214  val PAddrBits = coreParams.PAddrBits // PAddrBits is Phyical Memory addr bits
215  val AddrBytes = AddrBits / 8 // unused
216  val DataBits = XLEN
217  val DataBytes = DataBits / 8
218  val HasFPU = coreParams.HasFPU
219  val FetchWidth = coreParams.FetchWidth
220  val PredictWidth = FetchWidth * (if (HasCExtension) 2 else 1)
221  val EnableBPU = coreParams.EnableBPU
222  val EnableBPD = coreParams.EnableBPD // enable backing predictor(like Tage) in BPUStage3
223  val EnableRAS = coreParams.EnableRAS
224  val EnableLB = coreParams.EnableLB
225  val EnableLoop = coreParams.EnableLoop
226  val EnableSC = coreParams.EnableSC
227  val EnbaleTlbDebug = coreParams.EnbaleTlbDebug
228  val HistoryLength = coreParams.HistoryLength
229  val BtbSize = coreParams.BtbSize
230  // val BtbWays = 4
231  val BtbBanks = PredictWidth
232  // val BtbSets = BtbSize / BtbWays
233  val JbtacSize = coreParams.JbtacSize
234  val JbtacBanks = coreParams.JbtacBanks
235  val RasSize = coreParams.RasSize
236
237  def getBPDComponents(resp_in: BranchPredictionResp, p: Parameters) = {
238    coreParams.branchPredictor(resp_in, p)
239  }
240
241  val CacheLineSize = coreParams.CacheLineSize
242  val CacheLineHalfWord = CacheLineSize / 16
243  val ExtHistoryLength = HistoryLength + 64
244  val UBtbWays = coreParams.UBtbWays
245  val BtbWays = coreParams.BtbWays
246  val EnableL1plusPrefetcher = coreParams.EnableL1plusPrefetcher
247  val IBufSize = coreParams.IBufSize
248  val DecodeWidth = coreParams.DecodeWidth
249  val RenameWidth = coreParams.RenameWidth
250  val CommitWidth = coreParams.CommitWidth
251  val BrqSize = coreParams.BrqSize
252  val FtqSize = coreParams.FtqSize
253  val IssQueSize = coreParams.IssQueSize
254  val EnableLoadFastWakeUp = coreParams.EnableLoadFastWakeUp
255  val BrTagWidth = log2Up(BrqSize)
256  val NRPhyRegs = coreParams.NRPhyRegs
257  val PhyRegIdxWidth = log2Up(NRPhyRegs)
258  val RoqSize = coreParams.RoqSize
259  val LoadQueueSize = coreParams.LoadQueueSize
260  val StoreQueueSize = coreParams.StoreQueueSize
261  val dpParams = coreParams.dpParams
262  val exuParameters = coreParams.exuParameters
263  val NRIntReadPorts = coreParams.NRIntReadPorts
264  val NRIntWritePorts = coreParams.NRIntWritePorts
265  val NRMemReadPorts = exuParameters.LduCnt + 2 * exuParameters.StuCnt
266  val NRFpReadPorts = coreParams.NRFpReadPorts
267  val NRFpWritePorts = coreParams.NRFpWritePorts
268  val LoadPipelineWidth = coreParams.LoadPipelineWidth
269  val StorePipelineWidth = coreParams.StorePipelineWidth
270  val StoreBufferSize = coreParams.StoreBufferSize
271  val StoreBufferThreshold = coreParams.StoreBufferThreshold
272  val RefillSize = coreParams.RefillSize
273  val DTLBWidth = coreParams.LoadPipelineWidth + coreParams.StorePipelineWidth
274  val TlbEntrySize = coreParams.TlbEntrySize
275  val TlbSPEntrySize = coreParams.TlbSPEntrySize
276  val PtwL3EntrySize = coreParams.PtwL3EntrySize
277  val PtwSPEntrySize = coreParams.PtwSPEntrySize
278  val PtwL1EntrySize = coreParams.PtwL1EntrySize
279  val PtwL2EntrySize = coreParams.PtwL2EntrySize
280  val PtwMissQueueSize = coreParams.PtwMissQueueSize
281  val NumPerfCounters = coreParams.NumPerfCounters
282
283  val instBytes = if (HasCExtension) 2 else 4
284  val instOffsetBits = log2Ceil(instBytes)
285
286  val icacheParameters = coreParams.icacheParameters
287  val l1plusCacheParameters = coreParams.l1plusCacheParameters
288  val dcacheParameters = coreParams.dcacheParameters
289
290  val LRSCCycles = 100
291
292
293  // cache hierarchy configurations
294  val l1BusDataWidth = 256
295
296  val usePTWRepeater = coreParams.usePTWRepeater
297  val useFakeDCache = coreParams.useFakeDCache
298  val useFakePTW = coreParams.useFakePTW
299  val useFakeL1plusCache = coreParams.useFakeL1plusCache
300  // L2 configurations
301  val useFakeL2Cache = useFakeDCache && useFakePTW && useFakeL1plusCache || coreParams.useFakeL2Cache
302  val L1BusWidth = 256
303  val L2Size = coreParams.L2Size
304  val L2BlockSize = 64
305  val L2NWays = coreParams.L2NWays
306  val L2NSets = L2Size / L2BlockSize / L2NWays
307
308  // L3 configurations
309  val L2BusWidth = 256
310
311  // icache prefetcher
312  val l1plusPrefetcherParameters = L1plusPrefetcherParameters(
313    enable = true,
314    _type = "stream",
315    streamParams = StreamPrefetchParameters(
316      streamCnt = 2,
317      streamSize = 4,
318      ageWidth = 4,
319      blockBytes = l1plusCacheParameters.blockBytes,
320      reallocStreamOnMissInstantly = true,
321      cacheName = "icache"
322    )
323  )
324
325  // dcache prefetcher
326  val l2PrefetcherParameters = L2PrefetcherParameters(
327    enable = true,
328    _type = "bop", // "stream" or "bop"
329    streamParams = StreamPrefetchParameters(
330      streamCnt = 4,
331      streamSize = 4,
332      ageWidth = 4,
333      blockBytes = L2BlockSize,
334      reallocStreamOnMissInstantly = true,
335      cacheName = "dcache"
336    ),
337    bopParams = BOPParameters(
338      rrTableEntries = 256,
339      rrTagBits = 12,
340      scoreBits = 5,
341      roundMax = 50,
342      badScore = 1,
343      blockBytes = L2BlockSize,
344      nEntries = dcacheParameters.nMissEntries * 2 // TODO: this is too large
345    ),
346  )
347
348  // load violation predict
349  val ResetTimeMax2Pow = 20 //1078576
350  val ResetTimeMin2Pow = 10 //1024
351  // wait table parameters
352  val WaitTableSize = 1024
353  val MemPredPCWidth = log2Up(WaitTableSize)
354  val LWTUse2BitCounter = true
355  // store set parameters
356  val SSITSize = WaitTableSize
357  val LFSTSize = 32
358  val SSIDWidth = log2Up(LFSTSize)
359  val LFSTWidth = 4
360  val StoreSetEnable = true // LWT will be disabled if SS is enabled
361
362  val loadExuConfigs = coreParams.loadExuConfigs
363  val storeExuConfigs = coreParams.storeExuConfigs
364
365  val intExuConfigs = coreParams.intExuConfigs
366
367  val fpExuConfigs = coreParams.fpExuConfigs
368
369  val exuConfigs = coreParams.exuConfigs
370
371}
372