@@ -77,7 +77,7 @@ macro_rules! int_divrem_guard {
77
77
( $lhs: ident,
78
78
$rhs: ident,
79
79
{ const PANIC_ZERO : & ' static str = $zero: literal;
80
- $simd_call: ident
80
+ $simd_call: ident, $op : tt
81
81
} ,
82
82
$int: ident ) => {
83
83
if $rhs. simd_eq( Simd :: splat( 0 as _) ) . any( ) {
@@ -97,39 +97,15 @@ macro_rules! int_divrem_guard {
97
97
$rhs
98
98
} ;
99
99
100
- // aarch64 fails for arbitrary `v % 0` for non-powers-of-two
100
+ // aarch64 div fails for arbitrary `v % 0`, mod fails when rhs is MIN, for non-powers-of-two
101
+ // these operations aren't vectorized on aarch64 anyway
101
102
#[ cfg( target_arch = "aarch64" ) ]
102
103
{
103
- const { assert!( Self :: LEN <= 64 ) } ;
104
- if Self :: LEN == 1 {
105
- // Safety: $lhs and rhs are vectors
106
- let x: Simd :: <_, 1 > = unsafe { core:: intrinsics:: simd:: $simd_call( $lhs. resize:: <1 >( Default :: default ( ) ) , rhs. resize:: <1 >( Default :: default ( ) ) ) } ;
107
- x. resize( Default :: default ( ) )
108
- } else if Self :: LEN <= 2 {
109
- // Safety: $lhs and rhs are vectors
110
- let x: Simd :: <_, 2 > = unsafe { core:: intrinsics:: simd:: $simd_call( $lhs. resize:: <2 >( Default :: default ( ) ) , rhs. resize:: <2 >( Default :: default ( ) ) ) } ;
111
- x. resize( Default :: default ( ) )
112
- } else if Self :: LEN <= 4 {
113
- // Safety: $lhs and rhs are vectors
114
- let x: Simd :: <_, 4 > = unsafe { core:: intrinsics:: simd:: $simd_call( $lhs. resize:: <4 >( Default :: default ( ) ) , rhs. resize:: <4 >( Default :: default ( ) ) ) } ;
115
- x. resize( Default :: default ( ) )
116
- } else if Self :: LEN <= 8 {
117
- // Safety: $lhs and rhs are vectors
118
- let x: Simd :: <_, 8 > = unsafe { core:: intrinsics:: simd:: $simd_call( $lhs. resize:: <8 >( Default :: default ( ) ) , rhs. resize:: <8 >( Default :: default ( ) ) ) } ;
119
- x. resize( Default :: default ( ) )
120
- } else if Self :: LEN <= 16 {
121
- // Safety: $lhs and rhs are vectors
122
- let x: Simd :: <_, 16 > = unsafe { core:: intrinsics:: simd:: $simd_call( $lhs. resize:: <16 >( Default :: default ( ) ) , rhs. resize:: <16 >( Default :: default ( ) ) ) } ;
123
- x. resize( Default :: default ( ) )
124
- } else if Self :: LEN <= 32 {
125
- // Safety: $lhs and rhs are vectors
126
- let x: Simd :: <_, 32 > = unsafe { core:: intrinsics:: simd:: $simd_call( $lhs. resize:: <32 >( Default :: default ( ) ) , rhs. resize:: <32 >( Default :: default ( ) ) ) } ;
127
- x. resize( Default :: default ( ) )
128
- } else {
129
- // Safety: $lhs and rhs are vectors
130
- let x: Simd :: <_, 64 > = unsafe { core:: intrinsics:: simd:: $simd_call( $lhs. resize:: <64 >( Default :: default ( ) ) , rhs. resize:: <64 >( Default :: default ( ) ) ) } ;
131
- x. resize( Default :: default ( ) )
104
+ let mut out = Simd :: splat( 0 as _) ;
105
+ for i in 0 ..Self :: LEN {
106
+ out[ i] = $lhs[ i] $op rhs[ i] ;
132
107
}
108
+ out
133
109
}
134
110
135
111
#[ cfg( not( target_arch = "aarch64" ) ) ]
@@ -244,14 +220,14 @@ for_base_ops! {
244
220
impl Div :: div {
245
221
int_divrem_guard {
246
222
const PANIC_ZERO : & ' static str = "attempt to divide by zero" ;
247
- simd_div
223
+ simd_div, /
248
224
}
249
225
}
250
226
251
227
impl Rem :: rem {
252
228
int_divrem_guard {
253
229
const PANIC_ZERO : & ' static str = "attempt to calculate the remainder with a divisor of zero" ;
254
- simd_rem
230
+ simd_rem, %
255
231
}
256
232
}
257
233
0 commit comments