Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
361 changes: 308 additions & 53 deletions src/row/arch/neon.rs

Large diffs are not rendered by default.

179 changes: 179 additions & 0 deletions src/row/arch/neon/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2367,3 +2367,182 @@ fn neon_p416_matches_scalar_tail_widths() {
check_p_n_444_16_u16_neon_equivalence(w, ColorMatrix::Bt2020Ncl, true);
}
}

// ---- High-bit 4:4:4 u8 RGBA equivalence (Ship 8 Tranche 7b) ---------
//
// Mirrors the 4:2:0 RGBA pattern in PR #25 (Tranche 5a). Each kernel
// family — Yuv444p_n (BITS-generic), Yuv444p16, Pn_444 (BITS-generic),
// Pn_444_16 — has its NEON RGBA kernel byte-pinned against the scalar
// reference at the natural width and a sweep of tail widths.

fn check_yuv444p_n_u8_neon_rgba_equivalence<const BITS: u32>(
width: usize,
matrix: ColorMatrix,
full_range: bool,
) {
let y = planar_n_plane::<BITS>(width, 37);
let u = planar_n_plane::<BITS>(width, 53);
let v = planar_n_plane::<BITS>(width, 71);
let mut rgba_scalar = std::vec![0u8; width * 4];
let mut rgba_neon = std::vec![0u8; width * 4];
scalar::yuv_444p_n_to_rgba_row::<BITS>(&y, &u, &v, &mut rgba_scalar, width, matrix, full_range);
unsafe {
yuv_444p_n_to_rgba_row::<BITS>(&y, &u, &v, &mut rgba_neon, width, matrix, full_range);
}
assert_eq!(
rgba_scalar, rgba_neon,
"NEON Yuv444p<{BITS}> → RGBA u8 diverges (width={width}, matrix={matrix:?}, full_range={full_range})"
);
}

fn check_pn_444_u8_neon_rgba_equivalence<const BITS: u32>(
width: usize,
matrix: ColorMatrix,
full_range: bool,
) {
let y = high_bit_plane::<BITS>(width, 37);
let u = high_bit_plane::<BITS>(width, 53);
let v = high_bit_plane::<BITS>(width, 71);
let uv = interleave_uv(&u, &v);
let mut rgba_scalar = std::vec![0u8; width * 4];
let mut rgba_neon = std::vec![0u8; width * 4];
scalar::p_n_444_to_rgba_row::<BITS>(&y, &uv, &mut rgba_scalar, width, matrix, full_range);
unsafe {
p_n_444_to_rgba_row::<BITS>(&y, &uv, &mut rgba_neon, width, matrix, full_range);
}
assert_eq!(
rgba_scalar, rgba_neon,
"NEON Pn4:4:4<{BITS}> → RGBA u8 diverges (width={width}, matrix={matrix:?}, full_range={full_range})"
);
}

fn check_yuv444p16_u8_neon_rgba_equivalence(width: usize, matrix: ColorMatrix, full_range: bool) {
let y = p16_plane_neon(width, 37);
let u = p16_plane_neon(width, 53);
let v = p16_plane_neon(width, 71);
let mut rgba_scalar = std::vec![0u8; width * 4];
let mut rgba_neon = std::vec![0u8; width * 4];
scalar::yuv_444p16_to_rgba_row(&y, &u, &v, &mut rgba_scalar, width, matrix, full_range);
unsafe {
yuv_444p16_to_rgba_row(&y, &u, &v, &mut rgba_neon, width, matrix, full_range);
}
assert_eq!(
rgba_scalar, rgba_neon,
"NEON Yuv444p16 → RGBA u8 diverges (width={width}, matrix={matrix:?}, full_range={full_range})"
);
}

fn check_p_n_444_16_u8_neon_rgba_equivalence(width: usize, matrix: ColorMatrix, full_range: bool) {
let y = p16_plane_neon(width, 37);
let u = p16_plane_neon(width, 53);
let v = p16_plane_neon(width, 71);
let uv = interleave_uv(&u, &v);
let mut rgba_scalar = std::vec![0u8; width * 4];
let mut rgba_neon = std::vec![0u8; width * 4];
scalar::p_n_444_16_to_rgba_row(&y, &uv, &mut rgba_scalar, width, matrix, full_range);
unsafe {
p_n_444_16_to_rgba_row(&y, &uv, &mut rgba_neon, width, matrix, full_range);
}
assert_eq!(
rgba_scalar, rgba_neon,
"NEON P416 → RGBA u8 diverges (width={width}, matrix={matrix:?}, full_range={full_range})"
);
}

#[test]
#[cfg_attr(miri, ignore = "NEON SIMD intrinsics unsupported by Miri")]
fn neon_yuv444p_n_rgba_matches_scalar_all_bits() {
for m in [
ColorMatrix::Bt601,
ColorMatrix::Bt709,
ColorMatrix::Bt2020Ncl,
ColorMatrix::Smpte240m,
ColorMatrix::Fcc,
ColorMatrix::YCgCo,
] {
for full in [true, false] {
check_yuv444p_n_u8_neon_rgba_equivalence::<9>(16, m, full);
check_yuv444p_n_u8_neon_rgba_equivalence::<10>(16, m, full);
check_yuv444p_n_u8_neon_rgba_equivalence::<12>(16, m, full);
check_yuv444p_n_u8_neon_rgba_equivalence::<14>(16, m, full);
}
}
}

#[test]
#[cfg_attr(miri, ignore = "NEON SIMD intrinsics unsupported by Miri")]
fn neon_yuv444p_n_rgba_matches_scalar_tail_and_widths() {
for w in [17usize, 31, 47, 63, 1920, 1922] {
check_yuv444p_n_u8_neon_rgba_equivalence::<9>(w, ColorMatrix::Bt601, false);
check_yuv444p_n_u8_neon_rgba_equivalence::<10>(w, ColorMatrix::Bt709, true);
check_yuv444p_n_u8_neon_rgba_equivalence::<12>(w, ColorMatrix::Bt2020Ncl, false);
check_yuv444p_n_u8_neon_rgba_equivalence::<14>(w, ColorMatrix::YCgCo, true);
}
}

#[test]
#[cfg_attr(miri, ignore = "NEON SIMD intrinsics unsupported by Miri")]
fn neon_pn_444_rgba_matches_scalar_all_bits() {
for m in [
ColorMatrix::Bt601,
ColorMatrix::Bt709,
ColorMatrix::Bt2020Ncl,
ColorMatrix::Smpte240m,
ColorMatrix::Fcc,
ColorMatrix::YCgCo,
] {
for full in [true, false] {
check_pn_444_u8_neon_rgba_equivalence::<10>(16, m, full);
check_pn_444_u8_neon_rgba_equivalence::<12>(16, m, full);
}
}
}

#[test]
#[cfg_attr(miri, ignore = "NEON SIMD intrinsics unsupported by Miri")]
fn neon_pn_444_rgba_matches_scalar_tail_and_widths() {
for w in [17usize, 31, 47, 63, 1920, 1922] {
check_pn_444_u8_neon_rgba_equivalence::<10>(w, ColorMatrix::Bt601, false);
check_pn_444_u8_neon_rgba_equivalence::<12>(w, ColorMatrix::Bt709, true);
}
}

#[test]
#[cfg_attr(miri, ignore = "NEON SIMD intrinsics unsupported by Miri")]
fn neon_yuv444p16_rgba_matches_scalar_all_matrices() {
for m in [
ColorMatrix::Bt601,
ColorMatrix::Bt709,
ColorMatrix::Bt2020Ncl,
ColorMatrix::Smpte240m,
ColorMatrix::Fcc,
ColorMatrix::YCgCo,
] {
for full in [true, false] {
check_yuv444p16_u8_neon_rgba_equivalence(16, m, full);
}
}
for w in [17usize, 31, 47, 63, 1920, 1922] {
check_yuv444p16_u8_neon_rgba_equivalence(w, ColorMatrix::Bt709, false);
}
}

#[test]
#[cfg_attr(miri, ignore = "NEON SIMD intrinsics unsupported by Miri")]
fn neon_p416_rgba_matches_scalar_all_matrices() {
for m in [
ColorMatrix::Bt601,
ColorMatrix::Bt709,
ColorMatrix::Bt2020Ncl,
ColorMatrix::Smpte240m,
ColorMatrix::Fcc,
ColorMatrix::YCgCo,
] {
for full in [true, false] {
check_p_n_444_16_u8_neon_rgba_equivalence(16, m, full);
}
}
for w in [17usize, 31, 47, 63, 1920, 1922] {
check_p_n_444_16_u8_neon_rgba_equivalence(w, ColorMatrix::Bt709, false);
}
}
Loading
Loading