Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make calculate new vl configurable #608

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading