]> git.lizzy.rs Git - rust.git/blob - src/test/run-make/simd-ffi/simd.rs
Auto merge of #41258 - clarcharr:str_box_extras, r=Kimundi
[rust.git] / src / test / run-make / simd-ffi / simd.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // ensures that public symbols are not removed completely
12 #![crate_type = "lib"]
13 // we can compile to a variety of platforms, because we don't need
14 // cross-compiled standard libraries.
15 #![feature(no_core, optin_builtin_traits)]
16 #![no_core]
17
18 #![feature(repr_simd, simd_ffi, link_llvm_intrinsics, lang_items)]
19
20
21 #[repr(C)]
22 #[derive(Copy)]
23 #[repr(simd)]
24 pub struct f32x4(f32, f32, f32, f32);
25
26
27 extern {
28     #[link_name = "llvm.sqrt.v4f32"]
29     fn vsqrt(x: f32x4) -> f32x4;
30 }
31
32 pub fn foo(x: f32x4) -> f32x4 {
33     unsafe {vsqrt(x)}
34 }
35
36 #[repr(C)]
37 #[derive(Copy)]
38 #[repr(simd)]
39 pub struct i32x4(i32, i32, i32, i32);
40
41
42 extern {
43     // _mm_sll_epi32
44     #[cfg(any(target_arch = "x86",
45               target_arch = "x86-64"))]
46     #[link_name = "llvm.x86.sse2.psll.d"]
47     fn integer(a: i32x4, b: i32x4) -> i32x4;
48
49     // vmaxq_s32
50     #[cfg(target_arch = "arm")]
51     #[link_name = "llvm.arm.neon.vmaxs.v4i32"]
52     fn integer(a: i32x4, b: i32x4) -> i32x4;
53     // vmaxq_s32
54     #[cfg(target_arch = "aarch64")]
55     #[link_name = "llvm.aarch64.neon.maxs.v4i32"]
56     fn integer(a: i32x4, b: i32x4) -> i32x4;
57
58     // just some substitute foreign symbol, not an LLVM intrinsic; so
59     // we still get type checking, but not as detailed as (ab)using
60     // LLVM.
61     #[cfg(not(any(target_arch = "x86",
62                   target_arch = "x86-64",
63                   target_arch = "arm",
64                   target_arch = "aarch64")))]
65     fn integer(a: i32x4, b: i32x4) -> i32x4;
66 }
67
68 pub fn bar(a: i32x4, b: i32x4) -> i32x4 {
69     unsafe {integer(a, b)}
70 }
71
72 #[lang = "sized"]
73 pub trait Sized { }
74
75 #[lang = "copy"]
76 pub trait Copy { }
77
78 pub mod marker {
79     pub use Copy;
80 }
81
82 #[lang = "freeze"]
83 trait Freeze {}
84 impl Freeze for .. {}