-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Floating minmax: fix negative zero handling and dedicated test coverage for arrays of +0.0 and -0.0 only #4734
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
Merged
Stephan T. Lavavej (StephanTLavavej)
merged 38 commits into
microsoft:main
from
AlexGuteniev:float_zeros
Aug 25, 2024
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
b1e4baf
Sedicated test coverage for floating minmax of +0.0 and -0.0 only
AlexGuteniev 18cc8b1
expand test
AlexGuteniev fba7701
expand test with canned simple case
AlexGuteniev f0b43fb
Fix the bug
AlexGuteniev 52eda32
Merge branch 'main' into float_zeros
AlexGuteniev 4040d48
fix merge error
AlexGuteniev 75acc88
more interesting predefined cases
AlexGuteniev 48c23b5
Even more coverage
AlexGuteniev 7d00070
Implement `minmax` in terms of `minmax_element`
AlexGuteniev 4302235
Fix ascending order
AlexGuteniev 1f124c4
tail correctness is not needed anymore
AlexGuteniev 0a0be65
Merge remote-tracking branch 'upstream/main' into float_zeros
AlexGuteniev b34c73e
even better random coverage
AlexGuteniev 893792f
Don't check zeros for fp:fast
AlexGuteniev ff3e15b
Restore the full optimization, it is fine for `/fp:fast`
AlexGuteniev 8bdda8b
disable value-based floating vector algorithms for non-fast-math in h…
AlexGuteniev 3f0b77f
/fp:fast coverage
AlexGuteniev b7b19d0
fix Both_val
AlexGuteniev 1a818d6
common header
AlexGuteniev 714be8d
Merge branch 'main' into float_zeros
StephanTLavavej e1a5ff7
Add `#pragma once` to new test header.
StephanTLavavej 437454e
Include more headers.
StephanTLavavej 684cd27
Include fewer headers.
StephanTLavavej 206ef5c
Add `std::` qualification.
StephanTLavavej 7a0d538
Remove `std::` qualification.
StephanTLavavej 7891ef7
Drop unnecessary `if constexpr` suppression.
StephanTLavavej 158a007
Take a function object instead of a function pointer.
StephanTLavavej 1058249
Header-only functions should be `inline`.
StephanTLavavej 1384cf8
Use consistent preprocessor guards.
StephanTLavavej e50cf12
Add new test to test.lst.
StephanTLavavej 129c8d7
Fix code typo: `-1, 0` => `-1.0`
StephanTLavavej 3ccad6c
Fix bug: `-0` => `-0.0`
StephanTLavavej 09450f6
Add missing quotes.
StephanTLavavej b1fb57b
Drop /fp options instead of whole lines.
StephanTLavavej 8d55da1
Adjust endif comment to match.
StephanTLavavej 2e947b6
Drop duplicate comment in vector_algorithms.cpp.
StephanTLavavej b7c840c
Improve comments.
StephanTLavavej e1c4d4f
Drop /clr and /clr:pure lines.
StephanTLavavej File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <algorithm> | ||
| #include <cstddef> | ||
| #include <cstdint> | ||
| #include <cstdio> | ||
| #include <functional> | ||
| #include <isa_availability.h> | ||
| #include <random> | ||
| #include <vector> | ||
|
StephanTLavavej marked this conversation as resolved.
|
||
|
|
||
| inline void initialize_randomness(std::mt19937_64& gen) { | ||
| constexpr std::size_t n = std::mt19937_64::state_size; | ||
| constexpr std::size_t w = std::mt19937_64::word_size; | ||
| static_assert(w % 32 == 0, "w should be evenly divisible by 32"); | ||
| constexpr std::size_t k = w / 32; | ||
|
|
||
| std::vector<std::uint32_t> vec(n * k); | ||
|
|
||
| std::random_device rd; | ||
| std::generate(vec.begin(), vec.end(), std::ref(rd)); | ||
|
|
||
| std::printf("This is a randomized test.\n"); | ||
| std::printf("DO NOT IGNORE/RERUN ANY FAILURES.\n"); | ||
| std::printf("You must report them to the STL maintainers.\n\n"); | ||
|
|
||
| std::printf("Seed vector: "); | ||
| for (const auto& e : vec) { | ||
| std::printf("%u,", e); | ||
| } | ||
| std::printf("\n"); | ||
|
|
||
| std::seed_seq seq(vec.cbegin(), vec.cend()); | ||
| gen.seed(seq); | ||
| } | ||
|
|
||
| #if (defined(_M_IX86) || defined(_M_X64)) && !defined(_M_CEE_PURE) | ||
| extern "C" long __isa_enabled; | ||
|
|
||
| inline void disable_instructions(ISA_AVAILABILITY isa) { | ||
| __isa_enabled &= ~(1UL << static_cast<unsigned long>(isa)); | ||
| } | ||
| #endif // (defined(_M_IX86) || defined(_M_X64)) && !defined(_M_CEE_PURE) | ||
|
|
||
| constexpr std::size_t dataCount = 1024; | ||
|
|
||
| template <class TestFunc> | ||
| void run_randomized_tests_with_different_isa_levels(TestFunc tests) { | ||
| std::mt19937_64 gen; | ||
| initialize_randomness(gen); | ||
|
|
||
| tests(gen); | ||
|
|
||
| #if (defined(_M_IX86) || defined(_M_X64)) && !defined(_M_CEE_PURE) | ||
| disable_instructions(__ISA_AVAILABLE_AVX2); | ||
| tests(gen); | ||
|
|
||
| disable_instructions(__ISA_AVAILABLE_SSE42); | ||
| tests(gen); | ||
| #endif // (defined(_M_IX86) || defined(_M_X64)) && !defined(_M_CEE_PURE) | ||
| } | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.