Missing carry-optimization for subtraction on aarch64
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.2k
- PR merge metrics
- PR metrics pending
Description
The compiler fails to optimize "sub-with-borrow" on aarch64 as demonstrated here:
https://godbolt.org/z/5MPxbfzsM
In more detail:
When adding big-integers, we would like the compiler to utilize "add-with-carry" instructions. Similarly for subtraction, we would like to utilize "sub-with-borrow". This works fine on x86_64 for both addition and subtraction, but on aarch64, only addition will utilize the carry-instructions. Subtraction on aarch64 fails to optimize and will use "cset" and "ccmp" instructions, where-as in the above link, the optimal assembly should be along "subs, sbcs, sbcs, sbcs".
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Godbolt reproduction linked in the issue and compare the AArch64 subtraction output with the expected subs/sbcs sequence and the working x86_64 behavior. Trace the Rust compiler's AArch64 lowering for subtraction with borrow; done when the generated code uses the carry instructions instead of cset and ccmp for the demonstrated case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100