File tree Expand file tree Collapse file tree 6 files changed +14
-12
lines changed Expand file tree Collapse file tree 6 files changed +14
-12
lines changed Original file line number Diff line number Diff line change 11use super :: specialized_div_rem:: * ;
22
3- // NOTE: there are panics inside the specialized_div_rem functions if division by 0
3+ // NOTE: there are aborts inside the specialized_div_rem functions if division by 0
44// is encountered, however these should be unreachable and optimized away unless
55// uses of `std/core::intrinsics::unchecked_div/rem` do not have a 0 check in front
66// of them.
Original file line number Diff line number Diff line change @@ -48,7 +48,8 @@ macro_rules! impl_asymmetric {
4848 let div_hi = ( div >> n) as $uX;
4949 if div_hi == 0 {
5050 if div_lo == 0 {
51- panic!( "division by zero" ) ;
51+ // division by zero
52+ :: abort( ) ;
5253 }
5354 if duo_hi < div_lo {
5455 // plain $uD by $uX division that will fit into $uX
Original file line number Diff line number Diff line change @@ -23,7 +23,8 @@ macro_rules! impl_binary_long {
2323 ) *
2424 pub fn $unsigned_name( duo: $uX, div: $uX) -> ( $uX, $uX) {
2525 if div == 0 {
26- panic!( "division by zero" )
26+ // division by zero
27+ :: abort( ) ;
2728 }
2829
2930 // Full $uX binary long division. Use `leading_zeros` on the first round,
Original file line number Diff line number Diff line change @@ -38,7 +38,8 @@ macro_rules! impl_delegate {
3838
3939 match ( div_lo == 0 , div_hi == 0 , duo_hi == 0 ) {
4040 ( true , true , _) => {
41- panic!( "division by zero" )
41+ // division by zero
42+ :: abort( ) ;
4243 }
4344 ( _, false , true ) => {
4445 // `duo` < `div`
Original file line number Diff line number Diff line change @@ -50,8 +50,12 @@ macro_rules! impl_trifecta {
5050
5151 // the number of bits in a $uX
5252 let n = $n_h * 2 ;
53- // the number of bits in a $uD
54- let n_d = n * 2 ;
53+
54+ // This should be optimized away because of checks for zero upstream
55+ if div == 0 {
56+ // division by zero
57+ :: abort( ) ;
58+ }
5559
5660 // Note that throughout this function, `lo` and `hi` refer to the high and low `n` bits
5761 // of a `$uD`, `0` to `3` refer to the 4 `n_h` bit parts of a `$uD`,
@@ -60,11 +64,6 @@ macro_rules! impl_trifecta {
6064 let div_lz = div. leading_zeros( ) ;
6165 let mut duo_lz = duo. leading_zeros( ) ;
6266
63- // division by zero branch
64- if div_lz == n_d {
65- panic!( "division by zero" )
66- }
67-
6867 // the possible ranges of `duo` and `div` at this point:
6968 // `0 <= duo < 2^n_d`
7069 // `1 <= div < 2^n_d`
Original file line number Diff line number Diff line change 11use super :: specialized_div_rem:: * ;
22
3- // NOTE: there are panics inside the specialized_div_rem functions if division by 0
3+ // NOTE: there are aborts inside the specialized_div_rem functions if division by 0
44// is encountered, however these should be unreachable and optimized away unless
55// uses of `std/core::intrinsics::unchecked_div/rem` do not have a 0 check in front
66// of them.
You can’t perform that action at this time.
0 commit comments