xref: /XiangShan/src/main/scala/xiangshan/package.scala (revision a273862e37f1d43bee748f2a6353320a2f52f6f4)
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
17import chisel3._
18import chisel3.util._
19import chipsalliance.rocketchip.config.Parameters
20import freechips.rocketchip.tile.XLen
21import xiangshan.backend.fu._
22import xiangshan.backend.fu.fpu._
23import xiangshan.backend.exu._
24import xiangshan.backend.{AmoData, Std}
25
26package object xiangshan {
27  object SrcType {
28    def reg = "b00".U
29    def pc  = "b01".U
30    def imm = "b01".U
31    def fp  = "b10".U
32
33    def DC = imm // Don't Care
34
35    def isReg(srcType: UInt) = srcType===reg
36    def isPc(srcType: UInt) = srcType===pc
37    def isImm(srcType: UInt) = srcType===imm
38    def isFp(srcType: UInt) = srcType(1)
39    def isPcOrImm(srcType: UInt) = srcType(0)
40    def isRegOrFp(srcType: UInt) = !srcType(0)
41    def regIsFp(srcType: UInt) = srcType(1)
42
43    def apply() = UInt(2.W)
44  }
45
46  object SrcState {
47    def busy    = "b0".U
48    def rdy     = "b1".U
49    // def specRdy = "b10".U // speculative ready, for future use
50    def apply() = UInt(1.W)
51  }
52
53  object FuType {
54    def jmp          = "b0000".U
55    def i2f          = "b0001".U
56    def csr          = "b0010".U
57    def alu          = "b0110".U
58    def mul          = "b0100".U
59    def div          = "b0101".U
60    def fence        = "b0011".U
61    def bku          = "b0111".U
62
63    def fmac         = "b1000".U
64    def fmisc        = "b1011".U
65    def fDivSqrt     = "b1010".U
66
67    def ldu          = "b1100".U
68    def stu          = "b1101".U
69    def mou          = "b1111".U // for amo, lr, sc, fence
70
71    def num = 14
72
73    def apply() = UInt(log2Up(num).W)
74
75    def isIntExu(fuType: UInt) = !fuType(3)
76    def isJumpExu(fuType: UInt) = fuType === jmp
77    def isFpExu(fuType: UInt) = fuType(3, 2) === "b10".U
78    def isMemExu(fuType: UInt) = fuType(3, 2) === "b11".U
79    def isLoadStore(fuType: UInt) = isMemExu(fuType) && !fuType(1)
80    def isStoreExu(fuType: UInt) = isMemExu(fuType) && fuType(0)
81    def isAMO(fuType: UInt) = fuType(1)
82    def isFence(fuType: UInt) = fuType === fence
83    def isSvinvalBegin(fuType: UInt, func: UInt, flush: Bool) = isFence(fuType) && func === FenceOpType.nofence && !flush
84    def isSvinval(fuType: UInt, func: UInt, flush: Bool) = isFence(fuType) && func === FenceOpType.sfence && !flush
85    def isSvinvalEnd(fuType: UInt, func: UInt, flush: Bool) = isFence(fuType) && func === FenceOpType.nofence && flush
86
87
88    def jmpCanAccept(fuType: UInt) = !fuType(2)
89    def mduCanAccept(fuType: UInt) = fuType(2) && !fuType(1) || fuType(2) && fuType(1) && fuType(0)
90    def aluCanAccept(fuType: UInt) = fuType(2) && fuType(1) && !fuType(0)
91
92    def fmacCanAccept(fuType: UInt) = !fuType(1)
93    def fmiscCanAccept(fuType: UInt) = fuType(1)
94
95    def loadCanAccept(fuType: UInt) = !fuType(0)
96    def storeCanAccept(fuType: UInt) = fuType(0)
97
98    def storeIsAMO(fuType: UInt) = fuType(1)
99
100    val functionNameMap = Map(
101      jmp.litValue() -> "jmp",
102      i2f.litValue() -> "int_to_float",
103      csr.litValue() -> "csr",
104      alu.litValue() -> "alu",
105      mul.litValue() -> "mul",
106      div.litValue() -> "div",
107      fence.litValue() -> "fence",
108      bku.litValue() -> "bku",
109      fmac.litValue() -> "fmac",
110      fmisc.litValue() -> "fmisc",
111      fDivSqrt.litValue() -> "fdiv/fsqrt",
112      ldu.litValue() -> "load",
113      stu.litValue() -> "store",
114      mou.litValue() -> "mou"
115    )
116  }
117
118  object FuOpType {
119    def apply() = UInt(7.W)
120  }
121
122  object CommitType {
123    def NORMAL = "b000".U  // int/fp
124    def BRANCH = "b001".U  // branch
125    def LOAD   = "b010".U  // load
126    def STORE  = "b011".U  // store
127
128    def apply() = UInt(3.W)
129    def isFused(commitType: UInt): Bool = commitType(2)
130    def isLoadStore(commitType: UInt): Bool = !isFused(commitType) && commitType(1)
131    def lsInstIsStore(commitType: UInt): Bool = commitType(0)
132    def isStore(commitType: UInt): Bool = isLoadStore(commitType) && lsInstIsStore(commitType)
133    def isBranch(commitType: UInt): Bool = commitType(0) && !commitType(1) && !isFused(commitType)
134  }
135
136  object RedirectLevel {
137    def flushAfter = "b0".U
138    def flush      = "b1".U
139
140    def apply() = UInt(1.W)
141    // def isUnconditional(level: UInt) = level(1)
142    def flushItself(level: UInt) = level(0)
143    // def isException(level: UInt) = level(1) && level(0)
144  }
145
146  object ExceptionVec {
147    def apply() = Vec(16, Bool())
148  }
149
150  object PMAMode {
151    def R = "b1".U << 0 //readable
152    def W = "b1".U << 1 //writeable
153    def X = "b1".U << 2 //executable
154    def I = "b1".U << 3 //cacheable: icache
155    def D = "b1".U << 4 //cacheable: dcache
156    def S = "b1".U << 5 //enable speculative access
157    def A = "b1".U << 6 //enable atomic operation, A imply R & W
158    def C = "b1".U << 7 //if it is cacheable is configable
159    def Reserved = "b0".U
160
161    def apply() = UInt(7.W)
162
163    def read(mode: UInt) = mode(0)
164    def write(mode: UInt) = mode(1)
165    def execute(mode: UInt) = mode(2)
166    def icache(mode: UInt) = mode(3)
167    def dcache(mode: UInt) = mode(4)
168    def speculate(mode: UInt) = mode(5)
169    def atomic(mode: UInt) = mode(6)
170    def configable_cache(mode: UInt) = mode(7)
171
172    def strToMode(s: String) = {
173      var result = 0.U(8.W)
174      if (s.toUpperCase.indexOf("R") >= 0) result = result + R
175      if (s.toUpperCase.indexOf("W") >= 0) result = result + W
176      if (s.toUpperCase.indexOf("X") >= 0) result = result + X
177      if (s.toUpperCase.indexOf("I") >= 0) result = result + I
178      if (s.toUpperCase.indexOf("D") >= 0) result = result + D
179      if (s.toUpperCase.indexOf("S") >= 0) result = result + S
180      if (s.toUpperCase.indexOf("A") >= 0) result = result + A
181      if (s.toUpperCase.indexOf("C") >= 0) result = result + C
182      result
183    }
184  }
185
186
187  object CSROpType {
188    def jmp  = "b000".U
189    def wrt  = "b001".U
190    def set  = "b010".U
191    def clr  = "b011".U
192    def wrti = "b101".U
193    def seti = "b110".U
194    def clri = "b111".U
195  }
196
197  // jump
198  object JumpOpType {
199    def jal  = "b00".U
200    def jalr = "b01".U
201    def auipc = "b10".U
202//    def call = "b11_011".U
203//    def ret  = "b11_100".U
204    def jumpOpisJalr(op: UInt) = op(0)
205    def jumpOpisAuipc(op: UInt) = op(1)
206  }
207
208  object FenceOpType {
209    def fence  = "b10000".U
210    def sfence = "b10001".U
211    def fencei = "b10010".U
212    def nofence= "b00000".U
213  }
214
215  object ALUOpType {
216    // shift optype
217    def slliuw     = "b000_0000".U // slliuw: ZEXT(src1[31:0]) << shamt
218    def sll        = "b000_0001".U // sll:     src1 << src2
219
220    def bclr       = "b000_0010".U // bclr:    src1 & ~(1 << src2[5:0])
221    def bset       = "b000_0011".U // bset:    src1 | (1 << src2[5:0])
222    def binv       = "b000_0100".U // binv:    src1 ^ ~(1 << src2[5:0])
223
224    def srl        = "b000_0101".U // srl:     src1 >> src2
225    def bext       = "b000_0110".U // bext:    (src1 >> src2)[0]
226    def sra        = "b000_0111".U // sra:     src1 >> src2 (arithmetic)
227
228    def rol        = "b000_1001".U // rol:     (src1 << src2) | (src1 >> (xlen - src2))
229    def ror        = "b000_1011".U // ror:     (src1 >> src2) | (src1 << (xlen - src2))
230
231    // RV64 32bit optype
232    def addw       = "b001_0000".U // addw:      SEXT((src1 + src2)[31:0])
233    def oddaddw    = "b001_0001".U // oddaddw:   SEXT((src1[0] + src2)[31:0])
234    def subw       = "b001_0010".U // subw:      SEXT((src1 - src2)[31:0])
235
236    def addwbit    = "b001_0100".U // addwbit:   (src1 + src2)[0]
237    def addwbyte   = "b001_0101".U // addwbyte:  (src1 + src2)[7:0]
238    def addwzexth  = "b001_0110".U // addwzexth: ZEXT((src1  + src2)[15:0])
239    def addwsexth  = "b001_0111".U // addwsexth: SEXT((src1  + src2)[15:0])
240
241    def sllw       = "b001_1000".U // sllw:     SEXT((src1 << src2)[31:0])
242    def srlw       = "b001_1001".U // srlw:     SEXT((src1[31:0] >> src2)[31:0])
243    def sraw       = "b001_1010".U // sraw:     SEXT((src1[31:0] >> src2)[31:0])
244    def rolw       = "b001_1100".U
245    def rorw       = "b001_1101".U
246
247    // ADD-op
248    def adduw      = "b010_0000".U // adduw:  src1[31:0]  + src2
249    def add        = "b010_0001".U // add:     src1        + src2
250    def oddadd     = "b010_0010".U // oddadd:  src1[0]     + src2
251
252    def sr29add    = "b010_0100".U // sr29add: src1[63:29] + src2
253    def sr30add    = "b010_0101".U // sr30add: src1[63:30] + src2
254    def sr31add    = "b010_0110".U // sr31add: src1[63:31] + src2
255    def sr32add    = "b010_0111".U // sr32add: src1[63:32] + src2
256
257    def sh1adduw   = "b010_1000".U // sh1adduw: {src1[31:0], 1'b0} + src2
258    def sh1add     = "b010_1001".U // sh1add: {src1[62:0], 1'b0} + src2
259    def sh2adduw   = "b010_1010".U // sh2add_uw: {src1[31:0], 2'b0} + src2
260    def sh2add     = "b010_1011".U // sh2add: {src1[61:0], 2'b0} + src2
261    def sh3adduw   = "b010_1100".U // sh3add_uw: {src1[31:0], 3'b0} + src2
262    def sh3add     = "b010_1101".U // sh3add: {src1[60:0], 3'b0} + src2
263    def sh4add     = "b010_1111".U // sh4add: {src1[59:0], 4'b0} + src2
264
265    // SUB-op: src1 - src2
266    def sub        = "b011_0000".U
267    def sltu       = "b011_0001".U
268    def slt        = "b011_0010".U
269    def maxu       = "b011_0100".U
270    def minu       = "b011_0101".U
271    def max        = "b011_0110".U
272    def min        = "b011_0111".U
273
274    // branch
275    def beq        = "b111_0000".U
276    def bne        = "b111_0010".U
277    def blt        = "b111_1000".U
278    def bge        = "b111_1010".U
279    def bltu       = "b111_1100".U
280    def bgeu       = "b111_1110".U
281
282    // misc optype
283    def and        = "b100_0000".U
284    def andn       = "b100_0001".U
285    def or         = "b100_0010".U
286    def orn        = "b100_0011".U
287    def xor        = "b100_0100".U
288    def xnor       = "b100_0101".U
289    def orcb       = "b100_0110".U
290
291    def sextb      = "b100_1000".U
292    def packh      = "b100_1001".U
293    def sexth      = "b100_1010".U
294    def packw      = "b100_1011".U
295
296    def revb       = "b101_0000".U
297    def rev8       = "b101_0001".U
298    def pack       = "b101_0010".U
299    def orh48      = "b101_0011".U
300
301    def szewl1     = "b101_1000".U
302    def szewl2     = "b101_1001".U
303    def szewl3     = "b101_1010".U
304    def byte2      = "b101_1011".U
305
306    def andlsb     = "b110_0000".U
307    def andzexth   = "b110_0001".U
308    def orlsb      = "b110_0010".U
309    def orzexth    = "b110_0011".U
310    def xorlsb     = "b110_0100".U
311    def xorzexth   = "b110_0101".U
312    def orcblsb    = "b110_0110".U
313    def orcbzexth  = "b110_0111".U
314
315    def isAddw(func: UInt) = func(6, 4) === "b001".U && !func(3) && !func(1)
316    def isSimpleLogic(func: UInt) = func(6, 4) === "b100".U && !func(0)
317    def logicToLsb(func: UInt) = Cat("b110".U(3.W), func(3, 1), 0.U(1.W))
318    def logicToZexth(func: UInt) = Cat("b110".U(3.W), func(3, 1), 1.U(1.W))
319    def isBranch(func: UInt) = func(6, 4) === "b111".U
320    def getBranchType(func: UInt) = func(3, 2)
321    def isBranchInvert(func: UInt) = func(1)
322
323    def apply() = UInt(7.W)
324  }
325
326  object MDUOpType {
327    // mul
328    // bit encoding: | type (2bit) | isWord(1bit) | opcode(2bit) |
329    def mul    = "b00000".U
330    def mulh   = "b00001".U
331    def mulhsu = "b00010".U
332    def mulhu  = "b00011".U
333    def mulw   = "b00100".U
334
335    def mulw7  = "b01100".U
336
337    // div
338    // bit encoding: | type (2bit) | isWord(1bit) | isSign(1bit) | opcode(1bit) |
339    def div    = "b10000".U
340    def divu   = "b10010".U
341    def rem    = "b10001".U
342    def remu   = "b10011".U
343
344    def divw   = "b10100".U
345    def divuw  = "b10110".U
346    def remw   = "b10101".U
347    def remuw  = "b10111".U
348
349    def isMul(op: UInt) = !op(4)
350    def isDiv(op: UInt) = op(4)
351
352    def isDivSign(op: UInt) = isDiv(op) && !op(1)
353    def isW(op: UInt) = op(2)
354    def isH(op: UInt) = (isDiv(op) && op(0)) || (isMul(op) && op(1, 0) =/= 0.U)
355    def getMulOp(op: UInt) = op(1, 0)
356  }
357
358  object LSUOpType {
359    // load pipeline
360
361    // normal load
362    // Note: bit(1, 0) are size, DO NOT CHANGE
363    // bit encoding: | load 0 | is unsigned(1bit) | size(2bit) |
364    def lb       = "b0000".U
365    def lh       = "b0001".U
366    def lw       = "b0010".U
367    def ld       = "b0011".U
368    def lbu      = "b0100".U
369    def lhu      = "b0101".U
370    def lwu      = "b0110".U
371
372    // Zicbop software prefetch
373    // bit encoding: | prefetch 1 | 0 | prefetch type (2bit) |
374    def prefetch_i = "b1000".U // TODO
375    def prefetch_r = "b1001".U
376    def prefetch_w = "b1010".U
377
378    def isPrefetch(op: UInt): Bool = op(3)
379
380    // store pipeline
381    // normal store
382    // bit encoding: | store 00 | size(2bit) |
383    def sb       = "b0000".U
384    def sh       = "b0001".U
385    def sw       = "b0010".U
386    def sd       = "b0011".U
387
388    // l1 cache op
389    // bit encoding: | cbo_zero 01 | size(2bit) 11 |
390    def cbo_zero  = "b0111".U
391
392    // llc op
393    // bit encoding: | prefetch 11 | suboptype(2bit) |
394    def cbo_clean = "b1100".U
395    def cbo_flush = "b1101".U
396    def cbo_inval = "b1110".U
397
398    def isCbo(op: UInt): Bool = op(3, 2) === "b11".U
399
400    // atomics
401    // bit(1, 0) are size
402    // since atomics use a different fu type
403    // so we can safely reuse other load/store's encodings
404    // bit encoding: | optype(4bit) | size (2bit) |
405    def lr_w      = "b000010".U
406    def sc_w      = "b000110".U
407    def amoswap_w = "b001010".U
408    def amoadd_w  = "b001110".U
409    def amoxor_w  = "b010010".U
410    def amoand_w  = "b010110".U
411    def amoor_w   = "b011010".U
412    def amomin_w  = "b011110".U
413    def amomax_w  = "b100010".U
414    def amominu_w = "b100110".U
415    def amomaxu_w = "b101010".U
416
417    def lr_d      = "b000011".U
418    def sc_d      = "b000111".U
419    def amoswap_d = "b001011".U
420    def amoadd_d  = "b001111".U
421    def amoxor_d  = "b010011".U
422    def amoand_d  = "b010111".U
423    def amoor_d   = "b011011".U
424    def amomin_d  = "b011111".U
425    def amomax_d  = "b100011".U
426    def amominu_d = "b100111".U
427    def amomaxu_d = "b101011".U
428
429    def size(op: UInt) = op(1,0)
430  }
431
432  object BKUOpType {
433
434    def clmul       = "b000000".U
435    def clmulh      = "b000001".U
436    def clmulr      = "b000010".U
437    def xpermn      = "b000100".U
438    def xpermb      = "b000101".U
439
440    def clz         = "b001000".U
441    def clzw        = "b001001".U
442    def ctz         = "b001010".U
443    def ctzw        = "b001011".U
444    def cpop        = "b001100".U
445    def cpopw       = "b001101".U
446
447    // 01xxxx is reserve
448    def aes64es     = "b100000".U
449    def aes64esm    = "b100001".U
450    def aes64ds     = "b100010".U
451    def aes64dsm    = "b100011".U
452    def aes64im     = "b100100".U
453    def aes64ks1i   = "b100101".U
454    def aes64ks2    = "b100110".U
455
456    // merge to two instruction sm4ks & sm4ed
457    def sm4ks0      = "b101000".U
458    def sm4ks1      = "b101001".U
459    def sm4ks2      = "b101010".U
460    def sm4ks3      = "b101011".U
461    def sm4ed0      = "b101100".U
462    def sm4ed1      = "b101101".U
463    def sm4ed2      = "b101110".U
464    def sm4ed3      = "b101111".U
465
466    def sha256sum0  = "b110000".U
467    def sha256sum1  = "b110001".U
468    def sha256sig0  = "b110010".U
469    def sha256sig1  = "b110011".U
470    def sha512sum0  = "b110100".U
471    def sha512sum1  = "b110101".U
472    def sha512sig0  = "b110110".U
473    def sha512sig1  = "b110111".U
474
475    def sm3p0       = "b111000".U
476    def sm3p1       = "b111001".U
477  }
478
479  object BTBtype {
480    def B = "b00".U  // branch
481    def J = "b01".U  // jump
482    def I = "b10".U  // indirect
483    def R = "b11".U  // return
484
485    def apply() = UInt(2.W)
486  }
487
488  object SelImm {
489    def IMM_X  = "b0111".U
490    def IMM_S  = "b0000".U
491    def IMM_SB = "b0001".U
492    def IMM_U  = "b0010".U
493    def IMM_UJ = "b0011".U
494    def IMM_I  = "b0100".U
495    def IMM_Z  = "b0101".U
496    def INVALID_INSTR = "b0110".U
497    def IMM_B6 = "b1000".U
498
499    def apply() = UInt(4.W)
500  }
501
502  def dividerGen(p: Parameters) = new SRT16Divider(p(XLen))(p)
503  def multiplierGen(p: Parameters) = new ArrayMultiplier(p(XLen) + 1)(p)
504  def aluGen(p: Parameters) = new Alu()(p)
505  def bkuGen(p: Parameters) = new Bku()(p)
506  def jmpGen(p: Parameters) = new Jump()(p)
507  def fenceGen(p: Parameters) = new Fence()(p)
508  def csrGen(p: Parameters) = new CSR()(p)
509  def i2fGen(p: Parameters) = new IntToFP()(p)
510  def fmacGen(p: Parameters) = new FMA()(p)
511  def f2iGen(p: Parameters) = new FPToInt()(p)
512  def f2fGen(p: Parameters) = new FPToFP()(p)
513  def fdivSqrtGen(p: Parameters) = new FDivSqrt()(p)
514  def stdGen(p: Parameters) = new Std()(p)
515  def mouDataGen(p: Parameters) = new AmoData()(p)
516
517  def f2iSel(uop: MicroOp): Bool = {
518    uop.ctrl.rfWen
519  }
520
521  def i2fSel(uop: MicroOp): Bool = {
522    uop.ctrl.fpu.fromInt
523  }
524
525  def f2fSel(uop: MicroOp): Bool = {
526    val ctrl = uop.ctrl.fpu
527    ctrl.fpWen && !ctrl.div && !ctrl.sqrt
528  }
529
530  def fdivSqrtSel(uop: MicroOp): Bool = {
531    val ctrl = uop.ctrl.fpu
532    ctrl.div || ctrl.sqrt
533  }
534
535  val aluCfg = FuConfig(
536    name = "alu",
537    fuGen = aluGen,
538    fuSel = (uop: MicroOp) => uop.ctrl.fuType === FuType.alu,
539    fuType = FuType.alu,
540    numIntSrc = 2,
541    numFpSrc = 0,
542    writeIntRf = true,
543    writeFpRf = false,
544    hasRedirect = true,
545  )
546
547  val jmpCfg = FuConfig(
548    name = "jmp",
549    fuGen = jmpGen,
550    fuSel = (uop: MicroOp) => uop.ctrl.fuType === FuType.jmp,
551    fuType = FuType.jmp,
552    numIntSrc = 1,
553    numFpSrc = 0,
554    writeIntRf = true,
555    writeFpRf = false,
556    hasRedirect = true,
557  )
558
559  val fenceCfg = FuConfig(
560    name = "fence",
561    fuGen = fenceGen,
562    fuSel = (uop: MicroOp) => uop.ctrl.fuType === FuType.fence,
563    FuType.fence, 2, 0, writeIntRf = false, writeFpRf = false, hasRedirect = false,
564    latency = UncertainLatency(), // TODO: need rewrite latency structure, not just this value,
565    hasExceptionOut = true
566  )
567
568  val csrCfg = FuConfig(
569    name = "csr",
570    fuGen = csrGen,
571    fuSel = (uop: MicroOp) => uop.ctrl.fuType === FuType.csr,
572    fuType = FuType.csr,
573    numIntSrc = 1,
574    numFpSrc = 0,
575    writeIntRf = true,
576    writeFpRf = false,
577    hasRedirect = false,
578    hasExceptionOut = true
579  )
580
581  val i2fCfg = FuConfig(
582    name = "i2f",
583    fuGen = i2fGen,
584    fuSel = i2fSel,
585    FuType.i2f,
586    numIntSrc = 1,
587    numFpSrc = 0,
588    writeIntRf = false,
589    writeFpRf = true,
590    hasRedirect = false,
591    latency = CertainLatency(2),
592    fastUopOut = true, fastImplemented = true
593  )
594
595  val divCfg = FuConfig(
596    name = "div",
597    fuGen = dividerGen,
598    fuSel = (uop: MicroOp) => uop.ctrl.fuType === FuType.div,
599    FuType.div,
600    2,
601    0,
602    writeIntRf = true,
603    writeFpRf = false,
604    hasRedirect = false,
605    latency = UncertainLatency(),
606    fastUopOut = true,
607    fastImplemented = false
608  )
609
610  val mulCfg = FuConfig(
611    name = "mul",
612    fuGen = multiplierGen,
613    fuSel = (uop: MicroOp) => uop.ctrl.fuType === FuType.mul,
614    FuType.mul,
615    2,
616    0,
617    writeIntRf = true,
618    writeFpRf = false,
619    hasRedirect = false,
620    latency = CertainLatency(2),
621    fastUopOut = true,
622    fastImplemented = true
623  )
624
625  val bkuCfg = FuConfig(
626    name = "bku",
627    fuGen = bkuGen,
628    fuSel = (uop: MicroOp) => uop.ctrl.fuType === FuType.bku,
629    fuType = FuType.bku,
630    numIntSrc = 2,
631    numFpSrc = 0,
632    writeIntRf = true,
633    writeFpRf = false,
634    hasRedirect = false,
635    latency = CertainLatency(1),
636    fastUopOut = true,
637    fastImplemented = true
638 )
639
640  val fmacCfg = FuConfig(
641    name = "fmac",
642    fuGen = fmacGen,
643    fuSel = _ => true.B,
644    FuType.fmac, 0, 3, writeIntRf = false, writeFpRf = true, hasRedirect = false,
645    latency = UncertainLatency(), fastUopOut = true, fastImplemented = true
646  )
647
648  val f2iCfg = FuConfig(
649    name = "f2i",
650    fuGen = f2iGen,
651    fuSel = f2iSel,
652    FuType.fmisc, 0, 1, writeIntRf = true, writeFpRf = false, hasRedirect = false, CertainLatency(2),
653    fastUopOut = true, fastImplemented = true
654  )
655
656  val f2fCfg = FuConfig(
657    name = "f2f",
658    fuGen = f2fGen,
659    fuSel = f2fSel,
660    FuType.fmisc, 0, 1, writeIntRf = false, writeFpRf = true, hasRedirect = false, CertainLatency(2),
661    fastUopOut = true, fastImplemented = true
662  )
663
664  val fdivSqrtCfg = FuConfig(
665    name = "fdivSqrt",
666    fuGen = fdivSqrtGen,
667    fuSel = fdivSqrtSel,
668    FuType.fDivSqrt, 0, 2, writeIntRf = false, writeFpRf = true, hasRedirect = false, UncertainLatency(),
669    fastUopOut = true, fastImplemented = false, hasInputBuffer = true
670  )
671
672  val lduCfg = FuConfig(
673    "ldu",
674    null, // DontCare
675    (uop: MicroOp) => FuType.loadCanAccept(uop.ctrl.fuType),
676    FuType.ldu, 1, 0, writeIntRf = true, writeFpRf = true, hasRedirect = false,
677    latency = UncertainLatency(), hasExceptionOut = true
678  )
679
680  val staCfg = FuConfig(
681    "sta",
682    null,
683    (uop: MicroOp) => FuType.storeCanAccept(uop.ctrl.fuType),
684    FuType.stu, 1, 0, writeIntRf = false, writeFpRf = false, hasRedirect = false,
685    latency = UncertainLatency(), hasExceptionOut = true
686  )
687
688  val stdCfg = FuConfig(
689    "std",
690    fuGen = stdGen, fuSel = (uop: MicroOp) => FuType.storeCanAccept(uop.ctrl.fuType), FuType.stu, 1, 1,
691    writeIntRf = false, writeFpRf = false, hasRedirect = false, latency = CertainLatency(1)
692  )
693
694  val mouCfg = FuConfig(
695    "mou",
696    null,
697    (uop: MicroOp) => FuType.storeCanAccept(uop.ctrl.fuType),
698    FuType.mou, 1, 0, writeIntRf = false, writeFpRf = false, hasRedirect = false,
699    latency = UncertainLatency(), hasExceptionOut = true
700  )
701
702  val mouDataCfg = FuConfig(
703    "mou",
704    mouDataGen,
705    (uop: MicroOp) => FuType.storeCanAccept(uop.ctrl.fuType),
706    FuType.mou, 1, 0, writeIntRf = false, writeFpRf = false, hasRedirect = false,
707    latency = UncertainLatency(), hasExceptionOut = true
708  )
709
710  val JumpExeUnitCfg = ExuConfig("JmpExeUnit", "Int", Seq(jmpCfg, i2fCfg), 2, Int.MaxValue)
711  val AluExeUnitCfg = ExuConfig("AluExeUnit", "Int", Seq(aluCfg), 0, Int.MaxValue)
712  val JumpCSRExeUnitCfg = ExuConfig("JmpCSRExeUnit", "Int", Seq(jmpCfg, csrCfg, fenceCfg, i2fCfg), 2, Int.MaxValue)
713  val MulDivExeUnitCfg = ExuConfig("MulDivExeUnit", "Int", Seq(mulCfg, divCfg, bkuCfg), 1, Int.MaxValue)
714  val FmacExeUnitCfg = ExuConfig("FmacExeUnit", "Fp", Seq(fmacCfg), Int.MaxValue, 0)
715  val FmiscExeUnitCfg = ExuConfig(
716    "FmiscExeUnit",
717    "Fp",
718    Seq(f2iCfg, f2fCfg, fdivSqrtCfg),
719    Int.MaxValue, 1
720  )
721  val LdExeUnitCfg = ExuConfig("LoadExu", "Mem", Seq(lduCfg), wbIntPriority = 0, wbFpPriority = 0, extendsExu = false)
722  val StaExeUnitCfg = ExuConfig("StaExu", "Mem", Seq(staCfg, mouCfg), wbIntPriority = Int.MaxValue, wbFpPriority = Int.MaxValue, extendsExu = false)
723  val StdExeUnitCfg = ExuConfig("StdExu", "Mem", Seq(stdCfg, mouDataCfg), wbIntPriority = Int.MaxValue, wbFpPriority = Int.MaxValue, extendsExu = false)
724}
725