Skip to content

Commit 275baff

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

File tree

3 files changed

+77
-31
lines changed

3 files changed

+77
-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: 67 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,42 @@ 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+
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

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

Comments
 (0)