Skip to content

Add NEON path for avifFillAlpha and same-depth avifReformatAlpha copies - #3312

Open
kjg0724 wants to merge 1 commit into
AOMediaCodec:mainfrom
kjg0724:neon-alpha-fill-reformat
Open

Add NEON path for avifFillAlpha and same-depth avifReformatAlpha copies#3312
kjg0724 wants to merge 1 commit into
AOMediaCodec:mainfrom
kjg0724:neon-alpha-fill-reformat

Conversation

@kjg0724

@kjg0724 kjg0724 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

avifFillAlpha and avifReformatAlpha currently use scalar C when alpha processing is not already handled by libyuv. This adds AArch64 NEON implementations for:

  • avifFillAlpha, for both 8-bit and 16-bit storage
  • avifReformatAlpha same-depth copies (srcDepth == dstDepth), for both 8-bit and 16-bit storage

Gated by #if defined(__aarch64__): Advanced SIMD is part of the AArch64 baseline, so no runtime feature detection is needed. MSVC's _M_ARM64 is not covered by this guard and stays on the existing scalar path.

The differing-depth avifReformatAlpha rescale paths remain scalar.

Tested:

  • macOS arm64 (Apple Clang): cmake --build build --target avifalphatest, all cases pass; existing avifalphapremtest/avifbasictest/avifrgbtoyuvtest/avifyuv unaffected
  • Ubuntu 22.04 aarch64 (GCC 11.4): same test suite, all pass
  • This repo's CI has no AArch64 runner, so both platforms above were verified manually on real hardware rather than in CI

Benchmark (Oracle Cloud A1, Neoverse-N1, 8-bit depth, NEON vs a scalar-forced build of the same source):

  • Fill, contiguous plane: 7.55x at 1920x1080, 7.13x at 4096x4096
  • Fill, interleaved RGBA (alpha lane 3): 1.56x at 1920x1080, 1.29x at 4096x4096
  • Reformat, interleaved RGBA -> contiguous plane (gather): 3.67x at 1920x1080, 2.52x at 4096x4096
  • Reformat, contiguous plane -> interleaved RGBA (scatter): 1.69x at 1920x1080, 1.56x at 4096x4096

Both functions are 100% scalar today with no libyuv involvement, and run on
every alpha-channel image during decode/reformat. Add an AArch64 NEON
implementation gated by __aarch64__ (NEON is the mandatory Advanced SIMD
baseline there, so no runtime feature detection is needed). MSVC's
_M_ARM64 is not covered by this guard and stays on the existing scalar
path for now.

avifReformatAlpha's rescale paths (differing src/dst depth) are
intentionally left scalar in this change; they involve a float
multiply/round/clamp per pixel and are a natural follow-up once this
lands.

Adds tests/gtest/avifalphatest.cc covering valid interleave layouts,
tail/remainder widths, zero dimensions, and layouts the NEON dispatch
must reject in favor of the scalar fallback.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant