core/stdarch/crates/core_arch/src/x86/
bswap.rs

1//! Byte swap intrinsics.
2#![allow(clippy::module_name_repetitions)]
3
4#[cfg(test)]
5use stdarch_test::assert_instr;
6
7/// Returns an integer with the reversed byte order of x
8///
9/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_bswap)
10#[inline]
11#[cfg_attr(test, assert_instr(bswap))]
12#[stable(feature = "simd_x86", since = "1.27.0")]
13#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
14pub const fn _bswap(x: i32) -> i32 {
15    x.swap_bytes()
16}
17
18#[cfg(test)]
19mod tests {
20    use crate::core_arch::assert_eq_const as assert_eq;
21    use stdarch_test::simd_test;
22
23    use super::*;
24
25    #[simd_test]
26    const fn test_bswap() {
27        assert_eq!(_bswap(0x0EADBE0F), 0x0FBEAD0E);
28        assert_eq!(_bswap(0x00000000), 0x00000000);
29    }
30}