Skip to content

Commit 28d4f80

Browse files
committed
consistently use LLVM floating point intrinsics
1 parent 2760974 commit 28d4f80

File tree

3 files changed

+18
-87
lines changed

3 files changed

+18
-87
lines changed

src/libstd/num/cmath.rs

-57
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,15 @@ pub mod c_double {
2828
pub fn atan(n: c_double) -> c_double;
2929
pub fn atan2(a: c_double, b: c_double) -> c_double;
3030
pub fn cbrt(n: c_double) -> c_double;
31-
pub fn ceil(n: c_double) -> c_double;
32-
pub fn copysign(x: c_double, y: c_double) -> c_double;
33-
pub fn cos(n: c_double) -> c_double;
3431
pub fn cosh(n: c_double) -> c_double;
3532
pub fn erf(n: c_double) -> c_double;
3633
pub fn erfc(n: c_double) -> c_double;
37-
pub fn exp(n: c_double) -> c_double;
3834
// rename: for consistency with underscore usage elsewhere
3935
#[link_name="expm1"]
4036
pub fn exp_m1(n: c_double) -> c_double;
41-
pub fn exp2(n: c_double) -> c_double;
42-
#[link_name="fabs"]
43-
pub fn abs(n: c_double) -> c_double;
4437
// rename: for clarity and consistency with add/sub/mul/div
4538
#[link_name="fdim"]
4639
pub fn abs_sub(a: c_double, b: c_double) -> c_double;
47-
pub fn floor(n: c_double) -> c_double;
48-
// rename: for clarity and consistency with add/sub/mul/div
49-
#[link_name="fma"]
50-
pub fn mul_add(a: c_double, b: c_double, c: c_double) -> c_double;
5140
#[link_name="fmax"]
5241
pub fn fmax(a: c_double, b: c_double) -> c_double;
5342
#[link_name="fmin"]
@@ -63,34 +52,22 @@ pub mod c_double {
6352
#[cfg(windows)]
6453
#[link_name="__lgamma_r"]
6554
pub fn lgamma(n: c_double, sign: &mut c_int) -> c_double;
66-
// renamed: ln seems more natural
67-
#[link_name="log"]
68-
pub fn ln(n: c_double) -> c_double;
6955
// renamed: "logb" /often/ is confused for log2 by beginners
7056
#[link_name="logb"]
7157
pub fn log_radix(n: c_double) -> c_double;
7258
// renamed: to be consitent with log as ln
7359
#[link_name="log1p"]
7460
pub fn ln_1p(n: c_double) -> c_double;
75-
pub fn log10(n: c_double) -> c_double;
76-
pub fn log2(n: c_double) -> c_double;
7761
#[link_name="ilogb"]
7862
pub fn ilog_radix(n: c_double) -> c_int;
7963
pub fn modf(n: c_double, iptr: &mut c_double) -> c_double;
80-
pub fn pow(n: c_double, e: c_double) -> c_double;
81-
// FIXME (#1379): enable when rounding modes become available
82-
// fn rint(n: c_double) -> c_double;
83-
pub fn round(n: c_double) -> c_double;
8464
// rename: for consistency with logradix
8565
#[link_name="scalbn"]
8666
pub fn ldexp_radix(n: c_double, i: c_int) -> c_double;
87-
pub fn sin(n: c_double) -> c_double;
8867
pub fn sinh(n: c_double) -> c_double;
89-
pub fn sqrt(n: c_double) -> c_double;
9068
pub fn tan(n: c_double) -> c_double;
9169
pub fn tanh(n: c_double) -> c_double;
9270
pub fn tgamma(n: c_double) -> c_double;
93-
pub fn trunc(n: c_double) -> c_double;
9471

9572
// These are commonly only available for doubles
9673

@@ -121,34 +98,18 @@ pub mod c_float {
12198
pub fn atan2(a: c_float, b: c_float) -> c_float;
12299
#[link_name="cbrtf"]
123100
pub fn cbrt(n: c_float) -> c_float;
124-
#[link_name="ceilf"]
125-
pub fn ceil(n: c_float) -> c_float;
126-
#[link_name="copysignf"]
127-
pub fn copysign(x: c_float, y: c_float) -> c_float;
128-
#[link_name="cosf"]
129-
pub fn cos(n: c_float) -> c_float;
130101
#[link_name="coshf"]
131102
pub fn cosh(n: c_float) -> c_float;
132103
#[link_name="erff"]
133104
pub fn erf(n: c_float) -> c_float;
134105
#[link_name="erfcf"]
135106
pub fn erfc(n: c_float) -> c_float;
136-
#[link_name="expf"]
137-
pub fn exp(n: c_float) -> c_float;
138107
#[link_name="expm1f"]
139108
pub fn exp_m1(n: c_float) -> c_float;
140-
#[link_name="exp2f"]
141-
pub fn exp2(n: c_float) -> c_float;
142-
#[link_name="fabsf"]
143-
pub fn abs(n: c_float) -> c_float;
144109
#[link_name="fdimf"]
145110
pub fn abs_sub(a: c_float, b: c_float) -> c_float;
146-
#[link_name="floorf"]
147-
pub fn floor(n: c_float) -> c_float;
148111
#[link_name="frexpf"]
149112
pub fn frexp(n: c_float, value: &mut c_int) -> c_float;
150-
#[link_name="fmaf"]
151-
pub fn mul_add(a: c_float, b: c_float, c: c_float) -> c_float;
152113
#[link_name="fmaxf"]
153114
pub fn fmax(a: c_float, b: c_float) -> c_float;
154115
#[link_name="fminf"]
@@ -168,41 +129,23 @@ pub mod c_float {
168129
#[link_name="__lgammaf_r"]
169130
pub fn lgamma(n: c_float, sign: &mut c_int) -> c_float;
170131

171-
#[link_name="logf"]
172-
pub fn ln(n: c_float) -> c_float;
173132
#[link_name="logbf"]
174133
pub fn log_radix(n: c_float) -> c_float;
175134
#[link_name="log1pf"]
176135
pub fn ln_1p(n: c_float) -> c_float;
177-
#[link_name="log2f"]
178-
pub fn log2(n: c_float) -> c_float;
179-
#[link_name="log10f"]
180-
pub fn log10(n: c_float) -> c_float;
181136
#[link_name="ilogbf"]
182137
pub fn ilog_radix(n: c_float) -> c_int;
183138
#[link_name="modff"]
184139
pub fn modf(n: c_float, iptr: &mut c_float) -> c_float;
185-
#[link_name="powf"]
186-
pub fn pow(n: c_float, e: c_float) -> c_float;
187-
// FIXME (#1379): enable when rounding modes become available
188-
// #[link_name="rintf"] fn rint(n: c_float) -> c_float;
189-
#[link_name="roundf"]
190-
pub fn round(n: c_float) -> c_float;
191140
#[link_name="scalbnf"]
192141
pub fn ldexp_radix(n: c_float, i: c_int) -> c_float;
193-
#[link_name="sinf"]
194-
pub fn sin(n: c_float) -> c_float;
195142
#[link_name="sinhf"]
196143
pub fn sinh(n: c_float) -> c_float;
197-
#[link_name="sqrtf"]
198-
pub fn sqrt(n: c_float) -> c_float;
199144
#[link_name="tanf"]
200145
pub fn tan(n: c_float) -> c_float;
201146
#[link_name="tanhf"]
202147
pub fn tanh(n: c_float) -> c_float;
203148
#[link_name="tgammaf"]
204149
pub fn tgamma(n: c_float) -> c_float;
205-
#[link_name="truncf"]
206-
pub fn trunc(n: c_float) -> c_float;
207150
}
208151
}

src/libstd/num/f32.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -46,37 +46,32 @@ macro_rules! delegate(
4646

4747
delegate!(
4848
// intrinsics
49-
fn abs(n: f32) -> f32 = intrinsics::fabsf32,
49+
fn sqrt(n: f32) -> f32 = intrinsics::sqrtf32,
50+
fn powi(n: f32, e: i32) -> f32 = intrinsics::powif32,
51+
fn sin(n: f32) -> f32 = intrinsics::sinf32,
5052
fn cos(n: f32) -> f32 = intrinsics::cosf32,
53+
fn pow(n: f32, e: f32) -> f32 = intrinsics::powf32,
5154
fn exp(n: f32) -> f32 = intrinsics::expf32,
5255
fn exp2(n: f32) -> f32 = intrinsics::exp2f32,
53-
fn floor(x: f32) -> f32 = intrinsics::floorf32,
5456
fn ln(n: f32) -> f32 = intrinsics::logf32,
5557
fn log10(n: f32) -> f32 = intrinsics::log10f32,
5658
fn log2(n: f32) -> f32 = intrinsics::log2f32,
5759
fn mul_add(a: f32, b: f32, c: f32) -> f32 = intrinsics::fmaf32,
58-
fn pow(n: f32, e: f32) -> f32 = intrinsics::powf32,
59-
// fn powi(n: f32, e: c_int) -> f32 = intrinsics::powif32,
60-
fn sin(n: f32) -> f32 = intrinsics::sinf32,
61-
fn sqrt(n: f32) -> f32 = intrinsics::sqrtf32,
62-
63-
// LLVM 3.3 required to use intrinsics for these four
64-
fn ceil(n: c_float) -> c_float = cmath::c_float::ceil,
65-
fn trunc(n: c_float) -> c_float = cmath::c_float::trunc,
66-
/*
60+
fn abs(n: f32) -> f32 = intrinsics::fabsf32,
61+
fn copysign(x: f32, y: f32) -> f32 = intrinsics::copysignf32,
62+
fn floor(x: f32) -> f32 = intrinsics::floorf32,
6763
fn ceil(n: f32) -> f32 = intrinsics::ceilf32,
6864
fn trunc(n: f32) -> f32 = intrinsics::truncf32,
6965
fn rint(n: f32) -> f32 = intrinsics::rintf32,
7066
fn nearbyint(n: f32) -> f32 = intrinsics::nearbyintf32,
71-
*/
67+
fn round(n: f32) -> f32 = intrinsics::roundf32,
7268

7369
// cmath
7470
fn acos(n: c_float) -> c_float = cmath::c_float::acos,
7571
fn asin(n: c_float) -> c_float = cmath::c_float::asin,
7672
fn atan(n: c_float) -> c_float = cmath::c_float::atan,
7773
fn atan2(a: c_float, b: c_float) -> c_float = cmath::c_float::atan2,
7874
fn cbrt(n: c_float) -> c_float = cmath::c_float::cbrt,
79-
fn copysign(x: c_float, y: c_float) -> c_float = cmath::c_float::copysign,
8075
fn cosh(n: c_float) -> c_float = cmath::c_float::cosh,
8176
// fn erf(n: c_float) -> c_float = cmath::c_float::erf,
8277
// fn erfc(n: c_float) -> c_float = cmath::c_float::erfc,
@@ -90,7 +85,6 @@ delegate!(
9085
fn ln_1p(n: c_float) -> c_float = cmath::c_float::ln_1p,
9186
// fn ilog_radix(n: c_float) -> c_int = cmath::c_float::ilog_radix,
9287
// fn modf(n: c_float, iptr: &mut c_float) -> c_float = cmath::c_float::modf,
93-
fn round(n: c_float) -> c_float = cmath::c_float::round,
9488
// fn ldexp_radix(n: c_float, i: c_int) -> c_float = cmath::c_float::ldexp_radix,
9589
fn sinh(n: c_float) -> c_float = cmath::c_float::sinh,
9690
fn tan(n: c_float) -> c_float = cmath::c_float::tan,

src/libstd/num/f64.rs

+10-16
Original file line numberDiff line numberDiff line change
@@ -46,37 +46,32 @@ macro_rules! delegate(
4646

4747
delegate!(
4848
// intrinsics
49-
fn abs(n: f64) -> f64 = intrinsics::fabsf64,
49+
fn sqrt(n: f64) -> f64 = intrinsics::sqrtf64,
50+
fn powi(n: f64, e: i32) -> f64 = intrinsics::powif64,
51+
fn sin(n: f64) -> f64 = intrinsics::sinf64,
5052
fn cos(n: f64) -> f64 = intrinsics::cosf64,
53+
fn pow(n: f64, e: f64) -> f64 = intrinsics::powf64,
5154
fn exp(n: f64) -> f64 = intrinsics::expf64,
5255
fn exp2(n: f64) -> f64 = intrinsics::exp2f64,
53-
fn floor(x: f64) -> f64 = intrinsics::floorf64,
5456
fn ln(n: f64) -> f64 = intrinsics::logf64,
5557
fn log10(n: f64) -> f64 = intrinsics::log10f64,
5658
fn log2(n: f64) -> f64 = intrinsics::log2f64,
5759
fn mul_add(a: f64, b: f64, c: f64) -> f64 = intrinsics::fmaf64,
58-
fn pow(n: f64, e: f64) -> f64 = intrinsics::powf64,
59-
// fn powi(n: f64, e: c_int) -> f64 = intrinsics::powif64,
60-
fn sin(n: f64) -> f64 = intrinsics::sinf64,
61-
fn sqrt(n: f64) -> f64 = intrinsics::sqrtf64,
62-
63-
// LLVM 3.3 required to use intrinsics for these four
64-
fn ceil(n: c_double) -> c_double = cmath::c_double::ceil,
65-
fn trunc(n: c_double) -> c_double = cmath::c_double::trunc,
66-
/*
60+
fn abs(n: f64) -> f64 = intrinsics::fabsf64,
61+
fn copysign(x: f64, y: f64) -> f64 = intrinsics::copysignf64,
62+
fn floor(x: f64) -> f64 = intrinsics::floorf64,
6763
fn ceil(n: f64) -> f64 = intrinsics::ceilf64,
6864
fn trunc(n: f64) -> f64 = intrinsics::truncf64,
69-
fn rint(n: c_double) -> c_double = intrinsics::rintf64,
70-
fn nearbyint(n: c_double) -> c_double = intrinsics::nearbyintf64,
71-
*/
65+
fn rint(n: f64) -> f64 = intrinsics::rintf64,
66+
fn nearbyint(n: f64) -> f64 = intrinsics::nearbyintf64,
67+
fn round(n: f64) -> f64 = intrinsics::roundf64,
7268

7369
// cmath
7470
fn acos(n: c_double) -> c_double = cmath::c_double::acos,
7571
fn asin(n: c_double) -> c_double = cmath::c_double::asin,
7672
fn atan(n: c_double) -> c_double = cmath::c_double::atan,
7773
fn atan2(a: c_double, b: c_double) -> c_double = cmath::c_double::atan2,
7874
fn cbrt(n: c_double) -> c_double = cmath::c_double::cbrt,
79-
fn copysign(x: c_double, y: c_double) -> c_double = cmath::c_double::copysign,
8075
fn cosh(n: c_double) -> c_double = cmath::c_double::cosh,
8176
// fn erf(n: c_double) -> c_double = cmath::c_double::erf,
8277
// fn erfc(n: c_double) -> c_double = cmath::c_double::erfc,
@@ -90,7 +85,6 @@ delegate!(
9085
fn ln_1p(n: c_double) -> c_double = cmath::c_double::ln_1p,
9186
// fn ilog_radix(n: c_double) -> c_int = cmath::c_double::ilog_radix,
9287
// fn modf(n: c_double, iptr: &mut c_double) -> c_double = cmath::c_double::modf,
93-
fn round(n: c_double) -> c_double = cmath::c_double::round,
9488
// fn ldexp_radix(n: c_double, i: c_int) -> c_double = cmath::c_double::ldexp_radix,
9589
fn sinh(n: c_double) -> c_double = cmath::c_double::sinh,
9690
fn tan(n: c_double) -> c_double = cmath::c_double::tan,

0 commit comments

Comments
 (0)