Skip to content

Commit 34cd40f

Browse files
author
Jorge Aparicio
committed
get profile.dev (-debug-assertions) + LTO working
1 parent e20c91a commit 34cd40f

File tree

6 files changed

+76
-30
lines changed

6 files changed

+76
-30
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ compiler-rt = { path = "compiler-rt" }
2525
c = []
2626
weak = ["rlibc/weak"]
2727

28-
[workspace]
28+
[profile.dev]
29+
debug-assertions = false
2930

30-
[profile.release]
31-
lto = true
31+
[workspace]

ci/run.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ esac
3333
# Verify that there are no undefined symbols to `panic` within our implementations
3434
case $1 in
3535
thumb*)
36-
xargo build --features c --target $1 --bin intrinsics --release
36+
xargo rustc --features c --target $1 --bin intrinsics -- -C lto
37+
xargo rustc --features c --target $1 --bin intrinsics --release -- -C lto
3738
;;
3839
*)
39-
cargo build --features c --target $1 --bin intrinsics --release
40+
cargo rustc --features c --target $1 --bin intrinsics -- -C lto
41+
cargo rustc --features c --target $1 --bin intrinsics --release -- -C lto
4042
;;
4143
esac
4244

src/float/pow.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
use core::intrinsics;
12

23
macro_rules! pow {
3-
($intrinsic:ident: $fty:ty, $ity:ty) => {
4+
($intrinsic:ident: $fty:ty, $ity:ident) => {
45
/// Returns `a` raised to the power `b`
56
#[cfg_attr(not(test), no_mangle)]
67
pub extern "C" fn $intrinsic(a: $fty, b: $ity) -> $fty {
@@ -11,7 +12,7 @@ macro_rules! pow {
1112
if (b & 1) != 0 {
1213
r *= a;
1314
}
14-
b /= 2;
15+
b = sdiv!($ity, b, 2);
1516
if b == 0 {
1617
break;
1718
}

src/int/sdiv.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@ macro_rules! div {
1313
let b = (b ^ s_b) - s_b;
1414
let s = s_a ^ s_b;
1515

16-
if b == 0 {
17-
unsafe {
18-
intrinsics::abort()
19-
}
20-
}
21-
let r = (a as $uty) / (b as $uty);
16+
let r = udiv!((a as $uty), (b as $uty));
2217
(r as $ty ^ s) - s
2318
}
2419
}
@@ -34,12 +29,7 @@ macro_rules! mod_ {
3429
let s = a >> (<$ty>::bits() - 1);
3530
let a = (a ^ s) - s;
3631

37-
if b == 0 {
38-
unsafe {
39-
intrinsics::abort()
40-
}
41-
}
42-
let r = (a as $uty) % (b as $uty);
32+
let r = urem!((a as $uty), (b as $uty));
4333
(r as $ty ^ s) - s
4434
}
4535
}

src/int/udiv.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,11 @@ pub extern "C" fn __udivmoddi4(n: u64, d: u64, rem: Option<&mut u64>) -> u64 {
109109
// 0 X
110110
// ---
111111
// 0 X
112-
// NOTE This should be unreachable in safe Rust because the program will panic before
113-
// this intrinsic is called
114-
if d.low() == 0 {
115-
unsafe {
116-
intrinsics::abort()
117-
}
118-
}
119112

120113
if let Some(rem) = rem {
121-
*rem = u64::from(n.low() % d.low());
114+
*rem = u64::from(urem!(n.low(), d.low()));
122115
}
123-
return u64::from(n.low() / d.low());
116+
return u64::from(udiv!(n.low(), d.low()));
124117
} else {
125118
// 0 X
126119
// ---
@@ -153,9 +146,9 @@ pub extern "C" fn __udivmoddi4(n: u64, d: u64, rem: Option<&mut u64>) -> u64 {
153146
// ---
154147
// K 0
155148
if let Some(rem) = rem {
156-
*rem = u64::from_parts(0, n.high() % d.high());
149+
*rem = u64::from_parts(0, urem!(n.high(), d.high()));
157150
}
158-
return u64::from(n.high() / d.high());
151+
return u64::from(udiv!(n.high(), d.high()));
159152
}
160153

161154
// K K

src/lib.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,66 @@
1313
// NOTE cfg(all(feature = "c", ..)) indicate that compiler-rt provides an arch optimized
1414
// implementation of that intrinsic and we'll prefer to use that
1515

16+
macro_rules! udiv {
17+
($a:expr, $b:expr) => {
18+
unsafe {
19+
let a = $a;
20+
let b = $b;
21+
22+
if b == 0 {
23+
intrinsics::abort()
24+
} else {
25+
intrinsics::unchecked_div(a, b)
26+
}
27+
}
28+
}
29+
}
30+
31+
macro_rules! sdiv {
32+
($sty:ident, $a:expr, $b:expr) => {
33+
unsafe {
34+
let a = $a;
35+
let b = $b;
36+
37+
if b == 0 || (b == -1 && a == $sty::min_value()) {
38+
intrinsics::abort()
39+
} else {
40+
intrinsics::unchecked_div(a, b)
41+
}
42+
}
43+
}
44+
}
45+
46+
macro_rules! urem {
47+
($a:expr, $b:expr) => {
48+
unsafe {
49+
let a = $a;
50+
let b = $b;
51+
52+
if b == 0 {
53+
intrinsics::abort()
54+
} else {
55+
intrinsics::unchecked_rem(a, b)
56+
}
57+
}
58+
}
59+
}
60+
61+
macro_rules! srem {
62+
($sty:ty, $a:expr, $b:expr) => {
63+
unsafe {
64+
let a = $a;
65+
let b = $b;
66+
67+
if b == 0 || (b == -1 && a == $sty::min_value()) {
68+
intrinsics::abort()
69+
} else {
70+
intrinsics::unchecked_rem(a, b)
71+
}
72+
}
73+
}
74+
}
75+
1676
#[cfg(test)]
1777
#[macro_use]
1878
extern crate quickcheck;

0 commit comments

Comments
 (0)