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