diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ad937d5..3e0fecf5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -142,10 +142,6 @@ target_link_libraries(sfizz_tests Catch2::Catch2 absl::strings absl::flat_hash_m target_include_directories(sfizz_tests SYSTEM PRIVATE sources) file(COPY "tests" DESTINATION ${CMAKE_BINARY_DIR}) -############################### -add_executable(bench_span benchmarks/Spans.cpp) -target_link_libraries(bench_span benchmark gsl::gsl-lite absl::span) - ############################### add_executable(bench_opf_high_vs_low benchmarks/OPF_high_vs_low.cpp) target_link_libraries(bench_opf_high_vs_low benchmark absl::span) diff --git a/sources/SIMDDummy.cpp b/sources/SIMDDummy.cpp index 59cb624b..14f52424 100644 --- a/sources/SIMDDummy.cpp +++ b/sources/SIMDDummy.cpp @@ -14,19 +14,10 @@ void writeInterleaved(absl::Span inputLeft, absl::Span } // template -// void loopingSFZIndex(absl::Span inputLeft, absl::Span inputRight, absl::Span output); +// void linearRamp(absl::Span output, Type start, Type step); // template -// void linearRamp(absl::Span output, Type start, Type end); - -// template -// void exponentialRamp(absl::Span output, Type start, Type end); - -// template -// void applyGain(Type gain, absl::Span output); - -// template -// void applyGain(absl::Span output, absl::Span output); +// void exponentialRamp(absl::Span output, Type start, Type step); template<> void fill(absl::Span output, float value) noexcept diff --git a/sources/SIMDHelpers.h b/sources/SIMDHelpers.h index b41a3cb0..6e9261da 100644 --- a/sources/SIMDHelpers.h +++ b/sources/SIMDHelpers.h @@ -1,8 +1,16 @@ #include "Globals.h" #include +#include #include "Helpers.h" #include +template +inline void snippetRead(const T*& input, T*& outputLeft, T*& outputRight) +{ + *outputLeft++ = *input++; + *outputRight++ = *input++; +} + template void readInterleaved(absl::Span input, absl::Span outputLeft, absl::Span outputRight) noexcept { @@ -14,10 +22,14 @@ void readInterleaved(absl::Span input, absl::Span outputLeft, absl:: auto* lOut = outputLeft.begin(); auto* rOut = outputRight.begin(); while (in < (input.end() - 1) && lOut < outputLeft.end() && rOut < outputRight.end()) - { - *lOut++ = *in++; - *rOut++ = *in++; - } + snippetRead(in, lOut, rOut); +} + +template +inline void snippetWrite(T*& output, const T*& inputLeft, const T*& inputRight) +{ + *output++ = *inputLeft++; + *output++ = *inputRight++; } template @@ -30,10 +42,7 @@ void writeInterleaved(absl::Span inputLeft, absl::Span inputRi auto* rIn = inputRight.begin(); auto* out = output.begin(); while (lIn < inputLeft.end() && rIn < inputRight.end() && out < (output.end() - 1)) - { - *out++ = *lIn++; - *out++ = *rIn++; - } + snippetWrite(out, lIn, rIn); } // Specializations @@ -45,7 +54,7 @@ void readInterleaved(absl::Span input, absl::Span void fill(absl::Span output, T value) noexcept { - std::fill(output.begin(), output.end(), value); + absl::c_fill(output, value); } template<> @@ -99,6 +108,21 @@ void cos(absl::Span input, absl::Span output) noexcept template<> void cos(absl::Span input, absl::Span output) noexcept; +template +inline void snippetLoopingIndex(const T*& jump, T*& leftCoeff, T*& rightCoeff, int*& index, T& floatIndex, T loopEnd, T loopStart) +{ + floatIndex += *jump; + if (floatIndex >= loopEnd) + floatIndex -= loopEnd - loopStart; + *index = static_cast(floatIndex); + *rightCoeff = floatIndex - *index; + *leftCoeff = 1.0f - *rightCoeff; + index++; + leftCoeff++; + rightCoeff++; + jump++; +} + template void loopingSFZIndex(absl::Span jumps, absl::Span leftCoeffs, absl::Span rightCoeffs, absl::Span indices, T floatIndex, T loopEnd, T loopStart) noexcept { @@ -114,18 +138,7 @@ void loopingSFZIndex(absl::Span jumps, absl::Span leftCoeffs, absl:: auto* sentinel = jumps.begin() + size; while (jump < sentinel) - { - floatIndex += *jump; - if (floatIndex >= loopEnd) - floatIndex -= loopEnd - loopStart; - *index = static_cast(floatIndex); - *rightCoeff = floatIndex - *index; - *leftCoeff = 1.0f - *rightCoeff; - index++; - leftCoeff++; - rightCoeff++; - jump++; - } + snippetLoopingIndex(jump, leftCoeff, rightCoeff, index, floatIndex, loopEnd, loopStart); } template<> @@ -137,6 +150,12 @@ void linearRamp(absl::Span output, T start, T end); template void exponentialRamp(absl::Span output, T start, T end); +template +inline void snippetGain(T gain, const T*& input, T*& output) +{ + *output++ = gain * (*input++); +} + template void applyGain(T gain, absl::Span input, absl::Span output) noexcept { @@ -145,9 +164,13 @@ void applyGain(T gain, absl::Span input, absl::Span output) noexcept auto* out = output.begin(); auto* sentinel = out + std::min(output.size(), input.size()); while (out < sentinel) - { - *out++ = gain * (*in++); - } + snippetGain(gain, in, out); +} + +template +inline void snippetGainSpan(const T*& gain, const T*& input, T*& output) +{ + *output++ = (*gain++) * (*input++); } template @@ -160,9 +183,7 @@ void applyGain(absl::Span gain, absl::Span input, absl::Span(g, in, out); } template diff --git a/sources/SIMDSSE.cpp b/sources/SIMDSSE.cpp index 806496d8..1c616742 100644 --- a/sources/SIMDSSE.cpp +++ b/sources/SIMDSSE.cpp @@ -59,10 +59,7 @@ void readInterleaved(absl::Span input, absl::Span(in, lOut, rOut); while (in < lastAligned ) { @@ -83,10 +80,7 @@ void readInterleaved(absl::Span input, absl::Span(in, lOut, rOut); } template<> @@ -104,10 +98,7 @@ void writeInterleaved(absl::Span inputLeft, absl::Span const auto* lastAligned = prevAligned(output.begin() + size - TypeAlignment); while (unaligned(out, rIn, lIn) && out < lastAligned) - { - *out++ = *lIn++; - *out++ = *rIn++; - } + snippetWrite(out, lIn, rIn); while (out < lastAligned) { @@ -127,10 +118,7 @@ void writeInterleaved(absl::Span inputLeft, absl::Span } while (out < output.end() - 1) - { - *out++ = *lIn++; - *out++ = *rIn++; - } + snippetWrite(out, lIn, rIn); } @@ -247,7 +235,7 @@ void applyGain(absl::Span gain, absl::Span(g, in, out); while (out < lastAligned) { @@ -258,7 +246,7 @@ void applyGain(absl::Span gain, absl::Span(g, in, out); } template<> @@ -277,18 +265,7 @@ void loopingSFZIndex(absl::Span jumps, absl::Span(index), leftCoeff, rightCoeff, jump) && jump < alignedEnd) - { - floatIndex += *jump; - if (floatIndex >= loopEnd) - floatIndex -= loopEnd - loopStart; - *index = static_cast(floatIndex); - *rightCoeff = floatIndex - *index; - *leftCoeff = 1.0f - *rightCoeff; - index++; - leftCoeff++; - rightCoeff++; - jump++; - } + snippetLoopingIndex(jump, leftCoeff, rightCoeff, index, floatIndex, loopEnd, loopStart); auto mmFloatIndex = _mm_set_ps1(floatIndex); const auto mmJumpBack = _mm_set1_ps(loopEnd - loopStart); @@ -325,16 +302,5 @@ void loopingSFZIndex(absl::Span jumps, absl::Span= loopEnd) - floatIndex -= loopEnd - loopStart; - *index = static_cast(floatIndex); - *rightCoeff = floatIndex - *index; - *leftCoeff = 1.0f - *rightCoeff; - index++; - leftCoeff++; - rightCoeff++; - jump++; - } + snippetLoopingIndex(jump, leftCoeff, rightCoeff, index, floatIndex, loopEnd, loopStart); } \ No newline at end of file diff --git a/tests/SIMDHelpersT.cpp b/tests/SIMDHelpersT.cpp index a9703189..d0d58171 100644 --- a/tests/SIMDHelpersT.cpp +++ b/tests/SIMDHelpersT.cpp @@ -2,6 +2,7 @@ #include "../sources/SIMDHelpers.h" #include #include +#include #include #include using namespace Catch::literals;