vector_algorithms.cpp: Add [[nodiscard]] to _Use_avx2() and _Use_sse42()#6192
vector_algorithms.cpp: Add [[nodiscard]] to _Use_avx2() and _Use_sse42()#6192StephanTLavavej merged 2 commits intomicrosoft:mainfrom
vector_algorithms.cpp: Add [[nodiscard]] to _Use_avx2() and _Use_sse42()#6192Conversation
|
The query results can be cached as |
|
MSVC can optimize the function-scoped static atomic to be the same as one with internal linkage at namespace scope, without using the magic static mechanism, and magic static is worse, see: https://godbolt.org/z/r4zr9oE7s |
|
No - Aside from that, the complexity of introducing atomics isn't worth it here. We're reading an integer, not doing anything outrageously expensive, and branch prediction is going to be really happy with a result that doesn't change. |
|
Dragging-in atomics for such a tiny function would definitely be an overkill, imo.
Can you give any hints, what exactly these unusual interactions is, or where to read about it? |
<vector_algorithms.cpp> Add static and [[nodiscard]] to _Use_avx2() and _Use_sse42()vector_algorithms.cpp: Add [[nodiscard]] to _Use_avx2() and _Use_sse42()
|
As I recall, they create a TLS section in the resulting binary, which had weird interactions with an optimization that Windows wanted to do. |
|
I have re-showd my comments, which compare magic static and atomic. The conclusion is that if you want the best performance, then use lock-free atomics, or do not cache the result. Although I have only shown the results for MSVC, this actually applies to all compilers and operating systems. |
|
I'm mirroring this to the MSVC-internal repo. Please notify me if any further changes are pushed, otherwise no action is required. |
|
Thanks for adding our favorite attribute! 😻 |
Adds
[[nodiscard]]to_Use_avx2()and_Use_sse42()functions.