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