Commit cac561fd15 for aom
commit cac561fd15b32b85b2be7ce9c2398bdf2963d1d7
Author: Frank Galligan <fgalligan@google.com>
Date: Mon Nov 23 01:04:01 2026 -0800
av1,hwy: Keep warp coeffs and window in registers
Eliminate intermediate stack arrays for horizontal and vertical filter
coefficients and keep the vertical sliding window in Highway vector
registers across loop iterations in av1/common/warp_plane_hwy.h. Also
change inline to HWY_INLINE on helper functions, pass vector
parameters by reference, replace switch dispatch with if constexpr +
static_assert, drop the redundant D16 template parameter in favor of
hn::Repartition<int16_t, D>, and use int16x8_tag for
WarpHorizontalFilterOutOfBoundsPad() tail coefficients.
Speedup on AMD EPYC 7B13 (CONFIG_HIGHWAY=1, bit-exact):
- 2-pass VOD AV1 (MT): -1.37% weighted encode time (all 5 profiles
faster: -1.30% 1080p s2, -1.91% 360p s1, -0.49% 720p s3, -1.19%
4K s5, -1.88% 720p HDR10 s3).
- AVX2/AV1WarpFilterTest.DISABLED_Speed: 1.17x faster overall
(1037.9->888.5 s across all 80 cases, -14.4%).
- Bit-exact output across all 5 VOD profiles and x86_64 SIMD masks up
to AVX2 (1T/MT); AVX-512 path compile-verified only on this host.
Binary size (x86_64 -O3, HWY=1): libaom.a .text +2.0 KiB (+0.02%),
.rodata +0.1 KiB (+0.01%); stripped aomenc +0.0 KiB (+0.00%).
Memory (peak RSS, 720p 2-pass inter): 1T +1060 KiB (+0.40%),
8T +1492 KiB (+0.55%).
TAG=agy
CONV=181013d1-8c6e-44c8-b7ad-7781bba16c12
Change-Id: I53a01b3bf9fdf19d3bf39da05a280ea6dd1023fa
diff --git a/av1/common/warp_plane_hwy.h b/av1/common/warp_plane_hwy.h
index da0d5450bc..ce2afd46b9 100644
--- a/av1/common/warp_plane_hwy.h
+++ b/av1/common/warp_plane_hwy.h
@@ -26,6 +26,7 @@ namespace hn = hwy::HWY_NAMESPACE;
constexpr hn::ScalableTag<uint8_t> uint8xN_tag;
constexpr hn::ScalableTag<uint16_t> uint16xN_tag;
+constexpr hn::ScalableTag<int8_t> coeff_tag;
constexpr hn::ScalableTag<int16_t> int16xN_tag;
constexpr hn::ScalableTag<int32_t> int32xN_tag;
constexpr hn::ScalableTag<int64_t> int64xN_tag;
@@ -45,8 +46,6 @@ constexpr hn::FixedTag<int16_t, 8> int16x8_tag;
constexpr hn::FixedTag<int32_t, 4> int32x4_tag;
constexpr hn::FixedTag<int64_t, 2> int64x2_tag;
-constexpr hn::ScalableTag<int8_t> coeff_tag;
-
HWY_ATTR HWY_INLINE hn::Vec<decltype(uint8xN_tag)> GetShuffle0() {
return hn::Dup128VecFromValues(
uint8xN_tag, 0, 2, 2, 4, 4, 6, 6, 8, 1, 3, 3, 5, 5, 7, 7, 9 //
@@ -68,25 +67,21 @@ HWY_ATTR HWY_INLINE hn::Vec<decltype(uint8xN_tag)> GetShuffle3() {
);
}
+using IVec8 = hn::Vec<decltype(coeff_tag)>;
using IVec16 = hn::Vec<decltype(int16xN_tag)>;
using IVec32 = hn::Vec<decltype(int32xN_tag)>;
using IVec8x16 = hn::Vec<decltype(int8x16_tag)>;
template <typename D>
-HWY_ATTR inline void FilterPixelsHorizontal(D tag, const hn::VFromD<D> src,
- int16_t *HWY_RESTRICT horz_out,
- int8_t *HWY_RESTRICT coeff,
- const IVec16 round_const,
- const int shift, int row) {
- constexpr hn::Repartition<int8_t, D> int8_tag;
+HWY_ATTR HWY_INLINE void FilterPixelsHorizontal(
+ D tag, const hn::VFromD<D> &src, int16_t *HWY_RESTRICT horz_out,
+ const hn::VFromD<hn::Repartition<int8_t, D>> &coeff0,
+ const hn::VFromD<hn::Repartition<int8_t, D>> &coeff1,
+ const hn::VFromD<hn::Repartition<int8_t, D>> &coeff2,
+ const hn::VFromD<hn::Repartition<int8_t, D>> &coeff3,
+ const IVec16 &round_const, int shift, int row) {
constexpr hn::Repartition<int16_t, D> result_tag;
constexpr hn::Repartition<uint16_t, D> unsigned_result_tag;
- // N.B. coeffs are stored to support the maximum vector width, which may not
- // be the vector width being filtered on now.
- const auto coeff0 = hn::Load(int8_tag, coeff + hn::MaxLanes(coeff_tag) * 0);
- const auto coeff1 = hn::Load(int8_tag, coeff + hn::MaxLanes(coeff_tag) * 1);
- const auto coeff2 = hn::Load(int8_tag, coeff + hn::MaxLanes(coeff_tag) * 2);
- const auto coeff3 = hn::Load(int8_tag, coeff + hn::MaxLanes(coeff_tag) * 3);
const auto src_0 =
hn::TableLookupBytes(src, hn::ResizeBitCast(tag, GetShuffle0()));
@@ -140,8 +135,12 @@ HWY_ATTR HWY_INLINE hn::VFromD<D> LoadAV1Filter8BitUpper(D int8_tag,
}
template <typename D>
-HWY_ATTR inline void PrepareHorizontalFilterCoefficients(
- D int16_tag, int alpha, int beta, int sx, int8_t *HWY_RESTRICT coeff) {
+HWY_ATTR HWY_INLINE void PrepareHorizontalFilterCoefficients(
+ D int16_tag, int alpha, int beta, int sx,
+ hn::VFromD<hn::Repartition<int8_t, D>> &coeff0,
+ hn::VFromD<hn::Repartition<int8_t, D>> &coeff1,
+ hn::VFromD<hn::Repartition<int8_t, D>> &coeff2,
+ hn::VFromD<hn::Repartition<int8_t, D>> &coeff3) {
constexpr auto int8_tag = hn::Repartition<int8_t, D>();
constexpr auto int32_tag = hn::Repartition<int32_t, D>();
constexpr auto int64_tag = hn::Repartition<int64_t, D>();
@@ -221,19 +220,19 @@ HWY_ATTR inline void PrepareHorizontalFilterCoefficients(
const auto res_2 = hn::ZipLower(int64_tag, tmp_13, tmp_15);
const auto res_3 = hn::ZipUpper(int64_tag, tmp_13, tmp_15);
- hn::Store(hn::BitCast(int8_tag, hn::InterleaveLower(int64_tag, res_0, res_2)),
- int8_tag, coeff + hn::MaxLanes(coeff_tag) * 0);
- hn::Store(hn::BitCast(int8_tag, hn::InterleaveUpper(int64_tag, res_0, res_2)),
- int8_tag, coeff + hn::MaxLanes(coeff_tag) * 1);
- hn::Store(hn::BitCast(int8_tag, hn::InterleaveLower(int64_tag, res_1, res_3)),
- int8_tag, coeff + hn::MaxLanes(coeff_tag) * 2);
- hn::Store(hn::BitCast(int8_tag, hn::InterleaveUpper(int64_tag, res_1, res_3)),
- int8_tag, coeff + hn::MaxLanes(coeff_tag) * 3);
+ coeff0 = hn::BitCast(int8_tag, hn::InterleaveLower(int64_tag, res_0, res_2));
+ coeff1 = hn::BitCast(int8_tag, hn::InterleaveUpper(int64_tag, res_0, res_2));
+ coeff2 = hn::BitCast(int8_tag, hn::InterleaveLower(int64_tag, res_1, res_3));
+ coeff3 = hn::BitCast(int8_tag, hn::InterleaveUpper(int64_tag, res_1, res_3));
}
template <typename D>
-HWY_ATTR inline void PrepareHorizontalFilterCoefficientsBeta0(
- D int16_tag, int alpha, int beta, int sx, int8_t *HWY_RESTRICT coeff) {
+HWY_ATTR HWY_INLINE void PrepareHorizontalFilterCoefficientsBeta0(
+ D int16_tag, int alpha, int beta, int sx,
+ hn::VFromD<hn::Repartition<int8_t, D>> &coeff0,
+ hn::VFromD<hn::Repartition<int8_t, D>> &coeff1,
+ hn::VFromD<hn::Repartition<int8_t, D>> &coeff2,
+ hn::VFromD<hn::Repartition<int8_t, D>> &coeff3) {
(void)int16_tag;
(void)beta;
const auto tmp_0 =
@@ -276,19 +275,19 @@ HWY_ATTR inline void PrepareHorizontalFilterCoefficientsBeta0(
const auto res_2 = hn::ZipLower(int64_tag, broadcast_13, broadcast_15);
const auto res_3 = hn::ZipUpper(int64_tag, broadcast_13, broadcast_15);
- hn::Store(hn::BitCast(int8_tag, hn::InterleaveLower(int64_tag, res_0, res_2)),
- int8_tag, coeff + hn::MaxLanes(coeff_tag) * 0);
- hn::Store(hn::BitCast(int8_tag, hn::InterleaveUpper(int64_tag, res_0, res_2)),
- int8_tag, coeff + hn::MaxLanes(coeff_tag) * 1);
- hn::Store(hn::BitCast(int8_tag, hn::InterleaveLower(int64_tag, res_1, res_3)),
- int8_tag, coeff + hn::MaxLanes(coeff_tag) * 2);
- hn::Store(hn::BitCast(int8_tag, hn::InterleaveUpper(int64_tag, res_1, res_3)),
- int8_tag, coeff + hn::MaxLanes(coeff_tag) * 3);
+ coeff0 = hn::BitCast(int8_tag, hn::InterleaveLower(int64_tag, res_0, res_2));
+ coeff1 = hn::BitCast(int8_tag, hn::InterleaveUpper(int64_tag, res_0, res_2));
+ coeff2 = hn::BitCast(int8_tag, hn::InterleaveLower(int64_tag, res_1, res_3));
+ coeff3 = hn::BitCast(int8_tag, hn::InterleaveUpper(int64_tag, res_1, res_3));
}
template <typename D>
-HWY_ATTR inline void PrepareHorizontalFilterCoefficientsAlpha0(
- D int16_tag, int alpha, int beta, int sx, int8_t *HWY_RESTRICT coeff) {
+HWY_ATTR HWY_INLINE void PrepareHorizontalFilterCoefficientsAlpha0(
+ D int16_tag, int alpha, int beta, int sx,
+ hn::VFromD<hn::Repartition<int8_t, D>> &coeff0,
+ hn::VFromD<hn::Repartition<int8_t, D>> &coeff1,
+ hn::VFromD<hn::Repartition<int8_t, D>> &coeff2,
+ hn::VFromD<hn::Repartition<int8_t, D>> &coeff3) {
(void)alpha;
constexpr auto int8_tag = hn::Repartition<int8_t, D>();
auto tmp_0 = LoadAV1Filter8BitLower(int8_tag, sx);
@@ -301,32 +300,33 @@ HWY_ATTR inline void PrepareHorizontalFilterCoefficientsAlpha0(
}
const auto res_0 = hn::BitCast(int16_tag, tmp_0);
- hn::Store(hn::BitCast(int8_tag, hn::Broadcast<0>(res_0)), int8_tag,
- coeff + hn::MaxLanes(coeff_tag) * 0);
- hn::Store(hn::BitCast(int8_tag, hn::Broadcast<1>(res_0)), int8_tag,
- coeff + hn::MaxLanes(coeff_tag) * 1);
- hn::Store(hn::BitCast(int8_tag, hn::Broadcast<2>(res_0)), int8_tag,
- coeff + hn::MaxLanes(coeff_tag) * 2);
- hn::Store(hn::BitCast(int8_tag, hn::Broadcast<3>(res_0)), int8_tag,
- coeff + hn::MaxLanes(coeff_tag) * 3);
+ coeff0 = hn::BitCast(int8_tag, hn::Broadcast<0>(res_0));
+ coeff1 = hn::BitCast(int8_tag, hn::Broadcast<1>(res_0));
+ coeff2 = hn::BitCast(int8_tag, hn::Broadcast<2>(res_0));
+ coeff3 = hn::BitCast(int8_tag, hn::Broadcast<3>(res_0));
}
template <typename D>
-HWY_ATTR inline void HorizontalFilter(D tag, const hn::VFromD<D> src,
- int16_t *HWY_RESTRICT horz_out, int sx,
- int alpha, int beta, int row,
- const IVec16 round_const,
- const int reduce_bits_horiz) {
- HWY_ALIGN int8_t coeff[4 * hn::MaxLanes(coeff_tag)];
+HWY_ATTR HWY_INLINE void HorizontalFilter(D tag, const hn::VFromD<D> &src,
+ int16_t *HWY_RESTRICT horz_out,
+ int sx, int alpha, int beta, int row,
+ const IVec16 &round_const,
+ int reduce_bits_horiz) {
+ constexpr hn::Repartition<int8_t, D> int8_tag;
+ hn::VFromD<decltype(int8_tag)> coeff0, coeff1, coeff2, coeff3;
PrepareHorizontalFilterCoefficients(hn::Repartition<int16_t, D>(), alpha,
- beta, sx, coeff);
- FilterPixelsHorizontal(tag, src, horz_out, coeff, round_const,
- reduce_bits_horiz, row);
+ beta, sx, coeff0, coeff1, coeff2, coeff3);
+ FilterPixelsHorizontal(tag, src, horz_out, coeff0, coeff1, coeff2, coeff3,
+ round_const, reduce_bits_horiz, row);
}
template <typename D>
-HWY_ATTR inline void PrepareLastHorizontalFilterCoefficients(
- D int16_tag, int alpha, int beta, int sx, int8_t *HWY_RESTRICT coeff) {
+HWY_ATTR HWY_INLINE void PrepareLastHorizontalFilterCoefficients(
+ D int16_tag, int alpha, int beta, int sx,
+ hn::VFromD<hn::Repartition<int8_t, D>> &coeff0,
+ hn::VFromD<hn::Repartition<int8_t, D>> &coeff1,
+ hn::VFromD<hn::Repartition<int8_t, D>> &coeff2,
+ hn::VFromD<hn::Repartition<int8_t, D>> &coeff3) {
(void)int16_tag;
(void)beta;
const auto tmp_0 =
@@ -368,14 +368,10 @@ HWY_ATTR inline void PrepareLastHorizontalFilterCoefficients(
const auto tmp_22 = hn::ResizeBitCast(int8_tag, tmp_18);
const auto tmp_23 = hn::ResizeBitCast(int8_tag, tmp_19);
- hn::Store(hn::BroadcastBlock<0>(tmp_20), int8_tag,
- coeff + hn::MaxLanes(coeff_tag) * 0);
- hn::Store(hn::BroadcastBlock<0>(tmp_21), int8_tag,
- coeff + hn::MaxLanes(coeff_tag) * 1);
- hn::Store(hn::BroadcastBlock<0>(tmp_22), int8_tag,
- coeff + hn::MaxLanes(coeff_tag) * 2);
- hn::Store(hn::BroadcastBlock<0>(tmp_23), int8_tag,
- coeff + hn::MaxLanes(coeff_tag) * 3);
+ coeff0 = hn::BroadcastBlock<0>(tmp_20);
+ coeff1 = hn::BroadcastBlock<0>(tmp_21);
+ coeff2 = hn::BroadcastBlock<0>(tmp_22);
+ coeff3 = hn::BroadcastBlock<0>(tmp_23);
}
template <typename D>
@@ -427,69 +423,94 @@ enum class HorizontalFilterCoeffs {
};
template <bool IsLast, HorizontalFilterCoeffs Filter, typename D>
-HWY_ATTR void WarpHorizontalPrepareCoeffs(int alpha, int beta, int sx,
- int8_t *HWY_RESTRICT coeffs) {
- D int16_tag;
- switch (Filter) {
- case HorizontalFilterCoeffs::kAlpha0:
- PrepareHorizontalFilterCoefficientsAlpha0(int16_tag, alpha, beta, sx,
- coeffs);
- return;
- case HorizontalFilterCoeffs::kBeta0:
- PrepareHorizontalFilterCoefficientsBeta0(int16_tag, alpha, beta, sx,
- coeffs);
- return;
- case HorizontalFilterCoeffs::kDefault:
- default:
- if (IsLast) {
- PrepareLastHorizontalFilterCoefficients(int16_tag, alpha, beta, sx,
- coeffs);
- } else {
- PrepareHorizontalFilterCoefficients(int16_tag, alpha, beta, sx, coeffs);
- }
- return;
+HWY_ATTR HWY_INLINE void WarpHorizontalPrepareCoeffs(
+ int alpha, int beta, int sx, hn::VFromD<hn::Repartition<int8_t, D>> &coeff0,
+ hn::VFromD<hn::Repartition<int8_t, D>> &coeff1,
+ hn::VFromD<hn::Repartition<int8_t, D>> &coeff2,
+ hn::VFromD<hn::Repartition<int8_t, D>> &coeff3) {
+ constexpr D int16_tag;
+ if constexpr (Filter == HorizontalFilterCoeffs::kAlpha0) {
+ PrepareHorizontalFilterCoefficientsAlpha0(int16_tag, alpha, beta, sx,
+ coeff0, coeff1, coeff2, coeff3);
+ } else if constexpr (Filter == HorizontalFilterCoeffs::kBeta0) {
+ PrepareHorizontalFilterCoefficientsBeta0(int16_tag, alpha, beta, sx, coeff0,
+ coeff1, coeff2, coeff3);
+ } else {
+ static_assert(Filter == HorizontalFilterCoeffs::kDefault,
+ "Unhandled HorizontalFilterCoeffs value");
+ if constexpr (IsLast) {
+ PrepareLastHorizontalFilterCoefficients(int16_tag, alpha, beta, sx,
+ coeff0, coeff1, coeff2, coeff3);
+ } else {
+ PrepareHorizontalFilterCoefficients(int16_tag, alpha, beta, sx, coeff0,
+ coeff1, coeff2, coeff3);
+ }
}
}
template <bool InnerCoeffUpdate, bool IsLast, HorizontalFilterCoeffs Filter,
- typename D, typename D16>
-HWY_ATTR int WarpHorizontalFilterLoop(
- D tag, D16, const uint8_t *HWY_RESTRICT ref, int16_t *HWY_RESTRICT horz_out,
+ typename D>
+HWY_ATTR HWY_INLINE int WarpHorizontalFilterLoop(
+ D tag, const uint8_t *HWY_RESTRICT ref, int16_t *HWY_RESTRICT horz_out,
int stride, int32_t ix4, int32_t iy4, int32_t sx4, int alpha, int beta,
- int p_height, int height, int i, const IVec16 round_const,
- const int reduce_bits_horiz, int k, int8_t *HWY_RESTRICT coeff) {
+ int p_height, int height, int i, const IVec16 &round_const,
+ int reduce_bits_horiz, int k, const IVec8 &outer_coeff0,
+ const IVec8 &outer_coeff1, const IVec8 &outer_coeff2,
+ const IVec8 &outer_coeff3) {
+ using D16 = hn::Repartition<int16_t, D>;
constexpr int kNumRows = tag.MaxBlocks();
+ constexpr hn::Repartition<int8_t, D> int8_tag;
for (; k < AOMMIN(8, p_height - i) - kNumRows; k += kNumRows) {
const auto src =
LoadRowsClamped(tag, ref + ix4 - 7, stride, iy4 + k, height);
+ hn::VFromD<decltype(int8_tag)> coeff0, coeff1, coeff2, coeff3;
if constexpr (InnerCoeffUpdate) {
int sx = sx4 + beta * (k + 4);
- WarpHorizontalPrepareCoeffs<IsLast, Filter, D16>(alpha, beta, sx, coeff);
+ WarpHorizontalPrepareCoeffs<IsLast, Filter, D16>(alpha, beta, sx, coeff0,
+ coeff1, coeff2, coeff3);
+ } else {
+ // The outer coeffs are prepared at the maximum vector width; keep the
+ // lower lanes for the (possibly narrower) width being filtered now.
+ coeff0 = hn::ResizeBitCast(int8_tag, outer_coeff0);
+ coeff1 = hn::ResizeBitCast(int8_tag, outer_coeff1);
+ coeff2 = hn::ResizeBitCast(int8_tag, outer_coeff2);
+ coeff3 = hn::ResizeBitCast(int8_tag, outer_coeff3);
}
- FilterPixelsHorizontal(tag, src, horz_out, coeff, round_const,
- reduce_bits_horiz, k + 7);
+ FilterPixelsHorizontal(tag, src, horz_out, coeff0, coeff1, coeff2, coeff3,
+ round_const, reduce_bits_horiz, k + 7);
}
return k;
}
template <bool InnerCoeffUpdate, bool IsLast, HorizontalFilterCoeffs Filter,
- typename D, typename D16>
-HWY_ATTR int WarpHorizontalFilterLoopInterior(
- D tag, D16, const uint8_t *HWY_RESTRICT base_ptr,
- int16_t *HWY_RESTRICT horz_out, int stride, int stride2, int stride3,
- int32_t sx4, int alpha, int beta, int p_height, int i,
- const IVec16 round_const, const int reduce_bits_horiz, int k,
- int8_t *HWY_RESTRICT coeff) {
+ typename D>
+HWY_ATTR HWY_INLINE int WarpHorizontalFilterLoopInterior(
+ D tag, const uint8_t *HWY_RESTRICT base_ptr, int16_t *HWY_RESTRICT horz_out,
+ int stride, int stride2, int stride3, int32_t sx4, int alpha, int beta,
+ int p_height, int i, const IVec16 &round_const, int reduce_bits_horiz,
+ int k, const IVec8 &outer_coeff0, const IVec8 &outer_coeff1,
+ const IVec8 &outer_coeff2, const IVec8 &outer_coeff3) {
+ using D16 = hn::Repartition<int16_t, D>;
constexpr int kNumRows = tag.MaxBlocks();
+ constexpr hn::Repartition<int8_t, D> int8_tag;
for (; k < AOMMIN(8, p_height - i) - kNumRows; k += kNumRows) {
const auto src = LoadRowsInterior(tag, base_ptr + (k + 7) * stride, stride,
stride2, stride3);
+ hn::VFromD<decltype(int8_tag)> coeff0, coeff1, coeff2, coeff3;
if constexpr (InnerCoeffUpdate) {
int sx = sx4 + beta * (k + 4);
- WarpHorizontalPrepareCoeffs<IsLast, Filter, D16>(alpha, beta, sx, coeff);
+ WarpHorizontalPrepareCoeffs<IsLast, Filter, D16>(alpha, beta, sx, coeff0,
+ coeff1, coeff2, coeff3);
+ } else {
+ // The outer coeffs are prepared at the maximum vector width; keep the
+ // lower lanes for the (possibly narrower) width being filtered now.
+ coeff0 = hn::ResizeBitCast(int8_tag, outer_coeff0);
+ coeff1 = hn::ResizeBitCast(int8_tag, outer_coeff1);
+ coeff2 = hn::ResizeBitCast(int8_tag, outer_coeff2);
+ coeff3 = hn::ResizeBitCast(int8_tag, outer_coeff3);
}
- FilterPixelsHorizontal(tag, src, horz_out, coeff, round_const,
- reduce_bits_horiz, k + 7);
+ FilterPixelsHorizontal(tag, src, horz_out, coeff0, coeff1, coeff2, coeff3,
+ round_const, reduce_bits_horiz, k + 7);
}
return k;
}
@@ -500,35 +521,50 @@ HWY_ATTR inline void WarpHorizontalFilterTemplate(
int32_t ix4, int32_t iy4, int32_t sx4, int alpha, int beta, int p_height,
int height, int i, const IVec16 round_const, const int reduce_bits_horiz) {
int k = -7, iy;
- HWY_ALIGN int8_t coeff[4 * hn::MaxLanes(coeff_tag)];
+ IVec8 coeff0 = hn::Undefined(coeff_tag);
+ IVec8 coeff1 = hn::Undefined(coeff_tag);
+ IVec8 coeff2 = hn::Undefined(coeff_tag);
+ IVec8 coeff3 = hn::Undefined(coeff_tag);
if constexpr (!InnerCoeffUpdate) {
WarpHorizontalPrepareCoeffs<false, Filter, decltype(int16xN_tag)>(
- alpha, beta, sx4, coeff);
+ alpha, beta, sx4, coeff0, coeff1, coeff2, coeff3);
}
if constexpr (uint8xN_tag.MaxBlocks() >= 3) {
k = WarpHorizontalFilterLoop<InnerCoeffUpdate, false, Filter>(
- uint8xN_tag, int16xN_tag, ref, horz_out, stride, ix4, iy4, sx4, alpha,
- beta, p_height, height, i, round_const, reduce_bits_horiz, k, coeff);
+ uint8xN_tag, ref, horz_out, stride, ix4, iy4, sx4, alpha, beta,
+ p_height, height, i, round_const, reduce_bits_horiz, k, coeff0, coeff1,
+ coeff2, coeff3);
}
if constexpr (uint8xN_tag.MaxBlocks() >= 2) {
k = WarpHorizontalFilterLoop<InnerCoeffUpdate, false, Filter>(
- uint8x32_tag, int16x16_tag, ref, horz_out, stride, ix4, iy4, sx4, alpha,
- beta, p_height, height, i, round_const, reduce_bits_horiz, k, coeff);
+ uint8x32_tag, ref, horz_out, stride, ix4, iy4, sx4, alpha, beta,
+ p_height, height, i, round_const, reduce_bits_horiz, k, coeff0, coeff1,
+ coeff2, coeff3);
}
if constexpr (uint8xN_tag.MaxBlocks() == 1) {
k = WarpHorizontalFilterLoop<InnerCoeffUpdate, true, Filter>(
- uint8x16_tag, int16x8_tag, ref, horz_out, stride, ix4, iy4, sx4, alpha,
- beta, p_height, height, i, round_const, reduce_bits_horiz, k, coeff);
+ uint8x16_tag, ref, horz_out, stride, ix4, iy4, sx4, alpha, beta,
+ p_height, height, i, round_const, reduce_bits_horiz, k, coeff0, coeff1,
+ coeff2, coeff3);
}
iy = iy4 + k;
iy = clamp(iy, 0, height - 1);
const auto src = hn::LoadU(uint8x16_tag, ref + iy * stride + ix4 - 7);
+ IVec8x16 tail_coeff0, tail_coeff1, tail_coeff2, tail_coeff3;
if constexpr (InnerCoeffUpdate) {
int sx = sx4 + beta * (k + 4);
WarpHorizontalPrepareCoeffs<true, Filter, decltype(int16x8_tag)>(
- alpha, beta, sx, coeff);
+ alpha, beta, sx, tail_coeff0, tail_coeff1, tail_coeff2, tail_coeff3);
+ } else {
+ // The outer coeffs are prepared at the maximum vector width; keep the
+ // lower lanes for the (possibly narrower) 128-bit tail.
+ tail_coeff0 = hn::ResizeBitCast(int8x16_tag, coeff0);
+ tail_coeff1 = hn::ResizeBitCast(int8x16_tag, coeff1);
+ tail_coeff2 = hn::ResizeBitCast(int8x16_tag, coeff2);
+ tail_coeff3 = hn::ResizeBitCast(int8x16_tag, coeff3);
}
- FilterPixelsHorizontal(uint8x16_tag, src, horz_out, coeff, round_const,
+ FilterPixelsHorizontal(uint8x16_tag, src, horz_out, tail_coeff0, tail_coeff1,
+ tail_coeff2, tail_coeff3, round_const,
reduce_bits_horiz, k + 7);
}
@@ -542,36 +578,48 @@ HWY_ATTR inline void WarpHorizontalFilterTemplateInterior(
const int stride3 = stride * 3;
int k = -7;
- HWY_ALIGN int8_t coeff[4 * hn::MaxLanes(coeff_tag)];
+ IVec8 coeff0 = hn::Undefined(coeff_tag);
+ IVec8 coeff1 = hn::Undefined(coeff_tag);
+ IVec8 coeff2 = hn::Undefined(coeff_tag);
+ IVec8 coeff3 = hn::Undefined(coeff_tag);
if constexpr (!InnerCoeffUpdate) {
WarpHorizontalPrepareCoeffs<false, Filter, decltype(int16xN_tag)>(
- alpha, beta, sx4, coeff);
+ alpha, beta, sx4, coeff0, coeff1, coeff2, coeff3);
}
if constexpr (uint8xN_tag.MaxBlocks() >= 3) {
k = WarpHorizontalFilterLoopInterior<InnerCoeffUpdate, false, Filter>(
- uint8xN_tag, int16xN_tag, base_ptr, horz_out, stride, stride2, stride3,
- sx4, alpha, beta, p_height, i, round_const, reduce_bits_horiz, k,
- coeff);
+ uint8xN_tag, base_ptr, horz_out, stride, stride2, stride3, sx4, alpha,
+ beta, p_height, i, round_const, reduce_bits_horiz, k, coeff0, coeff1,
+ coeff2, coeff3);
}
if constexpr (uint8xN_tag.MaxBlocks() >= 2) {
k = WarpHorizontalFilterLoopInterior<InnerCoeffUpdate, false, Filter>(
- uint8x32_tag, int16x16_tag, base_ptr, horz_out, stride, stride2,
- stride3, sx4, alpha, beta, p_height, i, round_const, reduce_bits_horiz,
- k, coeff);
+ uint8x32_tag, base_ptr, horz_out, stride, stride2, stride3, sx4, alpha,
+ beta, p_height, i, round_const, reduce_bits_horiz, k, coeff0, coeff1,
+ coeff2, coeff3);
}
if constexpr (uint8xN_tag.MaxBlocks() == 1) {
k = WarpHorizontalFilterLoopInterior<InnerCoeffUpdate, true, Filter>(
- uint8x16_tag, int16x8_tag, base_ptr, horz_out, stride, stride2, stride3,
- sx4, alpha, beta, p_height, i, round_const, reduce_bits_horiz, k,
- coeff);
+ uint8x16_tag, base_ptr, horz_out, stride, stride2, stride3, sx4, alpha,
+ beta, p_height, i, round_const, reduce_bits_horiz, k, coeff0, coeff1,
+ coeff2, coeff3);
}
const auto src = hn::LoadU(uint8x16_tag, base_ptr + (k + 7) * stride);
+ IVec8x16 tail_coeff0, tail_coeff1, tail_coeff2, tail_coeff3;
if constexpr (InnerCoeffUpdate) {
int sx = sx4 + beta * (k + 4);
WarpHorizontalPrepareCoeffs<true, Filter, decltype(int16x8_tag)>(
- alpha, beta, sx, coeff);
+ alpha, beta, sx, tail_coeff0, tail_coeff1, tail_coeff2, tail_coeff3);
+ } else {
+ // The outer coeffs are prepared at the maximum vector width; keep the
+ // lower lanes for the (possibly narrower) 128-bit tail.
+ tail_coeff0 = hn::ResizeBitCast(int8x16_tag, coeff0);
+ tail_coeff1 = hn::ResizeBitCast(int8x16_tag, coeff1);
+ tail_coeff2 = hn::ResizeBitCast(int8x16_tag, coeff2);
+ tail_coeff3 = hn::ResizeBitCast(int8x16_tag, coeff3);
}
- FilterPixelsHorizontal(uint8x16_tag, src, horz_out, coeff, round_const,
+ FilterPixelsHorizontal(uint8x16_tag, src, horz_out, tail_coeff0, tail_coeff1,
+ tail_coeff2, tail_coeff3, round_const,
reduce_bits_horiz, k + 7);
}
@@ -616,8 +664,10 @@ HWY_ATTR HWY_INLINE IVec16 LoadAV1WarpedFilterUpper(size_t offset, IVec16 src) {
warped_filter_ptr + (offset >> WARPEDDIFF_PREC_BITS) * 8));
}
-HWY_ATTR inline void PrepareVerticalFilterCoeffs(int gamma, int delta, int sy,
- int16_t *HWY_RESTRICT coeffs) {
+HWY_ATTR HWY_INLINE void PrepareVerticalFilterCoeffs(
+ int gamma, int delta, int sy, IVec16 &coeff0, IVec16 &coeff1,
+ IVec16 &coeff2, IVec16 &coeff3, IVec16 &coeff4, IVec16 &coeff5,
+ IVec16 &coeff6, IVec16 &coeff7) {
auto filt_00 = LoadAV1WarpedFilterLower(sy + 0 * gamma);
auto filt_01 = LoadAV1WarpedFilterLower(sy + 2 * gamma);
auto filt_02 = LoadAV1WarpedFilterLower(sy + 4 * gamma);
@@ -652,18 +702,14 @@ HWY_ATTR inline void PrepareVerticalFilterCoeffs(int gamma, int delta, int sy,
auto res_2 = hn::ZipUpper(int64xN_tag, filt_0, filt_1);
auto res_3 = hn::ZipUpper(int64xN_tag, filt_2, filt_3);
- hn::Store(
- hn::BitCast(int16xN_tag, hn::InterleaveLower(int64xN_tag, res_0, res_1)),
- int16xN_tag, coeffs + 0 * hn::MaxLanes(int16xN_tag));
- hn::Store(
- hn::BitCast(int16xN_tag, hn::InterleaveUpper(int64xN_tag, res_0, res_1)),
- int16xN_tag, coeffs + 1 * hn::MaxLanes(int16xN_tag));
- hn::Store(
- hn::BitCast(int16xN_tag, hn::InterleaveLower(int64xN_tag, res_2, res_3)),
- int16xN_tag, coeffs + 2 * hn::MaxLanes(int16xN_tag));
- hn::Store(
- hn::BitCast(int16xN_tag, hn::InterleaveUpper(int64xN_tag, res_2, res_3)),
- int16xN_tag, coeffs + 3 * hn::MaxLanes(int16xN_tag));
+ coeff0 =
+ hn::BitCast(int16xN_tag, hn::InterleaveLower(int64xN_tag, res_0, res_1));
+ coeff1 =
+ hn::BitCast(int16xN_tag, hn::InterleaveUpper(int64xN_tag, res_0, res_1));
+ coeff2 =
+ hn::BitCast(int16xN_tag, hn::InterleaveLower(int64xN_tag, res_2, res_3));
+ coeff3 =
+ hn::BitCast(int16xN_tag, hn::InterleaveUpper(int64xN_tag, res_2, res_3));
filt_00 = LoadAV1WarpedFilterLower(sy + 1 * gamma);
filt_01 = LoadAV1WarpedFilterLower(sy + 3 * gamma);
@@ -699,22 +745,20 @@ HWY_ATTR inline void PrepareVerticalFilterCoeffs(int gamma, int delta, int sy,
res_2 = hn::ZipUpper(int64xN_tag, filt_0, filt_1);
res_3 = hn::ZipUpper(int64xN_tag, filt_2, filt_3);
- hn::Store(
- hn::BitCast(int16xN_tag, hn::InterleaveLower(int64xN_tag, res_0, res_1)),
- int16xN_tag, coeffs + 4 * hn::MaxLanes(int16xN_tag));
- hn::Store(
- hn::BitCast(int16xN_tag, hn::InterleaveUpper(int64xN_tag, res_0, res_1)),
- int16xN_tag, coeffs + 5 * hn::MaxLanes(int16xN_tag));
- hn::Store(
- hn::BitCast(int16xN_tag, hn::InterleaveLower(int64xN_tag, res_2, res_3)),
- int16xN_tag, coeffs + 6 * hn::MaxLanes(int16xN_tag));
- hn::Store(
- hn::BitCast(int16xN_tag, hn::InterleaveUpper(int64xN_tag, res_2, res_3)),
- int16xN_tag, coeffs + 7 * hn::MaxLanes(int16xN_tag));
+ coeff4 =
+ hn::BitCast(int16xN_tag, hn::InterleaveLower(int64xN_tag, res_0, res_1));
+ coeff5 =
+ hn::BitCast(int16xN_tag, hn::InterleaveUpper(int64xN_tag, res_0, res_1));
+ coeff6 =
+ hn::BitCast(int16xN_tag, hn::InterleaveLower(int64xN_tag, res_2, res_3));
+ coeff7 =
+ hn::BitCast(int16xN_tag, hn::InterleaveUpper(int64xN_tag, res_2, res_3));
}
-HWY_ATTR inline void PrepareVerticalFilterCoeffsDelta0(
- int gamma, int delta, int sy, int16_t *HWY_RESTRICT coeffs) {
+HWY_ATTR HWY_INLINE void PrepareVerticalFilterCoeffsDelta0(
+ int gamma, int delta, int sy, IVec16 &coeff0, IVec16 &coeff1,
+ IVec16 &coeff2, IVec16 &coeff3, IVec16 &coeff4, IVec16 &coeff5,
+ IVec16 &coeff6, IVec16 &coeff7) {
(void)delta;
auto filt_00 = LoadAV1WarpedFilter(sy + 0 * gamma);
auto filt_01 = LoadAV1WarpedFilter(sy + 2 * gamma);
@@ -731,18 +775,14 @@ HWY_ATTR inline void PrepareVerticalFilterCoeffsDelta0(
auto res_2 = hn::ZipUpper(int64xN_tag, filt_10, filt_11);
auto res_3 = hn::ZipUpper(int64xN_tag, filt_12, filt_13);
- hn::Store(
- hn::BitCast(int16xN_tag, hn::InterleaveLower(int64xN_tag, res_0, res_1)),
- int16xN_tag, coeffs + 0 * hn::MaxLanes(int16xN_tag));
- hn::Store(
- hn::BitCast(int16xN_tag, hn::InterleaveUpper(int64xN_tag, res_0, res_1)),
- int16xN_tag, coeffs + 1 * hn::MaxLanes(int16xN_tag));
- hn::Store(
- hn::BitCast(int16xN_tag, hn::InterleaveLower(int64xN_tag, res_2, res_3)),
- int16xN_tag, coeffs + 2 * hn::MaxLanes(int16xN_tag));
- hn::Store(
- hn::BitCast(int16xN_tag, hn::InterleaveUpper(int64xN_tag, res_2, res_3)),
- int16xN_tag, coeffs + 3 * hn::MaxLanes(int16xN_tag));
+ coeff0 =
+ hn::BitCast(int16xN_tag, hn::InterleaveLower(int64xN_tag, res_0, res_1));
+ coeff1 =
+ hn::BitCast(int16xN_tag, hn::InterleaveUpper(int64xN_tag, res_0, res_1));
+ coeff2 =
+ hn::BitCast(int16xN_tag, hn::InterleaveLower(int64xN_tag, res_2, res_3));
+ coeff3 =
+ hn::BitCast(int16xN_tag, hn::InterleaveUpper(int64xN_tag, res_2, res_3));
filt_00 = LoadAV1WarpedFilter(sy + 1 * gamma);
filt_01 = LoadAV1WarpedFilter(sy + 3 * gamma);
@@ -759,22 +799,20 @@ HWY_ATTR inline void PrepareVerticalFilterCoeffsDelta0(
res_2 = hn::ZipUpper(int64xN_tag, filt_10, filt_11);
res_3 = hn::ZipUpper(int64xN_tag, filt_12, filt_13);
- hn::Store(
- hn::BitCast(int16xN_tag, hn::InterleaveLower(int64xN_tag, res_0, res_1)),
- int16xN_tag, coeffs + 4 * hn::MaxLanes(int16xN_tag));
- hn::Store(
- hn::BitCast(int16xN_tag, hn::InterleaveUpper(int64xN_tag, res_0, res_1)),
- int16xN_tag, coeffs + 5 * hn::MaxLanes(int16xN_tag));
- hn::Store(
- hn::BitCast(int16xN_tag, hn::InterleaveLower(int64xN_tag, res_2, res_3)),
- int16xN_tag, coeffs + 6 * hn::MaxLanes(int16xN_tag));
- hn::Store(
- hn::BitCast(int16xN_tag, hn::InterleaveUpper(int64xN_tag, res_2, res_3)),
- int16xN_tag, coeffs + 7 * hn::MaxLanes(int16xN_tag));
+ coeff4 =
+ hn::BitCast(int16xN_tag, hn::InterleaveLower(int64xN_tag, res_0, res_1));
+ coeff5 =
+ hn::BitCast(int16xN_tag, hn::InterleaveUpper(int64xN_tag, res_0, res_1));
+ coeff6 =
+ hn::BitCast(int16xN_tag, hn::InterleaveLower(int64xN_tag, res_2, res_3));
+ coeff7 =
+ hn::BitCast(int16xN_tag, hn::InterleaveUpper(int64xN_tag, res_2, res_3));
}
-HWY_ATTR inline void PrepareVerticalFilterCoeffsGamma0(
- int gamma, int delta, int sy, int16_t *HWY_RESTRICT coeffs) {
+HWY_ATTR HWY_INLINE void PrepareVerticalFilterCoeffsGamma0(
+ int gamma, int delta, int sy, IVec16 &coeff0, IVec16 &coeff1,
+ IVec16 &coeff2, IVec16 &coeff3, IVec16 &coeff4, IVec16 &coeff5,
+ IVec16 &coeff6, IVec16 &coeff7) {
(void)gamma;
auto filt_0 = LoadAV1WarpedFilterLower(sy);
if constexpr (int16xN_tag.MaxBlocks() >= 2) {
@@ -791,123 +829,45 @@ HWY_ATTR inline void PrepareVerticalFilterCoeffsGamma0(
auto broadcast_2 = hn::BitCast(int16xN_tag, hn::Broadcast<2>(res_0));
auto broadcast_3 = hn::BitCast(int16xN_tag, hn::Broadcast<3>(res_0));
- hn::Store(broadcast_0, int16xN_tag, coeffs + 0 * hn::MaxLanes(int16xN_tag));
- hn::Store(broadcast_1, int16xN_tag, coeffs + 1 * hn::MaxLanes(int16xN_tag));
- hn::Store(broadcast_2, int16xN_tag, coeffs + 2 * hn::MaxLanes(int16xN_tag));
- hn::Store(broadcast_3, int16xN_tag, coeffs + 3 * hn::MaxLanes(int16xN_tag));
- hn::Store(broadcast_0, int16xN_tag, coeffs + 4 * hn::MaxLanes(int16xN_tag));
- hn::Store(broadcast_1, int16xN_tag, coeffs + 5 * hn::MaxLanes(int16xN_tag));
- hn::Store(broadcast_2, int16xN_tag, coeffs + 6 * hn::MaxLanes(int16xN_tag));
- hn::Store(broadcast_3, int16xN_tag, coeffs + 7 * hn::MaxLanes(int16xN_tag));
+ coeff0 = broadcast_0;
+ coeff1 = broadcast_1;
+ coeff2 = broadcast_2;
+ coeff3 = broadcast_3;
+ coeff4 = broadcast_0;
+ coeff5 = broadcast_1;
+ coeff6 = broadcast_2;
+ coeff7 = broadcast_3;
}
-HWY_ATTR inline void FilterPixelsVertical(int16_t *HWY_RESTRICT horz_out,
- int16_t *HWY_RESTRICT src_lo,
- int16_t *HWY_RESTRICT src_hi,
- int16_t *HWY_RESTRICT coeffs,
- IVec32 &HWY_RESTRICT res_lo,
- IVec32 &HWY_RESTRICT res_hi, int row,
- const IVec32 res_add_const) {
- if constexpr (int16xN_tag.MaxBlocks() >= 3) {
- const auto horz_out_4 =
- hn::Load(int16xN_tag, horz_out + (row + 4) * hn::MaxLanes(int16x8_tag));
- const auto horz_out_5 = hn::LoadU(
- int16xN_tag, horz_out + (row + 5) * hn::MaxLanes(int16x8_tag));
- const auto horz_out_6 = hn::LoadU(
- int16xN_tag, horz_out + (row + 6) * hn::MaxLanes(int16x8_tag));
- const auto horz_out_7 = hn::LoadU(
- int16xN_tag, horz_out + (row + 7) * hn::MaxLanes(int16x8_tag));
- const auto src_lo_2 =
- hn::InterleaveLower(int16xN_tag, horz_out_4, horz_out_5);
- const auto src_hi_2 =
- hn::InterleaveUpper(int16xN_tag, horz_out_4, horz_out_5);
- const auto src_lo_3 =
- hn::InterleaveLower(int16xN_tag, horz_out_6, horz_out_7);
- const auto src_hi_3 =
- hn::InterleaveUpper(int16xN_tag, horz_out_6, horz_out_7);
- hn::Store(src_lo_2, int16xN_tag, src_lo + 2 * hn::MaxLanes(int16xN_tag));
- hn::Store(src_hi_2, int16xN_tag, src_hi + 2 * hn::MaxLanes(int16xN_tag));
- hn::Store(src_lo_3, int16xN_tag, src_lo + 3 * hn::MaxLanes(int16xN_tag));
- hn::Store(src_hi_3, int16xN_tag, src_hi + 3 * hn::MaxLanes(int16xN_tag));
- } else if constexpr (int16xN_tag.MaxBlocks() == 2) {
- const auto horz_out_6 =
- hn::Load(int16xN_tag, horz_out + (row + 6) * hn::MaxLanes(int16x8_tag));
- const auto horz_out_7 = hn::LoadU(
- int16xN_tag, horz_out + (row + 7) * hn::MaxLanes(int16x8_tag));
- const auto src_lo_3 =
- hn::InterleaveLower(int16xN_tag, horz_out_6, horz_out_7);
- const auto src_hi_3 =
- hn::InterleaveUpper(int16xN_tag, horz_out_6, horz_out_7);
- hn::Store(src_lo_3, int16xN_tag, src_lo + 3 * hn::MaxLanes(int16xN_tag));
- hn::Store(src_hi_3, int16xN_tag, src_hi + 3 * hn::MaxLanes(int16xN_tag));
- } else if constexpr (int16xN_tag.MaxBlocks() == 1) {
- const auto horz_out_6 =
- hn::Load(int16x8_tag, horz_out + (row + 6) * hn::MaxLanes(int16x8_tag));
- const auto horz_out_7 =
- hn::Load(int16x8_tag, horz_out + (row + 7) * hn::MaxLanes(int16x8_tag));
- const auto src_lo_3 =
- hn::InterleaveLower(int16x8_tag, horz_out_6, horz_out_7);
- const auto src_hi_3 =
- hn::InterleaveUpper(int16x8_tag, horz_out_6, horz_out_7);
- hn::Store(src_lo_3, int16x8_tag, src_lo + 3 * hn::MaxLanes(int16x8_tag));
- hn::Store(src_hi_3, int16x8_tag, src_hi + 3 * hn::MaxLanes(int16x8_tag));
- }
-
- const auto coeff_0 =
- hn::Load(int16xN_tag, coeffs + 0 * hn::MaxLanes(int16xN_tag));
- const auto coeff_1 =
- hn::Load(int16xN_tag, coeffs + 1 * hn::MaxLanes(int16xN_tag));
- const auto coeff_2 =
- hn::Load(int16xN_tag, coeffs + 2 * hn::MaxLanes(int16xN_tag));
- const auto coeff_3 =
- hn::Load(int16xN_tag, coeffs + 3 * hn::MaxLanes(int16xN_tag));
- const auto coeff_4 =
- hn::Load(int16xN_tag, coeffs + 4 * hn::MaxLanes(int16xN_tag));
- const auto coeff_5 =
- hn::Load(int16xN_tag, coeffs + 5 * hn::MaxLanes(int16xN_tag));
- const auto coeff_6 =
- hn::Load(int16xN_tag, coeffs + 6 * hn::MaxLanes(int16xN_tag));
- const auto coeff_7 =
- hn::Load(int16xN_tag, coeffs + 7 * hn::MaxLanes(int16xN_tag));
-
- const auto src_lo_0 =
- hn::Load(int16xN_tag, src_lo + 0 * hn::MaxLanes(int16xN_tag));
- const auto src_lo_1 =
- hn::Load(int16xN_tag, src_lo + 1 * hn::MaxLanes(int16xN_tag));
- const auto src_lo_2 =
- hn::Load(int16xN_tag, src_lo + 2 * hn::MaxLanes(int16xN_tag));
- const auto src_lo_3 =
- hn::Load(int16xN_tag, src_lo + 3 * hn::MaxLanes(int16xN_tag));
- const auto src_hi_0 =
- hn::Load(int16xN_tag, src_hi + 0 * hn::MaxLanes(int16xN_tag));
- const auto src_hi_1 =
- hn::Load(int16xN_tag, src_hi + 1 * hn::MaxLanes(int16xN_tag));
- const auto src_hi_2 =
- hn::Load(int16xN_tag, src_hi + 2 * hn::MaxLanes(int16xN_tag));
- const auto src_hi_3 =
- hn::Load(int16xN_tag, src_hi + 3 * hn::MaxLanes(int16xN_tag));
-
+HWY_ATTR HWY_INLINE void FilterPixelsVertical(
+ const IVec16 &src_lo_0, const IVec16 &src_lo_1, const IVec16 &src_lo_2,
+ const IVec16 &src_lo_3, const IVec16 &src_hi_0, const IVec16 &src_hi_1,
+ const IVec16 &src_hi_2, const IVec16 &src_hi_3, const IVec16 &coeff0,
+ const IVec16 &coeff1, const IVec16 &coeff2, const IVec16 &coeff3,
+ const IVec16 &coeff4, const IVec16 &coeff5, const IVec16 &coeff6,
+ const IVec16 &coeff7, IVec32 &HWY_RESTRICT res_lo,
+ IVec32 &HWY_RESTRICT res_hi, const IVec32 &res_add_const) {
auto even_sum0 = res_add_const;
auto even_sum1 = hn::Zero(int32xN_tag);
- even_sum0 = hn::ReorderWidenMulAccumulate(int32xN_tag, src_lo_0, coeff_0,
+ even_sum0 = hn::ReorderWidenMulAccumulate(int32xN_tag, src_lo_0, coeff0,
even_sum0, even_sum1);
- even_sum0 = hn::ReorderWidenMulAccumulate(int32xN_tag, src_lo_1, coeff_1,
+ even_sum0 = hn::ReorderWidenMulAccumulate(int32xN_tag, src_lo_1, coeff1,
even_sum0, even_sum1);
- even_sum0 = hn::ReorderWidenMulAccumulate(int32xN_tag, src_lo_2, coeff_2,
+ even_sum0 = hn::ReorderWidenMulAccumulate(int32xN_tag, src_lo_2, coeff2,
even_sum0, even_sum1);
- even_sum0 = hn::ReorderWidenMulAccumulate(int32xN_tag, src_lo_3, coeff_3,
+ even_sum0 = hn::ReorderWidenMulAccumulate(int32xN_tag, src_lo_3, coeff3,
even_sum0, even_sum1);
auto res_even = hn::RearrangeToOddPlusEven(even_sum0, even_sum1);
auto odd_sum0 = res_add_const;
auto odd_sum1 = hn::Zero(int32xN_tag);
- odd_sum0 = hn::ReorderWidenMulAccumulate(int32xN_tag, src_hi_0, coeff_4,
+ odd_sum0 = hn::ReorderWidenMulAccumulate(int32xN_tag, src_hi_0, coeff4,
odd_sum0, odd_sum1);
- odd_sum0 = hn::ReorderWidenMulAccumulate(int32xN_tag, src_hi_1, coeff_5,
+ odd_sum0 = hn::ReorderWidenMulAccumulate(int32xN_tag, src_hi_1, coeff5,
odd_sum0, odd_sum1);
- odd_sum0 = hn::ReorderWidenMulAccumulate(int32xN_tag, src_hi_2, coeff_6,
+ odd_sum0 = hn::ReorderWidenMulAccumulate(int32xN_tag, src_hi_2, coeff6,
odd_sum0, odd_sum1);
- odd_sum0 = hn::ReorderWidenMulAccumulate(int32xN_tag, src_hi_3, coeff_7,
+ odd_sum0 = hn::ReorderWidenMulAccumulate(int32xN_tag, src_hi_3, coeff7,
odd_sum0, odd_sum1);
auto res_odd = hn::RearrangeToOddPlusEven(odd_sum0, odd_sum1);
@@ -1107,14 +1067,19 @@ HWY_ATTR HWY_INLINE void StoreVerticalFilterOutput(
enum class VerticalFilterCoeffs { kGamma0, kDelta0, kDefault };
template <VerticalFilterCoeffs Filter>
-HWY_ATTR inline void WarpVerticalPrepareCoeffs(int gamma, int delta, int sy,
- int16_t *HWY_RESTRICT coeffs) {
+HWY_ATTR HWY_INLINE void WarpVerticalPrepareCoeffs(
+ int gamma, int delta, int sy, IVec16 &coeff0, IVec16 &coeff1,
+ IVec16 &coeff2, IVec16 &coeff3, IVec16 &coeff4, IVec16 &coeff5,
+ IVec16 &coeff6, IVec16 &coeff7) {
if constexpr (Filter == VerticalFilterCoeffs::kGamma0) {
- PrepareVerticalFilterCoeffsGamma0(gamma, delta, sy, coeffs);
+ PrepareVerticalFilterCoeffsGamma0(gamma, delta, sy, coeff0, coeff1, coeff2,
+ coeff3, coeff4, coeff5, coeff6, coeff7);
} else if constexpr (Filter == VerticalFilterCoeffs::kDelta0) {
- PrepareVerticalFilterCoeffsDelta0(gamma, delta, sy, coeffs);
+ PrepareVerticalFilterCoeffsDelta0(gamma, delta, sy, coeff0, coeff1, coeff2,
+ coeff3, coeff4, coeff5, coeff6, coeff7);
} else {
- PrepareVerticalFilterCoeffs(gamma, delta, sy, coeffs);
+ PrepareVerticalFilterCoeffs(gamma, delta, sy, coeff0, coeff1, coeff2,
+ coeff3, coeff4, coeff5, coeff6, coeff7);
}
}
@@ -1125,8 +1090,14 @@ HWY_ATTR inline void WarpVerticalFilterTemplate(
int p_height, int p_stride, int p_width, int i, int j, int sy4,
const int reduce_bits_vert, const IVec32 res_add_const,
const int round_bits, const IVec16 res_sub_round_const, const IVec16 wt) {
- HWY_ALIGN int16_t src_lo[4 * hn::MaxLanes(int16xN_tag)];
- HWY_ALIGN int16_t src_hi[4 * hn::MaxLanes(int16xN_tag)];
+ IVec16 src_lo_0 = hn::Undefined(int16xN_tag);
+ IVec16 src_lo_1 = hn::Undefined(int16xN_tag);
+ IVec16 src_lo_2 = hn::Undefined(int16xN_tag);
+ IVec16 src_lo_3 = hn::Undefined(int16xN_tag);
+ IVec16 src_hi_0 = hn::Undefined(int16xN_tag);
+ IVec16 src_hi_1 = hn::Undefined(int16xN_tag);
+ IVec16 src_hi_2 = hn::Undefined(int16xN_tag);
+ IVec16 src_hi_3 = hn::Undefined(int16xN_tag);
if constexpr (int16xN_tag.MaxBlocks() >= 3) {
const auto horz_out_0 =
hn::Load(int16xN_tag, horz_out + 0 * hn::MaxLanes(int16x8_tag));
@@ -1136,14 +1107,10 @@ HWY_ATTR inline void WarpVerticalFilterTemplate(
hn::LoadU(int16xN_tag, horz_out + 2 * hn::MaxLanes(int16x8_tag));
const auto horz_out_3 =
hn::LoadU(int16xN_tag, horz_out + 3 * hn::MaxLanes(int16x8_tag));
- hn::Store(hn::InterleaveLower(int16xN_tag, horz_out_0, horz_out_1),
- int16xN_tag, src_lo + 0 * hn::MaxLanes(int16xN_tag));
- hn::Store(hn::InterleaveUpper(int16xN_tag, horz_out_0, horz_out_1),
- int16xN_tag, src_hi + 0 * hn::MaxLanes(int16xN_tag));
- hn::Store(hn::InterleaveLower(int16xN_tag, horz_out_2, horz_out_3),
- int16xN_tag, src_lo + 1 * hn::MaxLanes(int16xN_tag));
- hn::Store(hn::InterleaveUpper(int16xN_tag, horz_out_2, horz_out_3),
- int16xN_tag, src_hi + 1 * hn::MaxLanes(int16xN_tag));
+ src_lo_0 = hn::InterleaveLower(int16xN_tag, horz_out_0, horz_out_1);
+ src_hi_0 = hn::InterleaveUpper(int16xN_tag, horz_out_0, horz_out_1);
+ src_lo_1 = hn::InterleaveLower(int16xN_tag, horz_out_2, horz_out_3);
+ src_hi_1 = hn::InterleaveUpper(int16xN_tag, horz_out_2, horz_out_3);
} else if constexpr (int16xN_tag.MaxBlocks() == 2) {
const auto horz_out_0 =
hn::Load(int16xN_tag, horz_out + 0 * hn::MaxLanes(int16xN_tag));
@@ -1157,18 +1124,12 @@ HWY_ATTR inline void WarpVerticalFilterTemplate(
hn::LoadU(int16xN_tag, horz_out + 3 * hn::MaxLanes(int16x8_tag));
const auto horz_out_5 =
hn::LoadU(int16xN_tag, horz_out + 5 * hn::MaxLanes(int16x8_tag));
- hn::Store(hn::InterleaveLower(int16xN_tag, horz_out_0, horz_out_1),
- int16xN_tag, src_lo + 0 * hn::MaxLanes(int16xN_tag));
- hn::Store(hn::InterleaveUpper(int16xN_tag, horz_out_0, horz_out_1),
- int16xN_tag, src_hi + 0 * hn::MaxLanes(int16xN_tag));
- hn::Store(hn::InterleaveLower(int16xN_tag, horz_out_2, horz_out_3),
- int16xN_tag, src_lo + 1 * hn::MaxLanes(int16xN_tag));
- hn::Store(hn::InterleaveUpper(int16xN_tag, horz_out_2, horz_out_3),
- int16xN_tag, src_hi + 1 * hn::MaxLanes(int16xN_tag));
- hn::Store(hn::InterleaveLower(int16xN_tag, horz_out_4, horz_out_5),
- int16xN_tag, src_lo + 2 * hn::MaxLanes(int16xN_tag));
- hn::Store(hn::InterleaveUpper(int16xN_tag, horz_out_4, horz_out_5),
- int16xN_tag, src_hi + 2 * hn::MaxLanes(int16xN_tag));
+ src_lo_0 = hn::InterleaveLower(int16xN_tag, horz_out_0, horz_out_1);
+ src_hi_0 = hn::InterleaveUpper(int16xN_tag, horz_out_0, horz_out_1);
+ src_lo_1 = hn::InterleaveLower(int16xN_tag, horz_out_2, horz_out_3);
+ src_hi_1 = hn::InterleaveUpper(int16xN_tag, horz_out_2, horz_out_3);
+ src_lo_2 = hn::InterleaveLower(int16xN_tag, horz_out_4, horz_out_5);
+ src_hi_2 = hn::InterleaveUpper(int16xN_tag, horz_out_4, horz_out_5);
} else {
const auto horz_out_0 =
hn::Load(int16xN_tag, horz_out + 0 * hn::MaxLanes(int16xN_tag));
@@ -1182,102 +1143,100 @@ HWY_ATTR inline void WarpVerticalFilterTemplate(
hn::Load(int16xN_tag, horz_out + 4 * hn::MaxLanes(int16xN_tag));
const auto horz_out_5 =
hn::Load(int16xN_tag, horz_out + 5 * hn::MaxLanes(int16xN_tag));
- hn::Store(hn::InterleaveLower(int16xN_tag, horz_out_0, horz_out_1),
- int16xN_tag, src_lo + 0 * hn::MaxLanes(int16xN_tag));
- hn::Store(hn::InterleaveUpper(int16xN_tag, horz_out_0, horz_out_1),
- int16xN_tag, src_hi + 0 * hn::MaxLanes(int16xN_tag));
- hn::Store(hn::InterleaveLower(int16xN_tag, horz_out_2, horz_out_3),
- int16xN_tag, src_lo + 1 * hn::MaxLanes(int16xN_tag));
- hn::Store(hn::InterleaveUpper(int16xN_tag, horz_out_2, horz_out_3),
- int16xN_tag, src_hi + 1 * hn::MaxLanes(int16xN_tag));
- hn::Store(hn::InterleaveLower(int16xN_tag, horz_out_4, horz_out_5),
- int16xN_tag, src_lo + 2 * hn::MaxLanes(int16xN_tag));
- hn::Store(hn::InterleaveUpper(int16xN_tag, horz_out_4, horz_out_5),
- int16xN_tag, src_hi + 2 * hn::MaxLanes(int16xN_tag));
+ src_lo_0 = hn::InterleaveLower(int16xN_tag, horz_out_0, horz_out_1);
+ src_hi_0 = hn::InterleaveUpper(int16xN_tag, horz_out_0, horz_out_1);
+ src_lo_1 = hn::InterleaveLower(int16xN_tag, horz_out_2, horz_out_3);
+ src_hi_1 = hn::InterleaveUpper(int16xN_tag, horz_out_2, horz_out_3);
+ src_lo_2 = hn::InterleaveLower(int16xN_tag, horz_out_4, horz_out_5);
+ src_hi_2 = hn::InterleaveUpper(int16xN_tag, horz_out_4, horz_out_5);
}
- HWY_ALIGN int16_t coeffs[8 * hn::MaxLanes(int16xN_tag)];
+ IVec16 coeff0 = hn::Undefined(int16xN_tag);
+ IVec16 coeff1 = hn::Undefined(int16xN_tag);
+ IVec16 coeff2 = hn::Undefined(int16xN_tag);
+ IVec16 coeff3 = hn::Undefined(int16xN_tag);
+ IVec16 coeff4 = hn::Undefined(int16xN_tag);
+ IVec16 coeff5 = hn::Undefined(int16xN_tag);
+ IVec16 coeff6 = hn::Undefined(int16xN_tag);
+ IVec16 coeff7 = hn::Undefined(int16xN_tag);
if constexpr (!InnerCoeffUpdate) {
- WarpVerticalPrepareCoeffs<Filter>(gamma, delta, sy4, coeffs);
+ WarpVerticalPrepareCoeffs<Filter>(gamma, delta, sy4, coeff0, coeff1, coeff2,
+ coeff3, coeff4, coeff5, coeff6, coeff7);
}
for (int k = -4; k < AOMMIN(4, p_height - i - 4);
k += static_cast<int>(int16xN_tag.MaxBlocks())) {
+ const int row = k + 4;
if constexpr (InnerCoeffUpdate) {
- int sy = sy4 + delta * (k + 4);
- WarpVerticalPrepareCoeffs<Filter>(gamma, delta, sy, coeffs);
+ int sy = sy4 + delta * row;
+ WarpVerticalPrepareCoeffs<Filter>(gamma, delta, sy, coeff0, coeff1,
+ coeff2, coeff3, coeff4, coeff5, coeff6,
+ coeff7);
+ }
+
+ if constexpr (int16xN_tag.MaxBlocks() >= 3) {
+ const auto horz_out_4 = hn::Load(
+ int16xN_tag, horz_out + (row + 4) * hn::MaxLanes(int16x8_tag));
+ const auto horz_out_5 = hn::LoadU(
+ int16xN_tag, horz_out + (row + 5) * hn::MaxLanes(int16x8_tag));
+ const auto horz_out_6 = hn::LoadU(
+ int16xN_tag, horz_out + (row + 6) * hn::MaxLanes(int16x8_tag));
+ const auto horz_out_7 = hn::LoadU(
+ int16xN_tag, horz_out + (row + 7) * hn::MaxLanes(int16x8_tag));
+ src_lo_2 = hn::InterleaveLower(int16xN_tag, horz_out_4, horz_out_5);
+ src_hi_2 = hn::InterleaveUpper(int16xN_tag, horz_out_4, horz_out_5);
+ src_lo_3 = hn::InterleaveLower(int16xN_tag, horz_out_6, horz_out_7);
+ src_hi_3 = hn::InterleaveUpper(int16xN_tag, horz_out_6, horz_out_7);
+ } else if constexpr (int16xN_tag.MaxBlocks() == 2) {
+ const auto horz_out_6 = hn::Load(
+ int16xN_tag, horz_out + (row + 6) * hn::MaxLanes(int16x8_tag));
+ const auto horz_out_7 = hn::LoadU(
+ int16xN_tag, horz_out + (row + 7) * hn::MaxLanes(int16x8_tag));
+ src_lo_3 = hn::InterleaveLower(int16xN_tag, horz_out_6, horz_out_7);
+ src_hi_3 = hn::InterleaveUpper(int16xN_tag, horz_out_6, horz_out_7);
+ } else if constexpr (int16xN_tag.MaxBlocks() == 1) {
+ const auto horz_out_6 = hn::Load(
+ int16xN_tag, horz_out + (row + 6) * hn::MaxLanes(int16x8_tag));
+ const auto horz_out_7 = hn::Load(
+ int16xN_tag, horz_out + (row + 7) * hn::MaxLanes(int16x8_tag));
+ src_lo_3 = hn::InterleaveLower(int16xN_tag, horz_out_6, horz_out_7);
+ src_hi_3 = hn::InterleaveUpper(int16xN_tag, horz_out_6, horz_out_7);
}
IVec32 res_lo, res_hi;
- FilterPixelsVertical(horz_out, src_lo, src_hi, coeffs, res_lo, res_hi,
- k + 4, res_add_const);
+ FilterPixelsVertical(src_lo_0, src_lo_1, src_lo_2, src_lo_3, src_hi_0,
+ src_hi_1, src_hi_2, src_hi_3, coeff0, coeff1, coeff2,
+ coeff3, coeff4, coeff5, coeff6, coeff7, res_lo, res_hi,
+ res_add_const);
StoreVerticalFilterOutput(res_lo, res_hi, wt, res_sub_round_const, pred,
- conv_params, i, j, k + 4, reduce_bits_vert,
+ conv_params, i, j, row, reduce_bits_vert,
p_stride, p_width, round_bits);
if constexpr (int16xN_tag.MaxBlocks() >= 3) {
- hn::Store(hn::Load(int16xN_tag, src_lo + 2 * hn::MaxLanes(int16xN_tag)),
- int16xN_tag, src_lo + 0 * hn::MaxLanes(int16xN_tag));
- hn::Store(hn::Load(int16xN_tag, src_lo + 3 * hn::MaxLanes(int16xN_tag)),
- int16xN_tag, src_lo + 1 * hn::MaxLanes(int16xN_tag));
- hn::Store(hn::Load(int16xN_tag, src_hi + 2 * hn::MaxLanes(int16xN_tag)),
- int16xN_tag, src_hi + 0 * hn::MaxLanes(int16xN_tag));
- hn::Store(hn::Load(int16xN_tag, src_hi + 3 * hn::MaxLanes(int16xN_tag)),
- int16xN_tag, src_hi + 1 * hn::MaxLanes(int16xN_tag));
+ src_lo_0 = src_lo_2;
+ src_lo_1 = src_lo_3;
+ src_hi_0 = src_hi_2;
+ src_hi_1 = src_hi_3;
} else if constexpr (int16xN_tag.MaxBlocks() == 2) {
- hn::Store(hn::Load(int16xN_tag, src_lo + 1 * hn::MaxLanes(int16xN_tag)),
- int16xN_tag, src_lo + 0 * hn::MaxLanes(int16xN_tag));
- hn::Store(hn::Load(int16xN_tag, src_lo + 2 * hn::MaxLanes(int16xN_tag)),
- int16xN_tag, src_lo + 1 * hn::MaxLanes(int16xN_tag));
- hn::Store(hn::Load(int16xN_tag, src_lo + 3 * hn::MaxLanes(int16xN_tag)),
- int16xN_tag, src_lo + 2 * hn::MaxLanes(int16xN_tag));
- hn::Store(hn::Load(int16xN_tag, src_hi + 1 * hn::MaxLanes(int16xN_tag)),
- int16xN_tag, src_hi + 0 * hn::MaxLanes(int16xN_tag));
- hn::Store(hn::Load(int16xN_tag, src_hi + 2 * hn::MaxLanes(int16xN_tag)),
- int16xN_tag, src_hi + 1 * hn::MaxLanes(int16xN_tag));
- hn::Store(hn::Load(int16xN_tag, src_hi + 3 * hn::MaxLanes(int16xN_tag)),
- int16xN_tag, src_hi + 2 * hn::MaxLanes(int16xN_tag));
+ src_lo_0 = src_lo_1;
+ src_lo_1 = src_lo_2;
+ src_lo_2 = src_lo_3;
+ src_hi_0 = src_hi_1;
+ src_hi_1 = src_hi_2;
+ src_hi_2 = src_hi_3;
} else if constexpr (int16xN_tag.MaxBlocks() == 1) {
- const auto src_lo_0 =
- hn::Load(int16xN_tag, src_lo + 0 * hn::MaxLanes(int16xN_tag));
- const auto src_lo_1 =
- hn::Load(int16xN_tag, src_lo + 1 * hn::MaxLanes(int16xN_tag));
- const auto src_lo_2 =
- hn::Load(int16xN_tag, src_lo + 2 * hn::MaxLanes(int16xN_tag));
- const auto src_lo_3 =
- hn::Load(int16xN_tag, src_lo + 3 * hn::MaxLanes(int16xN_tag));
- const auto src_lo_0_new = hn::InterleaveEven(
+ src_lo_0 = hn::InterleaveEven(
hn::ShiftRightLanes<1>(int16xN_tag, src_lo_0), src_lo_1);
- const auto src_lo_1_new = hn::InterleaveEven(
+ src_lo_1 = hn::InterleaveEven(
hn::ShiftRightLanes<1>(int16xN_tag, src_lo_1), src_lo_2);
- const auto src_lo_2_new = hn::InterleaveEven(
+ src_lo_2 = hn::InterleaveEven(
hn::ShiftRightLanes<1>(int16xN_tag, src_lo_2), src_lo_3);
- hn::Store(src_lo_0_new, int16xN_tag,
- src_lo + 0 * hn::MaxLanes(int16xN_tag));
- hn::Store(src_lo_1_new, int16xN_tag,
- src_lo + 1 * hn::MaxLanes(int16xN_tag));
- hn::Store(src_lo_2_new, int16xN_tag,
- src_lo + 2 * hn::MaxLanes(int16xN_tag));
- const auto src_hi_0 =
- hn::Load(int16xN_tag, src_hi + 0 * hn::MaxLanes(int16xN_tag));
- const auto src_hi_1 =
- hn::Load(int16xN_tag, src_hi + 1 * hn::MaxLanes(int16xN_tag));
- const auto src_hi_2 =
- hn::Load(int16xN_tag, src_hi + 2 * hn::MaxLanes(int16xN_tag));
- const auto src_hi_3 =
- hn::Load(int16xN_tag, src_hi + 3 * hn::MaxLanes(int16xN_tag));
- const auto src_hi_0_new = hn::InterleaveEven(
+ src_hi_0 = hn::InterleaveEven(
hn::ShiftRightLanes<1>(int16xN_tag, src_hi_0), src_hi_1);
- const auto src_hi_1_new = hn::InterleaveEven(
+ src_hi_1 = hn::InterleaveEven(
hn::ShiftRightLanes<1>(int16xN_tag, src_hi_1), src_hi_2);
- const auto src_hi_2_new = hn::InterleaveEven(
+ src_hi_2 = hn::InterleaveEven(
hn::ShiftRightLanes<1>(int16xN_tag, src_hi_2), src_hi_3);
- hn::Store(src_hi_0_new, int16xN_tag,
- src_hi + 0 * hn::MaxLanes(int16xN_tag));
- hn::Store(src_hi_1_new, int16xN_tag,
- src_hi + 1 * hn::MaxLanes(int16xN_tag));
- hn::Store(src_hi_2_new, int16xN_tag,
- src_hi + 2 * hn::MaxLanes(int16xN_tag));
}
}
}
@@ -1456,9 +1415,12 @@ HWY_ATTR void WarpHorizontalFilterOutOfBoundsPad(
src = hn::TableLookupBytes(src, shuffle_reg_right);
}
sx = sx4 + beta * (k + 4);
- HWY_ALIGN int8_t coeff[4 * hn::MaxLanes(coeff_tag)];
- PrepareLastHorizontalFilterCoefficients(int16xN_tag, alpha, beta, sx, coeff);
- FilterPixelsHorizontal(uint8x16_tag, src, horz_out, coeff, round_const,
+ IVec8x16 tail_coeff0, tail_coeff1, tail_coeff2, tail_coeff3;
+ PrepareLastHorizontalFilterCoefficients(int16x8_tag, alpha, beta, sx,
+ tail_coeff0, tail_coeff1, tail_coeff2,
+ tail_coeff3);
+ FilterPixelsHorizontal(uint8x16_tag, src, horz_out, tail_coeff0, tail_coeff1,
+ tail_coeff2, tail_coeff3, round_const,
reduce_bits_horiz, k + 7);
}