Skip to content

Upstream, take 2 #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
authors = ["Jorge Aparicio <[email protected]>"]
build = "build.rs"
name = "rustc_builtins"
name = "compiler_builtins"
version = "0.1.0"

[build-dependencies]
Expand Down
9 changes: 8 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,15 @@ fn main() {
sources.remove(&["aeabi_cdcmp", "aeabi_cfcmp"]);
}

let root = if env::var_os("CARGO_FEATURE_RUSTBUILD").is_some() {
Path::new("../../libcompiler_builtins")
} else {
Path::new(".")
};

let src_dir = root.join("compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins");
for src in sources.map.values() {
let src = Path::new("compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins").join(src);
let src = src_dir.join(src);
cfg.file(&src);
println!("cargo:rerun-if-changed={}", src.display());
}
Expand Down
3 changes: 2 additions & 1 deletion src/bin/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#![cfg_attr(thumb, no_main)]
#![deny(dead_code)]
#![feature(asm)]
#![feature(compiler_builtins_lib)]
#![feature(core_float)]
#![feature(lang_items)]
#![feature(libc)]
Expand All @@ -15,7 +16,7 @@

#[cfg(not(thumb))]
extern crate libc;
extern crate rustc_builtins;
extern crate compiler_builtins;

// NOTE cfg(not(thumbv6m)) means that the operation is not supported on ARMv6-M at all. Not even
// compiler-rt provides a C/assembly implementation.
Expand Down
4 changes: 3 additions & 1 deletion src/int/mul.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use int::{Int, LargeInt};
#[cfg(not(all(feature = "c", target_arch = "x86")))]
use int::LargeInt;
use int::Int;

macro_rules! mul {
($intrinsic:ident: $ty:ty) => {
Expand Down
7 changes: 6 additions & 1 deletion src/int/sdiv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ macro_rules! divmod {
fn $div(a: $ty, b: $ty) -> $ty;
}

let r = unsafe { $div(a, b) };
let r = match () {
#[cfg(not(all(feature = "c", any(target_arch = "x86"))))]
() => $div(a, b),
#[cfg(all(feature = "c", any(target_arch = "x86")))]
() => unsafe { $div(a, b) },
};
*rem = a - (r * b);
r
}
Expand Down
1 change: 1 addition & 0 deletions src/int/shift.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(not(all(feature = "c", target_arch = "x86")))]
use int::{Int, LargeInt};

macro_rules! ashl {
Expand Down
20 changes: 17 additions & 3 deletions src/int/udiv.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::{intrinsics, mem};
use core::intrinsics;
use int::{Int, LargeInt};

/// Returns `n / d`
Expand Down Expand Up @@ -65,7 +65,14 @@ pub extern "C" fn __umodsi3(n: u32, d: u32) -> u32 {
fn __udivsi3(n: u32, d: u32) -> u32;
}

n - unsafe { __udivsi3(n, d) * d }
let q = match () {
#[cfg(all(feature = "c", target_arch = "arm", not(target_os = "ios")))]
() => unsafe { __udivsi3(n, d) },
#[cfg(not(all(feature = "c", target_arch = "arm", not(target_os = "ios"))))]
() => __udivsi3(n, d),
};

n - q * d
}

/// Returns `n / d` and sets `*rem = n % d`
Expand All @@ -77,7 +84,12 @@ pub extern "C" fn __udivmodsi4(n: u32, d: u32, rem: Option<&mut u32>) -> u32 {
fn __udivsi3(n: u32, d: u32) -> u32;
}

let q = unsafe { __udivsi3(n, d) };
let q = match () {
#[cfg(all(feature = "c", target_arch = "arm", not(target_os = "ios")))]
() => unsafe { __udivsi3(n, d) },
#[cfg(not(all(feature = "c", target_arch = "arm", not(target_os = "ios"))))]
() => __udivsi3(n, d),
};
if let Some(rem) = rem {
*rem = n - (q * d);
}
Expand All @@ -95,6 +107,8 @@ pub extern "C" fn __udivdi3(n: u64, d: u64) -> u64 {
#[cfg(not(all(feature = "c", target_arch = "x86")))]
#[cfg_attr(not(test), no_mangle)]
pub extern "C" fn __umoddi3(a: u64, b: u64) -> u64 {
use core::mem;

let mut rem = unsafe { mem::uninitialized() };
__udivmoddi4(a, b, Some(&mut rem));
rem
Expand Down
18 changes: 15 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
#![cfg_attr(not(stage0), deny(warnings))]
#![cfg_attr(not(test), no_std)]
#![cfg_attr(rustbuild, compiler_builtins)]
#![crate_name = "compiler_builtins"]
#![crate_type = "rlib"]
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png",
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
html_root_url = "https://doc.rust-lang.org/nightly/",
html_playground_url = "https://play.rust-lang.org/",
test(attr(deny(warnings))))]
#![feature(asm)]
#![feature(compiler_builtins)]
#![feature(core_intrinsics)]
#![feature(linkage)]
#![feature(naked_functions)]
#![cfg_attr(not(test), no_std)]
#![feature(staged_api)]
#![no_builtins]
// TODO(rust-lang/rust#35021) uncomment when that PR lands
// #![feature(rustc_builtins)]
#![unstable(feature = "compiler_builtins_lib",
reason = "Compiler builtins. Will never become stable.",
issue = "0")]

// We disable #[no_mangle] for tests so that we can verify the test results
// against the native compiler-rt implementations of the builtins.
Expand Down