@@ -96,8 +96,33 @@ 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+ const { assert!( Self :: LEN <= 64 ) } ;
102+ if cfg!( not( target_arch = "aarch64" ) ) || Self :: LEN <= 2 {
103+ // Safety: $lhs and rhs are vectors
104+ unsafe { core:: intrinsics:: simd:: $simd_call( $lhs, rhs) }
105+ } else if Self :: LEN <= 4 {
106+ // Safety: $lhs and rhs are vectors
107+ let x: Simd :: <_, 4 > = unsafe { core:: intrinsics:: simd:: $simd_call( $lhs. resize:: <4 >( Default :: default ( ) ) , rhs. resize:: <4 >( Default :: default ( ) ) ) } ;
108+ x. resize( Default :: default ( ) )
109+ } else if Self :: LEN <= 8 {
110+ // Safety: $lhs and rhs are vectors
111+ let x: Simd :: <_, 8 > = unsafe { core:: intrinsics:: simd:: $simd_call( $lhs. resize:: <8 >( Default :: default ( ) ) , rhs. resize:: <8 >( Default :: default ( ) ) ) } ;
112+ x. resize( Default :: default ( ) )
113+ } else if Self :: LEN <= 16 {
114+ // Safety: $lhs and rhs are vectors
115+ let x: Simd :: <_, 16 > = unsafe { core:: intrinsics:: simd:: $simd_call( $lhs. resize:: <16 >( Default :: default ( ) ) , rhs. resize:: <16 >( Default :: default ( ) ) ) } ;
116+ x. resize( Default :: default ( ) )
117+ } else if Self :: LEN <= 32 {
118+ // Safety: $lhs and rhs are vectors
119+ let x: Simd :: <_, 32 > = unsafe { core:: intrinsics:: simd:: $simd_call( $lhs. resize:: <32 >( Default :: default ( ) ) , rhs. resize:: <32 >( Default :: default ( ) ) ) } ;
120+ x. resize( Default :: default ( ) )
121+ } else {
122+ // Safety: $lhs and rhs are vectors
123+ let x: Simd :: <_, 64 > = unsafe { core:: intrinsics:: simd:: $simd_call( $lhs. resize:: <64 >( Default :: default ( ) ) , rhs. resize:: <64 >( Default :: default ( ) ) ) } ;
124+ x. resize( Default :: default ( ) )
125+ }
101126 }
102127 } ;
103128}
0 commit comments