Skip to content

Commit

Permalink
Make calculate new vl configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Yui5427 committed Oct 29, 2024
1 parent 9d86f01 commit 424c23d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
5 changes: 5 additions & 0 deletions c_emulator/riscv_platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ mach_bits sys_writable_hpm_counters(unit u)
return rv_writable_hpm_counters;
}

bool sys_vext_vl_use_ceil(unit u)
{
return rv_vext_vl_use_ceil;
}

bool plat_enable_dirty_update(unit u)
{
return rv_enable_dirty_update;
Expand Down
1 change: 1 addition & 0 deletions c_emulator/riscv_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ bool sys_enable_zicboz(unit);
uint64_t sys_pmp_count(unit);
uint64_t sys_pmp_grain(unit);

bool sys_vext_vl_use_ceil(unit);
uint64_t sys_vector_vlen_exp(unit);
uint64_t sys_vector_elen_exp(unit);

Expand Down
2 changes: 2 additions & 0 deletions c_emulator/riscv_platform_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ uint64_t rv_ram_size = UINT64_C(0x4000000);
uint64_t rv_rom_base = UINT64_C(0x1000);
uint64_t rv_rom_size = UINT64_C(0x100);

bool rv_vext_vl_use_ceil = false;

// Default 64, which is mandated by RVA22.
uint64_t rv_cache_block_size_exp = UINT64_C(6);

Expand Down
2 changes: 2 additions & 0 deletions c_emulator/riscv_platform_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ extern uint64_t rv_rom_size;

extern uint64_t rv_cache_block_size_exp;

extern bool rv_vext_vl_use_ceil;

// Provides entropy for the scalar cryptography extension.
extern uint64_t rv_16_random_bits(void);

Expand Down
16 changes: 10 additions & 6 deletions model/riscv_insts_vext_vset.sail
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,18 @@ function handle_illegal_vtype() = {
print_reg("CSR vl <- " ^ BitStr(vl))
}

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

val calculate_new_vl : (int, int) -> xlenbits
function calculate_new_vl(AVL, VLMAX) = {
/* Note: ceil(AVL / 2) ≤ vl ≤ VLMAX when VLMAX < AVL < (2 * VLMAX)
* TODO: configuration support for either using ceil(AVL / 2) or VLMAX
*/
if AVL <= VLMAX then to_bits(xlen, AVL)
else if AVL < 2 * VLMAX then to_bits(xlen, (AVL + 1) / 2)
else to_bits(xlen, VLMAX)
if(sys_vext_vl_use_ceil()) then {
if AVL <= VLMAX then to_bits(xlen, AVL)
else if AVL < 2 * VLMAX then to_bits(xlen, (AVL + 1) / 2)
else to_bits(xlen, VLMAX)
} else {
if AVL <= VLMAX then to_bits(xlen, AVL)
else to_bits(xlen, VLMAX)
}
}

/* *********************************** vsetvli *********************************** */
Expand Down

0 comments on commit 424c23d

Please sign in to comment.