|
| 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 | +#![no_std] |
| 16 | + |
| 17 | +#![feature(simd, link_llvm_intrinsics, lang_items)] |
| 18 | + |
| 19 | + |
| 20 | +#[repr(C)] |
| 21 | +#[derive(Copy)] |
| 22 | +#[simd] |
| 23 | +pub struct f32x4(f32, f32, f32, f32); |
| 24 | + |
| 25 | + |
| 26 | +extern { |
| 27 | + #[link_name = "llvm.sqrt.v4f32"] |
| 28 | + fn vsqrt(x: f32x4) -> f32x4; |
| 29 | +} |
| 30 | + |
| 31 | +pub fn foo(x: f32x4) -> f32x4 { |
| 32 | + unsafe {vsqrt(x)} |
| 33 | +} |
| 34 | + |
| 35 | +#[repr(C)] |
| 36 | +#[derive(Copy)] |
| 37 | +#[simd] |
| 38 | +pub struct i32x4(i32, i32, i32, i32); |
| 39 | + |
| 40 | + |
| 41 | +extern { |
| 42 | + // _mm_sll_epi32 |
| 43 | + #[cfg(any(target_arch = "x86", |
| 44 | + target_arch = "x86-64"))] |
| 45 | + #[link_name = "llvm.x86.sse2.psll.d"] |
| 46 | + fn integer(a: i32x4, b: i32x4) -> i32x4; |
| 47 | + |
| 48 | + // vmaxq_s32 |
| 49 | + #[cfg(any(target_arch = "arm"))] |
| 50 | + #[link_name = "llvm.arm.neon.vmaxs.v4i32"] |
| 51 | + fn integer(a: i32x4, b: i32x4) -> i32x4; |
| 52 | + // vmaxq_s32 |
| 53 | + #[cfg(any(target_arch = "aarch64"))] |
| 54 | + #[link_name = "llvm.aarch64.neon.maxs.v4i32"] |
| 55 | + fn integer(a: i32x4, b: i32x4) -> i32x4; |
| 56 | + |
| 57 | + // just some substitute foreign symbol, not an LLVM intrinsic; so |
| 58 | + // we still get type checking, but not as detailed as (ab)using |
| 59 | + // LLVM. |
| 60 | + #[cfg(not(any(target_arch = "x86", |
| 61 | + target_arch = "x86-64", |
| 62 | + target_arch = "arm", |
| 63 | + target_arch = "aarch64")))] |
| 64 | + fn integer(a: i32x4, b: i32x4) -> i32x4; |
| 65 | +} |
| 66 | + |
| 67 | +pub fn bar(a: i32x4, b: i32x4) -> i32x4 { |
| 68 | + unsafe {integer(a, b)} |
| 69 | +} |
| 70 | + |
| 71 | +#[lang = "sized"] |
| 72 | +trait Sized {} |
| 73 | + |
| 74 | +#[lang = "copy"] |
| 75 | +trait Copy {} |
| 76 | + |
| 77 | +mod std { |
| 78 | + pub mod marker { |
| 79 | + pub use Copy; |
| 80 | + } |
| 81 | +} |
0 commit comments