#![cfg_attr(not(feature = "std"), allow(dead_code))]
#[cfg(any(
target_arch = "aarch64",
target_arch = "x86_64",
target_arch = "wasm32"
))]
use crate::row::arch;
#[cfg(target_arch = "aarch64")]
use crate::row::neon_available;
use crate::row::scalar::y_plane_to_luma_u16 as scalar;
#[cfg(target_arch = "wasm32")]
use crate::row::simd128_available;
#[cfg(target_arch = "x86_64")]
use crate::row::{avx2_available, avx512_available, sse41_available};
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn y_plane_to_luma_u16_row(plane: &[u8], out: &mut [u16], width: usize, use_simd: bool) {
assert!(plane.len() >= width, "plane too short");
assert!(out.len() >= width, "out too short");
if !use_simd {
return scalar::y_plane_to_luma_u16_row(plane, out, width);
}
cfg_select! {
target_arch = "aarch64" => {
if neon_available() {
unsafe { arch::neon::y_plane_to_luma_u16_row(plane, out, width); }
return;
}
},
target_arch = "x86_64" => {
if avx512_available() {
unsafe { arch::x86_avx512::y_plane_to_luma_u16_row(plane, out, width); }
return;
}
if avx2_available() {
unsafe { arch::x86_avx2::y_plane_to_luma_u16_row(plane, out, width); }
return;
}
if sse41_available() {
unsafe { arch::x86_sse41::y_plane_to_luma_u16_row(plane, out, width); }
return;
}
},
target_arch = "wasm32" => {
if simd128_available() {
unsafe { arch::wasm_simd128::y_plane_to_luma_u16_row(plane, out, width); }
return;
}
},
_ => {}
}
scalar::y_plane_to_luma_u16_row(plane, out, width);
}
#[cfg(all(test, feature = "std"))]
mod tests {
use super::*;
#[test]
#[should_panic(expected = "plane too short")]
fn dispatcher_panics_on_short_plane() {
let plane = std::vec![0u8; 4];
let mut out = std::vec![0u16; 8];
y_plane_to_luma_u16_row(&plane, &mut out, 8, true);
}
#[test]
#[should_panic(expected = "out too short")]
fn dispatcher_panics_on_short_out() {
let plane = std::vec![0u8; 8];
let mut out = std::vec![0u16; 4];
y_plane_to_luma_u16_row(&plane, &mut out, 8, true);
}
#[test]
#[should_panic(expected = "plane too short")]
fn dispatcher_panics_on_short_plane_use_simd_false() {
let plane = std::vec![0u8; 4];
let mut out = std::vec![0u16; 8];
y_plane_to_luma_u16_row(&plane, &mut out, 8, false);
}
}