Skip to content

Conversation

folkertdev
Copy link
Contributor

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.

@rustbot
Copy link
Collaborator

rustbot commented Jul 5, 2025

r? @lcnr

rustbot has assigned @lcnr.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added 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-review Status: Awaiting review from the assignee but also interested parties. 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. labels Jul 5, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 5, 2025

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

cc @RalfJung, @oli-obk, @lcnr

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

@joshtriplett
Copy link
Member

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Jul 6, 2025

📌 Commit ed3711e has been approved by joshtriplett

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 6, 2025
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
@bors bors merged commit 6fb00b1 into rust-lang:master Jul 6, 2025
11 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jul 6, 2025
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.
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request Jul 11, 2025
…oshtriplett

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants