Commit 78e26c6d00 for aom

commit 78e26c6d00d54b02c58a92d9cb7c360bf77ef86b
Author: Frank Galligan <fgalligan@google.com>
Date:   Tue Nov 17 06:28:45 2026 -0800

    av1,neon: Fuse subtract+hadamard+satd in intra RD

    Add fused 8-bit av1_hadamard_satd_{4x4,8x8,16x16,32x32}_sub RTCD
    entry points with NEON implementations (plus pure scalar C references
    and GTest coverage in test/hadamard_test.cc). Inline single-block
    lowbd dispatch in intra_model_rd, outline the multi-block and border
    fallback in intra_mode_search_utils.c, and leave non-NEON targets
    unchanged.

    Speedup (Pixel 9 Tensor G4 Cortex-A720, 1T, bit-exact):
    - realtime 768x1024 intra: -1.16% (speed 6), -0.92% (speed 7).
    - allintra speed 6: -1.73%; good speed 6: -1.78%.
    - Non-NEON targets: 0.00% change (inline intra_model_rd preserved).

    TAG=agy
    CONV=b929a630-a6cd-45a0-979c-1767c30178ee
    Change-Id: I86045e4c1535dc4d78847d009cface06dcb364fa

diff --git a/av1/av1.cmake b/av1/av1.cmake
index 6799d42ec6..732fd2d564 100644
--- a/av1/av1.cmake
+++ b/av1/av1.cmake
@@ -252,6 +252,7 @@ list(APPEND AOM_AV1_ENCODER_SOURCES
             "${AOM_ROOT}/av1/encoder/txb_rdopt_utils.h"
             "${AOM_ROOT}/av1/encoder/intra_mode_search.c"
             "${AOM_ROOT}/av1/encoder/intra_mode_search.h"
+            "${AOM_ROOT}/av1/encoder/intra_mode_search_utils.c"
             "${AOM_ROOT}/av1/encoder/intra_mode_search_utils.h"
             "${AOM_ROOT}/av1/encoder/wedge_utils.c"
             "${AOM_ROOT}/av1/encoder/var_based_part.c"
diff --git a/av1/common/av1_rtcd_defs.pl b/av1/common/av1_rtcd_defs.pl
index 9a9858531a..dd70ffca44 100644
--- a/av1/common/av1_rtcd_defs.pl
+++ b/av1/common/av1_rtcd_defs.pl
@@ -583,6 +583,19 @@ if (aom_config("CONFIG_AV1_ENCODER") eq "yes") {
     add_proto qw/int av1_denoiser_filter/, "const uint8_t *sig, int sig_stride, const uint8_t *mc_avg, int mc_avg_stride, uint8_t *avg, int avg_stride, int increase_denoising, BLOCK_SIZE bs, int motion_magnitude";
     specialize qw/av1_denoiser_filter neon sse2/;
   }
+
+  # Fused subtract + Hadamard + SATD for intra model RD
+  add_proto qw/int av1_hadamard_satd_4x4_sub/, "const uint8_t *src, ptrdiff_t src_stride, const uint8_t *pred, ptrdiff_t pred_stride";
+  specialize qw/av1_hadamard_satd_4x4_sub neon/;
+
+  add_proto qw/int av1_hadamard_satd_8x8_sub/, "const uint8_t *src, ptrdiff_t src_stride, const uint8_t *pred, ptrdiff_t pred_stride";
+  specialize qw/av1_hadamard_satd_8x8_sub neon/;
+
+  add_proto qw/int av1_hadamard_satd_16x16_sub/, "const uint8_t *src, ptrdiff_t src_stride, const uint8_t *pred, ptrdiff_t pred_stride";
+  specialize qw/av1_hadamard_satd_16x16_sub neon/;
+
+  add_proto qw/int av1_hadamard_satd_32x32_sub/, "const uint8_t *src, ptrdiff_t src_stride, const uint8_t *pred, ptrdiff_t pred_stride";
+  specialize qw/av1_hadamard_satd_32x32_sub neon/;
 }
 # end encoder functions

diff --git a/av1/encoder/arm/intra_mode_search_neon.c b/av1/encoder/arm/intra_mode_search_neon.c
index e41144afc0..3e2a7235e4 100644
--- a/av1/encoder/arm/intra_mode_search_neon.c
+++ b/av1/encoder/arm/intra_mode_search_neon.c
@@ -11,12 +11,17 @@

 #include <arm_neon.h>
 #include <assert.h>
+#include <stddef.h>
+#include <stdint.h>
 #include <stdlib.h>

 #include "config/aom_config.h"
 #include "config/av1_rtcd.h"

+#include "aom_dsp/arm/mem_neon.h"
 #include "aom_dsp/arm/sum_neon.h"
+#include "aom_dsp/arm/transpose_neon.h"
+#include "aom_ports/mem.h"
 #include "av1/encoder/intra_mode_search_utils.h"

 #if AOM_ARCH_AARCH64
@@ -504,3 +509,393 @@ void av1_highbd_compute_gradient_info_sb_neon(MACROBLOCK *const x,
 }
 #endif  // CONFIG_AV1_HIGHBITDEPTH
 #endif  // AOM_ARCH_AARCH64
+
+int av1_hadamard_satd_4x4_sub_neon(const uint8_t *src, ptrdiff_t src_stride,
+                                   const uint8_t *pred, ptrdiff_t pred_stride) {
+  const uint8x8_t s02 = load_unaligned_u8_4x2(src, 2 * src_stride);
+  const uint8x8_t s13 = load_unaligned_u8_4x2(src + src_stride, 2 * src_stride);
+  const uint8x8_t d02 = load_unaligned_u8_4x2(pred, 2 * pred_stride);
+  const uint8x8_t d13 =
+      load_unaligned_u8_4x2(pred + pred_stride, 2 * pred_stride);
+  const int16x8_t diff02 = vreinterpretq_s16_u16(vsubl_u8(s02, d02));
+  const int16x8_t diff13 = vreinterpretq_s16_u16(vsubl_u8(s13, d13));
+
+  // Pass 1 (columns): residuals in [-255, 255]; t02/t13 in [-255, 255];
+  // y01/y23 in [-510, 510] with no 16-bit overflow.
+  const int16x8_t t02 = vhaddq_s16(diff02, diff13);
+  const int16x8_t t13 = vhsubq_s16(diff02, diff13);
+  const int16x8_t p01 = vreinterpretq_s16_s64(
+      aom_vtrn1q_s64(vreinterpretq_s64_s16(t02), vreinterpretq_s64_s16(t13)));
+  const int16x8_t p23 = vreinterpretq_s16_s64(
+      aom_vtrn2q_s64(vreinterpretq_s64_s16(t02), vreinterpretq_s64_s16(t13)));
+  const int16x8_t y01 = vaddq_s16(p01, p23);
+  const int16x8_t y23 = vsubq_s16(p01, p23);
+
+  // Pass 2 (rows): deinterleave even/odd columns and fold the final butterfly
+  // via |u + v| + |u - v| = 2 * max(|u|, |v|) on [-510, 510] pairs.
+  const int16x8x2_t y_uzp = vuzpq_s16(y01, y23);
+  const int16x8_t b02 = vhaddq_s16(y_uzp.val[0], y_uzp.val[1]);
+  const int16x8_t b13 = vhsubq_s16(y_uzp.val[0], y_uzp.val[1]);
+  const int16x8_t abs02 = vabsq_s16(b02);
+  const int16x8_t abs13 = vabsq_s16(b13);
+#if AOM_ARCH_AARCH64
+  const int16x8_t m = vpmaxq_s16(abs02, abs13);
+  return (int)(horizontal_add_u16x8(vreinterpretq_u16_s16(m)) << 1);
+#else
+  const int16x4_t m0 = vpmax_s16(vget_low_s16(abs02), vget_high_s16(abs02));
+  const int16x4_t m1 = vpmax_s16(vget_low_s16(abs13), vget_high_s16(abs13));
+  const uint16x4_t m =
+      vadd_u16(vreinterpret_u16_s16(m0), vreinterpret_u16_s16(m1));
+  return (int)(horizontal_add_u16x4(m) << 1);
+#endif  // AOM_ARCH_AARCH64
+}
+
+static inline void load_u8_sub_s16_8x8(
+    const uint8_t *src, ptrdiff_t src_stride, const uint8_t *pred,
+    ptrdiff_t pred_stride, int16x8_t *a0, int16x8_t *a1, int16x8_t *a2,
+    int16x8_t *a3, int16x8_t *a4, int16x8_t *a5, int16x8_t *a6, int16x8_t *a7) {
+  uint8x8_t s0, s1, s2, s3, s4, s5, s6, s7;
+  uint8x8_t d0, d1, d2, d3, d4, d5, d6, d7;
+  load_u8_8x8(src, src_stride, &s0, &s1, &s2, &s3, &s4, &s5, &s6, &s7);
+  load_u8_8x8(pred, pred_stride, &d0, &d1, &d2, &d3, &d4, &d5, &d6, &d7);
+  *a0 = vreinterpretq_s16_u16(vsubl_u8(s0, d0));
+  *a1 = vreinterpretq_s16_u16(vsubl_u8(s1, d1));
+  *a2 = vreinterpretq_s16_u16(vsubl_u8(s2, d2));
+  *a3 = vreinterpretq_s16_u16(vsubl_u8(s3, d3));
+  *a4 = vreinterpretq_s16_u16(vsubl_u8(s4, d4));
+  *a5 = vreinterpretq_s16_u16(vsubl_u8(s5, d5));
+  *a6 = vreinterpretq_s16_u16(vsubl_u8(s6, d6));
+  *a7 = vreinterpretq_s16_u16(vsubl_u8(s7, d7));
+}
+
+static inline void hadamard_8x8_stage1_2_neon(
+    int16x8_t a0, int16x8_t a1, int16x8_t a2, int16x8_t a3, int16x8_t a4,
+    int16x8_t a5, int16x8_t a6, int16x8_t a7, int16x8_t *c0, int16x8_t *c1,
+    int16x8_t *c2, int16x8_t *c3, int16x8_t *c4, int16x8_t *c5, int16x8_t *c6,
+    int16x8_t *c7) {
+  const int16x8_t b0 = vaddq_s16(a0, a1);
+  const int16x8_t b1 = vsubq_s16(a0, a1);
+  const int16x8_t b2 = vaddq_s16(a2, a3);
+  const int16x8_t b3 = vsubq_s16(a2, a3);
+  const int16x8_t b4 = vaddq_s16(a4, a5);
+  const int16x8_t b5 = vsubq_s16(a4, a5);
+  const int16x8_t b6 = vaddq_s16(a6, a7);
+  const int16x8_t b7 = vsubq_s16(a6, a7);
+
+  *c0 = vaddq_s16(b0, b2);
+  *c1 = vaddq_s16(b1, b3);
+  *c2 = vsubq_s16(b0, b2);
+  *c3 = vsubq_s16(b1, b3);
+  *c4 = vaddq_s16(b4, b6);
+  *c5 = vaddq_s16(b5, b7);
+  *c6 = vsubq_s16(b4, b6);
+  *c7 = vsubq_s16(b5, b7);
+}
+
+static inline void hadamard_8x8_one_pass_neon(int16x8_t *a0, int16x8_t *a1,
+                                              int16x8_t *a2, int16x8_t *a3,
+                                              int16x8_t *a4, int16x8_t *a5,
+                                              int16x8_t *a6, int16x8_t *a7) {
+  int16x8_t c0, c1, c2, c3, c4, c5, c6, c7;
+  hadamard_8x8_stage1_2_neon(*a0, *a1, *a2, *a3, *a4, *a5, *a6, *a7, &c0, &c1,
+                             &c2, &c3, &c4, &c5, &c6, &c7);
+  *a0 = vaddq_s16(c0, c4);
+  *a1 = vsubq_s16(c2, c6);
+  *a2 = vsubq_s16(c0, c4);
+  *a3 = vaddq_s16(c2, c6);
+  *a4 = vaddq_s16(c3, c7);
+  *a5 = vsubq_s16(c3, c7);
+  *a6 = vsubq_s16(c1, c5);
+  *a7 = vaddq_s16(c1, c5);
+}
+
+int av1_hadamard_satd_8x8_sub_neon(const uint8_t *src, ptrdiff_t src_stride,
+                                   const uint8_t *pred, ptrdiff_t pred_stride) {
+  int16x8_t a0, a1, a2, a3, a4, a5, a6, a7;
+  load_u8_sub_s16_8x8(src, src_stride, pred, pred_stride, &a0, &a1, &a2, &a3,
+                      &a4, &a5, &a6, &a7);
+
+  hadamard_8x8_one_pass_neon(&a0, &a1, &a2, &a3, &a4, &a5, &a6, &a7);
+  transpose_elems_inplace_s16_8x8(&a0, &a1, &a2, &a3, &a4, &a5, &a6, &a7);
+
+  // Pass 2 reaches c0..c7 in [-8160, 8160] (sum of 32 terms in [-255, 255]).
+  // Folding the final add/sub via |u + v| + |u - v| = 2 * max(|u|, |v|) gives
+  // m0..m3 <= 8160 and sum <= 32640 <= UINT16_MAX without signed 16-bit
+  // overflow.
+  int16x8_t c0, c1, c2, c3, c4, c5, c6, c7;
+  hadamard_8x8_stage1_2_neon(a0, a1, a2, a3, a4, a5, a6, a7, &c0, &c1, &c2, &c3,
+                             &c4, &c5, &c6, &c7);
+
+  const uint16x8_t m0 =
+      vreinterpretq_u16_s16(vmaxq_s16(vabsq_s16(c0), vabsq_s16(c4)));
+  const uint16x8_t m1 =
+      vreinterpretq_u16_s16(vmaxq_s16(vabsq_s16(c2), vabsq_s16(c6)));
+  const uint16x8_t m2 =
+      vreinterpretq_u16_s16(vmaxq_s16(vabsq_s16(c3), vabsq_s16(c7)));
+  const uint16x8_t m3 =
+      vreinterpretq_u16_s16(vmaxq_s16(vabsq_s16(c1), vabsq_s16(c5)));
+  const uint16x8_t sum = vaddq_u16(vaddq_u16(m0, m1), vaddq_u16(m2, m3));
+  return (int)(horizontal_add_u16x8(sum) << 1);
+}
+
+static inline void hadamard_lp_8x8_sub_neon(const uint8_t *src,
+                                            ptrdiff_t src_stride,
+                                            const uint8_t *pred,
+                                            ptrdiff_t pred_stride,
+                                            int16_t *coeff) {
+  int16x8_t a0, a1, a2, a3, a4, a5, a6, a7;
+  load_u8_sub_s16_8x8(src, src_stride, pred, pred_stride, &a0, &a1, &a2, &a3,
+                      &a4, &a5, &a6, &a7);
+
+  hadamard_8x8_one_pass_neon(&a0, &a1, &a2, &a3, &a4, &a5, &a6, &a7);
+  transpose_elems_inplace_s16_8x8(&a0, &a1, &a2, &a3, &a4, &a5, &a6, &a7);
+  hadamard_8x8_one_pass_neon(&a0, &a1, &a2, &a3, &a4, &a5, &a6, &a7);
+
+  vst1q_s16(coeff + 0, a0);
+  vst1q_s16(coeff + 8, a1);
+  vst1q_s16(coeff + 16, a2);
+  vst1q_s16(coeff + 24, a3);
+  vst1q_s16(coeff + 32, a4);
+  vst1q_s16(coeff + 40, a5);
+  vst1q_s16(coeff + 48, a6);
+  vst1q_s16(coeff + 56, a7);
+}
+
+static inline void hadamard_lp_16x16_quadrants_sub_neon(const uint8_t *src,
+                                                        ptrdiff_t src_stride,
+                                                        const uint8_t *pred,
+                                                        ptrdiff_t pred_stride,
+                                                        int16_t *lp_coeff) {
+  for (int row = 0; row < 2; ++row) {
+    const uint8_t *const s_row = src + row * 8 * src_stride;
+    const uint8_t *const p_row = pred + row * 8 * pred_stride;
+    for (int col = 0; col < 2; ++col) {
+      hadamard_lp_8x8_sub_neon(s_row + col * 8, src_stride, p_row + col * 8,
+                               pred_stride, lp_coeff + (row * 2 + col) * 64);
+    }
+  }
+}
+
+static inline uint16x8_t hadamard_satd_16x16_pair_max_neon(
+    const int16_t *lp_coeff) {
+  // 8x8 LP coefficients fit in [-16320, 16320]; vhaddq/vhsubq halves into
+  // [-16320, 16320], so |u + v| + |u - v| = 2 * max(|u|, |v|) avoids [-32640,
+  // 32640] abs hazards and yields m0 + m1 <= 32640 (2 slices <= 65280 <= u16).
+  const int16x8_t a0 = vld1q_s16(lp_coeff + 0);
+  const int16x8_t a1 = vld1q_s16(lp_coeff + 64);
+  const int16x8_t a2 = vld1q_s16(lp_coeff + 128);
+  const int16x8_t a3 = vld1q_s16(lp_coeff + 192);
+  const int16x8_t b0 = vhaddq_s16(a0, a1);
+  const int16x8_t b1 = vhsubq_s16(a0, a1);
+  const int16x8_t b2 = vhaddq_s16(a2, a3);
+  const int16x8_t b3 = vhsubq_s16(a2, a3);
+  const uint16x8_t m0 =
+      vreinterpretq_u16_s16(vmaxq_s16(vabsq_s16(b0), vabsq_s16(b2)));
+  const uint16x8_t m1 =
+      vreinterpretq_u16_s16(vmaxq_s16(vabsq_s16(b1), vabsq_s16(b3)));
+  return vaddq_u16(m0, m1);
+}
+
+int av1_hadamard_satd_16x16_sub_neon(const uint8_t *src, ptrdiff_t src_stride,
+                                     const uint8_t *pred,
+                                     ptrdiff_t pred_stride) {
+  DECLARE_ALIGNED(16, int16_t, lp_coeff[256]);
+  hadamard_lp_16x16_quadrants_sub_neon(src, src_stride, pred, pred_stride,
+                                       lp_coeff);
+  uint32x4_t acc =
+      vpaddlq_u16(vaddq_u16(hadamard_satd_16x16_pair_max_neon(lp_coeff + 0),
+                            hadamard_satd_16x16_pair_max_neon(lp_coeff + 8)));
+  const int16_t *lp = lp_coeff + 16;
+  const int16_t *const lp_end = lp_coeff + 64;
+// Disabling unrolling on this 3-iteration loop avoids ARMv7 Q-register spills
+// and keeps the AArch64 loop compact.
+#if defined(__clang__)
+#pragma clang loop unroll(disable)
+#elif defined(__GNUC__) && __GNUC__ >= 8
+#pragma GCC unroll 1
+#endif
+  do {
+    acc =
+        vpadalq_u16(acc, vaddq_u16(hadamard_satd_16x16_pair_max_neon(lp + 0),
+                                   hadamard_satd_16x16_pair_max_neon(lp + 8)));
+    lp += 16;
+  } while (lp != lp_end);
+  return (int)(horizontal_add_u32x4(acc) << 1);
+}
+
+static inline uint16x8_t hadamard_satd_32x32_stage3_pair_max_neon(
+    int16x8_t a0, int16x8_t a1, int16x8_t a2, int16x8_t a3) {
+  // Stage 2 outputs fit in [-32640, 32640]; >> 2 keeps b0..b3 in
+  // [-16320, 16320], so m0 + m1 <= 32640 and two slices sum to <= 65280.
+  const int16x8_t b0 = vshrq_n_s16(vhaddq_s16(a0, a1), 1);
+  const int16x8_t b1 = vshrq_n_s16(vhsubq_s16(a0, a1), 1);
+  const int16x8_t b2 = vshrq_n_s16(vhaddq_s16(a2, a3), 1);
+  const int16x8_t b3 = vshrq_n_s16(vhsubq_s16(a2, a3), 1);
+  const uint16x8_t m0 =
+      vreinterpretq_u16_s16(vmaxq_s16(vabsq_s16(b0), vabsq_s16(b2)));
+  const uint16x8_t m1 =
+      vreinterpretq_u16_s16(vmaxq_s16(vabsq_s16(b1), vabsq_s16(b3)));
+  return vaddq_u16(m0, m1);
+}
+
+#if AOM_ARCH_AARCH64
+static inline void hadamard_lp_16x16_stage2_col_neon(const int16_t *lp_coeff,
+                                                     int16x8_t *c0,
+                                                     int16x8_t *c1,
+                                                     int16x8_t *c2,
+                                                     int16x8_t *c3) {
+  const int16x8_t a0 = vld1q_s16(lp_coeff + 0);
+  const int16x8_t a1 = vld1q_s16(lp_coeff + 64);
+  const int16x8_t a2 = vld1q_s16(lp_coeff + 128);
+  const int16x8_t a3 = vld1q_s16(lp_coeff + 192);
+  const int16x8_t b0 = vhaddq_s16(a0, a1);
+  const int16x8_t b1 = vhsubq_s16(a0, a1);
+  const int16x8_t b2 = vhaddq_s16(a2, a3);
+  const int16x8_t b3 = vhsubq_s16(a2, a3);
+  *c0 = vaddq_s16(b0, b2);
+  *c1 = vaddq_s16(b1, b3);
+  *c2 = vsubq_s16(b0, b2);
+  *c3 = vsubq_s16(b1, b3);
+}
+
+static inline void hadamard_satd_32x32_stage3_block_neon(const int16_t *lp,
+                                                         uint16x8_t *sum01,
+                                                         uint16x8_t *sum23) {
+  int16x8_t q0_0, q0_1, q0_2, q0_3;
+  int16x8_t q1_0, q1_1, q1_2, q1_3;
+  int16x8_t q2_0, q2_1, q2_2, q2_3;
+  int16x8_t q3_0, q3_1, q3_2, q3_3;
+  hadamard_lp_16x16_stage2_col_neon(lp + 0, &q0_0, &q0_1, &q0_2, &q0_3);
+  hadamard_lp_16x16_stage2_col_neon(lp + 256, &q1_0, &q1_1, &q1_2, &q1_3);
+  hadamard_lp_16x16_stage2_col_neon(lp + 512, &q2_0, &q2_1, &q2_2, &q2_3);
+  hadamard_lp_16x16_stage2_col_neon(lp + 768, &q3_0, &q3_1, &q3_2, &q3_3);
+  const uint16x8_t p0 =
+      hadamard_satd_32x32_stage3_pair_max_neon(q0_0, q1_0, q2_0, q3_0);
+  const uint16x8_t p1 =
+      hadamard_satd_32x32_stage3_pair_max_neon(q0_1, q1_1, q2_1, q3_1);
+  const uint16x8_t p2 =
+      hadamard_satd_32x32_stage3_pair_max_neon(q0_2, q1_2, q2_2, q3_2);
+  const uint16x8_t p3 =
+      hadamard_satd_32x32_stage3_pair_max_neon(q0_3, q1_3, q2_3, q3_3);
+  *sum01 = vaddq_u16(p0, p1);
+  *sum23 = vaddq_u16(p2, p3);
+}
+#else
+static inline void hadamard_lp_16x16_stage2_col_even_neon(
+    const int16_t *lp_coeff, int16x8_t *c0, int16x8_t *c2) {
+  const int16x8_t a0 = vld1q_s16(lp_coeff + 0);
+  const int16x8_t a1 = vld1q_s16(lp_coeff + 64);
+  const int16x8_t a2 = vld1q_s16(lp_coeff + 128);
+  const int16x8_t a3 = vld1q_s16(lp_coeff + 192);
+  const int16x8_t b0 = vhaddq_s16(a0, a1);
+  const int16x8_t b2 = vhaddq_s16(a2, a3);
+  *c0 = vaddq_s16(b0, b2);
+  *c2 = vsubq_s16(b0, b2);
+}
+
+static inline void hadamard_lp_16x16_stage2_col_odd_neon(
+    const int16_t *lp_coeff, int16x8_t *c1, int16x8_t *c3) {
+  const int16x8_t a0 = vld1q_s16(lp_coeff + 0);
+  const int16x8_t a1 = vld1q_s16(lp_coeff + 64);
+  const int16x8_t a2 = vld1q_s16(lp_coeff + 128);
+  const int16x8_t a3 = vld1q_s16(lp_coeff + 192);
+  const int16x8_t b1 = vhsubq_s16(a0, a1);
+  const int16x8_t b3 = vhsubq_s16(a2, a3);
+  *c1 = vaddq_s16(b1, b3);
+  *c3 = vsubq_s16(b1, b3);
+}
+
+static inline uint16x8_t hadamard_satd_32x32_stage3_half_even_neon(
+    const int16_t *lp) {
+  int16x8_t q0_0, q0_2, q1_0, q1_2, q2_0, q2_2, q3_0, q3_2;
+  hadamard_lp_16x16_stage2_col_even_neon(lp + 0, &q0_0, &q0_2);
+  hadamard_lp_16x16_stage2_col_even_neon(lp + 256, &q1_0, &q1_2);
+  hadamard_lp_16x16_stage2_col_even_neon(lp + 512, &q2_0, &q2_2);
+  hadamard_lp_16x16_stage2_col_even_neon(lp + 768, &q3_0, &q3_2);
+  const uint16x8_t p0 =
+      hadamard_satd_32x32_stage3_pair_max_neon(q0_0, q1_0, q2_0, q3_0);
+  const uint16x8_t p2 =
+      hadamard_satd_32x32_stage3_pair_max_neon(q0_2, q1_2, q2_2, q3_2);
+  return vaddq_u16(p0, p2);
+}
+
+static inline uint16x8_t hadamard_satd_32x32_stage3_half_odd_neon(
+    const int16_t *lp) {
+  int16x8_t q0_1, q0_3, q1_1, q1_3, q2_1, q2_3, q3_1, q3_3;
+  hadamard_lp_16x16_stage2_col_odd_neon(lp + 0, &q0_1, &q0_3);
+  hadamard_lp_16x16_stage2_col_odd_neon(lp + 256, &q1_1, &q1_3);
+  hadamard_lp_16x16_stage2_col_odd_neon(lp + 512, &q2_1, &q2_3);
+  hadamard_lp_16x16_stage2_col_odd_neon(lp + 768, &q3_1, &q3_3);
+  const uint16x8_t p1 =
+      hadamard_satd_32x32_stage3_pair_max_neon(q0_1, q1_1, q2_1, q3_1);
+  const uint16x8_t p3 =
+      hadamard_satd_32x32_stage3_pair_max_neon(q0_3, q1_3, q2_3, q3_3);
+  return vaddq_u16(p1, p3);
+}
+#endif  // AOM_ARCH_AARCH64
+
+int av1_hadamard_satd_32x32_sub_neon(const uint8_t *src, ptrdiff_t src_stride,
+                                     const uint8_t *pred,
+                                     ptrdiff_t pred_stride) {
+  DECLARE_ALIGNED(16, int16_t, lp_coeff[1024]);
+  for (int q = 0; q < 4; ++q) {
+    const ptrdiff_t row_off = (q >> 1) * 16;
+    const ptrdiff_t col_off = (q & 1) * 16;
+    hadamard_lp_16x16_quadrants_sub_neon(src + row_off * src_stride + col_off,
+                                         src_stride,
+                                         pred + row_off * pred_stride + col_off,
+                                         pred_stride, lp_coeff + q * 256);
+  }
+#if AOM_ARCH_AARCH64
+  uint16x8_t sum01, sum23;
+  hadamard_satd_32x32_stage3_block_neon(lp_coeff, &sum01, &sum23);
+  uint32x4_t acc0 = vpaddlq_u16(sum01);
+  uint32x4_t acc1 = vpaddlq_u16(sum23);
+  const int16_t *lp = lp_coeff + 8;
+  const int16_t *const lp_end = lp_coeff + 64;
+#if defined(__clang__)
+#pragma clang loop unroll(disable)
+#elif defined(__GNUC__) && __GNUC__ >= 8
+#pragma GCC unroll 1
+#endif
+  do {
+    hadamard_satd_32x32_stage3_block_neon(lp, &sum01, &sum23);
+    acc0 = vpadalq_u16(acc0, sum01);
+    acc1 = vpadalq_u16(acc1, sum23);
+    lp += 8;
+  } while (lp != lp_end);
+#else
+  // Split Stage 2+3 into even (c0, c2) and odd (c1, c3) passes on ARMv7 so
+  // live vectors stay within the 16 Q-register budget without stack spills.
+  // Peel the final slice (lp_coeff + 56) for acc1 so the compiler does not CSE
+  // lp_coeff's 16 loads across the even loop.
+  uint32x4_t acc0 =
+      vpaddlq_u16(hadamard_satd_32x32_stage3_half_even_neon(lp_coeff));
+  const int16_t *const lp_end = lp_coeff + 64;
+  const int16_t *lp = lp_coeff + 8;
+#if defined(__clang__)
+#pragma clang loop unroll(disable)
+#elif defined(__GNUC__) && __GNUC__ >= 8
+#pragma GCC unroll 1
+#endif
+  do {
+    acc0 = vpadalq_u16(acc0, hadamard_satd_32x32_stage3_half_even_neon(lp));
+    lp += 8;
+  } while (lp != lp_end);
+
+  const int16_t *const lp_odd_end = lp_coeff + 56;
+  uint32x4_t acc1 =
+      vpaddlq_u16(hadamard_satd_32x32_stage3_half_odd_neon(lp_odd_end));
+  lp = lp_coeff;
+#if defined(__clang__)
+#pragma clang loop unroll(disable)
+#elif defined(__GNUC__) && __GNUC__ >= 8
+#pragma GCC unroll 1
+#endif
+  do {
+    acc1 = vpadalq_u16(acc1, hadamard_satd_32x32_stage3_half_odd_neon(lp));
+    lp += 8;
+  } while (lp != lp_odd_end);
+#endif  // AOM_ARCH_AARCH64
+  return (int)(horizontal_add_u32x4(vaddq_u32(acc0, acc1)) << 1);
+}
diff --git a/av1/encoder/intra_mode_search_utils.c b/av1/encoder/intra_mode_search_utils.c
new file mode 100644
index 0000000000..6ad48fe530
--- /dev/null
+++ b/av1/encoder/intra_mode_search_utils.c
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2026, Alliance for Open Media. All rights reserved.
+ *
+ * This source code is subject to the terms of the BSD 2 Clause License and
+ * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
+ * was not distributed with this source code in the LICENSE file, you can
+ * obtain it at www.aomedia.org/license/software. If the Alliance for Open
+ * Media Patent License 1.0 was not distributed with this source code in the
+ * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
+ */
+
+#include <assert.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+
+#include "config/aom_config.h"
+#include "config/aom_dsp_rtcd.h"
+#include "config/av1_rtcd.h"
+
+#include "aom_dsp/aom_dsp_common.h"
+#include "aom_ports/mem.h"
+
+#if HAVE_NEON
+#include "av1/common/enums.h"
+#include "av1/common/reconintra.h"
+#include "av1/encoder/encodemb.h"
+#include "av1/encoder/hybrid_fwd_txfm.h"
+#include "av1/encoder/intra_mode_search_utils.h"
+#endif
+
+int av1_hadamard_satd_4x4_sub_c(const uint8_t *src, ptrdiff_t src_stride,
+                                const uint8_t *pred, ptrdiff_t pred_stride) {
+  DECLARE_ALIGNED(16, int16_t, src_diff[16]);
+  DECLARE_ALIGNED(16, tran_low_t, coeff[16]);
+  aom_subtract_block_c(4, 4, src_diff, 4, src, src_stride, pred, pred_stride);
+  aom_hadamard_4x4_c(src_diff, 4, coeff);
+  return aom_satd_c(coeff, 16);
+}
+
+int av1_hadamard_satd_8x8_sub_c(const uint8_t *src, ptrdiff_t src_stride,
+                                const uint8_t *pred, ptrdiff_t pred_stride) {
+  DECLARE_ALIGNED(16, int16_t, src_diff[64]);
+  DECLARE_ALIGNED(16, int16_t, lp_coeff[64]);
+  aom_subtract_block_c(8, 8, src_diff, 8, src, src_stride, pred, pred_stride);
+  aom_hadamard_lp_8x8_c(src_diff, 8, lp_coeff);
+  return aom_satd_lp_c(lp_coeff, 64);
+}
+
+int av1_hadamard_satd_16x16_sub_c(const uint8_t *src, ptrdiff_t src_stride,
+                                  const uint8_t *pred, ptrdiff_t pred_stride) {
+  DECLARE_ALIGNED(16, int16_t, src_diff[256]);
+  DECLARE_ALIGNED(16, int16_t, lp_coeff[256]);
+  aom_subtract_block_c(16, 16, src_diff, 16, src, src_stride, pred,
+                       pred_stride);
+  aom_hadamard_lp_16x16_c(src_diff, 16, lp_coeff);
+  return aom_satd_lp_c(lp_coeff, 256);
+}
+
+int av1_hadamard_satd_32x32_sub_c(const uint8_t *src, ptrdiff_t src_stride,
+                                  const uint8_t *pred, ptrdiff_t pred_stride) {
+  DECLARE_ALIGNED(16, int16_t, src_diff[1024]);
+  DECLARE_ALIGNED(16, tran_low_t, coeff[1024]);
+  aom_subtract_block_c(32, 32, src_diff, 32, src, src_stride, pred,
+                       pred_stride);
+  aom_hadamard_32x32_c(src_diff, 32, coeff);
+  return aom_satd_c(coeff, 1024);
+}
+
+#if HAVE_NEON
+int64_t av1_intra_model_rd_slow(const AV1_COMMON *cm, MACROBLOCK *const x,
+                                int plane, BLOCK_SIZE plane_bsize,
+                                TX_SIZE tx_size, int use_hadamard,
+                                bool need_border_pad) {
+  assert(plane >= 0 && plane < MAX_MB_PLANE);
+  assert(plane_bsize < BLOCK_SIZES_ALL);
+  assert(tx_size < TX_SIZES_ALL);
+  assert(IMPLIES(use_hadamard, tx_size <= TX_32X32));
+  MACROBLOCKD *const xd = &x->e_mbd;
+  const struct macroblock_plane *const p = &x->plane[plane];
+  const struct macroblockd_plane *const pd = &xd->plane[plane];
+  const uint8_t *const src_buf = p->src.buf;
+  const ptrdiff_t src_stride = p->src.stride;
+  const uint8_t *const dst_buf = pd->dst.buf;
+  const ptrdiff_t dst_stride = pd->dst.stride;
+  const int stepr = tx_size_high_unit[tx_size];
+  const int stepc = tx_size_wide_unit[tx_size];
+  const int max_blocks_wide = max_block_wide(xd, plane_bsize, plane);
+  const int max_blocks_high = max_block_high(xd, plane_bsize, plane);
+  const bool is_hbd = is_cur_buf_hbd(xd);
+  int64_t satd_cost = 0;
+
+  if (use_hadamard && !need_border_pad && !is_hbd) {
+    for (int row = 0; row < max_blocks_high; row += stepr) {
+      for (int col = 0; col < max_blocks_wide; col += stepc) {
+        av1_predict_intra_block_facade(cm, xd, plane, col, row, tx_size);
+        satd_cost += quick_sub_hadamard_satd_lowbd(
+            src_buf + (((row * src_stride) + col) << 2), src_stride,
+            dst_buf + (((row * dst_stride) + col) << 2), dst_stride, tx_size);
+      }
+    }
+    return satd_cost;
+  }
+
+  // Here we use p->src_diff and p->coeff as temporary buffers for
+  // prediction residue and transform coefficients. The buffers are only
+  // used in this for loop, therefore we don't need to properly add offset
+  // to the buffers.
+  const BitDepthInfo bd_info = get_bit_depth_info(xd);
+  const int txbw = tx_size_wide[tx_size];
+  const int txbh = tx_size_high[tx_size];
+  const int diff_stride = block_size_wide[plane_bsize];
+  int16_t *const src_diff = p->src_diff;
+  tran_low_t *const coeff = p->coeff;
+  const int num_coeffs = tx_size_2d[tx_size];
+  for (int row = 0; row < max_blocks_high; row += stepr) {
+    for (int col = 0; col < max_blocks_wide; col += stepc) {
+      av1_predict_intra_block_facade(cm, xd, plane, col, row, tx_size);
+      av1_subtract_block(
+          x, txbh, txbw, src_diff, diff_stride,
+          src_buf + (((row * src_stride) + col) << 2), src_stride,
+          dst_buf + (((row * dst_stride) + col) << 2), dst_stride, plane,
+          plane_bsize, col, row, DCT_DCT, need_border_pad);
+      av1_quick_txfm(use_hadamard, tx_size, bd_info, src_diff, diff_stride,
+                     coeff);
+      satd_cost += aom_satd(coeff, num_coeffs);
+    }
+  }
+  return satd_cost;
+}
+#endif  // HAVE_NEON
diff --git a/av1/encoder/intra_mode_search_utils.h b/av1/encoder/intra_mode_search_utils.h
index 505a77af42..68059e9e79 100644
--- a/av1/encoder/intra_mode_search_utils.h
+++ b/av1/encoder/intra_mode_search_utils.h
@@ -17,8 +17,17 @@
 #ifndef AOM_AV1_ENCODER_INTRA_MODE_SEARCH_UTILS_H_
 #define AOM_AV1_ENCODER_INTRA_MODE_SEARCH_UTILS_H_

+#include <assert.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+
+#include "config/aom_config.h"
+#include "config/aom_dsp_rtcd.h"
 #include "config/av1_rtcd.h"

+#include "aom_dsp/aom_dsp_common.h"
+
 #include "av1/common/enums.h"
 #include "av1/common/pred_common.h"
 #include "av1/common/reconintra.h"
@@ -677,6 +686,57 @@ static inline int intra_mode_info_cost_uv(const AV1_COMP *cpi,
 }

 /*!\cond */
+#if HAVE_NEON
+static inline int quick_sub_hadamard_satd_lowbd(const uint8_t *src,
+                                                ptrdiff_t src_stride,
+                                                const uint8_t *pred,
+                                                ptrdiff_t pred_stride,
+                                                TX_SIZE tx_size) {
+  switch (tx_size) {
+    case TX_4X4:
+      return av1_hadamard_satd_4x4_sub(src, src_stride, pred, pred_stride);
+    case TX_8X8:
+      return av1_hadamard_satd_8x8_sub(src, src_stride, pred, pred_stride);
+    case TX_16X16:
+      return av1_hadamard_satd_16x16_sub(src, src_stride, pred, pred_stride);
+    case TX_32X32:
+      return av1_hadamard_satd_32x32_sub(src, src_stride, pred, pred_stride);
+    default: assert(0); return 0;
+  }
+}
+
+int64_t av1_intra_model_rd_slow(const AV1_COMMON *cm, MACROBLOCK *const x,
+                                int plane, BLOCK_SIZE plane_bsize,
+                                TX_SIZE tx_size, int use_hadamard,
+                                bool need_border_pad);
+
+// Makes a quick intra prediction and estimate the rdcost with a model without
+// going through the whole txfm/quantize/itxfm process.
+// Note: leaves p->src_diff and p->coeff with unspecified scratch contents.
+static inline int64_t intra_model_rd(const AV1_COMMON *cm, MACROBLOCK *const x,
+                                     int plane, BLOCK_SIZE plane_bsize,
+                                     TX_SIZE tx_size, int use_hadamard,
+                                     bool do_border_pad) {
+  MACROBLOCKD *const xd = &x->e_mbd;
+  assert(!is_inter_block(xd->mi[0]));
+  assert(plane >= 0 && plane < MAX_MB_PLANE);
+  assert(plane_bsize < BLOCK_SIZES_ALL);
+  assert(tx_size < TX_SIZES_ALL);
+  assert(IMPLIES(use_hadamard, tx_size <= TX_32X32));
+  const bool need_border_pad =
+      do_border_pad && (x->pix_to_bottom_edge < 0 || x->pix_to_right_edge < 0);
+  if (use_hadamard && !need_border_pad && !is_cur_buf_hbd(xd) &&
+      txsize_to_bsize[tx_size] == plane_bsize) {
+    const struct macroblock_plane *const p = &x->plane[plane];
+    const struct macroblockd_plane *const pd = &xd->plane[plane];
+    av1_predict_intra_block_facade(cm, xd, plane, 0, 0, tx_size);
+    return quick_sub_hadamard_satd_lowbd(p->src.buf, p->src.stride, pd->dst.buf,
+                                         pd->dst.stride, tx_size);
+  }
+  return av1_intra_model_rd_slow(cm, x, plane, plane_bsize, tx_size,
+                                 use_hadamard, need_border_pad);
+}
+#else
 // Makes a quick intra prediction and estimate the rdcost with a model without
 // going through the whole txfm/quantize/itxfm process.
 static int64_t intra_model_rd(const AV1_COMMON *cm, MACROBLOCK *const x,
@@ -716,6 +776,7 @@ static int64_t intra_model_rd(const AV1_COMMON *cm, MACROBLOCK *const x,
   }
   return satd_cost;
 }
+#endif  // HAVE_NEON
 /*!\endcond */

 /*!\brief Estimate the luma rdcost of a given intra mode and try to prune it.
diff --git a/test/hadamard_test.cc b/test/hadamard_test.cc
index ea6775c320..20b8eb4213 100644
--- a/test/hadamard_test.cc
+++ b/test/hadamard_test.cc
@@ -10,11 +10,20 @@
  */

 #include <algorithm>
+#include <cstddef>
+#include <cstdint>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
 #include <ostream>

 #include "gtest/gtest.h"

+#include "config/aom_config.h"
 #include "config/aom_dsp_rtcd.h"
+#include "config/av1_rtcd.h"
+
+#include "aom_ports/mem.h"

 #include "test/acm_random.h"
 #include "test/register_state_check.h"
@@ -567,4 +576,236 @@ INSTANTIATE_TEST_SUITE_P(NEON, HadamardLowbdLP8x8DualTest,
                              &aom_hadamard_lp_8x8_dual_neon, 8, 16)));
 #endif  // HAVE_NEON

+using HadamardSatdSubFunc = int (*)(const uint8_t *src, ptrdiff_t src_stride,
+                                    const uint8_t *pred, ptrdiff_t pred_stride);
+using HadamardSatdSubFuncWithSize = FuncWithSize<HadamardSatdSubFunc>;
+
+int ReferenceHadamardSatdSub(const uint8_t *src, ptrdiff_t src_stride,
+                             const uint8_t *pred, ptrdiff_t pred_stride, int bw,
+                             int bh) {
+  const int block_size = bw * bh;
+  int16_t diff[32 * 32] = {};
+  for (int r = 0; r < bh; ++r) {
+    for (int c = 0; c < bw; ++c) {
+      diff[r * bw + c] = static_cast<int16_t>(src[r * src_stride + c] -
+                                              pred[r * pred_stride + c]);
+    }
+  }
+  tran_low_t coeff[32 * 32] = {};
+  ReferenceHadamard(diff, bw, coeff, bw, bh, /*shift=*/true);
+  int satd = 0;
+  for (int i = 0; i < block_size; ++i) {
+    satd += std::abs(static_cast<int>(coeff[i]));
+  }
+  return satd;
+}
+
+class HadamardSatdSubTest
+    : public ::testing::TestWithParam<HadamardSatdSubFuncWithSize> {
+ public:
+  void SetUp() override {
+    func_ = GetParam().func;
+    bw_ = GetParam().block_width;
+    bh_ = GetParam().block_height;
+    rnd_.Reset(ACMRandom::DeterministicSeed());
+  }
+
+ protected:
+  void CompareReferenceRandom() {
+    constexpr int kMaxBlockSize = 32 * 32;
+    DECLARE_ALIGNED(16, uint8_t, src[kMaxBlockSize]);
+    DECLARE_ALIGNED(16, uint8_t, dst[kMaxBlockSize]);
+    memset(src, 0, sizeof(src));
+    memset(dst, 0, sizeof(dst));
+    for (int iter = 0; iter < 20; ++iter) {
+      for (int i = 0; i < bw_ * bh_; ++i) {
+        src[i] = rnd_.Rand8();
+        dst[i] = rnd_.Rand8();
+      }
+      const int expected =
+          ReferenceHadamardSatdSub(src, bw_, dst, bw_, bw_, bh_);
+      int actual = 0;
+      API_REGISTER_STATE_CHECK(actual = func_(src, bw_, dst, bw_));
+      EXPECT_EQ(actual, expected) << "iter=" << iter;
+    }
+  }
+
+  void CompareReferenceExtreme() {
+    constexpr int kMaxBlockSize = 32 * 32;
+    DECLARE_ALIGNED(16, uint8_t, src[kMaxBlockSize]);
+    DECLARE_ALIGNED(16, uint8_t, dst[kMaxBlockSize]);
+    memset(src, 0, sizeof(src));
+    memset(dst, 0, sizeof(dst));
+    const int block_size = bw_ * bh_;
+    for (int pattern = 0; pattern < 13; ++pattern) {
+      for (int i = 0; i < block_size; ++i) {
+        const int row = i / bw_;
+        const int col = i % bw_;
+        switch (pattern) {
+          case 0:
+            src[i] = 255;
+            dst[i] = 0;
+            break;
+          case 1:
+            src[i] = 0;
+            dst[i] = 255;
+            break;
+          case 2:
+            src[i] = 0;
+            dst[i] = 0;
+            break;
+          case 3:
+            src[i] = 255;
+            dst[i] = 255;
+            break;
+          case 4:
+            src[i] = (col & 1) ? 255 : 0;
+            dst[i] = (col & 1) ? 0 : 255;
+            break;
+          case 5:
+            src[i] = ((row + col) & 1) ? 255 : 0;
+            dst[i] = ((row + col) & 1) ? 0 : 255;
+            break;
+          case 6:  // Horizontal quadrant sign flip (stresses a0 - a1).
+            src[i] = (col >= bw_ / 2) ? 255 : 0;
+            dst[i] = (col >= bw_ / 2) ? 0 : 255;
+            break;
+          case 7:  // 2x2 quadrant checkerboard (stresses b0 - b2 and b1 - b3).
+            src[i] = ((row >= bh_ / 2) ^ (col >= bw_ / 2)) ? 255 : 0;
+            dst[i] = ((row >= bh_ / 2) ^ (col >= bw_ / 2)) ? 0 : 255;
+            break;
+          case 8:  // 3-quadrant +255 / 1-quadrant -255 (32640 in uint16_t
+                   // pair-sum lane, 65280 after << 1).
+            src[i] = (row >= bh_ / 2 && col >= bw_ / 2) ? 0 : 255;
+            dst[i] = (row >= bh_ / 2 && col >= bw_ / 2) ? 255 : 0;
+            break;
+          case 9:
+            src[i] = (row >= bh_ / 2 && col >= bw_ / 2) ? 255 : 0;
+            dst[i] = (row >= bh_ / 2 && col >= bw_ / 2) ? 0 : 255;
+            break;
+          case 10: {  // Hits 40800 (> INT16_MAX) in 32x32 AArch64 u16 pair-sum.
+            const bool neg = !(row >= bh_ / 2 && col >= bw_ / 2) &&
+                             (col % (bw_ / 2)) < bw_ / 4;
+            src[i] = neg ? 0 : 255;
+            dst[i] = neg ? 255 : 0;
+            break;
+          }
+          case 11: {  // Hits 40800 (> INT16_MAX) in 32x32 ARMv7 u16 pair-sum.
+            const bool neg = !(row >= bh_ / 2 && col >= bw_ / 2) &&
+                             (row % (bh_ / 2)) < bh_ / 4;
+            src[i] = neg ? 0 : 255;
+            dst[i] = neg ? 255 : 0;
+            break;
+          }
+          case 12:
+          default: {  // Hits 40800 (> INT16_MAX) in 16x16 u16 pair-sum lane.
+            const bool neg =
+                !(row >= bh_ / 2 && col >= bw_ / 2) && ((col + 2) & 4) != 0;
+            src[i] = neg ? 0 : 255;
+            dst[i] = neg ? 255 : 0;
+            break;
+          }
+        }
+      }
+      const int expected =
+          ReferenceHadamardSatdSub(src, bw_, dst, bw_, bw_, bh_);
+      int actual = 0;
+      API_REGISTER_STATE_CHECK(actual = func_(src, bw_, dst, bw_));
+      EXPECT_EQ(actual, expected) << "pattern=" << pattern;
+    }
+  }
+
+  void VaryStrideAndAlignment() {
+    constexpr int kMaxStride = 128;
+    constexpr int kMaxAlignOffset = 15;
+    constexpr int kBufSize = 32 * kMaxStride + kMaxAlignOffset + 32;
+    DECLARE_ALIGNED(16, uint8_t, src_buf[kBufSize]);
+    DECLARE_ALIGNED(16, uint8_t, dst_buf[kBufSize]);
+    for (int i = 0; i < kBufSize; ++i) {
+      src_buf[i] = rnd_.Rand8();
+      dst_buf[i] = rnd_.Rand8();
+    }
+    const int offsets[] = { 0, 1, 3, 7, 15 };
+    const int extras[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 16, 17, 26, 32, 35 };
+    for (int src_off : offsets) {
+      for (int dst_off : offsets) {
+        for (int extra : extras) {
+          const ptrdiff_t src_stride = bw_ + extra;
+          const ptrdiff_t pred_stride = bw_ + ((extra + 5) % 40);
+          const uint8_t *const src = src_buf + src_off;
+          const uint8_t *const pred = dst_buf + dst_off;
+          const int expected = ReferenceHadamardSatdSub(src, src_stride, pred,
+                                                        pred_stride, bw_, bh_);
+          int actual = 0;
+          API_REGISTER_STATE_CHECK(
+              actual = func_(src, src_stride, pred, pred_stride));
+          EXPECT_EQ(actual, expected)
+              << "src_off=" << src_off << " dst_off=" << dst_off
+              << " src_stride=" << src_stride << " pred_stride=" << pred_stride;
+        }
+      }
+    }
+  }
+
+  void SpeedTest(int times) {
+    constexpr int kMaxBlockSize = 32 * 32;
+    DECLARE_ALIGNED(16, uint8_t, src[kMaxBlockSize]);
+    DECLARE_ALIGNED(16, uint8_t, dst[kMaxBlockSize]);
+    for (int i = 0; i < kMaxBlockSize; ++i) {
+      src[i] = static_cast<uint8_t>((i * 7 + 13) & 255);
+      dst[i] = static_cast<uint8_t>((i * 5 + 3) & 255);
+    }
+
+    uint64_t sum = 0;
+    aom_usec_timer timer;
+    aom_usec_timer_start(&timer);
+    for (int i = 0; i < times; ++i) {
+      sum += static_cast<uint32_t>(func_(src, bw_, dst, bw_));
+    }
+    aom_usec_timer_mark(&timer);
+
+    const int elapsed_time = static_cast<int>(aom_usec_timer_elapsed(&timer));
+    printf("HadamardSatdSub%dx%d[%12d runs]: %d us (sum=%llu)\n", bw_, bh_,
+           times, elapsed_time, static_cast<unsigned long long>(sum));
+  }
+
+  HadamardSatdSubFunc func_ = nullptr;
+  int bw_ = 0;
+  int bh_ = 0;
+  ACMRandom rnd_;
+};
+
+TEST_P(HadamardSatdSubTest, CompareReferenceRandom) {
+  CompareReferenceRandom();
+}
+
+TEST_P(HadamardSatdSubTest, CompareReferenceExtreme) {
+  CompareReferenceExtreme();
+}
+
+TEST_P(HadamardSatdSubTest, VaryStrideAndAlignment) {
+  VaryStrideAndAlignment();
+}
+
+TEST_P(HadamardSatdSubTest, DISABLED_SpeedTest) { SpeedTest(1000000); }
+
+INSTANTIATE_TEST_SUITE_P(
+    C, HadamardSatdSubTest,
+    ::testing::Values(
+        HadamardSatdSubFuncWithSize(&av1_hadamard_satd_4x4_sub_c, 4, 4),
+        HadamardSatdSubFuncWithSize(&av1_hadamard_satd_8x8_sub_c, 8, 8),
+        HadamardSatdSubFuncWithSize(&av1_hadamard_satd_16x16_sub_c, 16, 16),
+        HadamardSatdSubFuncWithSize(&av1_hadamard_satd_32x32_sub_c, 32, 32)));
+
+#if HAVE_NEON
+INSTANTIATE_TEST_SUITE_P(
+    NEON, HadamardSatdSubTest,
+    ::testing::Values(
+        HadamardSatdSubFuncWithSize(&av1_hadamard_satd_4x4_sub_neon, 4, 4),
+        HadamardSatdSubFuncWithSize(&av1_hadamard_satd_8x8_sub_neon, 8, 8),
+        HadamardSatdSubFuncWithSize(&av1_hadamard_satd_16x16_sub_neon, 16, 16),
+        HadamardSatdSubFuncWithSize(&av1_hadamard_satd_32x32_sub_neon, 32,
+                                    32)));
+#endif  // HAVE_NEON
+
 }  // namespace