-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Use a bitwise and instead of shifts #3092
Conversation
This is faster in some instances and is clearer in intent
Thanks for looking into this! The optimized codegen is identical: https://godbolt.org/z/K4envEYs5 I believe that the debug codegen is not important here - these are per-algorithm-call, and we generally don't worry about slightly suboptimal instruction sequences (whereas we occasionally worry about many layers of unnecessary function calls, e.g. in So the main question is clarity, which is a judgement call. I believe that the existing pattern of shifting back and forth by N more clearly expresses the intent to clear the low N bits. Marking as "decision needed" for the other maintainers to consider. |
Just a suggestion: If you want to use this notation, I'd use binary litterals instead of decimal numbers. |
My opinion:
|
I strongly agree that |
Replacements: _Byte_length(_First, _Last) >> 5 << 5 _Byte_length(_First, _Last) & ~size_t{0x1F} _Byte_length(_First, _Last) >> 4 << 4 _Byte_length(_First, _Last) & ~size_t{0xF}
Replacements: _Byte_length(_First, _Last) >> 6 << 5 (_Byte_length(_First, _Last) >> 1) & ~size_t{0x1F} _Byte_length(_First, _Last) >> 5 << 4 (_Byte_length(_First, _Last) >> 1) & ~size_t{0xF}
Ok, I've validated and pushed changes to:
Codegen is unaffected: https://godbolt.org/z/h7qE3vca1 Thanks again! |
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
Thanks for this code cleanup! 😸 😸 😸 😸 😸 😸 😸 😸 |
Co-authored-by: Stephan T. Lavavej <stl@nuwen.net>
This is faster in some instances and is clearer in intent