File: swap-simd-types.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 893,396 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (40 lines) | stat: -rw-r--r-- 1,080 bytes parent folder | download | duplicates (2)
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
//@ compile-flags: -O -C target-feature=+avx
//@ only-x86_64

#![crate_type = "lib"]

use std::mem::swap;

// SIMD types are highly-aligned already, so make sure the swap code leaves their
// types alone and doesn't pessimize them (such as by swapping them as `usize`s).
extern crate core;
use core::arch::x86_64::__m256;

// CHECK-LABEL: @swap_single_m256
#[no_mangle]
pub fn swap_single_m256(x: &mut __m256, y: &mut __m256) {
    // CHECK-NOT: alloca
    // CHECK: load <8 x float>{{.+}}align 32
    // CHECK: store <8 x float>{{.+}}align 32
    swap(x, y)
}

// CHECK-LABEL: @swap_m256_slice
#[no_mangle]
pub fn swap_m256_slice(x: &mut [__m256], y: &mut [__m256]) {
    // CHECK-NOT: alloca
    // CHECK: load <8 x float>{{.+}}align 32
    // CHECK: store <8 x float>{{.+}}align 32
    if x.len() == y.len() {
        x.swap_with_slice(y);
    }
}

// CHECK-LABEL: @swap_bytes32
#[no_mangle]
pub fn swap_bytes32(x: &mut [u8; 32], y: &mut [u8; 32]) {
    // CHECK-NOT: alloca
    // CHECK: load <32 x i8>{{.+}}align 1
    // CHECK: store <32 x i8>{{.+}}align 1
    swap(x, y)
}