about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorJens Nockert <jens@nockert.se>2013-06-17 02:05:36 +0200
committerJens Nockert <jens@nockert.se>2013-06-17 02:05:36 +0200
commitbc6848d352dd234ffb9c6cb97e2fbcf6c878c8d8 (patch)
tree89b87feeb250cfd65085486e8c9d59f5ef53ba7e /src
parenta4cc34fa120cacde411ccdc6b62cc8b6f5f14e24 (diff)
downloadrust-bc6848d352dd234ffb9c6cb97e2fbcf6c878c8d8.tar.gz
rust-bc6848d352dd234ffb9c6cb97e2fbcf6c878c8d8.zip
Adds conditional byteswapping intrinsics
These intrinsics are synthesized, so maybe they should be in another
file. But since they are just a single line of code each, based on the
bswap intrinsics and aren't really intended for public consumption (they should be exposed as a
single function / trait) I thought they would fit here.
Diffstat (limited to 'src')
-rw-r--r--src/libstd/unstable/intrinsics.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libstd/unstable/intrinsics.rs b/src/libstd/unstable/intrinsics.rs
index 908c5e23ab0..599ecc3c465 100644
--- a/src/libstd/unstable/intrinsics.rs
+++ b/src/libstd/unstable/intrinsics.rs
@@ -238,3 +238,17 @@ pub extern "rust-intrinsic" {
     pub fn bswap32(x: i32) -> i32;
     pub fn bswap64(x: i64) -> i64;
 }
+
+#[cfg(target_endian = "little")] pub fn to_le16(x: i16) -> i16 { x }
+#[cfg(target_endian = "big")]    pub fn to_le16(x: i16) -> i16 { unsafe { bswap16(x) } }
+#[cfg(target_endian = "little")] pub fn to_le32(x: i32) -> i32 { x }
+#[cfg(target_endian = "big")]    pub fn to_le32(x: i32) -> i32 { unsafe { bswap32(x) } }
+#[cfg(target_endian = "little")] pub fn to_le64(x: i64) -> i64 { x }
+#[cfg(target_endian = "big")]    pub fn to_le64(x: i64) -> i64 { unsafe { bswap64(x) } }
+
+#[cfg(target_endian = "little")] pub fn to_be16(x: i16) -> i16 { unsafe { bswap16(x) } }
+#[cfg(target_endian = "big")]    pub fn to_be16(x: i16) -> i16 { x }
+#[cfg(target_endian = "little")] pub fn to_be32(x: i32) -> i32 { unsafe { bswap32(x) } }
+#[cfg(target_endian = "big")]    pub fn to_be32(x: i32) -> i32 { x }
+#[cfg(target_endian = "little")] pub fn to_be64(x: i64) -> i64 { unsafe { bswap64(x) } }
+#[cfg(target_endian = "big")]    pub fn to_be64(x: i64) -> i64 { x }