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