Added another subtract SIMD helper
This commit is contained in:
parent
563e7624d9
commit
a900580a66
3 changed files with 44 additions and 0 deletions
|
|
@ -126,6 +126,13 @@ void subtract<float, true>(absl::Span<const float> input, absl::Span<float> outp
|
|||
subtract<float, false>(input, output);
|
||||
}
|
||||
|
||||
template <>
|
||||
void subtract<float, true>(const float value, absl::Span<float> output) noexcept
|
||||
{
|
||||
subtract<float, false>(value, output);
|
||||
}
|
||||
|
||||
|
||||
template <>
|
||||
void copy<float, true>(absl::Span<const float> input, absl::Span<float> output) noexcept
|
||||
{
|
||||
|
|
|
|||
|
|
@ -374,6 +374,21 @@ inline void snippetSubtract(const T*& input, T*& output)
|
|||
*output++ -= *input++;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void snippetSubtract(const T value, T*& output)
|
||||
{
|
||||
*output++ -= value;
|
||||
}
|
||||
|
||||
template <class T, bool SIMD = SIMDConfig::subtract>
|
||||
void subtract(const T value, absl::Span<T> output) noexcept
|
||||
{
|
||||
auto* out = output.begin();
|
||||
auto* sentinel = output.end();
|
||||
while (out < sentinel)
|
||||
snippetSubtract(value, out);
|
||||
}
|
||||
|
||||
template <class T, bool SIMD = SIMDConfig::subtract>
|
||||
void subtract(absl::Span<const T> input, absl::Span<T> output) noexcept
|
||||
{
|
||||
|
|
@ -388,6 +403,8 @@ void subtract(absl::Span<const T> input, absl::Span<T> output) noexcept
|
|||
template <>
|
||||
void subtract<float, true>(absl::Span<const float> input, absl::Span<float> output) noexcept;
|
||||
|
||||
template <>
|
||||
void subtract<float, true>(const float value, absl::Span<float> output) noexcept;
|
||||
|
||||
template <class T>
|
||||
void snippetCopy(const T*& input, T*& output)
|
||||
|
|
|
|||
|
|
@ -564,6 +564,26 @@ void subtract<float, true>(absl::Span<const float> input, absl::Span<float> outp
|
|||
snippetSubtract<float>(in, out);
|
||||
}
|
||||
|
||||
template <>
|
||||
void subtract<float, true>(const float value, absl::Span<float> output) noexcept
|
||||
{
|
||||
auto* out = output.begin();
|
||||
auto* sentinel = output.end();
|
||||
const auto* lastAligned = prevAligned(sentinel);
|
||||
|
||||
while (unaligned(out) && out < lastAligned)
|
||||
snippetSubtract<float>(value, out);
|
||||
|
||||
auto mmValue = _mm_set_ps1(value);
|
||||
while (out < lastAligned) {
|
||||
_mm_store_ps(out, _mm_sub_ps(_mm_load_ps(out), mmValue));
|
||||
out += TypeAlignment;
|
||||
}
|
||||
|
||||
while (out < sentinel)
|
||||
snippetSubtract<float>(value, out);
|
||||
}
|
||||
|
||||
template <>
|
||||
void copy<float, true>(absl::Span<const float> input, absl::Span<float> output) noexcept
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue