2020-01-25 10:04:31 +01:00
|
|
|
// SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
|
2020-01-25 13:13:07 +01:00
|
|
|
// This code is part of the sfizz library and is licensed under a BSD 2-clause
|
|
|
|
|
// license. You should have receive a LICENSE.md file along with the code.
|
|
|
|
|
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
|
2019-08-30 00:49:58 +02:00
|
|
|
|
2019-11-23 18:58:51 +01:00
|
|
|
#include "SIMDHelpers.h"
|
|
|
|
|
#include "Buffer.h"
|
2020-01-04 17:38:51 +01:00
|
|
|
#include <benchmark/benchmark.h>
|
2019-08-21 18:45:59 +02:00
|
|
|
#include <algorithm>
|
|
|
|
|
#include <numeric>
|
|
|
|
|
#include <absl/types/span.h>
|
|
|
|
|
|
|
|
|
|
static void Scalar(benchmark::State& state) {
|
2019-09-25 23:48:52 +02:00
|
|
|
sfz::Buffer<float> input (state.range(0) * 2);
|
|
|
|
|
sfz::Buffer<float> outputLeft (state.range(0));
|
|
|
|
|
sfz::Buffer<float> outputRight (state.range(0));
|
2019-08-21 18:45:59 +02:00
|
|
|
std::iota(input.begin(), input.end(), 1.0f);
|
|
|
|
|
|
|
|
|
|
for (auto _ : state) {
|
2020-06-03 21:57:04 +02:00
|
|
|
sfz::setSIMDOpStatus<float>(sfz::SIMDOps::readInterleaved, false);
|
2020-05-30 20:27:44 +02:00
|
|
|
sfz::readInterleaved(input, absl::MakeSpan(outputLeft), absl::MakeSpan(outputRight));
|
2019-08-21 18:45:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void SSE(benchmark::State& state) {
|
2019-09-25 23:48:52 +02:00
|
|
|
sfz::Buffer<float> input (state.range(0) * 2);
|
|
|
|
|
sfz::Buffer<float> outputLeft (state.range(0));
|
|
|
|
|
sfz::Buffer<float> outputRight (state.range(0));
|
2019-08-21 18:45:59 +02:00
|
|
|
std::iota(input.begin(), input.end(), 1.0f);
|
|
|
|
|
|
|
|
|
|
for (auto _ : state) {
|
2020-06-03 21:57:04 +02:00
|
|
|
sfz::setSIMDOpStatus<float>(sfz::SIMDOps::readInterleaved, true);
|
2020-05-30 20:27:44 +02:00
|
|
|
sfz::readInterleaved(input, absl::MakeSpan(outputLeft), absl::MakeSpan(outputRight));
|
2019-08-21 18:45:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void Scalar_Unaligned(benchmark::State& state) {
|
2019-09-25 23:48:52 +02:00
|
|
|
sfz::Buffer<float> input (state.range(0) * 2);
|
|
|
|
|
sfz::Buffer<float> outputLeft (state.range(0));
|
|
|
|
|
sfz::Buffer<float> outputRight (state.range(0));
|
2019-08-21 18:45:59 +02:00
|
|
|
std::iota(input.begin(), input.end(), 1.0f);
|
|
|
|
|
for (auto _ : state) {
|
2020-06-03 21:57:04 +02:00
|
|
|
sfz::setSIMDOpStatus<float>(sfz::SIMDOps::readInterleaved, false);
|
2020-05-30 20:27:44 +02:00
|
|
|
sfz::readInterleaved(
|
|
|
|
|
absl::MakeSpan(input).subspan(2),
|
|
|
|
|
absl::MakeSpan(outputLeft),
|
|
|
|
|
absl::MakeSpan(outputRight)
|
|
|
|
|
);
|
2019-08-21 18:45:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void SSE_Unaligned(benchmark::State& state) {
|
2019-09-25 23:48:52 +02:00
|
|
|
sfz::Buffer<float> input (state.range(0) * 2);
|
|
|
|
|
sfz::Buffer<float> outputLeft (state.range(0));
|
|
|
|
|
sfz::Buffer<float> outputRight (state.range(0));
|
2019-08-21 18:45:59 +02:00
|
|
|
std::iota(input.begin(), input.end(), 1.0f);
|
|
|
|
|
for (auto _ : state) {
|
2020-06-03 21:57:04 +02:00
|
|
|
sfz::setSIMDOpStatus<float>(sfz::SIMDOps::readInterleaved, true);
|
2020-05-30 20:27:44 +02:00
|
|
|
sfz::readInterleaved(
|
|
|
|
|
absl::MakeSpan(input).subspan(2),
|
|
|
|
|
absl::MakeSpan(outputLeft),
|
|
|
|
|
absl::MakeSpan(outputRight)
|
|
|
|
|
);
|
2019-08-21 23:00:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void Scalar_Unaligned_2(benchmark::State& state) {
|
2019-09-25 23:48:52 +02:00
|
|
|
sfz::Buffer<float> input (state.range(0) * 2);
|
|
|
|
|
sfz::Buffer<float> outputLeft (state.range(0));
|
|
|
|
|
sfz::Buffer<float> outputRight (state.range(0));
|
2019-08-21 23:00:06 +02:00
|
|
|
std::iota(input.begin(), input.end(), 1.0f);
|
|
|
|
|
for (auto _ : state) {
|
2020-06-03 21:57:04 +02:00
|
|
|
sfz::setSIMDOpStatus<float>(sfz::SIMDOps::readInterleaved, false);
|
2020-05-30 20:27:44 +02:00
|
|
|
sfz::readInterleaved(
|
|
|
|
|
absl::MakeSpan(input).subspan(2),
|
|
|
|
|
absl::MakeSpan(outputLeft).subspan(1),
|
|
|
|
|
absl::MakeSpan(outputRight).subspan(3)
|
|
|
|
|
);
|
2019-08-21 23:00:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void SSE_Unaligned_2(benchmark::State& state) {
|
2019-09-25 23:48:52 +02:00
|
|
|
sfz::Buffer<float> input (state.range(0) * 2);
|
|
|
|
|
sfz::Buffer<float> outputLeft (state.range(0));
|
|
|
|
|
sfz::Buffer<float> outputRight (state.range(0));
|
2019-08-21 23:00:06 +02:00
|
|
|
std::iota(input.begin(), input.end(), 1.0f);
|
|
|
|
|
for (auto _ : state) {
|
2020-06-03 21:57:04 +02:00
|
|
|
sfz::setSIMDOpStatus<float>(sfz::SIMDOps::readInterleaved, true);
|
2020-05-30 20:27:44 +02:00
|
|
|
sfz::readInterleaved(
|
|
|
|
|
absl::MakeSpan(input).subspan(2),
|
|
|
|
|
absl::MakeSpan(outputLeft).subspan(1),
|
|
|
|
|
absl::MakeSpan(outputRight).subspan(3)
|
|
|
|
|
);
|
2019-08-21 18:45:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BENCHMARK(Scalar)->Range((8<<10), (8<<20));
|
|
|
|
|
BENCHMARK(SSE)->Range((8<<10), (8<<20));
|
|
|
|
|
BENCHMARK(Scalar_Unaligned)->Range((8<<10), (8<<20));
|
|
|
|
|
BENCHMARK(SSE_Unaligned)->Range((8<<10), (8<<20));
|
2019-08-21 23:00:06 +02:00
|
|
|
BENCHMARK(Scalar_Unaligned_2)->Range((8<<10), (8<<20));
|
|
|
|
|
BENCHMARK(SSE_Unaligned_2)->Range((8<<10), (8<<20));
|
2020-01-04 17:38:51 +01:00
|
|
|
BENCHMARK_MAIN();
|