-
Notifications
You must be signed in to change notification settings - Fork 58
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
Cross-sizes wide multiplication & Mul trait implementation #226
Conversation
This feels like a combinatorial explosion. Are you checking how it impacts compile times? |
On my PC it's an increase from 1.47s to 4.98s:
After change:
Seems fine to me, but I'll let you decide on that. The output binary size is roughly 4x as well. One thing that it does impact is Intellij with its macro-expansion feature, but I think that's also acceptable, again up to you |
Oof, so a ~350% increase. This really feels like the sort of problem it would be worth waiting for const generics to properly address, rather than providing a "brute force" solution that adds hundreds (thousands?) or trait impls. |
How would const-generics properly address this? I am writing my library now, and if I won't have these features I'd have to fork which I really am trying my best to avoid here. I prefer having a temporary solution that will be replaced in the future rather than having nothing. Would feature-gating this be an acceptable compromise? Another option would be to export the macro, and not instantiate it with any specific values. So that later on in my crate I can choose the exact types I need and implement the cross-support needed for them specifically by calling this macro. But the macro would still be in crypto-bigint. This would give me the needed functionality, and add no overhead of compilation time / size. |
Yes, an off-by-default feature gate would be ok, preferably one that happens prior to the macro being expanded. Maybe move all of that to its own module and feature gate the module? |
Do you prefer feature-gating over the option to export the macro only (and not call it within crypto-bigint but within the consumer)? |
I don't see how exporting the macro would help. It's adding |
# Conflicts: # src/uint/concat.rs
Replaced by #230 |
This implements
Mul<Self, Output = Self::Concat>
for all types as well asMul<Rhs, Output = Uint<{nlimbs!($self_bits) + nlimbs!($rhs_bits)}>>
for all types.This is possible because
mul_wide
now takes a second generic paramater:One could debate whether this is a breaking change, for this changes the signature of a public function, but I'd argue against that, for Rust allows type inference in a way that simplifies down to the exact same signature for the special case where
Rhs = Self
which was the case formul_wide()
before this change.This means that I did not need to change any code that used
mul_wide
, and for example,U64::ONE.mul_wide(&U64::ZERO)
compiles without needing to specify the generic parameters.In order to implement this, I needed to also implement cross-sizes concatenation, which is why I already merged #224 into this PR, so it should be reviewed & approved before this one.
Resolves #209