Add byteswap intrinsics for converting from big/little to host endian
These are similar to the ntoh[s|l] functions in C and have the style of from_[be|le][16|32|64].
This commit is contained in:
parent
c34ef5d7e4
commit
3abc633658
1 changed files with 13 additions and 0 deletions
|
|
@ -500,6 +500,19 @@ extern "rust-intrinsic" {
|
|||
#[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 }
|
||||
|
||||
#[cfg(target_endian = "little")] pub fn from_le16(x: i16) -> i16 { x }
|
||||
#[cfg(target_endian = "big")] pub fn from_le16(x: i16) -> i16 { unsafe { bswap16(x) } }
|
||||
#[cfg(target_endian = "little")] pub fn from_le32(x: i32) -> i32 { x }
|
||||
#[cfg(target_endian = "big")] pub fn from_le32(x: i32) -> i32 { unsafe { bswap32(x) } }
|
||||
#[cfg(target_endian = "little")] pub fn from_le64(x: i64) -> i64 { x }
|
||||
#[cfg(target_endian = "big")] pub fn from_le64(x: i64) -> i64 { unsafe { bswap64(x) } }
|
||||
|
||||
#[cfg(target_endian = "little")] pub fn from_be16(x: i16) -> i16 { unsafe { bswap16(x) } }
|
||||
#[cfg(target_endian = "big")] pub fn from_be16(x: i16) -> i16 { x }
|
||||
#[cfg(target_endian = "little")] pub fn from_be32(x: i32) -> i32 { unsafe { bswap32(x) } }
|
||||
#[cfg(target_endian = "big")] pub fn from_be32(x: i32) -> i32 { x }
|
||||
#[cfg(target_endian = "little")] pub fn from_be64(x: i64) -> i64 { unsafe { bswap64(x) } }
|
||||
#[cfg(target_endian = "big")] pub fn from_be64(x: i64) -> i64 { x }
|
||||
|
||||
/// `TypeId` represents a globally unique identifier for a type
|
||||
#[lang="type_id"] // This needs to be kept in lockstep with the code in trans/intrinsic.rs and
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue