Skip to content

Commit

Permalink
Convert panics to aborts
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronKutch committed Dec 19, 2019
1 parent 6573765 commit b03ce24
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/int/sdiv.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 2 additions & 1 deletion src/int/specialized_div_rem/asymmetric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/int/specialized_div_rem/binary_long.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/int/specialized_div_rem/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
13 changes: 6 additions & 7 deletions src/int/specialized_div_rem/trifecta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand All @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion src/int/udiv.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit b03ce24

Please sign in to comment.