Skip to content

Commit

Permalink
Adds conditional byteswapping intrinsics
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
auroranockert committed Jun 17, 2013
1 parent a4cc34f commit bc6848d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/libstd/unstable/intrinsics.rs
Expand Up @@ -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 }

5 comments on commit bc6848d

@bors
Copy link
Contributor

@bors bors commented on bc6848d Jul 6, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from cmr
at auroranockert@bc6848d

@bors
Copy link
Contributor

@bors bors commented on bc6848d Jul 6, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging jensnockert/rust/endian = bc6848d into auto

@bors
Copy link
Contributor

@bors bors commented on bc6848d Jul 6, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jensnockert/rust/endian = bc6848d merged ok, testing candidate = 3e933b1

@bors
Copy link
Contributor

@bors bors commented on bc6848d Jul 6, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 3e933b1

Please sign in to comment.