Commit 729da58a3a for aom
commit 729da58a3af9c26f65d98e5cb9a0b3157692f6a7
Author: Lin Zheng <linzhen@google.com>
Date: Wed Nov 25 16:54:40 2026 +0000
Highway: Optimize 1D convolve horiz/vert
Optimize 1D convolve horiz/vert with full-width pairwise MAC.
Up to 8.5% speed-up for libaom speed 0 to 3:
speed 0: 8.5%
speed 1: 3.4%
speed 2: 2.0%
speed 3: 0.1%
Pinned 1-thread microbenchmarks (taskset -c 0, AMD EPYC 7B13, AVX2,
GCC 15.2.0 -O3 -DNDEBUG):
Function │ Base (ns) │ Opt (ns) │ Speedup (x)
─────────────────────────┼───────────┼──────────┼────────────
convolve8_horiz 4x4 │ 16.0 │ 11.9 │ 1.34x
convolve8_vert 4x4 │ 14.8 │ 12.0 │ 1.23x
convolve8_horiz 8x8 │ 22.5 │ 14.1 │ 1.60x
convolve8_vert 8x8 │ 19.9 │ 16.1 │ 1.24x
convolve8_horiz 16x16 │ 63.0 │ 33.4 │ 1.89x
convolve8_vert 16x16 │ 39.0 │ 34.2 │ 1.14x
convolve8_horiz 16x32 │ 114.6 │ 61.3 │ 1.87x
convolve8_vert 16x32 │ 69.9 │ 57.2 │ 1.22x
convolve8_horiz 32x32 │ 132.5 │ 96.3 │ 1.38x
convolve8_vert 32x32 │ 137.4 │ 107.3 │ 1.28x
convolve8_horiz 32x39 │ 271.9 │ 116.1 │ 2.34x
convolve8_vert 32x39 │ 166.5 │ 129.7 │ 1.28x
convolve8_horiz 64x64 │ 782.1 │ 382.1 │ 2.05x
convolve8_vert 64x64 │ 561.3 │ 414.3 │ 1.35x
convolve8_horiz 64x71 │ 907.0 │ 425.8 │ 2.13x
convolve8_vert 64x71 │ 619.9 │ 465.2 │ 1.33x
convolve8_horiz 128x128 │ 3174.5 │ 1484.9 │ 2.14x
convolve8_vert 128x128 │ 2336.8 │ 1962.6 │ 1.19x
Change-Id: Ic2399c60d11dc0b639818407ef4c9cf562407be0
diff --git a/aom_dsp/convolve_hwy.h b/aom_dsp/convolve_hwy.h
index e1c4192650..52d00df039 100644
--- a/aom_dsp/convolve_hwy.h
+++ b/aom_dsp/convolve_hwy.h
@@ -15,17 +15,14 @@
#include "config/aom_config.h"
#include <cassert>
+#include <cstddef>
+#include <cstdint>
+#include <cstring>
+#include <type_traits>
#include "aom_dsp/arm/aom_filter.h"
#include "hwy/highway.h"
-#if HAVE_SSSE3
-extern "C" void aom_convolve8_horiz_ssse3(
- const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst,
- ptrdiff_t dst_stride, const int16_t *filter_x, int x_step_q4,
- const int16_t *filter_y, int y_step_q4, int w, int h);
-#endif
-
HWY_BEFORE_NAMESPACE();
namespace {
@@ -33,1375 +30,1183 @@ namespace HWY_NAMESPACE {
namespace hn = hwy::HWY_NAMESPACE;
-template <typename T16_8, typename T8_16, typename V8_16, typename M,
- typename VC>
-HWY_ATTR HWY_INLINE hn::VFromD<T16_8> ComputeHoriz8TapSum(
- T16_8 tag16_8, T8_16 tag8_16, const V8_16 &d0, const V8_16 &d2,
- const V8_16 &d4, const V8_16 &d6, const M &shuffle_mask, const VC &coeff01,
- const VC &coeff23, const VC &coeff45, const VC &coeff67) {
- (void)tag8_16;
- return hn::Add(
- hn::Add(hn::SatWidenMulPairwiseAdd(
- tag16_8, hn::TableLookupBytes(d0, shuffle_mask), coeff01),
- hn::SatWidenMulPairwiseAdd(
- tag16_8, hn::TableLookupBytes(d2, shuffle_mask), coeff23)),
- hn::Add(hn::SatWidenMulPairwiseAdd(
- tag16_8, hn::TableLookupBytes(d4, shuffle_mask), coeff45),
- hn::SatWidenMulPairwiseAdd(
- tag16_8, hn::TableLookupBytes(d6, shuffle_mask), coeff67)));
-}
-
-template <typename T16_8, typename T8_16, typename V8_16, typename M,
- typename VC>
-HWY_ATTR HWY_INLINE hn::VFromD<T16_8> ComputeHoriz4TapSum(
- T16_8 tag16_8, T8_16 tag8_16, const V8_16 &d0, const V8_16 &d2,
- const M &shuffle_mask, const VC &coeff23, const VC &coeff45) {
- (void)tag8_16;
- return hn::Add(hn::SatWidenMulPairwiseAdd(
- tag16_8, hn::TableLookupBytes(d0, shuffle_mask), coeff23),
- hn::SatWidenMulPairwiseAdd(
- tag16_8, hn::TableLookupBytes(d2, shuffle_mask), coeff45));
+template <typename V, size_t kN>
+HWY_ATTR HWY_INLINE void ShiftLeft1(V (&a)[kN]) {
+ if constexpr (kN >= 2) a[0] = a[1];
+ if constexpr (kN >= 3) a[1] = a[2];
+ if constexpr (kN >= 4) a[2] = a[3];
+ if constexpr (kN >= 5) a[3] = a[4];
+ if constexpr (kN >= 6) a[4] = a[5];
+ if constexpr (kN >= 7) a[5] = a[6];
+ if constexpr (kN >= 8) a[6] = a[7];
}
-template <int chunk_size, typename T8_8, typename T8_4, typename V16_8>
-HWY_ATTR HWY_INLINE void StoreOutputChunk(T8_8 tag8_8, T8_4 tag8_4,
- const V16_8 &sum,
- const V16_8 &bias_val, uint8_t *dst) {
- auto res = hn::ShiftRight<FILTER_BITS - 1>(hn::Add(sum, bias_val));
- if (chunk_size == 4) {
- hn::StoreU(hn::LowerHalf(tag8_4, hn::DemoteTo(tag8_8, res)), tag8_4, dst);
+// Pairwise uint8*int8 fast paths rely on:
+// 1. x86 vpackuswb 128-bit in-lane 8-byte half interleaving in
+// hn::ReorderDemote2To (implementation-defined in Highway; differs on
+// SVE/RVV).
+// 2. >= 256-bit vectors for CappedTag<uint8_t, 32> (and 512-bit for HWY_AVX3).
+#define AOM_CONVOLVE_HWY_X86_PAIRWISE (HWY_ARCH_X86 && HWY_TARGET <= HWY_AVX2)
+
+#if AOM_CONVOLVE_HWY_X86_PAIRWISE
+template <int kTaps>
+HWY_ATTR HWY_INLINE bool AreTapsEven(const int16_t *filter) {
+ if constexpr (kTaps == 2) {
+ return ((filter[3] | filter[4]) & 1) == 0;
+ } else if constexpr (kTaps == 4) {
+ uint64_t v;
+ std::memcpy(&v, filter + 2, sizeof(v));
+ return (v & 0x0001000100010001ULL) == 0;
} else {
- // chunk_size == 8
- hn::StoreU(hn::DemoteTo(tag8_8, res), tag8_8, dst);
+ uint64_t lo, hi;
+ std::memcpy(&lo, filter, sizeof(lo));
+ std::memcpy(&hi, filter + 4, sizeof(hi));
+ return ((lo | hi) & 0x0001000100010001ULL) == 0;
}
}
-template <typename T16_8, typename T8_16, typename M, typename VC>
-HWY_ATTR HWY_INLINE hn::VFromD<T16_8> ComputeChunkSum2Tap(
- T16_8 tag16_8, T8_16 tag8_16, const uint8_t *src, int j,
- const M &shuffle_mask, const VC &coeff) {
- (void)tag8_16;
- auto d0 = hn::LoadU(tag8_16, src + j);
- return hn::SatWidenMulPairwiseAdd(
- tag16_8, hn::TableLookupBytes(d0, shuffle_mask), coeff);
+HWY_ATTR HWY_INLINE int8_t PackHalfTap(int16_t tap) {
+ assert(tap >= -256 && tap <= 254);
+ return static_cast<int8_t>(tap >> 1);
}
-template <typename T16_8, typename T8_16, typename M, typename VC>
-HWY_ATTR HWY_INLINE hn::VFromD<T16_8> ComputeChunkSum4Tap(
- T16_8 tag16_8, T8_16 tag8_16, const uint8_t *src, int j,
- const M &shuffle_mask, const VC &coeff0, const VC &coeff1) {
- auto d0 = hn::LoadU(tag8_16, src + j + 0);
- auto d2 = hn::LoadU(tag8_16, src + j + 2);
- return ComputeHoriz4TapSum(tag16_8, tag8_16, d0, d2, shuffle_mask, coeff0,
- coeff1);
+template <typename D8>
+HWY_ATTR HWY_INLINE hn::VFromD<hn::Repartition<int8_t, D8>> BroadcastPair(
+ D8 /*tag*/, int8_t a, int8_t b) {
+ constexpr hn::Repartition<int8_t, D8> i8_tag;
+ constexpr hn::Repartition<uint16_t, D8> u16_tag;
+ const uint16_t pair = static_cast<uint16_t>(
+ static_cast<uint8_t>(a) |
+ (static_cast<uint16_t>(static_cast<uint8_t>(b)) << 8));
+ return hn::BitCast(i8_tag, hn::Set(u16_tag, pair));
}
-template <typename T16_8, typename T8_16, typename M, typename VC>
-HWY_ATTR HWY_INLINE hn::VFromD<T16_8> ComputeChunkSum8Tap(
- T16_8 tag16_8, T8_16 tag8_16, const uint8_t *src, int j,
- const M &shuffle_mask, const VC &coeff0, const VC &coeff1, const VC &coeff2,
- const VC &coeff3) {
- auto d0 = hn::LoadU(tag8_16, src + j + 0);
- auto d2 = hn::LoadU(tag8_16, src + j + 2);
- auto d4 = hn::LoadU(tag8_16, src + j + 4);
- auto d6 = hn::LoadU(tag8_16, src + j + 6);
- return ComputeHoriz8TapSum(tag16_8, tag8_16, d0, d2, d4, d6, shuffle_mask,
- coeff0, coeff1, coeff2, coeff3);
-}
-
-template <int chunk_size, typename T8_8, typename T8_4, typename V16_8,
- typename SumComputer>
-HWY_ATTR HWY_INLINE void Process2RowsChunk(T8_8 tag8_8, T8_4 tag8_4,
- const uint8_t *src,
- ptrdiff_t src_stride, uint8_t *dst,
- ptrdiff_t dst_stride, int j,
- const V16_8 &bias_val,
- SumComputer sum_computer) {
- auto r0_sum = sum_computer(src, j);
- auto r1_sum = sum_computer(src + src_stride, j);
- StoreOutputChunk<chunk_size>(tag8_8, tag8_4, r0_sum, bias_val, dst + j);
- StoreOutputChunk<chunk_size>(tag8_8, tag8_4, r1_sum, bias_val,
- dst + dst_stride + j);
-}
-
-template <int chunk_size, typename T8_8, typename T8_4, typename V16_8,
- typename SumComputer>
-HWY_ATTR HWY_INLINE void Process1RowChunk(T8_8 tag8_8, T8_4 tag8_4,
- const uint8_t *src, uint8_t *dst,
- int j, const V16_8 &bias_val,
- SumComputer sum_computer) {
- auto r0_sum = sum_computer(src, j);
- StoreOutputChunk<chunk_size>(tag8_8, tag8_4, r0_sum, bias_val, dst + j);
-}
+template <int kTaps, typename D8>
+struct HorizFilter;
+
+template <typename D8>
+struct HorizFilter<2, D8> {
+ using D16 = hn::Repartition<int16_t, D8>;
+ using DI8 = hn::Repartition<int8_t, D8>;
+ hn::VFromD<D8> shuf01;
+ hn::VFromD<DI8> coeff01;
+ hn::VFromD<D16> round_vec;
+
+ HWY_ATTR HWY_INLINE explicit HorizFilter(const int16_t *filter_x) {
+ constexpr D8 u8_tag;
+ constexpr D16 i16_tag;
+ shuf01 = hn::Dup128VecFromValues(u8_tag, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6,
+ 6, 7, 7, 8);
+ coeff01 = BroadcastPair(u8_tag, PackHalfTap(filter_x[3]),
+ PackHalfTap(filter_x[4]));
+ round_vec = hn::Set(i16_tag, 1 << (FILTER_BITS - 2));
+ }
-template <typename D>
-HWY_ATTR HWY_INLINE hn::VFromD<D> LoadUnaligned4x4(D tag16, const uint8_t *buf,
- ptrdiff_t stride) {
- hn::CappedTag<uint32_t, 4> tag32;
- uint32_t r0, r1, r2, r3;
- memcpy(&r0, buf, 4);
- memcpy(&r1, buf + stride, 4);
- memcpy(&r2, buf + 2 * stride, 4);
- memcpy(&r3, buf + 3 * stride, 4);
- auto v32 = hn::Zero(tag32);
- v32 = hn::InsertLane(v32, 0, r0);
- v32 = hn::InsertLane(v32, 1, r1);
- v32 = hn::InsertLane(v32, 2, r2);
- v32 = hn::InsertLane(v32, 3, r3);
- hn::Rebind<uint8_t, D> tag8;
- return hn::PromoteTo(tag16, hn::BitCast(tag8, v32));
-}
+ HWY_ATTR HWY_INLINE hn::VFromD<D16> Apply(hn::VFromD<D8> v) const {
+ constexpr D16 i16_tag;
+ const auto s01 = hn::SatWidenMulPairwiseAdd(
+ i16_tag, hn::TableLookupBytes(v, shuf01), coeff01);
+ return hn::ShiftRight<FILTER_BITS - 1>(hn::SaturatedAdd(s01, round_vec));
+ }
+};
+
+template <typename D8>
+struct HorizFilter<4, D8> {
+ using D16 = hn::Repartition<int16_t, D8>;
+ using DI8 = hn::Repartition<int8_t, D8>;
+ hn::VFromD<D8> shuf01, shuf23;
+ hn::VFromD<DI8> coeff01, coeff23;
+ hn::VFromD<D16> round_vec;
+
+ HWY_ATTR HWY_INLINE explicit HorizFilter(const int16_t *filter_x) {
+ constexpr D8 u8_tag;
+ constexpr D16 i16_tag;
+ shuf01 = hn::Dup128VecFromValues(u8_tag, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6,
+ 6, 7, 7, 8);
+ shuf23 = hn::Dup128VecFromValues(u8_tag, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8,
+ 8, 9, 9, 10);
+ coeff01 = BroadcastPair(u8_tag, PackHalfTap(filter_x[2]),
+ PackHalfTap(filter_x[3]));
+ coeff23 = BroadcastPair(u8_tag, PackHalfTap(filter_x[4]),
+ PackHalfTap(filter_x[5]));
+ round_vec = hn::Set(i16_tag, 1 << (FILTER_BITS - 2));
+ }
-template <typename D>
-HWY_ATTR HWY_INLINE void StoreUnaligned4x4(D tag16, uint8_t *buf,
- ptrdiff_t stride,
- hn::VFromD<D> &vec) {
- (void)tag16;
- hn::Rebind<uint8_t, D> tag8;
- constexpr hn::Half<D> half_tag16;
- auto vec_demoted = hn::ReorderDemote2To(tag8, hn::LowerHalf(half_tag16, vec),
- hn::UpperHalf(half_tag16, vec));
- constexpr hn::Half<decltype(tag8)> half_tag;
- constexpr hn::Half<decltype(half_tag)> quarter_tag;
- auto vec1_2 = hn::LowerHalf(half_tag, vec_demoted);
- auto vec2_2 = hn::UpperHalf(half_tag, vec_demoted);
- auto vec1_4 = hn::LowerHalf(quarter_tag, vec1_2);
- auto vec2_4 = hn::UpperHalf(quarter_tag, vec1_2);
- auto vec3_4 = hn::LowerHalf(quarter_tag, vec2_2);
- auto vec4_4 = hn::UpperHalf(quarter_tag, vec2_2);
- hn::StoreU(vec1_4, quarter_tag, buf);
- hn::StoreU(vec2_4, quarter_tag, buf + stride);
- hn::StoreU(vec3_4, quarter_tag, buf + 2 * stride);
- hn::StoreU(vec4_4, quarter_tag, buf + 3 * stride);
-}
+ HWY_ATTR HWY_INLINE hn::VFromD<D16> Apply(hn::VFromD<D8> v) const {
+ constexpr D16 i16_tag;
+ const auto s01 = hn::SatWidenMulPairwiseAdd(
+ i16_tag, hn::TableLookupBytes(v, shuf01), coeff01);
+ const auto s23 = hn::SatWidenMulPairwiseAdd(
+ i16_tag, hn::TableLookupBytes(v, shuf23), coeff23);
+ const auto sum = hn::SaturatedAdd(s01, s23);
+ return hn::ShiftRight<FILTER_BITS - 1>(hn::SaturatedAdd(sum, round_vec));
+ }
+};
+
+template <typename D8>
+struct HorizFilter<8, D8> {
+ using D16 = hn::Repartition<int16_t, D8>;
+ using DI8 = hn::Repartition<int8_t, D8>;
+ hn::VFromD<D8> shuf01, shuf23, shuf45, shuf67;
+ hn::VFromD<DI8> coeff01, coeff23, coeff45, coeff67;
+ hn::VFromD<D16> round_vec;
+
+ HWY_ATTR HWY_INLINE explicit HorizFilter(const int16_t *filter_x) {
+ constexpr D8 u8_tag;
+ constexpr D16 i16_tag;
+ shuf01 = hn::Dup128VecFromValues(u8_tag, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6,
+ 6, 7, 7, 8);
+ shuf23 = hn::Dup128VecFromValues(u8_tag, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8,
+ 8, 9, 9, 10);
+ shuf45 = hn::Dup128VecFromValues(u8_tag, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,
+ 10, 10, 11, 11, 12);
+ shuf67 = hn::Dup128VecFromValues(u8_tag, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11,
+ 11, 12, 12, 13, 13, 14);
+ coeff01 = BroadcastPair(u8_tag, PackHalfTap(filter_x[0]),
+ PackHalfTap(filter_x[1]));
+ coeff23 = BroadcastPair(u8_tag, PackHalfTap(filter_x[2]),
+ PackHalfTap(filter_x[3]));
+ coeff45 = BroadcastPair(u8_tag, PackHalfTap(filter_x[4]),
+ PackHalfTap(filter_x[5]));
+ coeff67 = BroadcastPair(u8_tag, PackHalfTap(filter_x[6]),
+ PackHalfTap(filter_x[7]));
+ round_vec = hn::Set(i16_tag, 1 << (FILTER_BITS - 2));
+ }
-template <typename D>
-HWY_ATTR HWY_INLINE hn::VFromD<D> LoadUnaligned2x8(D tag16, const uint8_t *buf,
- ptrdiff_t stride) {
- hn::Rebind<uint8_t, D> tag8;
- constexpr hn::Half<decltype(tag8)> half_tag8;
- auto first_half = hn::LoadU(half_tag8, buf);
- auto second_half = hn::LoadU(half_tag8, buf + stride);
- return hn::PromoteTo(tag16, hn::Combine(tag8, first_half, second_half));
+ HWY_ATTR HWY_INLINE hn::VFromD<D16> Apply(hn::VFromD<D8> v) const {
+ constexpr D16 i16_tag;
+ const auto s01 = hn::SatWidenMulPairwiseAdd(
+ i16_tag, hn::TableLookupBytes(v, shuf01), coeff01);
+ const auto s67 = hn::SatWidenMulPairwiseAdd(
+ i16_tag, hn::TableLookupBytes(v, shuf67), coeff67);
+ const auto s23 = hn::SatWidenMulPairwiseAdd(
+ i16_tag, hn::TableLookupBytes(v, shuf23), coeff23);
+ const auto s45 = hn::SatWidenMulPairwiseAdd(
+ i16_tag, hn::TableLookupBytes(v, shuf45), coeff45);
+ const auto sum = hn::SaturatedAdd(hn::SaturatedAdd(s01, s67),
+ hn::SaturatedAdd(s23, s45));
+ return hn::ShiftRight<FILTER_BITS - 1>(hn::SaturatedAdd(sum, round_vec));
+ }
+};
+
+template <int kW>
+HWY_ATTR HWY_INLINE void StoreSmallRow(
+ hn::VFromD<hn::CappedTag<uint8_t, 16>> row, uint8_t *dst) {
+ constexpr hn::CappedTag<uint8_t, 8> u8_8;
+ constexpr hn::CappedTag<uint8_t, 4> u8_4;
+ if constexpr (kW == 4) {
+ hn::StoreU(hn::LowerHalf(u8_4, hn::LowerHalf(u8_8, row)), u8_4, dst);
+ } else {
+ hn::StoreU(hn::LowerHalf(u8_8, row), u8_8, dst);
+ }
}
-template <typename D>
-HWY_ATTR HWY_INLINE void StoreUnaligned2x8(D tag, uint8_t *buf,
- ptrdiff_t stride,
- hn::VFromD<D> &vec) {
- (void)tag;
- hn::Rebind<uint8_t, D> tag8;
- constexpr hn::Half<D> half_tag16;
- auto vec_demoted = hn::ReorderDemote2To(tag8, hn::LowerHalf(half_tag16, vec),
- hn::UpperHalf(half_tag16, vec));
- constexpr hn::Half<decltype(tag8)> half_tag8;
- auto vec1_2 = hn::UpperHalf(half_tag8, vec_demoted);
- auto vec2_2 = hn::LowerHalf(half_tag8, vec_demoted);
- hn::StoreU(vec1_2, half_tag8, buf);
- hn::StoreU(vec2_2, half_tag8, buf + stride);
-}
+template <int kTaps, int kW>
+HWY_ATTR HWY_INLINE void ConvolveHorizEvenSmall(
+ const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst,
+ ptrdiff_t dst_stride, const int16_t *filter_x, int h) {
+ constexpr hn::CappedTag<uint8_t, 16> u8_16;
+ constexpr hn::CappedTag<uint8_t, 32> u8_32;
+
+#if HWY_TARGET <= HWY_AVX3
+ if (h >= 4) {
+ constexpr hn::CappedTag<uint8_t, 64> u8_64;
+ const HorizFilter<kTaps, hn::CappedTag<uint8_t, 64>> filt64(filter_x);
+ while (h >= 4) {
+ const auto r0 = hn::LoadU(u8_16, src);
+ const auto r1 = hn::LoadU(u8_16, src + src_stride);
+ const auto r2 = hn::LoadU(u8_16, src + 2 * src_stride);
+ const auto r3 = hn::LoadU(u8_16, src + 3 * src_stride);
+ const auto v = hn::Combine(u8_64, hn::Combine(u8_32, r3, r2),
+ hn::Combine(u8_32, r1, r0));
+ const auto res = filt64.Apply(v);
+ const auto packed = hn::ReorderDemote2To(u8_64, res, res);
+ const auto lo32 = hn::LowerHalf(u8_32, packed);
+ const auto hi32 = hn::UpperHalf(u8_32, packed);
+ StoreSmallRow<kW>(hn::LowerHalf(u8_16, lo32), dst);
+ StoreSmallRow<kW>(hn::UpperHalf(u8_16, lo32), dst + dst_stride);
+ StoreSmallRow<kW>(hn::LowerHalf(u8_16, hi32), dst + 2 * dst_stride);
+ StoreSmallRow<kW>(hn::UpperHalf(u8_16, hi32), dst + 3 * dst_stride);
+ src += 4 * src_stride;
+ dst += 4 * dst_stride;
+ h -= 4;
+ }
+ }
+#endif
-template <typename D>
-HWY_ATTR HWY_INLINE hn::VFromD<D> LoadUnaligned4x8(D scalable_tag,
- const uint8_t *buf,
- ptrdiff_t stride) {
- hn::Rebind<uint8_t, D> tag8;
- constexpr hn::Half<decltype(tag8)> half_tag8;
- constexpr hn::Half<decltype(half_tag8)> quarter_tag8;
- auto first_quarter = hn::LoadU(quarter_tag8, buf);
- auto second_quarter = hn::LoadU(quarter_tag8, buf + stride);
- auto third_quarter = hn::LoadU(quarter_tag8, buf + 2 * stride);
- auto fourth_quarter = hn::LoadU(quarter_tag8, buf + 3 * stride);
- return hn::PromoteTo(
- scalable_tag,
- hn::Combine(tag8, hn::Combine(half_tag8, first_quarter, second_quarter),
- hn::Combine(half_tag8, third_quarter, fourth_quarter)));
-}
+ if (h >= 2) {
+ const HorizFilter<kTaps, hn::CappedTag<uint8_t, 32>> filt32(filter_x);
+ while (h >= 2) {
+ const auto r0 = hn::LoadU(u8_16, src);
+ const auto r1 = hn::LoadU(u8_16, src + src_stride);
+ const auto v = hn::Combine(u8_32, r1, r0);
+ const auto res = filt32.Apply(v);
+ const auto packed = hn::ReorderDemote2To(u8_32, res, res);
+ StoreSmallRow<kW>(hn::LowerHalf(u8_16, packed), dst);
+ StoreSmallRow<kW>(hn::UpperHalf(u8_16, packed), dst + dst_stride);
+ src += 2 * src_stride;
+ dst += 2 * dst_stride;
+ h -= 2;
+ }
+ }
-template <typename D>
-HWY_ATTR HWY_INLINE void StoreUnaligned4x8(D tag, uint8_t *buf,
- ptrdiff_t stride,
- hn::VFromD<D> &vec) {
- (void)tag;
- hn::Rebind<uint8_t, D> tag8;
- constexpr hn::Half<D> half_tag16;
- auto vec_demoted = hn::ReorderDemote2To(tag8, hn::LowerHalf(half_tag16, vec),
- hn::UpperHalf(half_tag16, vec));
- constexpr hn::Half<decltype(tag8)> half_tag8;
- constexpr hn::Half<decltype(half_tag8)> quarter_tag8;
- auto vec1_2 = hn::UpperHalf(half_tag8, vec_demoted);
- auto vec2_2 = hn::LowerHalf(half_tag8, vec_demoted);
- auto vec1_4 = hn::UpperHalf(quarter_tag8, vec1_2);
- auto vec2_4 = hn::LowerHalf(quarter_tag8, vec1_2);
- auto vec3_4 = hn::UpperHalf(quarter_tag8, vec2_2);
- auto vec4_4 = hn::LowerHalf(quarter_tag8, vec2_2);
- hn::StoreU(vec1_4, quarter_tag8, buf);
- hn::StoreU(vec2_4, quarter_tag8, buf + stride);
- hn::StoreU(vec3_4, quarter_tag8, buf + 2 * stride);
- hn::StoreU(vec4_4, quarter_tag8, buf + 3 * stride);
+ if (h & 1) {
+ const HorizFilter<kTaps, hn::CappedTag<uint8_t, 16>> filt16(filter_x);
+ const auto v = hn::LoadU(u8_16, src);
+ const auto res = filt16.Apply(v);
+ const auto packed = hn::ReorderDemote2To(u8_16, res, res);
+ StoreSmallRow<kW>(packed, dst);
+ }
}
-HWY_ATTR inline void ConvolveHoriz2Tap(const uint8_t *src, ptrdiff_t src_stride,
- uint8_t *dst, ptrdiff_t dst_stride,
- const int16_t *filter_x, int w, int h) {
- const bool can_use_pareto_optimal_2tap =
- (h == 32 && (w == 16 || w == 32 || w == 64)) && (filter_x[3] % 2 == 0) &&
- (filter_x[4] % 2 == 0);
-
- if (can_use_pareto_optimal_2tap) {
- if (w == 16) {
- constexpr hn::CappedTag<uint8_t, 16> u8_16_tag;
- constexpr hn::CappedTag<int8_t, 16> i8_16_tag;
- constexpr hn::CappedTag<int16_t, 8> i16_8_tag;
-
- const auto shuf34_16 = hn::Dup128VecFromValues(
- u8_16_tag, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8);
-
- const int8_t c3 = static_cast<int8_t>(filter_x[3] / 2);
- const int8_t c4 = static_cast<int8_t>(filter_x[4] / 2);
-
- const auto coeff34_16 =
- hn::Dup128VecFromValues(i8_16_tag, c3, c4, c3, c4, c3, c4, c3, c4, c3,
- c4, c3, c4, c3, c4, c3, c4);
-
- const auto round_vec_16 = hn::Set(i16_8_tag, 1 << (FILTER_BITS - 2));
-
- for (int y = 0; y < h; ++y) {
- const uint8_t *src_row = src + y * src_stride;
- uint8_t *dst_row = dst + y * dst_stride;
-
- auto v0 = hn::LoadU(u8_16_tag, src_row + 0);
- auto v8 = hn::LoadU(u8_16_tag, src_row + 8);
-
- auto p34_0 = hn::TableLookupBytes(v0, shuf34_16);
- auto res0 = hn::ShiftRightSame(
- hn::Add(hn::SatWidenMulPairwiseAdd(i16_8_tag, p34_0, coeff34_16),
- round_vec_16),
- FILTER_BITS - 1);
-
- auto p34_8 = hn::TableLookupBytes(v8, shuf34_16);
- auto res8 = hn::ShiftRightSame(
- hn::Add(hn::SatWidenMulPairwiseAdd(i16_8_tag, p34_8, coeff34_16),
- round_vec_16),
- FILTER_BITS - 1);
+// Requires readable right-border padding beyond src + w (for w == 4,
+// LoadU(u8_16, src) reads up to src[w + 11], i.e., up to 9/11/12 bytes past
+// unshifted src + w for 8/4/2-tap; satisfied by YV12_BUFFER_CONFIG padding).
+template <int kTaps>
+HWY_ATTR HWY_INLINE void ConvolveHorizEven(const uint8_t *src,
+ ptrdiff_t src_stride, uint8_t *dst,
+ ptrdiff_t dst_stride,
+ const int16_t *filter_x, int w,
+ int h) {
+ constexpr hn::CappedTag<uint8_t, 16> u8_16;
+ constexpr hn::CappedTag<uint8_t, 32> u8_32;
- auto packed = hn::ReorderDemote2To(u8_16_tag, res0, res8);
- hn::StoreU(packed, u8_16_tag, dst_row);
- }
- } else {
- constexpr hn::CappedTag<uint8_t, 16> u8_16_tag;
- constexpr hn::CappedTag<uint8_t, 32> u8_32_tag;
- constexpr hn::CappedTag<int8_t, 16> i8_16_tag;
- constexpr hn::CappedTag<int8_t, 32> i8_32_tag;
- constexpr hn::CappedTag<int16_t, 16> i16_16_tag;
-
- const auto shuf34_16 = hn::Dup128VecFromValues(
- u8_16_tag, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8);
- const auto shuf34_32 = hn::Combine(u8_32_tag, shuf34_16, shuf34_16);
-
- const int8_t c3 = static_cast<int8_t>(filter_x[3] / 2);
- const int8_t c4 = static_cast<int8_t>(filter_x[4] / 2);
-
- const auto coeff34_16 =
- hn::Dup128VecFromValues(i8_16_tag, c3, c4, c3, c4, c3, c4, c3, c4, c3,
- c4, c3, c4, c3, c4, c3, c4);
- const auto coeff34_32 = hn::Combine(i8_32_tag, coeff34_16, coeff34_16);
-
- const auto round_vec_32 = hn::Set(i16_16_tag, 1 << (FILTER_BITS - 2));
-
- for (int y = 0; y < h; ++y) {
- const uint8_t *src_row = src + y * src_stride;
- uint8_t *dst_row = dst + y * dst_stride;
-
- for (int j = 0; j < w; j += 32) {
- auto v_curr = hn::LoadU(u8_32_tag, src_row + j + 0);
- auto v8 = hn::LoadU(u8_32_tag, src_row + j + 8);
-
- auto p34_0 = hn::TableLookupBytes(v_curr, shuf34_32);
- auto res0 = hn::ShiftRightSame(
- hn::Add(hn::SatWidenMulPairwiseAdd(i16_16_tag, p34_0, coeff34_32),
- round_vec_32),
- FILTER_BITS - 1);
-
- auto p34_8 = hn::TableLookupBytes(v8, shuf34_32);
- auto res8 = hn::ShiftRightSame(
- hn::Add(hn::SatWidenMulPairwiseAdd(i16_16_tag, p34_8, coeff34_32),
- round_vec_32),
- FILTER_BITS - 1);
-
- constexpr hn::CappedTag<uint8_t, 8> u8_8_tag;
- auto demoted0 = hn::DemoteTo(u8_16_tag, res0);
- auto demoted8 = hn::DemoteTo(u8_16_tag, res8);
- auto p0_15 = hn::Combine(u8_16_tag, hn::LowerHalf(u8_8_tag, demoted8),
- hn::LowerHalf(u8_8_tag, demoted0));
- auto p16_31 =
- hn::Combine(u8_16_tag, hn::UpperHalf(u8_8_tag, demoted8),
- hn::UpperHalf(u8_8_tag, demoted0));
- hn::StoreU(p0_15, u8_16_tag, dst_row + j);
- hn::StoreU(p16_31, u8_16_tag, dst_row + j + 16);
- }
- }
- }
+ if (w == 4) {
+ ConvolveHorizEvenSmall<kTaps, 4>(src, src_stride, dst, dst_stride, filter_x,
+ h);
return;
}
-
- const bool can_use_optimized_path =
- (w <= 32) && (filter_x[3] % 2 == 0) && (filter_x[4] % 2 == 0);
-
- if (can_use_optimized_path) {
- hn::CappedTag<uint8_t, 16> tag8_16;
- hn::CappedTag<int8_t, 16> tag_i8;
- hn::CappedTag<int16_t, 8> tag16_8;
- hn::CappedTag<uint8_t, 8> tag8_8;
- hn::CappedTag<uint8_t, 4> tag8_4;
- const auto bias_val = hn::Set(tag16_8, 1 << (FILTER_BITS - 2));
-
- const auto shuffle_mask = hn::Dup128VecFromValues(
- tag8_16, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8);
-
- const int8_t c3 = static_cast<int8_t>(filter_x[3] / 2);
- const int8_t c4 = static_cast<int8_t>(filter_x[4] / 2);
-
- const auto coeff34 = hn::Dup128VecFromValues(
- tag_i8, c3, c4, c3, c4, c3, c4, c3, c4, c3, c4, c3, c4, c3, c4, c3, c4);
-
- auto sum_2tap = [&](const uint8_t *s, int offset) {
- return ComputeChunkSum2Tap(tag16_8, tag8_16, s, offset, shuffle_mask,
- coeff34);
- };
-
- if (w == 4) {
- while (h >= 2) {
- Process2RowsChunk<4>(tag8_8, tag8_4, src, src_stride, dst, dst_stride,
- 0, bias_val, sum_2tap);
- src += 2 * src_stride;
- dst += 2 * dst_stride;
- h -= 2;
- }
- if (h & 1) {
- Process1RowChunk<4>(tag8_8, tag8_4, src, dst, 0, bias_val, sum_2tap);
- }
- } else if (w == 8) {
- while (h >= 2) {
- Process2RowsChunk<8>(tag8_8, tag8_4, src, src_stride, dst, dst_stride,
- 0, bias_val, sum_2tap);
- src += 2 * src_stride;
- dst += 2 * dst_stride;
- h -= 2;
- }
- if (h & 1) {
- Process1RowChunk<8>(tag8_8, tag8_4, src, dst, 0, bias_val, sum_2tap);
- }
- } else if (w == 16) {
- while (h >= 2) {
- Process2RowsChunk<8>(tag8_8, tag8_4, src, src_stride, dst, dst_stride,
- 0, bias_val, sum_2tap);
- Process2RowsChunk<8>(tag8_8, tag8_4, src, src_stride, dst, dst_stride,
- 8, bias_val, sum_2tap);
- src += 2 * src_stride;
- dst += 2 * dst_stride;
- h -= 2;
- }
- if (h & 1) {
- Process1RowChunk<8>(tag8_8, tag8_4, src, dst, 0, bias_val, sum_2tap);
- Process1RowChunk<8>(tag8_8, tag8_4, src, dst, 8, bias_val, sum_2tap);
+ if (w == 8) {
+ ConvolveHorizEvenSmall<kTaps, 8>(src, src_stride, dst, dst_stride, filter_x,
+ h);
+ return;
+ }
+ if (w == 16) {
+#if HWY_TARGET <= HWY_AVX3
+ if (h >= 4) {
+ constexpr hn::CappedTag<uint8_t, 64> u8_64;
+ const HorizFilter<kTaps, hn::CappedTag<uint8_t, 64>> filt64(filter_x);
+ while (h >= 4) {
+ const auto v0 = hn::Combine(
+ u8_64,
+ hn::Combine(u8_32, hn::LoadU(u8_16, src + 3 * src_stride),
+ hn::LoadU(u8_16, src + 2 * src_stride)),
+ hn::Combine(u8_32, hn::LoadU(u8_16, src + src_stride),
+ hn::LoadU(u8_16, src)));
+ const auto v8 = hn::Combine(
+ u8_64,
+ hn::Combine(u8_32, hn::LoadU(u8_16, src + 3 * src_stride + 8),
+ hn::LoadU(u8_16, src + 2 * src_stride + 8)),
+ hn::Combine(u8_32, hn::LoadU(u8_16, src + src_stride + 8),
+ hn::LoadU(u8_16, src + 8)));
+ const auto packed =
+ hn::ReorderDemote2To(u8_64, filt64.Apply(v0), filt64.Apply(v8));
+ const auto lo32 = hn::LowerHalf(u8_32, packed);
+ const auto hi32 = hn::UpperHalf(u8_32, packed);
+ hn::StoreU(hn::LowerHalf(u8_16, lo32), u8_16, dst);
+ hn::StoreU(hn::UpperHalf(u8_16, lo32), u8_16, dst + dst_stride);
+ hn::StoreU(hn::LowerHalf(u8_16, hi32), u8_16, dst + 2 * dst_stride);
+ hn::StoreU(hn::UpperHalf(u8_16, hi32), u8_16, dst + 3 * dst_stride);
+ src += 4 * src_stride;
+ dst += 4 * dst_stride;
+ h -= 4;
}
- } else if (w == 32) {
+ }
+#endif
+ if (h >= 2) {
+ const HorizFilter<kTaps, hn::CappedTag<uint8_t, 32>> filt32(filter_x);
while (h >= 2) {
- Process2RowsChunk<8>(tag8_8, tag8_4, src, src_stride, dst, dst_stride,
- 0, bias_val, sum_2tap);
- Process2RowsChunk<8>(tag8_8, tag8_4, src, src_stride, dst, dst_stride,
- 8, bias_val, sum_2tap);
- Process2RowsChunk<8>(tag8_8, tag8_4, src, src_stride, dst, dst_stride,
- 16, bias_val, sum_2tap);
- Process2RowsChunk<8>(tag8_8, tag8_4, src, src_stride, dst, dst_stride,
- 24, bias_val, sum_2tap);
+ const auto v0 = hn::Combine(u8_32, hn::LoadU(u8_16, src + src_stride),
+ hn::LoadU(u8_16, src));
+ const auto v8 =
+ hn::Combine(u8_32, hn::LoadU(u8_16, src + src_stride + 8),
+ hn::LoadU(u8_16, src + 8));
+ const auto packed =
+ hn::ReorderDemote2To(u8_32, filt32.Apply(v0), filt32.Apply(v8));
+ hn::StoreU(hn::LowerHalf(u8_16, packed), u8_16, dst);
+ hn::StoreU(hn::UpperHalf(u8_16, packed), u8_16, dst + dst_stride);
src += 2 * src_stride;
dst += 2 * dst_stride;
h -= 2;
}
- if (h & 1) {
- for (int j = 0; j < 32; j += 8) {
- Process1RowChunk<8>(tag8_8, tag8_4, src, dst, j, bias_val, sum_2tap);
- }
+ }
+ if (h & 1) {
+ const HorizFilter<kTaps, hn::CappedTag<uint8_t, 16>> filt16(filter_x);
+ const auto res0 = filt16.Apply(hn::LoadU(u8_16, src));
+ const auto res8 = filt16.Apply(hn::LoadU(u8_16, src + 8));
+ hn::StoreU(hn::ReorderDemote2To(u8_16, res0, res8), u8_16, dst);
+ }
+ return;
+ }
+
+ // w >= 32 and (w & 31) == 0.
+#if HWY_TARGET <= HWY_AVX3
+ constexpr hn::CappedTag<uint8_t, 64> u8_64;
+ if ((w & 63) == 0) {
+ const HorizFilter<kTaps, hn::CappedTag<uint8_t, 64>> filt64(filter_x);
+ for (int y = 0; y < h; ++y) {
+ const uint8_t *src_row = src + y * src_stride;
+ uint8_t *dst_row = dst + y * dst_stride;
+ for (int j = 0; j < w; j += 64) {
+ const auto v_even = hn::LoadU(u8_64, src_row + j);
+ const auto v_odd = hn::LoadU(u8_64, src_row + j + 8);
+ const auto packed = hn::ReorderDemote2To(u8_64, filt64.Apply(v_even),
+ filt64.Apply(v_odd));
+ hn::StoreU(packed, u8_64, dst_row + j);
}
}
- } else {
- hn::ScalableTag<int16_t> mul_tag;
- hn::Rebind<uint8_t, decltype(mul_tag)> pixel_tag;
- auto filter_0 = hn::Set(mul_tag, filter_x[3]);
- auto filter_1 = hn::Set(mul_tag, filter_x[4]);
- auto vw = hn::Lanes(mul_tag);
- for (int i = 0; i < h; ++i) {
- for (int j = 0; j < w; j += vw) {
- auto src0 = hn::PromoteTo(mul_tag, hn::LoadU(pixel_tag, &src[j]));
- auto src1 = hn::PromoteTo(mul_tag, hn::LoadU(pixel_tag, &src[j + 1]));
- auto mulv = hn::RoundingShiftRight<FILTER_BITS>(src0 * filter_0 +
- src1 * filter_1);
- auto mulv_demoted = hn::DemoteTo(pixel_tag, mulv);
- if (j + static_cast<int>(vw) > w) {
- hn::StoreN(mulv_demoted, pixel_tag, &dst[j], w - j);
- } else {
- hn::StoreU(mulv_demoted, pixel_tag, &dst[j]);
- }
+ return;
+ }
+
+ if (h >= 2) {
+ const HorizFilter<kTaps, hn::CappedTag<uint8_t, 64>> filt64(filter_x);
+ while (h >= 2) {
+ for (int j = 0; j < w; j += 32) {
+ const auto v_even =
+ hn::Combine(u8_64, hn::LoadU(u8_32, src + src_stride + j),
+ hn::LoadU(u8_32, src + j));
+ const auto v_odd =
+ hn::Combine(u8_64, hn::LoadU(u8_32, src + src_stride + j + 8),
+ hn::LoadU(u8_32, src + j + 8));
+ const auto packed = hn::ReorderDemote2To(u8_64, filt64.Apply(v_even),
+ filt64.Apply(v_odd));
+ hn::StoreU(hn::LowerHalf(u8_32, packed), u8_32, dst + j);
+ hn::StoreU(hn::UpperHalf(u8_32, packed), u8_32, dst + dst_stride + j);
}
- src += src_stride;
- dst += dst_stride;
+ src += 2 * src_stride;
+ dst += 2 * dst_stride;
+ h -= 2;
+ }
+ }
+ if (h & 1) {
+ const HorizFilter<kTaps, hn::CappedTag<uint8_t, 32>> filt32(filter_x);
+ for (int j = 0; j < w; j += 32) {
+ const auto v_even = hn::LoadU(u8_32, src + j);
+ const auto v_odd = hn::LoadU(u8_32, src + j + 8);
+ const auto packed = hn::ReorderDemote2To(u8_32, filt32.Apply(v_even),
+ filt32.Apply(v_odd));
+ hn::StoreU(packed, u8_32, dst + j);
+ }
+ }
+#else
+ const HorizFilter<kTaps, hn::CappedTag<uint8_t, 32>> filt32(filter_x);
+ for (int y = 0; y < h; ++y) {
+ const uint8_t *src_row = src + y * src_stride;
+ uint8_t *dst_row = dst + y * dst_stride;
+ for (int j = 0; j < w; j += 32) {
+ const auto v_even = hn::LoadU(u8_32, src_row + j);
+ const auto v_odd = hn::LoadU(u8_32, src_row + j + 8);
+ const auto packed = hn::ReorderDemote2To(u8_32, filt32.Apply(v_even),
+ filt32.Apply(v_odd));
+ hn::StoreU(packed, u8_32, dst_row + j);
}
}
+#endif
}
+#endif // AOM_CONVOLVE_HWY_X86_PAIRWISE
+
+HWY_ATTR HWY_NOINLINE void ConvolveHoriz2Tap(const uint8_t *src,
+ ptrdiff_t src_stride, uint8_t *dst,
+ ptrdiff_t dst_stride,
+ const int16_t *filter_x, int w,
+ int h) {
+#if AOM_CONVOLVE_HWY_X86_PAIRWISE
+ if (AreTapsEven<2>(filter_x) &&
+ (w == 4 || w == 8 || w == 16 || (w >= 32 && (w & 31) == 0))) {
+ ConvolveHorizEven<2>(src, src_stride, dst, dst_stride, filter_x, w, h);
+ return;
+ }
+#endif
-template <typename D, typename DFilter>
-HWY_ATTR HWY_INLINE hn::VFromD<D> Convolve4_8(
- D tag16, DFilter tag_filter, hn::VFromD<D> &s0, hn::VFromD<D> &s1,
- hn::VFromD<D> &s2, hn::VFromD<D> &s3, hn::VFromD<DFilter> &filter) {
- (void)tag_filter;
- auto mul0 = hn::Mul(s0, hn::Set(tag16, hn::ExtractLane(filter, 0)));
- auto mul1 = hn::Mul(s1, hn::Set(tag16, hn::ExtractLane(filter, 1)));
- auto mul2 = hn::Mul(s2, hn::Set(tag16, hn::ExtractLane(filter, 2)));
- auto mul3 = hn::Mul(s3, hn::Set(tag16, hn::ExtractLane(filter, 3)));
-
- auto res = mul0 + mul1 + mul2 + mul3;
- // Shift (FILTER_BITS - 1) because filter values were halved.
- return hn::RoundingShiftRight<FILTER_BITS - 1>(res);
+ hn::ScalableTag<int16_t> mul_tag;
+ hn::Rebind<uint8_t, decltype(mul_tag)> pixel_tag;
+ auto filter_0 = hn::Set(mul_tag, filter_x[3]);
+ auto filter_1 = hn::Set(mul_tag, filter_x[4]);
+ auto vw = hn::Lanes(mul_tag);
+ for (int i = 0; i < h; ++i) {
+ for (int j = 0; j < w; j += vw) {
+ auto src0 = hn::PromoteTo(mul_tag, hn::LoadU(pixel_tag, &src[j]));
+ auto src1 = hn::PromoteTo(mul_tag, hn::LoadU(pixel_tag, &src[j + 1]));
+ auto mulv = hn::RoundingShiftRight<FILTER_BITS>(src0 * filter_0 +
+ src1 * filter_1);
+ auto mulv_demoted = hn::DemoteTo(pixel_tag, mulv);
+ if (j + static_cast<int>(vw) > w) {
+ hn::StoreN(mulv_demoted, pixel_tag, &dst[j], w - j);
+ } else {
+ hn::StoreU(mulv_demoted, pixel_tag, &dst[j]);
+ }
+ }
+ src += src_stride;
+ dst += dst_stride;
+ }
}
-HWY_ATTR inline void ConvolveHoriz4Tap(const uint8_t *src, ptrdiff_t src_stride,
- uint8_t *dst, ptrdiff_t dst_stride,
- const int16_t *filter_x, int w, int h) {
- const bool can_use_pareto_optimal_4tap =
- (h == 32 && (w == 16 || w == 32 || w == 64)) && (filter_x[2] % 2 == 0) &&
- (filter_x[3] % 2 == 0) && (filter_x[4] % 2 == 0) &&
- (filter_x[5] % 2 == 0);
-
- if (can_use_pareto_optimal_4tap) {
- if (w == 16) {
- constexpr hn::CappedTag<uint8_t, 16> u8_16_tag;
- constexpr hn::CappedTag<int8_t, 16> i8_16_tag;
- constexpr hn::CappedTag<int16_t, 8> i16_8_tag;
-
- const auto shuf01_16 = hn::Dup128VecFromValues(
- u8_16_tag, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8);
- const auto shuf23_16 = hn::Dup128VecFromValues(
- u8_16_tag, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10);
-
- const int8_t c2 = static_cast<int8_t>(filter_x[2] / 2);
- const int8_t c3 = static_cast<int8_t>(filter_x[3] / 2);
- const int8_t c4 = static_cast<int8_t>(filter_x[4] / 2);
- const int8_t c5 = static_cast<int8_t>(filter_x[5] / 2);
-
- const auto coeff23_16 =
- hn::Dup128VecFromValues(i8_16_tag, c2, c3, c2, c3, c2, c3, c2, c3, c2,
- c3, c2, c3, c2, c3, c2, c3);
- const auto coeff45_16 =
- hn::Dup128VecFromValues(i8_16_tag, c4, c5, c4, c5, c4, c5, c4, c5, c4,
- c5, c4, c5, c4, c5, c4, c5);
-
- const auto round_vec_16 = hn::Set(i16_8_tag, 1 << (FILTER_BITS - 2));
-
- for (int y = 0; y < h; ++y) {
- const uint8_t *src_row = src + y * src_stride;
- uint8_t *dst_row = dst + y * dst_stride;
-
- auto v0 = hn::LoadU(u8_16_tag, src_row + 0);
- auto v8 = hn::LoadU(u8_16_tag, src_row + 8);
-
- auto p01_0 = hn::TableLookupBytes(v0, shuf01_16);
- auto p23_0 = hn::TableLookupBytes(v0, shuf23_16);
- auto sum0 =
- hn::Add(hn::SatWidenMulPairwiseAdd(i16_8_tag, p01_0, coeff23_16),
- hn::SatWidenMulPairwiseAdd(i16_8_tag, p23_0, coeff45_16));
- auto res0 =
- hn::ShiftRightSame(hn::Add(sum0, round_vec_16), FILTER_BITS - 1);
-
- auto p01_8 = hn::TableLookupBytes(v8, shuf01_16);
- auto p23_8 = hn::TableLookupBytes(v8, shuf23_16);
- auto sum0_8 =
- hn::Add(hn::SatWidenMulPairwiseAdd(i16_8_tag, p01_8, coeff23_16),
- hn::SatWidenMulPairwiseAdd(i16_8_tag, p23_8, coeff45_16));
- auto res8 =
- hn::ShiftRightSame(hn::Add(sum0_8, round_vec_16), FILTER_BITS - 1);
-
- auto packed = hn::ReorderDemote2To(u8_16_tag, res0, res8);
- hn::StoreU(packed, u8_16_tag, dst_row);
- }
- } else {
- constexpr hn::CappedTag<uint8_t, 16> u8_16_tag;
- constexpr hn::CappedTag<uint8_t, 32> u8_32_tag;
- constexpr hn::CappedTag<int8_t, 16> i8_16_tag;
- constexpr hn::CappedTag<int8_t, 32> i8_32_tag;
- constexpr hn::CappedTag<int16_t, 16> i16_16_tag;
-
- const auto shuf01_16 = hn::Dup128VecFromValues(
- u8_16_tag, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8);
- const auto shuf23_16 = hn::Dup128VecFromValues(
- u8_16_tag, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10);
-
- const auto shuf01_32 = hn::Combine(u8_32_tag, shuf01_16, shuf01_16);
- const auto shuf23_32 = hn::Combine(u8_32_tag, shuf23_16, shuf23_16);
-
- const int8_t c2 = static_cast<int8_t>(filter_x[2] / 2);
- const int8_t c3 = static_cast<int8_t>(filter_x[3] / 2);
- const int8_t c4 = static_cast<int8_t>(filter_x[4] / 2);
- const int8_t c5 = static_cast<int8_t>(filter_x[5] / 2);
-
- const auto coeff23_16 =
- hn::Dup128VecFromValues(i8_16_tag, c2, c3, c2, c3, c2, c3, c2, c3, c2,
- c3, c2, c3, c2, c3, c2, c3);
- const auto coeff45_16 =
- hn::Dup128VecFromValues(i8_16_tag, c4, c5, c4, c5, c4, c5, c4, c5, c4,
- c5, c4, c5, c4, c5, c4, c5);
-
- const auto coeff23_32 = hn::Combine(i8_32_tag, coeff23_16, coeff23_16);
- const auto coeff45_32 = hn::Combine(i8_32_tag, coeff45_16, coeff45_16);
-
- const auto round_vec_32 = hn::Set(i16_16_tag, 1 << (FILTER_BITS - 2));
-
- for (int y = 0; y < h; ++y) {
- const uint8_t *src_row = src + y * src_stride;
- uint8_t *dst_row = dst + y * dst_stride;
-
- for (int j = 0; j < w; j += 32) {
- auto v_curr = hn::LoadU(u8_32_tag, src_row + j + 0);
- auto v8 = hn::LoadU(u8_32_tag, src_row + j + 8);
-
- auto p01_0 = hn::TableLookupBytes(v_curr, shuf01_32);
- auto p23_0 = hn::TableLookupBytes(v_curr, shuf23_32);
- auto sum0 = hn::Add(
- hn::SatWidenMulPairwiseAdd(i16_16_tag, p01_0, coeff23_32),
- hn::SatWidenMulPairwiseAdd(i16_16_tag, p23_0, coeff45_32));
- auto res0 =
- hn::ShiftRightSame(hn::Add(sum0, round_vec_32), FILTER_BITS - 1);
-
- auto p01_8 = hn::TableLookupBytes(v8, shuf01_32);
- auto p23_8 = hn::TableLookupBytes(v8, shuf23_32);
- auto sum0_8 = hn::Add(
- hn::SatWidenMulPairwiseAdd(i16_16_tag, p01_8, coeff23_32),
- hn::SatWidenMulPairwiseAdd(i16_16_tag, p23_8, coeff45_32));
- auto res8 = hn::ShiftRightSame(hn::Add(sum0_8, round_vec_32),
- FILTER_BITS - 1);
-
- constexpr hn::CappedTag<uint8_t, 8> u8_8_tag;
- auto demoted0 = hn::DemoteTo(u8_16_tag, res0);
- auto demoted8 = hn::DemoteTo(u8_16_tag, res8);
- auto p0_15 = hn::Combine(u8_16_tag, hn::LowerHalf(u8_8_tag, demoted8),
- hn::LowerHalf(u8_8_tag, demoted0));
- auto p16_31 =
- hn::Combine(u8_16_tag, hn::UpperHalf(u8_8_tag, demoted8),
- hn::UpperHalf(u8_8_tag, demoted0));
- hn::StoreU(p0_15, u8_16_tag, dst_row + j);
- hn::StoreU(p16_31, u8_16_tag, dst_row + j + 16);
- }
+HWY_ATTR HWY_NOINLINE void ConvolveHoriz4Tap(const uint8_t *src,
+ ptrdiff_t src_stride, uint8_t *dst,
+ ptrdiff_t dst_stride,
+ const int16_t *filter_x, int w,
+ int h) {
+#if AOM_CONVOLVE_HWY_X86_PAIRWISE
+ if (AreTapsEven<4>(filter_x) &&
+ (w == 4 || w == 8 || w == 16 || (w >= 32 && (w & 31) == 0))) {
+ ConvolveHorizEven<4>(src, src_stride, dst, dst_stride, filter_x, w, h);
+ return;
+ }
+#endif
+
+ hn::ScalableTag<int32_t> mul_tag;
+ hn::Rebind<int16_t, decltype(mul_tag)> i16_tag;
+ hn::Rebind<uint8_t, decltype(mul_tag)> pixel_tag;
+ auto f0 = hn::Set(mul_tag, filter_x[2]);
+ auto f1 = hn::Set(mul_tag, filter_x[3]);
+ auto f2 = hn::Set(mul_tag, filter_x[4]);
+ auto f3 = hn::Set(mul_tag, filter_x[5]);
+ auto round_offset = hn::Set(mul_tag, 1 << (FILTER_BITS - 1));
+ auto vw = hn::Lanes(mul_tag);
+ for (int i = 0; i < h; ++i) {
+ for (int j = 0; j < w; j += vw) {
+ auto src0 = hn::PromoteTo(mul_tag, hn::LoadU(pixel_tag, &src[j]));
+ auto src1 = hn::PromoteTo(mul_tag, hn::LoadU(pixel_tag, &src[j + 1]));
+ auto src2 = hn::PromoteTo(mul_tag, hn::LoadU(pixel_tag, &src[j + 2]));
+ auto src3 = hn::PromoteTo(mul_tag, hn::LoadU(pixel_tag, &src[j + 3]));
+ auto result = hn::ShiftRight<FILTER_BITS>(
+ src0 * f0 + src1 * f1 + src2 * f2 + src3 * f3 + round_offset);
+ auto result_demoted =
+ hn::DemoteTo(pixel_tag, hn::DemoteTo(i16_tag, result));
+ if (j + static_cast<int>(vw) > w) {
+ hn::StoreN(result_demoted, pixel_tag, &dst[j], w - j);
+ } else {
+ hn::StoreU(result_demoted, pixel_tag, &dst[j]);
}
}
+ src += src_stride;
+ dst += dst_stride;
+ }
+}
+
+HWY_ATTR HWY_NOINLINE void ConvolveHoriz8Tap(const uint8_t *src,
+ ptrdiff_t src_stride, uint8_t *dst,
+ ptrdiff_t dst_stride,
+ const int16_t *filter_x, int w,
+ int h) {
+#if AOM_CONVOLVE_HWY_X86_PAIRWISE
+ if (AreTapsEven<8>(filter_x) &&
+ (w == 4 || w == 8 || w == 16 || (w >= 32 && (w & 31) == 0))) {
+ ConvolveHorizEven<8>(src, src_stride, dst, dst_stride, filter_x, w, h);
return;
}
+#endif
- const bool can_use_optimized_path =
- (w <= 32) && (filter_x[2] % 2 == 0) && (filter_x[3] % 2 == 0) &&
- (filter_x[4] % 2 == 0) && (filter_x[5] % 2 == 0);
+ hn::ScalableTag<int32_t> mul_tag;
+ hn::Rebind<int16_t, decltype(mul_tag)> i16_tag;
+ hn::Rebind<uint8_t, decltype(mul_tag)> pixel_tag;
+ auto f0 = hn::Set(mul_tag, filter_x[0]);
+ auto f1 = hn::Set(mul_tag, filter_x[1]);
+ auto f2 = hn::Set(mul_tag, filter_x[2]);
+ auto f3 = hn::Set(mul_tag, filter_x[3]);
+ auto f4 = hn::Set(mul_tag, filter_x[4]);
+ auto f5 = hn::Set(mul_tag, filter_x[5]);
+ auto f6 = hn::Set(mul_tag, filter_x[6]);
+ auto f7 = hn::Set(mul_tag, filter_x[7]);
+ auto round_offset = hn::Set(mul_tag, 1 << (FILTER_BITS - 1));
+ auto vw = hn::Lanes(mul_tag);
+ for (int i = 0; i < h; ++i) {
+ for (int j = 0; j < w; j += vw) {
+ auto src0 = hn::PromoteTo(mul_tag, hn::LoadU(pixel_tag, &src[j]));
+ auto src1 = hn::PromoteTo(mul_tag, hn::LoadU(pixel_tag, &src[j + 1]));
+ auto src2 = hn::PromoteTo(mul_tag, hn::LoadU(pixel_tag, &src[j + 2]));
+ auto src3 = hn::PromoteTo(mul_tag, hn::LoadU(pixel_tag, &src[j + 3]));
+ auto src4 = hn::PromoteTo(mul_tag, hn::LoadU(pixel_tag, &src[j + 4]));
+ auto src5 = hn::PromoteTo(mul_tag, hn::LoadU(pixel_tag, &src[j + 5]));
+ auto src6 = hn::PromoteTo(mul_tag, hn::LoadU(pixel_tag, &src[j + 6]));
+ auto src7 = hn::PromoteTo(mul_tag, hn::LoadU(pixel_tag, &src[j + 7]));
+ auto sum = src0 * f0 + src1 * f1 + src2 * f2 + src3 * f3 + src4 * f4 +
+ src5 * f5 + src6 * f6 + src7 * f7;
+ auto result = hn::ShiftRight<FILTER_BITS>(sum + round_offset);
+ auto result_demoted =
+ hn::DemoteTo(pixel_tag, hn::DemoteTo(i16_tag, result));
+ if (j + static_cast<int>(vw) > w) {
+ hn::StoreN(result_demoted, pixel_tag, &dst[j], w - j);
+ } else {
+ hn::StoreU(result_demoted, pixel_tag, &dst[j]);
+ }
+ }
+ src += src_stride;
+ dst += dst_stride;
+ }
+}
- if (can_use_optimized_path) {
- hn::CappedTag<uint8_t, 16> tag8_16;
- hn::CappedTag<int8_t, 16> tag_i8;
- hn::CappedTag<int16_t, 8> tag16_8;
- hn::CappedTag<uint8_t, 8> tag8_8;
- hn::CappedTag<uint8_t, 4> tag8_4;
- const auto bias_val = hn::Set(tag16_8, 1 << (FILTER_BITS - 2));
+// ============================================================================
+// Vertical Convolution (pairwise uint8*int8 SatWidenMulPairwiseAdd)
+// ============================================================================
- const auto shuffle_mask = hn::Dup128VecFromValues(
- tag8_16, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8);
+#if AOM_CONVOLVE_HWY_X86_PAIRWISE
+HWY_ATTR HWY_INLINE uint32_t Load4BytesU32(const uint8_t *p) {
+ uint32_t v;
+ std::memcpy(&v, p, sizeof(v));
+ return v;
+}
- const int8_t c2 = static_cast<int8_t>(filter_x[2] / 2);
- const int8_t c3 = static_cast<int8_t>(filter_x[3] / 2);
- const int8_t c4 = static_cast<int8_t>(filter_x[4] / 2);
- const int8_t c5 = static_cast<int8_t>(filter_x[5] / 2);
+HWY_ATTR HWY_INLINE hn::VFromD<hn::CappedTag<uint8_t, 16>> Pack4Rows4B(
+ uint32_t r0, uint32_t r1, uint32_t r2, uint32_t r3) {
+ constexpr hn::CappedTag<uint32_t, 4> u32_4;
+ constexpr hn::CappedTag<uint8_t, 16> u8_16;
+ auto v = hn::Set(u32_4, r0);
+ v = hn::InsertLane(v, 1, r1);
+ v = hn::InsertLane(v, 2, r2);
+ v = hn::InsertLane(v, 3, r3);
+ return hn::BitCast(u8_16, v);
+}
- const auto coeff23 = hn::Dup128VecFromValues(
- tag_i8, c2, c3, c2, c3, c2, c3, c2, c3, c2, c3, c2, c3, c2, c3, c2, c3);
+HWY_ATTR HWY_INLINE hn::VFromD<hn::CappedTag<uint8_t, 32>> Interleave4Rows4B(
+ hn::VFromD<hn::CappedTag<uint8_t, 16>> a,
+ hn::VFromD<hn::CappedTag<uint8_t, 16>> b) {
+ constexpr hn::CappedTag<uint8_t, 16> u8_16;
+ constexpr hn::CappedTag<uint8_t, 32> u8_32;
+ return hn::Combine(u8_32, hn::InterleaveUpper(u8_16, a, b),
+ hn::InterleaveLower(u8_16, a, b));
+}
- const auto coeff45 = hn::Dup128VecFromValues(
- tag_i8, c4, c5, c4, c5, c4, c5, c4, c5, c4, c5, c4, c5, c4, c5, c4, c5);
+HWY_ATTR HWY_INLINE void Store4Rows4B(
+ hn::VFromD<hn::CappedTag<uint8_t, 16>> out16, uint8_t *dst,
+ ptrdiff_t dst_stride) {
+ constexpr hn::CappedTag<uint32_t, 4> u32_4;
+ const auto v32 = hn::BitCast(u32_4, out16);
+ const uint32_t o0 = hn::ExtractLane(v32, 0);
+ const uint32_t o1 = hn::ExtractLane(v32, 1);
+ const uint32_t o2 = hn::ExtractLane(v32, 2);
+ const uint32_t o3 = hn::ExtractLane(v32, 3);
+ std::memcpy(dst, &o0, 4);
+ std::memcpy(dst + dst_stride, &o1, 4);
+ std::memcpy(dst + 2 * dst_stride, &o2, 4);
+ std::memcpy(dst + 3 * dst_stride, &o3, 4);
+}
- auto sum_4tap = [&](const uint8_t *s, int offset) {
- return ComputeChunkSum4Tap(tag16_8, tag8_16, s, offset, shuffle_mask,
- coeff23, coeff45);
- };
+HWY_ATTR HWY_INLINE hn::VFromD<hn::CappedTag<uint8_t, 16>> Load8BytesIn16(
+ const uint8_t *p) {
+ constexpr hn::CappedTag<uint8_t, 16> u8_16;
+ constexpr hn::CappedTag<uint8_t, 8> u8_8;
+ return hn::ZeroExtendVector(u8_16, hn::LoadU(u8_8, p));
+}
- if (w == 4) {
- while (h >= 2) {
- Process2RowsChunk<4>(tag8_8, tag8_4, src, src_stride, dst, dst_stride,
- 0, bias_val, sum_4tap);
- src += 2 * src_stride;
- dst += 2 * dst_stride;
- h -= 2;
- }
- if (h & 1) {
- Process1RowChunk<4>(tag8_8, tag8_4, src, dst, 0, bias_val, sum_4tap);
- }
- } else if (w == 8) {
- while (h >= 2) {
- Process2RowsChunk<8>(tag8_8, tag8_4, src, src_stride, dst, dst_stride,
- 0, bias_val, sum_4tap);
- src += 2 * src_stride;
- dst += 2 * dst_stride;
- h -= 2;
- }
- if (h & 1) {
- Process1RowChunk<8>(tag8_8, tag8_4, src, dst, 0, bias_val, sum_4tap);
+HWY_ATTR HWY_INLINE hn::VFromD<hn::CappedTag<uint8_t, 16>> Load4BytesIn16(
+ const uint8_t *p) {
+ constexpr hn::CappedTag<uint32_t, 4> u32_4;
+ constexpr hn::CappedTag<uint8_t, 16> u8_16;
+ return hn::BitCast(u8_16, hn::Set(u32_4, Load4BytesU32(p)));
+}
+
+template <int kTaps, typename D8>
+struct VertFilter {
+ static constexpr int kPairs = kTaps / 2;
+ static constexpr int kStart = 4 - kPairs;
+ using D16 = hn::Repartition<int16_t, D8>;
+ using DI8 = hn::Repartition<int8_t, D8>;
+ using V8 = hn::VFromD<D8>;
+ hn::VFromD<DI8> c[kPairs];
+ hn::VFromD<D16> round_vec;
+
+ HWY_ATTR HWY_INLINE VertFilter() = default;
+
+ HWY_ATTR HWY_INLINE explicit VertFilter(const int16_t *filter_y) {
+ constexpr D8 u8_tag;
+ constexpr D16 i16_tag;
+ for (int i = 0; i < kPairs; ++i) {
+ c[i] = BroadcastPair(u8_tag, PackHalfTap(filter_y[kStart + 2 * i]),
+ PackHalfTap(filter_y[kStart + 2 * i + 1]));
+ }
+ round_vec = hn::Set(i16_tag, 1 << (FILTER_BITS - 2));
+ }
+
+ HWY_ATTR HWY_INLINE VertFilter<kTaps, hn::Half<D8>> LowerHalf() const {
+ using D8Half = hn::Half<D8>;
+ using D16Half = hn::Repartition<int16_t, D8Half>;
+ using DI8Half = hn::Repartition<int8_t, D8Half>;
+ constexpr DI8Half di8_half;
+ constexpr D16Half d16_half;
+ VertFilter<kTaps, D8Half> out;
+ for (int i = 0; i < kPairs; ++i) {
+ out.c[i] = hn::LowerHalf(di8_half, c[i]);
+ }
+ out.round_vec = hn::LowerHalf(d16_half, round_vec);
+ return out;
+ }
+
+ HWY_ATTR HWY_INLINE hn::VFromD<D16> Apply(const V8 (&p)[kPairs]) const {
+ constexpr D16 i16_tag;
+ if constexpr (kTaps == 2) {
+ const auto s01 = hn::SatWidenMulPairwiseAdd(i16_tag, p[0], c[0]);
+ return hn::ShiftRight<FILTER_BITS - 1>(hn::SaturatedAdd(s01, round_vec));
+ } else if constexpr (kTaps == 4) {
+ const auto s01 = hn::SatWidenMulPairwiseAdd(i16_tag, p[0], c[0]);
+ const auto s23 = hn::SatWidenMulPairwiseAdd(i16_tag, p[1], c[1]);
+ return hn::ShiftRight<FILTER_BITS - 1>(
+ hn::SaturatedAdd(hn::SaturatedAdd(s01, s23), round_vec));
+ } else {
+ const auto s01 = hn::SatWidenMulPairwiseAdd(i16_tag, p[0], c[0]);
+ const auto s67 = hn::SatWidenMulPairwiseAdd(i16_tag, p[3], c[3]);
+ const auto s23 = hn::SatWidenMulPairwiseAdd(i16_tag, p[1], c[1]);
+ const auto s45 = hn::SatWidenMulPairwiseAdd(i16_tag, p[2], c[2]);
+ const auto sum = hn::SaturatedAdd(hn::SaturatedAdd(s01, s67),
+ hn::SaturatedAdd(s23, s45));
+ return hn::ShiftRight<FILTER_BITS - 1>(hn::SaturatedAdd(sum, round_vec));
+ }
+ }
+};
+
+template <int kTaps>
+HWY_ATTR HWY_NOINLINE void ConvolveVertEvenW4(const uint8_t *src,
+ ptrdiff_t src_stride,
+ uint8_t *dst,
+ ptrdiff_t dst_stride,
+ const int16_t *filter_y, int h) {
+ constexpr int kPairs = kTaps / 2;
+ constexpr hn::CappedTag<uint8_t, 16> u8_16;
+ constexpr hn::CappedTag<uint8_t, 32> u8_32;
+ using V16 = hn::VFromD<decltype(u8_16)>;
+ using V32 = hn::VFromD<decltype(u8_32)>;
+
+ if (h >= 4) {
+ const VertFilter<kTaps, decltype(u8_32)> filt32(filter_y);
+ if constexpr (kTaps == 2) {
+ V16 x0 = Pack4Rows4B(Load4BytesU32(src), Load4BytesU32(src + src_stride),
+ Load4BytesU32(src + 2 * src_stride),
+ Load4BytesU32(src + 3 * src_stride));
+ while (h >= 8) {
+ const V16 x1 = Pack4Rows4B(Load4BytesU32(src + 4 * src_stride),
+ Load4BytesU32(src + 5 * src_stride),
+ Load4BytesU32(src + 6 * src_stride),
+ Load4BytesU32(src + 7 * src_stride));
+ const V32 p[1] = {
+ Interleave4Rows4B(x0, hn::CombineShiftRightBytes<4>(u8_16, x1, x0)),
+ };
+ const auto res = filt32.Apply(p);
+ Store4Rows4B(hn::DemoteTo(u8_16, res), dst, dst_stride);
+ x0 = x1;
+ src += 4 * src_stride;
+ dst += 4 * dst_stride;
+ h -= 4;
}
- } else if (w == 16) {
- while (h >= 2) {
- Process2RowsChunk<8>(tag8_8, tag8_4, src, src_stride, dst, dst_stride,
- 0, bias_val, sum_4tap);
- Process2RowsChunk<8>(tag8_8, tag8_4, src, src_stride, dst, dst_stride,
- 8, bias_val, sum_4tap);
- src += 2 * src_stride;
- dst += 2 * dst_stride;
- h -= 2;
+ if (h >= 4) {
+ const V16 x1 = Load4BytesIn16(src + 4 * src_stride);
+ const V32 p[1] = {
+ Interleave4Rows4B(x0, hn::CombineShiftRightBytes<4>(u8_16, x1, x0)),
+ };
+ const auto res = filt32.Apply(p);
+ Store4Rows4B(hn::DemoteTo(u8_16, res), dst, dst_stride);
+ src += 4 * src_stride;
+ dst += 4 * dst_stride;
+ h -= 4;
}
- if (h & 1) {
- Process1RowChunk<8>(tag8_8, tag8_4, src, dst, 0, bias_val, sum_4tap);
- Process1RowChunk<8>(tag8_8, tag8_4, src, dst, 8, bias_val, sum_4tap);
+ } else if constexpr (kTaps == 4) {
+ V16 x0 = Pack4Rows4B(Load4BytesU32(src), Load4BytesU32(src + src_stride),
+ Load4BytesU32(src + 2 * src_stride),
+ Load4BytesU32(src + 3 * src_stride));
+ while (h >= 8) {
+ const V16 x1 = Pack4Rows4B(Load4BytesU32(src + 4 * src_stride),
+ Load4BytesU32(src + 5 * src_stride),
+ Load4BytesU32(src + 6 * src_stride),
+ Load4BytesU32(src + 7 * src_stride));
+ const V32 p[2] = {
+ Interleave4Rows4B(x0, hn::CombineShiftRightBytes<4>(u8_16, x1, x0)),
+ Interleave4Rows4B(hn::CombineShiftRightBytes<8>(u8_16, x1, x0),
+ hn::CombineShiftRightBytes<12>(u8_16, x1, x0)),
+ };
+ const auto res = filt32.Apply(p);
+ Store4Rows4B(hn::DemoteTo(u8_16, res), dst, dst_stride);
+ x0 = x1;
+ src += 4 * src_stride;
+ dst += 4 * dst_stride;
+ h -= 4;
}
- } else if (w == 32) {
- while (h >= 2) {
- Process2RowsChunk<8>(tag8_8, tag8_4, src, src_stride, dst, dst_stride,
- 0, bias_val, sum_4tap);
- Process2RowsChunk<8>(tag8_8, tag8_4, src, src_stride, dst, dst_stride,
- 8, bias_val, sum_4tap);
- Process2RowsChunk<8>(tag8_8, tag8_4, src, src_stride, dst, dst_stride,
- 16, bias_val, sum_4tap);
- Process2RowsChunk<8>(tag8_8, tag8_4, src, src_stride, dst, dst_stride,
- 24, bias_val, sum_4tap);
- src += 2 * src_stride;
- dst += 2 * dst_stride;
- h -= 2;
+ if (h >= 4) {
+ const V16 x1 = Pack4Rows4B(Load4BytesU32(src + 4 * src_stride),
+ Load4BytesU32(src + 5 * src_stride),
+ Load4BytesU32(src + 6 * src_stride), 0);
+ const V32 p[2] = {
+ Interleave4Rows4B(x0, hn::CombineShiftRightBytes<4>(u8_16, x1, x0)),
+ Interleave4Rows4B(hn::CombineShiftRightBytes<8>(u8_16, x1, x0),
+ hn::CombineShiftRightBytes<12>(u8_16, x1, x0)),
+ };
+ const auto res = filt32.Apply(p);
+ Store4Rows4B(hn::DemoteTo(u8_16, res), dst, dst_stride);
+ src += 4 * src_stride;
+ dst += 4 * dst_stride;
+ h -= 4;
}
- if (h & 1) {
- for (int j = 0; j < 32; j += 8) {
- Process1RowChunk<8>(tag8_8, tag8_4, src, dst, j, bias_val, sum_4tap);
- }
+ } else {
+ const V16 x0 =
+ Pack4Rows4B(Load4BytesU32(src), Load4BytesU32(src + src_stride),
+ Load4BytesU32(src + 2 * src_stride),
+ Load4BytesU32(src + 3 * src_stride));
+ V16 x1 = Pack4Rows4B(Load4BytesU32(src + 4 * src_stride),
+ Load4BytesU32(src + 5 * src_stride),
+ Load4BytesU32(src + 6 * src_stride),
+ Load4BytesU32(src + 7 * src_stride));
+ V32 p[4];
+ p[0] =
+ Interleave4Rows4B(x0, hn::CombineShiftRightBytes<4>(u8_16, x1, x0));
+ p[1] = Interleave4Rows4B(hn::CombineShiftRightBytes<8>(u8_16, x1, x0),
+ hn::CombineShiftRightBytes<12>(u8_16, x1, x0));
+ while (h >= 4) {
+ const uint32_t r8 = Load4BytesU32(src + 8 * src_stride);
+ const uint32_t r9 = Load4BytesU32(src + 9 * src_stride);
+ const uint32_t r10 = Load4BytesU32(src + 10 * src_stride);
+ const uint32_t r11 =
+ (h >= 8) ? Load4BytesU32(src + 11 * src_stride) : 0;
+ const V16 x2 = Pack4Rows4B(r8, r9, r10, r11);
+ p[2] =
+ Interleave4Rows4B(x1, hn::CombineShiftRightBytes<4>(u8_16, x2, x1));
+ p[3] = Interleave4Rows4B(hn::CombineShiftRightBytes<8>(u8_16, x2, x1),
+ hn::CombineShiftRightBytes<12>(u8_16, x2, x1));
+ const auto res = filt32.Apply(p);
+ Store4Rows4B(hn::DemoteTo(u8_16, res), dst, dst_stride);
+ p[0] = p[2];
+ p[1] = p[3];
+ x1 = x2;
+ src += 4 * src_stride;
+ dst += 4 * dst_stride;
+ h -= 4;
}
}
- } else {
- hn::ScalableTag<int16_t> mul_tag;
- hn::Rebind<uint8_t, decltype(mul_tag)> pixel_tag;
- hn::CappedTag<int16_t, 4> filter_tag;
- auto f_vec = hn::LoadU(filter_tag, filter_x + 2);
- f_vec = hn::ShiftRight<1>(f_vec);
- auto vw = hn::Lanes(mul_tag);
- for (int i = 0; i < h; ++i) {
- for (int j = 0; j < w; j += vw) {
- auto src0 = hn::PromoteTo(mul_tag, hn::LoadU(pixel_tag, &src[j]));
- auto src1 = hn::PromoteTo(mul_tag, hn::LoadU(pixel_tag, &src[j + 1]));
- auto src2 = hn::PromoteTo(mul_tag, hn::LoadU(pixel_tag, &src[j + 2]));
- auto src3 = hn::PromoteTo(mul_tag, hn::LoadU(pixel_tag, &src[j + 3]));
- auto result =
- Convolve4_8(mul_tag, filter_tag, src0, src1, src2, src3, f_vec);
- auto result_demoted = hn::DemoteTo(pixel_tag, result);
- if (j + static_cast<int>(vw) > w) {
- hn::StoreN(result_demoted, pixel_tag, &dst[j], w - j);
- } else {
- hn::StoreU(result_demoted, pixel_tag, &dst[j]);
- }
+ }
+ if (h > 0) {
+ const VertFilter<kTaps, decltype(u8_16)> filt16(filter_y);
+ V16 r[kTaps - 1];
+ for (int i = 0; i < kTaps - 1; ++i) {
+ r[i] = Load4BytesIn16(src + i * src_stride);
+ }
+ while (h > 0) {
+ const V16 r_last = Load4BytesIn16(src + (kTaps - 1) * src_stride);
+ V16 p[kPairs];
+ for (int i = 0; i < kPairs - 1; ++i) {
+ p[i] = hn::InterleaveLower(u8_16, r[2 * i], r[2 * i + 1]);
}
+ p[kPairs - 1] = hn::InterleaveLower(u8_16, r[kTaps - 2], r_last);
+ const auto res = filt16.Apply(p);
+ StoreSmallRow<4>(hn::ReorderDemote2To(u8_16, res, res), dst);
+ ShiftLeft1(r);
+ r[kTaps - 2] = r_last;
src += src_stride;
dst += dst_stride;
+ --h;
}
}
}
-template <typename D, typename DFilter>
-HWY_ATTR HWY_INLINE hn::VFromD<D> Convolve8_8(
- D tag16, DFilter tag_filter, hn::VFromD<D> &s0, hn::VFromD<D> &s1,
- hn::VFromD<D> &s2, hn::VFromD<D> &s3, hn::VFromD<D> &s4, hn::VFromD<D> &s5,
- hn::VFromD<D> &s6, hn::VFromD<D> &s7, hn::VFromD<DFilter> &filter) {
- (void)tag_filter;
- auto filter_0 = hn::ExtractLane(filter, 0);
- auto filter_1 = hn::ExtractLane(filter, 1);
- auto filter_2 = hn::ExtractLane(filter, 2);
- auto filter_3 = hn::ExtractLane(filter, 3);
- auto filter_4 = hn::ExtractLane(filter, 4);
- auto filter_5 = hn::ExtractLane(filter, 5);
- auto filter_6 = hn::ExtractLane(filter, 6);
- auto filter_7 = hn::ExtractLane(filter, 7);
- auto mul0 = hn::Mul(s0, hn::Set(tag16, filter_0));
- auto mul1 = hn::Mul(s1, hn::Set(tag16, filter_1));
- auto mul2 = hn::Mul(s2, hn::Set(tag16, filter_2));
- auto mul3 = hn::Mul(s3, hn::Set(tag16, filter_3));
- auto mul4 = hn::Mul(s4, hn::Set(tag16, filter_4));
- auto mul5 = hn::Mul(s5, hn::Set(tag16, filter_5));
- auto mul6 = hn::Mul(s6, hn::Set(tag16, filter_6));
- auto mul7 = hn::Mul(s7, hn::Set(tag16, filter_7));
-
- auto res = mul0 + mul1 + mul2 + mul3 + mul4 + mul5 + mul6 + mul7;
- // Shift (FILTER_BITS - 1) because filter values were halved.
- return hn::RoundingShiftRight<FILTER_BITS - 1>(res);
+#if HWY_TARGET <= HWY_AVX3
+template <int kW>
+HWY_ATTR HWY_INLINE
+ hn::VFromD<hn::CappedTag<uint8_t, 16>> LoadZmmStripRow(const uint8_t *p) {
+ constexpr hn::CappedTag<uint8_t, 16> u8_16;
+ if constexpr (kW == 8) {
+ return Load8BytesIn16(p);
+ } else {
+ return hn::LoadU(u8_16, p);
+ }
+}
+
+template <int kW>
+HWY_ATTR HWY_INLINE void StoreZmmStripRow(
+ hn::VFromD<hn::CappedTag<uint8_t, 16>> row, uint8_t *dst) {
+ constexpr hn::CappedTag<uint8_t, 16> u8_16;
+ if constexpr (kW == 8) {
+ StoreSmallRow<8>(row, dst);
+ } else {
+ hn::StoreU(row, u8_16, dst);
+ }
}
-HWY_ATTR inline void ConvolveHoriz8Tap(const uint8_t *src, ptrdiff_t src_stride,
- uint8_t *dst, ptrdiff_t dst_stride,
- const int16_t *filter_x, int w, int h) {
- const bool can_use_pareto_optimal_8tap =
- (h == 32 && (w == 16 || w == 32 || w == 64)) && (filter_x[0] % 2 == 0) &&
- (filter_x[1] % 2 == 0) && (filter_x[2] % 2 == 0) &&
- (filter_x[3] % 2 == 0) && (filter_x[4] % 2 == 0) &&
- (filter_x[5] % 2 == 0) && (filter_x[6] % 2 == 0) &&
- (filter_x[7] % 2 == 0);
-
- if (can_use_pareto_optimal_8tap) {
- if (w == 16) {
- constexpr hn::CappedTag<uint8_t, 16> u8_16_tag;
- constexpr hn::CappedTag<int8_t, 16> i8_16_tag;
- constexpr hn::CappedTag<int16_t, 8> i16_8_tag;
-
- // Construct shuffles locally (no filt_global load)
- const auto shuf01_16 = hn::Dup128VecFromValues(
- u8_16_tag, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8);
- const auto shuf23_16 = hn::Dup128VecFromValues(
- u8_16_tag, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10);
- const auto shuf45_16 = hn::Dup128VecFromValues(
- u8_16_tag, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12);
- const auto shuf67_16 = hn::Dup128VecFromValues(
- u8_16_tag, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14);
-
- const int8_t c0 = static_cast<int8_t>(filter_x[0] / 2);
- const int8_t c1 = static_cast<int8_t>(filter_x[1] / 2);
- const int8_t c2 = static_cast<int8_t>(filter_x[2] / 2);
- const int8_t c3 = static_cast<int8_t>(filter_x[3] / 2);
- const int8_t c4 = static_cast<int8_t>(filter_x[4] / 2);
- const int8_t c5 = static_cast<int8_t>(filter_x[5] / 2);
- const int8_t c6 = static_cast<int8_t>(filter_x[6] / 2);
- const int8_t c7 = static_cast<int8_t>(filter_x[7] / 2);
-
- const auto coeff01_16 =
- hn::Dup128VecFromValues(i8_16_tag, c0, c1, c0, c1, c0, c1, c0, c1, c0,
- c1, c0, c1, c0, c1, c0, c1);
- const auto coeff23_16 =
- hn::Dup128VecFromValues(i8_16_tag, c2, c3, c2, c3, c2, c3, c2, c3, c2,
- c3, c2, c3, c2, c3, c2, c3);
- const auto coeff45_16 =
- hn::Dup128VecFromValues(i8_16_tag, c4, c5, c4, c5, c4, c5, c4, c5, c4,
- c5, c4, c5, c4, c5, c4, c5);
- const auto coeff67_16 =
- hn::Dup128VecFromValues(i8_16_tag, c6, c7, c6, c7, c6, c7, c6, c7, c6,
- c7, c6, c7, c6, c7, c6, c7);
-
- const auto round_vec_16 = hn::Set(i16_8_tag, 1 << (FILTER_BITS - 2));
-
- for (int y = 0; y < h; ++y) {
- const uint8_t *src_row = src + y * src_stride;
- uint8_t *dst_row = dst + y * dst_stride;
-
- auto v0 = hn::LoadU(u8_16_tag, src_row + 0);
- auto v8 = hn::LoadU(u8_16_tag, src_row + 8);
-
- auto p01_0 = hn::TableLookupBytes(v0, shuf01_16);
- auto p23_0 = hn::TableLookupBytes(v0, shuf23_16);
- auto p45_0 = hn::TableLookupBytes(v0, shuf45_16);
- auto p67_0 = hn::TableLookupBytes(v0, shuf67_16);
- auto sum0 =
- hn::Add(hn::SatWidenMulPairwiseAdd(i16_8_tag, p01_0, coeff01_16),
- hn::SatWidenMulPairwiseAdd(i16_8_tag, p23_0, coeff23_16));
- auto sum1 =
- hn::Add(hn::SatWidenMulPairwiseAdd(i16_8_tag, p45_0, coeff45_16),
- hn::SatWidenMulPairwiseAdd(i16_8_tag, p67_0, coeff67_16));
- auto res0 = hn::ShiftRightSame(
- hn::Add(hn::Add(sum0, sum1), round_vec_16), FILTER_BITS - 1);
-
- auto p01_8 = hn::TableLookupBytes(v8, shuf01_16);
- auto p23_8 = hn::TableLookupBytes(v8, shuf23_16);
- auto p45_8 = hn::TableLookupBytes(v8, shuf45_16);
- auto p67_8 = hn::TableLookupBytes(v8, shuf67_16);
- auto sum0_8 =
- hn::Add(hn::SatWidenMulPairwiseAdd(i16_8_tag, p01_8, coeff01_16),
- hn::SatWidenMulPairwiseAdd(i16_8_tag, p23_8, coeff23_16));
- auto sum1_8 =
- hn::Add(hn::SatWidenMulPairwiseAdd(i16_8_tag, p45_8, coeff45_16),
- hn::SatWidenMulPairwiseAdd(i16_8_tag, p67_8, coeff67_16));
- auto res8 = hn::ShiftRightSame(
- hn::Add(hn::Add(sum0_8, sum1_8), round_vec_16), FILTER_BITS - 1);
-
- auto packed = hn::ReorderDemote2To(u8_16_tag, res0, res8);
- hn::StoreU(packed, u8_16_tag, dst_row);
+template <int kTaps, int kW>
+HWY_ATTR HWY_NOINLINE void ConvolveVertEvenZmm4Rows(
+ const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst,
+ ptrdiff_t dst_stride, const int16_t *filter_y, int h) {
+ constexpr int kPairs = kTaps / 2;
+ constexpr hn::CappedTag<uint8_t, 16> u8_16;
+ constexpr hn::CappedTag<uint8_t, 32> u8_32;
+ constexpr hn::CappedTag<uint8_t, 64> u8_64;
+ using V16 = hn::VFromD<decltype(u8_16)>;
+ using V64 = hn::VFromD<decltype(u8_64)>;
+
+ const VertFilter<kTaps, decltype(u8_64)> filt64(filter_y);
+ V16 r_init[kTaps - 1];
+ for (int i = 0; i < kTaps - 1; ++i) {
+ r_init[i] = LoadZmmStripRow<kW>(src + i * src_stride);
+ }
+ V64 p_lo[kPairs];
+ V64 p_hi[kPairs];
+ if constexpr (kTaps == 8) {
+ for (int i = 0; i < 2; ++i) {
+ const V64 a = hn::Combine(
+ u8_64, hn::Combine(u8_32, r_init[2 * i + 3], r_init[2 * i + 2]),
+ hn::Combine(u8_32, r_init[2 * i + 1], r_init[2 * i]));
+ const V64 b = hn::Combine(
+ u8_64, hn::Combine(u8_32, r_init[2 * i + 4], r_init[2 * i + 3]),
+ hn::Combine(u8_32, r_init[2 * i + 2], r_init[2 * i + 1]));
+ p_lo[i] = hn::InterleaveLower(u8_64, a, b);
+ if constexpr (kW == 16) {
+ p_hi[i] = hn::InterleaveUpper(u8_64, a, b);
+ }
+ }
+ }
+ while (h >= 4) {
+ const V16 rn0 = LoadZmmStripRow<kW>(src + (kTaps - 1) * src_stride);
+ const V16 rn1 = LoadZmmStripRow<kW>(src + kTaps * src_stride);
+ const V16 rn2 = LoadZmmStripRow<kW>(src + (kTaps + 1) * src_stride);
+ const V16 rn3 = LoadZmmStripRow<kW>(src + (kTaps + 2) * src_stride);
+ if constexpr (kTaps >= 4) {
+ const V64 a_prev =
+ hn::Combine(u8_64, hn::Combine(u8_32, rn0, r_init[kTaps - 2]),
+ hn::Combine(u8_32, r_init[kTaps - 3], r_init[kTaps - 4]));
+ const V64 b_prev =
+ hn::Combine(u8_64, hn::Combine(u8_32, rn1, rn0),
+ hn::Combine(u8_32, r_init[kTaps - 2], r_init[kTaps - 3]));
+ p_lo[kPairs - 2] = hn::InterleaveLower(u8_64, a_prev, b_prev);
+ if constexpr (kW == 16) {
+ p_hi[kPairs - 2] = hn::InterleaveUpper(u8_64, a_prev, b_prev);
}
+ }
+ const V64 a = hn::Combine(u8_64, hn::Combine(u8_32, rn2, rn1),
+ hn::Combine(u8_32, rn0, r_init[kTaps - 2]));
+ const V64 b = hn::Combine(u8_64, hn::Combine(u8_32, rn3, rn2),
+ hn::Combine(u8_32, rn1, rn0));
+ p_lo[kPairs - 1] = hn::InterleaveLower(u8_64, a, b);
+ const auto res_lo = filt64.Apply(p_lo);
+ V64 packed;
+ if constexpr (kW == 16) {
+ p_hi[kPairs - 1] = hn::InterleaveUpper(u8_64, a, b);
+ const auto res_hi = filt64.Apply(p_hi);
+ packed = hn::ReorderDemote2To(u8_64, res_lo, res_hi);
} else {
- constexpr hn::CappedTag<uint8_t, 16> u8_16_tag;
- constexpr hn::CappedTag<uint8_t, 32> u8_32_tag;
- constexpr hn::CappedTag<int8_t, 16> i8_16_tag;
- constexpr hn::CappedTag<int8_t, 32> i8_32_tag;
- constexpr hn::CappedTag<int16_t, 16> i16_16_tag;
-
- const auto shuf01_16 = hn::Dup128VecFromValues(
- u8_16_tag, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8);
- const auto shuf23_16 = hn::Dup128VecFromValues(
- u8_16_tag, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10);
- const auto shuf45_16 = hn::Dup128VecFromValues(
- u8_16_tag, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12);
- const auto shuf67_16 = hn::Dup128VecFromValues(
- u8_16_tag, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14);
-
- const auto shuf01_32 = hn::Combine(u8_32_tag, shuf01_16, shuf01_16);
- const auto shuf23_32 = hn::Combine(u8_32_tag, shuf23_16, shuf23_16);
- const auto shuf45_32 = hn::Combine(u8_32_tag, shuf45_16, shuf45_16);
- const auto shuf67_32 = hn::Combine(u8_32_tag, shuf67_16, shuf67_16);
-
- const int8_t c0 = static_cast<int8_t>(filter_x[0] / 2);
- const int8_t c1 = static_cast<int8_t>(filter_x[1] / 2);
- const int8_t c2 = static_cast<int8_t>(filter_x[2] / 2);
- const int8_t c3 = static_cast<int8_t>(filter_x[3] / 2);
- const int8_t c4 = static_cast<int8_t>(filter_x[4] / 2);
- const int8_t c5 = static_cast<int8_t>(filter_x[5] / 2);
- const int8_t c6 = static_cast<int8_t>(filter_x[6] / 2);
- const int8_t c7 = static_cast<int8_t>(filter_x[7] / 2);
-
- const auto coeff01_16 =
- hn::Dup128VecFromValues(i8_16_tag, c0, c1, c0, c1, c0, c1, c0, c1, c0,
- c1, c0, c1, c0, c1, c0, c1);
- const auto coeff23_16 =
- hn::Dup128VecFromValues(i8_16_tag, c2, c3, c2, c3, c2, c3, c2, c3, c2,
- c3, c2, c3, c2, c3, c2, c3);
- const auto coeff45_16 =
- hn::Dup128VecFromValues(i8_16_tag, c4, c5, c4, c5, c4, c5, c4, c5, c4,
- c5, c4, c5, c4, c5, c4, c5);
- const auto coeff67_16 =
- hn::Dup128VecFromValues(i8_16_tag, c6, c7, c6, c7, c6, c7, c6, c7, c6,
- c7, c6, c7, c6, c7, c6, c7);
-
- const auto coeff01_32 = hn::Combine(i8_32_tag, coeff01_16, coeff01_16);
- const auto coeff23_32 = hn::Combine(i8_32_tag, coeff23_16, coeff23_16);
- const auto coeff45_32 = hn::Combine(i8_32_tag, coeff45_16, coeff45_16);
- const auto coeff67_32 = hn::Combine(i8_32_tag, coeff67_16, coeff67_16);
-
- const auto round_vec_32 = hn::Set(i16_16_tag, 1 << (FILTER_BITS - 2));
-
- for (int y = 0; y < h; ++y) {
- const uint8_t *src_row = src + y * src_stride;
- uint8_t *dst_row = dst + y * dst_stride;
-
- for (int j = 0; j < w; j += 32) {
- auto v_curr = hn::LoadU(u8_32_tag, src_row + j + 0);
- auto v8 = hn::LoadU(u8_32_tag, src_row + j + 8);
-
- auto p01_0 = hn::TableLookupBytes(v_curr, shuf01_32);
- auto p23_0 = hn::TableLookupBytes(v_curr, shuf23_32);
- auto p45_0 = hn::TableLookupBytes(v_curr, shuf45_32);
- auto p67_0 = hn::TableLookupBytes(v_curr, shuf67_32);
- auto sum0 = hn::Add(
- hn::SatWidenMulPairwiseAdd(i16_16_tag, p01_0, coeff01_32),
- hn::SatWidenMulPairwiseAdd(i16_16_tag, p23_0, coeff23_32));
- auto sum1 = hn::Add(
- hn::SatWidenMulPairwiseAdd(i16_16_tag, p45_0, coeff45_32),
- hn::SatWidenMulPairwiseAdd(i16_16_tag, p67_0, coeff67_32));
- auto res0 = hn::ShiftRightSame(
- hn::Add(hn::Add(sum0, sum1), round_vec_32), FILTER_BITS - 1);
-
- auto p01_8 = hn::TableLookupBytes(v8, shuf01_32);
- auto p23_8 = hn::TableLookupBytes(v8, shuf23_32);
- auto p45_8 = hn::TableLookupBytes(v8, shuf45_32);
- auto p67_8 = hn::TableLookupBytes(v8, shuf67_32);
- auto sum0_8 = hn::Add(
- hn::SatWidenMulPairwiseAdd(i16_16_tag, p01_8, coeff01_32),
- hn::SatWidenMulPairwiseAdd(i16_16_tag, p23_8, coeff23_32));
- auto sum1_8 = hn::Add(
- hn::SatWidenMulPairwiseAdd(i16_16_tag, p45_8, coeff45_32),
- hn::SatWidenMulPairwiseAdd(i16_16_tag, p67_8, coeff67_32));
- auto res8 = hn::ShiftRightSame(
- hn::Add(hn::Add(sum0_8, sum1_8), round_vec_32), FILTER_BITS - 1);
-
- constexpr hn::CappedTag<uint8_t, 8> u8_8_tag;
- auto demoted0 = hn::DemoteTo(u8_16_tag, res0);
- auto demoted8 = hn::DemoteTo(u8_16_tag, res8);
- auto p0_15 = hn::Combine(u8_16_tag, hn::LowerHalf(u8_8_tag, demoted8),
- hn::LowerHalf(u8_8_tag, demoted0));
- auto p16_31 =
- hn::Combine(u8_16_tag, hn::UpperHalf(u8_8_tag, demoted8),
- hn::UpperHalf(u8_8_tag, demoted0));
- hn::StoreU(p0_15, u8_16_tag, dst_row + j);
- hn::StoreU(p16_31, u8_16_tag, dst_row + j + 16);
- }
+ packed = hn::ReorderDemote2To(u8_64, res_lo, res_lo);
+ }
+ const auto lo32 = hn::LowerHalf(u8_32, packed);
+ const auto hi32 = hn::UpperHalf(u8_32, packed);
+ StoreZmmStripRow<kW>(hn::LowerHalf(u8_16, lo32), dst);
+ StoreZmmStripRow<kW>(hn::UpperHalf(u8_16, lo32), dst + dst_stride);
+ StoreZmmStripRow<kW>(hn::LowerHalf(u8_16, hi32), dst + 2 * dst_stride);
+ StoreZmmStripRow<kW>(hn::UpperHalf(u8_16, hi32), dst + 3 * dst_stride);
+ if constexpr (kTaps == 8) {
+ p_lo[0] = p_lo[2];
+ p_lo[1] = p_lo[3];
+ if constexpr (kW == 16) {
+ p_hi[0] = p_hi[2];
+ p_hi[1] = p_hi[3];
}
}
- return;
+ if constexpr (kTaps >= 4) {
+ r_init[kTaps - 4] = rn1;
+ r_init[kTaps - 3] = rn2;
+ r_init[kTaps - 2] = rn3;
+ } else {
+ r_init[0] = rn3;
+ }
+ src += 4 * src_stride;
+ dst += 4 * dst_stride;
+ h -= 4;
}
+}
+#endif // HWY_TARGET <= HWY_AVX3
+
+template <int kTaps>
+HWY_ATTR HWY_NOINLINE void ConvolveVertEvenW8(const uint8_t *src,
+ ptrdiff_t src_stride,
+ uint8_t *dst,
+ ptrdiff_t dst_stride,
+ const int16_t *filter_y, int h) {
+ constexpr int kPairs = kTaps / 2;
+ constexpr hn::CappedTag<uint8_t, 16> u8_16;
+ constexpr hn::CappedTag<uint8_t, 32> u8_32;
+ using V16 = hn::VFromD<decltype(u8_16)>;
+ using V32 = hn::VFromD<decltype(u8_32)>;
+
+ if (h >= 2) {
+ const VertFilter<kTaps, decltype(u8_32)> filt32(filter_y);
+ V16 r_init[kTaps - 1];
+ for (int i = 0; i < kTaps - 1; ++i) {
+ r_init[i] = Load8BytesIn16(src + i * src_stride);
+ }
+ V32 p[kPairs];
+ for (int i = 0; i < kPairs - 1; ++i) {
+ p[i] = hn::InterleaveLower(
+ u8_32, hn::Combine(u8_32, r_init[2 * i + 1], r_init[2 * i]),
+ hn::Combine(u8_32, r_init[2 * i + 2], r_init[2 * i + 1]));
+ }
+ V16 r_last = r_init[kTaps - 2];
+ while (h >= 2) {
+ const V16 rn0 = Load8BytesIn16(src + (kTaps - 1) * src_stride);
+ const V16 rn1 = Load8BytesIn16(src + kTaps * src_stride);
+ p[kPairs - 1] = hn::InterleaveLower(
+ u8_32, hn::Combine(u8_32, rn0, r_last), hn::Combine(u8_32, rn1, rn0));
+ const auto res = filt32.Apply(p);
+ const auto packed = hn::ReorderDemote2To(u8_32, res, res);
+ StoreSmallRow<8>(hn::LowerHalf(u8_16, packed), dst);
+ StoreSmallRow<8>(hn::UpperHalf(u8_16, packed), dst + dst_stride);
+ ShiftLeft1(p);
+ r_last = rn1;
+ src += 2 * src_stride;
+ dst += 2 * dst_stride;
+ h -= 2;
+ }
+ }
+ if (h & 1) {
+ const VertFilter<kTaps, decltype(u8_16)> filt16(filter_y);
+ V16 p[kPairs];
+ for (int i = 0; i < kPairs; ++i) {
+ const V16 r0 = Load8BytesIn16(src + 2 * i * src_stride);
+ const V16 r1 = Load8BytesIn16(src + (2 * i + 1) * src_stride);
+ p[i] = hn::InterleaveLower(u8_16, r0, r1);
+ }
+ const auto res = filt16.Apply(p);
+ StoreSmallRow<8>(hn::ReorderDemote2To(u8_16, res, res), dst);
+ }
+}
- const bool can_use_optimized_path =
- (w <= 32) && (filter_x[0] % 2 == 0) && (filter_x[1] % 2 == 0) &&
- (filter_x[2] % 2 == 0) && (filter_x[3] % 2 == 0) &&
- (filter_x[4] % 2 == 0) && (filter_x[5] % 2 == 0) &&
- (filter_x[6] % 2 == 0) && (filter_x[7] % 2 == 0);
-
- if (can_use_optimized_path) {
- hn::CappedTag<uint8_t, 16> tag8_16;
- hn::CappedTag<int8_t, 16> tag_i8;
- hn::CappedTag<int16_t, 8> tag16_8;
- hn::CappedTag<uint8_t, 8> tag8_8;
- hn::CappedTag<uint8_t, 4> tag8_4;
- const auto bias_val = hn::Set(tag16_8, 1 << (FILTER_BITS - 2));
-
- const auto shuffle_mask = hn::Dup128VecFromValues(
- tag8_16, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8);
-
- const int8_t c0 = static_cast<int8_t>(filter_x[0] / 2);
- const int8_t c1 = static_cast<int8_t>(filter_x[1] / 2);
- const int8_t c2 = static_cast<int8_t>(filter_x[2] / 2);
- const int8_t c3 = static_cast<int8_t>(filter_x[3] / 2);
- const int8_t c4 = static_cast<int8_t>(filter_x[4] / 2);
- const int8_t c5 = static_cast<int8_t>(filter_x[5] / 2);
- const int8_t c6 = static_cast<int8_t>(filter_x[6] / 2);
- const int8_t c7 = static_cast<int8_t>(filter_x[7] / 2);
-
- const auto coeff01 = hn::Dup128VecFromValues(
- tag_i8, c0, c1, c0, c1, c0, c1, c0, c1, c0, c1, c0, c1, c0, c1, c0, c1);
-
- const auto coeff23 = hn::Dup128VecFromValues(
- tag_i8, c2, c3, c2, c3, c2, c3, c2, c3, c2, c3, c2, c3, c2, c3, c2, c3);
-
- const auto coeff45 = hn::Dup128VecFromValues(
- tag_i8, c4, c5, c4, c5, c4, c5, c4, c5, c4, c5, c4, c5, c4, c5, c4, c5);
-
- const auto coeff67 = hn::Dup128VecFromValues(
- tag_i8, c6, c7, c6, c7, c6, c7, c6, c7, c6, c7, c6, c7, c6, c7, c6, c7);
-
- auto sum_8tap = [&](const uint8_t *s, int offset) {
- return ComputeChunkSum8Tap(tag16_8, tag8_16, s, offset, shuffle_mask,
- coeff01, coeff23, coeff45, coeff67);
- };
-
- if (w == 4) {
- while (h >= 2) {
- Process2RowsChunk<4>(tag8_8, tag8_4, src, src_stride, dst, dst_stride,
- 0, bias_val, sum_8tap);
- src += 2 * src_stride;
- dst += 2 * dst_stride;
- h -= 2;
- }
- if (h & 1) {
- Process1RowChunk<4>(tag8_8, tag8_4, src, dst, 0, bias_val, sum_8tap);
- }
- } else if (w == 8) {
- while (h >= 2) {
- Process2RowsChunk<8>(tag8_8, tag8_4, src, src_stride, dst, dst_stride,
- 0, bias_val, sum_8tap);
- src += 2 * src_stride;
- dst += 2 * dst_stride;
- h -= 2;
- }
- if (h & 1) {
- Process1RowChunk<8>(tag8_8, tag8_4, src, dst, 0, bias_val, sum_8tap);
- }
- } else if (w == 16) {
- while (h >= 2) {
- Process2RowsChunk<8>(tag8_8, tag8_4, src, src_stride, dst, dst_stride,
- 0, bias_val, sum_8tap);
- Process2RowsChunk<8>(tag8_8, tag8_4, src, src_stride, dst, dst_stride,
- 8, bias_val, sum_8tap);
- src += 2 * src_stride;
- dst += 2 * dst_stride;
- h -= 2;
+#if HWY_TARGET <= HWY_AVX3
+template <int kTaps>
+HWY_ATTR HWY_NOINLINE void ConvolveVertEvenStrip64(
+ const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst,
+ ptrdiff_t dst_stride, const int16_t *filter_y, int w, int h) {
+ constexpr int kPairs = kTaps / 2;
+ constexpr hn::CappedTag<uint8_t, 64> u8_64;
+ using V64 = hn::VFromD<decltype(u8_64)>;
+
+ const VertFilter<kTaps, decltype(u8_64)> filt64(filter_y);
+ for (int x = 0; x < w; x += 64) {
+ const uint8_t *s = src + x;
+ uint8_t *d = dst + x;
+ int rem = h;
+ if constexpr (kTaps == 2) {
+ V64 r0 = hn::LoadU(u8_64, s);
+ for (int y = 0; y < rem; ++y) {
+ const V64 r1 = hn::LoadU(u8_64, s + (y + 1) * src_stride);
+ const V64 p_lo[1] = { hn::InterleaveLower(u8_64, r0, r1) };
+ const V64 p_hi[1] = { hn::InterleaveUpper(u8_64, r0, r1) };
+ hn::StoreU(
+ hn::ReorderDemote2To(u8_64, filt64.Apply(p_lo), filt64.Apply(p_hi)),
+ u8_64, d + y * dst_stride);
+ r0 = r1;
}
- if (h & 1) {
- Process1RowChunk<8>(tag8_8, tag8_4, src, dst, 0, bias_val, sum_8tap);
- Process1RowChunk<8>(tag8_8, tag8_4, src, dst, 8, bias_val, sum_8tap);
+ } else {
+ V64 r_init[kTaps - 1];
+ for (int i = 0; i < kTaps - 1; ++i) {
+ r_init[i] = hn::LoadU(u8_64, s + i * src_stride);
}
- } else if (w == 32) {
- while (h >= 2) {
- Process2RowsChunk<8>(tag8_8, tag8_4, src, src_stride, dst, dst_stride,
- 0, bias_val, sum_8tap);
- Process2RowsChunk<8>(tag8_8, tag8_4, src, src_stride, dst, dst_stride,
- 8, bias_val, sum_8tap);
- Process2RowsChunk<8>(tag8_8, tag8_4, src, src_stride, dst, dst_stride,
- 16, bias_val, sum_8tap);
- Process2RowsChunk<8>(tag8_8, tag8_4, src, src_stride, dst, dst_stride,
- 24, bias_val, sum_8tap);
- src += 2 * src_stride;
- dst += 2 * dst_stride;
- h -= 2;
+ V64 e_lo[kPairs], e_hi[kPairs];
+ V64 o_lo[kPairs], o_hi[kPairs];
+ for (int i = 0; i < kPairs - 1; ++i) {
+ e_lo[i] = hn::InterleaveLower(u8_64, r_init[2 * i], r_init[2 * i + 1]);
+ e_hi[i] = hn::InterleaveUpper(u8_64, r_init[2 * i], r_init[2 * i + 1]);
+ o_lo[i] =
+ hn::InterleaveLower(u8_64, r_init[2 * i + 1], r_init[2 * i + 2]);
+ o_hi[i] =
+ hn::InterleaveUpper(u8_64, r_init[2 * i + 1], r_init[2 * i + 2]);
}
- if (h & 1) {
- for (int j = 0; j < 32; j += 8) {
- Process1RowChunk<8>(tag8_8, tag8_4, src, dst, j, bias_val, sum_8tap);
- }
+ V64 r_last = r_init[kTaps - 2];
+ while (rem >= 2) {
+ const V64 rn0 = hn::LoadU(u8_64, s + (kTaps - 1) * src_stride);
+ e_lo[kPairs - 1] = hn::InterleaveLower(u8_64, r_last, rn0);
+ e_hi[kPairs - 1] = hn::InterleaveUpper(u8_64, r_last, rn0);
+ hn::StoreU(
+ hn::ReorderDemote2To(u8_64, filt64.Apply(e_lo), filt64.Apply(e_hi)),
+ u8_64, d);
+
+ const V64 rn1 = hn::LoadU(u8_64, s + kTaps * src_stride);
+ o_lo[kPairs - 1] = hn::InterleaveLower(u8_64, rn0, rn1);
+ o_hi[kPairs - 1] = hn::InterleaveUpper(u8_64, rn0, rn1);
+ hn::StoreU(
+ hn::ReorderDemote2To(u8_64, filt64.Apply(o_lo), filt64.Apply(o_hi)),
+ u8_64, d + dst_stride);
+
+ ShiftLeft1(e_lo);
+ ShiftLeft1(e_hi);
+ ShiftLeft1(o_lo);
+ ShiftLeft1(o_hi);
+ r_last = rn1;
+ s += 2 * src_stride;
+ d += 2 * dst_stride;
+ rem -= 2;
}
- }
- } else {
- hn::CappedTag<int16_t, 8> filter_tag;
- auto f_vec = hn::LoadU(filter_tag, filter_x);
- f_vec = hn::ShiftRight<1>(f_vec);
- hn::ScalableTag<int16_t> mul_tag;
- hn::Rebind<uint8_t, decltype(mul_tag)> pixel_tag;
- auto vw = hn::Lanes(mul_tag);
- for (int i = 0; i < h; ++i) {
- for (int j = 0; j < w; j += vw) {
- auto s0 = hn::LoadU(pixel_tag, &src[j]);
- auto s1 = hn::LoadU(pixel_tag, &src[j + 1]);
- auto s2 = hn::LoadU(pixel_tag, &src[j + 2]);
- auto s3 = hn::LoadU(pixel_tag, &src[j + 3]);
- auto s4 = hn::LoadU(pixel_tag, &src[j + 4]);
- auto s5 = hn::LoadU(pixel_tag, &src[j + 5]);
- auto s6 = hn::LoadU(pixel_tag, &src[j + 6]);
- auto s7 = hn::LoadU(pixel_tag, &src[j + 7]);
- auto src0 = hn::PromoteTo(mul_tag, s0);
- auto src1 = hn::PromoteTo(mul_tag, s1);
- auto src2 = hn::PromoteTo(mul_tag, s2);
- auto src3 = hn::PromoteTo(mul_tag, s3);
- auto src4 = hn::PromoteTo(mul_tag, s4);
- auto src5 = hn::PromoteTo(mul_tag, s5);
- auto src6 = hn::PromoteTo(mul_tag, s6);
- auto src7 = hn::PromoteTo(mul_tag, s7);
- auto result = Convolve8_8(mul_tag, filter_tag, src0, src1, src2, src3,
- src4, src5, src6, src7, f_vec);
- auto result_demoted = hn::DemoteTo(pixel_tag, result);
- if (j + static_cast<int>(vw) > w) {
- hn::StoreN(result_demoted, pixel_tag, &dst[j], w - j);
- } else {
- hn::StoreU(result_demoted, pixel_tag, &dst[j]);
- }
+ if (rem & 1) {
+ const V64 rn0 = hn::LoadU(u8_64, s + (kTaps - 1) * src_stride);
+ e_lo[kPairs - 1] = hn::InterleaveLower(u8_64, r_last, rn0);
+ e_hi[kPairs - 1] = hn::InterleaveUpper(u8_64, r_last, rn0);
+ hn::StoreU(
+ hn::ReorderDemote2To(u8_64, filt64.Apply(e_lo), filt64.Apply(e_hi)),
+ u8_64, d);
}
- src += src_stride;
- dst += dst_stride;
}
}
}
+#endif // HWY_TARGET <= HWY_AVX3
-HWY_ATTR inline void ConvolveVert2Tap(const uint8_t *src, ptrdiff_t src_stride,
- uint8_t *dst, ptrdiff_t dst_stride,
- const int16_t *filter_y, int w, int h) {
- hn::CappedTag<int16_t, 16> tag16;
- hn::Rebind<uint8_t, decltype(tag16)> pixel_tag;
-
- auto f0 = hn::Set(tag16, filter_y[3]);
- auto f1 = hn::Set(tag16, filter_y[4]);
- auto round_offset = hn::Set(tag16, 1 << (FILTER_BITS - 1));
-
- if (w == 4) {
- for (int y = 0; y < h; y += 4) {
- auto s0 = LoadUnaligned4x4(tag16, src + y * src_stride, src_stride);
- auto s1 = LoadUnaligned4x4(tag16, src + (y + 1) * src_stride, src_stride);
- auto res = hn::ShiftRight<FILTER_BITS>(s0 * f0 + s1 * f1 + round_offset);
- StoreUnaligned4x4(tag16, dst + y * dst_stride, dst_stride, res);
+template <int kTaps, int kStripW>
+HWY_ATTR HWY_NOINLINE void ConvolveVertEvenStrip2Rows(
+ const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst,
+ ptrdiff_t dst_stride, const int16_t *filter_y, int w, int h) {
+ constexpr int kPairs = kTaps / 2;
+ constexpr hn::CappedTag<uint8_t, kStripW> d1;
+ constexpr hn::CappedTag<uint8_t, 2 * kStripW> d2;
+ using V1 = hn::VFromD<decltype(d1)>;
+ using V2 = hn::VFromD<decltype(d2)>;
+
+ const VertFilter<kTaps, decltype(d2)> filt2(filter_y);
+ for (int x = 0; x < w; x += kStripW) {
+ const uint8_t *s = src + x;
+ uint8_t *d = dst + x;
+ int rem = h;
+ V1 r_init[kTaps - 1];
+ for (int i = 0; i < kTaps - 1; ++i) {
+ r_init[i] = hn::LoadU(d1, s + i * src_stride);
}
- } else if (w == 8) {
- for (int y = 0; y < h; y += 4) {
- auto s0 = LoadUnaligned2x8(tag16, src + y * src_stride, src_stride);
- auto s1 = LoadUnaligned2x8(tag16, src + (y + 1) * src_stride, src_stride);
- auto s2 = LoadUnaligned2x8(tag16, src + (y + 2) * src_stride, src_stride);
- auto s3 = LoadUnaligned2x8(tag16, src + (y + 3) * src_stride, src_stride);
- auto res0 = hn::ShiftRight<FILTER_BITS>(s0 * f0 + s1 * f1 + round_offset);
- auto res1 = hn::ShiftRight<FILTER_BITS>(s2 * f0 + s3 * f1 + round_offset);
- StoreUnaligned2x8(tag16, dst + y * dst_stride, dst_stride, res0);
- StoreUnaligned2x8(tag16, dst + (y + 2) * dst_stride, dst_stride, res1);
+ V2 p_lo[kPairs];
+ V2 p_hi[kPairs];
+ for (int i = 0; i < kPairs - 1; ++i) {
+ const V2 a = hn::Combine(d2, r_init[2 * i + 1], r_init[2 * i]);
+ const V2 b = hn::Combine(d2, r_init[2 * i + 2], r_init[2 * i + 1]);
+ p_lo[i] = hn::InterleaveLower(d2, a, b);
+ p_hi[i] = hn::InterleaveUpper(d2, a, b);
}
- } else if (w == 16) {
- constexpr hn::Half<decltype(tag16)> half_tag16;
- auto s0 = hn::PromoteTo(tag16, hn::LoadU(pixel_tag, src));
- for (int y = 0; y < h; y += 4) {
- auto s1 = hn::PromoteTo(tag16,
- hn::LoadU(pixel_tag, src + (y + 1) * src_stride));
- auto s2 = hn::PromoteTo(tag16,
- hn::LoadU(pixel_tag, src + (y + 2) * src_stride));
- auto s3 = hn::PromoteTo(tag16,
- hn::LoadU(pixel_tag, src + (y + 3) * src_stride));
- auto s4 = hn::PromoteTo(tag16,
- hn::LoadU(pixel_tag, src + (y + 4) * src_stride));
-
- auto res0 = hn::ShiftRight<FILTER_BITS>(s0 * f0 + s1 * f1 + round_offset);
- auto res1 = hn::ShiftRight<FILTER_BITS>(s1 * f0 + s2 * f1 + round_offset);
- auto res2 = hn::ShiftRight<FILTER_BITS>(s2 * f0 + s3 * f1 + round_offset);
- auto res3 = hn::ShiftRight<FILTER_BITS>(s3 * f0 + s4 * f1 + round_offset);
-
- hn::StoreU(
- hn::ReorderDemote2To(pixel_tag, hn::LowerHalf(half_tag16, res0),
- hn::UpperHalf(half_tag16, res0)),
- pixel_tag, dst + y * dst_stride);
- hn::StoreU(
- hn::ReorderDemote2To(pixel_tag, hn::LowerHalf(half_tag16, res1),
- hn::UpperHalf(half_tag16, res1)),
- pixel_tag, dst + (y + 1) * dst_stride);
- hn::StoreU(
- hn::ReorderDemote2To(pixel_tag, hn::LowerHalf(half_tag16, res2),
- hn::UpperHalf(half_tag16, res2)),
- pixel_tag, dst + (y + 2) * dst_stride);
- hn::StoreU(
- hn::ReorderDemote2To(pixel_tag, hn::LowerHalf(half_tag16, res3),
- hn::UpperHalf(half_tag16, res3)),
- pixel_tag, dst + (y + 3) * dst_stride);
-
- s0 = s4;
+ V1 r_last = r_init[kTaps - 2];
+ while (rem >= 2) {
+ const V1 rn0 = hn::LoadU(d1, s + (kTaps - 1) * src_stride);
+ const V1 rn1 = hn::LoadU(d1, s + kTaps * src_stride);
+ const V2 a = hn::Combine(d2, rn0, r_last);
+ const V2 b = hn::Combine(d2, rn1, rn0);
+ p_lo[kPairs - 1] = hn::InterleaveLower(d2, a, b);
+ p_hi[kPairs - 1] = hn::InterleaveUpper(d2, a, b);
+ const auto packed =
+ hn::ReorderDemote2To(d2, filt2.Apply(p_lo), filt2.Apply(p_hi));
+ hn::StoreU(hn::LowerHalf(d1, packed), d1, d);
+ hn::StoreU(hn::UpperHalf(d1, packed), d1, d + dst_stride);
+ ShiftLeft1(p_lo);
+ ShiftLeft1(p_hi);
+ r_last = rn1;
+ s += 2 * src_stride;
+ d += 2 * dst_stride;
+ rem -= 2;
}
- } else {
- hn::ScalableTag<int16_t> mul_tag;
- hn::Rebind<uint8_t, decltype(mul_tag)> p_tag;
- auto f0_s = hn::Set(mul_tag, filter_y[3]);
- auto f1_s = hn::Set(mul_tag, filter_y[4]);
- auto round_offset_s = hn::Set(mul_tag, 1 << (FILTER_BITS - 1));
- auto vw = hn::Lanes(mul_tag);
- for (int x = 0; x < w; x += vw) {
- auto s0 = hn::PromoteTo(mul_tag, hn::LoadU(p_tag, src + x));
- for (int y = 0; y < h; ++y) {
- auto s1 = hn::PromoteTo(
- mul_tag, hn::LoadU(p_tag, src + x + (y + 1) * src_stride));
- auto res =
- hn::ShiftRight<FILTER_BITS>(s0 * f0_s + s1 * f1_s + round_offset_s);
- auto res_demoted = hn::DemoteTo(p_tag, res);
- if (x + static_cast<int>(vw) > w) {
- hn::StoreN(res_demoted, p_tag, dst + x + y * dst_stride, w - x);
- } else {
- hn::StoreU(res_demoted, p_tag, dst + x + y * dst_stride);
- }
- s0 = s1;
+ if (rem & 1) {
+ const auto filt1 = filt2.LowerHalf();
+ const V1 rn0 = hn::LoadU(d1, s + (kTaps - 1) * src_stride);
+ V1 p1_lo[kPairs], p1_hi[kPairs];
+ for (int i = 0; i < kPairs - 1; ++i) {
+ p1_lo[i] = hn::LowerHalf(d1, p_lo[i]);
+ p1_hi[i] = hn::LowerHalf(d1, p_hi[i]);
}
+ p1_lo[kPairs - 1] = hn::InterleaveLower(d1, r_last, rn0);
+ p1_hi[kPairs - 1] = hn::InterleaveUpper(d1, r_last, rn0);
+ hn::StoreU(
+ hn::ReorderDemote2To(d1, filt1.Apply(p1_lo), filt1.Apply(p1_hi)), d1,
+ d);
}
}
}
+#endif // AOM_CONVOLVE_HWY_X86_PAIRWISE
-HWY_ATTR inline void ConvolveVert4Tap(const uint8_t *src, ptrdiff_t src_stride,
- uint8_t *dst, ptrdiff_t dst_stride,
- const int16_t *filter_y, int w, int h) {
- hn::CappedTag<int16_t, 16> tag16;
- hn::Rebind<uint8_t, decltype(tag16)> pixel_tag;
-
- auto f0 = hn::Set(tag16, filter_y[2] >> 1);
- auto f1 = hn::Set(tag16, filter_y[3] >> 1);
- auto f2 = hn::Set(tag16, filter_y[4] >> 1);
- auto f3 = hn::Set(tag16, filter_y[5] >> 1);
- auto round_offset = hn::Set(tag16, 1 << (FILTER_BITS - 2));
-
- if (w == 4) {
- for (int y = 0; y < h; y += 4) {
- auto s0 = LoadUnaligned4x4(tag16, src + y * src_stride, src_stride);
- auto s1 = LoadUnaligned4x4(tag16, src + (y + 1) * src_stride, src_stride);
- auto s2 = LoadUnaligned4x4(tag16, src + (y + 2) * src_stride, src_stride);
- auto s3 = LoadUnaligned4x4(tag16, src + (y + 3) * src_stride, src_stride);
- auto res = hn::ShiftRight<FILTER_BITS - 1>(s0 * f0 + s1 * f1 + s2 * f2 +
- s3 * f3 + round_offset);
- StoreUnaligned4x4(tag16, dst + y * dst_stride, dst_stride, res);
- }
- } else if (w == 8) {
- auto s0 = LoadUnaligned2x8(tag16, src + 0 * src_stride, src_stride);
- auto s1 = LoadUnaligned2x8(tag16, src + 1 * src_stride, src_stride);
- for (int y = 0; y < h; y += 4) {
- auto s2 = LoadUnaligned2x8(tag16, src + (y + 2) * src_stride, src_stride);
- auto s3 = LoadUnaligned2x8(tag16, src + (y + 3) * src_stride, src_stride);
- auto s4 = LoadUnaligned2x8(tag16, src + (y + 4) * src_stride, src_stride);
- auto s5 = LoadUnaligned2x8(tag16, src + (y + 5) * src_stride, src_stride);
- auto res0 = hn::ShiftRight<FILTER_BITS - 1>(s0 * f0 + s1 * f1 + s2 * f2 +
- s3 * f3 + round_offset);
- auto res1 = hn::ShiftRight<FILTER_BITS - 1>(s2 * f0 + s3 * f1 + s4 * f2 +
- s5 * f3 + round_offset);
- StoreUnaligned2x8(tag16, dst + y * dst_stride, dst_stride, res0);
- StoreUnaligned2x8(tag16, dst + (y + 2) * dst_stride, dst_stride, res1);
- s0 = s4;
- s1 = s5;
- }
- } else if (w == 16) {
- constexpr hn::Half<decltype(tag16)> half_tag16;
- auto s0 = hn::PromoteTo(tag16, hn::LoadU(pixel_tag, src + 0 * src_stride));
- auto s1 = hn::PromoteTo(tag16, hn::LoadU(pixel_tag, src + 1 * src_stride));
- auto s2 = hn::PromoteTo(tag16, hn::LoadU(pixel_tag, src + 2 * src_stride));
- for (int y = 0; y < h; y += 4) {
- auto s3 = hn::PromoteTo(tag16,
- hn::LoadU(pixel_tag, src + (y + 3) * src_stride));
- auto s4 = hn::PromoteTo(tag16,
- hn::LoadU(pixel_tag, src + (y + 4) * src_stride));
- auto s5 = hn::PromoteTo(tag16,
- hn::LoadU(pixel_tag, src + (y + 5) * src_stride));
- auto s6 = hn::PromoteTo(tag16,
- hn::LoadU(pixel_tag, src + (y + 6) * src_stride));
-
- auto res0 = hn::ShiftRight<FILTER_BITS - 1>(s0 * f0 + s1 * f1 + s2 * f2 +
- s3 * f3 + round_offset);
- auto res1 = hn::ShiftRight<FILTER_BITS - 1>(s1 * f0 + s2 * f1 + s3 * f2 +
- s4 * f3 + round_offset);
- auto res2 = hn::ShiftRight<FILTER_BITS - 1>(s2 * f0 + s3 * f1 + s4 * f2 +
- s5 * f3 + round_offset);
- auto res3 = hn::ShiftRight<FILTER_BITS - 1>(s3 * f0 + s4 * f1 + s5 * f2 +
- s6 * f3 + round_offset);
-
- hn::StoreU(
- hn::ReorderDemote2To(pixel_tag, hn::LowerHalf(half_tag16, res0),
- hn::UpperHalf(half_tag16, res0)),
- pixel_tag, dst + y * dst_stride);
- hn::StoreU(
- hn::ReorderDemote2To(pixel_tag, hn::LowerHalf(half_tag16, res1),
- hn::UpperHalf(half_tag16, res1)),
- pixel_tag, dst + (y + 1) * dst_stride);
- hn::StoreU(
- hn::ReorderDemote2To(pixel_tag, hn::LowerHalf(half_tag16, res2),
- hn::UpperHalf(half_tag16, res2)),
- pixel_tag, dst + (y + 2) * dst_stride);
- hn::StoreU(
- hn::ReorderDemote2To(pixel_tag, hn::LowerHalf(half_tag16, res3),
- hn::UpperHalf(half_tag16, res3)),
- pixel_tag, dst + (y + 3) * dst_stride);
+template <int kTaps>
+HWY_ATTR HWY_NOINLINE void ConvolveVertFallback(
+ const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst,
+ ptrdiff_t dst_stride, const int16_t *filter_y, int w, int h) {
+ constexpr int kStart = 4 - kTaps / 2;
+ using MulElem = typename std::conditional<kTaps == 2, int16_t, int32_t>::type;
+ hn::ScalableTag<MulElem> mul_tag;
+ hn::Rebind<int16_t, decltype(mul_tag)> i16_tag;
+ hn::Rebind<uint8_t, decltype(mul_tag)> p_tag;
+ using V = hn::VFromD<decltype(mul_tag)>;
+
+ V f[kTaps];
+ for (int i = 0; i < kTaps; ++i) {
+ f[i] = hn::Set(mul_tag, filter_y[kStart + i]);
+ }
+ const V round_offset = hn::Set(mul_tag, 1 << (FILTER_BITS - 1));
+ const int vw = static_cast<int>(hn::Lanes(mul_tag));
- s0 = s4;
- s1 = s5;
- s2 = s6;
+ for (int x = 0; x < w; x += vw) {
+ V s[kTaps - 1];
+ for (int i = 0; i < kTaps - 1; ++i) {
+ s[i] = hn::PromoteTo(mul_tag, hn::LoadU(p_tag, src + x + i * src_stride));
}
- } else {
- hn::ScalableTag<int16_t> mul_tag;
- hn::Rebind<uint8_t, decltype(mul_tag)> p_tag;
- auto f0_s = hn::Set(mul_tag, filter_y[2] >> 1);
- auto f1_s = hn::Set(mul_tag, filter_y[3] >> 1);
- auto f2_s = hn::Set(mul_tag, filter_y[4] >> 1);
- auto f3_s = hn::Set(mul_tag, filter_y[5] >> 1);
- auto round_offset_s = hn::Set(mul_tag, 1 << (FILTER_BITS - 2));
- auto vw = hn::Lanes(mul_tag);
- for (int x = 0; x < w; x += vw) {
- auto s0 = hn::PromoteTo(mul_tag, hn::LoadU(p_tag, src + x));
- auto s1 =
- hn::PromoteTo(mul_tag, hn::LoadU(p_tag, src + x + 1 * src_stride));
- auto s2 =
- hn::PromoteTo(mul_tag, hn::LoadU(p_tag, src + x + 2 * src_stride));
- for (int y = 0; y < h; ++y) {
- auto s3 = hn::PromoteTo(
- mul_tag, hn::LoadU(p_tag, src + x + (y + 3) * src_stride));
- auto res = hn::ShiftRight<FILTER_BITS - 1>(
- s0 * f0_s + s1 * f1_s + s2 * f2_s + s3 * f3_s + round_offset_s);
- auto res_demoted = hn::DemoteTo(p_tag, res);
- if (x + static_cast<int>(vw) > w) {
- hn::StoreN(res_demoted, p_tag, dst + x + y * dst_stride, w - x);
- } else {
- hn::StoreU(res_demoted, p_tag, dst + x + y * dst_stride);
- }
- s0 = s1;
- s1 = s2;
- s2 = s3;
+ for (int y = 0; y < h; ++y) {
+ const V s_last = hn::PromoteTo(
+ mul_tag, hn::LoadU(p_tag, src + x + (y + kTaps - 1) * src_stride));
+ V sum = round_offset;
+ for (int i = 0; i < kTaps - 1; ++i) {
+ sum = sum + s[i] * f[i];
+ }
+ sum = sum + s_last * f[kTaps - 1];
+ const auto res = hn::ShiftRight<FILTER_BITS>(sum);
+ hn::VFromD<decltype(p_tag)> res_demoted;
+ if constexpr (kTaps == 2) {
+ res_demoted = hn::DemoteTo(p_tag, res);
+ } else {
+ res_demoted = hn::DemoteTo(p_tag, hn::DemoteTo(i16_tag, res));
}
+ if (x + vw > w) {
+ hn::StoreN(res_demoted, p_tag, dst + x + y * dst_stride, w - x);
+ } else {
+ hn::StoreU(res_demoted, p_tag, dst + x + y * dst_stride);
+ }
+ ShiftLeft1(s);
+ s[kTaps - 2] = s_last;
}
}
}
-HWY_ATTR inline void ConvolveVert8Tap(const uint8_t *src, ptrdiff_t src_stride,
+template <int kTaps>
+HWY_ATTR HWY_INLINE void ConvolveVert(const uint8_t *src, ptrdiff_t src_stride,
uint8_t *dst, ptrdiff_t dst_stride,
const int16_t *filter_y, int w, int h) {
- hn::CappedTag<int16_t, 16> tag16;
- hn::Rebind<uint8_t, decltype(tag16)> pixel_tag;
-
- auto f0 = hn::Set(tag16, filter_y[0] >> 1);
- auto f1 = hn::Set(tag16, filter_y[1] >> 1);
- auto f2 = hn::Set(tag16, filter_y[2] >> 1);
- auto f3 = hn::Set(tag16, filter_y[3] >> 1);
- auto f4 = hn::Set(tag16, filter_y[4] >> 1);
- auto f5 = hn::Set(tag16, filter_y[5] >> 1);
- auto f6 = hn::Set(tag16, filter_y[6] >> 1);
- auto f7 = hn::Set(tag16, filter_y[7] >> 1);
- auto round_offset = hn::Set(tag16, 1 << (FILTER_BITS - 2));
-
- if (w == 4) {
- for (int y = 0; y < h; y += 4) {
- auto s0 = LoadUnaligned4x4(tag16, src + (y + 0) * src_stride, src_stride);
- auto s1 = LoadUnaligned4x4(tag16, src + (y + 1) * src_stride, src_stride);
- auto s2 = LoadUnaligned4x4(tag16, src + (y + 2) * src_stride, src_stride);
- auto s3 = LoadUnaligned4x4(tag16, src + (y + 3) * src_stride, src_stride);
- auto s4 = LoadUnaligned4x4(tag16, src + (y + 4) * src_stride, src_stride);
- auto s5 = LoadUnaligned4x4(tag16, src + (y + 5) * src_stride, src_stride);
- auto s6 = LoadUnaligned4x4(tag16, src + (y + 6) * src_stride, src_stride);
- auto s7 = LoadUnaligned4x4(tag16, src + (y + 7) * src_stride, src_stride);
- auto res = hn::ShiftRight<FILTER_BITS - 1>(
- s0 * f0 + s1 * f1 + s2 * f2 + s3 * f3 + s4 * f4 + s5 * f5 + s6 * f6 +
- s7 * f7 + round_offset);
- StoreUnaligned4x4(tag16, dst + y * dst_stride, dst_stride, res);
- }
- } else if (w == 8) {
- auto s0 = LoadUnaligned2x8(tag16, src + 0 * src_stride, src_stride);
- auto s1 = LoadUnaligned2x8(tag16, src + 1 * src_stride, src_stride);
- auto s2 = LoadUnaligned2x8(tag16, src + 2 * src_stride, src_stride);
- auto s3 = LoadUnaligned2x8(tag16, src + 3 * src_stride, src_stride);
- auto s4 = LoadUnaligned2x8(tag16, src + 4 * src_stride, src_stride);
- auto s5 = LoadUnaligned2x8(tag16, src + 5 * src_stride, src_stride);
- for (int y = 0; y < h; y += 2) {
- auto s6 = LoadUnaligned2x8(tag16, src + (y + 6) * src_stride, src_stride);
- auto s7 = LoadUnaligned2x8(tag16, src + (y + 7) * src_stride, src_stride);
- auto res = hn::ShiftRight<FILTER_BITS - 1>(
- s0 * f0 + s1 * f1 + s2 * f2 + s3 * f3 + s4 * f4 + s5 * f5 + s6 * f6 +
- s7 * f7 + round_offset);
- StoreUnaligned2x8(tag16, dst + y * dst_stride, dst_stride, res);
- s0 = s2;
- s1 = s3;
- s2 = s4;
- s3 = s5;
- s4 = s6;
- s5 = s7;
+#if AOM_CONVOLVE_HWY_X86_PAIRWISE
+ if (AreTapsEven<kTaps>(filter_y)) {
+ if (w == 4) {
+ ConvolveVertEvenW4<kTaps>(src, src_stride, dst, dst_stride, filter_y, h);
+ return;
}
- } else if (w == 16) {
- constexpr hn::Half<decltype(tag16)> half_tag16;
- auto s0 = hn::PromoteTo(tag16, hn::LoadU(pixel_tag, src + 0 * src_stride));
- auto s1 = hn::PromoteTo(tag16, hn::LoadU(pixel_tag, src + 1 * src_stride));
- auto s2 = hn::PromoteTo(tag16, hn::LoadU(pixel_tag, src + 2 * src_stride));
- auto s3 = hn::PromoteTo(tag16, hn::LoadU(pixel_tag, src + 3 * src_stride));
- auto s4 = hn::PromoteTo(tag16, hn::LoadU(pixel_tag, src + 4 * src_stride));
- auto s5 = hn::PromoteTo(tag16, hn::LoadU(pixel_tag, src + 5 * src_stride));
- auto s6 = hn::PromoteTo(tag16, hn::LoadU(pixel_tag, src + 6 * src_stride));
- for (int y = 0; y < h; ++y) {
- auto s7 = hn::PromoteTo(tag16,
- hn::LoadU(pixel_tag, src + (y + 7) * src_stride));
- auto res = hn::ShiftRight<FILTER_BITS - 1>(
- s0 * f0 + s1 * f1 + s2 * f2 + s3 * f3 + s4 * f4 + s5 * f5 + s6 * f6 +
- s7 * f7 + round_offset);
- hn::StoreU(hn::ReorderDemote2To(pixel_tag, hn::LowerHalf(half_tag16, res),
- hn::UpperHalf(half_tag16, res)),
- pixel_tag, dst + y * dst_stride);
- s0 = s1;
- s1 = s2;
- s2 = s3;
- s3 = s4;
- s4 = s5;
- s5 = s6;
- s6 = s7;
+ if (w == 8) {
+#if HWY_TARGET <= HWY_AVX3
+ if (h >= 4) {
+ ConvolveVertEvenZmm4Rows<kTaps, 8>(src, src_stride, dst, dst_stride,
+ filter_y, h);
+ const int done = h & ~3;
+ src += done * src_stride;
+ dst += done * dst_stride;
+ h &= 3;
+ if (h == 0) return;
+ }
+#endif
+ ConvolveVertEvenW8<kTaps>(src, src_stride, dst, dst_stride, filter_y, h);
+ return;
}
- } else {
- hn::ScalableTag<int16_t> mul_tag;
- hn::Rebind<uint8_t, decltype(mul_tag)> p_tag;
- auto f0_s = hn::Set(mul_tag, filter_y[0] >> 1);
- auto f1_s = hn::Set(mul_tag, filter_y[1] >> 1);
- auto f2_s = hn::Set(mul_tag, filter_y[2] >> 1);
- auto f3_s = hn::Set(mul_tag, filter_y[3] >> 1);
- auto f4_s = hn::Set(mul_tag, filter_y[4] >> 1);
- auto f5_s = hn::Set(mul_tag, filter_y[5] >> 1);
- auto f6_s = hn::Set(mul_tag, filter_y[6] >> 1);
- auto f7_s = hn::Set(mul_tag, filter_y[7] >> 1);
- auto round_offset_s = hn::Set(mul_tag, 1 << (FILTER_BITS - 2));
- auto vw = hn::Lanes(mul_tag);
- for (int x = 0; x < w; x += vw) {
- auto s0 =
- hn::PromoteTo(mul_tag, hn::LoadU(p_tag, src + x + 0 * src_stride));
- auto s1 =
- hn::PromoteTo(mul_tag, hn::LoadU(p_tag, src + x + 1 * src_stride));
- auto s2 =
- hn::PromoteTo(mul_tag, hn::LoadU(p_tag, src + x + 2 * src_stride));
- auto s3 =
- hn::PromoteTo(mul_tag, hn::LoadU(p_tag, src + x + 3 * src_stride));
- auto s4 =
- hn::PromoteTo(mul_tag, hn::LoadU(p_tag, src + x + 4 * src_stride));
- auto s5 =
- hn::PromoteTo(mul_tag, hn::LoadU(p_tag, src + x + 5 * src_stride));
- auto s6 =
- hn::PromoteTo(mul_tag, hn::LoadU(p_tag, src + x + 6 * src_stride));
- for (int y = 0; y < h; ++y) {
- auto s7 = hn::PromoteTo(
- mul_tag, hn::LoadU(p_tag, src + x + (y + 7) * src_stride));
- auto sum = s0 * f0_s + s1 * f1_s + s2 * f2_s + s3 * f3_s + s4 * f4_s +
- s5 * f5_s + s6 * f6_s + s7 * f7_s;
- auto res = hn::ShiftRight<FILTER_BITS - 1>(sum + round_offset_s);
- auto res_demoted = hn::DemoteTo(p_tag, res);
- if (x + static_cast<int>(vw) > w) {
- hn::StoreN(res_demoted, p_tag, dst + x + y * dst_stride, w - x);
- } else {
- hn::StoreU(res_demoted, p_tag, dst + x + y * dst_stride);
- }
- s0 = s1;
- s1 = s2;
- s2 = s3;
- s3 = s4;
- s4 = s5;
- s5 = s6;
- s6 = s7;
+ if (w >= 16 && (w & 15) == 0) {
+#if HWY_TARGET <= HWY_AVX3
+ if ((w & 63) == 0) {
+ ConvolveVertEvenStrip64<kTaps>(src, src_stride, dst, dst_stride,
+ filter_y, w, h);
+ return;
+ }
+ if ((w & 31) == 0) {
+ ConvolveVertEvenStrip2Rows<kTaps, 32>(src, src_stride, dst, dst_stride,
+ filter_y, w, h);
+ return;
}
+ if (w == 16 && h >= 4) {
+ ConvolveVertEvenZmm4Rows<kTaps, 16>(src, src_stride, dst, dst_stride,
+ filter_y, h);
+ const int done = h & ~3;
+ src += done * src_stride;
+ dst += done * dst_stride;
+ h &= 3;
+ if (h == 0) return;
+ }
+#endif
+ ConvolveVertEvenStrip2Rows<kTaps, 16>(src, src_stride, dst, dst_stride,
+ filter_y, w, h);
+ return;
}
}
+#endif
+ ConvolveVertFallback<kTaps>(src, src_stride, dst, dst_stride, filter_y, w, h);
}
HWY_MAYBE_UNUSED void Convolve8Vert(const uint8_t *src, ptrdiff_t src_stride,
@@ -1409,6 +1214,7 @@ HWY_MAYBE_UNUSED void Convolve8Vert(const uint8_t *src, ptrdiff_t src_stride,
const int16_t *filter_x, int x_step_q4,
const int16_t *filter_y, int y_step_q4,
int w, int h) {
+ assert(w > 0 && h > 0);
assert((intptr_t)dst % 4 == 0);
assert(dst_stride % 4 == 0);
@@ -1419,14 +1225,14 @@ HWY_MAYBE_UNUSED void Convolve8Vert(const uint8_t *src, ptrdiff_t src_stride,
src -= src_stride * ((SUBPEL_TAPS / 2) - 1);
int filter_taps = get_filter_taps_convolve8(filter_y);
if (filter_taps == 2) {
- ConvolveVert2Tap(src + src_stride * 3, src_stride, dst, dst_stride,
- filter_y, w, h);
+ ConvolveVert<2>(src + src_stride * 3, src_stride, dst, dst_stride, filter_y,
+ w, h);
} else if (filter_taps == 4) {
- ConvolveVert4Tap(src + src_stride * 2, src_stride, dst, dst_stride,
- filter_y, w, h);
+ ConvolveVert<4>(src + src_stride * 2, src_stride, dst, dst_stride, filter_y,
+ w, h);
} else {
// filter_taps = 8
- ConvolveVert8Tap(src, src_stride, dst, dst_stride, filter_y, w, h);
+ ConvolveVert<8>(src, src_stride, dst, dst_stride, filter_y, w, h);
}
}
@@ -1435,16 +1241,7 @@ HWY_MAYBE_UNUSED void Convolve8Horiz(const uint8_t *src, ptrdiff_t src_stride,
const int16_t *filter_x, int x_step_q4,
const int16_t *filter_y, int y_step_q4,
int w, int h) {
-#if HAVE_SSSE3
- // TODO: jianj - 16x32 block is still fastest with handwritten avx2 which
- // uses ssse3 implementation. Further optimize for this case.
- if (w == 16 && h == 32) {
- aom_convolve8_horiz_ssse3(src, src_stride, dst, dst_stride, filter_x,
- x_step_q4, filter_y, y_step_q4, w, h);
- return;
- }
-#endif
-
+ assert(w > 0 && h > 0);
assert((intptr_t)dst % 4 == 0);
assert(dst_stride % 4 == 0);
@@ -1467,12 +1264,12 @@ HWY_MAYBE_UNUSED void Convolve8Horiz(const uint8_t *src, ptrdiff_t src_stride,
} // namespace HWY_NAMESPACE
} // namespace
+#undef AOM_CONVOLVE_HWY_X86_PAIRWISE
+
+HWY_AFTER_NAMESPACE();
+
#define CONVOLVE8HORIZ(suffix) \
- extern "C" void aom_convolve8_horiz_##suffix( \
- const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, \
- ptrdiff_t dst_stride, const int16_t *filter_x, int x_step_q4, \
- const int16_t *filter_y, int y_step_q4, int w, int h); \
- HWY_ATTR void aom_convolve8_horiz_##suffix( \
+ extern "C" HWY_ATTR void aom_convolve8_horiz_##suffix( \
const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, \
ptrdiff_t dst_stride, const int16_t *filter_x, int x_step_q4, \
const int16_t *filter_y, int y_step_q4, int w, int h) { \
@@ -1480,6 +1277,4 @@ HWY_MAYBE_UNUSED void Convolve8Horiz(const uint8_t *src, ptrdiff_t src_stride,
x_step_q4, filter_y, y_step_q4, w, h); \
}
-HWY_AFTER_NAMESPACE();
-
#endif // AOM_AOM_DSP_CONVOLVE_HWY_H_
diff --git a/test/convolve_test.cc b/test/convolve_test.cc
index dc61239089..41ddd587f3 100644
--- a/test/convolve_test.cc
+++ b/test/convolve_test.cc
@@ -70,6 +70,12 @@ using ConvolveParam = std::tuple<int, int, const ConvolveFunctions *>;
make_tuple(128, 64, &convolve_fn), make_tuple(64, 128, &convolve_fn), \
make_tuple(128, 128, &convolve_fn), ALL_SIZES_64(convolve_fn)
+#define ODD_HEIGHT_SIZES(convolve_fn) \
+ make_tuple(4, 11, &convolve_fn), make_tuple(8, 15, &convolve_fn), \
+ make_tuple(12, 12, &convolve_fn), make_tuple(16, 23, &convolve_fn), \
+ make_tuple(32, 39, &convolve_fn), make_tuple(64, 71, &convolve_fn), \
+ make_tuple(128, 127, &convolve_fn)
+
// Reference 8-tap subpixel filter, slightly modified to fit into this test.
#define AV1_FILTER_WEIGHT 128
#define AV1_FILTER_SHIFT 7
@@ -871,7 +877,12 @@ INSTANTIATE_TEST_SUITE_P(AVX2, HighbdConvolveTest,
#endif
const ConvolveFunctions convolve8_avx2(aom_convolve8_horiz_avx2,
aom_convolve8_vert_avx2, 0);
-const ConvolveParam kArray_Convolve8_avx2[] = { ALL_SIZES(convolve8_avx2) };
+const ConvolveParam kArray_Convolve8_avx2[] = {
+ ALL_SIZES(convolve8_avx2),
+#if CONFIG_HIGHWAY
+ ODD_HEIGHT_SIZES(convolve8_avx2),
+#endif
+};
INSTANTIATE_TEST_SUITE_P(AVX2, LowbdConvolveTest,
::testing::ValuesIn(kArray_Convolve8_avx2));
@@ -891,7 +902,9 @@ extern "C" void aom_convolve8_vert_avx512(
const ConvolveFunctions convolve8_avx512(aom_convolve8_horiz_avx512,
aom_convolve8_vert_avx512, 0);
-const ConvolveParam kArray_Convolve8_avx512[] = { ALL_SIZES(convolve8_avx512) };
+const ConvolveParam kArray_Convolve8_avx512[] = {
+ ALL_SIZES(convolve8_avx512), ODD_HEIGHT_SIZES(convolve8_avx512)
+};
INSTANTIATE_TEST_SUITE_P(AVX512, LowbdConvolveTest,
::testing::ValuesIn(kArray_Convolve8_avx512));