Added a copy helper
This commit is contained in:
parent
fad715559f
commit
a5212fd2d6
8 changed files with 86 additions and 3 deletions
|
|
@ -57,6 +57,9 @@ target_link_libraries(bm_ADSR benchmark absl::span absl::algorithm)
|
||||||
add_executable(bm_add BM_add.cpp ${SFIZZ_SIMD_SOURCES})
|
add_executable(bm_add BM_add.cpp ${SFIZZ_SIMD_SOURCES})
|
||||||
target_link_libraries(bm_add benchmark absl::span absl::algorithm)
|
target_link_libraries(bm_add benchmark absl::span absl::algorithm)
|
||||||
|
|
||||||
|
add_executable(bm_copy BM_copy.cpp ${SFIZZ_SIMD_SOURCES})
|
||||||
|
target_link_libraries(bm_copy benchmark absl::span absl::algorithm)
|
||||||
|
|
||||||
add_custom_target(sfizz_benchmarks)
|
add_custom_target(sfizz_benchmarks)
|
||||||
add_dependencies(sfizz_benchmarks
|
add_dependencies(sfizz_benchmarks
|
||||||
bm_opf_high_vs_low
|
bm_opf_high_vs_low
|
||||||
|
|
|
||||||
2
external/Catch2
vendored
2
external/Catch2
vendored
|
|
@ -1 +1 @@
|
||||||
Subproject commit ce42deb72fab2be85a862f559984580c24cb76c4
|
Subproject commit b77ab74b723cbd55ee12883562e22c7e467dbcb1
|
||||||
2
external/abseil-cpp
vendored
2
external/abseil-cpp
vendored
|
|
@ -1 +1 @@
|
||||||
Subproject commit 83c1d65c90a92aa49632b9ac5a793214bb0768bc
|
Subproject commit 325fd7b042ff4ec34f7dd32e602cd81ad0e24b22
|
||||||
|
|
@ -54,4 +54,5 @@ namespace SIMDConfig {
|
||||||
constexpr bool linearRamp { false };
|
constexpr bool linearRamp { false };
|
||||||
constexpr bool multiplicativeRamp { true };
|
constexpr bool multiplicativeRamp { true };
|
||||||
constexpr bool add { false };
|
constexpr bool add { false };
|
||||||
|
constexpr bool copy { false };
|
||||||
}
|
}
|
||||||
|
|
@ -106,4 +106,10 @@ template <>
|
||||||
void add<float, true>(absl::Span<const float> input, absl::Span<float> output) noexcept
|
void add<float, true>(absl::Span<const float> input, absl::Span<float> output) noexcept
|
||||||
{
|
{
|
||||||
add<float, false>(input, output);
|
add<float, false>(input, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
void copy<float, true>(absl::Span<const float> input, absl::Span<float> output) noexcept
|
||||||
|
{
|
||||||
|
copy<float, false>(input, output);
|
||||||
}
|
}
|
||||||
|
|
@ -325,4 +325,25 @@ void add(absl::Span<const T> input, absl::Span<T> output) noexcept
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
void add<float, true>(absl::Span<const float> input, absl::Span<float> output) noexcept;
|
void add<float, true>(absl::Span<const float> input, absl::Span<float> output) noexcept;
|
||||||
|
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void snippetCopy(const T*& input, T*& output)
|
||||||
|
{
|
||||||
|
*output++ = *input++;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T, bool SIMD = SIMDConfig::copy>
|
||||||
|
void copy(absl::Span<const T> input, absl::Span<T> output) noexcept
|
||||||
|
{
|
||||||
|
ASSERT(output.size() >= input.size());
|
||||||
|
auto* in = input.begin();
|
||||||
|
auto* out = output.begin();
|
||||||
|
auto* sentinel = out + min(input.size(), output.size());
|
||||||
|
while (out < sentinel)
|
||||||
|
snippetCopy(in, out);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
void copy<float, true>(absl::Span<const float> input, absl::Span<float> output) noexcept;
|
||||||
|
|
@ -494,4 +494,26 @@ void add<float, true>(absl::Span<const float> input, absl::Span<float> output) n
|
||||||
|
|
||||||
while (out < sentinel)
|
while (out < sentinel)
|
||||||
snippetAdd<float>(in, out);
|
snippetAdd<float>(in, out);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
void copy<float, true>(absl::Span<const float> input, absl::Span<float> output) noexcept
|
||||||
|
{
|
||||||
|
ASSERT(output.size() >= input.size());
|
||||||
|
auto* in = input.begin();
|
||||||
|
auto* out = output.begin();
|
||||||
|
auto* sentinel = out + min(input.size(), output.size());
|
||||||
|
const auto* lastAligned = prevAligned(sentinel);
|
||||||
|
|
||||||
|
while (unaligned(in, out) && out < lastAligned)
|
||||||
|
snippetCopy<float>(in, out);
|
||||||
|
|
||||||
|
while (out < lastAligned) {
|
||||||
|
_mm_store_ps(out, _mm_load_ps(in));
|
||||||
|
out += TypeAlignment;
|
||||||
|
in += TypeAlignment;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (out < sentinel)
|
||||||
|
snippetCopy<float>(in, out);
|
||||||
}
|
}
|
||||||
|
|
@ -622,3 +622,33 @@ TEST_CASE("[Helpers] Add (SIMD vs scalar)")
|
||||||
add<float, true>(input, absl::MakeSpan(outputSIMD));
|
add<float, true>(input, absl::MakeSpan(outputSIMD));
|
||||||
REQUIRE(approxEqual<float>(outputScalar, outputSIMD));
|
REQUIRE(approxEqual<float>(outputScalar, outputSIMD));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("[Helpers] copy")
|
||||||
|
{
|
||||||
|
std::array<float, 5> input { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };
|
||||||
|
std::array<float, 5> output { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f };
|
||||||
|
copy<float, false>(input, absl::MakeSpan(output));
|
||||||
|
REQUIRE(output == input);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("[Helpers] copy (SIMD)")
|
||||||
|
{
|
||||||
|
std::array<float, 5> input { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };
|
||||||
|
std::array<float, 5> output { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f };
|
||||||
|
copy<float, true>(input, absl::MakeSpan(output));
|
||||||
|
REQUIRE(output == input);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("[Helpers] copy (SIMD vs scalar)")
|
||||||
|
{
|
||||||
|
std::vector<float> input(bigBufferSize);
|
||||||
|
std::vector<float> outputScalar(bigBufferSize);
|
||||||
|
std::vector<float> outputSIMD(bigBufferSize);
|
||||||
|
absl::c_iota(input, 0.0);
|
||||||
|
absl::c_fill(outputScalar, 0.0);
|
||||||
|
absl::c_fill(outputSIMD, 0.0);
|
||||||
|
|
||||||
|
add<float, false>(input, absl::MakeSpan(outputScalar));
|
||||||
|
add<float, true>(input, absl::MakeSpan(outputSIMD));
|
||||||
|
REQUIRE(approxEqual<float>(outputScalar, outputSIMD));
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue