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

Fix Store-Conditional assembly operand order and add parens #345

Merged
merged 1 commit into from
Nov 29, 2023

Conversation

ThinkOpenly
Copy link
Contributor

The operand order for Store-Conditional assembly has the second and third operands reversed.

The RISC-V Instruction Set Manual states:

SC.W conditionally writes a word in rs2 to the address in rs1 [...]
If the SC.W succeeds, the instruction writes the word in rs2 to memory,
and it writes zero to rd. If the SC.W fails, the instruction does not
write to memory, and it writes a nonzero value to rd.

rd is for the return code, rs2 is the value, and rs1 is the memory address.

For the syntax sc.w A,B,(C):

  • A is where the result is stored, per convention. So, this is rd.
  • B is the value to be stored. So, this is rs2.
  • C is the address at which to store the value. So, this is rs1.

The resulting syntax would be stc.w rd,rs2,(rs1).

The current assembly representation is:

"sc." ^ size_mnemonic(size) [...] reg_name(rd) ^ sep() ^ reg_name(rs1) ^ sep() ^ reg_name(rs2)

Note that the order is wrong. In addition, parentheses are missing around rs2.

Fix this instance, as well as two other instances where parentheses are missing.

Fixes #338.
Fixes #344.

Suggested-by: Tim Hutt timothy.hutt@codasip.com

Copy link

github-actions bot commented Nov 14, 2023

Unit Test Results

712 tests  ±0   712 ✔️ ±0   0s ⏱️ ±0s
    6 suites ±0       0 💤 ±0 
    1 files   ±0       0 ±0 

Results for commit 61cfbf6. ± Comparison against base commit 9f4cad6.

♻️ This comment has been updated with latest results.

The operand order for Store-Conditional assembly has the second
and third operands reversed.

The RISC-V Instruction Set Manual states:
> ```
> SC.W conditionally writes a word in rs2 to the address in rs1 [...]
> If the SC.W succeeds, the instruction writes the word in rs2 to memory,
> and it writes zero to rd. If the SC.W fails, the instruction does not
> write to memory, and it writes a nonzero value to rd.
> ```

`rd` is for the return code, `rs2` is the value, and `rs1` is the memory
address.

For the syntax `sc.w A,B,(C)`:
- `A` is where the result is stored, per convention. So, this is `rd`.
- `B` is the value to be stored. So, this is `rs2`.
- `C` is the address at which to store the value. So, this is `rs1`.

The resulting syntax would be `stc.w rd,rs2,(rs1)`.

The current assembly representation is:
```
"sc." ^ size_mnemonic(size) [...] reg_name(rd) ^ sep() ^ reg_name(rs1) ^ sep() ^ reg_name(rs2)
```

Note that the order is wrong. In addition, parentheses are missing around `rs2`.

Fix this instance, as well as two other instances where parentheses are missing.

Fixes riscv#338.
Fixes riscv#344.

Suggested-by: Tim Hutt <timothy.hutt@codasip.com>
@Timmmm
Copy link
Collaborator

Timmmm commented Nov 14, 2023

LGTM

Copy link
Collaborator

@arichardson arichardson left a comment

Choose a reason for hiding this comment

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

LGTM

@billmcspadden-riscv billmcspadden-riscv merged commit b414bae into riscv:master Nov 29, 2023
2 checks passed
@ThinkOpenly ThinkOpenly deleted the parens branch August 6, 2024 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants