-
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
Don't include <bit>
in <compare>
#3627
Don't include <bit>
in <compare>
#3627
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.
However, I'm not convinced by this change at all; <bit>
is one of the "most core" headers possible, and I don't necessarily believe it to be a good idea to try and remove it as a dependency.
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.
We talked about this at the weekly maintainer meeting and would prefer to see a different approach here, although we don't immediately know what would be best. Possible approaches to consider (in rough order of preference, from most preferred to least):
- Disconnect
<bit>
from<limits>
, because<limits>
is needed only fornumeric_limits::digits
which is trivially easy to compute for integral types (it's justsizeof(T) * 8
). Then<bit>
would include only<type_traits>
(which we pay the cost for basically everywhere) and<isa_availability.h>
which is core-compatible and very small, so we wouldn't need to worry about including<bit>
in other headers.- We should consider doing this anyways.
_Bit_cast
is currently defined in<xutility>
but it could be moved up even higher (e.g. up to<type_traits>
or similar). Its whole purpose is to be widely available (even without C++20) and using it even in C++20 mode to avoid dragging in<bit>
is reasonable.- Move Standard
bit_cast
up higher (possibly<type_traits>
). This is perhaps the least clean solution, as it exposes a Standard name to more TUs that weren't asking for it, encouraging non-Standard code to be written.
I'm afraid that Additionally, in MSVC STL we generally includes
There are other dependencies on
In most cases, How about defining FP <-> UInt conversion functions in |
Thanks, I had forgotten that dependency.
I think of that as fairly lightweight. Granted, I haven't done detailed profiling of throughput recently, but my expectation is that function declarations are fairly cheap. It's class definitions that can start to be expensive as they add up, and especially function definitions (including function template instantiations).
Oh yeah, thanks.
That might be worth it, if it allows us to avoid dragging in significant machinery. However, we want to be careful about pursuing throughput too aggressively and ending up with replicating various kinds of helpers when we could have just one. What do you think about lifting just |
And use it in `<compare>`
Thanks, I think this change is simple and safe now. It affects only C++20 mode, so there is virtually zero concern about source-breaking changes. It's also nice that |
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
Thanks for improving throughput one bit at a time! 😹 🎉 🚀 |
Separated from #3623. Towards #3599.
Once
<compare>
doesn't include<bit>
,<format>
needs to include<bit>
directly. I think it's better to use the standardstd::bit_cast
in<format>
.I have no good idea how to movestd::bit_cast
to another header. So currently this PR uses the__builtin_bit_cast
intrinsic.The current decision is moving
_Bit_cast
from<xutility>
to<type_traits>
and using it in<compare>
.