File tree 1 file changed +4
-10
lines changed
1 file changed +4
-10
lines changed Original file line number Diff line number Diff line change @@ -701,21 +701,15 @@ macro_rules! uniform_simd_int_impl {
701
701
if !( low. simd_le( high) . all( ) ) {
702
702
return Err ( Error :: EmptyRange ) ;
703
703
}
704
- let unsigned_max = Simd :: splat( :: core:: $unsigned:: MAX ) ;
705
704
706
705
// NOTE: all `Simd` operations are inherently wrapping,
707
706
// see https://doc.rust-lang.org/std/simd/struct.Simd.html
708
707
let range: Simd <$unsigned, LANES > = ( ( high - low) + Simd :: splat( 1 ) ) . cast( ) ;
709
- // `% 0` will panic at runtime.
708
+
709
+ // We must avoid divide-by-zero by using 0 % 1 == 0.
710
710
let not_full_range = range. simd_gt( Simd :: splat( 0 ) ) ;
711
- // replacing 0 with `unsigned_max` allows a faster `select`
712
- // with bitwise OR
713
- let modulo = not_full_range. select( range, unsigned_max) ;
714
- // wrapping addition
715
- // TODO: replace with `range.wrapping_neg() % module` when Simd supports this.
716
- let ints_to_reject = ( Simd :: splat( 0 ) - range) % modulo;
717
- // When `range` is 0, `lo` of `v.wmul(range)` will always be
718
- // zero which means only one sample is needed.
711
+ let modulo = not_full_range. select( range, Simd :: splat( 1 ) ) ;
712
+ let ints_to_reject = range. wrapping_neg( ) % modulo;
719
713
720
714
Ok ( UniformInt {
721
715
low,
You can’t perform that action at this time.
0 commit comments