Skip to content

Commit

Permalink
Fix sign extension of byte offsets in vector extension
Browse files Browse the repository at this point in the history
According to the spec these byte offsets should be zero-extended, not sign-extended.

> If the vector offset elements are narrower than XLEN, they are zero-extended to XLEN before adding to the base effective address.

Co-authored-by: Yui5427 <[email protected]>
  • Loading branch information
rez5427 and Yui5427 authored Oct 8, 2024
1 parent b90ec78 commit ee17279
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions model/riscv_insts_vext_mem.sail
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ function process_vlsseg (nf, vm, vd, load_width_bytes, rs1, rs2, EMUL_pow, num_e
let width_type : word_width = size_bytes(load_width_bytes);
let vm_val : vector('n, bool) = read_vmask(num_elem, vm, 0b00000);
let vd_seg : vector('n, bits('f * 'b * 8)) = read_vreg_seg(num_elem, load_width_bytes * 8, EMUL_pow, nf, vd);
let rs2_val : int = signed(get_scalar(rs2, xlen));
let rs2_val : int = unsigned(get_scalar(rs2, xlen));

let (result, mask) = init_masked_result(num_elem, nf * load_width_bytes * 8, EMUL_pow, vd_seg, vm_val);

Expand Down Expand Up @@ -380,7 +380,7 @@ function process_vssseg (nf, vm, vs3, load_width_bytes, rs1, rs2, EMUL_pow, num_
let width_type : word_width = size_bytes(load_width_bytes);
let vm_val : vector('n, bool) = read_vmask(num_elem, vm, 0b00000);
let vs3_seg : vector('n, bits('f * 'b * 8)) = read_vreg_seg(num_elem, load_width_bytes * 8, EMUL_pow, nf, vs3);
let rs2_val : int = signed(get_scalar(rs2, xlen));
let rs2_val : int = unsigned(get_scalar(rs2, xlen));
let mask : vector('n, bool) = init_masked_source(num_elem, EMUL_pow, vm_val);

foreach (i from 0 to (num_elem - 1)) {
Expand Down Expand Up @@ -459,7 +459,7 @@ function process_vlxseg (nf, vm, vd, EEW_index_bytes, EEW_data_bytes, EMUL_index
if mask[i] then { /* active segments */
vstart = to_bits(16, i);
foreach (j from 0 to (nf - 1)) {
let elem_offset : int = signed(vs2_val[i]) + j * EEW_data_bytes;
let elem_offset : int = unsigned(vs2_val[i]) + j * EEW_data_bytes;
match ext_data_get_addr(rs1, to_bits(xlen, elem_offset), Read(Data), EEW_data_bytes) {
Ext_DataAddr_Error(e) => { ext_handle_data_check_error(e); return RETIRE_FAIL },
Ext_DataAddr_OK(vaddr) =>
Expand Down Expand Up @@ -550,7 +550,7 @@ function process_vsxseg (nf, vm, vs3, EEW_index_bytes, EEW_data_bytes, EMUL_inde
if mask[i] then { /* active segments */
vstart = to_bits(16, i);
foreach (j from 0 to (nf - 1)) {
let elem_offset : int = signed(vs2_val[i]) + j * EEW_data_bytes;
let elem_offset : int = unsigned(vs2_val[i]) + j * EEW_data_bytes;
match ext_data_get_addr(rs1, to_bits(xlen, elem_offset), Write(Data), EEW_data_bytes) {
Ext_DataAddr_Error(e) => { ext_handle_data_check_error(e); return RETIRE_FAIL },
Ext_DataAddr_OK(vaddr) =>
Expand Down

0 comments on commit ee17279

Please sign in to comment.