Skip to content

Conversation

Kivooeo
Copy link
Member

@Kivooeo Kivooeo commented Sep 6, 2025

Since u128 is stable now, I guess, we can safely add this, not sure if this requires tests or anything

cc #137887

@rustbot
Copy link
Collaborator

rustbot commented Sep 6, 2025

r? @scottmcm

rustbot has assigned @scottmcm.
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 S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Sep 6, 2025
@hanna-kruppe
Copy link
Contributor

I’m pretty sure uncommenting this doesn’t actually do anything unless you also update the define_bignum! invocations at the bottom of the file, and update some other code to use a new u64-limb-based type.

@Kivooeo
Copy link
Member Author

Kivooeo commented Sep 6, 2025

Thanks, I wanted to hear something like this, but I might need little bit more explanations about this

update the define_bignum! invocations at the bottom of the file

Do I have to replace this u32 with u64 and rename it to 64 as well?

pub type Digit32 = u32;

define_bignum!(Big32x40: type=Digit32, n=40);

And update this name in other places like imports and tests?

@hanna-kruppe
Copy link
Contributor

I don’t know if I can provide much guidance here. I haven’t touched this code in about ten years and the parts I’ve worked on have almost entirely been replaced by now. The only thing I can tell you is that simply replacing the existing u32 limbs with u64 limbs will probably be a performance regression on 32 bit targets. A straight replacement is probably easier to try out (to see if it gives any performance gains) but a version that can happily be merged will probably have to grapple with using different bignum types based on some cfg(…)s.

@Kivooeo
Copy link
Member Author

Kivooeo commented Sep 6, 2025

I like your idea with cfg, but I wonder about how can I benchmark code in core? Is there any tools or something I can use to measure bignum performance before and after changes

@hanna-kruppe
Copy link
Contributor

It used to be used in the slow paths of dec2flt and flt2dec. From a quick code search on GitHub, only flt2dec is still using it. I don’t know off-hand how to find a benchmark that takes that particular code path.

@Kivooeo
Copy link
Member Author

Kivooeo commented Sep 6, 2025

I tried a full replacement locally and saw the extensive fallout in tests and constants. It's a much larger change than I initially thought.

Given the scope and the risk of regression on 32-bit, I'll keep this PR minimal and just uncommenting the line to clean up the obsolete comment. The architectural shift to cfg-based types is better suited for a dedicated effort.

}

impl_full_ops! {
u8: add(intrinsics::u8_add_with_overflow), mul/div(u16);
Copy link
Member

Choose a reason for hiding this comment

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

Speaking of things being stable‚ it looks like full_mul_add above could just be a call to https://doc.rust-lang.org/nightly/std/primitive.u32.html#method.carrying_mul_add -- which is now stable -- instead of needing to write out the multiplication in $bigty.

Want to make another PR after this one to do that? 🙂

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure

@scottmcm
Copy link
Member

Agreed it seems reasonable to just impl the trait for the type -- better than a fixme, at least.

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Oct 14, 2025

📌 Commit 13ed4a3 has been approved by scottmcm

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 Oct 14, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Oct 14, 2025
Enable `u64` limbs in `core::num::bignum`

Since `u128` is stable now, I guess, we can safely add this, not sure if this requires tests or anything

cc rust-lang#137887
Zalathar added a commit to Zalathar/rust that referenced this pull request Oct 14, 2025
Enable `u64` limbs in `core::num::bignum`

Since `u128` is stable now, I guess, we can safely add this, not sure if this requires tests or anything

cc rust-lang#137887
bors added a commit that referenced this pull request Oct 14, 2025
Rollup of 11 pull requests

Successful merges:

 - #146277 (Enable `u64` limbs in `core::num::bignum`)
 - #146976 (constify basic Clone impls)
 - #147249 (Do two passes of `handle_opaque_type_uses_next`)
 - #147266 (fix 2 search graph bugs)
 - #147468 (Implement fs api set_times and set_times_nofollow)
 - #147497 (`proc_macro` cleanups (3/N))
 - #147594 (std: implement `pal::os::exit` for VEXos)
 - #147596 (Adjust the Arm targets in CI to reflect latest changes)
 - #147607 (GVN: Invalidate derefs at loop headers)
 - #147620 (Avoid redundant UB check in RangeFrom slice indexing)
 - #147647 (Hide vendoring and copyright in GHA group)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 14, 2025
Enable `u64` limbs in `core::num::bignum`

Since `u128` is stable now, I guess, we can safely add this, not sure if this requires tests or anything

cc rust-lang#137887
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 14, 2025
Enable `u64` limbs in `core::num::bignum`

Since `u128` is stable now, I guess, we can safely add this, not sure if this requires tests or anything

cc rust-lang#137887
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 14, 2025
Enable `u64` limbs in `core::num::bignum`

Since `u128` is stable now, I guess, we can safely add this, not sure if this requires tests or anything

cc rust-lang#137887
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 14, 2025
Enable `u64` limbs in `core::num::bignum`

Since `u128` is stable now, I guess, we can safely add this, not sure if this requires tests or anything

cc rust-lang#137887
bors added a commit that referenced this pull request Oct 14, 2025
Rollup of 12 pull requests

Successful merges:

 - #146277 (Enable `u64` limbs in `core::num::bignum`)
 - #146976 (constify basic Clone impls)
 - #147249 (Do two passes of `handle_opaque_type_uses_next`)
 - #147266 (fix 2 search graph bugs)
 - #147497 (`proc_macro` cleanups (3/N))
 - #147546 (Suppress unused_parens for labeled break)
 - #147548 (Fix ICE for never pattern as closure parameters)
 - #147594 (std: implement `pal::os::exit` for VEXos)
 - #147596 (Adjust the Arm targets in CI to reflect latest changes)
 - #147607 (GVN: Invalidate derefs at loop headers)
 - #147620 (Avoid redundant UB check in RangeFrom slice indexing)
 - #147647 (Hide vendoring and copyright in GHA group)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 14, 2025
…cottmcm

Replace manual implementation with `carrying_mul_add`

cc rust-lang#146277 (comment)

r? scottmcm
@bors bors merged commit 6e07b25 into rust-lang:master Oct 14, 2025
10 checks passed
@rustbot rustbot added this to the 1.92.0 milestone Oct 14, 2025
rust-timer added a commit that referenced this pull request Oct 14, 2025
Rollup merge of #146277 - Kivooeo:u64-unlock, r=scottmcm

Enable `u64` limbs in `core::num::bignum`

Since `u128` is stable now, I guess, we can safely add this, not sure if this requires tests or anything

cc #137887
jdonszelmann added a commit to jdonszelmann/rust that referenced this pull request Oct 14, 2025
…cottmcm

Replace manual implementation with `carrying_mul_add`

cc rust-lang#146277 (comment)

r? scottmcm
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 14, 2025
…cottmcm

Replace manual implementation with `carrying_mul_add`

cc rust-lang#146277 (comment)

r? scottmcm
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 14, 2025
…cottmcm

Replace manual implementation with `carrying_mul_add`

cc rust-lang#146277 (comment)

r? scottmcm
rust-timer added a commit that referenced this pull request Oct 15, 2025
Rollup merge of #147666 - Kivooeo:full_mud_add-followup, r=scottmcm

Replace manual implementation with `carrying_mul_add`

cc #146277 (comment)

r? scottmcm
@Zalathar
Copy link
Contributor

Bors hasn't noticed that this was merged.

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 15, 2025
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Oct 15, 2025
Replace manual implementation with `carrying_mul_add`

cc rust-lang/rust#146277 (comment)

r? scottmcm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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