@@ -8,27 +8,42 @@ use super::cli::Language;
88use super :: indentation:: Indentation ;
99use super :: values:: value_for_array;
1010
11+ #[ derive( Debug , PartialEq , Copy , Clone ) ]
12+ pub enum Sign {
13+ Signed ,
14+ Unsigned ,
15+ }
16+
1117#[ derive( Debug , PartialEq , Copy , Clone ) ]
1218pub enum TypeKind {
1319 BFloat ,
1420 Float ,
15- Int ,
16- UInt ,
21+
22+ // if signed, then the inner value is true
23+ Int ( Sign ) ,
24+ Char ( Sign ) ,
1725 Poly ,
1826 Void ,
27+ Mask ,
28+ Vector ,
1929}
2030
2131impl FromStr for TypeKind {
2232 type Err = String ;
2333
2434 fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
2535 match s {
26- "bfloat" => Ok ( Self :: BFloat ) ,
27- "float" => Ok ( Self :: Float ) ,
28- "int" => Ok ( Self :: Int ) ,
36+ "bfloat" | "BF16" => Ok ( Self :: BFloat ) ,
37+ "float" | "double" | "FP16" | "FP32" | "FP64" => Ok ( Self :: Float ) ,
38+ "int" | "long" | "short" | "SI8" | "SI16" | "SI32" | "SI64" => {
39+ Ok ( Self :: Int ( Sign :: Signed ) )
40+ }
2941 "poly" => Ok ( Self :: Poly ) ,
30- "uint" | "unsigned" => Ok ( Self :: UInt ) ,
42+ "char" => Ok ( Self :: Char ( Sign :: Signed ) ) ,
43+ "uint" | "unsigned" | "UI8" | "UI16" | "UI32" | "UI64" => Ok ( Self :: Int ( Sign :: Unsigned ) ) ,
3144 "void" => Ok ( Self :: Void ) ,
45+ "MASK" => Ok ( Self :: Mask ) ,
46+ "M64" | "M128" | "M256" | "M512" => Ok ( Self :: Vector ) ,
3247 _ => Err ( format ! ( "Impossible to parse argument kind {s}" ) ) ,
3348 }
3449 }
@@ -42,10 +57,14 @@ impl fmt::Display for TypeKind {
4257 match self {
4358 Self :: BFloat => "bfloat" ,
4459 Self :: Float => "float" ,
45- Self :: Int => "int" ,
46- Self :: UInt => "uint" ,
60+ Self :: Int ( Sign :: Signed ) => "int" ,
61+ Self :: Int ( Sign :: Unsigned ) => "uint" ,
4762 Self :: Poly => "poly" ,
4863 Self :: Void => "void" ,
64+ Self :: Char ( Sign :: Signed ) => "char" ,
65+ Self :: Char ( Sign :: Unsigned ) => "unsigned char" ,
66+ Self :: Mask => "mask" ,
67+ Self :: Vector => "vector" ,
4968 }
5069 )
5170 }
@@ -56,20 +75,24 @@ impl TypeKind {
5675 pub fn c_prefix ( & self ) -> & str {
5776 match self {
5877 Self :: Float => "float" ,
59- Self :: Int => "int" ,
60- Self :: UInt => "uint" ,
78+ Self :: Int ( Sign :: Signed ) => "int" ,
79+ Self :: Int ( Sign :: Unsigned ) => "uint" ,
6180 Self :: Poly => "poly" ,
81+ Self :: Char ( Sign :: Signed ) => "char" ,
6282 _ => unreachable ! ( "Not used: {:#?}" , self ) ,
6383 }
6484 }
6585
6686 /// Gets the rust prefix for the type kind i.e. i, u, f.
6787 pub fn rust_prefix ( & self ) -> & str {
6888 match self {
89+ Self :: BFloat => "bf" ,
6990 Self :: Float => "f" ,
70- Self :: Int => "i" ,
71- Self :: UInt => "u" ,
91+ Self :: Int ( Sign :: Signed ) => "i" ,
92+ Self :: Int ( Sign :: Unsigned ) => "u" ,
7293 Self :: Poly => "u" ,
94+ Self :: Char ( Sign :: Unsigned ) => "u" ,
95+ Self :: Char ( Sign :: Signed ) => "i" ,
7396 _ => unreachable ! ( "Unused type kind: {:#?}" , self ) ,
7497 }
7598 }
@@ -133,11 +156,17 @@ impl IntrinsicType {
133156 }
134157
135158 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- )
159+ match self {
160+ IntrinsicType {
161+ kind : TypeKind :: Char ( _) ,
162+ ..
163+ } => String :: from ( "char" ) ,
164+ _ => format ! (
165+ "{prefix}{bits}_t" ,
166+ prefix = self . kind( ) . c_prefix( ) ,
167+ bits = self . inner_size( )
168+ ) ,
169+ }
141170 }
142171
143172 pub fn rust_scalar_type ( & self ) -> String {
@@ -155,8 +184,8 @@ impl IntrinsicType {
155184 bit_len : Some ( 8 ) ,
156185 ..
157186 } => match kind {
158- TypeKind :: Int => "(int)" ,
159- TypeKind :: UInt => "(unsigned int)" ,
187+ TypeKind :: Int ( Sign :: Signed ) => "(int)" ,
188+ TypeKind :: Int ( Sign :: Unsigned ) => "(unsigned int)" ,
160189 TypeKind :: Poly => "(unsigned int)(uint8_t)" ,
161190 _ => "" ,
162191 } ,
@@ -172,6 +201,21 @@ impl IntrinsicType {
172201 128 => "" ,
173202 _ => panic ! ( "invalid bit_len" ) ,
174203 } ,
204+ IntrinsicType {
205+ kind : TypeKind :: Float ,
206+ bit_len : Some ( bit_len) ,
207+ ..
208+ } => match bit_len {
209+ 16 => "(float16_t)" ,
210+ 32 => "(float)" ,
211+ 64 => "(double)" ,
212+ 128 => "" ,
213+ _ => panic ! ( "invalid bit_len" ) ,
214+ } ,
215+ IntrinsicType {
216+ kind : TypeKind :: Char ( _) ,
217+ ..
218+ } => "(char)" ,
175219 _ => "" ,
176220 }
177221 }
@@ -185,7 +229,7 @@ impl IntrinsicType {
185229 match self {
186230 IntrinsicType {
187231 bit_len : Some ( bit_len @ ( 8 | 16 | 32 | 64 ) ) ,
188- kind : kind @ ( TypeKind :: Int | TypeKind :: UInt | TypeKind :: Poly ) ,
232+ kind : kind @ ( TypeKind :: Int ( _ ) | TypeKind :: Poly | TypeKind :: Char ( _ ) ) ,
189233 simd_len,
190234 vec_len,
191235 ..
@@ -201,7 +245,8 @@ impl IntrinsicType {
201245 . format_with( ",\n " , |i, fmt| {
202246 let src = value_for_array( * bit_len, i) ;
203247 assert!( src == 0 || src. ilog2( ) < * bit_len) ;
204- if * kind == TypeKind :: Int && ( src >> ( * bit_len - 1 ) ) != 0 {
248+ if * kind == TypeKind :: Int ( Sign :: Signed ) && ( src >> ( * bit_len - 1 ) ) != 0
249+ {
205250 // `src` is a two's complement representation of a negative value.
206251 let mask = !0u64 >> ( 64 - * bit_len) ;
207252 let ones_compl = src ^ mask;
@@ -257,7 +302,7 @@ impl IntrinsicType {
257302 ..
258303 } => false ,
259304 IntrinsicType {
260- kind : TypeKind :: Int | TypeKind :: UInt | TypeKind :: Poly ,
305+ kind : TypeKind :: Int ( _ ) | TypeKind :: Poly ,
261306 ..
262307 } => true ,
263308 _ => unimplemented ! ( ) ,
0 commit comments