diff --git a/src/main/scala/rocket/CSR.scala b/src/main/scala/rocket/CSR.scala index e8c56c2d9bc..e195ce42176 100644 --- a/src/main/scala/rocket/CSR.scala +++ b/src/main/scala/rocket/CSR.scala @@ -246,40 +246,52 @@ class VConfig(implicit p: Parameters) extends CoreBundle { } object VType { - private def fromUInt(that: UInt, ignore_vill: Boolean)(implicit p: Parameters): VType = { + def fromUInt(that: UInt, ignore_vill: Boolean = false)(implicit p: Parameters): VType = { val res = 0.U.asTypeOf(new VType) val in = that.asTypeOf(res) - res.vill := (in.max_vsew < in.vsew) || in.reserved =/= 0 || in.vill - when (!res.vill || ignore_vill) { + val vill = (in.max_vsew < in.vsew) || !in.lmul_ok || in.reserved =/= 0 || in.vill + when (!vill || ignore_vill) { + res := in res.vsew := in.vsew(log2Ceil(1 + in.max_vsew) - 1, 0) - res.vlmul := in.vlmul } + res.reserved := 0.U + res.vill := vill res } - def fromUInt(that: UInt)(implicit p: Parameters): VType = fromUInt(that, false) - def computeVL(avl: UInt, vtype: UInt, currentVL: UInt, useCurrentVL: Bool, useMax: Bool, useZero: Bool)(implicit p: Parameters): UInt = VType.fromUInt(vtype, true).vl(avl, currentVL, useCurrentVL, useMax, useZero) } class VType(implicit p: Parameters) extends CoreBundle { val vill = Bool() - val reserved = UInt((xLen - 6).W) + val reserved = UInt((xLen - 9).W) + val vma = Bool() + val vta = Bool() + val vlmul_sign = Bool() val vsew = UInt(3.W) - val vlmul = UInt(2.W) + val vlmul_mag = UInt(2.W) + + def vlmul_signed: SInt = Cat(vlmul_sign, vlmul_mag).asSInt + + @deprecated("use vlmul_sign, vlmul_mag, or vlmul_signed", "RVV 0.9") + def vlmul: UInt = vlmul_mag + + def max_vsew = log2Ceil(eLen/8) + def max_vlmul = (1 << vlmul_mag.getWidth) - 1 + + def lmul_ok: Bool = (!this.vlmul_sign || this.vlmul_mag =/= 0) && + (this.vsew +& Cat(this.vlmul_sign, ~this.vlmul_mag) <= maxVLMax.log2) - val max_vsew = log2Ceil(eLen/8) + def minVLMax: Int = ((maxVLMax / eLen) >> ((1 << vlmul_mag.getWidth) - 1)) max 1 - def minVLMax = maxVLMax / eLen - def vlMax: UInt = (maxVLMax >> (this.vsew +& ~this.vlmul)).andNot(minVLMax-1) - def vlMaxInBytes: UInt = maxVLMax >> ~this.vlmul + def vlMax: UInt = (maxVLMax >> (this.vsew +& Cat(this.vlmul_sign, ~this.vlmul_mag))).andNot(minVLMax-1) def vl(avl: UInt, currentVL: UInt, useCurrentVL: Bool, useMax: Bool, useZero: Bool): UInt = { val atLeastMaxVLMax = useMax || Mux(useCurrentVL, currentVL >= maxVLMax, avl >= maxVLMax) val avl_lsbs = Mux(useCurrentVL, currentVL, avl)(maxVLMax.log2 - 1, 0) - val atLeastVLMax = atLeastMaxVLMax || (avl_lsbs & (-maxVLMax.S >> (this.vsew +& ~this.vlmul)).asUInt.andNot(minVLMax-1)).orR + val atLeastVLMax = atLeastMaxVLMax || (avl_lsbs & (-maxVLMax.S >> (this.vsew +& Cat(this.vlmul_sign, ~this.vlmul_mag))).asUInt.andNot(minVLMax-1)).orR val isZero = vill || useZero Mux(!isZero && atLeastVLMax, vlMax, 0.U) | Mux(!isZero && !atLeastVLMax, avl_lsbs, 0.U) } @@ -995,6 +1007,7 @@ class CSRFile( vio.vxrm := reg_vxrm.get when (reset.toBool) { + reg_vconfig.get.vl := 0.U reg_vconfig.get.vtype := 0.U.asTypeOf(new VType) reg_vconfig.get.vtype.vill := true } diff --git a/src/main/scala/rocket/Instructions.scala b/src/main/scala/rocket/Instructions.scala index 905d2198979..98269f48331 100644 --- a/src/main/scala/rocket/Instructions.scala +++ b/src/main/scala/rocket/Instructions.scala @@ -319,52 +319,40 @@ object Instructions { def CUSTOM3_RD_RS1_RS2 = BitPat("b?????????????????111?????1111011") def VSETVLI = BitPat("b0????????????????111?????1010111") def VSETVL = BitPat("b1000000??????????111?????1010111") - def VLB_V = BitPat("b???100?00000?????000?????0000111") - def VLH_V = BitPat("b???100?00000?????101?????0000111") - def VLW_V = BitPat("b???100?00000?????110?????0000111") - def VLE_V = BitPat("b???000?00000?????111?????0000111") - def VLBU_V = BitPat("b???000?00000?????000?????0000111") - def VLHU_V = BitPat("b???000?00000?????101?????0000111") - def VLWU_V = BitPat("b???000?00000?????110?????0000111") - def VSB_V = BitPat("b???000?00000?????000?????0100111") - def VSH_V = BitPat("b???000?00000?????101?????0100111") - def VSW_V = BitPat("b???000?00000?????110?????0100111") - def VSE_V = BitPat("b???000?00000?????111?????0100111") - def VLSB_V = BitPat("b???110???????????000?????0000111") - def VLSH_V = BitPat("b???110???????????101?????0000111") - def VLSW_V = BitPat("b???110???????????110?????0000111") - def VLSE_V = BitPat("b???010???????????111?????0000111") - def VLSBU_V = BitPat("b???010???????????000?????0000111") - def VLSHU_V = BitPat("b???010???????????101?????0000111") - def VLSWU_V = BitPat("b???010???????????110?????0000111") - def VSSB_V = BitPat("b???010???????????000?????0100111") - def VSSH_V = BitPat("b???010???????????101?????0100111") - def VSSW_V = BitPat("b???010???????????110?????0100111") - def VSSE_V = BitPat("b???010???????????111?????0100111") - def VLXB_V = BitPat("b???111???????????000?????0000111") - def VLXH_V = BitPat("b???111???????????101?????0000111") - def VLXW_V = BitPat("b???111???????????110?????0000111") - def VLXE_V = BitPat("b???011???????????111?????0000111") - def VLXBU_V = BitPat("b???011???????????000?????0000111") - def VLXHU_V = BitPat("b???011???????????101?????0000111") - def VLXWU_V = BitPat("b???011???????????110?????0000111") - def VSXB_V = BitPat("b???011???????????000?????0100111") - def VSXH_V = BitPat("b???011???????????101?????0100111") - def VSXW_V = BitPat("b???011???????????110?????0100111") - def VSXE_V = BitPat("b???011???????????111?????0100111") - def VSUXB_V = BitPat("b000111???????????000?????0100111") - def VSUXH_V = BitPat("b000111???????????101?????0100111") - def VSUXW_V = BitPat("b000111???????????110?????0100111") - def VSUXE_V = BitPat("b000111???????????111?????0100111") - def VLBFF_V = BitPat("b???100?10000?????000?????0000111") - def VLHFF_V = BitPat("b???100?10000?????101?????0000111") - def VLWFF_V = BitPat("b???100?10000?????110?????0000111") - def VLEFF_V = BitPat("b???000?10000?????111?????0000111") - def VLBUFF_V = BitPat("b???000?10000?????000?????0000111") - def VLHUFF_V = BitPat("b???000?10000?????101?????0000111") - def VLWUFF_V = BitPat("b???000?10000?????110?????0000111") - def VL1R_V = BitPat("b000000101000?????111?????0000111") - def VS1R_V = BitPat("b000000101000?????111?????0100111") + def VLE8_V = BitPat("b???000?00000?????000?????0000111") + def VLE16_V = BitPat("b???000?00000?????101?????0000111") + def VLE32_V = BitPat("b???000?00000?????110?????0000111") + def VLE64_V = BitPat("b???000?00000?????111?????0000111") + def VSE8_V = BitPat("b???000?00000?????000?????0100111") + def VSE16_V = BitPat("b???000?00000?????101?????0100111") + def VSE32_V = BitPat("b???000?00000?????110?????0100111") + def VSE64_V = BitPat("b???000?00000?????111?????0100111") + def VLSE8_V = BitPat("b???010???????????000?????0000111") + def VLSE16_V = BitPat("b???010???????????101?????0000111") + def VLSE32_V = BitPat("b???010???????????110?????0000111") + def VLSE64_V = BitPat("b???010???????????111?????0000111") + def VSSE8_V = BitPat("b???010???????????000?????0100111") + def VSSE16_V = BitPat("b???010???????????101?????0100111") + def VSSE32_V = BitPat("b???010???????????110?????0100111") + def VSSE64_V = BitPat("b???010???????????111?????0100111") + def VLXEI8_V = BitPat("b???011???????????000?????0000111") + def VLXEI16_V = BitPat("b???011???????????101?????0000111") + def VLXEI32_V = BitPat("b???011???????????110?????0000111") + def VLXEI64_V = BitPat("b???011???????????111?????0000111") + def VSXEI8_V = BitPat("b???011???????????000?????0100111") + def VSXEI16_V = BitPat("b???011???????????101?????0100111") + def VSXEI32_V = BitPat("b???011???????????110?????0100111") + def VSXEI64_V = BitPat("b???011???????????111?????0100111") + def VSUXEI8_V = BitPat("b000001???????????000?????0100111") + def VSUXEI16_V = BitPat("b000001???????????101?????0100111") + def VSUXEI32_V = BitPat("b000001???????????110?????0100111") + def VSUXEI64_V = BitPat("b000001???????????111?????0100111") + def VLE8FF_V = BitPat("b???000?10000?????000?????0000111") + def VLE16FF_V = BitPat("b???000?10000?????101?????0000111") + def VLE32FF_V = BitPat("b???000?10000?????110?????0000111") + def VLE64FF_V = BitPat("b???000?10000?????111?????0000111") + def VL1R_V = BitPat("b000000101000?????000?????0000111") + def VS1R_V = BitPat("b000000101000?????000?????0100111") def VFADD_VF = BitPat("b000000???????????101?????1010111") def VFSUB_VF = BitPat("b000010???????????101?????1010111") def VFMIN_VF = BitPat("b000100???????????101?????1010111") @@ -430,35 +418,29 @@ object Instructions { def VFNMACC_VV = BitPat("b101101???????????001?????1010111") def VFMSAC_VV = BitPat("b101110???????????001?????1010111") def VFNMSAC_VV = BitPat("b101111???????????001?????1010111") - def VFCVT_XU_F_V = BitPat("b100010??????00000001?????1010111") - def VFCVT_X_F_V = BitPat("b100010??????00001001?????1010111") - def VFCVT_F_XU_V = BitPat("b100010??????00010001?????1010111") - def VFCVT_F_X_V = BitPat("b100010??????00011001?????1010111") - def VFCVT_RTZ_XU_F_V = BitPat("b100010??????00110001?????1010111") - def VFCVT_RTZ_X_F_V = BitPat("b100010??????00111001?????1010111") - def VFWCVT_XU_F_V = BitPat("b100010??????01000001?????1010111") - def VFWCVT_X_F_V = BitPat("b100010??????01001001?????1010111") - def VFWCVT_F_XU_V = BitPat("b100010??????01010001?????1010111") - def VFWCVT_F_X_V = BitPat("b100010??????01011001?????1010111") - def VFWCVT_F_F_V = BitPat("b100010??????01100001?????1010111") - def VFWCVT_RTZ_XU_F_V = BitPat("b100010??????01110001?????1010111") - def VFWCVT_RTZ_X_F_V = BitPat("b100010??????01111001?????1010111") - def VFNCVT_XU_F_V = BitPat("b100010??????10000001?????1010111") - def VFNCVT_X_F_V = BitPat("b100010??????10001001?????1010111") - def VFNCVT_F_XU_V = BitPat("b100010??????10010001?????1010111") - def VFNCVT_F_X_V = BitPat("b100010??????10011001?????1010111") - def VFNCVT_F_F_V = BitPat("b100010??????10100001?????1010111") - def VFNCVT_ROD_F_F_V = BitPat("b100010??????10101001?????1010111") - def VFNCVT_RTZ_XU_F_W = BitPat("b100010??????10110001?????1010111") - def VFNCVT_RTZ_X_F_W = BitPat("b100010??????10111001?????1010111") - def VFNCVT_XU_F_W = BitPat("b100010??????10000001?????1010111") - def VFNCVT_X_F_W = BitPat("b100010??????10001001?????1010111") - def VFNCVT_F_XU_W = BitPat("b100010??????10010001?????1010111") - def VFNCVT_F_X_W = BitPat("b100010??????10011001?????1010111") - def VFNCVT_F_F_W = BitPat("b100010??????10100001?????1010111") - def VFNCVT_ROD_F_F_W = BitPat("b100010??????10101001?????1010111") - def VFSQRT_V = BitPat("b100011??????00000001?????1010111") - def VFCLASS_V = BitPat("b100011??????10000001?????1010111") + def VFCVT_XU_F_V = BitPat("b010010??????00000001?????1010111") + def VFCVT_X_F_V = BitPat("b010010??????00001001?????1010111") + def VFCVT_F_XU_V = BitPat("b010010??????00010001?????1010111") + def VFCVT_F_X_V = BitPat("b010010??????00011001?????1010111") + def VFCVT_RTZ_XU_F_V = BitPat("b010010??????00110001?????1010111") + def VFCVT_RTZ_X_F_V = BitPat("b010010??????00111001?????1010111") + def VFWCVT_XU_F_V = BitPat("b010010??????01000001?????1010111") + def VFWCVT_X_F_V = BitPat("b010010??????01001001?????1010111") + def VFWCVT_F_XU_V = BitPat("b010010??????01010001?????1010111") + def VFWCVT_F_X_V = BitPat("b010010??????01011001?????1010111") + def VFWCVT_F_F_V = BitPat("b010010??????01100001?????1010111") + def VFWCVT_RTZ_XU_F_V = BitPat("b010010??????01110001?????1010111") + def VFWCVT_RTZ_X_F_V = BitPat("b010010??????01111001?????1010111") + def VFNCVT_XU_F_W = BitPat("b010010??????10000001?????1010111") + def VFNCVT_X_F_W = BitPat("b010010??????10001001?????1010111") + def VFNCVT_F_XU_W = BitPat("b010010??????10010001?????1010111") + def VFNCVT_F_X_W = BitPat("b010010??????10011001?????1010111") + def VFNCVT_F_F_W = BitPat("b010010??????10100001?????1010111") + def VFNCVT_ROD_F_F_W = BitPat("b010010??????10101001?????1010111") + def VFNCVT_RTZ_XU_F_W = BitPat("b010010??????10110001?????1010111") + def VFNCVT_RTZ_X_F_W = BitPat("b010010??????10111001?????1010111") + def VFSQRT_V = BitPat("b010011??????00000001?????1010111") + def VFCLASS_V = BitPat("b010011??????10000001?????1010111") def VFWADD_VV = BitPat("b110000???????????001?????1010111") def VFWREDSUM_VS = BitPat("b110001???????????001?????1010111") def VFWSUB_VV = BitPat("b110010???????????001?????1010111") @@ -508,10 +490,6 @@ object Instructions { def VSRA_VX = BitPat("b101001???????????100?????1010111") def VSSRL_VX = BitPat("b101010???????????100?????1010111") def VSSRA_VX = BitPat("b101011???????????100?????1010111") - def VNSRL_VX = BitPat("b101100???????????100?????1010111") - def VNSRA_VX = BitPat("b101101???????????100?????1010111") - def VNCLIPU_VX = BitPat("b101110???????????100?????1010111") - def VNCLIP_VX = BitPat("b101111???????????100?????1010111") def VNSRL_WX = BitPat("b101100???????????100?????1010111") def VNSRA_WX = BitPat("b101101???????????100?????1010111") def VNCLIPU_WX = BitPat("b101110???????????100?????1010111") @@ -552,10 +530,6 @@ object Instructions { def VSRA_VV = BitPat("b101001???????????000?????1010111") def VSSRL_VV = BitPat("b101010???????????000?????1010111") def VSSRA_VV = BitPat("b101011???????????000?????1010111") - def VNSRL_VV = BitPat("b101100???????????000?????1010111") - def VNSRA_VV = BitPat("b101101???????????000?????1010111") - def VNCLIPU_VV = BitPat("b101110???????????000?????1010111") - def VNCLIP_VV = BitPat("b101111???????????000?????1010111") def VNSRL_WV = BitPat("b101100???????????000?????1010111") def VNSRA_WV = BitPat("b101101???????????000?????1010111") def VNCLIPU_WV = BitPat("b101110???????????000?????1010111") @@ -596,10 +570,6 @@ object Instructions { def VSRA_VI = BitPat("b101001???????????011?????1010111") def VSSRL_VI = BitPat("b101010???????????011?????1010111") def VSSRA_VI = BitPat("b101011???????????011?????1010111") - def VNSRL_VI = BitPat("b101100???????????011?????1010111") - def VNSRA_VI = BitPat("b101101???????????011?????1010111") - def VNCLIPU_VI = BitPat("b101110???????????011?????1010111") - def VNCLIP_VI = BitPat("b101111???????????011?????1010111") def VNSRL_WI = BitPat("b101100???????????011?????1010111") def VNSRA_WI = BitPat("b101101???????????011?????1010111") def VNCLIPU_WI = BitPat("b101110???????????011?????1010111") @@ -617,6 +587,12 @@ object Instructions { def VASUBU_VV = BitPat("b001010???????????010?????1010111") def VASUB_VV = BitPat("b001011???????????010?????1010111") def VMV_X_S = BitPat("b0100001?????00000010?????1010111") + def VZEXT_VF8 = BitPat("b010010??????00010010?????1010111") + def VSEXT_VF8 = BitPat("b010010??????00011010?????1010111") + def VZEXT_VF4 = BitPat("b010010??????00100010?????1010111") + def VSEXT_VF4 = BitPat("b010010??????00101010?????1010111") + def VZEXT_VF2 = BitPat("b010010??????00110010?????1010111") + def VSEXT_VF2 = BitPat("b010010??????00111010?????1010111") def VCOMPRESS_VM = BitPat("b0101111??????????010?????1010111") def VMANDNOT_MM = BitPat("b011000???????????010?????1010111") def VMAND_MM = BitPat("b011001???????????010?????1010111") @@ -693,24 +669,42 @@ object Instructions { def VWMACC_VX = BitPat("b111101???????????110?????1010111") def VWMACCUS_VX = BitPat("b111110???????????110?????1010111") def VWMACCSU_VX = BitPat("b111111???????????110?????1010111") - def VAMOSWAPW_V = BitPat("b00001????????????110?????0101111") - def VAMOADDW_V = BitPat("b00000????????????110?????0101111") - def VAMOXORW_V = BitPat("b00100????????????110?????0101111") - def VAMOANDW_V = BitPat("b01100????????????110?????0101111") - def VAMOORW_V = BitPat("b01000????????????110?????0101111") - def VAMOMINW_V = BitPat("b10000????????????110?????0101111") - def VAMOMAXW_V = BitPat("b10100????????????110?????0101111") - def VAMOMINUW_V = BitPat("b11000????????????110?????0101111") - def VAMOMAXUW_V = BitPat("b11100????????????110?????0101111") - def VAMOSWAPE_V = BitPat("b00001????????????111?????0101111") - def VAMOADDE_V = BitPat("b00000????????????111?????0101111") - def VAMOXORE_V = BitPat("b00100????????????111?????0101111") - def VAMOANDE_V = BitPat("b01100????????????111?????0101111") - def VAMOORE_V = BitPat("b01000????????????111?????0101111") - def VAMOMINE_V = BitPat("b10000????????????111?????0101111") - def VAMOMAXE_V = BitPat("b10100????????????111?????0101111") - def VAMOMINUE_V = BitPat("b11000????????????111?????0101111") - def VAMOMAXUE_V = BitPat("b11100????????????111?????0101111") + def VAMOSWAPEI8_V = BitPat("b00001????????????000?????0101111") + def VAMOADDEI8_V = BitPat("b00000????????????000?????0101111") + def VAMOXOREI8_V = BitPat("b00100????????????000?????0101111") + def VAMOANDEI8_V = BitPat("b01100????????????000?????0101111") + def VAMOOREI8_V = BitPat("b01000????????????000?????0101111") + def VAMOMINEI8_V = BitPat("b10000????????????000?????0101111") + def VAMOMAXEI8_V = BitPat("b10100????????????000?????0101111") + def VAMOMINUEI8_V = BitPat("b11000????????????000?????0101111") + def VAMOMAXUEI8_V = BitPat("b11100????????????000?????0101111") + def VAMOSWAPEI16_V = BitPat("b00001????????????101?????0101111") + def VAMOADDEI16_V = BitPat("b00000????????????101?????0101111") + def VAMOXOREI16_V = BitPat("b00100????????????101?????0101111") + def VAMOANDEI16_V = BitPat("b01100????????????101?????0101111") + def VAMOOREI16_V = BitPat("b01000????????????101?????0101111") + def VAMOMINEI16_V = BitPat("b10000????????????101?????0101111") + def VAMOMAXEI16_V = BitPat("b10100????????????101?????0101111") + def VAMOMINUEI16_V = BitPat("b11000????????????101?????0101111") + def VAMOMAXUEI16_V = BitPat("b11100????????????101?????0101111") + def VAMOSWAPEI32_V = BitPat("b00001????????????110?????0101111") + def VAMOADDEI32_V = BitPat("b00000????????????110?????0101111") + def VAMOXOREI32_V = BitPat("b00100????????????110?????0101111") + def VAMOANDEI32_V = BitPat("b01100????????????110?????0101111") + def VAMOOREI32_V = BitPat("b01000????????????110?????0101111") + def VAMOMINEI32_V = BitPat("b10000????????????110?????0101111") + def VAMOMAXEI32_V = BitPat("b10100????????????110?????0101111") + def VAMOMINUEI32_V = BitPat("b11000????????????110?????0101111") + def VAMOMAXUEI32_V = BitPat("b11100????????????110?????0101111") + def VAMOSWAPEI64_V = BitPat("b00001????????????111?????0101111") + def VAMOADDEI64_V = BitPat("b00000????????????111?????0101111") + def VAMOXOREI64_V = BitPat("b00100????????????111?????0101111") + def VAMOANDEI64_V = BitPat("b01100????????????111?????0101111") + def VAMOOREI64_V = BitPat("b01000????????????111?????0101111") + def VAMOMINEI64_V = BitPat("b10000????????????111?????0101111") + def VAMOMAXEI64_V = BitPat("b10100????????????111?????0101111") + def VAMOMINUEI64_V = BitPat("b11000????????????111?????0101111") + def VAMOMAXUEI64_V = BitPat("b11100????????????111?????0101111") def VMVNFR_V = BitPat("b1001111??????????011?????1010111") def SLLI_RV32 = BitPat("b0000000??????????001?????0010011") def SRLI_RV32 = BitPat("b0000000??????????101?????0010011") diff --git a/src/main/scala/util/package.scala b/src/main/scala/util/package.scala index 9025d4d978d..e07dfda9d5d 100644 --- a/src/main/scala/util/package.scala +++ b/src/main/scala/util/package.scala @@ -113,6 +113,24 @@ package object util { else Cat(UInt(0, n - x.getWidth), x) } + // shifts left by n if n >= 0, or right by -n if n < 0 + def << (n: SInt): UInt = { + val w = n.getWidth - 1 + require(w <= 30) + + val shifted = x << n(w-1, 0) + Mux(n(w), shifted >> (1 << w), shifted) + } + + // shifts right by n if n >= 0, or left by -n if n < 0 + def >> (n: SInt): UInt = { + val w = n.getWidth - 1 + require(w <= 30) + + val shifted = x << (1 << w) >> n(w-1, 0) + Mux(n(w), shifted, shifted >> (1 << w)) + } + // Like UInt.apply(hi, lo), but returns 0.U for zero-width extracts def extract(hi: Int, lo: Int): UInt = { require(hi >= lo-1)