-
Notifications
You must be signed in to change notification settings - Fork 13.5k
use is_multiple_of
and div_ceil
#143477
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
Merged
Merged
use is_multiple_of
and div_ceil
#143477
+33
−34
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Portable SIMD is developed in its own repository. If possible, consider making this change to rust-lang/portable-simd instead. cc @calebzulawski, @programmerjake Some changes occurred to the CTFE machinery Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri |
hanna-kruppe
reviewed
Jul 5, 2025
0649318
to
ed3711e
Compare
@bors r+ rollup |
bors
added a commit
that referenced
this pull request
Jul 6, 2025
Rollup of 6 pull requests Successful merges: - #143416 (mbe: Defer checks for `compile_error!` until reporting an unused macro rule) - #143470 (std: sys: net: uefi: tcp4: Implement read) - #143477 (use `is_multiple_of` and `div_ceil`) - #143484 (distinguish the duplicate item of rpitit) - #143493 (tidy: use --bless for tidy spellcheck instead of spellcheck:fix) - #143504 (compiletest: print slightly more information on fs::write failure) r? `@ghost` `@rustbot` modify labels: rollup
rust-timer
added a commit
that referenced
this pull request
Jul 6, 2025
Rollup merge of #143477 - folkertdev:use-is-multiple-of, r=joshtriplett use `is_multiple_of` and `div_ceil` In tricky logic, these functions are much more informative than the manual implementations. They also catch subtle bugs: - the manual `is_multiple_of` often does not handle division by zero - manual `div_ceil` often does not consider overflow The transformation is free for `is_multiple_of` if the divisor is compile-time known to be non-zero. For `div_ceil` there is a small cost to considering overflow. Here is some assembly https://godbolt.org/z/5zP8KaE1d.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-LLVM
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
A-query-system
Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html)
S-waiting-on-bors
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In tricky logic, these functions are much more informative than the manual implementations. They also catch subtle bugs:
is_multiple_of
often does not handle division by zerodiv_ceil
often does not consider overflowThe transformation is free for
is_multiple_of
if the divisor is compile-time known to be non-zero. Fordiv_ceil
there is a small cost to considering overflow. Here is some assembly https://godbolt.org/z/5zP8KaE1d.