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