mirror of
https://mirror.skon.top/https://github.com/FFmpeg/FFmpeg
synced 2026-04-20 12:50:49 +08:00
avutil/aarch64: add pixelutils 32x32 SAD NEON implementation
This adds a NEON-optimized function for computing 32x32 Sum of Absolute Differences (SAD) on AArch64, addressing a gap where x86 had SSE2/AVX2 implementations but AArch64 lacked equivalent coverage. The implementation mirrors the existing sad8 and sad16 NEON functions, employing a 4-row unrolled loop with UABAL and UABAL2 instructions for efficient load-compute interleaving, and four 8x16-bit accumulators to handle the wider 32-byte rows. Benchmarks on AWS Graviton3 (Neoverse V1, c7g.xlarge) using checkasm: sad_32x32_0: C 146.4 cycles -> NEON 98.1 cycles (1.49x speedup) sad_32x32_1: C 141.4 cycles -> NEON 98.9 cycles (1.43x speedup) sad_32x32_2: C 140.7 cycles -> NEON 95.0 cycles (1.48x speedup) Signed-off-by: Jeongkeun Kim <variety0724@gmail.com>
This commit is contained in:
committed by
Martin Storsjö
parent
4af27ba4ca
commit
de18feb0f0
@@ -27,9 +27,11 @@
|
||||
#include "libavutil/cpu.h"
|
||||
#include "libavutil/pixelutils.h"
|
||||
|
||||
int ff_pixelutils_sad8_neon (const uint8_t *src1, ptrdiff_t stride1,
|
||||
const uint8_t *src2, ptrdiff_t stride2);
|
||||
int ff_pixelutils_sad16_neon(const uint8_t *src1, ptrdiff_t stride1,
|
||||
const uint8_t *src2, ptrdiff_t stride2);
|
||||
int ff_pixelutils_sad8_neon (const uint8_t *src1, ptrdiff_t stride1,
|
||||
int ff_pixelutils_sad32_neon(const uint8_t *src1, ptrdiff_t stride1,
|
||||
const uint8_t *src2, ptrdiff_t stride2);
|
||||
|
||||
static inline av_cold void ff_pixelutils_sad_init_aarch64(av_pixelutils_sad_fn *sad, int aligned)
|
||||
@@ -39,6 +41,7 @@ static inline av_cold void ff_pixelutils_sad_init_aarch64(av_pixelutils_sad_fn *
|
||||
if (have_neon(cpu_flags)) {
|
||||
sad[2] = ff_pixelutils_sad8_neon;
|
||||
sad[3] = ff_pixelutils_sad16_neon;
|
||||
sad[4] = ff_pixelutils_sad32_neon;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -86,3 +86,50 @@ function ff_pixelutils_sad8_neon, export=1
|
||||
|
||||
ret
|
||||
endfunc
|
||||
|
||||
function ff_pixelutils_sad32_neon, export=1
|
||||
// x0 uint8_t *pix1
|
||||
// x1 ptrdiff_t stride1
|
||||
// x2 uint8_t *pix2
|
||||
// x3 ptrdiff_t stride2
|
||||
movi v16.8h, #0 // clear result accumulator
|
||||
movi v17.8h, #0 // clear result accumulator
|
||||
movi v18.8h, #0 // clear result accumulator
|
||||
movi v19.8h, #0 // clear result accumulator
|
||||
mov w4, 32
|
||||
1:
|
||||
ld1 {v0.16b, v1.16b}, [x0], x1 // load pix1
|
||||
ld1 {v4.16b, v5.16b}, [x2], x3 // load pix2
|
||||
ld1 {v2.16b, v3.16b}, [x0], x1 // load pix1
|
||||
ld1 {v6.16b, v7.16b}, [x2], x3 // load pix2
|
||||
uabal v16.8h, v0.8b, v4.8b // absolute difference accumulate
|
||||
uabal2 v17.8h, v0.16b, v4.16b
|
||||
uabal v18.8h, v1.8b, v5.8b
|
||||
uabal2 v19.8h, v1.16b, v5.16b
|
||||
ld1 {v0.16b, v1.16b}, [x0], x1 // load pix1
|
||||
ld1 {v4.16b, v5.16b}, [x2], x3 // load pix2
|
||||
uabal v16.8h, v2.8b, v6.8b // absolute difference accumulate
|
||||
uabal2 v17.8h, v2.16b, v6.16b
|
||||
uabal v18.8h, v3.8b, v7.8b
|
||||
uabal2 v19.8h, v3.16b, v7.16b
|
||||
ld1 {v2.16b, v3.16b}, [x0], x1
|
||||
ld1 {v6.16b, v7.16b}, [x2], x3
|
||||
uabal v16.8h, v0.8b, v4.8b
|
||||
uabal2 v17.8h, v0.16b, v4.16b
|
||||
uabal v18.8h, v1.8b, v5.8b
|
||||
uabal2 v19.8h, v1.16b, v5.16b
|
||||
subs w4, w4, #4 // h -= 4
|
||||
uabal v16.8h, v2.8b, v6.8b
|
||||
uabal2 v17.8h, v2.16b, v6.16b
|
||||
uabal v18.8h, v3.8b, v7.8b
|
||||
uabal2 v19.8h, v3.16b, v7.16b
|
||||
|
||||
b.gt 1b // if h > 0, loop
|
||||
|
||||
add v16.8h, v16.8h, v17.8h
|
||||
add v18.8h, v18.8h, v19.8h
|
||||
add v16.8h, v16.8h, v18.8h
|
||||
uaddlv s16, v16.8h // add up everything in v16 accumulator
|
||||
fmov w0, s16 // copy result to general purpose register
|
||||
ret
|
||||
endfunc
|
||||
|
||||
Reference in New Issue
Block a user