about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/cast.rs15
-rw-r--r--src/libstd/ptr.rs48
-rw-r--r--src/libstd/unstable/intrinsics.rs15
3 files changed, 59 insertions, 19 deletions
diff --git a/src/libstd/cast.rs b/src/libstd/cast.rs
index a4f2ee0d09c..05a72dc4109 100644
--- a/src/libstd/cast.rs
+++ b/src/libstd/cast.rs
@@ -13,26 +13,15 @@
 use ptr::RawPtr;
 use mem;
 use unstable::intrinsics;
+use ptr::copy_nonoverlapping_memory;
 
 /// Casts the value at `src` to U. The two types must have the same length.
-#[cfg(target_word_size = "32")]
 #[inline]
 pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
     let mut dest: U = intrinsics::uninit();
     let dest_ptr: *mut u8 = transmute(&mut dest);
     let src_ptr: *u8 = transmute(src);
-    intrinsics::memcpy32(dest_ptr, src_ptr, mem::size_of::<U>() as u32);
-    dest
-}
-
-/// Casts the value at `src` to U. The two types must have the same length.
-#[cfg(target_word_size = "64")]
-#[inline]
-pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
-    let mut dest: U = intrinsics::uninit();
-    let dest_ptr: *mut u8 = transmute(&mut dest);
-    let src_ptr: *u8 = transmute(src);
-    intrinsics::memcpy64(dest_ptr, src_ptr, mem::size_of::<U>() as u64);
+    copy_nonoverlapping_memory(dest_ptr, src_ptr, mem::size_of::<U>());
     dest
 }
 
diff --git a/src/libstd/ptr.rs b/src/libstd/ptr.rs
index 376d178f8f7..65ae9f40403 100644
--- a/src/libstd/ptr.rs
+++ b/src/libstd/ptr.rs
@@ -87,7 +87,7 @@ pub fn is_not_null<T,P:RawPtr<T>>(ptr: P) -> bool { ptr.is_not_null() }
  * and destination may overlap.
  */
 #[inline]
-#[cfg(target_word_size = "32")]
+#[cfg(target_word_size = "32", stage0)]
 pub unsafe fn copy_memory<T,P:RawPtr<T>>(dst: *mut T, src: P, count: uint) {
     intrinsics::memmove32(dst,
                           cast::transmute_immut_unsafe(src),
@@ -101,7 +101,7 @@ pub unsafe fn copy_memory<T,P:RawPtr<T>>(dst: *mut T, src: P, count: uint) {
  * and destination may overlap.
  */
 #[inline]
-#[cfg(target_word_size = "64")]
+#[cfg(target_word_size = "64", stage0)]
 pub unsafe fn copy_memory<T,P:RawPtr<T>>(dst: *mut T, src: P, count: uint) {
     intrinsics::memmove64(dst,
                           cast::transmute_immut_unsafe(src),
@@ -112,10 +112,22 @@ pub unsafe fn copy_memory<T,P:RawPtr<T>>(dst: *mut T, src: P, count: uint) {
  * Copies data from one location to another.
  *
  * Copies `count` elements (not bytes) from `src` to `dst`. The source
+ * and destination may overlap.
+ */
+#[inline]
+#[cfg(not(stage0))]
+pub unsafe fn copy_memory<T,P:RawPtr<T>>(dst: *mut T, src: P, count: uint) {
+    intrinsics::copy_memory(dst, cast::transmute_immut_unsafe(src), count)
+}
+
+/**
+ * Copies data from one location to another.
+ *
+ * Copies `count` elements (not bytes) from `src` to `dst`. The source
  * and destination may *not* overlap.
  */
 #[inline]
-#[cfg(target_word_size = "32")]
+#[cfg(target_word_size = "32", stage0)]
 pub unsafe fn copy_nonoverlapping_memory<T,P:RawPtr<T>>(dst: *mut T,
                                                         src: P,
                                                         count: uint) {
@@ -131,7 +143,7 @@ pub unsafe fn copy_nonoverlapping_memory<T,P:RawPtr<T>>(dst: *mut T,
  * and destination may *not* overlap.
  */
 #[inline]
-#[cfg(target_word_size = "64")]
+#[cfg(target_word_size = "64", stage0)]
 pub unsafe fn copy_nonoverlapping_memory<T,P:RawPtr<T>>(dst: *mut T,
                                                         src: P,
                                                         count: uint) {
@@ -141,11 +153,25 @@ pub unsafe fn copy_nonoverlapping_memory<T,P:RawPtr<T>>(dst: *mut T,
 }
 
 /**
+ * Copies data from one location to another.
+ *
+ * Copies `count` elements (not bytes) from `src` to `dst`. The source
+ * and destination may *not* overlap.
+ */
+#[inline]
+#[cfg(not(stage0))]
+pub unsafe fn copy_nonoverlapping_memory<T,P:RawPtr<T>>(dst: *mut T,
+                                                        src: P,
+                                                        count: uint) {
+    intrinsics::copy_nonoverlapping_memory(dst, cast::transmute_immut_unsafe(src), count)
+}
+
+/**
  * Invokes memset on the specified pointer, setting `count * size_of::<T>()`
  * bytes of memory starting at `dst` to `c`.
  */
 #[inline]
-#[cfg(target_word_size = "32")]
+#[cfg(target_word_size = "32", stage0)]
 pub unsafe fn set_memory<T>(dst: *mut T, c: u8, count: uint) {
     intrinsics::memset32(dst, c, count as u32);
 }
@@ -155,12 +181,22 @@ pub unsafe fn set_memory<T>(dst: *mut T, c: u8, count: uint) {
  * bytes of memory starting at `dst` to `c`.
  */
 #[inline]
-#[cfg(target_word_size = "64")]
+#[cfg(target_word_size = "64", stage0)]
 pub unsafe fn set_memory<T>(dst: *mut T, c: u8, count: uint) {
     intrinsics::memset64(dst, c, count as u64);
 }
 
 /**
+ * Invokes memset on the specified pointer, setting `count * size_of::<T>()`
+ * bytes of memory starting at `dst` to `c`.
+ */
+#[inline]
+#[cfg(not(stage0))]
+pub unsafe fn set_memory<T>(dst: *mut T, c: u8, count: uint) {
+    intrinsics::set_memory(dst, c, count)
+}
+
+/**
  * Zeroes out `count * size_of::<T>` bytes of memory at `dst`
  */
 #[inline]
diff --git a/src/libstd/unstable/intrinsics.rs b/src/libstd/unstable/intrinsics.rs
index 9d3e3446a4b..c086e13d740 100644
--- a/src/libstd/unstable/intrinsics.rs
+++ b/src/libstd/unstable/intrinsics.rs
@@ -345,25 +345,40 @@ extern "rust-intrinsic" {
 
     /// Equivalent to the `llvm.memcpy.p0i8.0i8.i32` intrinsic, with a size of
     /// `count` * `size_of::<T>()` and an alignment of `min_align_of::<T>()`
+    #[cfg(stage0)]
     pub fn memcpy32<T>(dst: *mut T, src: *T, count: u32);
     /// Equivalent to the `llvm.memcpy.p0i8.0i8.i64` intrinsic, with a size of
     /// `count` * `size_of::<T>()` and an alignment of `min_align_of::<T>()`
+    #[cfg(stage0)]
     pub fn memcpy64<T>(dst: *mut T, src: *T, count: u64);
 
     /// Equivalent to the `llvm.memmove.p0i8.0i8.i32` intrinsic, with a size of
     /// `count` * `size_of::<T>()` and an alignment of `min_align_of::<T>()`
+    #[cfg(stage0)]
     pub fn memmove32<T>(dst: *mut T, src: *T, count: u32);
     /// Equivalent to the `llvm.memmove.p0i8.0i8.i64` intrinsic, with a size of
     /// `count` * `size_of::<T>()` and an alignment of `min_align_of::<T>()`
+    #[cfg(stage0)]
     pub fn memmove64<T>(dst: *mut T, src: *T, count: u64);
 
     /// Equivalent to the `llvm.memset.p0i8.i32` intrinsic, with a size of
     /// `count` * `size_of::<T>()` and an alignment of `min_align_of::<T>()`
+    #[cfg(stage0)]
     pub fn memset32<T>(dst: *mut T, val: u8, count: u32);
     /// Equivalent to the `llvm.memset.p0i8.i64` intrinsic, with a size of
     /// `count` * `size_of::<T>()` and an alignment of `min_align_of::<T>()`
+    #[cfg(stage0)]
     pub fn memset64<T>(dst: *mut T, val: u8, count: u64);
 
+    #[cfg(not(stage0))]
+    pub fn copy_nonoverlapping_memory<T>(dst: *mut T, src: *T, count: uint);
+
+    #[cfg(not(stage0))]
+    pub fn copy_memory<T>(dst: *mut T, src: *T, count: uint);
+
+    #[cfg(not(stage0))]
+    pub fn set_memory<T>(dst: *mut T, val: u8, count: uint);
+
     pub fn sqrtf32(x: f32) -> f32;
     pub fn sqrtf64(x: f64) -> f64;