@@ -96,8 +96,47 @@ macro_rules! int_divrem_guard {
9696 // Nice base case to make it easy to const-fold away the other branch.
9797 $rhs
9898 } ;
99- // Safety: $lhs and rhs are vectors
100- unsafe { core:: intrinsics:: simd:: $simd_call( $lhs, rhs) }
99+
100+ // aarch64 fails for arbitrary `v % 0` for non-powers-of-two
101+ #[ cfg( target_arch = "aarch64" ) ]
102+ {
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 ( ) )
132+ }
133+ }
134+
135+ #[ cfg( not( target_arch = "aarch64" ) ) ]
136+ {
137+ // Safety: $lhs and rhs are vectors
138+ unsafe { core:: intrinsics:: simd:: $simd_call( $lhs, rhs) }
139+ }
101140 }
102141 } ;
103142}
0 commit comments