-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Followups to int128_struct arithmetic #1156
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
Conversation
| } | ||
|
|
||
| static SECP256K1_INLINE void secp256k1_i128_load(secp256k1_int128 *r, int64_t hi, uint64_t lo) { | ||
| *r = (((uint128_t)(uint64_t)hi) << 64) + lo; |
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.
why not ((int128_t)hi << 64) + lo?
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.
((int128_t)hi << 64) + lo is UB if hi is negative (left-shift of negative value is undefined).
((uint128_t)hi << 64) + lo would work, but involves sign-extending hi, and then throwing those extension bits away.
((uint128_t)(uint64_t)hi << 64) + lo is equivalent, but avoids the sign-extension, which I thought would be more obviously correct.
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.
Somehow I missed the fact the left-shift of negative values is UB. In retrospect, that makes a bit of sense if you cannot count on two's complement, even if the formal definition of multiplying by 2^n still makes sense for negative numbers.
real-or-random
left a comment
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.
utACK 3afce0a
|
utACK 99bd335 |
real-or-random
left a comment
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.
utACK 99bd335
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.
utACK 99bd335
EDIT: Maybe #1158 (comment) should be merged first?
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.
ACK 99bd335 tested this also on MSVC locally with the override, including all the benchmark binaries
EDIT: Maybe #1158 (comment) should be merged first?
I think we should be greedy and merge it now that it has enough ACKs. The other one will be rather easy to rebase.
This is a follow-up to #1000:
_(u)mulhcode path (on non-ARM64 MSVC).