File tree 6 files changed +14
-12
lines changed
6 files changed +14
-12
lines changed Original file line number Diff line number Diff line change 1
1
use super :: specialized_div_rem:: * ;
2
2
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
4
4
// is encountered, however these should be unreachable and optimized away unless
5
5
// uses of `std/core::intrinsics::unchecked_div/rem` do not have a 0 check in front
6
6
// of them.
Original file line number Diff line number Diff line change @@ -48,7 +48,8 @@ macro_rules! impl_asymmetric {
48
48
let div_hi = ( div >> n) as $uX;
49
49
if div_hi == 0 {
50
50
if div_lo == 0 {
51
- panic!( "division by zero" ) ;
51
+ // division by zero
52
+ :: abort( ) ;
52
53
}
53
54
if duo_hi < div_lo {
54
55
// 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 {
23
23
) *
24
24
pub fn $unsigned_name( duo: $uX, div: $uX) -> ( $uX, $uX) {
25
25
if div == 0 {
26
- panic!( "division by zero" )
26
+ // division by zero
27
+ :: abort( ) ;
27
28
}
28
29
29
30
// 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 {
38
38
39
39
match ( div_lo == 0 , div_hi == 0 , duo_hi == 0 ) {
40
40
( true , true , _) => {
41
- panic!( "division by zero" )
41
+ // division by zero
42
+ :: abort( ) ;
42
43
}
43
44
( _, false , true ) => {
44
45
// `duo` < `div`
Original file line number Diff line number Diff line change @@ -50,8 +50,12 @@ macro_rules! impl_trifecta {
50
50
51
51
// the number of bits in a $uX
52
52
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
+ }
55
59
56
60
// Note that throughout this function, `lo` and `hi` refer to the high and low `n` bits
57
61
// 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 {
60
64
let div_lz = div. leading_zeros( ) ;
61
65
let mut duo_lz = duo. leading_zeros( ) ;
62
66
63
- // division by zero branch
64
- if div_lz == n_d {
65
- panic!( "division by zero" )
66
- }
67
-
68
67
// the possible ranges of `duo` and `div` at this point:
69
68
// `0 <= duo < 2^n_d`
70
69
// `1 <= div < 2^n_d`
Original file line number Diff line number Diff line change 1
1
use super :: specialized_div_rem:: * ;
2
2
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
4
4
// is encountered, however these should be unreachable and optimized away unless
5
5
// uses of `std/core::intrinsics::unchecked_div/rem` do not have a 0 check in front
6
6
// of them.
You can’t perform that action at this time.
0 commit comments