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
#![allow(unused)]
macro_rules! impl_reduction_bitwise {
(
[$elem_ty:ident; $elem_count:expr]:
$id:ident | $ielem_ty:ident | $test_tt:tt |
($convert:expr) |
($true:expr, $false:expr)
) => {
impl $id {
#[inline]
pub fn and(self) -> $elem_ty {
#[cfg(not(target_arch = "aarch64"))]
{
use crate::llvm::simd_reduce_and;
let r: $ielem_ty = unsafe { simd_reduce_and(self.0) };
$convert(r)
}
#[cfg(target_arch = "aarch64")]
{
let mut x = self.extract(0) as $elem_ty;
for i in 1..$id::lanes() {
x &= self.extract(i) as $elem_ty;
}
x
}
}
#[inline]
pub fn or(self) -> $elem_ty {
#[cfg(not(target_arch = "aarch64"))]
{
use crate::llvm::simd_reduce_or;
let r: $ielem_ty = unsafe { simd_reduce_or(self.0) };
$convert(r)
}
#[cfg(target_arch = "aarch64")]
{
let mut x = self.extract(0) as $elem_ty;
for i in 1..$id::lanes() {
x |= self.extract(i) as $elem_ty;
}
x
}
}
#[inline]
pub fn xor(self) -> $elem_ty {
#[cfg(not(target_arch = "aarch64"))]
{
use crate::llvm::simd_reduce_xor;
let r: $ielem_ty = unsafe { simd_reduce_xor(self.0) };
$convert(r)
}
#[cfg(target_arch = "aarch64")]
{
let mut x = self.extract(0) as $elem_ty;
for i in 1..$id::lanes() {
x ^= self.extract(i) as $elem_ty;
}
x
}
}
}
test_if!{
$test_tt:
paste::item! {
pub mod [<$id _reduction_bitwise>] {
use super::*;
#[cfg_attr(not(target_arch = "wasm32"), test)] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn and() {
let v = $id::splat($false);
assert_eq!(v.and(), $false);
let v = $id::splat($true);
assert_eq!(v.and(), $true);
let v = $id::splat($false);
let v = v.replace(0, $true);
if $id::lanes() > 1 {
assert_eq!(v.and(), $false);
} else {
assert_eq!(v.and(), $true);
}
let v = $id::splat($true);
let v = v.replace(0, $false);
assert_eq!(v.and(), $false);
}
#[cfg_attr(not(target_arch = "wasm32"), test)] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn or() {
let v = $id::splat($false);
assert_eq!(v.or(), $false);
let v = $id::splat($true);
assert_eq!(v.or(), $true);
let v = $id::splat($false);
let v = v.replace(0, $true);
assert_eq!(v.or(), $true);
let v = $id::splat($true);
let v = v.replace(0, $false);
if $id::lanes() > 1 {
assert_eq!(v.or(), $true);
} else {
assert_eq!(v.or(), $false);
}
}
#[cfg_attr(not(target_arch = "wasm32"), test)] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn xor() {
let v = $id::splat($false);
assert_eq!(v.xor(), $false);
let v = $id::splat($true);
if $id::lanes() > 1 {
assert_eq!(v.xor(), $false);
} else {
assert_eq!(v.xor(), $true);
}
let v = $id::splat($false);
let v = v.replace(0, $true);
assert_eq!(v.xor(), $true);
let v = $id::splat($true);
let v = v.replace(0, $false);
if $id::lanes() > 1 {
assert_eq!(v.xor(), $true);
} else {
assert_eq!(v.xor(), $false);
}
}
}
}
}
};
}