1 | #![allow (unsafe_code)] |
2 | |
3 | mod neon; |
4 | mod ssse3; |
5 | mod wasm; |
6 | |
7 | #[cfg (any(target_arch = "x86" , target_arch = "x86_64" ))] |
8 | use std::is_x86_feature_detected; |
9 | |
10 | /// Arch-specific implementation of YCbCr conversion. Returns the number of pixels that were |
11 | /// converted. |
12 | #[allow (clippy::type_complexity)] |
13 | pub fn get_color_convert_line_ycbcr() -> Option<unsafe fn(&[u8], &[u8], &[u8], &mut [u8]) -> usize> |
14 | { |
15 | #[cfg (any(target_arch = "x86" , target_arch = "x86_64" ))] |
16 | #[allow (unsafe_code)] |
17 | { |
18 | if is_x86_feature_detected!("ssse3" ) { |
19 | return Some(ssse3::color_convert_line_ycbcr); |
20 | } |
21 | } |
22 | // Runtime detection is not needed on aarch64. |
23 | #[cfg (all(feature = "nightly_aarch64_neon" , target_arch = "aarch64" ))] |
24 | { |
25 | return Some(neon::color_convert_line_ycbcr); |
26 | } |
27 | #[cfg (all(target_feature = "simd128" , target_arch = "wasm32" ))] |
28 | { |
29 | return Some(wasm::color_convert_line_ycbcr); |
30 | } |
31 | #[allow (unreachable_code)] |
32 | None |
33 | } |
34 | |
35 | /// Arch-specific implementation of 8x8 IDCT. |
36 | #[allow (clippy::type_complexity)] |
37 | pub fn get_dequantize_and_idct_block_8x8( |
38 | ) -> Option<unsafe fn(&[i16; 64], &[u16; 64], usize, &mut [u8])> { |
39 | #[cfg (any(target_arch = "x86" , target_arch = "x86_64" ))] |
40 | #[allow (unsafe_code)] |
41 | { |
42 | if is_x86_feature_detected!("ssse3" ) { |
43 | return Some(ssse3::dequantize_and_idct_block_8x8); |
44 | } |
45 | } |
46 | // Runtime detection is not needed on aarch64. |
47 | #[cfg (all(feature = "nightly_aarch64_neon" , target_arch = "aarch64" ))] |
48 | { |
49 | return Some(neon::dequantize_and_idct_block_8x8); |
50 | } |
51 | #[cfg (all(target_feature = "simd128" , target_arch = "wasm32" ))] |
52 | { |
53 | return Some(wasm::dequantize_and_idct_block_8x8); |
54 | } |
55 | #[allow (unreachable_code)] |
56 | None |
57 | } |
58 | |