]> git.lizzy.rs Git - rust.git/blob - src/test/run-make-fulldeps/simd-ffi/simd.rs
Rollup merge of #62734 - GuillaumeGomez:hide-default-methods, r=Mark-Simulacrum
[rust.git] / src / test / run-make-fulldeps / simd-ffi / simd.rs
1 // ensures that public symbols are not removed completely
2 #![crate_type = "lib"]
3 // we can compile to a variety of platforms, because we don't need
4 // cross-compiled standard libraries.
5 #![feature(no_core, optin_builtin_traits)]
6 #![no_core]
7
8 #![feature(repr_simd, simd_ffi, link_llvm_intrinsics, lang_items, rustc_attrs)]
9
10
11 #[repr(C)]
12 #[derive(Copy)]
13 #[repr(simd)]
14 pub struct f32x4(f32, f32, f32, f32);
15
16
17 extern {
18     #[link_name = "llvm.sqrt.v4f32"]
19     fn vsqrt(x: f32x4) -> f32x4;
20 }
21
22 pub fn foo(x: f32x4) -> f32x4 {
23     unsafe {vsqrt(x)}
24 }
25
26 #[repr(C)]
27 #[derive(Copy)]
28 #[repr(simd)]
29 pub struct i32x4(i32, i32, i32, i32);
30
31
32 extern {
33     // _mm_sll_epi32
34     #[cfg(any(target_arch = "x86",
35               target_arch = "x86-64"))]
36     #[link_name = "llvm.x86.sse2.psll.d"]
37     fn integer(a: i32x4, b: i32x4) -> i32x4;
38
39     // vmaxq_s32
40     #[cfg(target_arch = "arm")]
41     #[link_name = "llvm.arm.neon.vmaxs.v4i32"]
42     fn integer(a: i32x4, b: i32x4) -> i32x4;
43     // vmaxq_s32
44     #[cfg(target_arch = "aarch64")]
45     #[link_name = "llvm.aarch64.neon.maxs.v4i32"]
46     fn integer(a: i32x4, b: i32x4) -> i32x4;
47
48     // just some substitute foreign symbol, not an LLVM intrinsic; so
49     // we still get type checking, but not as detailed as (ab)using
50     // LLVM.
51     #[cfg(not(any(target_arch = "x86",
52                   target_arch = "x86-64",
53                   target_arch = "arm",
54                   target_arch = "aarch64")))]
55     fn integer(a: i32x4, b: i32x4) -> i32x4;
56 }
57
58 pub fn bar(a: i32x4, b: i32x4) -> i32x4 {
59     unsafe {integer(a, b)}
60 }
61
62 #[lang = "sized"]
63 pub trait Sized { }
64
65 #[lang = "copy"]
66 pub trait Copy { }
67
68 impl Copy for f32 {}
69 impl Copy for i32 {}
70
71 pub mod marker {
72     pub use Copy;
73 }
74
75 #[lang = "freeze"]
76 auto trait Freeze {}
77
78 #[macro_export]
79 #[rustc_builtin_macro]
80 macro_rules! Copy { () => () }