riscv / sail-riscv

Sail RISC-V model
https://lists.riscv.org/g/tech-golden-model
Other
433 stars 159 forks source link

Suspicious code in init_masked_result #567

Closed Timmmm closed 3 hours ago

Timmmm commented 3 hours ago

init_masked_result is called 3 times always like this:

  let (initial_result, mask) = init_masked_result(num_elem, SEW, LMUL_pow, vd_val, vec_trues);

In each case the last parameter is a vector of all true values. In the function it becomes vm_val

function init_masked_result(num_elem, SEW, LMUL_pow, vd_val, vm_val) = {

which is only accessed here:

    } else if not(vm_val[i]) then {
      /* Inactive body elements defined by vm */
      result[i] = match mask_ag {
        UNDISTURBED => vd_val[i],
        AGNOSTIC    => vd_val[i] /* TODO: configuration support */
      };
      mask[i] = false
    } else {

This code can never be executed. It's possible the implementation is still correct. We should confirm this and then remove the parameter.

Timmmm commented 3 hours ago

Actually, scratch that; it is called in more places than the 3 I was looking at.