Skip to content

Commit 102092e

Browse files
committed
Remove most intrinsics from the compiler, replacing them with regular calls to them
1 parent 260d74d commit 102092e

File tree

7 files changed

+207
-599
lines changed

7 files changed

+207
-599
lines changed

src/libcore/num/f32.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use num::NumCast;
1616
use num::strconv;
1717
use num;
1818
use option::Option;
19-
use unstable::intrinsics::floorf32;
19+
use unstable::intrinsics;
2020
use from_str;
2121
use to_str;
2222

@@ -93,7 +93,6 @@ delegate!(fn ldexp_radix(n: c_float, i: c_int) -> c_float =
9393
cmath::c_float_utils::ldexp_radix)
9494
delegate!(fn sin(n: c_float) -> c_float = cmath::c_float_utils::sin)
9595
delegate!(fn sinh(n: c_float) -> c_float = cmath::c_float_utils::sinh)
96-
delegate!(fn sqrt(n: c_float) -> c_float = cmath::c_float_utils::sqrt)
9796
delegate!(fn tan(n: c_float) -> c_float = cmath::c_float_utils::tan)
9897
delegate!(fn tanh(n: c_float) -> c_float = cmath::c_float_utils::tanh)
9998
delegate!(fn tgamma(n: c_float) -> c_float = cmath::c_float_utils::tgamma)
@@ -146,7 +145,10 @@ pub fn gt(x: f32, y: f32) -> bool { return x > y; }
146145

147146
/// Returns `x` rounded down
148147
#[inline(always)]
149-
pub fn floor(x: f32) -> f32 { unsafe { floorf32(x) } }
148+
pub fn floor(x: f32) -> f32 { unsafe { intrinsics::llvm::floorf32(x) } }
149+
150+
#[inline(always)]
151+
pub fn sqrt(x: f32) -> f32 { unsafe { intrinsics::llvm::sqrtf32(x) } }
150152

151153
// FIXME (#1999): replace the predicates below with llvm intrinsics or
152154
// calls to the libmath macros in the rust runtime for performance.

src/libcore/num/f64.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use num::NumCast;
1616
use num::strconv;
1717
use num;
1818
use option::Option;
19-
use unstable::intrinsics::floorf64;
19+
use unstable::intrinsics;
2020
use to_str;
2121
use from_str;
2222

@@ -94,7 +94,6 @@ delegate!(fn ldexp_radix(n: c_double, i: c_int) -> c_double =
9494
cmath::c_double_utils::ldexp_radix)
9595
delegate!(fn sin(n: c_double) -> c_double = cmath::c_double_utils::sin)
9696
delegate!(fn sinh(n: c_double) -> c_double = cmath::c_double_utils::sinh)
97-
delegate!(fn sqrt(n: c_double) -> c_double = cmath::c_double_utils::sqrt)
9897
delegate!(fn tan(n: c_double) -> c_double = cmath::c_double_utils::tan)
9998
delegate!(fn tanh(n: c_double) -> c_double = cmath::c_double_utils::tanh)
10099
delegate!(fn tgamma(n: c_double) -> c_double = cmath::c_double_utils::tgamma)
@@ -221,7 +220,10 @@ pub fn is_finite(x: f64) -> bool {
221220

222221
/// Returns `x` rounded down
223222
#[inline(always)]
224-
pub fn floor(x: f64) -> f64 { unsafe { floorf64(x) } }
223+
pub fn floor(x: f64) -> f64 { unsafe { intrinsics::llvm::floorf64(x) } }
224+
225+
#[inline(always)]
226+
pub fn sqrt(x: f64) -> f64 { unsafe { intrinsics::llvm::sqrtf64(x) } }
225227

226228
// FIXME (#1999): add is_normal, is_subnormal, and fpclassify
227229

src/libcore/unstable/intrinsics.rs

Lines changed: 197 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,69 +63,253 @@ pub extern "rust-intrinsic" {
6363

6464
pub fn memmove32(dst: *mut u8, src: *u8, size: u32);
6565
pub fn memmove64(dst: *mut u8, src: *u8, size: u64);
66+
}
6667

68+
#[nolink]
69+
pub extern mod llvm {
70+
#[nomangle]
71+
#[rust_stack]
72+
#[inline(always)]
73+
#[link_name="llvm.sqrt.f32"]
6774
pub fn sqrtf32(x: f32) -> f32;
75+
76+
#[nomangle]
77+
#[rust_stack]
78+
#[inline(always)]
79+
#[link_name="llvm.sqrt.f64"]
6880
pub fn sqrtf64(x: f64) -> f64;
6981

82+
#[nomangle]
83+
#[rust_stack]
84+
#[inline(always)]
85+
#[link_name="llvm.powi.f32"]
7086
pub fn powif32(a: f32, x: i32) -> f32;
87+
88+
#[nomangle]
89+
#[rust_stack]
90+
#[inline(always)]
91+
#[link_name="llvm.powi.f64"]
7192
pub fn powif64(a: f64, x: i32) -> f64;
7293

94+
#[nomangle]
95+
#[rust_stack]
96+
#[inline(always)]
97+
#[link_name="llvm.sin.f32"]
7398
pub fn sinf32(x: f32) -> f32;
99+
100+
#[nomangle]
101+
#[rust_stack]
102+
#[inline(always)]
103+
#[link_name="llvm.sin.f64"]
74104
pub fn sinf64(x: f64) -> f64;
75105

106+
#[nomangle]
107+
#[rust_stack]
108+
#[inline(always)]
109+
#[link_name="llvm.cos.f32"]
76110
pub fn cosf32(x: f32) -> f32;
111+
112+
#[nomangle]
113+
#[rust_stack]
114+
#[inline(always)]
115+
#[link_name="llvm.cos.f64"]
77116
pub fn cosf64(x: f64) -> f64;
78117

118+
#[nomangle]
119+
#[rust_stack]
120+
#[inline(always)]
121+
#[link_name="llvm.pow.f32"]
79122
pub fn powf32(a: f32, x: f32) -> f32;
123+
124+
#[nomangle]
125+
#[rust_stack]
126+
#[inline(always)]
127+
#[link_name="llvm.pow.f64"]
80128
pub fn powf64(a: f64, x: f64) -> f64;
81129

130+
#[nomangle]
131+
#[rust_stack]
132+
#[inline(always)]
133+
#[link_name="llvm.exp.f32"]
82134
pub fn expf32(x: f32) -> f32;
135+
136+
#[nomangle]
137+
#[rust_stack]
138+
#[inline(always)]
139+
#[link_name="llvm.exp.f64"]
83140
pub fn expf64(x: f64) -> f64;
84141

142+
#[nomangle]
143+
#[rust_stack]
144+
#[inline(always)]
145+
#[link_name="llvm.log.f32"]
146+
pub fn logf32(x: f32) -> f32;
147+
148+
#[nomangle]
149+
#[rust_stack]
150+
#[inline(always)]
151+
#[link_name="llvm.log.f64"]
152+
pub fn logf64(x: f64) -> f64;
153+
154+
/* TODO: Do these intrinsics even exist?
85155
pub fn exp2f32(x: f32) -> f32;
86156
pub fn exp2f64(x: f64) -> f64;
87157
88-
pub fn logf32(x: f32) -> f32;
89-
pub fn logf64(x: f64) -> f64;
90158
91159
pub fn log10f32(x: f32) -> f32;
92160
pub fn log10f64(x: f64) -> f64;
93161
94162
pub fn log2f32(x: f32) -> f32;
95163
pub fn log2f64(x: f64) -> f64;
164+
*/
96165

166+
#[nomangle]
167+
#[rust_stack]
168+
#[inline(always)]
169+
#[link_name="llvm.fma.f32"]
97170
pub fn fmaf32(a: f32, b: f32, c: f32) -> f32;
171+
172+
#[nomangle]
173+
#[rust_stack]
174+
#[inline(always)]
175+
#[link_name="llvm.fma.f64"]
98176
pub fn fmaf64(a: f64, b: f64, c: f64) -> f64;
99177

178+
#[nomangle]
179+
#[rust_stack]
180+
#[inline(always)]
181+
#[link_name="llvm.fabs.f32"]
100182
pub fn fabsf32(x: f32) -> f32;
183+
184+
#[nomangle]
185+
#[rust_stack]
186+
#[inline(always)]
187+
#[link_name="llvm.fabs.f64"]
101188
pub fn fabsf64(x: f64) -> f64;
102189

190+
#[nomangle]
191+
#[rust_stack]
192+
#[inline(always)]
193+
#[link_name="llvm.floor.f32"]
103194
pub fn floorf32(x: f32) -> f32;
195+
196+
#[nomangle]
197+
#[rust_stack]
198+
#[inline(always)]
199+
#[link_name="llvm.floor.f64"]
104200
pub fn floorf64(x: f64) -> f64;
105201

202+
/* TODO: Needs LLVM 3.3
203+
#[nomangle]
204+
#[rust_stack]
205+
#[link_name="llvm.ceil.f32"]
106206
pub fn ceilf32(x: f32) -> f32;
207+
208+
#[nomangle]
209+
#[rust_stack]
210+
#[link_name="llvm.ceil.f64"]
107211
pub fn ceilf64(x: f64) -> f64;
108212
213+
#[nomangle]
214+
#[rust_stack]
215+
#[link_name="llvm.trunc.f32"]
109216
pub fn truncf32(x: f32) -> f32;
217+
218+
#[nomangle]
219+
#[rust_stack]
220+
#[link_name="llvm.trunc.f64"]
110221
pub fn truncf64(x: f64) -> f64;
222+
*/
111223

224+
#[nomangle]
225+
#[rust_stack]
226+
#[inline(always)]
227+
#[link_name="llvm.ctpop.i8"]
112228
pub fn ctpop8(x: i8) -> i8;
229+
230+
#[nomangle]
231+
#[rust_stack]
232+
#[inline(always)]
233+
#[link_name="llvm.ctpop.i16"]
113234
pub fn ctpop16(x: i16) -> i16;
114-
pub fn ctpop32(x: i32) -> i32;
115-
pub fn ctpop64(x: i64) -> i64;
116235

117-
pub fn ctlz8(x: i8) -> i8;
118-
pub fn ctlz16(x: i16) -> i16;
119-
pub fn ctlz32(x: i32) -> i32;
120-
pub fn ctlz64(x: i64) -> i64;
236+
#[nomangle]
237+
#[rust_stack]
238+
#[inline(always)]
239+
#[link_name="llvm.ctpop.i32"]
240+
pub fn ctpop32(x: i32) -> i32;
121241

122-
pub fn cttz8(x: i8) -> i8;
123-
pub fn cttz16(x: i16) -> i16;
124-
pub fn cttz32(x: i32) -> i32;
125-
pub fn cttz64(x: i64) -> i64;
242+
#[nomangle]
243+
#[rust_stack]
244+
#[inline(always)]
245+
#[link_name="llvm.ctpop.i64"]
246+
pub fn ctpop64(x: i64) -> i64;
126247

248+
/* TODO: Needs bool constants
249+
#[nomangle]
250+
#[rust_stack]
251+
#[inline(always)]
252+
#[link_name="llvm.ctlz.i8"]
253+
pub fn ctlz8(x: i8, is_zero_undef: bool) -> i8;
254+
255+
#[nomangle]
256+
#[rust_stack]
257+
#[inline(always)]
258+
#[link_name="llvm.ctlz.i16"]
259+
pub fn ctlz16(x: i16, is_zero_undef: bool) -> i16;
260+
261+
#[nomangle]
262+
#[rust_stack]
263+
#[inline(always)]
264+
#[link_name="llvm.ctlz.i32"]
265+
pub fn ctlz32(x: i32, is_zero_undef: bool) -> i32;
266+
267+
#[nomangle]
268+
#[rust_stack]
269+
#[inline(always)]
270+
#[link_name="llvm.ctlz.i64"]
271+
pub fn ctlz64(x: i64, is_zero_undef: bool) -> i64;
272+
273+
#[nomangle]
274+
#[rust_stack]
275+
#[inline(always)]
276+
#[link_name="llvm.cttz.i8"]
277+
pub fn cttz8(x: i8, is_zero_undef: bool) -> i8;
278+
279+
#[nomangle]
280+
#[rust_stack]
281+
#[inline(always)]
282+
#[link_name="llvm.cttz.i16"]
283+
pub fn cttz16(x: i16, is_zero_undef: bool) -> i16;
284+
285+
#[nomangle]
286+
#[rust_stack]
287+
#[inline(always)]
288+
#[link_name="llvm.cttz.i32"]
289+
pub fn cttz32(x: i32, is_zero_undef: bool) -> i32;
290+
291+
#[nomangle]
292+
#[rust_stack]
293+
#[inline(always)]
294+
#[link_name="llvm.cttz.i64"]
295+
pub fn cttz64(x: i64, is_zero_undef: bool) -> i64;
296+
*/
297+
298+
#[nomangle]
299+
#[rust_stack]
300+
#[inline(always)]
301+
#[link_name="llvm.bswap.i16"]
127302
pub fn bswap16(x: i16) -> i16;
303+
304+
#[nomangle]
305+
#[rust_stack]
306+
#[inline(always)]
307+
#[link_name="llvm.bswap.i32"]
128308
pub fn bswap32(x: i32) -> i32;
309+
310+
#[nomangle]
311+
#[rust_stack]
312+
#[inline(always)]
313+
#[link_name="llvm.bswap.i64"]
129314
pub fn bswap64(x: i64) -> i64;
130315
}
131-

0 commit comments

Comments
 (0)