Skip to content

Commit 7914a68

Browse files
committed
make sure vstart is zero when instruction early return
1 parent 296f8cd commit 7914a68

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

model/riscv_insts_vext_fp_red.sail

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@ function process_rfvv_single(funct6, vm, vs2, vs1, vd, num_elem_vs, SEW, LMUL_po
3232
let rm_3b = fcsr[FRM];
3333
let num_elem_vd = get_num_elem(0, SEW); /* vd regardless of LMUL setting */
3434

35-
if illegal_fp_reduction(SEW, rm_3b) then return Illegal_Instruction();
35+
if illegal_fp_reduction(SEW, rm_3b) then {
36+
return Illegal_Instruction();
37+
};
3638
assert(SEW != 8);
3739

38-
if unsigned(vl) == 0 then return RETIRE_SUCCESS; /* if vl=0, no operation is performed */
40+
if unsigned(vl) == 0 then {
41+
return RETIRE_SUCCESS; /* if vl=0, no operation is performed */
42+
};
3943

4044
let 'n = num_elem_vs;
4145
let 'd = num_elem_vd;
@@ -66,7 +70,7 @@ function process_rfvv_single(funct6, vm, vs2, vs1, vd, num_elem_vs, SEW, LMUL_po
6670
write_single_element(SEW, 0, vd, sum);
6771
/* other elements in vd are treated as tail elements, currently remain unchanged */
6872
/* TODO: configuration support for agnostic behavior */
69-
set_vstart(zeros());
73+
// illegal_fp_reduction checks vstart == 0, and raises illegal-instruction otherwise.
7074
RETIRE_SUCCESS
7175
}
7276

@@ -75,12 +79,16 @@ function process_rfvv_widening_reduction(funct6, vm, vs2, vs1, vd, num_elem_vs,
7579
let rm_3b = fcsr[FRM];
7680
let SEW_widen = SEW * 2;
7781

78-
if illegal_fp_widening_reduction(SEW, rm_3b, SEW_widen) then return Illegal_Instruction();
82+
if illegal_fp_widening_reduction(SEW, rm_3b, SEW_widen) then {
83+
return Illegal_Instruction();
84+
};
7985
assert(SEW >= 16 & SEW_widen <= 64);
8086

8187
let num_elem_vd = get_num_elem(0, SEW_widen); /* vd regardless of LMUL setting */
8288

83-
if unsigned(vl) == 0 then return RETIRE_SUCCESS; /* if vl=0, no operation is performed */
89+
if unsigned(vl) == 0 then {
90+
return RETIRE_SUCCESS; /* if vl=0, no operation is performed */
91+
};
8492

8593
let 'n = num_elem_vs;
8694
let 'd = num_elem_vd;
@@ -106,7 +114,7 @@ function process_rfvv_widening_reduction(funct6, vm, vs2, vs1, vd, num_elem_vs,
106114
write_single_element(SEW_widen, 0, vd, sum);
107115
/* other elements in vd are treated as tail elements, currently remain unchanged */
108116
/* TODO: configuration support for agnostic behavior */
109-
set_vstart(zeros());
117+
// illegal_fp_widening_reduction checks vstart == 0, and raises illegal-instruction otherwise.
110118
RETIRE_SUCCESS
111119
}
112120

model/riscv_insts_vext_red.sail

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,18 @@ function clause execute(RIVVTYPE(funct6, vm, vs2, vs1, vd)) = {
2828
let LMUL_pow = get_lmul_pow();
2929
let SEW_widen = SEW * 2;
3030

31-
if illegal_widening_reduction(SEW_widen) then return Illegal_Instruction();
31+
if illegal_widening_reduction(SEW_widen) then {
32+
return Illegal_Instruction();
33+
};
3234

3335
assert(SEW_widen <= 64);
3436

3537
let num_elem_vs = get_num_elem(LMUL_pow, SEW);
3638
let num_elem_vd = get_num_elem(0, SEW_widen); /* vd regardless of LMUL setting */
3739

38-
if unsigned(vl) == 0 then return RETIRE_SUCCESS; /* if vl=0, no operation is performed */
40+
if unsigned(vl) == 0 then {
41+
return RETIRE_SUCCESS; /* if vl=0, no operation is performed */
42+
};
3943

4044
let 'n = num_elem_vs;
4145
let 'd = num_elem_vd;
@@ -64,7 +68,7 @@ function clause execute(RIVVTYPE(funct6, vm, vs2, vs1, vd)) = {
6468
write_single_element(SEW_widen, 0, vd, sum);
6569
/* other elements in vd are treated as tail elements, currently remain unchanged */
6670
/* TODO: configuration support for agnostic behavior */
67-
set_vstart(zeros());
71+
// illegal_widening_reduction checks vstart == 0, and raises illegal-instruction otherwise.
6872
RETIRE_SUCCESS
6973
}
7074

@@ -100,9 +104,13 @@ function clause execute(RMVVTYPE(funct6, vm, vs2, vs1, vd)) = {
100104
let num_elem_vs = get_num_elem(LMUL_pow, SEW);
101105
let num_elem_vd = get_num_elem(0, SEW); /* vd regardless of LMUL setting */
102106

103-
if illegal_reduction() then return Illegal_Instruction();
107+
if illegal_reduction() then {
108+
return Illegal_Instruction();
109+
};
104110

105-
if unsigned(vl) == 0 then return RETIRE_SUCCESS; /* if vl=0, no operation is performed */
111+
if unsigned(vl) == 0 then {
112+
return RETIRE_SUCCESS; /* if vl=0, no operation is performed */
113+
};
106114

107115
let 'n = num_elem_vs;
108116
let 'd = num_elem_vd;
@@ -135,7 +143,7 @@ function clause execute(RMVVTYPE(funct6, vm, vs2, vs1, vd)) = {
135143
write_single_element(SEW, 0, vd, sum);
136144
/* other elements in vd are treated as tail elements, currently remain unchanged */
137145
/* TODO: configuration support for agnostic behavior */
138-
set_vstart(zeros());
146+
// illegal_reduction checks vstart == 0, and raises illegal-instruction otherwise.
139147
RETIRE_SUCCESS
140148
}
141149

model/riscv_insts_vext_vm.sail

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function clause execute(VVMTYPE(funct6, vs2, vs1, vd)) = {
4343

4444
let (initial_result, mask) : (bits('n), bits('n)) = match init_masked_result_carry(num_elem, SEW, LMUL_pow, vd_val) {
4545
Ok(v) => v,
46-
Err(()) => return Illegal_Instruction()
46+
Err(()) => return Illegal_Instruction(),
4747
};
4848
var result = initial_result;
4949

0 commit comments

Comments
 (0)