1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//! Mask reductions implementation for `arm` targets
/// ARM m32x2 v7+neon implementation
macro_rules! arm_m32x2_v7_neon_impl {
($id:ident, $vpmin:ident, $vpmax:ident) => {
impl All for $id {
#[inline]
#[target_feature(enable = "v7,neon")]
unsafe fn all(self) -> bool {
use crate::arch::arm::$vpmin;
use crate::mem::transmute;
// pmin((a, b), (-,-)) => (b, -).0 => b
let tmp: $id =
transmute($vpmin(transmute(self), crate::mem::uninitialized()));
tmp.extract(0)
}
}
impl Any for $id {
#[inline]
#[target_feature(enable = "v7,neon")]
unsafe fn any(self) -> bool {
use crate::arch::arm::$vpmax;
use crate::mem::transmute;
// pmax((a, b), (-,-)) => (b, -).0 => b
let tmp: $id =
transmute($vpmax(transmute(self), crate::mem::uninitialized()));
tmp.extract(0)
}
}
};
}
/// ARM m16x4 v7+neon implementation
macro_rules! arm_m16x4_v7_neon_impl {
($id:ident, $vpmin:ident, $vpmax:ident) => {
impl All for $id {
#[inline]
#[target_feature(enable = "v7,neon")]
unsafe fn all(self) -> bool {
use crate::arch::arm::$vpmin;
use crate::mem::transmute;
// tmp = pmin((a, b, c, d), (-,-,-,-)) => (a, c, -, -)
let tmp = $vpmin(transmute(self), crate::mem::uninitialized());
// tmp = pmin((a, b, -, -), (-,-,-,-)) => (c, -, -, -).0 => c
let tmp: $id = transmute($vpmin(tmp, crate::mem::uninitialized()));
tmp.extract(0)
}
}
impl Any for $id {
#[inline]
#[target_feature(enable = "v7,neon")]
unsafe fn any(self) -> bool {
use crate::arch::arm::$vpmax;
use crate::mem::transmute;
// tmp = pmax((a, b, c, d), (-,-,-,-)) => (a, c, -, -)
let tmp = $vpmax(transmute(self), crate::mem::uninitialized());
// tmp = pmax((a, b, -, -), (-,-,-,-)) => (c, -, -, -).0 => c
let tmp: $id = transmute($vpmax(tmp, crate::mem::uninitialized()));
tmp.extract(0)
}
}
};
}
/// ARM m8x8 v7+neon implementation
macro_rules! arm_m8x8_v7_neon_impl {
($id:ident, $vpmin:ident, $vpmax:ident) => {
impl All for $id {
#[inline]
#[target_feature(enable = "v7,neon")]
unsafe fn all(self) -> bool {
use crate::arch::arm::$vpmin;
use crate::mem::transmute;
// tmp = pmin(
// (a, b, c, d, e, f, g, h),
// (-, -, -, -, -, -, -, -)
// ) => (a, c, e, g, -, -, -, -)
let tmp = $vpmin(transmute(self), crate::mem::uninitialized());
// tmp = pmin(
// (a, c, e, g, -, -, -, -),
// (-, -, -, -, -, -, -, -)
// ) => (c, g, -, -, -, -, -, -)
let tmp = $vpmin(tmp, crate::mem::uninitialized());
// tmp = pmin(
// (c, g, -, -, -, -, -, -),
// (-, -, -, -, -, -, -, -)
// ) => (g, -, -, -, -, -, -, -).0 => g
let tmp: $id = transmute($vpmin(tmp, crate::mem::uninitialized()));
tmp.extract(0)
}
}
impl Any for $id {
#[inline]
#[target_feature(enable = "v7,neon")]
unsafe fn any(self) -> bool {
use crate::arch::arm::$vpmax;
use crate::mem::transmute;
// tmp = pmax(
// (a, b, c, d, e, f, g, h),
// (-, -, -, -, -, -, -, -)
// ) => (a, c, e, g, -, -, -, -)
let tmp = $vpmax(transmute(self), crate::mem::uninitialized());
// tmp = pmax(
// (a, c, e, g, -, -, -, -),
// (-, -, -, -, -, -, -, -)
// ) => (c, g, -, -, -, -, -, -)
let tmp = $vpmax(tmp, crate::mem::uninitialized());
// tmp = pmax(
// (c, g, -, -, -, -, -, -),
// (-, -, -, -, -, -, -, -)
// ) => (g, -, -, -, -, -, -, -).0 => g
let tmp: $id = transmute($vpmax(tmp, crate::mem::uninitialized()));
tmp.extract(0)
}
}
};
}
/// Implementation for ARM + v7 + NEON for 64-bit or 128-bit wide vectors with
/// more than two elements.
macro_rules! arm_128_v7_neon_impl {
($id:ident, $half:ident, $vpmin:ident, $vpmax:ident) => {
impl All for $id {
#[inline]
#[target_feature(enable = "v7,neon")]
unsafe fn all(self) -> bool {
use crate::arch::arm::$vpmin;
use crate::mem::transmute;
union U {
halves: ($half, $half),
vec: $id,
}
let halves = U { vec: self }.halves;
let h: $half = transmute($vpmin(
transmute(halves.0),
transmute(halves.1),
));
h.all()
}
}
impl Any for $id {
#[inline]
#[target_feature(enable = "v7,neon")]
unsafe fn any(self) -> bool {
use crate::arch::arm::$vpmax;
use crate::mem::transmute;
union U {
halves: ($half, $half),
vec: $id,
}
let halves = U { vec: self }.halves;
let h: $half = transmute($vpmax(
transmute(halves.0),
transmute(halves.1),
));
h.any()
}
}
};
}
/// Mask reduction implementation for `arm` targets
macro_rules! impl_mask_reductions {
// 64-bit wide masks
(m8x8) => { arm_m8x8_v7_neon_impl!(m8x8, vpmin_u8, vpmax_u8); };
(m16x4) => { arm_m16x4_v7_neon_impl!(m16x4, vpmin_u16, vpmax_u16); };
(m32x2) => { arm_m32x2_v7_neon_impl!(m32x2, vpmin_u32, vpmax_u32); };
// 128-bit wide masks
(m8x16) => { arm_128_v7_neon_impl!(m8x16, m8x8, vpmin_u8, vpmax_u8); };
(m16x8) => { arm_128_v7_neon_impl!(m16x8, m16x4, vpmin_u16, vpmax_u16); };
(m32x4) => { arm_128_v7_neon_impl!(m32x4, m32x2, vpmin_u32, vpmax_u32); };
// Fallback to LLVM's default code-generation:
($id:ident) => { fallback_impl!($id); };
}