Skip to content

Commit 9595fde

Browse files
feat: added the simple set of argument types for X86 intrinsics
1 parent ae72698 commit 9595fde

File tree

5 files changed

+75
-44
lines changed

5 files changed

+75
-44
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ 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(true) => format!("int{}_t", self.results().inner_size()),
77+
TypeKind::Int(false) => format!("uint{}_t", self.results().inner_size()),
7878
TypeKind::Poly => format!("poly{}_t", self.results().inner_size()),
7979
ty => todo!("print_result_c - Unknown type: {:#?}", ty),
8080
},

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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(false) => "u",
77+
TypeKind::Int(true) => "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(false) => "u",
111+
TypeKind::Int(true) => "s",
112112
TypeKind::Float => "f",
113113
TypeKind::Poly => "p",
114114
x => todo!("get_load_function TypeKind: {:#?}", x),
@@ -175,7 +175,7 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
175175
} else {
176176
let kind = start.parse::<TypeKind>()?;
177177
let bit_len = match kind {
178-
TypeKind::Int => Some(32),
178+
TypeKind::Int(_) => Some(32),
179179
_ => None,
180180
};
181181
Ok(ArmIntrinsicType(IntrinsicType {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ where
7979
) -> Argument<T> {
8080
let (ty, var_name) = Self::type_and_name_from_c(arg);
8181

82-
let ty =
83-
T::from_c(ty, target).unwrap_or_else(|_| panic!("Failed to parse argument '{arg}'"));
82+
let ty = T::from_c(ty, &target.to_string())
83+
.unwrap_or_else(|_| panic!("Failed to parse argument '{arg}'"));
8484

8585
Argument {
8686
pos,

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

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ use super::values::value_for_array;
1212
pub enum TypeKind {
1313
BFloat,
1414
Float,
15-
Int,
16-
UInt,
15+
Double,
16+
17+
// if signed, then the inner value is true
18+
Int(bool),
19+
Char(bool),
20+
Short(bool),
1721
Poly,
1822
Void,
1923
}
@@ -25,9 +29,10 @@ impl FromStr for TypeKind {
2529
match s {
2630
"bfloat" => Ok(Self::BFloat),
2731
"float" => Ok(Self::Float),
28-
"int" => Ok(Self::Int),
32+
"int" => Ok(Self::Int(true)),
2933
"poly" => Ok(Self::Poly),
30-
"uint" | "unsigned" => Ok(Self::UInt),
34+
"char" => Ok(Self::Char(true)),
35+
"uint" | "unsigned" => Ok(Self::Int(false)),
3136
"void" => Ok(Self::Void),
3237
_ => Err(format!("Impossible to parse argument kind {s}")),
3338
}
@@ -42,10 +47,15 @@ impl fmt::Display for TypeKind {
4247
match self {
4348
Self::BFloat => "bfloat",
4449
Self::Float => "float",
45-
Self::Int => "int",
46-
Self::UInt => "uint",
50+
Self::Double => "double",
51+
Self::Int(true) => "int",
52+
Self::Int(false) => "uint",
4753
Self::Poly => "poly",
4854
Self::Void => "void",
55+
Self::Char(true) => "char",
56+
Self::Char(false) => "unsigned char",
57+
Self::Short(true) => "short",
58+
Self::Short(false) => "unsigned short",
4959
}
5060
)
5161
}
@@ -56,9 +66,11 @@ impl TypeKind {
5666
pub fn c_prefix(&self) -> &str {
5767
match self {
5868
Self::Float => "float",
59-
Self::Int => "int",
60-
Self::UInt => "uint",
69+
Self::Int(true) => "int",
70+
Self::Int(false) => "uint",
6171
Self::Poly => "poly",
72+
Self::Char(true) => "char",
73+
Self::Char(false) => "unsigned char",
6274
_ => unreachable!("Not used: {:#?}", self),
6375
}
6476
}
@@ -67,8 +79,8 @@ impl TypeKind {
6779
pub fn rust_prefix(&self) -> &str {
6880
match self {
6981
Self::Float => "f",
70-
Self::Int => "i",
71-
Self::UInt => "u",
82+
Self::Int(true) => "i",
83+
Self::Int(false) => "u",
7284
Self::Poly => "u",
7385
_ => unreachable!("Unused type kind: {:#?}", self),
7486
}
@@ -132,6 +144,18 @@ impl IntrinsicType {
132144
self.ptr
133145
}
134146

147+
pub fn set_bit_len(&mut self, value: Option<u32>) {
148+
self.bit_len = value;
149+
}
150+
151+
pub fn set_simd_len(&mut self, value: Option<u32>) {
152+
self.simd_len = value;
153+
}
154+
155+
pub fn set_vec_len(&mut self, value: Option<u32>) {
156+
self.vec_len = value;
157+
}
158+
135159
pub fn c_scalar_type(&self) -> String {
136160
format!(
137161
"{prefix}{bits}_t",
@@ -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(true) => "(int)",
183+
TypeKind::Int(false) => "(unsigned int)",
160184
TypeKind::Poly => "(unsigned int)(uint8_t)",
161185
_ => "",
162186
},
@@ -185,7 +209,7 @@ impl IntrinsicType {
185209
match self {
186210
IntrinsicType {
187211
bit_len: Some(bit_len @ (8 | 16 | 32 | 64)),
188-
kind: kind @ (TypeKind::Int | TypeKind::UInt | TypeKind::Poly),
212+
kind: kind @ (TypeKind::Int(_) | TypeKind::Poly),
189213
simd_len,
190214
vec_len,
191215
..
@@ -201,7 +225,7 @@ impl IntrinsicType {
201225
.format_with(",\n", |i, fmt| {
202226
let src = value_for_array(*bit_len, i);
203227
assert!(src == 0 || src.ilog2() < *bit_len);
204-
if *kind == TypeKind::Int && (src >> (*bit_len - 1)) != 0 {
228+
if *kind == TypeKind::Int(true) && (src >> (*bit_len - 1)) != 0 {
205229
// `src` is a two's complement representation of a negative value.
206230
let mask = !0u64 >> (64 - *bit_len);
207231
let ones_compl = src ^ mask;
@@ -257,7 +281,7 @@ impl IntrinsicType {
257281
..
258282
} => false,
259283
IntrinsicType {
260-
kind: TypeKind::Int | TypeKind::UInt | TypeKind::Poly,
284+
kind: TypeKind::Int(_) | TypeKind::Poly,
261285
..
262286
} => true,
263287
_ => unimplemented!(),

crates/intrinsic-test/src/x86/xml_parser.rs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -105,26 +105,33 @@ fn xml_to_intrinsic(
105105
let name = intr.name;
106106
let results = X86IntrinsicType::from_c(&intr.return_data.type_data, target)?;
107107

108-
let args: Vec<_> = intr
109-
.parameters
110-
.into_iter()
111-
.enumerate()
112-
.map(|(i, param)| {
113-
let constraint = None;
114-
let ty = X86IntrinsicType::from_c(param.type_data.as_str(), target)
115-
.unwrap_or_else(|_| panic!("Failed to parse argument '{i}'"));
116-
117-
let mut arg = Argument::<X86IntrinsicType>::new(i, param.var_name, ty, constraint);
118-
let IntrinsicType {
119-
ref mut constant, ..
120-
} = arg.ty.0;
121-
if param.etype == "IMM" {
122-
*constant = true
123-
}
124-
arg
125-
})
126-
.collect();
127-
108+
let args_check = intr.parameters.into_iter().enumerate().map(|(i, param)| {
109+
let constraint = None;
110+
let ty = X86IntrinsicType::from_c(param.type_data.as_str(), target);
111+
112+
if let Err(_) = ty {
113+
return None;
114+
}
115+
let mut ty_bit_len = param.etype.clone();
116+
ty_bit_len.retain(|c| c.is_numeric());
117+
let ty_bit_len = str::parse::<u32>(ty_bit_len.as_str()).ok();
118+
let mut ty = ty.unwrap();
119+
ty.set_bit_len(ty_bit_len);
120+
let mut arg = Argument::<X86IntrinsicType>::new(i, param.var_name, ty, constraint);
121+
let IntrinsicType {
122+
ref mut constant, ..
123+
} = arg.ty.0;
124+
if param.etype == "IMM" {
125+
*constant = true
126+
}
127+
Some(arg)
128+
});
129+
130+
let args = args_check.collect::<Vec<_>>();
131+
if args.iter().any(|elem| elem.is_none()) {
132+
return Err(Box::from("intrinsic isn't fully supported in this test!"));
133+
}
134+
let args = args.into_iter().map(|e| e.unwrap()).collect::<Vec<_>>();
128135
let arguments = ArgumentList::<X86IntrinsicType> { args };
129136

130137
Ok(Intrinsic {

0 commit comments

Comments
 (0)