Commit 7beff30a38 for aom
commit 7beff30a380931ed9a21e1dcdb93da784141bfd8
Author: Frank Galligan <fgalligan@google.com>
Date: Tue Nov 17 06:28:33 2026 -0800
av1,neon: Optimize filter_intra & intra edge
Rewrite av1_filter_intra_predictor_neon() (single-accumulator
vmull/vmlal carry at width <= 8, countdown row loop across widths)
and av1_filter_intra_predictor_neon_i8mm() (vsudotq_lane_s32 across
bw in {4, 8, 16, 32}) to reduce dst top-pixel reloads: width <= 8
(NEON) and bw <= 16 (I8MM) carry interior top pixels in registers,
while NEON width >= 16 and I8MM bw == 32 still reload dst.
Restore full I8MM dispatch for all 14 tx sizes: swapping
gather_p_left vcombine_u8(prev_top, cur_left) cuts stall latency so
the I8MM kernel beats NEON on every shape on A720 (-17.7% to -59.9%)
and beats baseline I8MM on A720 (-14.7% to -68.9%) and A520 (-22.5% to
-39.5%). Keep single-acc NEON, left[] loads, and I8MM bw == 32
store_u8x4_strided_x2 after A720/A520 AB checks showed alternatives
regressed. Use load_unaligned_dup_u8_4x2 for UBSan integer cleanliness.
Vectorize small/medium tails and remove stack buffers in
av1_filter_intra_edge_neon() and av1_upsample_intra_edge_neon(), using
vrhadd(vhadd) / vhadd+vrshrn edge filters, canonical rem > 16 fast
paths, and AOM_ARCH_AARCH64 guards with ARMv7 fallbacks. Set
UpsampleTest::kMaxEdge = 16 and add FilterEdgeTest8B.AllSizes across
sz in [1, 129] with NEON guard-byte checks.
Note: Pixel 9 A720 has I8MM, so end-to-end runs execute the I8MM path
rather than av1_filter_intra_predictor_neon. Kernel microbenchmarks
(Pixel 9 A720 @ 2.60 GHz, 3-round paired): FilterIntra NEON -5.1% to
-31.4% for width <= 8 (-4.4%..+2.0% at width >= 16); I8MM -14.7% to
-68.9% (-22.5%..-39.5% A520); FilterEdge8B -41.2% (-46.1% A520);
UpsampleTest8B.DISABLED_Speed 139 ms A720 / 302 ms A520. Unit tests
pass (217/217 ARM64, 147/147 x86); hash108 108/108 match (RTCD & 0x0).
Speedup (Pixel 9 Tensor G4 Cortex-A720, 1T, realtime 768x1024 intra,
bit-exact): -0.83% (speed 6), -2.33% (speed 7) encode time (-1.55%
R1 paired; min-of-2 -1.45% s6, -3.15% s7, -2.27% overall).
TAG=agy
CONV=bc5228f2-7fa6-4522-aad6-34935d739e28
Change-Id: Id4644132138a2c43db6722413ddc34450f2a0cad
diff --git a/av1/common/arm/reconintra_neon.c b/av1/common/arm/reconintra_neon.c
index 9ac013f008..1d1331cae2 100644
--- a/av1/common/arm/reconintra_neon.c
+++ b/av1/common/arm/reconintra_neon.c
@@ -11,6 +11,7 @@
#include <arm_neon.h>
#include <assert.h>
+#include <string.h>
#include "config/aom_config.h"
#include "config/av1_rtcd.h"
@@ -19,7 +20,6 @@
#include "aom_dsp/arm/mem_neon.h"
#include "aom_dsp/arm/sum_neon.h"
-#define MAX_UPSAMPLE_SZ 16
#define FILTER_INTRA_SCALE_BITS 4
// These kernels are a transposed version of those defined in reconintra.c,
@@ -95,9 +95,12 @@ static inline uint8x8_t filter_intra_predictor(
void av1_filter_intra_predictor_neon(uint8_t *dst, ptrdiff_t stride,
TX_SIZE tx_size, const uint8_t *above,
const uint8_t *left, int mode) {
+ assert(tx_size < TX_SIZES_ALL);
+ assert(mode >= 0 && mode < FILTER_INTRA_MODES);
const int width = tx_size_wide[tx_size];
const int height = tx_size_high[tx_size];
- assert(width <= 32 && height <= 32);
+ assert(width >= 4 && width <= 32 && height >= 4 && height <= 32);
+ assert((height & 1) == 0);
const uint8x8_t f0 = vld1_u8(av1_filter_intra_taps_neon[mode][0]);
const uint8x8_t f1 = vld1_u8(av1_filter_intra_taps_neon[mode][1]);
@@ -107,61 +110,116 @@ void av1_filter_intra_predictor_neon(uint8_t *dst, ptrdiff_t stride,
const uint8x8_t f5 = vld1_u8(av1_filter_intra_taps_neon[mode][5]);
const uint8x8_t f6 = vld1_u8(av1_filter_intra_taps_neon[mode][6]);
- // Computing 4 cols per iteration (instead of 8) for 8x<h> blocks is faster.
- if (width <= 8) {
+ if (width == 4) {
uint8x8_t s0 = vdup_n_u8(above[-1]);
uint8x8_t s5 = vdup_n_u8(left[0]);
uint8x8_t s6 = vdup_n_u8(left[1]);
- int c = 0;
- do {
- uint8x8_t s1234 = load_unaligned_u8_4x1(above + c);
- uint8x8_t s1 = vdup_lane_u8(s1234, 0);
- uint8x8_t s2 = vdup_lane_u8(s1234, 1);
- uint8x8_t s3 = vdup_lane_u8(s1234, 2);
- uint8x8_t s4 = vdup_lane_u8(s1234, 3);
-
- uint8x8_t res = filter_intra_predictor(s0, s1, s2, s3, s4, s5, s6, f0, f1,
- f2, f3, f4, f5, f6);
+ uint8x8_t s1234 = load_unaligned_dup_u8_4x2(above);
+ uint8x8_t s1 = vdup_lane_u8(s1234, 0);
+ uint8x8_t s2 = vdup_lane_u8(s1234, 1);
+ uint8x8_t s3 = vdup_lane_u8(s1234, 2);
+ uint8x8_t s4 = vdup_lane_u8(s1234, 3);
- store_u8x4_strided_x2(dst + c, stride, res);
+ uint8x8_t res = filter_intra_predictor(s0, s1, s2, s3, s4, s5, s6, f0, f1,
+ f2, f3, f4, f5, f6);
- s0 = s4;
- s5 = vdup_lane_u8(res, 3);
- s6 = vdup_lane_u8(res, 7);
+ store_u8x4_strided_x2(dst, stride, res);
- c += 4;
- } while (c < width);
-
- int r = 2;
+ left += 1;
+ int h = height - 2;
+ dst += 2 * stride;
do {
- s0 = vdup_n_u8(left[r - 1]);
- s5 = vdup_n_u8(left[r + 0]);
- s6 = vdup_n_u8(left[r + 1]);
+ s0 = vdup_n_u8(left[0]);
+ s5 = vdup_n_u8(left[1]);
+ s6 = vdup_n_u8(left[2]);
- c = 0;
- do {
- uint8x8_t s1234 = load_u8_4x1(dst + (r - 1) * stride + c);
- uint8x8_t s1 = vdup_lane_u8(s1234, 0);
- uint8x8_t s2 = vdup_lane_u8(s1234, 1);
- uint8x8_t s3 = vdup_lane_u8(s1234, 2);
- uint8x8_t s4 = vdup_lane_u8(s1234, 3);
+ s1 = vdup_lane_u8(res, 4);
+ s2 = vdup_lane_u8(res, 5);
+ s3 = vdup_lane_u8(res, 6);
+ s4 = vdup_lane_u8(res, 7);
- uint8x8_t res = filter_intra_predictor(s0, s1, s2, s3, s4, s5, s6, f0,
- f1, f2, f3, f4, f5, f6);
+ res = filter_intra_predictor(s0, s1, s2, s3, s4, s5, s6, f0, f1, f2, f3,
+ f4, f5, f6);
- store_u8x4_strided_x2(dst + r * stride + c, stride, res);
+ store_u8x4_strided_x2(dst, stride, res);
- s0 = s4;
- s5 = vdup_lane_u8(res, 3);
- s6 = vdup_lane_u8(res, 7);
+ left += 2;
+ dst += 2 * stride;
+ h -= 2;
+ } while (h != 0);
+ } else if (width == 8) {
+ uint8x8_t s0_lo = vdup_n_u8(above[-1]);
+ uint8x8_t s5_lo = vdup_n_u8(left[0]);
+ uint8x8_t s6_lo = vdup_n_u8(left[1]);
+ const uint8x8_t abv = vld1_u8(above);
+
+ uint8x8_t s1_lo = vdup_lane_u8(abv, 0);
+ uint8x8_t s2_lo = vdup_lane_u8(abv, 1);
+ uint8x8_t s3_lo = vdup_lane_u8(abv, 2);
+ uint8x8_t s4_lo = vdup_lane_u8(abv, 3);
+
+ uint8x8_t res_lo =
+ filter_intra_predictor(s0_lo, s1_lo, s2_lo, s3_lo, s4_lo, s5_lo, s6_lo,
+ f0, f1, f2, f3, f4, f5, f6);
+
+ uint8x8_t s0_hi = s4_lo;
+ uint8x8_t s1_hi = vdup_lane_u8(abv, 4);
+ uint8x8_t s2_hi = vdup_lane_u8(abv, 5);
+ uint8x8_t s3_hi = vdup_lane_u8(abv, 6);
+ uint8x8_t s4_hi = vdup_lane_u8(abv, 7);
+ uint8x8_t s5_hi = vdup_lane_u8(res_lo, 3);
+ uint8x8_t s6_hi = vdup_lane_u8(res_lo, 7);
+
+ uint8x8_t res_hi =
+ filter_intra_predictor(s0_hi, s1_hi, s2_hi, s3_hi, s4_hi, s5_hi, s6_hi,
+ f0, f1, f2, f3, f4, f5, f6);
+
+ uint32x2x2_t res_zip =
+ vzip_u32(vreinterpret_u32_u8(res_lo), vreinterpret_u32_u8(res_hi));
+
+ vst1_u8(dst + 0 * stride, vreinterpret_u8_u32(res_zip.val[0]));
+ vst1_u8(dst + 1 * stride, vreinterpret_u8_u32(res_zip.val[1]));
+
+ left += 1;
+ int h = height - 2;
+ dst += 2 * stride;
+ do {
+ s0_lo = vdup_n_u8(left[0]);
+ s5_lo = vdup_n_u8(left[1]);
+ s6_lo = vdup_n_u8(left[2]);
+
+ s1_lo = vdup_lane_u8(res_lo, 4);
+ s2_lo = vdup_lane_u8(res_lo, 5);
+ s3_lo = vdup_lane_u8(res_lo, 6);
+ s4_lo = vdup_lane_u8(res_lo, 7);
+
+ res_lo = filter_intra_predictor(s0_lo, s1_lo, s2_lo, s3_lo, s4_lo, s5_lo,
+ s6_lo, f0, f1, f2, f3, f4, f5, f6);
+
+ s0_hi = s4_lo;
+ s1_hi = vdup_lane_u8(res_hi, 4);
+ s2_hi = vdup_lane_u8(res_hi, 5);
+ s3_hi = vdup_lane_u8(res_hi, 6);
+ s4_hi = vdup_lane_u8(res_hi, 7);
+ s5_hi = vdup_lane_u8(res_lo, 3);
+ s6_hi = vdup_lane_u8(res_lo, 7);
+
+ res_hi = filter_intra_predictor(s0_hi, s1_hi, s2_hi, s3_hi, s4_hi, s5_hi,
+ s6_hi, f0, f1, f2, f3, f4, f5, f6);
+
+ res_zip =
+ vzip_u32(vreinterpret_u32_u8(res_lo), vreinterpret_u32_u8(res_hi));
- c += 4;
- } while (c < width);
+ vst1_u8(dst + 0 * stride, vreinterpret_u8_u32(res_zip.val[0]));
+ vst1_u8(dst + 1 * stride, vreinterpret_u8_u32(res_zip.val[1]));
- r += 2;
- } while (r < height);
+ left += 2;
+ dst += 2 * stride;
+ h -= 2;
+ } while (h != 0);
} else {
+ assert(width >= 16 && (width & 7) == 0);
uint8x8_t s0_lo = vdup_n_u8(above[-1]);
uint8x8_t s5_lo = vdup_n_u8(left[0]);
uint8x8_t s6_lo = vdup_n_u8(left[1]);
@@ -199,18 +257,21 @@ void av1_filter_intra_predictor_neon(uint8_t *dst, ptrdiff_t stride,
s0_lo = s4_hi;
s5_lo = vdup_lane_u8(res_hi, 3);
s6_lo = vdup_lane_u8(res_hi, 7);
+
c += 8;
- } while (c < width);
+ } while (c != width);
- int r = 2;
+ left += 1;
+ int h = height - 2;
+ dst += 2 * stride;
do {
- s0_lo = vdup_n_u8(left[r - 1]);
- s5_lo = vdup_n_u8(left[r + 0]);
- s6_lo = vdup_n_u8(left[r + 1]);
+ s0_lo = vdup_n_u8(left[0]);
+ s5_lo = vdup_n_u8(left[1]);
+ s6_lo = vdup_n_u8(left[2]);
c = 0;
do {
- uint8x8_t s1234 = vld1_u8(dst + (r - 1) * stride + c);
+ uint8x8_t s1234 = vld1_u8(dst - stride + c);
uint8x8_t s1_lo = vdup_lane_u8(s1234, 0);
uint8x8_t s2_lo = vdup_lane_u8(s1234, 1);
uint8x8_t s3_lo = vdup_lane_u8(s1234, 2);
@@ -235,198 +296,391 @@ void av1_filter_intra_predictor_neon(uint8_t *dst, ptrdiff_t stride,
uint32x2x2_t res =
vzip_u32(vreinterpret_u32_u8(res_lo), vreinterpret_u32_u8(res_hi));
- vst1_u8(dst + (r + 0) * stride + c, vreinterpret_u8_u32(res.val[0]));
- vst1_u8(dst + (r + 1) * stride + c, vreinterpret_u8_u32(res.val[1]));
+ vst1_u8(dst + 0 * stride + c, vreinterpret_u8_u32(res.val[0]));
+ vst1_u8(dst + 1 * stride + c, vreinterpret_u8_u32(res.val[1]));
s0_lo = s4_hi;
s5_lo = vdup_lane_u8(res_hi, 3);
s6_lo = vdup_lane_u8(res_hi, 7);
+
c += 8;
- } while (c < width);
+ } while (c != width);
- r += 2;
- } while (r < height);
+ left += 2;
+ dst += 2 * stride;
+ h -= 2;
+ } while (h != 0);
}
}
-void av1_filter_intra_edge_neon(uint8_t *p, int sz, int strength) {
- if (!strength) return;
- assert(sz >= 0 && sz <= 129);
+DECLARE_ALIGNED(16, static const uint8_t,
+ kEdgeTailIdx[16]) = { 0, 1, 2, 3, 4, 5, 6, 7,
+ 8, 9, 10, 11, 12, 13, 14, 15 };
+
+static inline uint8x8_t load_padded_u8x8(const uint8_t *p, int n, uint8_t pad) {
+ assert(n >= 1 && n <= 8);
+ if (n == 8) return vld1_u8(p);
+ uint64_t val = 0;
+ int shift = 0;
+ if (n & 4) {
+ uint32_t w;
+ memcpy(&w, p, 4);
+ val = (uint64_t)w;
+ p += 4;
+ shift = 32;
+ }
+ if (n & 2) {
+ uint16_t h;
+ memcpy(&h, p, 2);
+ val |= (uint64_t)h << shift;
+ p += 2;
+ shift += 16;
+ }
+ if (n & 1) {
+ val |= (uint64_t)(*p) << shift;
+ }
+ const uint64_t pad64 = (uint64_t)pad * 0x0101010101010101ULL;
+ const uint64_t mask = (1ULL << (n * 8)) - 1ULL;
+ return vcreate_u8(val | (pad64 & ~mask));
+}
- uint8_t edge[160]; // Max value of sz + enough padding for vector accesses.
- memcpy(edge + 1, p, sz * sizeof(*p));
+static inline uint8x8_t load_tail_u8x8(const uint8_t *end_ptr, int k) {
+ assert(k >= 1 && k <= 8);
+ const uint8x8_t raw = vld1_u8(end_ptr - 8);
+ const uint8x8_t shift = vdup_n_u8((uint8_t)(8 - k));
+ const uint8x8_t idx =
+ vmin_u8(vadd_u8(vld1_u8(kEdgeTailIdx), shift), vdup_n_u8(7));
+ return vtbl1_u8(raw, idx);
+}
- // Populate extra space appropriately.
- edge[0] = edge[1];
- edge[sz + 1] = edge[sz];
- edge[sz + 2] = edge[sz];
+static inline void store_partial_u8x8(uint8_t *dst, uint8x8_t res, int n) {
+ assert(n >= 1 && n <= 8);
+ if (n == 8) {
+ vst1_u8(dst, res);
+ return;
+ }
+ uint64_t val = vget_lane_u64(vreinterpret_u64_u8(res), 0);
+ if (n & 4) {
+ uint32_t w = (uint32_t)val;
+ memcpy(dst, &w, 4);
+ dst += 4;
+ val >>= 32;
+ }
+ if (n & 2) {
+ uint16_t h = (uint16_t)val;
+ memcpy(dst, &h, 2);
+ dst += 2;
+ val >>= 16;
+ }
+ if (n & 1) {
+ *dst = (uint8_t)val;
+ }
+}
- // Don't overwrite first pixel.
- uint8_t *dst = p + 1;
- sz--;
+static inline void store_partial_u8x16(uint8_t *dst, uint8x16_t res, int n) {
+ assert(n >= 1 && n <= 16);
+ if (n == 16) {
+ vst1q_u8(dst, res);
+ return;
+ }
+ uint8x8_t lo = vget_low_u8(res);
+ if (n >= 8) {
+ vst1_u8(dst, lo);
+ dst += 8;
+ n -= 8;
+ if (!n) return;
+ lo = vget_high_u8(res);
+ }
+ store_partial_u8x8(dst, lo, n);
+}
- if (strength == 1) { // Filter: {4, 8, 4}.
- const uint8_t *src = edge + 1;
+static inline uint8x16_t load_tail_u8x16(const uint8_t *end_ptr, int k) {
+ assert(k >= 1 && k <= 15);
+ const uint8x16_t raw = vld1q_u8(end_ptr - 16);
+ const uint8x16_t shift = vdupq_n_u8((uint8_t)(16 - k));
+ const uint8x16_t idx =
+ vminq_u8(vaddq_u8(vld1q_u8(kEdgeTailIdx), shift), vdupq_n_u8(15));
+#if AOM_ARCH_AARCH64
+ return vqtbl1q_u8(raw, idx);
+#else
+ const uint8x8x2_t tbl = { { vget_low_u8(raw), vget_high_u8(raw) } };
+ return vcombine_u8(vtbl2_u8(tbl, vget_low_u8(idx)),
+ vtbl2_u8(tbl, vget_high_u8(idx)));
+#endif
+}
- while (sz >= 8) {
- uint8x8_t s0 = vld1_u8(src);
- uint8x8_t s1 = vld1_u8(src + 1);
- uint8x8_t s2 = vld1_u8(src + 2);
+static inline uint8x8_t filter_edge_s1_x8(uint8x8_t in0, uint8x8_t in1) {
+ const uint8x8_t s1 = vext_u8(in0, in1, 1);
+ const uint8x8_t s2 = vext_u8(in0, in1, 2);
+ return vrhadd_u8(vhadd_u8(in0, s2), s1);
+}
- // Make use of the identity:
- // (4*a + 8*b + 4*c) >> 4 == (a + (b << 1) + c) >> 2
- uint16x8_t t0 = vaddl_u8(s0, s2);
- uint16x8_t t1 = vaddl_u8(s1, s1);
- uint16x8_t sum = vaddq_u16(t0, t1);
- uint8x8_t res = vrshrn_n_u16(sum, 2);
+static inline uint8x16_t filter_edge_s1_x16(uint8x16_t in0, uint8x16_t in1) {
+ const uint8x16_t s1 = vextq_u8(in0, in1, 1);
+ const uint8x16_t s2 = vextq_u8(in0, in1, 2);
+ return vrhaddq_u8(vhaddq_u8(in0, s2), s1);
+}
- vst1_u8(dst, res);
+static inline uint8x8_t filter_edge_s2_x8(uint8x8_t in0, uint8x8_t in1,
+ uint8x8_t f5, uint8x8_t f6) {
+ const uint8x8_t s0 = in0;
+ const uint8x8_t s1 = vext_u8(in0, in1, 1);
+ const uint8x8_t s2 = vext_u8(in0, in1, 2);
+ uint16x8_t accum = vmull_u8(s0, f5);
+ accum = vmlal_u8(accum, s1, f6);
+ accum = vmlal_u8(accum, s2, f5);
+ return vrshrn_n_u16(accum, 4);
+}
- src += 8;
- dst += 8;
- sz -= 8;
- }
+static inline uint8x16_t filter_edge_s2_x16(uint8x16_t in0, uint8x16_t in1,
+ uint8x16_t f5q, uint8x16_t f6q) {
+ const uint8x16_t s0 = in0;
+ const uint8x16_t s1 = vextq_u8(in0, in1, 1);
+ const uint8x16_t s2 = vextq_u8(in0, in1, 2);
+
+ uint16x8_t acc_lo = vmull_u8(vget_low_u8(s0), vget_low_u8(f5q));
+ acc_lo = vmlal_u8(acc_lo, vget_low_u8(s1), vget_low_u8(f6q));
+ acc_lo = vmlal_u8(acc_lo, vget_low_u8(s2), vget_low_u8(f5q));
+ const uint8x8_t res_lo = vrshrn_n_u16(acc_lo, 4);
+
+#if AOM_ARCH_AARCH64
+ uint16x8_t acc_hi = vmull_high_u8(s0, f5q);
+ acc_hi = vmlal_high_u8(acc_hi, s1, f6q);
+ acc_hi = vmlal_high_u8(acc_hi, s2, f5q);
+#else
+ uint16x8_t acc_hi = vmull_u8(vget_high_u8(s0), vget_high_u8(f5q));
+ acc_hi = vmlal_u8(acc_hi, vget_high_u8(s1), vget_high_u8(f6q));
+ acc_hi = vmlal_u8(acc_hi, vget_high_u8(s2), vget_high_u8(f5q));
+#endif
+ const uint8x8_t res_hi = vrshrn_n_u16(acc_hi, 4);
+
+ return vcombine_u8(res_lo, res_hi);
+}
- if (sz > 0) { // Handle sz < 8 to avoid modifying out-of-bounds values.
- uint8x8_t s0 = vld1_u8(src);
- uint8x8_t s1 = vld1_u8(src + 1);
- uint8x8_t s2 = vld1_u8(src + 2);
+static inline uint8x8_t filter_edge_s3_x8(uint8x8_t prev, uint8x8_t in0,
+ uint8x8_t in1) {
+ const uint8x8_t s0 = vext_u8(prev, in0, 7);
+ const uint8x8_t s1 = in0;
+ const uint8x8_t s2 = vext_u8(in0, in1, 1);
+ const uint8x8_t s3 = vext_u8(in0, in1, 2);
+ const uint8x8_t s4 = vext_u8(in0, in1, 3);
+
+ const uint8x8_t h04 = vhadd_u8(s0, s4);
+ uint16x8_t sum = vaddl_u8(s1, s2);
+ sum = vaddw_u8(sum, s3);
+ sum = vaddw_u8(sum, h04);
+ return vrshrn_n_u16(sum, 2);
+}
- uint16x8_t t0 = vaddl_u8(s0, s2);
- uint16x8_t t1 = vaddl_u8(s1, s1);
- uint16x8_t sum = vaddq_u16(t0, t1);
- uint8x8_t res = vrshrn_n_u16(sum, 2);
+static inline uint8x16_t filter_edge_s3_x16(uint8x16_t prev, uint8x16_t in0,
+ uint8x16_t in1) {
+ const uint8x16_t s0 = vextq_u8(prev, in0, 15);
+ const uint8x16_t s1 = in0;
+ const uint8x16_t s2 = vextq_u8(in0, in1, 1);
+ const uint8x16_t s3 = vextq_u8(in0, in1, 2);
+ const uint8x16_t s4 = vextq_u8(in0, in1, 3);
+
+ const uint8x16_t h04 = vhaddq_u8(s0, s4);
+ uint16x8_t sum_lo = vaddl_u8(vget_low_u8(s1), vget_low_u8(s2));
+ sum_lo = vaddw_u8(sum_lo, vget_low_u8(s3));
+ sum_lo = vaddw_u8(sum_lo, vget_low_u8(h04));
+ const uint8x8_t res_lo = vrshrn_n_u16(sum_lo, 2);
+
+#if AOM_ARCH_AARCH64
+ uint16x8_t sum_hi = vaddl_high_u8(s1, s2);
+ sum_hi = vaddw_high_u8(sum_hi, s3);
+ sum_hi = vaddw_high_u8(sum_hi, h04);
+#else
+ uint16x8_t sum_hi = vaddl_u8(vget_high_u8(s1), vget_high_u8(s2));
+ sum_hi = vaddw_u8(sum_hi, vget_high_u8(s3));
+ sum_hi = vaddw_u8(sum_hi, vget_high_u8(h04));
+#endif
+ const uint8x8_t res_hi = vrshrn_n_u16(sum_hi, 2);
+
+ return vcombine_u8(res_lo, res_hi);
+}
- // Mask off out-of-bounds indices.
- uint8x8_t current_dst = vld1_u8(dst);
- uint8x8_t mask = vcgt_u8(vdup_n_u8(sz), vcreate_u8(0x0706050403020100));
- res = vbsl_u8(mask, res, current_dst);
+void av1_filter_intra_edge_neon(uint8_t *p, int sz, int strength) {
+ assert(sz >= 0 && sz <= 129);
+ assert(strength >= 0 && strength <= 3);
+ if (!strength || sz <= 1) return;
- vst1_u8(dst, res);
+ uint8_t *dst = p + 1;
+ int rem = sz - 1;
+
+ if (sz <= 9) {
+ const uint8_t last = p[sz - 1];
+ const uint8x8_t in0 =
+ (sz == 9) ? vld1_u8(p) : load_padded_u8x8(p, sz, last);
+ const uint8x8_t in1 = vdup_n_u8(last);
+ uint8x8_t res;
+ if (strength == 1) {
+ res = filter_edge_s1_x8(in0, in1);
+ } else if (strength == 2) {
+ res = filter_edge_s2_x8(in0, in1, vdup_n_u8(5), vdup_n_u8(6));
+ } else {
+ res = filter_edge_s3_x8(vdup_n_u8(p[0]), in0, in1);
}
- } else if (strength == 2) { // Filter: {5, 6, 5}.
- const uint8_t *src = edge + 1;
-
- const uint8x8x3_t filter = { { vdup_n_u8(5), vdup_n_u8(6), vdup_n_u8(5) } };
-
- while (sz >= 8) {
- uint8x8_t s0 = vld1_u8(src);
- uint8x8_t s1 = vld1_u8(src + 1);
- uint8x8_t s2 = vld1_u8(src + 2);
-
- uint16x8_t accum = vmull_u8(s0, filter.val[0]);
- accum = vmlal_u8(accum, s1, filter.val[1]);
- accum = vmlal_u8(accum, s2, filter.val[2]);
- uint8x8_t res = vrshrn_n_u16(accum, 4);
+ store_partial_u8x8(dst, res, rem);
+ return;
+ }
- vst1_u8(dst, res);
+ const uint8_t *const end_ptr = p + sz;
+ const uint8_t last = end_ptr[-1];
+ const uint8_t *src = p;
+ uint8x16_t in0;
+ if (sz < 16) {
+ in0 = vcombine_u8(vld1_u8(p), load_tail_u8x8(end_ptr, sz - 8));
+ } else {
+ in0 = vld1q_u8(src);
+ }
- src += 8;
- dst += 8;
- sz -= 8;
+ uint8x16_t tail_res;
+ if (strength == 1) {
+ while (rem >= 31) {
+ const uint8x16_t in1 = vld1q_u8(src + 16);
+ vst1q_u8(dst, filter_edge_s1_x16(in0, in1));
+ in0 = in1;
+ src += 16;
+ dst += 16;
+ rem -= 16;
}
-
- if (sz > 0) { // Handle sz < 8 to avoid modifying out-of-bounds values.
- uint8x8_t s0 = vld1_u8(src);
- uint8x8_t s1 = vld1_u8(src + 1);
- uint8x8_t s2 = vld1_u8(src + 2);
-
- uint16x8_t accum = vmull_u8(s0, filter.val[0]);
- accum = vmlal_u8(accum, s1, filter.val[1]);
- accum = vmlal_u8(accum, s2, filter.val[2]);
- uint8x8_t res = vrshrn_n_u16(accum, 4);
-
- // Mask off out-of-bounds indices.
- uint8x8_t current_dst = vld1_u8(dst);
- uint8x8_t mask = vcgt_u8(vdup_n_u8(sz), vcreate_u8(0x0706050403020100));
- res = vbsl_u8(mask, res, current_dst);
-
- vst1_u8(dst, res);
+ if (rem > 16) {
+ const uint8x16_t in1 = load_tail_u8x16(end_ptr, rem - 15);
+ vst1q_u8(dst, filter_edge_s1_x16(in0, in1));
+ in0 = in1;
+ dst += 16;
+ rem -= 16;
}
- } else { // Filter {2, 4, 4, 4, 2}.
- const uint8_t *src = edge;
-
- while (sz >= 8) {
- uint8x8_t s0 = vld1_u8(src);
- uint8x8_t s1 = vld1_u8(src + 1);
- uint8x8_t s2 = vld1_u8(src + 2);
- uint8x8_t s3 = vld1_u8(src + 3);
- uint8x8_t s4 = vld1_u8(src + 4);
-
- // Make use of the identity:
- // (2*a + 4*b + 4*c + 4*d + 2*e) >> 4 == (a + ((b + c + d) << 1) + e) >> 3
- uint16x8_t t0 = vaddl_u8(s0, s4);
- uint16x8_t t1 = vaddl_u8(s1, s2);
- t1 = vaddw_u8(t1, s3);
- t1 = vaddq_u16(t1, t1);
- uint16x8_t sum = vaddq_u16(t0, t1);
- uint8x8_t res = vrshrn_n_u16(sum, 3);
-
- vst1_u8(dst, res);
-
- src += 8;
- dst += 8;
- sz -= 8;
+ tail_res = filter_edge_s1_x16(in0, vdupq_n_u8(last));
+ } else if (strength == 2) {
+ const uint8x16_t f5q = vdupq_n_u8(5);
+ const uint8x16_t f6q = vdupq_n_u8(6);
+ while (rem >= 31) {
+ const uint8x16_t in1 = vld1q_u8(src + 16);
+ vst1q_u8(dst, filter_edge_s2_x16(in0, in1, f5q, f6q));
+ in0 = in1;
+ src += 16;
+ dst += 16;
+ rem -= 16;
}
-
- if (sz > 0) { // Handle sz < 8 to avoid modifying out-of-bounds values.
- uint8x8_t s0 = vld1_u8(src);
- uint8x8_t s1 = vld1_u8(src + 1);
- uint8x8_t s2 = vld1_u8(src + 2);
- uint8x8_t s3 = vld1_u8(src + 3);
- uint8x8_t s4 = vld1_u8(src + 4);
-
- uint16x8_t t0 = vaddl_u8(s0, s4);
- uint16x8_t t1 = vaddl_u8(s1, s2);
- t1 = vaddw_u8(t1, s3);
- t1 = vaddq_u16(t1, t1);
- uint16x8_t sum = vaddq_u16(t0, t1);
- uint8x8_t res = vrshrn_n_u16(sum, 3);
-
- // Mask off out-of-bounds indices.
- uint8x8_t current_dst = vld1_u8(dst);
- uint8x8_t mask = vcgt_u8(vdup_n_u8(sz), vcreate_u8(0x0706050403020100));
- res = vbsl_u8(mask, res, current_dst);
-
- vst1_u8(dst, res);
+ if (rem > 16) {
+ const uint8x16_t in1 = load_tail_u8x16(end_ptr, rem - 15);
+ vst1q_u8(dst, filter_edge_s2_x16(in0, in1, f5q, f6q));
+ in0 = in1;
+ dst += 16;
+ rem -= 16;
}
+ tail_res = filter_edge_s2_x16(in0, vdupq_n_u8(last), f5q, f6q);
+ } else {
+ uint8x16_t prev = vdupq_lane_u8(vget_low_u8(in0), 0);
+ while (rem >= 31) {
+ const uint8x16_t in1 = vld1q_u8(src + 16);
+ vst1q_u8(dst, filter_edge_s3_x16(prev, in0, in1));
+ prev = in0;
+ in0 = in1;
+ src += 16;
+ dst += 16;
+ rem -= 16;
+ }
+ if (rem > 16) {
+ const uint8x16_t in1 = load_tail_u8x16(end_ptr, rem - 15);
+ vst1q_u8(dst, filter_edge_s3_x16(prev, in0, in1));
+ prev = in0;
+ in0 = in1;
+ dst += 16;
+ rem -= 16;
+ }
+ tail_res = filter_edge_s3_x16(prev, in0, vdupq_n_u8(last));
}
+ store_partial_u8x16(dst, tail_res, rem);
+}
+
+static inline uint8x8_t upsample_edge_x8(uint8x8_t s0, uint8x8_t s1,
+ uint8x8_t s2, uint8x8_t s3) {
+ const int16x8_t t0 = vreinterpretq_s16_u16(vaddl_u8(s0, s3));
+ int16x8_t t1 = vreinterpretq_s16_u16(vaddl_u8(s1, s2));
+ t1 = vmulq_n_s16(t1, 9);
+ t1 = vsubq_s16(t1, t0);
+ return vqrshrun_n_s16(t1, 4);
}
void av1_upsample_intra_edge_neon(uint8_t *p, int sz) {
if (!sz) return;
- assert(sz <= MAX_UPSAMPLE_SZ);
-
- uint8_t edge[MAX_UPSAMPLE_SZ + 3];
- const uint8_t *src = edge;
-
- // Copy p[-1..(sz-1)] and pad out both ends.
- edge[0] = p[-1];
- edge[1] = p[-1];
- memcpy(edge + 2, p, sz);
- edge[sz + 2] = p[sz - 1];
- p[-2] = p[-1];
-
- uint8_t *dst = p - 1;
-
- do {
- uint8x8_t s0 = vld1_u8(src);
- uint8x8_t s1 = vld1_u8(src + 1);
- uint8x8_t s2 = vld1_u8(src + 2);
- uint8x8_t s3 = vld1_u8(src + 3);
-
- int16x8_t t0 = vreinterpretq_s16_u16(vaddl_u8(s0, s3));
- int16x8_t t1 = vreinterpretq_s16_u16(vaddl_u8(s1, s2));
- t1 = vmulq_n_s16(t1, 9);
- t1 = vsubq_s16(t1, t0);
-
- uint8x8x2_t res = { { vqrshrun_n_s16(t1, 4), s2 } };
+ assert(sz == 4 || sz == 8 || sz == 12 || sz == 16);
+
+ const uint8_t pm1_val = p[-1];
+ p[-2] = pm1_val;
+
+ if (sz == 4) {
+ const uint8x8_t p03 = load_unaligned_dup_u8_4x2(p);
+ const uint8x8_t tail = vdup_lane_u8(p03, 3);
+ const uint8x8_t s2 = vreinterpret_u8_u64(
+ vsli_n_u64(vreinterpret_u64_u8(p03), vreinterpret_u64_u8(tail), 32));
+ const uint8x8_t pm1 = vdup_n_u8(pm1_val);
+ const uint8x8_t s0 = vext_u8(pm1, s2, 6);
+ const uint8x8_t s1 = vext_u8(pm1, s2, 7);
+ const uint8x8_t s3 = vext_u8(s2, s2, 1);
+ const uint8x8_t interp = upsample_edge_x8(s0, s1, s2, s3);
+ const uint8x8x2_t zipped = vzip_u8(interp, s2);
+ vst1_u8(p - 1, zipped.val[0]);
+ return;
+ }
- vst2_u8(dst, res);
+ if (sz == 8) {
+ const uint8x8_t s2 = vld1_u8(p);
+ const uint8x8_t pm1 = vdup_n_u8(pm1_val);
+ const uint8x8_t tail = vdup_lane_u8(s2, 7);
+ const uint8x8_t s0 = vext_u8(pm1, s2, 6);
+ const uint8x8_t s1 = vext_u8(pm1, s2, 7);
+ const uint8x8_t s3 = vext_u8(s2, tail, 1);
+ const uint8x8x2_t res = { { upsample_edge_x8(s0, s1, s2, s3), s2 } };
+ vst2_u8(p - 1, res);
+ return;
+ }
- src += 8;
- dst += 16;
- sz -= 8;
- } while (sz > 0);
+ assert(sz == 12 || sz == 16);
+ uint8x16_t s2_q;
+ if (sz == 16) {
+ s2_q = vld1q_u8(p);
+ } else {
+ const uint8x8_t lo = vld1_u8(p);
+ const uint8x8_t p8_11 = load_unaligned_dup_u8_4x2(p + 8);
+ const uint8x8_t tail8 = vdup_lane_u8(p8_11, 3);
+ const uint8x8_t hi = vreinterpret_u8_u64(
+ vsli_n_u64(vreinterpret_u64_u8(p8_11), vreinterpret_u64_u8(tail8), 32));
+ s2_q = vcombine_u8(lo, hi);
+ }
+ const uint8x16_t tail_q = vdupq_lane_u8(vget_high_u8(s2_q), 7);
+ const uint8x16_t pm1_q = vdupq_n_u8(pm1_val);
+ const uint8x16_t s0_q = vextq_u8(pm1_q, s2_q, 14);
+ const uint8x16_t s1_q = vextq_u8(pm1_q, s2_q, 15);
+ const uint8x16_t s3_q = vextq_u8(s2_q, tail_q, 1);
+
+ const uint8x8_t res_lo =
+ upsample_edge_x8(vget_low_u8(s0_q), vget_low_u8(s1_q), vget_low_u8(s2_q),
+ vget_low_u8(s3_q));
+
+#if AOM_ARCH_AARCH64
+ const int16x8_t t0_hi = vreinterpretq_s16_u16(vaddl_high_u8(s0_q, s3_q));
+ int16x8_t t1_hi = vreinterpretq_s16_u16(vaddl_high_u8(s1_q, s2_q));
+ t1_hi = vmulq_n_s16(t1_hi, 9);
+ t1_hi = vsubq_s16(t1_hi, t0_hi);
+ const uint8x8_t res_hi = vqrshrun_n_s16(t1_hi, 4);
+#else
+ const uint8x8_t res_hi =
+ upsample_edge_x8(vget_high_u8(s0_q), vget_high_u8(s1_q),
+ vget_high_u8(s2_q), vget_high_u8(s3_q));
+#endif
+
+ if (sz == 16) {
+ const uint8x16x2_t res = { { vcombine_u8(res_lo, res_hi), s2_q } };
+ vst2q_u8(p - 1, res);
+ } else {
+ const uint8x8x2_t res_lo2 = { { res_lo, vget_low_u8(s2_q) } };
+ vst2_u8(p - 1, res_lo2);
+ const uint8x8x2_t zipped_hi = vzip_u8(res_hi, vget_high_u8(s2_q));
+ vst1_u8(p + 15, zipped_hi.val[0]);
+ }
}
diff --git a/av1/common/arm/reconintra_neon_i8mm.c b/av1/common/arm/reconintra_neon_i8mm.c
index 21b7170f3b..20aa2ec245 100644
--- a/av1/common/arm/reconintra_neon_i8mm.c
+++ b/av1/common/arm/reconintra_neon_i8mm.c
@@ -11,6 +11,7 @@
#include <arm_neon.h>
#include <assert.h>
+#include <string.h>
#include "config/aom_config.h"
#include "config/av1_rtcd.h"
@@ -19,164 +20,360 @@
#define FILTER_INTRA_SCALE_BITS 4
-// The input arrays are reordered compared to the C implementation: the first
-// four vectors contain the lower elements of the original filter, the next four
-// vectors contain the upper elements. This layout allows all 8 multiplications
-// to accumulate into a single element using USDOT instructions, instead of
-// having two partial sums in adjacent vector elements and needing to combine
-// them with an additional pairwise add.
+// Taps split into contiguous top-4 [t1, t2, t3, t4] (rows 0..3 and 4..7) and
+// left-3 [t0, t5, t6, 0] (rows 0..3 and 4..7) so top pixels from the previous
+// row pair require zero permutation and accumulate in parallel with left-col
+// dependencies via SUDOT.
DECLARE_ALIGNED(16, static const int8_t,
- av1_filter_intra_taps_neon_i8mm[FILTER_INTRA_MODES][8][8]) = {
+ av1_filter_intra_taps_neon_i8mm[FILTER_INTRA_MODES][4][16]) = {
{
- { -6, 10, 0, 0, -5, 2, 10, 0 },
- { -3, 1, 1, 10, -3, 1, 1, 2 },
- { -4, 6, 0, 0, -3, 2, 6, 0 },
- { -3, 2, 2, 6, -3, 1, 2, 2 },
- { 0, 12, 0, 0, 0, 9, 0, 0 },
- { 0, 7, 0, 0, 10, 5, 0, 0 },
- { 0, 2, 12, 0, 0, 2, 9, 0 },
- { 0, 2, 7, 0, 6, 3, 5, 0 },
+ { 10, 0, 0, 0, 2, 10, 0, 0, 1, 1, 10, 0, 1, 1, 2, 10 },
+ { 6, 0, 0, 0, 2, 6, 0, 0, 2, 2, 6, 0, 1, 2, 2, 6 },
+ { -6, 12, 0, 0, -5, 9, 0, 0, -3, 7, 0, 0, -3, 5, 0, 0 },
+ { -4, 2, 12, 0, -3, 2, 9, 0, -3, 2, 7, 0, -3, 3, 5, 0 },
},
{
- { -10, 16, 0, 0, -6, 0, 16, 0 },
- { -4, 0, 0, 16, -2, 0, 0, 0 },
- { -10, 16, 0, 0, -6, 0, 16, 0 },
- { -4, 0, 0, 16, -2, 0, 0, 0 },
- { 0, 10, 0, 0, 0, 6, 0, 0 },
- { 0, 4, 0, 0, 16, 2, 0, 0 },
- { 0, 0, 10, 0, 0, 0, 6, 0 },
- { 0, 0, 4, 0, 16, 0, 2, 0 },
+ { 16, 0, 0, 0, 0, 16, 0, 0, 0, 0, 16, 0, 0, 0, 0, 16 },
+ { 16, 0, 0, 0, 0, 16, 0, 0, 0, 0, 16, 0, 0, 0, 0, 16 },
+ { -10, 10, 0, 0, -6, 6, 0, 0, -4, 4, 0, 0, -2, 2, 0, 0 },
+ { -10, 0, 10, 0, -6, 0, 6, 0, -4, 0, 4, 0, -2, 0, 2, 0 },
},
{
- { -8, 8, 0, 0, -8, 0, 8, 0 },
- { -8, 0, 0, 8, -8, 0, 0, 0 },
- { -4, 4, 0, 0, -4, 0, 4, 0 },
- { -4, 0, 0, 4, -4, 0, 0, 0 },
- { 0, 16, 0, 0, 0, 16, 0, 0 },
- { 0, 16, 0, 0, 8, 16, 0, 0 },
- { 0, 0, 16, 0, 0, 0, 16, 0 },
- { 0, 0, 16, 0, 4, 0, 16, 0 },
+ { 8, 0, 0, 0, 0, 8, 0, 0, 0, 0, 8, 0, 0, 0, 0, 8 },
+ { 4, 0, 0, 0, 0, 4, 0, 0, 0, 0, 4, 0, 0, 0, 0, 4 },
+ { -8, 16, 0, 0, -8, 16, 0, 0, -8, 16, 0, 0, -8, 16, 0, 0 },
+ { -4, 0, 16, 0, -4, 0, 16, 0, -4, 0, 16, 0, -4, 0, 16, 0 },
},
{
- { -2, 8, 0, 0, -1, 3, 8, 0 },
- { -1, 2, 3, 8, 0, 1, 2, 3 },
- { -1, 4, 0, 0, -1, 3, 4, 0 },
- { -1, 2, 3, 4, -1, 2, 2, 3 },
- { 0, 10, 0, 0, 0, 6, 0, 0 },
- { 0, 4, 0, 0, 8, 2, 0, 0 },
- { 0, 3, 10, 0, 0, 4, 6, 0 },
- { 0, 4, 4, 0, 4, 3, 3, 0 },
+ { 8, 0, 0, 0, 3, 8, 0, 0, 2, 3, 8, 0, 1, 2, 3, 8 },
+ { 4, 0, 0, 0, 3, 4, 0, 0, 2, 3, 4, 0, 2, 2, 3, 4 },
+ { -2, 10, 0, 0, -1, 6, 0, 0, -1, 4, 0, 0, 0, 2, 0, 0 },
+ { -1, 3, 10, 0, -1, 4, 6, 0, -1, 4, 4, 0, -1, 3, 3, 0 },
},
{
- { -12, 14, 0, 0, -10, 0, 14, 0 },
- { -9, 0, 0, 14, -8, 0, 0, 0 },
- { -10, 12, 0, 0, -9, 1, 12, 0 },
- { -8, 0, 0, 12, -7, 0, 0, 1 },
- { 0, 14, 0, 0, 0, 12, 0, 0 },
- { 0, 11, 0, 0, 14, 10, 0, 0 },
- { 0, 0, 14, 0, 0, 0, 12, 0 },
- { 0, 1, 11, 0, 12, 1, 9, 0 },
+ { 14, 0, 0, 0, 0, 14, 0, 0, 0, 0, 14, 0, 0, 0, 0, 14 },
+ { 12, 0, 0, 0, 1, 12, 0, 0, 0, 0, 12, 0, 0, 0, 1, 12 },
+ { -12, 14, 0, 0, -10, 12, 0, 0, -9, 11, 0, 0, -8, 10, 0, 0 },
+ { -10, 0, 14, 0, -9, 0, 12, 0, -8, 1, 11, 0, -7, 1, 9, 0 },
},
};
-static inline uint8x8_t filter_intra_predictor(uint8x16_t p_lo, uint8x16_t p_hi,
- const int8x16_t f01,
- const int8x16_t f23,
- const int8x16_t f45,
- const int8x16_t f67) {
- int32x4_t acc_0123 = vusdotq_s32(vdupq_n_s32(0), p_lo, f01);
- acc_0123 = vusdotq_s32(acc_0123, p_hi, f23);
+// Filter sums lie in [-3060, 7140], fitting in signed 16-bit lanes without
+// saturation before vqrshrun_n_s16.
+static inline uint8x8_t filter_intra_finish(int32x4_t acc0, int32x4_t acc1) {
+ const int16x8_t acc =
+ vuzp1q_s16(vreinterpretq_s16_s32(acc0), vreinterpretq_s16_s32(acc1));
+ return vqrshrun_n_s16(acc, FILTER_INTRA_SCALE_BITS);
+}
- int32x4_t acc_4567 = vusdotq_s32(vdupq_n_s32(0), p_lo, f45);
- acc_4567 = vusdotq_s32(acc_4567, p_hi, f67);
+static inline uint8x8_t filter_intra_left_first_lane0(
+ uint8x8_t p_left, uint8x8_t p_top, int8x16_t ft0, int8x16_t ft1,
+ int8x16_t fl0, int8x16_t fl1) {
+ int32x4_t acc0 = vsudotq_lane_s32(vdupq_n_s32(0), fl0, p_left, 0);
+ int32x4_t acc1 = vsudotq_lane_s32(vdupq_n_s32(0), fl1, p_left, 0);
+ acc0 = vsudotq_lane_s32(acc0, ft0, p_top, 0);
+ acc1 = vsudotq_lane_s32(acc1, ft1, p_top, 0);
+ return filter_intra_finish(acc0, acc1);
+}
- const int16x8_t acc = vcombine_s16(vmovn_s32(acc_0123), vmovn_s32(acc_4567));
+static inline uint8x8_t filter_intra_left_first_lane1(
+ uint8x8_t p_left, uint8x8_t p_top, int8x16_t ft0, int8x16_t ft1,
+ int8x16_t fl0, int8x16_t fl1) {
+ int32x4_t acc0 = vsudotq_lane_s32(vdupq_n_s32(0), fl0, p_left, 0);
+ int32x4_t acc1 = vsudotq_lane_s32(vdupq_n_s32(0), fl1, p_left, 0);
+ acc0 = vsudotq_lane_s32(acc0, ft0, p_top, 1);
+ acc1 = vsudotq_lane_s32(acc1, ft1, p_top, 1);
+ return filter_intra_finish(acc0, acc1);
+}
- return vqrshrun_n_s16(acc, FILTER_INTRA_SCALE_BITS);
+static inline uint8x8_t filter_intra_top_first_lane0(
+ uint8x8_t p_top, uint8x8_t p_left, int8x16_t ft0, int8x16_t ft1,
+ int8x16_t fl0, int8x16_t fl1) {
+ int32x4_t acc0 = vsudotq_lane_s32(vdupq_n_s32(0), ft0, p_top, 0);
+ int32x4_t acc1 = vsudotq_lane_s32(vdupq_n_s32(0), ft1, p_top, 0);
+ acc0 = vsudotq_lane_s32(acc0, fl0, p_left, 0);
+ acc1 = vsudotq_lane_s32(acc1, fl1, p_left, 0);
+ return filter_intra_finish(acc0, acc1);
+}
+
+static inline uint8x8_t filter_intra_top_first_lane1(
+ uint8x8_t p_top, uint8x8_t p_left, int8x16_t ft0, int8x16_t ft1,
+ int8x16_t fl0, int8x16_t fl1) {
+ int32x4_t acc0 = vsudotq_lane_s32(vdupq_n_s32(0), ft0, p_top, 1);
+ int32x4_t acc1 = vsudotq_lane_s32(vdupq_n_s32(0), ft1, p_top, 1);
+ acc0 = vsudotq_lane_s32(acc0, fl0, p_left, 0);
+ acc1 = vsudotq_lane_s32(acc1, fl1, p_left, 0);
+ return filter_intra_finish(acc0, acc1);
+}
+
+static inline uint8x8_t gather_p_left(uint8x8_t cur_left, uint8x8_t prev_top,
+ uint8x16_t tbl_idx) {
+ return vget_low_u8(vqtbl1q_u8(vcombine_u8(prev_top, cur_left), tbl_idx));
}
void av1_filter_intra_predictor_neon_i8mm(uint8_t *dst, ptrdiff_t stride,
TX_SIZE tx_size, const uint8_t *above,
const uint8_t *left, int mode) {
+ assert(tx_size < TX_SIZES_ALL);
+ assert(mode >= 0 && mode < FILTER_INTRA_MODES);
const int bw = tx_size_wide[tx_size];
const int bh = tx_size_high[tx_size];
- if (bw == 4 || (bw == 8 && bh < 16) || (bw == 16 && bh <= 4) || bw == 32) {
- av1_filter_intra_predictor_neon(dst, stride, tx_size, above, left, mode);
+ assert(bw >= 4 && bw <= 32 && bh >= 4 && bh <= 32);
+ assert((bw & 3) == 0 && (bh & 1) == 0);
+
+ const int8x16_t ft0 = vld1q_s8(av1_filter_intra_taps_neon_i8mm[mode][0]);
+ const int8x16_t ft1 = vld1q_s8(av1_filter_intra_taps_neon_i8mm[mode][1]);
+ const int8x16_t fl0 = vld1q_s8(av1_filter_intra_taps_neon_i8mm[mode][2]);
+ const int8x16_t fl1 = vld1q_s8(av1_filter_intra_taps_neon_i8mm[mode][3]);
+
+ if (bw == 4) {
+ uint16_t l12;
+ memcpy(&l12, left, 2);
+ uint32_t l012 = (uint32_t)above[-1] | ((uint32_t)l12 << 8);
+ uint8_t l_prev = (uint8_t)(l12 >> 8);
+ uint8x8_t prev = filter_intra_left_first_lane0(
+ vreinterpret_u8_u32(vdup_n_u32(l012)), load_unaligned_dup_u8_4x2(above),
+ ft0, ft1, fl0, fl1);
+ store_u8x4_strided_x2(dst, stride, prev);
+ left += 2;
+ dst += 2 * stride;
+ int h = bh - 2;
+ do {
+ memcpy(&l12, left, 2);
+ l012 = (uint32_t)l_prev | ((uint32_t)l12 << 8);
+ l_prev = (uint8_t)(l12 >> 8);
+ prev = filter_intra_left_first_lane1(
+ vreinterpret_u8_u32(vdup_n_u32(l012)), prev, ft0, ft1, fl0, fl1);
+ store_u8x4_strided_x2(dst, stride, prev);
+ left += 2;
+ dst += 2 * stride;
+ h -= 2;
+ } while (h != 0);
return;
}
- assert(bw <= 32 && bh <= 32);
+ // Gather [p0=prev_top[3] (lane 3), p5=cur_left[3] (11), p6=cur_left[7] (15),
+ // 0] or [p0=prev_top[7] (lane 7), p5=cur_left[3] (11), p6=cur_left[7] (15),
+ // 0] for the next 4x2 sub-block in row pairs.
+ const uint8x16_t idx_tl_lane3 = vreinterpretq_u8_u32(vdupq_n_u32(0xFF0F0B03));
+ const uint8x16_t idx_tl_lane7 = vreinterpretq_u8_u32(vdupq_n_u32(0xFF0F0B07));
+
+ if (bw == 8) {
+ const uint8x8_t abv = vld1_u8(above);
+ uint16_t l12;
+ memcpy(&l12, left, 2);
+ uint32_t l012 = (uint32_t)above[-1] | ((uint32_t)l12 << 8);
+ uint8_t l_prev = (uint8_t)(l12 >> 8);
+
+ uint8x8_t prev0, prev1;
+ {
+ int32x4_t acc1_0 = vsudotq_lane_s32(vdupq_n_s32(0), ft0, abv, 1);
+ int32x4_t acc1_1 = vsudotq_lane_s32(vdupq_n_s32(0), ft1, abv, 1);
- const int8x16_t f01 = vld1q_s8(av1_filter_intra_taps_neon_i8mm[mode][0]);
- const int8x16_t f45 = vld1q_s8(av1_filter_intra_taps_neon_i8mm[mode][2]);
- const int8x16_t f23 = vld1q_s8(av1_filter_intra_taps_neon_i8mm[mode][4]);
- const int8x16_t f67 = vld1q_s8(av1_filter_intra_taps_neon_i8mm[mode][6]);
+ prev0 = filter_intra_left_first_lane0(
+ vreinterpret_u8_u32(vdup_n_u32(l012)), abv, ft0, ft1, fl0, fl1);
- // indexes : 0, 19, 23, -1
- uint8x16_t p_hi_idx = vreinterpretq_u8_u32(vdupq_n_u32(0xFF171300));
+ const uint8x8_t p_left1 = gather_p_left(prev0, abv, idx_tl_lane3);
+ acc1_0 = vsudotq_lane_s32(acc1_0, fl0, p_left1, 0);
+ acc1_1 = vsudotq_lane_s32(acc1_1, fl1, p_left1, 0);
+ prev1 = filter_intra_finish(acc1_0, acc1_1);
- uint64_t l01 = ((uint64_t)left[0] << 24) | ((uint64_t)left[1] << 56);
- uint8x16_t l = vreinterpretq_u8_u64(vdupq_n_u64(l01));
+ const uint32x2x2_t res_zip =
+ vzip_u32(vreinterpret_u32_u8(prev0), vreinterpret_u32_u8(prev1));
+ vst1_u8(dst, vreinterpret_u8_u32(res_zip.val[0]));
+ vst1_u8(dst + stride, vreinterpret_u8_u32(res_zip.val[1]));
+ }
+
+ left += 2;
+ dst += 2 * stride;
+ int h = bh - 2;
+ do {
+ memcpy(&l12, left, 2);
+ l012 = (uint32_t)l_prev | ((uint32_t)l12 << 8);
+ l_prev = (uint8_t)(l12 >> 8);
+
+ int32x4_t acc1_0 = vsudotq_lane_s32(vdupq_n_s32(0), ft0, prev1, 1);
+ int32x4_t acc1_1 = vsudotq_lane_s32(vdupq_n_s32(0), ft1, prev1, 1);
+
+ const uint8x8_t next0 = filter_intra_left_first_lane1(
+ vreinterpret_u8_u32(vdup_n_u32(l012)), prev0, ft0, ft1, fl0, fl1);
+
+ const uint8x8_t p_left1 = gather_p_left(next0, prev0, idx_tl_lane7);
+ acc1_0 = vsudotq_lane_s32(acc1_0, fl0, p_left1, 0);
+ acc1_1 = vsudotq_lane_s32(acc1_1, fl1, p_left1, 0);
+ const uint8x8_t next1 = filter_intra_finish(acc1_0, acc1_1);
+
+ const uint32x2x2_t res_zip =
+ vzip_u32(vreinterpret_u32_u8(next0), vreinterpret_u32_u8(next1));
+ vst1_u8(dst, vreinterpret_u8_u32(res_zip.val[0]));
+ vst1_u8(dst + stride, vreinterpret_u8_u32(res_zip.val[1]));
+ prev0 = next0;
+ prev1 = next1;
+ left += 2;
+ dst += 2 * stride;
+ h -= 2;
+ } while (h != 0);
+ return;
+ }
- int c = 0;
- do {
- const uint8_t *ptr = above + c - 1;
- uint32_t lo =
- ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | ((uint32_t)ptr[3] << 24);
- uint8x16_t p_lo = vreinterpretq_u8_u32(vdupq_n_u32(lo));
+ if (bw == 16) {
+ const uint8x8_t abv_lo = vld1_u8(above);
+ const uint8x8_t abv_hi = vld1_u8(above + 8);
+ uint16_t l12;
+ memcpy(&l12, left, 2);
+ uint32_t l012 = (uint32_t)above[-1] | ((uint32_t)l12 << 8);
+ uint8_t l_prev = (uint8_t)(l12 >> 8);
- uint8x16x2_t hi;
- hi.val[0] = vdupq_n_u8(ptr[4]);
- hi.val[1] = l;
- uint8x16_t p_hi = vqtbl2q_u8(hi, p_hi_idx);
+ uint8x8_t prev0, prev1, prev2, prev3;
+ {
+ int32x4_t a1_0 = vsudotq_lane_s32(vdupq_n_s32(0), ft0, abv_lo, 1);
+ int32x4_t a1_1 = vsudotq_lane_s32(vdupq_n_s32(0), ft1, abv_lo, 1);
+ int32x4_t a2_0 = vsudotq_lane_s32(vdupq_n_s32(0), ft0, abv_hi, 0);
+ int32x4_t a2_1 = vsudotq_lane_s32(vdupq_n_s32(0), ft1, abv_hi, 0);
+ int32x4_t a3_0 = vsudotq_lane_s32(vdupq_n_s32(0), ft0, abv_hi, 1);
+ int32x4_t a3_1 = vsudotq_lane_s32(vdupq_n_s32(0), ft1, abv_hi, 1);
- const uint8x8_t res =
- filter_intra_predictor(p_lo, p_hi, f01, f23, f45, f67);
+ prev0 = filter_intra_left_first_lane0(
+ vreinterpret_u8_u32(vdup_n_u32(l012)), abv_lo, ft0, ft1, fl0, fl1);
- store_u8x4_strided_x2(dst + c, stride, res);
+ const uint8x8_t pl1 = gather_p_left(prev0, abv_lo, idx_tl_lane3);
+ a1_0 = vsudotq_lane_s32(a1_0, fl0, pl1, 0);
+ a1_1 = vsudotq_lane_s32(a1_1, fl1, pl1, 0);
+ prev1 = filter_intra_finish(a1_0, a1_1);
- l = vcombine_u8(res, res);
+ const uint8x8_t pl2 = gather_p_left(prev1, abv_lo, idx_tl_lane7);
+ a2_0 = vsudotq_lane_s32(a2_0, fl0, pl2, 0);
+ a2_1 = vsudotq_lane_s32(a2_1, fl1, pl2, 0);
+ prev2 = filter_intra_finish(a2_0, a2_1);
- c += 4;
- } while (c < bw);
+ const uint8x8_t pl3 = gather_p_left(prev2, abv_hi, idx_tl_lane3);
+ a3_0 = vsudotq_lane_s32(a3_0, fl0, pl3, 0);
+ a3_1 = vsudotq_lane_s32(a3_1, fl1, pl3, 0);
+ prev3 = filter_intra_finish(a3_0, a3_1);
- dst += 2 * stride;
- int r = 2;
- while (r < bh) {
- const uint8_t *ptr = dst - stride;
- uint32_t lo =
- left[r - 1] | (ptr[0] << 8) | (ptr[1] << 16) | ((uint32_t)ptr[2] << 24);
- uint32_t hi = ptr[3] | (left[r] << 8) | (left[r + 1] << 16);
- uint8x16_t p_lo = vreinterpretq_u8_u32(vdupq_n_u32(lo));
- uint8x16_t p_hi = vreinterpretq_u8_u32(vdupq_n_u32(hi));
+ const uint32x2x2_t z01 =
+ vzip_u32(vreinterpret_u32_u8(prev0), vreinterpret_u32_u8(prev1));
+ const uint32x2x2_t z23 =
+ vzip_u32(vreinterpret_u32_u8(prev2), vreinterpret_u32_u8(prev3));
+ vst1q_u8(dst, vcombine_u8(vreinterpret_u8_u32(z01.val[0]),
+ vreinterpret_u8_u32(z23.val[0])));
+ vst1q_u8(dst + stride, vcombine_u8(vreinterpret_u8_u32(z01.val[1]),
+ vreinterpret_u8_u32(z23.val[1])));
+ }
- uint8x8_t res = filter_intra_predictor(p_lo, p_hi, f01, f23, f45, f67);
+ left += 2;
+ dst += 2 * stride;
+ int h = bh - 2;
+ do {
+ memcpy(&l12, left, 2);
+ l012 = (uint32_t)l_prev | ((uint32_t)l12 << 8);
+ l_prev = (uint8_t)(l12 >> 8);
- store_u8x4_strided_x2(dst, stride, res);
+ int32x4_t a1_0 = vsudotq_lane_s32(vdupq_n_s32(0), ft0, prev1, 1);
+ int32x4_t a1_1 = vsudotq_lane_s32(vdupq_n_s32(0), ft1, prev1, 1);
+ int32x4_t a2_0 = vsudotq_lane_s32(vdupq_n_s32(0), ft0, prev2, 1);
+ int32x4_t a2_1 = vsudotq_lane_s32(vdupq_n_s32(0), ft1, prev2, 1);
+ int32x4_t a3_0 = vsudotq_lane_s32(vdupq_n_s32(0), ft0, prev3, 1);
+ int32x4_t a3_1 = vsudotq_lane_s32(vdupq_n_s32(0), ft1, prev3, 1);
- l = vcombine_u8(res, res);
+ const uint8x8_t next0 = filter_intra_left_first_lane1(
+ vreinterpret_u8_u32(vdup_n_u32(l012)), prev0, ft0, ft1, fl0, fl1);
- c = 4;
- while (c < bw) {
- ptr = dst - stride + c - 1;
- lo = ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | ((uint32_t)ptr[3] << 24);
- p_lo = vreinterpretq_u8_u32(vdupq_n_u32(lo));
+ const uint8x8_t pl1 = gather_p_left(next0, prev0, idx_tl_lane7);
+ a1_0 = vsudotq_lane_s32(a1_0, fl0, pl1, 0);
+ a1_1 = vsudotq_lane_s32(a1_1, fl1, pl1, 0);
+ const uint8x8_t next1 = filter_intra_finish(a1_0, a1_1);
- uint8x16x2_t hi_v;
- hi_v.val[0] = vdupq_n_u8(ptr[4]);
- hi_v.val[1] = l;
- p_hi = vqtbl2q_u8(hi_v, p_hi_idx);
+ const uint8x8_t pl2 = gather_p_left(next1, prev1, idx_tl_lane7);
+ a2_0 = vsudotq_lane_s32(a2_0, fl0, pl2, 0);
+ a2_1 = vsudotq_lane_s32(a2_1, fl1, pl2, 0);
+ const uint8x8_t next2 = filter_intra_finish(a2_0, a2_1);
- res = filter_intra_predictor(p_lo, p_hi, f01, f23, f45, f67);
+ const uint8x8_t pl3 = gather_p_left(next2, prev2, idx_tl_lane7);
+ a3_0 = vsudotq_lane_s32(a3_0, fl0, pl3, 0);
+ a3_1 = vsudotq_lane_s32(a3_1, fl1, pl3, 0);
+ const uint8x8_t next3 = filter_intra_finish(a3_0, a3_1);
- store_u8x4_strided_x2(dst + c, stride, res);
+ const uint32x2x2_t z01 =
+ vzip_u32(vreinterpret_u32_u8(next0), vreinterpret_u32_u8(next1));
+ const uint32x2x2_t z23 =
+ vzip_u32(vreinterpret_u32_u8(next2), vreinterpret_u32_u8(next3));
+ vst1q_u8(dst, vcombine_u8(vreinterpret_u8_u32(z01.val[0]),
+ vreinterpret_u8_u32(z23.val[0])));
+ vst1q_u8(dst + stride, vcombine_u8(vreinterpret_u8_u32(z01.val[1]),
+ vreinterpret_u8_u32(z23.val[1])));
+ prev0 = next0;
+ prev1 = next1;
+ prev2 = next2;
+ prev3 = next3;
+ left += 2;
+ dst += 2 * stride;
+ h -= 2;
+ } while (h != 0);
+ return;
+ }
- l = vcombine_u8(res, res);
- c += 4;
+ assert(bw == 32);
+ {
+ uint16_t l12;
+ memcpy(&l12, left, 2);
+ uint32_t l012 = (uint32_t)above[-1] | ((uint32_t)l12 << 8);
+ uint8_t l_prev = (uint8_t)(l12 >> 8);
+ {
+ uint8x8_t abv8 = vld1_u8(above);
+ uint8x8_t res = filter_intra_left_first_lane0(
+ vreinterpret_u8_u32(vdup_n_u32(l012)), abv8, ft0, ft1, fl0, fl1);
+ store_u8x4_strided_x2(dst, stride, res);
+ res = filter_intra_top_first_lane1(
+ abv8, gather_p_left(res, abv8, idx_tl_lane3), ft0, ft1, fl0, fl1);
+ store_u8x4_strided_x2(dst + 4, stride, res);
+ int c = 8;
+ do {
+ const uint8x8_t prev_abv8 = abv8;
+ abv8 = vld1_u8(above + c);
+ res = filter_intra_top_first_lane0(
+ abv8, gather_p_left(res, prev_abv8, idx_tl_lane7), ft0, ft1, fl0,
+ fl1);
+ store_u8x4_strided_x2(dst + c, stride, res);
+ res = filter_intra_top_first_lane1(
+ abv8, gather_p_left(res, abv8, idx_tl_lane3), ft0, ft1, fl0, fl1);
+ store_u8x4_strided_x2(dst + c + 4, stride, res);
+ c += 8;
+ } while (c != 32);
}
- r += 2;
+ left += 2;
dst += 2 * stride;
+ int h = bh - 2;
+ do {
+ const uint8_t *ptr = dst - stride;
+ memcpy(&l12, left, 2);
+ l012 = (uint32_t)l_prev | ((uint32_t)l12 << 8);
+ l_prev = (uint8_t)(l12 >> 8);
+ uint8x8_t abv8 = vld1_u8(ptr);
+ uint8x8_t res = filter_intra_left_first_lane0(
+ vreinterpret_u8_u32(vdup_n_u32(l012)), abv8, ft0, ft1, fl0, fl1);
+ store_u8x4_strided_x2(dst, stride, res);
+ res = filter_intra_top_first_lane1(
+ abv8, gather_p_left(res, abv8, idx_tl_lane3), ft0, ft1, fl0, fl1);
+ store_u8x4_strided_x2(dst + 4, stride, res);
+ int c = 8;
+ do {
+ const uint8x8_t prev_abv8 = abv8;
+ abv8 = vld1_u8(ptr + c);
+ res = filter_intra_top_first_lane0(
+ abv8, gather_p_left(res, prev_abv8, idx_tl_lane7), ft0, ft1, fl0,
+ fl1);
+ store_u8x4_strided_x2(dst + c, stride, res);
+ res = filter_intra_top_first_lane1(
+ abv8, gather_p_left(res, abv8, idx_tl_lane3), ft0, ft1, fl0, fl1);
+ store_u8x4_strided_x2(dst + c + 4, stride, res);
+ c += 8;
+ } while (c != 32);
+ left += 2;
+ dst += 2 * stride;
+ h -= 2;
+ } while (h != 0);
}
}
diff --git a/test/intra_edge_test.cc b/test/intra_edge_test.cc
index 9b992d2d64..6b715828b1 100644
--- a/test/intra_edge_test.cc
+++ b/test/intra_edge_test.cc
@@ -33,7 +33,7 @@ class UpsampleTest : public FunctionEquivalenceTest<F> {
protected:
static const int kIterations = 1000000;
static const int kMinEdge = 4;
- static const int kMaxEdge = 24;
+ static const int kMaxEdge = 16;
static const int kBufSize = 2 * 64 + 32;
static const int kOffset = 16;
@@ -181,6 +181,33 @@ TEST_P(FilterEdgeTest8B, RandomValues) {
}
}
+TEST_P(FilterEdgeTest8B, AllSizes) {
+ for (int sz = 1; sz <= kMaxEdge + 1; ++sz) {
+ size_ = sz;
+ for (int strength = 0; strength <= 3; ++strength) {
+ strength_ = strength;
+ for (int iter = 0; iter < 8 && !HasFatalFailure(); ++iter) {
+ for (int i = 0; i < kBufSize; ++i) {
+ const uint8_t pix = rng_.Rand8();
+ edge_ref_data_[i] = pix;
+ edge_tst_data_[i] = pix;
+ }
+ Common();
+#if HAVE_NEON
+ if (params_.tst_func == av1_filter_intra_edge_neon) {
+ for (int i = 0; i < kOffset; ++i) {
+ ASSERT_EQ(edge_ref_data_[i], edge_tst_data_[i]);
+ }
+ for (int i = size_; i < kBufSize - kOffset; ++i) {
+ ASSERT_EQ(edge_ref_[i], edge_tst_[i]);
+ }
+ }
+#endif // HAVE_NEON
+ }
+ }
+ }
+}
+
TEST_P(FilterEdgeTest8B, DISABLED_Speed) {
const int test_count = 10000000;
size_ = kMaxEdge;