xref: /XiangShan/src/main/scala/xiangshan/backend/fu/vector/Bundles.scala (revision bb2f3f51dd67f6e16e0cc1ffe43368c9fc7e4aef)
1package xiangshan.backend.fu.vector
2
3import org.chipsalliance.cde.config.Parameters
4import chisel3._
5import chisel3.util._
6import xiangshan.XSBundle
7import xiangshan.XSCoreParamsKey
8import xiangshan.backend.decode.isa.bitfield.InstVType
9import xiangshan.backend.fu.VtypeStruct
10import _root_.utils.NamedUInt
11
12object Bundles {
13
14  /**
15    * vtype bundle, should not used as csr reg
16    */
17  class VType(implicit p: Parameters) extends Bundle {
18    val illegal = Bool()
19    val vma     = Bool()
20    val vta     = Bool()
21    val vsew    = VSew()
22    val vlmul   = VLmul()
23  }
24
25  /**
26    * vset module's vtype bundle, use 3 bits vsew to check if it is illegal
27    *
28    * we need to get 3 bits vsew in Vtype struct, then vset module can check if it is reserved.
29    * and we use 2 bits to store vsew in other places to save space
30    */
31  class VsetVType(implicit p: Parameters) extends XSBundle {
32    val illegal  = Bool()
33    val reserved = UInt((XLEN - 9).W)
34    val vma      = Bool()
35    val vta      = Bool()
36    val vsew     = VtypeVSew()
37    val vlmul    = VLmul()
38  }
39
40  object VType {
41    def apply()(implicit p: Parameters) : VType = {
42      new VType
43    }
44
45    def fromInstVType(instVType: InstVType)(implicit p: Parameters) : VType = {
46      val res = Wire(VType())
47      res.vma   := instVType.vma
48      res.vta   := instVType.vta
49      res.vsew  := instVType.vsew(VSew.width - 1, 0)
50      res.vlmul := instVType.vlmul
51      res.illegal := false.B // Todo: add illegal check function
52      res
53    }
54
55    def fromVtypeStruct(vtypeStruct: VtypeStruct)(implicit p: Parameters): VType = {
56      val res = Wire(VType())
57      res.illegal := vtypeStruct.vill
58      res.vma := vtypeStruct.vma
59      res.vta := vtypeStruct.vta
60      res.vsew := vtypeStruct.vsew(VSew.width - 1, 0)
61      res.vlmul := vtypeStruct.vlmul
62      res
63    }
64
65    def toVtypeStruct(vtype: VType)(implicit p: Parameters) : VtypeStruct = {
66      val res = WireInit(0.U.asTypeOf(new VtypeStruct))
67      res.vill := vtype.illegal
68      res.vma := vtype.vma
69      res.vta := vtype.vta
70      res.vsew := Cat(0.U(1.W), vtype.vsew)
71      res.vlmul := vtype.vlmul
72      res
73    }
74  }
75
76  object VsetVType {
77    def apply()(implicit p: Parameters) : VsetVType = {
78      new VsetVType
79    }
80
81    def fromInstVType(instVType: InstVType)(implicit p: Parameters) : VsetVType = {
82      val res = Wire(VsetVType())
83      res.vma   := instVType.vma
84      res.vta   := instVType.vta
85      res.vsew  := instVType.vsew
86      res.vlmul := instVType.vlmul
87      res.illegal := false.B
88      res.reserved := instVType.reserved
89      res
90    }
91
92    def fromVtypeStruct(vtypeStruct: VtypeStruct)(implicit p: Parameters): VsetVType = {
93      val res = Wire(VsetVType())
94      res.illegal := vtypeStruct.vill
95      res.vma := vtypeStruct.vma
96      res.vta := vtypeStruct.vta
97      res.vsew := vtypeStruct.vsew
98      res.vlmul := vtypeStruct.vlmul
99      res.reserved := vtypeStruct.reserved
100      res
101    }
102  }
103
104  class VConfig(implicit p: Parameters) extends Bundle {
105    val vtype = new VType
106    val vl    = Vl()
107  }
108
109  object VConfig {
110    def apply()(implicit p: Parameters) : VConfig = {
111      new VConfig()
112    }
113  }
114
115  def mu: UInt = 0.U(1.W)
116  def ma: UInt = 1.U(1.W)
117  def tu: UInt = 0.U(1.W)
118  def ta: UInt = 1.U(1.W)
119
120  // modify the width when support more vector data width
121  object VSew extends NamedUInt(2) {
122    def e8  : UInt = "b000".U(width.W)
123    def e16 : UInt = "b001".U(width.W)
124    def e32 : UInt = "b010".U(width.W)
125    def e64 : UInt = "b011".U(width.W)
126
127    def reserved: BitPat = BitPat("b1??")
128
129    def isReserved(sew: UInt) : Bool = {
130      require(sew.getWidth >= 2 && sew.getWidth <= 3)
131      if (sew.getWidth == 3) {
132        sew === reserved
133      } else {
134        false.B
135      }
136    }
137  }
138
139  object VtypeVSew extends NamedUInt(3)
140
141  object VLmul extends NamedUInt(3) {
142    def m1  : UInt = "b000".U(width.W)
143    def m2  : UInt = "b001".U(width.W)
144    def m4  : UInt = "b010".U(width.W)
145    def m8  : UInt = "b011".U(width.W)
146    def mf2 : UInt = "b111".U(width.W)
147    def mf4 : UInt = "b110".U(width.W)
148    def mf8 : UInt = "b101".U(width.W)
149
150    def reserved: BitPat = BitPat("b100")
151
152    def isReserved(vlmul: UInt) : Bool = {
153      require(vlmul.getWidth == 3)
154      vlmul === reserved
155    }
156  }
157
158  object Vl {
159    def apply()(implicit p: Parameters): UInt = UInt(width.W)
160
161    def width(implicit p: Parameters) = p(XSCoreParamsKey).vlWidth
162  }
163
164  object Vxsat extends NamedUInt(1)
165
166  object Vxrm extends NamedUInt(2)
167
168  object Nf extends NamedUInt(3)
169
170  object VEew extends NamedUInt(3)
171
172  object NumLsElem {
173    def apply()(implicit p: Parameters): UInt = UInt(width.W)
174
175    def width(implicit p: Parameters) = log2Up(p(XSCoreParamsKey).maxElemPerVreg) + 1
176  }
177
178  class Fpu extends Bundle{
179    val isFpToVecInst = Bool()
180    val isFP32Instr   = Bool()
181    val isFP64Instr   = Bool()
182    val isReduction   = Bool()
183    val isFoldTo1_2   = Bool()
184    val isFoldTo1_4   = Bool()
185    val isFoldTo1_8   = Bool()
186  }
187  object Fpu {
188    def apply() = new Fpu
189  }
190}
191