Skip to content

Commit d6c2c5b

Browse files
Modified Typekind to group the Signed and Unsigned version of types.
1 parent c6b2f48 commit d6c2c5b

File tree

3 files changed

+72
-31
lines changed

3 files changed

+72
-31
lines changed

crates/intrinsic-test/src/arm/intrinsic.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::common::argument::ArgumentList;
22
use crate::common::indentation::Indentation;
33
use crate::common::intrinsic::{Intrinsic, IntrinsicDefinition};
4-
use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, TypeKind};
4+
use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, Sign, TypeKind};
55
use std::ops::Deref;
66

77
#[derive(Debug, Clone, PartialEq)]
@@ -73,8 +73,9 @@ impl IntrinsicDefinition<ArmIntrinsicType> for Intrinsic<ArmIntrinsicType> {
7373
TypeKind::Float if self.results().inner_size() == 16 => "float16_t".to_string(),
7474
TypeKind::Float if self.results().inner_size() == 32 => "float".to_string(),
7575
TypeKind::Float if self.results().inner_size() == 64 => "double".to_string(),
76-
TypeKind::Int => format!("int{}_t", self.results().inner_size()),
77-
TypeKind::UInt => format!("uint{}_t", self.results().inner_size()),
76+
TypeKind::Int(Sign::Signed) => format!("int{}_t", self.results().inner_size()),
77+
TypeKind::Int(Sign::Unsigned) =>
78+
format!("uint{}_t", self.results().inner_size()),
7879
TypeKind::Poly => format!("poly{}_t", self.results().inner_size()),
7980
ty => todo!("print_result_c - Unknown type: {:#?}", ty),
8081
},

crates/intrinsic-test/src/arm/types.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::intrinsic::ArmIntrinsicType;
22
use crate::common::cli::Language;
3-
use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, TypeKind};
3+
use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, Sign, TypeKind};
44

55
impl IntrinsicTypeDefinition for ArmIntrinsicType {
66
/// Gets a string containing the typename for this type in C format.
@@ -73,8 +73,8 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
7373
format!(
7474
"vld{len}{quad}_{type}{size}",
7575
type = match k {
76-
TypeKind::UInt => "u",
77-
TypeKind::Int => "s",
76+
TypeKind::Int(Sign::Unsigned) => "u",
77+
TypeKind::Int(Sign::Signed) => "s",
7878
TypeKind::Float => "f",
7979
// The ACLE doesn't support 64-bit polynomial loads on Armv7
8080
// if armv7 and bl == 64, use "s", else "p"
@@ -107,8 +107,8 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
107107
format!(
108108
"vget{quad}_lane_{type}{size}",
109109
type = match k {
110-
TypeKind::UInt => "u",
111-
TypeKind::Int => "s",
110+
TypeKind::Int(Sign::Unsigned) => "u",
111+
TypeKind::Int(Sign::Signed) => "s",
112112
TypeKind::Float => "f",
113113
TypeKind::Poly => "p",
114114
x => todo!("get_load_function TypeKind: {:#?}", x),
@@ -176,7 +176,7 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
176176
} else {
177177
let kind = start.parse::<TypeKind>()?;
178178
let bit_len = match kind {
179-
TypeKind::Int => Some(32),
179+
TypeKind::Int(_) => Some(32),
180180
_ => None,
181181
};
182182
Ok(Box::new(ArmIntrinsicType(IntrinsicType {

crates/intrinsic-test/src/common/intrinsic_helpers.rs

Lines changed: 62 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,40 @@ use super::cli::Language;
88
use super::indentation::Indentation;
99
use 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)]
1218
pub 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

2129
impl 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

Comments
 (0)