<cmath>: Use Clang builtins for classification/comparison functions#4612
Merged
StephanTLavavej merged 4 commits intomicrosoft:mainfrom Apr 26, 2024
Merged
<cmath>: Use Clang builtins for classification/comparison functions#4612StephanTLavavej merged 4 commits intomicrosoft:mainfrom
<cmath>: Use Clang builtins for classification/comparison functions#4612StephanTLavavej merged 4 commits intomicrosoft:mainfrom
Conversation
Contributor
I'm planning to create a follow-up PR addressing this. The changes would be somehow boilerplate though. |
CaseyCarter
approved these changes
Apr 24, 2024
Member
Author
|
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4609.
This is limited to functions that the UCRT has templated, where our non-template overloads will be preferred. For example, this PR omits
fpclassify()because the UCRT overloads it forfloat,double, andlong double(to call_fdtest(),_dtest(), and_ldtest(), respectively), so even though Clang provides aconstexpr-compatible__builtin_fpclassify, the STL can't provide overloads without introducing ambiguity.Note that we define our overloads in the global namespace and then drag them into
namespace std. Therefore, as long as users include<cmath>, their global namespace calls will benefit from this improvement.Also note an additional limitation: calls to the binary comparison functions with mixed argument types will select the UCRT templates as being better matches.
In the medium future, it looks like we're going to need a major UCRT overhaul of
<math.h>to implement all of theconstexprdemanded by C++23/26 - at that time we can also untangle the additional overloads that the STL is providing (for both integral and floating-point), and teach the UCRT to use MSVC and Clang builtins when possible.The MSVC compiler back-end should probably provide similar builtins - I am a lazy kitty 🐈 💤 so I haven't asked them, but again the upcoming
constexproverhaul work will likely result in such machinery becoming available.Click to expand codegen before:
Click to expand codegen after: