Skip to content

[RV64_DYNAREC] Reduce instruction count for 64-bit addition carry flag - #4079

Merged
ptitSeb merged 1 commit into
ptitSeb:mainfrom
zengdage:carry
Jul 21, 2026
Merged

[RV64_DYNAREC] Reduce instruction count for 64-bit addition carry flag#4079
ptitSeb merged 1 commit into
ptitSeb:mainfrom
zengdage:carry

Conversation

@zengdage

@zengdage zengdage commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

For the risc-v instruction add rd, rs1, rs2, if an overflow occurs, only the lower XLEN bits of the sum are retained, and the resulting value will be numerically smaller than both rs1 and rs2.

The combination of risc-v add and sltu instructions is commonly used to compute the carry flag of a 64-bit addition.

@ksco ksco left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Interesting, thanks!

@ksco ksco left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You can move SET_FLAGS_NEZ(s5, F_CF, s4); to the else block and use OR(xFlags, xFlags, s5); in the if block to save 1 more instuction.

@zengdage

Copy link
Copy Markdown
Contributor Author

You can move SET_FLAGS_NEZ(s5, F_CF, s4); to the else block and use OR(xFlags, xFlags, s5); in the if block to save 1 more instuction.

Done.

@ksco

ksco commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

The code is pretty obvious, so I think it's better to just remove those comments.

…lag calculation

Because CF flag reside in bit 0 of risc-v xFlags (x23), so we also can remove
BEQZ inst for if block.
@ptitSeb
ptitSeb merged commit c8a5246 into ptitSeb:main Jul 21, 2026
28 checks passed
ptitSeb pushed a commit that referenced this pull request Jul 21, 2026
@zengdage
zengdage deleted the carry branch July 21, 2026 10:16
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