Skip to content

Commit b03ce24

Browse files
committed
Convert panics to aborts
1 parent 6573765 commit b03ce24

File tree

6 files changed

+14
-12
lines changed

6 files changed

+14
-12
lines changed

src/int/sdiv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use 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.

src/int/specialized_div_rem/asymmetric.rs

+2-1
Original file line numberDiff line numberDiff 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

src/int/specialized_div_rem/binary_long.rs

+2-1
Original file line numberDiff line numberDiff 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,

src/int/specialized_div_rem/delegate.rs

+2-1
Original file line numberDiff line numberDiff 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`

src/int/specialized_div_rem/trifecta.rs

+6-7
Original file line numberDiff line numberDiff 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`

src/int/udiv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use 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.

0 commit comments

Comments
 (0)