vsetvli
Set vector length immediate
Sets the vector length register vl and vector type register vtype based on immediate values. Configures SEW, LMUL, and other vector parameters for subsequent vector operations.
Decode Variables
Bits<11> vtypei = $encoding[30:20];
Bits<5> xs1 = $encoding[19:15];
Bits<5> xd = $encoding[11:7];
Execution
VectorState old_state = vector_state();
XReg new_vtype = vtypei;
if ((new_vtype[xlen() - 1] == 1'b1) || new_vtype & 8'd0) != 0) || (new_vtype[5] == 1) || (new_vtype[2:0] == 3'b100 {
CSR[vtype].VILL = 1;
CSR[vtype].VMA = 0;
CSR[vtype].VTA = 0;
CSR[vtype].VSEW = 0;
CSR[vtype].VLMUL = 0;
CSR[vl].VALUE = 0;
} else {
CSR[vtype].VILL = 0;
CSR[vtype].VMA = new_vtype[7];
CSR[vtype].VTA = new_vtype[6];
CSR[vtype].VSEW = new_vtype[5:3];
CSR[vtype].VLMUL = new_vtype[2:0];
VectorState state = vector_state();
XReg vlen = VLEN;
XReg vlmax = (vlen << state.log2_lmul) >> state.log2_sew;
XReg avl = X[xs1];
XReg ceil_avl_over_two = (avl + 1) / 2;
if (xs1 == 0 && xd != 0) {
CSR[vl].VALUE = vlmax;
} else if (xs1 == 0) {
XReg old_ratio = old_state.log2_sew - old_state.log2_lmul;
XReg new_ratio = state.log2_sew - state.log2_lmul;
if (new_ratio != old_ratio) {
CSR[vtype].VILL = 1;
CSR[vtype].VMA = 0;
CSR[vtype].VTA = 0;
CSR[vtype].VSEW = 0;
CSR[vtype].VLMUL = 0;
CSR[vl].VALUE = 0;
}
} else if (avl <= vlmax) {
CSR[vl].VALUE = avl;
} else if (avl < 2 * vlmax) {
if (RVV_VL_WHEN_AVL_LT_DOUBLE_VLMAX == "ceil(AVL/2)") {
CSR[vl].VALUE = ceil_avl_over_two;
} else if (RVV_VL_WHEN_AVL_LT_DOUBLE_VLMAX == "VLMAX") {
CSR[vl].VALUE = vlmax;
} else {
unpredictable("Implementations may choose a custom value for vl in the case AVL < (2*VLMAX), so long as ceil(AVL/2) <= vl <= VLMAX");
}
} else {
CSR[vl].VALUE = vlmax;
}
}
X[xd] = CSR[vl].VALUE;
CSR[vstart].VALUE = 0;