Skip to content

Commit f3f87f2

Browse files
fix: more support for Mask types
1 parent 8fc09ee commit f3f87f2

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl IntrinsicType {
131131
if let Some(bl) = self.bit_len {
132132
bl
133133
} else {
134-
unreachable!("")
134+
unreachable!("{:#?}", self)
135135
}
136136
}
137137

@@ -222,7 +222,7 @@ impl IntrinsicType {
222222
match self {
223223
IntrinsicType {
224224
bit_len: Some(bit_len @ (8 | 16 | 32 | 64)),
225-
kind: kind @ (TypeKind::Int(_) | TypeKind::Poly | TypeKind::Char(_)),
225+
kind: kind @ (TypeKind::Int(_) | TypeKind::Poly | TypeKind::Char(_) | TypeKind::Mask),
226226
simd_len,
227227
vec_len,
228228
..

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use itertools::Itertools;
55
use regex::Regex;
66

77
use super::intrinsic::X86IntrinsicType;
8+
use crate::common::argument::Argument;
89
use crate::common::cli::Language;
910
use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, Sign, TypeKind};
1011
use crate::x86::xml_parser::Parameter;
@@ -18,7 +19,7 @@ impl IntrinsicTypeDefinition for X86IntrinsicType {
1819

1920
fn c_single_vector_type(&self) -> String {
2021
// matches __m128, __m256 and similar types
21-
let re = Regex::new(r"\__m\d+\").unwrap();
22+
let re = Regex::new(r"__m\d+").unwrap();
2223
if re.is_match(self.param.type_data.as_str()) {
2324
self.param.type_data.clone()
2425
} else {
@@ -129,8 +130,6 @@ impl IntrinsicTypeDefinition for X86IntrinsicType {
129130
impl X86IntrinsicType {
130131
fn from_c(s: &str) -> Result<IntrinsicType, String> {
131132
let mut s_copy = s.to_string();
132-
let mut metadata: HashMap<String, String> = HashMap::new();
133-
metadata.insert("type".to_string(), s.to_string());
134133
s_copy = s_copy
135134
.replace("*", "")
136135
.replace("_", "")
@@ -195,6 +194,9 @@ impl X86IntrinsicType {
195194

196195
let mut etype_processed = param.etype.clone();
197196
etype_processed.retain(|c| c.is_numeric());
197+
198+
let mut type_processed = param.type_data.clone();
199+
type_processed.retain(|c| c.is_numeric());
198200

199201
match str::parse::<u32>(etype_processed.as_str()) {
200202
Ok(value) => data.bit_len = Some(value),
@@ -208,15 +210,17 @@ impl X86IntrinsicType {
208210
};
209211
}
210212
}
213+
214+
if param.type_data.matches("__mmask").next().is_some() {
215+
data.bit_len = str::parse::<u32>(type_processed.as_str()).ok();
216+
}
211217

212218
// then check the param.type and extract numeric part if there are double
213219
// underscores. divide this number with bit-len and set this as simd-len.
214220
// Only __m<int> types can have a simd-len.
215221
if param.type_data.matches("__m").next().is_some()
216222
&& param.type_data.matches("__mmask").next().is_none()
217223
{
218-
let mut type_processed = param.type_data.clone();
219-
type_processed.retain(|c| c.is_numeric());
220224
data.vec_len = match str::parse::<u32>(type_processed.as_str()) {
221225
// If bit_len is None, vec_len will be None.
222226
// Else vec_len will be (num_bits / bit_len).
@@ -235,7 +239,6 @@ impl X86IntrinsicType {
235239
// if param.etype == IMM, then it is a constant.
236240
// else it stays unchanged.
237241
data.constant |= param.etype == "IMM";
238-
239242
Ok(X86IntrinsicType {
240243
data,
241244
param: param.clone(),

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::x86::constraint::map_constraints;
55

66
use serde::{Deserialize, Deserializer};
77
use std::path::Path;
8+
use regex::Regex;
89

910
use super::intrinsic::X86IntrinsicType;
1011

@@ -96,11 +97,24 @@ fn xml_to_intrinsic(
9697
if args.iter().any(|elem| elem.is_none()) {
9798
return Err(Box::from("intrinsic isn't fully supported in this test!"));
9899
}
99-
let args = args
100+
let mut args = args
100101
.into_iter()
101102
.map(|e| e.unwrap())
102103
.filter(|arg| arg.ty.ptr || arg.ty.kind != TypeKind::Void)
103104
.collect::<Vec<_>>();
105+
106+
let mut args_test = args.iter();
107+
108+
// if one of the args has etype="MASK" and type="__m<int>d",
109+
// then set the bit_len and vec_len accordingly
110+
let re = Regex::new(r"__m\d+").unwrap();
111+
let is_mask = |arg: &Argument<X86IntrinsicType>| arg.ty.param.etype.as_str() == "MASK";
112+
let is_vector = |arg: &Argument<X86IntrinsicType>| re.is_match(arg.ty.param.type_data.as_str());
113+
let pos = args_test.position(|arg| is_mask(arg) && is_vector(arg));
114+
if let Some(index) = pos {
115+
args[index].ty.bit_len = args[0].ty.bit_len;
116+
}
117+
104118
let arguments = ArgumentList::<X86IntrinsicType> { args };
105119

106120
if let Err(message) = result {

0 commit comments

Comments
 (0)