xref: /XiangShan/src/main/scala/xiangshan/package.scala (revision de59342305cf26dec4c8351e499322ab34c7b4ba)
1import chisel3._
2import chisel3.util._
3
4package object xiangshan {
5  object SrcType {
6    def reg = "b00".U
7    def pc  = "b01".U
8    def imm = "b01".U
9    def fp  = "b10".U
10
11    def isReg(srcType: UInt) = srcType===reg
12    def isPc(srcType: UInt) = srcType===pc
13    def isImm(srcType: UInt) = srcType===imm
14    def isFp(srcType: UInt) = srcType===fp
15    def isPcImm(srcType: UInt) = isPc(srcType) || isImm(srcType)
16    def isRegFp(srcType: UInt) = isReg(srcType) || isFp(srcType)
17
18    def apply() = UInt(2.W)
19  }
20
21  object SrcState {
22    def busy    = "b00".U
23    def rdy     = "b01".U
24    def specRdy = "b10".U // speculative ready, for future use
25    def apply() = UInt(2.W)
26  }
27
28  object FuType extends HasXSParameter {
29    def num           = exuParameters.NRFuType
30
31    def jmp          = "b0000".U
32    def i2f          = "b0001".U
33    def csr          = "b0010".U
34    def alu          = "b0011".U
35    def mul          = "b0100".U
36    def div          = "b0101".U
37
38    def fmac         = "b1000".U
39    def fmisc        = "b1001".U
40    def fDivSqrt     = "b1010".U
41
42    def ldu          = "b1100".U
43    def stu          = "b1101".U
44
45    def apply() = UInt(log2Up(num).W)
46
47    def isIntExu(fuType: UInt) =  !fuType(3)
48    def isFpExu(fuType: UInt) = fuType(3, 2) === "b10".U
49    def isMemExu(fuType: UInt) = fuType(3, 2) === "b11".U
50    def isLoadExu(fuType: UInt) = fuType === ldu
51    def isStoreExu(fuType: UInt) = fuType === stu
52
53    val functionNameMap = Map(
54      jmp.litValue() -> "jmp",
55      i2f.litValue() -> "int to float",
56      csr.litValue() -> "csr",
57      alu.litValue() -> "alu",
58      mul.litValue() -> "mul",
59      div.litValue() -> "div",
60      fmac.litValue() -> "fmac",
61      fmisc.litValue() -> "fmisc",
62      fDivSqrt.litValue() -> "fdiv/fsqrt",
63      ldu.litValue() -> "load",
64      stu.litValue() -> "store"
65    )
66
67  }
68
69  object FuOpType extends HasXSParameter {
70    def apply() = UInt(exuParameters.FuOpWidth.W)
71  }
72
73  object BTBtype {
74    def B = "b00".U  // branch
75    def J = "b01".U  // jump
76    def I = "b10".U  // indirect
77    def R = "b11".U  // return
78
79    def apply() = UInt(2.W)
80  }
81
82  object CommitType {
83    def INT = "b00".U    // int
84    def FP = "b01".U     // fp
85    def LOAD = "b10".U   // load
86    def STORE = "b11".U  // store
87
88    def apply() = UInt(2.W)
89    def isLoadStore(commitType: UInt) = commitType(1)
90  }
91}
92