2025-03-31 09:39:28 +02:00
|
|
|
//@ revisions: OPT2 OPT3 OPT3_S390X
|
2025-02-09 16:54:53 -08:00
|
|
|
//@[OPT2] compile-flags: -Copt-level=2
|
|
|
|
//@[OPT3] compile-flags: -C opt-level=3
|
|
|
|
// some targets don't do the opt we are looking for
|
|
|
|
//@[OPT3] only-64bit
|
2025-03-31 09:39:28 +02:00
|
|
|
//@[OPT3] ignore-s390x
|
|
|
|
//@[OPT3_S390X] compile-flags: -C opt-level=3 -C target-cpu=z13
|
|
|
|
//@[OPT3_S390X] only-s390x
|
2024-04-06 22:16:10 +08:00
|
|
|
|
|
|
|
#![crate_type = "lib"]
|
|
|
|
#![no_std]
|
|
|
|
|
|
|
|
// The code is from https://github.com/rust-lang/rust/issues/122805.
|
|
|
|
// Ensure we do not generate the shufflevector instruction
|
|
|
|
// to avoid complicating the code.
|
|
|
|
// CHECK-LABEL: define{{.*}}void @convert(
|
|
|
|
// CHECK-NOT: shufflevector
|
2025-02-09 16:54:53 -08:00
|
|
|
// On higher opt levels, this should just be a bswap:
|
|
|
|
// OPT3: load <8 x i16>
|
|
|
|
// OPT3-NEXT: call <8 x i16> @llvm.bswap
|
|
|
|
// OPT3-NEXT: store <8 x i16>
|
|
|
|
// OPT3-NEXT: ret void
|
2025-03-31 09:39:28 +02:00
|
|
|
// OPT3_S390X: load <8 x i16>
|
|
|
|
// OPT3_S390X-NEXT: call <8 x i16> @llvm.bswap
|
|
|
|
// OPT3_S390X-NEXT: store <8 x i16>
|
|
|
|
// OPT3_S390X-NEXT: ret void
|
2024-04-06 22:16:10 +08:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn convert(value: [u16; 8]) -> [u8; 16] {
|
2024-06-11 10:13:07 +02:00
|
|
|
#[cfg(target_endian = "little")]
|
|
|
|
let bswap = u16::to_be;
|
|
|
|
#[cfg(target_endian = "big")]
|
|
|
|
let bswap = u16::to_le;
|
2024-04-06 22:16:10 +08:00
|
|
|
let addr16 = [
|
2024-06-11 10:13:07 +02:00
|
|
|
bswap(value[0]),
|
|
|
|
bswap(value[1]),
|
|
|
|
bswap(value[2]),
|
|
|
|
bswap(value[3]),
|
|
|
|
bswap(value[4]),
|
|
|
|
bswap(value[5]),
|
|
|
|
bswap(value[6]),
|
|
|
|
bswap(value[7]),
|
2024-04-06 22:16:10 +08:00
|
|
|
];
|
|
|
|
unsafe { core::mem::transmute::<_, [u8; 16]>(addr16) }
|
|
|
|
}
|