Debian Codegraph @

third_party/rust/any_all_workaround/src/lib.rs

raw
1 // This code began as a fork of
2 // https://raw.githubusercontent.com/rust-lang/packed_simd/d938e39bee9bc5c222f5f2f2a0df9e53b5ce36ae/src/codegen/reductions/mask/arm.rs
3 // which didn't have a license header on the file, but Cargo.toml said "MIT OR Apache-2.0".
4 // See LICENSE-MIT and LICENSE-APACHE.
5
6 #![no_std]
7 #![feature(portable_simd)]
8 #![cfg_attr(
9 all(
10 stdsimd_split,
11 target_arch = "arm",
12 target_endian = "little",
13 target_feature = "neon",
14 target_feature = "v7"
15 ),
16 feature(stdarch_arm_neon_intrinsics)
17 )]
18 #![cfg_attr(
19 all(
20 not(stdsimd_split),
21 target_arch = "arm",
22 target_endian = "little",
23 target_feature = "neon",
24 target_feature = "v7"
25 ),
26 feature(stdsimd)
27 )]
28
29 use cfg_if::cfg_if;
30 use core::simd::mask16x8;
31 use core::simd::mask32x4;
32 use core::simd::mask8x16;
33
34 cfg_if! {
35 if #[cfg(all(target_arch = "arm", target_endian = "little", target_feature = "neon", target_feature = "v7"))] {
36 use core::simd::mask8x8;
37 use core::simd::mask16x4;
38 use core::simd::mask32x2;
39 macro_rules! arm_128_v7_neon_impl {
40 ($all:ident, $any:ident, $id:ident, $half:ident, $vpmin:ident, $vpmax:ident) => {
41 #[inline]
42 pub fn $all(s: $id) -> bool {
43 use core::arch::arm::$vpmin;
44 use core::mem::transmute;
45 unsafe {
46 union U {
47 halves: ($half, $half),
48 vec: $id,
49 }
50 let halves = U { vec: s }.halves;
51 let h: $half = transmute($vpmin(transmute(halves.0), transmute(halves.1)));
52 h.all()
53 }
54 }
55 #[inline]
56 pub fn $any(s: $id) -> bool {
57 use core::arch::arm::$vpmax;
58 use core::mem::transmute;
59 unsafe {
60 union U {
61 halves: ($half, $half),
62 vec: $id,
63 }
64 let halves = U { vec: s }.halves;
65 let h: $half = transmute($vpmax(transmute(halves.0), transmute(halves.1)));
66 h.any()
67 }
68 }
69 }
70 }
71 } else {
72 macro_rules! arm_128_v7_neon_impl {
73 ($all:ident, $any:ident, $id:ident, $half:ident, $vpmin:ident, $vpmax:ident) => {
74 #[inline(always)]
75 pub fn $all(s: $id) -> bool {
76 s.all()
77 }
78 #[inline(always)]
79 pub fn $any(s: $id) -> bool {
80 s.any()
81 }
82 }
83 }
84 }
85 }
86
87 arm_128_v7_neon_impl!(
88 all_mask8x16,
89 any_mask8x16,
90 mask8x16,
91 mask8x8,
92 vpmin_u8,
93 vpmax_u8
94 );
95 arm_128_v7_neon_impl!(
96 all_mask16x8,
97 any_mask16x8,
98 mask16x8,
99 mask16x4,
100 vpmin_u16,
101 vpmax_u16
102 );
103 arm_128_v7_neon_impl!(
104 all_mask32x4,
105 any_mask32x4,
106 mask32x4,
107 mask32x2,
108 vpmin_u32,
109 vpmax_u32
110 );