]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/swap-small-types.rs
rustdoc: Early doc link resolution fixes and refactorings
[rust.git] / src / test / codegen / swap-small-types.rs
1 // compile-flags: -O
2 // only-x86_64
3 // ignore-debug: the debug assertions get in the way
4
5 #![crate_type = "lib"]
6
7 use std::mem::swap;
8
9 type RGB48 = [u16; 3];
10
11 // CHECK-LABEL: @swap_rgb48
12 #[no_mangle]
13 pub fn swap_rgb48(x: &mut RGB48, y: &mut RGB48) {
14 // CHECK-NOT: alloca
15 // CHECK: load i48
16 // CHECK: store i48
17     swap(x, y)
18 }
19
20 // LLVM doesn't vectorize a loop over 3-byte elements,
21 // so we chunk it down to bytes and loop over those instead.
22 type RGB24 = [u8; 3];
23
24 // CHECK-LABEL: @swap_rgb24_slices
25 #[no_mangle]
26 pub fn swap_rgb24_slices(x: &mut [RGB24], y: &mut [RGB24]) {
27 // CHECK-NOT: alloca
28 // CHECK: load <{{[0-9]+}} x i8>
29 // CHECK: store <{{[0-9]+}} x i8>
30     if x.len() == y.len() {
31         x.swap_with_slice(y);
32     }
33 }
34
35 // This one has a power-of-two size, so we iterate over it directly
36 type RGBA32 = [u8; 4];
37
38 // CHECK-LABEL: @swap_rgba32_slices
39 #[no_mangle]
40 pub fn swap_rgba32_slices(x: &mut [RGBA32], y: &mut [RGBA32]) {
41 // CHECK-NOT: alloca
42 // CHECK: load <{{[0-9]+}} x i32>
43 // CHECK: store <{{[0-9]+}} x i32>
44     if x.len() == y.len() {
45         x.swap_with_slice(y);
46     }
47 }
48
49 // Strings have a non-power-of-two size, but have pointer alignment,
50 // so we swap usizes instead of dropping all the way down to bytes.
51 const _: () = assert!(!std::mem::size_of::<String>().is_power_of_two());
52
53 // CHECK-LABEL: @swap_string_slices
54 #[no_mangle]
55 pub fn swap_string_slices(x: &mut [String], y: &mut [String]) {
56 // CHECK-NOT: alloca
57 // CHECK: load <{{[0-9]+}} x i64>
58 // CHECK: store <{{[0-9]+}} x i64>
59     if x.len() == y.len() {
60         x.swap_with_slice(y);
61     }
62 }