File: dont-shuffle-bswaps-opt3.rs

package info (click to toggle)
rustc 1.88.0%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 934,168 kB
  • sloc: xml: 158,127; python: 36,062; javascript: 19,855; sh: 19,700; cpp: 18,947; ansic: 12,993; asm: 4,792; makefile: 690; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (40 lines) | stat: -rw-r--r-- 1,094 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//@ revisions: AARCH64 X86_64
//@ compile-flags: -Copt-level=3
//@[AARCH64] only-aarch64
//@[X86_64] only-x86_64

#![crate_type = "lib"]
#![no_std]

// This test is paired with the arch-neutral -opt2.rs test

// 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

// On higher opt levels, this should just be a bswap:
// CHECK: load <8 x i16>
// CHECK-NEXT: call <8 x i16> @llvm.bswap
// CHECK-NEXT: store <8 x i16>
// CHECK-NEXT: ret void
#[no_mangle]
pub fn convert(value: [u16; 8]) -> [u8; 16] {
    #[cfg(target_endian = "little")]
    let bswap = u16::to_be;
    #[cfg(target_endian = "big")]
    let bswap = u16::to_le;
    let addr16 = [
        bswap(value[0]),
        bswap(value[1]),
        bswap(value[2]),
        bswap(value[3]),
        bswap(value[4]),
        bswap(value[5]),
        bswap(value[6]),
        bswap(value[7]),
    ];
    unsafe { core::mem::transmute::<_, [u8; 16]>(addr16) }
}