Skip to content

Commit 2bef828

Browse files
committed
intrinsic-test: arg generic over arch not type
Refactoring enabling accessing architecture-specific behaviour that isn't associated with the specific argument type.
1 parent 62efe89 commit 2bef828

6 files changed

Lines changed: 20 additions & 24 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ fn json_to_intrinsic(
122122
});
123123

124124
let mut arg =
125-
Argument::<ArmType>::new(i, String::from(arg_name), ArmType(arg_ty), constraint);
125+
Argument::<Arm>::new(i, String::from(arg_name), ArmType(arg_ty), constraint);
126126

127127
// The JSON doesn't list immediates as const
128128
let IntrinsicType {
@@ -135,7 +135,7 @@ fn json_to_intrinsic(
135135
})
136136
.collect();
137137

138-
let arguments = ArgumentList::<ArmType> { args };
138+
let arguments = ArgumentList::<Arm> { args };
139139

140140
Ok(Intrinsic {
141141
name,

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use itertools::Itertools;
22

3+
use crate::common::SupportedArchitecture;
34
use crate::common::intrinsic_helpers::TypeKind;
45
use crate::common::values::test_values_array_name;
56

@@ -9,22 +10,22 @@ use super::intrinsic_helpers::TypeDefinition;
910

1011
/// An argument for the intrinsic.
1112
#[derive(Debug, PartialEq, Clone)]
12-
pub struct Argument<T: TypeDefinition> {
13+
pub struct Argument<A: SupportedArchitecture> {
1314
/// The argument's index in the intrinsic function call.
1415
pub pos: usize,
1516
/// The argument name.
1617
pub name: String,
1718
/// The type of the argument.
18-
pub ty: T,
19+
pub ty: A::Type,
1920
/// Any constraints that are on this argument
2021
pub constraint: Option<Constraint>,
2122
}
2223

23-
impl<T> Argument<T>
24+
impl<A> Argument<A>
2425
where
25-
T: TypeDefinition,
26+
A: SupportedArchitecture,
2627
{
27-
pub fn new(pos: usize, name: String, ty: T, constraint: Option<Constraint>) -> Self {
28+
pub fn new(pos: usize, name: String, ty: A::Type, constraint: Option<Constraint>) -> Self {
2829
Argument {
2930
pos,
3031
name,
@@ -63,13 +64,13 @@ where
6364

6465
/// Arguments of an intrinsic - including parameters that end up being const generics.
6566
#[derive(Debug, PartialEq, Clone)]
66-
pub struct ArgumentList<T: TypeDefinition> {
67-
pub args: Vec<Argument<T>>,
67+
pub struct ArgumentList<A: SupportedArchitecture> {
68+
pub args: Vec<Argument<A>>,
6869
}
6970

70-
impl<T> ArgumentList<T>
71+
impl<A> ArgumentList<A>
7172
where
72-
T: TypeDefinition,
73+
A: SupportedArchitecture,
7374
{
7475
/// Returns a string with the arguments in `self` as a parameter list for a wrapper fn
7576
/// definition in C (e.g. `$ty1 $arg1, $ty2 $arg2`).
@@ -196,7 +197,7 @@ where
196197
}
197198

198199
/// Returns an iterator over the contained arguments
199-
pub fn iter(&self) -> std::slice::Iter<'_, Argument<T>> {
200+
pub fn iter(&self) -> std::slice::Iter<'_, Argument<A>> {
200201
self.args.iter()
201202
}
202203
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub struct Intrinsic<A: SupportedArchitecture> {
88
pub name: String,
99

1010
/// Any arguments for this intrinsic.
11-
pub arguments: ArgumentList<A::Type>,
11+
pub arguments: ArgumentList<A>,
1212

1313
/// The return type of this intrinsic.
1414
pub results: A::Type,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl IntrinsicType {
195195
}
196196
}
197197

198-
pub trait TypeDefinition: Deref<Target = IntrinsicType> {
198+
pub trait TypeDefinition: Clone + Deref<Target = IntrinsicType> {
199199
/// Determines the load function for this type.
200200
fn get_load_function(&self) -> String;
201201

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub(crate) const PASSES: u32 = 20;
3030
/// Architectures must support this trait
3131
/// to be successfully tested.
3232
pub trait SupportedArchitecture: Sized {
33-
type Type: TypeDefinition + Sync;
33+
type Type: TypeDefinition + std::fmt::Debug + PartialEq + Sync;
3434

3535
fn intrinsics(&self) -> &[Intrinsic<Self>];
3636

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,7 @@ fn xml_to_intrinsic(intr: XMLIntrinsic) -> Result<Intrinsic<X86>, Box<dyn std::e
9999
param.imm_width
100100
};
101101
let constraint = map_constraints(&name, &param.imm_type, effective_imm_width);
102-
let arg = Argument::<X86IntrinsicType>::new(
103-
i,
104-
param.var_name.clone(),
105-
ty.unwrap(),
106-
constraint,
107-
);
102+
let arg = Argument::<X86>::new(i, param.var_name.clone(), ty.unwrap(), constraint);
108103
Some(arg)
109104
}
110105
});
@@ -124,16 +119,16 @@ fn xml_to_intrinsic(intr: XMLIntrinsic) -> Result<Intrinsic<X86>, Box<dyn std::e
124119
// if one of the args has etype="MASK" and type="__m<int>d",
125120
// then set the bit_len and simd_len accordingly
126121
let re = Regex::new(r"__m\d+").unwrap();
127-
let is_mask = |arg: &Argument<X86IntrinsicType>| arg.ty.param.etype.as_str() == "MASK";
128-
let is_vector = |arg: &Argument<X86IntrinsicType>| re.is_match(arg.ty.param.type_data.as_str());
122+
let is_mask = |arg: &Argument<X86>| arg.ty.param.etype.as_str() == "MASK";
123+
let is_vector = |arg: &Argument<X86>| re.is_match(arg.ty.param.type_data.as_str());
129124
let pos = args_test.position(|arg| is_mask(arg) && is_vector(arg));
130125
if let Some(index) = pos {
131126
args[index].ty.bit_len = args[0].ty.bit_len;
132127
}
133128

134129
args.iter_mut().for_each(|arg| arg.ty.update_simd_len());
135130

136-
let arguments = ArgumentList::<X86IntrinsicType> { args };
131+
let arguments = ArgumentList::<X86> { args };
137132

138133
if let Err(message) = result {
139134
return Err(Box::from(message));

0 commit comments

Comments
 (0)