Skip to content

Commit 675bdcf

Browse files
committed
Created libcore/private/intrinsics.rs, which aims to contain every
rustc intrinsic. Several files in libcore have been changed to use these intrinsics. As of yet, none of the intrinsics are documented.
1 parent b88e4f3 commit 675bdcf

File tree

11 files changed

+168
-89
lines changed

11 files changed

+168
-89
lines changed

src/libcore/at_vec.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ pub extern mod rustrt {
3030
++n: libc::size_t);
3131
}
3232

33-
#[abi = "rust-intrinsic"]
34-
pub extern mod rusti {
35-
pub fn move_val_init<T>(dst: &mut T, -src: T);
36-
}
37-
3833
/// Returns the number of elements the vector can hold without reallocating
3934
#[inline(always)]
4035
pub pure fn capacity<T>(v: @[const T]) -> uint {
@@ -185,9 +180,10 @@ pub mod traits {
185180
pub mod traits {}
186181

187182
pub mod raw {
188-
use at_vec::{capacity, rusti, rustrt};
183+
use at_vec::{capacity, rustrt};
189184
use cast::transmute;
190185
use libc;
186+
use private::intrinsics::{move_val_init};
191187
use ptr::addr_of;
192188
use ptr;
193189
use sys;
@@ -229,7 +225,7 @@ pub mod raw {
229225
(**repr).unboxed.fill += sys::size_of::<T>();
230226
let p = addr_of(&((**repr).unboxed.data));
231227
let p = ptr::offset(p, fill) as *mut T;
232-
rusti::move_val_init(&mut(*p), initval);
228+
move_val_init(&mut(*p), initval);
233229
}
234230

235231
pub unsafe fn push_slow<T>(v: &mut @[const T], initval: T) {

src/libcore/num/f32.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use num::strconv;
1818
use num;
1919
use ops;
2020
use option::Option;
21+
use private::intrinsics::floorf32;
2122
use from_str;
2223
use to_str;
2324

@@ -332,11 +333,6 @@ impl ops::Neg<f32> for f32 {
332333
pure fn neg(&self) -> f32 { -*self }
333334
}
334335

335-
#[abi="rust-intrinsic"]
336-
pub extern {
337-
fn floorf32(val: f32) -> f32;
338-
}
339-
340336
impl num::Round for f32 {
341337
#[inline(always)]
342338
pure fn round(&self, mode: num::RoundMode) -> f32 {

src/libcore/num/f64.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use num::strconv;
1919
use num;
2020
use ops;
2121
use option::Option;
22+
use private::intrinsics::floorf64;
2223
use to_str;
2324
use from_str;
2425

@@ -357,11 +358,6 @@ impl ops::Neg<f64> for f64 {
357358
pure fn neg(&self) -> f64 { -*self }
358359
}
359360

360-
#[abi="rust-intrinsic"]
361-
pub extern {
362-
fn floorf64(val: f64) -> f64;
363-
}
364-
365361
impl num::Round for f64 {
366362
#[inline(always)]
367363
pure fn round(&self, mode: num::RoundMode) -> f64 {

src/libcore/pipes.rs

+7-17
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ use libc;
9292
use option;
9393
use option::{None, Option, Some, unwrap};
9494
use pipes;
95+
use private::intrinsics;
9596
use ptr;
9697
use private;
9798
use task;
@@ -256,37 +257,26 @@ pub fn entangle_buffer<T: Owned, Tstart: Owned>(
256257
(SendPacketBuffered(p), RecvPacketBuffered(p))
257258
}
258259

259-
#[abi = "rust-intrinsic"]
260-
#[doc(hidden)]
261-
extern mod rusti {
262-
fn atomic_xchg(dst: &mut int, src: int) -> int;
263-
fn atomic_xchg_acq(dst: &mut int, src: int) -> int;
264-
fn atomic_xchg_rel(dst: &mut int, src: int) -> int;
265-
266-
fn atomic_xadd_acq(dst: &mut int, src: int) -> int;
267-
fn atomic_xsub_rel(dst: &mut int, src: int) -> int;
268-
}
269-
270260
// If I call the rusti versions directly from a polymorphic function,
271261
// I get link errors. This is a bug that needs investigated more.
272262
#[doc(hidden)]
273263
pub fn atomic_xchng_rel(dst: &mut int, src: int) -> int {
274264
unsafe {
275-
rusti::atomic_xchg_rel(dst, src)
265+
intrinsics::atomic_xchg_rel(dst, src)
276266
}
277267
}
278268

279269
#[doc(hidden)]
280270
pub fn atomic_add_acq(dst: &mut int, src: int) -> int {
281271
unsafe {
282-
rusti::atomic_xadd_acq(dst, src)
272+
intrinsics::atomic_xadd_acq(dst, src)
283273
}
284274
}
285275

286276
#[doc(hidden)]
287277
pub fn atomic_sub_rel(dst: &mut int, src: int) -> int {
288278
unsafe {
289-
rusti::atomic_xsub_rel(dst, src)
279+
intrinsics::atomic_xsub_rel(dst, src)
290280
}
291281
}
292282

@@ -295,7 +285,7 @@ pub fn swap_task(dst: &mut *rust_task, src: *rust_task) -> *rust_task {
295285
// It might be worth making both acquire and release versions of
296286
// this.
297287
unsafe {
298-
transmute(rusti::atomic_xchg(transmute(dst), src as int))
288+
transmute(intrinsics::atomic_xchg(transmute(dst), src as int))
299289
}
300290
}
301291

@@ -335,14 +325,14 @@ fn wait_event(this: *rust_task) -> *libc::c_void {
335325
#[doc(hidden)]
336326
fn swap_state_acq(dst: &mut State, src: State) -> State {
337327
unsafe {
338-
transmute(rusti::atomic_xchg_acq(transmute(dst), src as int))
328+
transmute(intrinsics::atomic_xchg_acq(transmute(dst), src as int))
339329
}
340330
}
341331
342332
#[doc(hidden)]
343333
fn swap_state_rel(dst: &mut State, src: State) -> State {
344334
unsafe {
345-
transmute(rusti::atomic_xchg_rel(transmute(dst), src as int))
335+
transmute(intrinsics::atomic_xchg_rel(transmute(dst), src as int))
346336
}
347337
}
348338

src/libcore/private.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ pub mod finally;
3232
pub mod weak_task;
3333
#[path = "private/exchange_alloc.rs"]
3434
pub mod exchange_alloc;
35+
#[path = "private/intrinsics.rs"]
36+
pub mod intrinsics;
3537

3638
extern mod rustrt {
3739
pub unsafe fn rust_create_little_lock() -> rust_little_lock;
@@ -43,13 +45,6 @@ extern mod rustrt {
4345
pub unsafe fn rust_raw_thread_join_delete(thread: *raw_thread);
4446
}
4547

46-
#[abi = "rust-intrinsic"]
47-
extern mod rusti {
48-
fn atomic_cxchg(dst: &mut int, old: int, src: int) -> int;
49-
fn atomic_xadd(dst: &mut int, src: int) -> int;
50-
fn atomic_xsub(dst: &mut int, src: int) -> int;
51-
}
52-
5348
#[allow(non_camel_case_types)] // runtime type
5449
type raw_thread = libc::c_void;
5550

@@ -101,7 +96,7 @@ fn test_run_in_bare_thread_exchange() {
10196

10297
fn compare_and_swap(address: &mut int, oldval: int, newval: int) -> bool {
10398
unsafe {
104-
let old = rusti::atomic_cxchg(address, oldval, newval);
99+
let old = intrinsics::atomic_cxchg(address, oldval, newval);
105100
old == oldval
106101
}
107102
}
@@ -132,7 +127,7 @@ struct ArcDestruct<T> {
132127
}
133128
do task::unkillable {
134129
let data: ~ArcData<T> = cast::reinterpret_cast(&self.data);
135-
let new_count = rusti::atomic_xsub(&mut data.count, 1) - 1;
130+
let new_count = intrinsics::atomic_xsub(&mut data.count, 1) - 1;
136131
assert new_count >= 0;
137132
if new_count == 0 {
138133
// Were we really last, or should we hand off to an
@@ -205,7 +200,7 @@ pub unsafe fn unwrap_shared_mutable_state<T: Owned>(rc: SharedMutableState<T>)
205200
// Got in. Step 0: Tell destructor not to run. We are now it.
206201
rc.data = ptr::null();
207202
// Step 1 - drop our own reference.
208-
let new_count = rusti::atomic_xsub(&mut ptr.count, 1) - 1;
203+
let new_count = intrinsics::atomic_xsub(&mut ptr.count, 1) - 1;
209204
//assert new_count >= 0;
210205
if new_count == 0 {
211206
// We were the last owner. Can unwrap immediately.
@@ -284,7 +279,7 @@ pub unsafe fn clone_shared_mutable_state<T: Owned>(rc: &SharedMutableState<T>)
284279
-> SharedMutableState<T> {
285280
unsafe {
286281
let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
287-
let new_count = rusti::atomic_xadd(&mut ptr.count, 1) + 1;
282+
let new_count = intrinsics::atomic_xadd(&mut ptr.count, 1) + 1;
288283
assert new_count >= 2;
289284
cast::forget(ptr);
290285
}

src/libcore/private/at_exit.rs

-6
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,6 @@ fn exit_runner(exit_fns: *ExitFunctions) {
7070
}
7171
}
7272

73-
#[abi = "rust-intrinsic"]
74-
pub extern mod rusti {
75-
fn move_val_init<T>(dst: &mut T, -src: T);
76-
fn init<T>() -> T;
77-
}
78-
7973
#[test]
8074
fn test_at_exit() {
8175
let i = 10;

src/libcore/private/exchange_alloc.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use c_malloc = libc::malloc;
1414
use c_free = libc::free;
1515
use managed::raw::{BoxHeaderRepr, BoxRepr};
1616
use cast::transmute;
17+
use private::intrinsics::{atomic_xadd,atomic_xsub};
1718
use ptr::null;
1819
use intrinsic::TyDesc;
1920

@@ -35,15 +36,15 @@ pub unsafe fn malloc(td: *TypeDesc, size: uint) -> *c_void {
3536
box.header.next = null();
3637

3738
let exchange_count = &mut *rust_get_exchange_count_ptr();
38-
rusti::atomic_xadd(exchange_count, 1);
39+
atomic_xadd(exchange_count, 1);
3940

4041
return transmute(box);
4142
}
4243
}
4344

4445
pub unsafe fn free(ptr: *c_void) {
4546
let exchange_count = &mut *rust_get_exchange_count_ptr();
46-
rusti::atomic_xsub(exchange_count, 1);
47+
atomic_xsub(exchange_count, 1);
4748

4849
assert ptr.is_not_null();
4950
c_free(ptr);
@@ -68,8 +69,3 @@ extern {
6869
fn rust_get_exchange_count_ptr() -> *mut int;
6970
}
7071

71-
#[abi = "rust-intrinsic"]
72-
extern mod rusti {
73-
fn atomic_xadd(dst: &mut int, src: int) -> int;
74-
fn atomic_xsub(dst: &mut int, src: int) -> int;
75-
}

src/libcore/private/global.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use private::{Exclusive, exclusive};
3636
use private::{SharedMutableState, shared_mutable_state};
3737
use private::{get_shared_immutable_state};
3838
use private::at_exit::at_exit;
39+
use private::intrinsics::atomic_cxchg;
3940
use hashmap::linear::LinearMap;
4041
use sys::Closure;
4142
use task::spawn;
@@ -231,11 +232,6 @@ extern {
231232
fn rust_get_global_data_ptr() -> *mut int;
232233
}
233234

234-
#[abi = "rust-intrinsic"]
235-
extern {
236-
fn atomic_cxchg(dst: &mut int, old: int, src: int) -> int;
237-
}
238-
239235
#[test]
240236
fn test_clone_rc() {
241237
type MyType = SharedMutableState<int>;

0 commit comments

Comments
 (0)