Skip to content

Commit 870712b

Browse files
author
Jorge Aparicio
committed
stop compiling some compiler-rt implementations that have already
been ported to Rust. Being careful of still preferring compiler-rt arch-optimized implementations.
1 parent 310aaa9 commit 870712b

File tree

8 files changed

+60
-25
lines changed

8 files changed

+60
-25
lines changed

build.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,9 @@ fn main() {
101101
let mut sources = Sources::new();
102102
sources.extend(&["absvdi2.c",
103103
"absvsi2.c",
104-
"adddf3.c",
105-
"addsf3.c",
106104
"addvdi3.c",
107105
"addvsi3.c",
108106
"apple_versioning.c",
109-
"ashldi3.c",
110-
"ashrdi3.c",
111107
"clear_cache.c",
112108
"clzdi2.c",
113109
"clzsi2.c",
@@ -118,12 +114,8 @@ fn main() {
118114
"ctzsi2.c",
119115
"divdc3.c",
120116
"divdf3.c",
121-
"divdi3.c",
122-
"divmoddi4.c",
123-
"divmodsi4.c",
124117
"divsc3.c",
125118
"divsf3.c",
126-
"divsi3.c",
127119
"divxc3.c",
128120
"extendsfdf2.c",
129121
"extendhfsf2.c",
@@ -150,14 +142,8 @@ fn main() {
150142
"floatunsidf.c",
151143
"floatunsisf.c",
152144
"int_util.c",
153-
"lshrdi3.c",
154-
"moddi3.c",
155-
"modsi3.c",
156145
"muldc3.c",
157146
"muldf3.c",
158-
"muldi3.c",
159-
"mulodi4.c",
160-
"mulosi4.c",
161147
"muloti4.c",
162148
"mulsc3.c",
163149
"mulsf3.c",
@@ -183,13 +169,7 @@ fn main() {
183169
"truncdfhf2.c",
184170
"truncdfsf2.c",
185171
"truncsfhf2.c",
186-
"ucmpdi2.c",
187-
"udivdi3.c",
188-
"udivmoddi4.c",
189-
"udivmodsi4.c",
190-
"udivsi3.c",
191-
"umoddi3.c",
192-
"umodsi3.c"]);
172+
"ucmpdi2.c"]);
193173

194174
if target_os != "ios" {
195175
sources.extend(&["absvti2.c",

ci/script.sh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ inspect() {
4141
set -e
4242
fi
4343

44-
# verify we haven't drop any intrinsic/symbol
45-
cargo rustc --features c --target $TARGET --bin intrinsics
4644
}
4745

4846
run_tests() {
@@ -56,6 +54,20 @@ run_tests() {
5654
fi
5755
}
5856

57+
c_test() {
58+
$CARGO clean
59+
60+
# verify we haven't drop any intrinsic/symbol
61+
$CARGO build --features c --target $TARGET --bin intrinsics
62+
63+
set +e
64+
# verify that we don't have duplicated symbols when we include symbols from compiler-rt
65+
$PREFIX$NM --defined-only target/$TARGET/debug/librustc_builtins.rlib | sort | uniq -d | grep 'T __'
66+
67+
[[ $? == 0 ]] && exit 1
68+
set -e
69+
}
70+
5971
main() {
6072
if [[ $LINUX && ${IN_DOCKER_CONTAINER:-n} == n ]]; then
6173
# NOTE The Dockerfile of this image is in the docker branch of this repository
@@ -76,6 +88,7 @@ main() {
7688
build
7789
inspect
7890
run_tests
91+
c_test
7992
fi
8093
}
8194

src/arm.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ pub extern "C" fn __aeabi_fadd(a: f32, b: f32) -> f32 {
6868
::float::add::__addsf3(a, b)
6969
}
7070

71+
#[cfg(not(all(feature = "c", target_arch = "arm", not(target_os = "ios"))))]
7172
#[cfg_attr(not(test), no_mangle)]
7273
pub extern "C" fn __aeabi_idiv(a: i32, b: i32) -> i32 {
7374
::int::sdiv::__divsi3(a, b)
@@ -93,6 +94,7 @@ pub extern "C" fn __aeabi_lmul(a: u64, b: u64) -> u64 {
9394
::int::mul::__muldi3(a, b)
9495
}
9596

97+
#[cfg(not(all(feature = "c", target_arch = "arm", not(target_os = "ios"))))]
9698
#[cfg_attr(not(test), no_mangle)]
9799
pub extern "C" fn __aeabi_uidiv(a: u32, b: u32) -> u32 {
98100
::int::udiv::__udivsi3(a, b)

src/int/mul.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ macro_rules! mulo {
6666
}
6767
}
6868

69+
#[cfg(not(all(feature = "c", target_arch = "x86")))]
6970
mul!(__muldi3: u64);
71+
7072
mulo!(__mulosi4: i32);
7173
mulo!(__mulodi4: i64);
7274

src/int/sdiv.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,33 @@ macro_rules! divmod {
3636
/// Returns `a / b` and sets `*rem = n % d`
3737
#[cfg_attr(not(test), no_mangle)]
3838
pub extern "C" fn $intrinsic(a: $ty, b: $ty, rem: &mut $ty) -> $ty {
39-
let r = $div(a, b);
39+
#[cfg(all(feature = "c", any(target_arch = "x86")))]
40+
extern {
41+
fn $div(a: $ty, b: $ty) -> $ty;
42+
}
43+
44+
let r = unsafe { $div(a, b) };
4045
*rem = a - (r * b);
4146
r
4247
}
4348
}
4449
}
4550

51+
#[cfg(not(all(feature = "c", target_arch = "arm", not(target_os = "ios"))))]
4652
div!(__divsi3: i32, u32);
53+
54+
#[cfg(not(all(feature = "c", target_arch = "x86")))]
4755
div!(__divdi3: i64, u64);
56+
57+
#[cfg(not(all(feature = "c", target_arch = "arm", not(target_os = "ios"))))]
4858
mod_!(__modsi3: i32, u32);
59+
60+
#[cfg(not(all(feature = "c", target_arch = "x86")))]
4961
mod_!(__moddi3: i64, u64);
62+
63+
#[cfg(not(all(feature = "c", target_arch = "arm", not(target_os = "ios"))))]
5064
divmod!(__divmodsi4, __divsi3: i32);
65+
5166
divmod!(__divmoddi4, __divdi3: i64);
5267

5368
#[cfg(test)]

src/int/shift.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,13 @@ macro_rules! lshr {
5454
}
5555
}
5656

57+
#[cfg(not(all(feature = "c", target_arch = "x86")))]
5758
ashl!(__ashldi3: u64);
59+
60+
#[cfg(not(all(feature = "c", target_arch = "x86")))]
5861
ashr!(__ashrdi3: i64);
62+
63+
#[cfg(not(all(feature = "c", target_arch = "x86")))]
5964
lshr!(__lshrdi3: u64);
6065

6166
#[cfg(test)]

src/int/udiv.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use core::mem;
22
use int::{Int, LargeInt};
33

44
/// Returns `n / d`
5+
#[cfg(not(all(feature = "c", target_arch = "arm", not(target_os = "ios"))))]
56
#[cfg_attr(not(test), no_mangle)]
67
pub extern "C" fn __udivsi3(n: u32, d: u32) -> u32 {
78
// Special cases
@@ -52,14 +53,26 @@ pub extern "C" fn __udivsi3(n: u32, d: u32) -> u32 {
5253
}
5354

5455
/// Returns `n % d`
56+
#[cfg(not(all(feature = "c", target_arch = "arm", not(target_os = "ios"))))]
5557
#[cfg_attr(not(test), no_mangle)]
5658
pub extern "C" fn __umodsi3(n: u32, d: u32) -> u32 {
57-
n - __udivsi3(n, d) * d
59+
#[cfg(all(feature = "c", target_arch = "arm", not(target_os = "ios")))]
60+
extern {
61+
fn __udivsi3(n: u32, d: u32) -> u32;
62+
}
63+
64+
n - unsafe { __udivsi3(n, d) * d }
5865
}
5966

6067
/// Returns `n / d` and sets `*rem = n % d`
68+
#[cfg(not(all(feature = "c", target_arch = "arm", not(target_os = "ios"))))]
6169
#[cfg_attr(not(test), no_mangle)]
6270
pub extern "C" fn __udivmodsi4(n: u32, d: u32, rem: Option<&mut u32>) -> u32 {
71+
#[cfg(all(feature = "c", target_arch = "arm", not(target_os = "ios")))]
72+
extern {
73+
fn __udivsi3(n: u32, d: u32) -> u32;
74+
}
75+
6376
let q = __udivsi3(n, d);
6477
if let Some(rem) = rem {
6578
*rem = n - (q * d);
@@ -69,11 +82,13 @@ pub extern "C" fn __udivmodsi4(n: u32, d: u32, rem: Option<&mut u32>) -> u32 {
6982

7083
/// Returns `n / d`
7184
#[cfg_attr(not(test), no_mangle)]
85+
#[cfg(not(all(feature = "c", target_arch = "x86")))]
7286
pub extern "C" fn __udivdi3(n: u64, d: u64) -> u64 {
7387
__udivmoddi4(n, d, None)
7488
}
7589

7690
/// Returns `n % d`
91+
#[cfg(not(all(feature = "c", target_arch = "x86")))]
7792
#[cfg_attr(not(test), no_mangle)]
7893
pub extern "C" fn __umoddi3(a: u64, b: u64) -> u64 {
7994
let mut rem = unsafe { mem::uninitialized() };

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
// We disable #[no_mangle] for tests so that we can verify the test results
1111
// against the native compiler-rt implementations of the builtins.
1212

13+
// NOTE cfg(all(feature = "c", ..)) indicate that compiler-rt provides an arch optimized
14+
// implementation of that intrinsic and we'll prefer to use that
15+
1316
#[cfg(test)]
1417
#[macro_use]
1518
extern crate quickcheck;

0 commit comments

Comments
 (0)