-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Help the compiler vectorize adjacent_difference
#4958
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
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
85a67ec
benchmark
AlexGuteniev b0bab69
test coverage
AlexGuteniev eb0cf5a
the optimization
AlexGuteniev eed039f
You shall pass!
AlexGuteniev bc92d54
constexpr
AlexGuteniev fd51080
ADL
AlexGuteniev 3db07e7
rvalue
AlexGuteniev 53a60d4
Review comments
AlexGuteniev 51595a3
types
AlexGuteniev 99e6058
Pointer math
AlexGuteniev 869a0cc
Merge remote-tracking branch 'upstream/main' into adjacent
AlexGuteniev 3cdbc88
std already
AlexGuteniev 18f64ca
const
AlexGuteniev c68b402
oops loops
AlexGuteniev da4ef2b
Merge remote-tracking branch 'upstream/main' into adjacent
AlexGuteniev ba9a098
U
AlexGuteniev 3ddaf9e
typos
AlexGuteniev 944672b
includes
AlexGuteniev 0042fe7
non-random filler
AlexGuteniev d06ea71
stray
AlexGuteniev df487ce
Merge branch 'main' into adjacent
StephanTLavavej f132d46
Test 8-bit and 16-bit, avoid truncation warnings.
StephanTLavavej cfb92a4
static_assert: The documentation that rewards poor reading comprehens…
StephanTLavavej c2a130f
Consistently order output_expected before output_actual.
StephanTLavavej 7a110a8
Minor comment grammar improvements.
StephanTLavavej d86bf29
Fix perf bug: Inspect unwrapped iterators with `_Iterators_are_contig…
StephanTLavavej 9b85627
Fix and test adjacent_difference with heterogeneous types.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
#include <algorithm> | ||
#include <benchmark/benchmark.h> | ||
#include <cstddef> | ||
#include <cstdint> | ||
#include <limits> | ||
#include <numeric> | ||
#include <random> | ||
#include <type_traits> | ||
#include <vector> | ||
|
||
using namespace std; | ||
|
||
template <class T> | ||
void bm(benchmark::State& state) { | ||
mt19937 gen(96337); | ||
|
||
const size_t size = static_cast<size_t>(state.range(0)); | ||
|
||
vector<T> input(size); | ||
vector<T> output(size); | ||
|
||
if constexpr (is_floating_point_v<T>) { | ||
AlexGuteniev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
normal_distribution<T> dis(-100.0, 100.0); | ||
ranges::generate(input, [&] { return dis(gen); }); | ||
AlexGuteniev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else { | ||
static_assert(is_unsigned_v<T>, "This avoids signed integers to avoid UB; they shouldn't perform differently"); | ||
uniform_int_distribution<conditional_t<sizeof(T) != 1, T, unsigned int>> dis(0, numeric_limits<T>::max()); | ||
ranges::generate(input, [&] { return static_cast<T>(dis(gen)); }); | ||
} | ||
|
||
for (auto _ : state) { | ||
benchmark::DoNotOptimize(input); | ||
adjacent_difference(input.begin(), input.end(), output.begin()); | ||
benchmark::DoNotOptimize(output); | ||
} | ||
} | ||
|
||
void common_args(auto bm) { | ||
bm->Arg(2255); | ||
} | ||
|
||
#pragma warning(push) | ||
#pragma warning(disable : 4244) // warning C4244: '=': conversion from 'int' to 'unsigned char', possible loss of data | ||
BENCHMARK(bm<uint8_t>)->Apply(common_args); | ||
BENCHMARK(bm<uint16_t>)->Apply(common_args); | ||
#pragma warning(pop) | ||
|
||
BENCHMARK(bm<uint32_t>)->Apply(common_args); | ||
BENCHMARK(bm<uint64_t>)->Apply(common_args); | ||
|
||
BENCHMARK(bm<float>)->Apply(common_args); | ||
BENCHMARK(bm<double>)->Apply(common_args); | ||
|
||
BENCHMARK_MAIN(); |
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
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.