@@ -8,27 +8,40 @@ use super::cli::Language;
8
8
use super :: indentation:: Indentation ;
9
9
use super :: values:: value_for_array;
10
10
11
+ #[ derive( Debug , PartialEq , Copy , Clone ) ]
12
+ pub enum Sign {
13
+ Signed ,
14
+ Unsigned ,
15
+ }
16
+
11
17
#[ derive( Debug , PartialEq , Copy , Clone ) ]
12
18
pub enum TypeKind {
13
19
BFloat ,
14
20
Float ,
15
- Int ,
16
- UInt ,
21
+ Int ( Sign ) ,
22
+ Char ( Sign ) ,
17
23
Poly ,
18
24
Void ,
25
+ Mask ,
26
+ Vector ,
19
27
}
20
28
21
29
impl FromStr for TypeKind {
22
30
type Err = String ;
23
31
24
32
fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
25
33
match s {
26
- "bfloat" => Ok ( Self :: BFloat ) ,
27
- "float" => Ok ( Self :: Float ) ,
28
- "int" => Ok ( Self :: Int ) ,
34
+ "bfloat" | "BF16" => Ok ( Self :: BFloat ) ,
35
+ "float" | "double" | "FP16" | "FP32" | "FP64" => Ok ( Self :: Float ) ,
36
+ "int" | "long" | "short" | "SI8" | "SI16" | "SI32" | "SI64" => {
37
+ Ok ( Self :: Int ( Sign :: Signed ) )
38
+ }
29
39
"poly" => Ok ( Self :: Poly ) ,
30
- "uint" | "unsigned" => Ok ( Self :: UInt ) ,
40
+ "char" => Ok ( Self :: Char ( Sign :: Signed ) ) ,
41
+ "uint" | "unsigned" | "UI8" | "UI16" | "UI32" | "UI64" => Ok ( Self :: Int ( Sign :: Unsigned ) ) ,
31
42
"void" => Ok ( Self :: Void ) ,
43
+ "MASK" => Ok ( Self :: Mask ) ,
44
+ "M64" | "M128" | "M256" | "M512" => Ok ( Self :: Vector ) ,
32
45
_ => Err ( format ! ( "Impossible to parse argument kind {s}" ) ) ,
33
46
}
34
47
}
@@ -42,10 +55,14 @@ impl fmt::Display for TypeKind {
42
55
match self {
43
56
Self :: BFloat => "bfloat" ,
44
57
Self :: Float => "float" ,
45
- Self :: Int => "int" ,
46
- Self :: UInt => "uint" ,
58
+ Self :: Int ( Sign :: Signed ) => "int" ,
59
+ Self :: Int ( Sign :: Unsigned ) => "uint" ,
47
60
Self :: Poly => "poly" ,
48
61
Self :: Void => "void" ,
62
+ Self :: Char ( Sign :: Signed ) => "char" ,
63
+ Self :: Char ( Sign :: Unsigned ) => "unsigned char" ,
64
+ Self :: Mask => "mask" ,
65
+ Self :: Vector => "vector" ,
49
66
}
50
67
)
51
68
}
@@ -56,20 +73,24 @@ impl TypeKind {
56
73
pub fn c_prefix ( & self ) -> & str {
57
74
match self {
58
75
Self :: Float => "float" ,
59
- Self :: Int => "int" ,
60
- Self :: UInt => "uint" ,
76
+ Self :: Int ( Sign :: Signed ) => "int" ,
77
+ Self :: Int ( Sign :: Unsigned ) => "uint" ,
61
78
Self :: Poly => "poly" ,
79
+ Self :: Char ( Sign :: Signed ) => "char" ,
62
80
_ => unreachable ! ( "Not used: {:#?}" , self ) ,
63
81
}
64
82
}
65
83
66
84
/// Gets the rust prefix for the type kind i.e. i, u, f.
67
85
pub fn rust_prefix ( & self ) -> & str {
68
86
match self {
87
+ Self :: BFloat => "bf" ,
69
88
Self :: Float => "f" ,
70
- Self :: Int => "i" ,
71
- Self :: UInt => "u" ,
89
+ Self :: Int ( Sign :: Signed ) => "i" ,
90
+ Self :: Int ( Sign :: Unsigned ) => "u" ,
72
91
Self :: Poly => "u" ,
92
+ Self :: Char ( Sign :: Unsigned ) => "u" ,
93
+ Self :: Char ( Sign :: Signed ) => "i" ,
73
94
_ => unreachable ! ( "Unused type kind: {:#?}" , self ) ,
74
95
}
75
96
}
@@ -133,11 +154,14 @@ impl IntrinsicType {
133
154
}
134
155
135
156
pub fn c_scalar_type ( & self ) -> String {
136
- format ! (
137
- "{prefix}{bits}_t" ,
138
- prefix = self . kind( ) . c_prefix( ) ,
139
- bits = self . inner_size( )
140
- )
157
+ match self . kind ( ) {
158
+ TypeKind :: Char ( _) => String :: from ( "char" ) ,
159
+ _ => format ! (
160
+ "{prefix}{bits}_t" ,
161
+ prefix = self . kind( ) . c_prefix( ) ,
162
+ bits = self . inner_size( )
163
+ ) ,
164
+ }
141
165
}
142
166
143
167
pub fn rust_scalar_type ( & self ) -> String {
@@ -155,8 +179,8 @@ impl IntrinsicType {
155
179
bit_len : Some ( 8 ) ,
156
180
..
157
181
} => match kind {
158
- TypeKind :: Int => "(int)" ,
159
- TypeKind :: UInt => "(unsigned int)" ,
182
+ TypeKind :: Int ( Sign :: Signed ) => "(int)" ,
183
+ TypeKind :: Int ( Sign :: Unsigned ) => "(unsigned int)" ,
160
184
TypeKind :: Poly => "(unsigned int)(uint8_t)" ,
161
185
_ => "" ,
162
186
} ,
@@ -172,6 +196,21 @@ impl IntrinsicType {
172
196
128 => "" ,
173
197
_ => panic ! ( "invalid bit_len" ) ,
174
198
} ,
199
+ IntrinsicType {
200
+ kind : TypeKind :: Float ,
201
+ bit_len : Some ( bit_len) ,
202
+ ..
203
+ } => match bit_len {
204
+ 16 => "(float16_t)" ,
205
+ 32 => "(float)" ,
206
+ 64 => "(double)" ,
207
+ 128 => "" ,
208
+ _ => panic ! ( "invalid bit_len" ) ,
209
+ } ,
210
+ IntrinsicType {
211
+ kind : TypeKind :: Char ( _) ,
212
+ ..
213
+ } => "(char)" ,
175
214
_ => "" ,
176
215
}
177
216
}
@@ -185,7 +224,7 @@ impl IntrinsicType {
185
224
match self {
186
225
IntrinsicType {
187
226
bit_len : Some ( bit_len @ ( 8 | 16 | 32 | 64 ) ) ,
188
- kind : kind @ ( TypeKind :: Int | TypeKind :: UInt | TypeKind :: Poly ) ,
227
+ kind : kind @ ( TypeKind :: Int ( _ ) | TypeKind :: Poly | TypeKind :: Char ( _ ) ) ,
189
228
simd_len,
190
229
vec_len,
191
230
..
@@ -201,7 +240,8 @@ impl IntrinsicType {
201
240
. format_with( ",\n " , |i, fmt| {
202
241
let src = value_for_array( * bit_len, i) ;
203
242
assert!( src == 0 || src. ilog2( ) < * bit_len) ;
204
- if * kind == TypeKind :: Int && ( src >> ( * bit_len - 1 ) ) != 0 {
243
+ if * kind == TypeKind :: Int ( Sign :: Signed ) && ( src >> ( * bit_len - 1 ) ) != 0
244
+ {
205
245
// `src` is a two's complement representation of a negative value.
206
246
let mask = !0u64 >> ( 64 - * bit_len) ;
207
247
let ones_compl = src ^ mask;
@@ -257,7 +297,7 @@ impl IntrinsicType {
257
297
..
258
298
} => false ,
259
299
IntrinsicType {
260
- kind : TypeKind :: Int | TypeKind :: UInt | TypeKind :: Poly ,
300
+ kind : TypeKind :: Int ( _ ) | TypeKind :: Poly ,
261
301
..
262
302
} => true ,
263
303
_ => unimplemented ! ( ) ,
0 commit comments