You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make wrapping_neg and overflowing_neg functions into const #57536
With the merge of #57234, we can now make wrapping_neg and overflowing_neg into const as well. They are currently branching, but with a small amount of bit math you can make it branchless instead.
(I have no opinions on whether this is feasible to do branchless and w/o control flow, seems like something that needs to be perf tested to not regress non-CTFE...)
There appears to be the same performance once you go through optimization (with 1.31, and on x86_64, I didn't check every single target). The overflowing versions are slightly different, but the wrapping versions are the exact same.
example::CORE_wrapping_neg_u8:
neg dil
mov eax, edi
ret
example::NEW_wrapping_neg_u8:
neg dil
mov eax, edi
ret
example::CORE_wrapping_neg_i8:
neg dil
mov eax, edi
ret
example::NEW_wrapping_neg_i8:
neg dil
mov eax, edi
ret
Activity
Centril commentedon Jan 12, 2019
cc @SimonSapin
(I have no opinions on whether this is feasible to do branchless and w/o control flow, seems like something that needs to be perf tested to not regress non-CTFE...)
Lokathor commentedon Jan 13, 2019
There appears to be the same performance once you go through optimization (with 1.31, and on x86_64, I didn't check every single target). The overflowing versions are slightly different, but the wrapping versions are the exact same.
https://godbolt.org/z/IWJ2ev
Centril commentedon Mar 28, 2019
This was done in #58044.