Skip to content

Commit 8336740

Browse files
committed
Make _bswap{,64} safe
1 parent 6db8109 commit 8336740

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

crates/core_arch/src/x86/bswap.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use stdarch_test::assert_instr;
1010
#[inline]
1111
#[cfg_attr(test, assert_instr(bswap))]
1212
#[stable(feature = "simd_x86", since = "1.27.0")]
13-
pub unsafe fn _bswap(x: i32) -> i32 {
13+
pub fn _bswap(x: i32) -> i32 {
1414
x.swap_bytes()
1515
}
1616

@@ -20,9 +20,7 @@ mod tests {
2020

2121
#[test]
2222
fn test_bswap() {
23-
unsafe {
24-
assert_eq!(_bswap(0x0EADBE0F), 0x0FBEAD0E);
25-
assert_eq!(_bswap(0x00000000), 0x00000000);
26-
}
23+
assert_eq!(_bswap(0x0EADBE0F), 0x0FBEAD0E);
24+
assert_eq!(_bswap(0x00000000), 0x00000000);
2725
}
2826
}

crates/core_arch/src/x86_64/bswap.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use stdarch_test::assert_instr;
1111
#[inline]
1212
#[cfg_attr(test, assert_instr(bswap))]
1313
#[stable(feature = "simd_x86", since = "1.27.0")]
14-
pub unsafe fn _bswap64(x: i64) -> i64 {
14+
pub fn _bswap64(x: i64) -> i64 {
1515
x.swap_bytes()
1616
}
1717

@@ -21,9 +21,7 @@ mod tests {
2121

2222
#[test]
2323
fn test_bswap64() {
24-
unsafe {
25-
assert_eq!(_bswap64(0x0EADBEEFFADECA0E), 0x0ECADEFAEFBEAD0E);
26-
assert_eq!(_bswap64(0x0000000000000000), 0x0000000000000000);
27-
}
24+
assert_eq!(_bswap64(0x0EADBEEFFADECA0E), 0x0ECADEFAEFBEAD0E);
25+
assert_eq!(_bswap64(0x0000000000000000), 0x0000000000000000);
2826
}
2927
}

0 commit comments

Comments
 (0)