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

'amomax.w' Instruction Fails to Store Maximum Value #181

Open
youzi27 opened this issue Mar 7, 2024 · 0 comments
Open

'amomax.w' Instruction Fails to Store Maximum Value #181

youzi27 opened this issue Mar 7, 2024 · 0 comments

Comments

@youzi27
Copy link

youzi27 commented Mar 7, 2024

Describe the Bug:
In the NutShell RISC-V implementation, the amomax.w instruction does not correctly update memory with the maximum value as specified in the RISC-V unprivileged ISA specification. Specifically, when executing amomax.w a1, a5, (a3) with the value at the address contained in a3 (a positive number) being greater than the value in a5 (a negative number), the expected behavior is to leave the memory at (a3) unchanged since the value at (a3) is already the maximum. Instead, NutShell erroneously updates the memory at (a3) with the value of a5 (the negative number), suggesting a possible incorrect implementation of signed comparison in amomax.w. This behavior is observed by executing ld a4, 0(a3) afterwards, where a4 ends up containing the smaller (negative) value, indicating that amomax.w stored a5's value instead of maintaining a3's. This issue contrasts with the expected behavior and the correct handling by Spike simulator.

To Reproduce:

  1. Prepare a scenario where the memory at (a3) contains a positive value, and a5 contains a negative value.
  2. Execute amomax.w a1, a5, (a3).
  3. Follow with ld a4, 0(a3) to check the value at (a3).
  4. Observe that a4 contains the negative value from a5, indicating that the memory at (a3) was incorrectly updated.

Expected Behavior:
According to the RISC-V unprivileged ISA specification, amomax.w should atomically load the value from the address contained in rs1, compare it with the value in rs2, and write the maximum of the two values back to the memory address in rs1. In the given scenario, since the memory at (a3) contains a greater value than a5, the memory content should remain unchanged, reflecting the correct maximum value determination. Subsequent checks, such as ld a4, 0(a3), should reveal that a4 retains the original, larger (positive) value from (a3), ensuring adherence to the specification​​.

Screenshots
image

Additional context
None

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

No branches or pull requests

1 participant