riscv / sail-riscv

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

Make calculate new vl configurable #608

Open rez5427 opened 3 weeks ago

rez5427 commented 3 weeks ago

I don't know whether sail-riscv needs this. The spike uses VLMAX to calculate new vl, and sail-riscv uses (AVL + 1) / 2.

The spec says:

The number of bits implemented in vl depends on the implementation’s maximum vector length of the smallest supported type. The smallest vector implementation with VLEN=32 and supporting SEW=8 would need at least six bits in vl to hold the values 0-32 (VLEN=32, with LMUL=8 and SEW=8, yields VLMAX=32).

github-actions[bot] commented 3 weeks ago

Test Results

396 tests  ±0   396 ✅ ±0   0s ⏱️ ±0s   4 suites ±0     0 💤 ±0    1 files   ±0     0 ❌ ±0 

Results for commit 01ff2b9f. ± Comparison against base commit 9d86f015.

:recycle: This comment has been updated with latest results.

Timmmm commented 3 days ago

LGTM but I would add some explanation and move the if to the place where it is actually used. Also move the to_bits outside the body to make it clearer.

val sys_vext_vl_use_ceil = pure "sys_vext_vl_use_ceil" : unit -> bool

function calculate_new_vl(AVL : int, VLMAX : int) -> xlenbits = {
  // See "Constraints on Setting vl" in the vector spec.
  let vl =
    if AVL <= VLMAX then AVL
    else if AVL < 2 * VLMAX then {
      // If VLMAX < AVL < 2 * VLMAX then we can use any value
      // such that ceil(AVL / 2) <= vl <= VLMAX. Here we provide
      // two options: ceil(AVL / 2) or VLMAX.
      if sys_vext_vl_use_ceil() then (AVL + 1) / 2 else VLMAX
    }
    else VLMAX;

  to_bits(xlen, vl)
}

(Feel free to copy/paste.)