-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Tracking Issue for int_roundings
#88581
Comments
Implement rust-lang#88581 See rust-lang#88581 for details. This API was discussed on Zulip. `@rustbot` label: +T-libs-api +S-waiting-on-review r? `@joshtriplett`
Rollup of 12 pull requests Successful merges: - rust-lang#88177 (Stabilize std::os::unix::fs::chroot) - rust-lang#88505 (Use `unwrap_unchecked` where possible) - rust-lang#88512 (Upgrade array_into_iter lint to include Deref-to-array types.) - rust-lang#88532 (Remove single use variables) - rust-lang#88543 (Improve closure dummy capture suggestion in macros.) - rust-lang#88560 (`fmt::Formatter::pad`: don't call chars().count() more than one time) - rust-lang#88565 (Add regression test for issue 83190) - rust-lang#88567 (Remove redundant `Span` in `QueryJobInfo`) - rust-lang#88573 (rustdoc: Don't panic on ambiguous inherent associated types) - rust-lang#88582 (Implement rust-lang#88581) - rust-lang#88589 (Correct doc comments inside `use_expr_visitor.rs`) - rust-lang#88592 (Fix ICE in const check) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Just updated to the latest nightly, looks like this feature breaks the num-bigint crate. error[E0658]: use of unstable library feature 'int_roundings'
|
That is considered acceptable breakage. Per RFC 1105, adding an inherent impl is a minor change. |
219: rust: use explicitily Integer::div_ceil r=cuviper a=catenacyber Fixes #218 cf rust-lang/rust#88581 Co-authored-by: Philippe Antoine <[email protected]> Co-authored-by: Josh Stone <[email protected]>
219: rust: use explicitily Integer::div_ceil r=cuviper a=catenacyber Fixes #218 cf rust-lang/rust#88581 Co-authored-by: Philippe Antoine <[email protected]> Co-authored-by: Josh Stone <[email protected]>
cf rust-lang/rust#88581 (cherry picked from commit a8fc78c)
Though technically not a breaking change, I wonder if it's worth delaying it landing in stable for a bit? "Everything that uses num-bigint" feels kinda large. I guess we'll see the scope of the breakage on a release-based crater run. |
`cargo check` on nightly was erroring due to num-bigint: ```text error[E0658]: use of unstable library feature 'int_roundings' --> [...]/.cargo/registry/src/github.com-1ecc6299db9ec823/num-bigint-0.3.1/src/biguint.rs:208:10 | 208 | .div_ceil(&big_digit::BITS.into()) | ^^^^^^^^ | = note: see issue #88581 <rust-lang/rust#88581> for more information = help: add `#![feature(int_roundings)]` to the crate attributes to enable ```
`cargo check` on nightly was erroring due to num-bigint: ```text error[E0658]: use of unstable library feature 'int_roundings' --> [...]/.cargo/registry/src/github.com-1ecc6299db9ec823/num-bigint-0.3.1/src/biguint.rs:208:10 | 208 | .div_ceil(&big_digit::BITS.into()) | ^^^^^^^^ | = note: see issue #88581 <rust-lang/rust#88581> for more information = help: add `#![feature(int_roundings)]` to the crate attributes to enable ```
* Update num-bigint to 0.3.3 `cargo check` on nightly was erroring due to num-bigint: ```text error[E0658]: use of unstable library feature 'int_roundings' --> [...]/.cargo/registry/src/github.com-1ecc6299db9ec823/num-bigint-0.3.1/src/biguint.rs:208:10 | 208 | .div_ceil(&big_digit::BITS.into()) | ^^^^^^^^ | = note: see issue #88581 <rust-lang/rust#88581> for more information = help: add `#![feature(int_roundings)]` to the crate attributes to enable ``` * pr: update enum-ordinalize and educe
|
Before stabilizing these functions let's see if enough people use them often enough (otherwise it's wiser to remove them). |
There's a well-established use for them via the |
rust-lang/rust#88581 adds several new integer methods as inherent impls. These new methods are a breaking change accepted as a minor change. They already cause build failures with nightly and will eventually cause build failures with stable as well, unless rust-lang changes course. This uses `Integer::div_floor` explicitly to avoid accidentally calling the new nightly methods, same as done for rust-num/num-bigint#218.
Now that FCP has completed, what is the actual API that was agreed upon? I can update the open PR (#94455), but I don't have the time to re-read this thread 😅 |
Unsigned only, and without div_floor. |
PR has been updated to that effect. |
…joshtriplett Partially stabilize `int_roundings` This stabilizes the following: ```rust impl uX { pub const fn div_ceil(self, rhs: Self) -> Self; pub const fn next_multiple_of(self, rhs: Self) -> Self; pub const fn checked_next_multiple_of(self, rhs: Self) -> Option<Self>; } ``` This feature is tracked in rust-lang#88581.
…joshtriplett Partially stabilize `int_roundings` This stabilizes the following: ```rust impl uX { pub const fn div_ceil(self, rhs: Self) -> Self; pub const fn next_multiple_of(self, rhs: Self) -> Self; pub const fn checked_next_multiple_of(self, rhs: Self) -> Option<Self>; } ``` This feature is tracked in rust-lang#88581.
Currently next_multiple_of() is behinged a Feature gate: int_rounding. See rust-lang/rust#88581 But it seems that this function is stablized in rust 1.73. See rust-lang/rust#94455 Currently Embassy is still using nightly for many other unstable features. So I do see an issue to use this function.
Currently next_multiple_of() is behinged a Feature gate: int_rounding. See rust-lang/rust#88581 But it seems that this function is stablized in rust 1.73. See rust-lang/rust#94455 Currently Embassy is still using nightly for many other unstable features. So I do see an issue to use this function.
I'm just stumbling on this feature right now and I can see that there's a tag that says FCP is completed (and conversation indicates that), so can we tick that one to-do item that's in the original comment? Just a nit-pick. |
That FCP was for a partial stabilization. |
I do not like that Then I propose that Note that this would mean nothing would change for |
Are there any plans to add a
Example application: I've been working on a stack allocator, and I would've liked to represent the size of a stack as a I think any (I'm sorry in advance if this is not the proper place to discuss this issue. It could also be part of the |
docs: correct panic conditions for rem_euclid and similar functions fixes rust-lang#128857 also fixes the documentation for functions behind the `int_roundings` feature (rust-lang#88581)
Rollup merge of rust-lang#129480 - lolbinarycat:euclid-docs, r=joboet docs: correct panic conditions for rem_euclid and similar functions fixes rust-lang#128857 also fixes the documentation for functions behind the `int_roundings` feature (rust-lang#88581)
better implementation of signed div_floor/ceil Tracking issue for signed `div_floor`/`div_ceil`: rust-lang#88581. This PR improves the implementation of those two functions by adding a better branchless algorithm. Side-by-side comparison of `i32::div_floor` on x86-64: ```asm div_floor_new: div_floor_old: push rax push rax test esi, esi test esi, esi je .LBB0_3 je .LBB1_6 mov eax, esi mov eax, esi not eax not eax lea ecx, [rdi - 2147483648] lea ecx, [rdi - 2147483648] or ecx, eax or ecx, eax je .LBB0_2 je .LBB1_7 mov eax, edi mov eax, edi cdq cdq idiv esi idiv esi xor esi, edi test edx, edx sar esi, 31 setg cl test edx, edx test esi, esi cmove esi, edx sets dil add eax, esi test dil, cl pop rcx jne .LBB1_4 ret test edx, edx .LBB0_3: setns cl lea rdi, [rip + .L__unnamed_1] test esi, esi call qword ptr [rip + panic...] setle dl .LBB0_2: or dl, cl lea rdi, [rip + .L__unnamed_1] jne .LBB1_5 call qword ptr [rip + panic...] .LBB1_4: dec eax .LBB1_5: pop rcx ret .LBB1_6: lea rdi, [rip + .L__unnamed_2] call qword ptr [rip + panic...] .LBB1_7: lea rdi, [rip + .L__unnamed_2] call qword ptr [rip + panic...] ``` And on Aarch64: ```asm _div_floor_new: _div_floor_old: stp x29, x30, [sp, #-16]! stp x29, x30, [sp, #-16]! mov x29, sp mov x29, sp cbz w1, LBB0_4 cbz w1, LBB1_9 mov w8, #-2147483648 mov x8, x0 cmp w0, w8 mov w9, #-2147483648 b.ne LBB0_3 cmp w0, w9 cmn w1, #1 b.ne LBB1_3 b.eq LBB0_5 cmn w1, #1 LBB0_3: b.eq LBB1_10 sdiv w8, w0, w1 LBB1_3: msub w9, w8, w1, w0 sdiv w0, w8, w1 eor w10, w1, w0 msub w8, w0, w1, w8 asr w10, w10, rust-lang#31 tbz w1, rust-lang#31, LBB1_5 cmp w9, #0 cmp w8, #0 csel w9, wzr, w10, eq b.gt LBB1_7 add w0, w9, w8 LBB1_5: ldp x29, x30, [sp], rust-lang#16 cmp w1, #1 ret b.lt LBB1_8 LBB0_4: tbz w8, rust-lang#31, LBB1_8 adrp x0, l___unnamed_1@PAGE LBB1_7: add x0, x0, l___unnamed_1@PAGEOFF sub w0, w0, #1 bl panic... LBB1_8: LBB0_5: ldp x29, x30, [sp], rust-lang#16 adrp x0, l___unnamed_1@PAGE ret add x0, x0, l___unnamed_1@PAGEOFF LBB1_9: bl panic... adrp x0, l___unnamed_2@PAGE add x0, x0, l___unnamed_2@PAGEOFF bl panic... LBB1_10: adrp x0, l___unnamed_2@PAGE add x0, x0, l___unnamed_2@PAGEOFF bl panic... ```
better implementation of signed div_floor/ceil Tracking issue for signed `div_floor`/`div_ceil`: rust-lang/rust#88581. This PR improves the implementation of those two functions by adding a better branchless algorithm. Side-by-side comparison of `i32::div_floor` on x86-64: ```asm div_floor_new: div_floor_old: push rax push rax test esi, esi test esi, esi je .LBB0_3 je .LBB1_6 mov eax, esi mov eax, esi not eax not eax lea ecx, [rdi - 2147483648] lea ecx, [rdi - 2147483648] or ecx, eax or ecx, eax je .LBB0_2 je .LBB1_7 mov eax, edi mov eax, edi cdq cdq idiv esi idiv esi xor esi, edi test edx, edx sar esi, 31 setg cl test edx, edx test esi, esi cmove esi, edx sets dil add eax, esi test dil, cl pop rcx jne .LBB1_4 ret test edx, edx .LBB0_3: setns cl lea rdi, [rip + .L__unnamed_1] test esi, esi call qword ptr [rip + panic...] setle dl .LBB0_2: or dl, cl lea rdi, [rip + .L__unnamed_1] jne .LBB1_5 call qword ptr [rip + panic...] .LBB1_4: dec eax .LBB1_5: pop rcx ret .LBB1_6: lea rdi, [rip + .L__unnamed_2] call qword ptr [rip + panic...] .LBB1_7: lea rdi, [rip + .L__unnamed_2] call qword ptr [rip + panic...] ``` And on Aarch64: ```asm _div_floor_new: _div_floor_old: stp x29, x30, [sp, #-16]! stp x29, x30, [sp, #-16]! mov x29, sp mov x29, sp cbz w1, LBB0_4 cbz w1, LBB1_9 mov w8, #-2147483648 mov x8, x0 cmp w0, w8 mov w9, #-2147483648 b.ne LBB0_3 cmp w0, w9 cmn w1, #1 b.ne LBB1_3 b.eq LBB0_5 cmn w1, #1 LBB0_3: b.eq LBB1_10 sdiv w8, w0, w1 LBB1_3: msub w9, w8, w1, w0 sdiv w0, w8, w1 eor w10, w1, w0 msub w8, w0, w1, w8 asr w10, w10, rust-lang#31 tbz w1, rust-lang#31, LBB1_5 cmp w9, #0 cmp w8, #0 csel w9, wzr, w10, eq b.gt LBB1_7 add w0, w9, w8 LBB1_5: ldp x29, x30, [sp], rust-lang#16 cmp w1, #1 ret b.lt LBB1_8 LBB0_4: tbz w8, rust-lang#31, LBB1_8 adrp x0, l___unnamed_1@PAGE LBB1_7: add x0, x0, l___unnamed_1@PAGEOFF sub w0, w0, #1 bl panic... LBB1_8: LBB0_5: ldp x29, x30, [sp], rust-lang#16 adrp x0, l___unnamed_1@PAGE ret add x0, x0, l___unnamed_1@PAGEOFF LBB1_9: bl panic... adrp x0, l___unnamed_2@PAGE add x0, x0, l___unnamed_2@PAGEOFF bl panic... LBB1_10: adrp x0, l___unnamed_2@PAGE add x0, x0, l___unnamed_2@PAGEOFF bl panic... ```
better implementation of signed div_floor/ceil Tracking issue for signed `div_floor`/`div_ceil`: rust-lang/rust#88581. This PR improves the implementation of those two functions by adding a better branchless algorithm. Side-by-side comparison of `i32::div_floor` on x86-64: ```asm div_floor_new: div_floor_old: push rax push rax test esi, esi test esi, esi je .LBB0_3 je .LBB1_6 mov eax, esi mov eax, esi not eax not eax lea ecx, [rdi - 2147483648] lea ecx, [rdi - 2147483648] or ecx, eax or ecx, eax je .LBB0_2 je .LBB1_7 mov eax, edi mov eax, edi cdq cdq idiv esi idiv esi xor esi, edi test edx, edx sar esi, 31 setg cl test edx, edx test esi, esi cmove esi, edx sets dil add eax, esi test dil, cl pop rcx jne .LBB1_4 ret test edx, edx .LBB0_3: setns cl lea rdi, [rip + .L__unnamed_1] test esi, esi call qword ptr [rip + panic...] setle dl .LBB0_2: or dl, cl lea rdi, [rip + .L__unnamed_1] jne .LBB1_5 call qword ptr [rip + panic...] .LBB1_4: dec eax .LBB1_5: pop rcx ret .LBB1_6: lea rdi, [rip + .L__unnamed_2] call qword ptr [rip + panic...] .LBB1_7: lea rdi, [rip + .L__unnamed_2] call qword ptr [rip + panic...] ``` And on Aarch64: ```asm _div_floor_new: _div_floor_old: stp x29, x30, [sp, #-16]! stp x29, x30, [sp, #-16]! mov x29, sp mov x29, sp cbz w1, LBB0_4 cbz w1, LBB1_9 mov w8, #-2147483648 mov x8, x0 cmp w0, w8 mov w9, #-2147483648 b.ne LBB0_3 cmp w0, w9 cmn w1, rust-lang#1 b.ne LBB1_3 b.eq LBB0_5 cmn w1, rust-lang#1 LBB0_3: b.eq LBB1_10 sdiv w8, w0, w1 LBB1_3: msub w9, w8, w1, w0 sdiv w0, w8, w1 eor w10, w1, w0 msub w8, w0, w1, w8 asr w10, w10, rust-lang#31 tbz w1, rust-lang#31, LBB1_5 cmp w9, #0 cmp w8, #0 csel w9, wzr, w10, eq b.gt LBB1_7 add w0, w9, w8 LBB1_5: ldp x29, x30, [sp], rust-lang#16 cmp w1, rust-lang#1 ret b.lt LBB1_8 LBB0_4: tbz w8, rust-lang#31, LBB1_8 adrp x0, l___unnamed_1@PAGE LBB1_7: add x0, x0, l___unnamed_1@PAGEOFF sub w0, w0, rust-lang#1 bl panic... LBB1_8: LBB0_5: ldp x29, x30, [sp], rust-lang#16 adrp x0, l___unnamed_1@PAGE ret add x0, x0, l___unnamed_1@PAGEOFF LBB1_9: bl panic... adrp x0, l___unnamed_2@PAGE add x0, x0, l___unnamed_2@PAGEOFF bl panic... LBB1_10: adrp x0, l___unnamed_2@PAGE add x0, x0, l___unnamed_2@PAGEOFF bl panic... ```
I am interested in this being fleshed out, so I surveyed the methods. The following division/remainder methods are not implemented. For ceiling and floored rounding, there is no
I maintain a document tracking rounding of division and modulo across languages, which may be a useful reference. |
Feature gate:
#![feature(int_roundings)]
This is a tracking issue for the
div_floor
,div_ceil
,next_multiple_of
, andchecked_multiple_of
methods on all integer types.Public API
Steps / History
int_roundings
methods from feedback #95359int_roundings
#94455Unresolved Questions
The text was updated successfully, but these errors were encountered: