@@ -8,27 +8,40 @@ 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+ Int ( Sign ) ,
22+ Char ( Sign ) ,
1723 Poly ,
1824 Void ,
25+ Mask ,
26+ Vector ,
1927}
2028
2129impl FromStr for TypeKind {
2230 type Err = String ;
2331
2432 fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
2533 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+ }
2939 "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 ) ) ,
3142 "void" => Ok ( Self :: Void ) ,
43+ "MASK" => Ok ( Self :: Mask ) ,
44+ "M64" | "M128" | "M256" | "M512" => Ok ( Self :: Vector ) ,
3245 _ => Err ( format ! ( "Impossible to parse argument kind {s}" ) ) ,
3346 }
3447 }
@@ -42,10 +55,14 @@ impl fmt::Display for TypeKind {
4255 match self {
4356 Self :: BFloat => "bfloat" ,
4457 Self :: Float => "float" ,
45- Self :: Int => "int" ,
46- Self :: UInt => "uint" ,
58+ Self :: Int ( Sign :: Signed ) => "int" ,
59+ Self :: Int ( Sign :: Unsigned ) => "uint" ,
4760 Self :: Poly => "poly" ,
4861 Self :: Void => "void" ,
62+ Self :: Char ( Sign :: Signed ) => "char" ,
63+ Self :: Char ( Sign :: Unsigned ) => "unsigned char" ,
64+ Self :: Mask => "mask" ,
65+ Self :: Vector => "vector" ,
4966 }
5067 )
5168 }
@@ -56,20 +73,24 @@ impl TypeKind {
5673 pub fn c_prefix ( & self ) -> & str {
5774 match self {
5875 Self :: Float => "float" ,
59- Self :: Int => "int" ,
60- Self :: UInt => "uint" ,
76+ Self :: Int ( Sign :: Signed ) => "int" ,
77+ Self :: Int ( Sign :: Unsigned ) => "uint" ,
6178 Self :: Poly => "poly" ,
79+ Self :: Char ( Sign :: Signed ) => "char" ,
6280 _ => unreachable ! ( "Not used: {:#?}" , self ) ,
6381 }
6482 }
6583
6684 /// Gets the rust prefix for the type kind i.e. i, u, f.
6785 pub fn rust_prefix ( & self ) -> & str {
6886 match self {
87+ Self :: BFloat => "bf" ,
6988 Self :: Float => "f" ,
70- Self :: Int => "i" ,
71- Self :: UInt => "u" ,
89+ Self :: Int ( Sign :: Signed ) => "i" ,
90+ Self :: Int ( Sign :: Unsigned ) => "u" ,
7291 Self :: Poly => "u" ,
92+ Self :: Char ( Sign :: Unsigned ) => "u" ,
93+ Self :: Char ( Sign :: Signed ) => "i" ,
7394 _ => unreachable ! ( "Unused type kind: {:#?}" , self ) ,
7495 }
7596 }
@@ -133,11 +154,14 @@ impl IntrinsicType {
133154 }
134155
135156 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+ }
141165 }
142166
143167 pub fn rust_scalar_type ( & self ) -> String {
@@ -155,8 +179,8 @@ impl IntrinsicType {
155179 bit_len : Some ( 8 ) ,
156180 ..
157181 } => match kind {
158- TypeKind :: Int => "(int)" ,
159- TypeKind :: UInt => "(unsigned int)" ,
182+ TypeKind :: Int ( Sign :: Signed ) => "(int)" ,
183+ TypeKind :: Int ( Sign :: Unsigned ) => "(unsigned int)" ,
160184 TypeKind :: Poly => "(unsigned int)(uint8_t)" ,
161185 _ => "" ,
162186 } ,
@@ -172,6 +196,21 @@ impl IntrinsicType {
172196 128 => "" ,
173197 _ => panic ! ( "invalid bit_len" ) ,
174198 } ,
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)" ,
175214 _ => "" ,
176215 }
177216 }
@@ -185,7 +224,7 @@ impl IntrinsicType {
185224 match self {
186225 IntrinsicType {
187226 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 ( _ ) ) ,
189228 simd_len,
190229 vec_len,
191230 ..
@@ -201,7 +240,8 @@ impl IntrinsicType {
201240 . format_with( ",\n " , |i, fmt| {
202241 let src = value_for_array( * bit_len, i) ;
203242 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+ {
205245 // `src` is a two's complement representation of a negative value.
206246 let mask = !0u64 >> ( 64 - * bit_len) ;
207247 let ones_compl = src ^ mask;
@@ -257,7 +297,7 @@ impl IntrinsicType {
257297 ..
258298 } => false ,
259299 IntrinsicType {
260- kind : TypeKind :: Int | TypeKind :: UInt | TypeKind :: Poly ,
300+ kind : TypeKind :: Int ( _ ) | TypeKind :: Poly ,
261301 ..
262302 } => true ,
263303 _ => unimplemented ! ( ) ,
0 commit comments