-
Notifications
You must be signed in to change notification settings - Fork 83
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
dev: Exponentiation & Bitshift generics #410
dev: Exponentiation & Bitshift generics #410
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice PR overall,
Good catch that wrappingbitshift and wrappingpow are not able to be generic over T
Saw that the original implementation of fn shr(self: u128, shift: u128) -> u128 {
if shift > 127 {
return 0;
}
self / 2.pow(shift)
}
// or
fn shr(self: u256, shift: u256) -> u256 {
if shift > 255 {
// 2.pow(shift) for shift > 255 will panic with 'u256_mul Overflow'
panic_with_felt252('u256_mul Overflow');
}
self / 2.pow(shift)
} Not sure of which we prefer for the T type. I'd say panic, what do you think @Eikix ? |
Regular |
Should be good then! I also quickly updated the organization of the code, added a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work
Also @akhercha I think your local git is not synced to your GH account - not sure if it's on purpose or not |
Ah no indeed, something exploded in my config I guess, gonna check that thanks! |
@akhercha I just pushed a change with more optimized gas usage - basically since Oneable and Zeroable fns are not inlined there's a small overhead in gas consumption if we rely on them for genericity. Therefore I changed my mind about my previous comment, and explicitly implemented Zero and One for u128, u256, and felt252 ( we won't need other impls, at least for now). This nullifies any increase in gas consumption for |
4924e76
to
b6a84b4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@akhercha do you want to open an issue to implement SizeOf in the corelib https://github.com/starkware-libs/cairo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm 🔥
Pull Request type
Please check the type of change your PR introduces:
What is the current behavior?
Resolves: #408
What is the new behavior?
Added
ExponentiationImpl<T, ...> of Exponentiation<T>
U256ExpImpl
&U128ExpImpl
Added
BitshiftImpl<T, ...> of Bitshift<T>
U256BitshiftImpl
&U128BitshiftImpl
Does this introduce a breaking change?