diff options
| author | bors <bors@rust-lang.org> | 2013-07-06 08:32:10 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-07-06 08:32:10 -0700 |
| commit | 3e933b199c69e1b6c32ecb65bb8f06127cfb8312 (patch) | |
| tree | 8f28a9f7ecf7bd331be9fceade75ddb283831bb1 /src/libstd | |
| parent | e9897cd08a069342c1aae67faa04b119968b44eb (diff) | |
| parent | bc6848d352dd234ffb9c6cb97e2fbcf6c878c8d8 (diff) | |
| download | rust-3e933b199c69e1b6c32ecb65bb8f06127cfb8312.tar.gz rust-3e933b199c69e1b6c32ecb65bb8f06127cfb8312.zip | |
auto merge of #7194 : jensnockert/rust/endian, r=cmr
They simply byte-swap an integer to a specific endian, like the hton* functions in C. 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 I thought they would fit in the intrinsics file. The next step working on this could be to expose a trait / generic function for byteswapping.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/unstable/intrinsics.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libstd/unstable/intrinsics.rs b/src/libstd/unstable/intrinsics.rs index 500143fb577..97e3cba92db 100644 --- a/src/libstd/unstable/intrinsics.rs +++ b/src/libstd/unstable/intrinsics.rs @@ -417,3 +417,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 } |
