diff --git a/src/int/sdiv.rs b/src/int/sdiv.rs index c62831d9..fa12d746 100644 --- a/src/int/sdiv.rs +++ b/src/int/sdiv.rs @@ -1,6 +1,6 @@ use super::specialized_div_rem::*; -// NOTE: there are panics inside the specialized_div_rem functions if division by 0 +// NOTE: there are aborts inside the specialized_div_rem functions if division by 0 // is encountered, however these should be unreachable and optimized away unless // uses of `std/core::intrinsics::unchecked_div/rem` do not have a 0 check in front // of them. diff --git a/src/int/specialized_div_rem/asymmetric.rs b/src/int/specialized_div_rem/asymmetric.rs index 9d27b99d..133d8249 100644 --- a/src/int/specialized_div_rem/asymmetric.rs +++ b/src/int/specialized_div_rem/asymmetric.rs @@ -48,7 +48,8 @@ macro_rules! impl_asymmetric { let div_hi = (div >> n) as $uX; if div_hi == 0 { if div_lo == 0 { - panic!("division by zero"); + // division by zero + ::abort(); } if duo_hi < div_lo { // plain $uD by $uX division that will fit into $uX diff --git a/src/int/specialized_div_rem/binary_long.rs b/src/int/specialized_div_rem/binary_long.rs index 7b10e952..dc80b75f 100644 --- a/src/int/specialized_div_rem/binary_long.rs +++ b/src/int/specialized_div_rem/binary_long.rs @@ -23,7 +23,8 @@ macro_rules! impl_binary_long { )* pub fn $unsigned_name(duo: $uX, div: $uX) -> ($uX,$uX) { if div == 0 { - panic!("division by zero") + // division by zero + ::abort(); } // Full $uX binary long division. Use `leading_zeros` on the first round, diff --git a/src/int/specialized_div_rem/delegate.rs b/src/int/specialized_div_rem/delegate.rs index 9206e299..bd6fc117 100644 --- a/src/int/specialized_div_rem/delegate.rs +++ b/src/int/specialized_div_rem/delegate.rs @@ -38,7 +38,8 @@ macro_rules! impl_delegate { match (div_lo == 0, div_hi == 0, duo_hi == 0) { (true, true, _) => { - panic!("division by zero") + // division by zero + ::abort(); } (_,false,true) => { // `duo` < `div` diff --git a/src/int/specialized_div_rem/trifecta.rs b/src/int/specialized_div_rem/trifecta.rs index dec3cc7d..78b6af65 100644 --- a/src/int/specialized_div_rem/trifecta.rs +++ b/src/int/specialized_div_rem/trifecta.rs @@ -50,8 +50,12 @@ macro_rules! impl_trifecta { // the number of bits in a $uX let n = $n_h * 2; - // the number of bits in a $uD - let n_d = n * 2; + + // This should be optimized away because of checks for zero upstream + if div == 0 { + // division by zero + ::abort(); + } // Note that throughout this function, `lo` and `hi` refer to the high and low `n` bits // 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 { let div_lz = div.leading_zeros(); let mut duo_lz = duo.leading_zeros(); - // division by zero branch - if div_lz == n_d { - panic!("division by zero") - } - // the possible ranges of `duo` and `div` at this point: // `0 <= duo < 2^n_d` // `1 <= div < 2^n_d` diff --git a/src/int/udiv.rs b/src/int/udiv.rs index 08905f25..a9415ed4 100644 --- a/src/int/udiv.rs +++ b/src/int/udiv.rs @@ -1,6 +1,6 @@ use super::specialized_div_rem::*; -// NOTE: there are panics inside the specialized_div_rem functions if division by 0 +// NOTE: there are aborts inside the specialized_div_rem functions if division by 0 // is encountered, however these should be unreachable and optimized away unless // uses of `std/core::intrinsics::unchecked_div/rem` do not have a 0 check in front // of them.