Skip to content

Remove the need for #[cfg] in #[use_c_shim_if] #293

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 1 commit into from
May 15, 2019
Merged
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
336 changes: 167 additions & 169 deletions build.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ci/run.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set -ex

export CARGO_INCREMENTAL=0
cargo=cargo

# Test our implementation
18 changes: 4 additions & 14 deletions src/float/conv.rs
Original file line number Diff line number Diff line change
@@ -87,11 +87,7 @@ intrinsics! {
int_to_float!(i, i32, f64)
}

#[use_c_shim_if(any(
all(target_arch = "x86", not(target_env = "msvc")),
all(target_arch = "x86_64", not(windows)),
all(target_arch = "x86_64", target_env = "msvc"),
))]
#[maybe_use_optimized_c_shim]
#[arm_aeabi_alias = __aeabi_l2f]
pub extern "C" fn __floatdisf(i: i64) -> f32 {
// On x86_64 LLVM will use native instructions for this conversion, we
@@ -103,7 +99,7 @@ intrinsics! {
}
}

#[use_c_shim_if(all(target_arch = "x86", not(target_env = "msvc")))]
#[maybe_use_optimized_c_shim]
#[arm_aeabi_alias = __aeabi_l2d]
pub extern "C" fn __floatdidf(i: i64) -> f64 {
// On x86_64 LLVM will use native instructions for this conversion, we
@@ -135,19 +131,13 @@ intrinsics! {
int_to_float!(i, u32, f64)
}

#[use_c_shim_if(any(
all(target_arch = "x86", not(target_env = "msvc")),
all(target_arch = "x86_64", not(windows)),
))]
#[maybe_use_optimized_c_shim]
#[arm_aeabi_alias = __aeabi_ul2f]
pub extern "C" fn __floatundisf(i: u64) -> f32 {
int_to_float!(i, u64, f32)
}

#[use_c_shim_if(any(
all(target_arch = "x86", not(target_env = "msvc")),
all(target_arch = "x86_64", not(windows)),
))]
#[maybe_use_optimized_c_shim]
#[arm_aeabi_alias = __aeabi_ul2d]
pub extern "C" fn __floatundidf(i: u64) -> f64 {
int_to_float!(i, u64, f64)
2 changes: 1 addition & 1 deletion src/int/mod.rs
Original file line number Diff line number Diff line change
@@ -302,7 +302,7 @@ impl_wide_int!(u32, u64, 32);
impl_wide_int!(u64, u128, 64);

intrinsics! {
#[use_c_shim_if(/* always if C compilation is enabled */)]
#[maybe_use_optimized_c_shim]
#[cfg(any(
target_pointer_width = "16",
target_pointer_width = "32",
2 changes: 1 addition & 1 deletion src/int/mul.rs
Original file line number Diff line number Diff line change
@@ -84,7 +84,7 @@ trait UMulo: Int {
impl UMulo for u128 {}

intrinsics! {
#[use_c_shim_if(all(target_arch = "x86", not(target_env = "msvc")))]
#[maybe_use_optimized_c_shim]
#[arm_aeabi_alias = __aeabi_lmul]
pub extern "C" fn __muldi3(a: u64, b: u64) -> u64 {
a.mul(b)
14 changes: 5 additions & 9 deletions src/int/sdiv.rs
Original file line number Diff line number Diff line change
@@ -58,13 +58,13 @@ impl Divmod for i32 {}
impl Divmod for i64 {}

intrinsics! {
#[use_c_shim_if(all(target_arch = "arm", not(target_os = "ios"), not(thumb_1)))]
#[maybe_use_optimized_c_shim]
#[arm_aeabi_alias = __aeabi_idiv]
pub extern "C" fn __divsi3(a: i32, b: i32) -> i32 {
a.div(b)
}

#[use_c_shim_if(all(target_arch = "x86", not(target_env = "msvc")))]
#[maybe_use_optimized_c_shim]
pub extern "C" fn __divdi3(a: i64, b: i64) -> i64 {
a.div(b)
}
@@ -74,15 +74,12 @@ intrinsics! {
a.div(b)
}

#[use_c_shim_if(all(target_arch = "arm",
not(target_os = "ios"),
not(target_env = "msvc"),
not(thumb_1)))]
#[maybe_use_optimized_c_shim]
pub extern "C" fn __modsi3(a: i32, b: i32) -> i32 {
a.mod_(b)
}

#[use_c_shim_if(all(target_arch = "x86", not(target_env = "msvc")))]
#[maybe_use_optimized_c_shim]
pub extern "C" fn __moddi3(a: i64, b: i64) -> i64 {
a.mod_(b)
}
@@ -92,8 +89,7 @@ intrinsics! {
a.mod_(b)
}

#[use_c_shim_if(all(target_arch = "arm", not(target_env = "msvc"),
not(target_os = "ios"), not(thumb_1)))]
#[maybe_use_optimized_c_shim]
pub extern "C" fn __divmodsi4(a: i32, b: i32, rem: &mut i32) -> i32 {
a.divmod(b, rem, |a, b| __divsi3(a, b))
}
6 changes: 3 additions & 3 deletions src/int/shift.rs
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@ impl Lshr for u64 {}
impl Lshr for u128 {}

intrinsics! {
#[use_c_shim_if(all(target_arch = "x86", not(target_env = "msvc")))]
#[maybe_use_optimized_c_shim]
#[arm_aeabi_alias = __aeabi_llsl]
pub extern "C" fn __ashldi3(a: u64, b: u32) -> u64 {
a.ashl(b)
@@ -84,7 +84,7 @@ intrinsics! {
a.ashl(b)
}

#[use_c_shim_if(all(target_arch = "x86", not(target_env = "msvc")))]
#[maybe_use_optimized_c_shim]
#[arm_aeabi_alias = __aeabi_lasr]
pub extern "C" fn __ashrdi3(a: i64, b: u32) -> i64 {
a.ashr(b)
@@ -94,7 +94,7 @@ intrinsics! {
a.ashr(b)
}

#[use_c_shim_if(all(target_arch = "x86", not(target_env = "msvc")))]
#[maybe_use_optimized_c_shim]
#[arm_aeabi_alias = __aeabi_llsr]
pub extern "C" fn __lshrdi3(a: u64, b: u32) -> u64 {
a.lshr(b)
18 changes: 5 additions & 13 deletions src/int/udiv.rs
Original file line number Diff line number Diff line change
@@ -152,9 +152,7 @@ macro_rules! udivmod_inner {
}

intrinsics! {
#[use_c_shim_if(all(target_arch = "arm",
not(target_os = "ios"),
not(thumb_1)))]
#[maybe_use_optimized_c_shim]
#[arm_aeabi_alias = __aeabi_uidiv]
/// Returns `n / d`
pub extern "C" fn __udivsi3(n: u32, d: u32) -> u32 {
@@ -212,20 +210,14 @@ intrinsics! {
(q << 1) | carry
}

#[use_c_shim_if(all(target_arch = "arm",
not(target_os = "ios"),
not(target_env = "msvc"),
not(thumb_1)))]
#[maybe_use_optimized_c_shim]
/// Returns `n % d`
pub extern "C" fn __umodsi3(n: u32, d: u32) -> u32 {
let q = __udivsi3(n, d);
n - q * d
}

#[use_c_shim_if(all(target_arch = "arm",
not(target_os = "ios"),
not(target_env = "msvc"),
not(thumb_1)))]
#[maybe_use_optimized_c_shim]
/// Returns `n / d` and sets `*rem = n % d`
pub extern "C" fn __udivmodsi4(n: u32, d: u32, rem: Option<&mut u32>) -> u32 {
let q = __udivsi3(n, d);
@@ -235,13 +227,13 @@ intrinsics! {
q
}

#[use_c_shim_if(all(target_arch = "x86", not(target_env = "msvc")))]
#[maybe_use_optimized_c_shim]
/// Returns `n / d`
pub extern "C" fn __udivdi3(n: u64, d: u64) -> u64 {
__udivmoddi4(n, d, None)
}

#[use_c_shim_if(all(target_arch = "x86", not(target_env = "msvc")))]
#[maybe_use_optimized_c_shim]
/// Returns `n % d`
pub extern "C" fn __umoddi3(n: u64, d: u64) -> u64 {
let mut rem = 0;
23 changes: 11 additions & 12 deletions src/macros.rs
Original file line number Diff line number Diff line change
@@ -30,8 +30,8 @@
///
/// A quick overview of attributes supported right now are:
///
/// * `use_c_shim_if` - takes a #[cfg] directive and falls back to the
/// C-compiled version if `use_c` is specified.
/// * `maybe_use_optimized_c_shim` - indicates that the Rust implementation is
/// ignored if an optimized C version was compiled.
/// * `aapcs_on_arm` - forces the ABI of the function to be `"aapcs"` on ARM and
/// the specified ABI everywhere else.
/// * `unadjusted_on_win64` - like `aapcs_on_arm` this switches to the
@@ -51,15 +51,14 @@ macro_rules! intrinsics {
// to the architecture-specific versions which should be more optimized. The
// purpose of this macro is to easily allow specifying this.
//
// The argument to `use_c_shim_if` is a `#[cfg]` directive which, when true,
// will cause this crate's exported version of `$name` to just redirect to
// the C implementation. No symbol named `$name` will be in the object file
// for this crate itself.
//
// When the `#[cfg]` directive is false, or when the `c` feature is
// disabled, the provided implementation is used instead.
// The `#[maybe_use_optimized_c_shim]` attribute indicates that this
// intrinsic may have an optimized C version. In these situations the build
// script, if the C code is enabled and compiled, will emit a cfg directive
// to get passed to rustc for our compilation. If that cfg is set we skip
// the Rust implementation, but if the attribute is not enabled then we
// compile in the Rust implementation.
(
#[use_c_shim_if($($cfg_clause:tt)*)]
#[maybe_use_optimized_c_shim]
$(#[$($attr:tt)*])*
pub extern $abi:tt fn $name:ident( $($argname:ident: $ty:ty),* ) -> $ret:ty {
$($body:tt)*
@@ -68,7 +67,7 @@ macro_rules! intrinsics {
$($rest:tt)*
) => (

#[cfg(all(use_c, $($cfg_clause)*))]
#[cfg($name = "optimized-c")]
pub extern $abi fn $name( $($argname: $ty),* ) -> $ret {
extern $abi {
fn $name($($argname: $ty),*) -> $ret;
@@ -78,7 +77,7 @@ macro_rules! intrinsics {
}
}

#[cfg(not(all(use_c, $($cfg_clause)*)))]
#[cfg(not($name = "optimized-c"))]
intrinsics! {
$(#[$($attr)*])*
pub extern $abi fn $name( $($argname: $ty),* ) -> $ret {