Skip to content

libstd: Resume inlining floating intrinsics #9479

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

Closed
Closed
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
38 changes: 31 additions & 7 deletions src/libstd/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ use to_str;
pub use cmath::c_float_targ_consts::*;

use self::delegated::*;
use self::delegated_intrinsics::*;

macro_rules! delegate(
(
$(
fn $name:ident(
$(
$arg:ident : $arg_ty:ty
),*
$($arg:ident : $arg_ty:ty),*
) -> $rv:ty = $bound_name:path
),*
) => (
Expand All @@ -39,10 +38,9 @@ macro_rules! delegate(
mod delegated {
use cmath::c_float_utils;
use libc::{c_float, c_int};
use unstable::intrinsics;

$(
#[inline] #[fixed_stack_segment] #[inline(never)]
#[fixed_stack_segment] #[inline(never)]
pub fn $name($( $arg : $arg_ty ),*) -> $rv {
unsafe {
$bound_name($( $arg ),*)
Expand All @@ -53,7 +51,31 @@ macro_rules! delegate(
)
)

delegate!(
macro_rules! delegate_intrinsics(
(
$(
fn $name:ident(
$($arg:ident : $arg_ty:ty),*
) -> $rv:ty = $bound_name:path
),*
) => (
// An inner module is required to get the #[inline] attribute on the
// functions.
mod delegated_intrinsics {
use unstable::intrinsics;
use libc::c_int;

$(
#[inline]
pub fn $name($( $arg : $arg_ty ),*) -> $rv {
unsafe { $bound_name($( $arg ),*) }
}
)*
}
)
)

delegate_intrinsics!(
// intrinsics
fn abs(n: f32) -> f32 = intrinsics::fabsf32,
fn cos(n: f32) -> f32 = intrinsics::cosf32,
Expand All @@ -67,8 +89,10 @@ delegate!(
fn pow(n: f32, e: f32) -> f32 = intrinsics::powf32,
fn powi(n: f32, e: c_int) -> f32 = intrinsics::powif32,
fn sin(n: f32) -> f32 = intrinsics::sinf32,
fn sqrt(n: f32) -> f32 = intrinsics::sqrtf32,
fn sqrt(n: f32) -> f32 = intrinsics::sqrtf32
)

delegate!(
// LLVM 3.3 required to use intrinsics for these four
fn ceil(n: c_float) -> c_float = c_float_utils::ceil,
fn trunc(n: c_float) -> c_float = c_float_utils::trunc,
Expand Down
38 changes: 31 additions & 7 deletions src/libstd/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ pub use cmath::c_double_targ_consts::*;
pub use cmp::{min, max};

use self::delegated::*;
use self::delegated_intrinsics::*;

macro_rules! delegate(
(
$(
fn $name:ident(
$(
$arg:ident : $arg_ty:ty
),*
$($arg:ident : $arg_ty:ty),*
) -> $rv:ty = $bound_name:path
),*
) => (
Expand All @@ -41,10 +40,9 @@ macro_rules! delegate(
mod delegated {
use cmath::c_double_utils;
use libc::{c_double, c_int};
use unstable::intrinsics;

$(
#[inline] #[fixed_stack_segment] #[inline(never)]
#[fixed_stack_segment] #[inline(never)]
pub fn $name($( $arg : $arg_ty ),*) -> $rv {
unsafe {
$bound_name($( $arg ),*)
Expand All @@ -55,7 +53,31 @@ macro_rules! delegate(
)
)

delegate!(
macro_rules! delegate_intrinsics(
(
$(
fn $name:ident(
$($arg:ident : $arg_ty:ty),*
) -> $rv:ty = $bound_name:path
),*
) => (
// An inner module is required to get the #[inline] attribute on the
// functions.
mod delegated_intrinsics {
use unstable::intrinsics;
use libc::c_int;

$(
#[inline]
pub fn $name($( $arg : $arg_ty ),*) -> $rv {
unsafe { $bound_name($( $arg ),*) }
}
)*
}
)
)

delegate_intrinsics!(
// intrinsics
fn abs(n: f64) -> f64 = intrinsics::fabsf64,
fn cos(n: f64) -> f64 = intrinsics::cosf64,
Expand All @@ -69,8 +91,10 @@ delegate!(
fn pow(n: f64, e: f64) -> f64 = intrinsics::powf64,
fn powi(n: f64, e: c_int) -> f64 = intrinsics::powif64,
fn sin(n: f64) -> f64 = intrinsics::sinf64,
fn sqrt(n: f64) -> f64 = intrinsics::sqrtf64,
fn sqrt(n: f64) -> f64 = intrinsics::sqrtf64
)

delegate!(
// LLVM 3.3 required to use intrinsics for these four
fn ceil(n: c_double) -> c_double = c_double_utils::ceil,
fn trunc(n: c_double) -> c_double = c_double_utils::trunc,
Expand Down