Make _bswap{,64} safe

This commit is contained in:
sayantn 2025-08-29 05:30:11 +05:30
parent cfb36829a9
commit 5dcd3046c8
No known key found for this signature in database
GPG key ID: B60412E056614AA4
2 changed files with 6 additions and 10 deletions

View file

@ -10,7 +10,7 @@ use stdarch_test::assert_instr;
#[inline]
#[cfg_attr(test, assert_instr(bswap))]
#[stable(feature = "simd_x86", since = "1.27.0")]
pub unsafe fn _bswap(x: i32) -> i32 {
pub fn _bswap(x: i32) -> i32 {
x.swap_bytes()
}
@ -20,9 +20,7 @@ mod tests {
#[test]
fn test_bswap() {
unsafe {
assert_eq!(_bswap(0x0EADBE0F), 0x0FBEAD0E);
assert_eq!(_bswap(0x00000000), 0x00000000);
}
assert_eq!(_bswap(0x0EADBE0F), 0x0FBEAD0E);
assert_eq!(_bswap(0x00000000), 0x00000000);
}
}

View file

@ -11,7 +11,7 @@ use stdarch_test::assert_instr;
#[inline]
#[cfg_attr(test, assert_instr(bswap))]
#[stable(feature = "simd_x86", since = "1.27.0")]
pub unsafe fn _bswap64(x: i64) -> i64 {
pub fn _bswap64(x: i64) -> i64 {
x.swap_bytes()
}
@ -21,9 +21,7 @@ mod tests {
#[test]
fn test_bswap64() {
unsafe {
assert_eq!(_bswap64(0x0EADBEEFFADECA0E), 0x0ECADEFAEFBEAD0E);
assert_eq!(_bswap64(0x0000000000000000), 0x0000000000000000);
}
assert_eq!(_bswap64(0x0EADBEEFFADECA0E), 0x0ECADEFAEFBEAD0E);
assert_eq!(_bswap64(0x0000000000000000), 0x0000000000000000);
}
}