Skip to content

Commit 94e2af7

Browse files
authored
Merge pull request #841 from GuillaumeGomez/more-mapping
Add two new target-specific intrinsics mapping
2 parents 774c8a2 + 436ae1e commit 94e2af7

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

src/intrinsic/llvm.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,13 +1061,18 @@ pub fn intrinsic<'gcc, 'tcx>(name: &str, cx: &CodegenCx<'gcc, 'tcx>) -> Function
10611061

10621062
"llvm.x86.xgetbv" => "__builtin_ia32_xgetbv",
10631063
// NOTE: this doc specifies the equivalent GCC builtins: http://huonw.github.io/llvmint/llvmint/x86/index.html
1064+
// FIXME: Should handle other targets than `ia32`.
10641065
"llvm.sqrt.v2f64" => "__builtin_ia32_sqrtpd",
1066+
// FIXME: Should handle other targets than `ia32`.
1067+
"llvm.sqrt.v4f32" => "__builtin_ia32_sqrtps",
10651068
"llvm.sqrt.f32" => {
10661069
let gcc_name = "__builtin_sqrtf";
10671070
let func = cx.context.get_builtin_function(gcc_name);
10681071
cx.functions.borrow_mut().insert(gcc_name.to_string(), func);
10691072
return func;
10701073
}
1074+
// FIXME: Should handle other targets than `ia32`.
1075+
"llvm.smax.v4i32" => "__builtin_ia32_pmaxsd128",
10711076
"llvm.x86.avx512.pmul.dq.512" => "__builtin_ia32_pmuldq512_mask",
10721077
"llvm.x86.avx512.pmulu.dq.512" => "__builtin_ia32_pmuludq512_mask",
10731078
"llvm.x86.avx512.max.ps.512" => "__builtin_ia32_maxps512_mask",

tests/run/simd-ffi.rs

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Compiler:
2+
//
3+
// Run-time:
4+
// status: 0
5+
6+
// FIXME: Remove this test once <tests/run-make/simd-ffi/simd.rs> stops
7+
// ignoring GCC backend.
8+
9+
#![allow(internal_features, non_camel_case_types)]
10+
// we can compile to a variety of platforms, because we don't need
11+
// cross-compiled standard libraries.
12+
#![feature(no_core, auto_traits)]
13+
#![no_core]
14+
#![feature(repr_simd, simd_ffi, link_llvm_intrinsics, lang_items, rustc_attrs)]
15+
16+
#[derive(Copy)]
17+
#[repr(simd)]
18+
pub struct f32x4([f32; 4]);
19+
20+
extern "C" {
21+
#[link_name = "llvm.sqrt.v4f32"]
22+
fn vsqrt(x: f32x4) -> f32x4;
23+
}
24+
25+
pub fn foo(x: f32x4) -> f32x4 {
26+
unsafe { vsqrt(x) }
27+
}
28+
29+
#[derive(Copy)]
30+
#[repr(simd)]
31+
pub struct i32x4([i32; 4]);
32+
33+
extern "C" {
34+
// _mm_sll_epi32
35+
#[cfg(all(any(target_arch = "x86", target_arch = "x86-64"), target_feature = "sse2"))]
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+
// Use a generic LLVM intrinsic to do type checking on other platforms
49+
#[cfg(not(any(
50+
all(any(target_arch = "x86", target_arch = "x86-64"), target_feature = "sse2"),
51+
target_arch = "arm",
52+
target_arch = "aarch64"
53+
)))]
54+
#[link_name = "llvm.smax.v4i32"]
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 = "pointee_sized"]
63+
pub trait PointeeSized {}
64+
65+
#[lang = "meta_sized"]
66+
pub trait MetaSized: PointeeSized {}
67+
68+
#[lang = "sized"]
69+
pub trait Sized: MetaSized {}
70+
71+
#[lang = "copy"]
72+
pub trait Copy {}
73+
74+
impl Copy for f32 {}
75+
impl Copy for i32 {}
76+
impl Copy for [f32; 4] {}
77+
impl Copy for [i32; 4] {}
78+
79+
pub mod marker {
80+
pub use Copy;
81+
}
82+
83+
#[lang = "freeze"]
84+
auto trait Freeze {}
85+
86+
#[macro_export]
87+
#[rustc_builtin_macro]
88+
macro_rules! Copy {
89+
() => {};
90+
}
91+
#[macro_export]
92+
#[rustc_builtin_macro]
93+
macro_rules! derive {
94+
() => {};
95+
}
96+
97+
#[lang = "start"]
98+
fn start<T>(_main: fn() -> T, _argc: isize, _argv: *const *const u8, _sigpipe: u8) -> isize {
99+
0
100+
}
101+
102+
fn main() {}

0 commit comments

Comments
 (0)