xref: /XiangShan/src/main/scala/xiangshan/package.scala (revision 48ae2f929153da8fe51635e68fa808c4ae68f951)
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    def fence        = "b0110".U
38
39    def fmac         = "b1000".U
40    def fmisc        = "b1001".U
41    def fDivSqrt     = "b1010".U
42
43    def ldu          = "b1100".U
44    def stu          = "b1101".U
45    def mou          = "b1110".U // for amo, lr, sc, fence
46
47    def apply() = UInt(log2Up(num).W)
48
49    def isIntExu(fuType: UInt) =  !fuType(3)
50    def isFpExu(fuType: UInt) = fuType(3, 2) === "b10".U
51    def isMemExu(fuType: UInt) = fuType(3, 2) === "b11".U
52    def isLoadExu(fuType: UInt) = fuType === ldu || fuType===mou
53    def isStoreExu(fuType: UInt) = fuType === stu
54
55    val functionNameMap = Map(
56      jmp.litValue() -> "jmp",
57      i2f.litValue() -> "int to float",
58      csr.litValue() -> "csr",
59      alu.litValue() -> "alu",
60      mul.litValue() -> "mul",
61      div.litValue() -> "div",
62      fence.litValue() -> "fence",
63      fmac.litValue() -> "fmac",
64      fmisc.litValue() -> "fmisc",
65      fDivSqrt.litValue() -> "fdiv/fsqrt",
66      ldu.litValue() -> "load",
67      stu.litValue() -> "store"
68    )
69
70  }
71
72  object FuOpType extends HasXSParameter {
73    def apply() = UInt(exuParameters.FuOpWidth.W)
74  }
75
76  object BTBtype {
77    def B = "b00".U  // branch
78    def J = "b01".U  // jump
79    def I = "b10".U  // indirect
80    def R = "b11".U  // return
81
82    def apply() = UInt(2.W)
83  }
84
85  object CommitType {
86    def INT   = "b00".U  // int
87    def FP    = "b01".U  // fp
88    def LOAD  = "b10".U  // load
89    def STORE = "b11".U  // store
90
91    def apply() = UInt(2.W)
92    def isLoadStore(commitType: UInt) = commitType(1)
93    def lsInstIsStore(commitType: UInt) = commitType(0)
94  }
95}
96