]> git.lizzy.rs Git - rust.git/blob - src/librustc_platform_intrinsics/lib.rs
Rollup merge of #41910 - mersinvald:master, r=Mark-Simulacrum
[rust.git] / src / librustc_platform_intrinsics / lib.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 #![crate_name = "rustc_platform_intrinsics"]
12 #![cfg_attr(stage0, unstable(feature = "rustc_private", issue = "27812"))]
13 #![crate_type = "dylib"]
14 #![crate_type = "rlib"]
15 #![cfg_attr(stage0, feature(staged_api))]
16 #![deny(warnings)]
17 #![allow(bad_style)]
18
19 pub struct Intrinsic {
20     pub inputs: &'static [&'static Type],
21     pub output: &'static Type,
22
23     pub definition: IntrinsicDef,
24 }
25
26 #[derive(Clone, Hash, Eq, PartialEq)]
27 pub enum Type {
28     Void,
29     Integer(/* signed */ bool, u8, /* llvm width */ u8),
30     Float(u8),
31     Pointer(&'static Type, Option<&'static Type>, /* const */ bool),
32     Vector(&'static Type, Option<&'static Type>, u16),
33     Aggregate(bool, &'static [&'static Type]),
34 }
35
36 pub enum IntrinsicDef {
37     Named(&'static str),
38 }
39
40 static I8: Type = Type::Integer(true, 8, 8);
41 static I16: Type = Type::Integer(true, 16, 16);
42 static I32: Type = Type::Integer(true, 32, 32);
43 static I64: Type = Type::Integer(true, 64, 64);
44 static U8: Type = Type::Integer(false, 8, 8);
45 static U16: Type = Type::Integer(false, 16, 16);
46 static U32: Type = Type::Integer(false, 32, 32);
47 static U64: Type = Type::Integer(false, 64, 64);
48 static F32: Type = Type::Float(32);
49 static F64: Type = Type::Float(64);
50
51 static I32_8: Type = Type::Integer(true, 32, 8);
52
53 static I8x8: Type = Type::Vector(&I8, None, 8);
54 static U8x8: Type = Type::Vector(&U8, None, 8);
55 static I8x16: Type = Type::Vector(&I8, None, 16);
56 static U8x16: Type = Type::Vector(&U8, None, 16);
57 static I8x32: Type = Type::Vector(&I8, None, 32);
58 static U8x32: Type = Type::Vector(&U8, None, 32);
59 static I8x64: Type = Type::Vector(&I8, None, 64);
60 static U8x64: Type = Type::Vector(&U8, None, 64);
61 static I8x128: Type = Type::Vector(&I8, None, 128);
62 static U8x128: Type = Type::Vector(&U8, None, 128);
63 static I8x256: Type = Type::Vector(&I8, None, 256);
64 static U8x256: Type = Type::Vector(&U8, None, 256);
65
66 static I16x4: Type = Type::Vector(&I16, None, 4);
67 static U16x4: Type = Type::Vector(&U16, None, 4);
68 static I16x8: Type = Type::Vector(&I16, None, 8);
69 static U16x8: Type = Type::Vector(&U16, None, 8);
70 static I16x16: Type = Type::Vector(&I16, None, 16);
71 static U16x16: Type = Type::Vector(&U16, None, 16);
72 static I16x32: Type = Type::Vector(&I16, None, 32);
73 static U16x32: Type = Type::Vector(&U16, None, 32);
74 static I16x64: Type = Type::Vector(&I16, None, 64);
75 static U16x64: Type = Type::Vector(&U16, None, 64);
76 static I16x128: Type = Type::Vector(&I16, None, 128);
77 static U16x128: Type = Type::Vector(&U16, None, 128);
78
79 static I32x2: Type = Type::Vector(&I32, None, 2);
80 static U32x2: Type = Type::Vector(&U32, None, 2);
81 static I32x4: Type = Type::Vector(&I32, None, 4);
82 static U32x4: Type = Type::Vector(&U32, None, 4);
83 static I32x8: Type = Type::Vector(&I32, None, 8);
84 static U32x8: Type = Type::Vector(&U32, None, 8);
85 static I32x16: Type = Type::Vector(&I32, None, 16);
86 static U32x16: Type = Type::Vector(&U32, None, 16);
87 static I32x32: Type = Type::Vector(&I32, None, 32);
88 static U32x32: Type = Type::Vector(&U32, None, 32);
89 static I32x64: Type = Type::Vector(&I32, None, 64);
90 static U32x64: Type = Type::Vector(&U32, None, 64);
91
92 static I64x1: Type = Type::Vector(&I64, None, 1);
93 static U64x1: Type = Type::Vector(&U64, None, 1);
94 static I64x2: Type = Type::Vector(&I64, None, 2);
95 static U64x2: Type = Type::Vector(&U64, None, 2);
96 static I64x4: Type = Type::Vector(&I64, None, 4);
97 static U64x4: Type = Type::Vector(&U64, None, 4);
98
99 static F32x2: Type = Type::Vector(&F32, None, 2);
100 static F32x4: Type = Type::Vector(&F32, None, 4);
101 static F32x8: Type = Type::Vector(&F32, None, 8);
102 static F64x1: Type = Type::Vector(&F64, None, 1);
103 static F64x2: Type = Type::Vector(&F64, None, 2);
104 static F64x4: Type = Type::Vector(&F64, None, 4);
105
106 static I32x4_F32: Type = Type::Vector(&I32, Some(&F32), 4);
107 static I32x8_F32: Type = Type::Vector(&I32, Some(&F32), 8);
108 static I64x2_F64: Type = Type::Vector(&I64, Some(&F64), 2);
109 static I64x4_F64: Type = Type::Vector(&I64, Some(&F64), 4);
110
111 static VOID: Type = Type::Void;
112
113 mod x86;
114 mod arm;
115 mod aarch64;
116 mod nvptx;
117 mod hexagon;
118
119 impl Intrinsic {
120     pub fn find(name: &str) -> Option<Intrinsic> {
121         if name.starts_with("x86_") {
122             x86::find(name)
123         } else if name.starts_with("arm_") {
124             arm::find(name)
125         } else if name.starts_with("aarch64_") {
126             aarch64::find(name)
127         } else if name.starts_with("nvptx_") {
128             nvptx::find(name)
129         } else if name.starts_with("Q6_") {
130             hexagon::find(name)
131         } else {
132             None
133         }
134     }
135 }