|
| 1 | +// Compiler: |
| 2 | + |
| 3 | +// FIXME: Remove this test once <tests/run-make/simd-ffi/simd.rs> stops |
| 4 | +// ignoring GCC backend. |
| 5 | + |
| 6 | +#![allow(internal_features, non_camel_case_types)] |
| 7 | +#![crate_type = "lib"] |
| 8 | + |
| 9 | +// we can compile to a variety of platforms, because we don't need |
| 10 | +// cross-compiled standard libraries. |
| 11 | +#![feature(no_core, auto_traits)] |
| 12 | +#![no_core] |
| 13 | +#![feature(repr_simd, simd_ffi, link_llvm_intrinsics, lang_items, rustc_attrs)] |
| 14 | + |
| 15 | +#[derive(Copy)] |
| 16 | +#[repr(simd)] |
| 17 | +pub struct f32x4([f32; 4]); |
| 18 | + |
| 19 | +extern "C" { |
| 20 | + #[link_name = "llvm.sqrt.v4f32"] |
| 21 | + fn vsqrt(x: f32x4) -> f32x4; |
| 22 | +} |
| 23 | + |
| 24 | +pub fn foo(x: f32x4) -> f32x4 { |
| 25 | + unsafe { vsqrt(x) } |
| 26 | +} |
| 27 | + |
| 28 | +#[derive(Copy)] |
| 29 | +#[repr(simd)] |
| 30 | +pub struct i32x4([i32; 4]); |
| 31 | + |
| 32 | +extern "C" { |
| 33 | + // _mm_sll_epi32 |
| 34 | + #[cfg(all(any(target_arch = "x86", target_arch = "x86-64"), target_feature = "sse2"))] |
| 35 | + #[link_name = "llvm.x86.sse2.psll.d"] |
| 36 | + fn integer(a: i32x4, b: i32x4) -> i32x4; |
| 37 | + |
| 38 | + // vmaxq_s32 |
| 39 | + #[cfg(target_arch = "arm")] |
| 40 | + #[link_name = "llvm.arm.neon.vmaxs.v4i32"] |
| 41 | + fn integer(a: i32x4, b: i32x4) -> i32x4; |
| 42 | + // vmaxq_s32 |
| 43 | + #[cfg(target_arch = "aarch64")] |
| 44 | + #[link_name = "llvm.aarch64.neon.maxs.v4i32"] |
| 45 | + fn integer(a: i32x4, b: i32x4) -> i32x4; |
| 46 | + |
| 47 | + // Use a generic LLVM intrinsic to do type checking on other platforms |
| 48 | + #[cfg(not(any( |
| 49 | + all(any(target_arch = "x86", target_arch = "x86-64"), target_feature = "sse2"), |
| 50 | + target_arch = "arm", |
| 51 | + target_arch = "aarch64" |
| 52 | + )))] |
| 53 | + #[link_name = "llvm.smax.v4i32"] |
| 54 | + fn integer(a: i32x4, b: i32x4) -> i32x4; |
| 55 | +} |
| 56 | + |
| 57 | +pub fn bar(a: i32x4, b: i32x4) -> i32x4 { |
| 58 | + unsafe { integer(a, b) } |
| 59 | +} |
| 60 | + |
| 61 | +#[lang = "pointee_sized"] |
| 62 | +pub trait PointeeSized {} |
| 63 | + |
| 64 | +#[lang = "meta_sized"] |
| 65 | +pub trait MetaSized: PointeeSized {} |
| 66 | + |
| 67 | +#[lang = "sized"] |
| 68 | +pub trait Sized: MetaSized {} |
| 69 | + |
| 70 | +#[lang = "copy"] |
| 71 | +pub trait Copy {} |
| 72 | + |
| 73 | +impl Copy for f32 {} |
| 74 | +impl Copy for i32 {} |
| 75 | +impl Copy for [f32; 4] {} |
| 76 | +impl Copy for [i32; 4] {} |
| 77 | + |
| 78 | +pub mod marker { |
| 79 | + pub use Copy; |
| 80 | +} |
| 81 | + |
| 82 | +#[lang = "freeze"] |
| 83 | +auto trait Freeze {} |
| 84 | + |
| 85 | +#[macro_export] |
| 86 | +#[rustc_builtin_macro] |
| 87 | +macro_rules! Copy { |
| 88 | + () => {}; |
| 89 | +} |
| 90 | +#[macro_export] |
| 91 | +#[rustc_builtin_macro] |
| 92 | +macro_rules! derive { |
| 93 | + () => {}; |
| 94 | +} |
0 commit comments