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

Refactor vstart assignments to use set_vstart function #688

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

rez5427
Copy link
Contributor

@rez5427 rez5427 commented Jan 14, 2025

Refactor vstart assignments to use set_vstart function
@rez5427 rez5427 force-pushed the add_set_vcsr_vxsat branch from 15dfbd1 to 8a488c5 Compare January 14, 2025 15:29
Copy link

github-actions bot commented Jan 14, 2025

Test Results

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

Results for commit 141b009. ± Comparison against base commit 70edcb0.

♻️ This comment has been updated with latest results.

Copy link
Collaborator

@Timmmm Timmmm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work. I think there are a couple of things to change though:

  1. set_vstart() needs to call dirty_v_context().
  2. function clause write_CSR(0x008, value) should use set_vstart().
  3. I'm not sure about this but the CSR writing function truncates the written value to get_vlen_pow() bits. That isn't done by the places that call set_vstart(to_bits(16...). Should it? Or do we know that that truncation would never make a difference?

@rez5427
Copy link
Contributor Author

rez5427 commented Jan 21, 2025

Is this okay? @Timmmm, it seems like the length of vstart depends on vlen. I checked Spike, and it uses typedef uint64_t reg_t; to define vstart and writes vstart using a mask of vlen - 1. Maybe setting a dynamic length for vstart based on vlen would be better?

@Timmmm
Copy link
Collaborator

Timmmm commented Jan 21, 2025

I don't think this is quite right either (but it is closer). I took the drastic action of actually reading the spec. These are the relevant bits:

The vstart CSR is defined to have only enough writable bits to hold the largest element index (one less than the maximum VLMAX).

The maximum vector length is obtained with the largest LMUL setting (8) and the smallest SEW setting (8), so VLMAX_max = 8*VLEN/8 = VLEN. For example, for VLEN=256, vstart would have 8 bits to represent indices from 0 through 255.

The use of vstart values greater than the largest element index for the current vtype setting is reserved.

It is recommended that implementations trap if vstart is out of bounds. It is not required to trap, as a possible future use of upper vstart bits is to store imprecise trap information.

Implementations are permitted to raise illegal instruction exceptions when attempting to execute a vector instruction with a value of vstart that the implementation can never produce when executing that same instruction with the same vtype setting.

Also:

The upper limit on VLEN allows software to know that indices will fit into 16 bits (largest VLMAX of 65,536 occurs for LMUL=8 and SEW=8 with VLEN=65,536).

So I think that's why the old code does tobits(16, ...) and vstart is a 16-bit register.

It does not look like the existing implementation traps when vstart is out of bounds; presumably because the current Sail CSR functions do not support trapping based on the value. Probably best to leave that for now. Maybe add a note.

So I think you want to change the xlen back to bits(16), and then take the lowest 16 bits of the write value for the CSR write clause.

rez5427 and others added 3 commits January 22, 2025 10:04
Co-authored-by: Tim Hutt <tdhutt@gmail.com>
Signed-off-by: guan jian <148229859+rez5427@users.noreply.github.com>
@rez5427
Copy link
Contributor Author

rez5427 commented Jan 23, 2025

Is this okay? @Timmmm

@Timmmm
Copy link
Collaborator

Timmmm commented Jan 24, 2025

Apart from that minor comment suggestion this LGTM. I'm still not 100% convinced by the original tobits(16, .. - it could probably do with fancier types so we can guarantee it doesn't truncate. But anyway this PR doesn't change that so it's fine.

Co-authored-by: Tim Hutt <tdhutt@gmail.com>
Signed-off-by: guan jian <148229859+rez5427@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants