Skip to content

Commit 071373d

Browse files
authored
Merge pull request #1895 from madhav-madhusoodanan/intrinsic-test-intrinsictype-cleanup
`intrinsic-test`: Cleaning the `IntrinsicType` struct and related functionalities
2 parents 7302715 + bc64faf commit 071373d

File tree

6 files changed

+50
-52
lines changed

6 files changed

+50
-52
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@ use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, S
55
use std::ops::{Deref, DerefMut};
66

77
#[derive(Debug, Clone, PartialEq)]
8-
pub struct ArmIntrinsicType(pub IntrinsicType);
8+
pub struct ArmIntrinsicType {
9+
pub data: IntrinsicType,
10+
pub target: String,
11+
}
912

1013
impl Deref for ArmIntrinsicType {
1114
type Target = IntrinsicType;
1215

1316
fn deref(&self) -> &Self::Target {
14-
&self.0
17+
&self.data
1518
}
1619
}
1720

1821
impl DerefMut for ArmIntrinsicType {
1922
fn deref_mut(&mut self) -> &mut Self::Target {
20-
&mut self.0
23+
&mut self.data
2124
}
2225
}
2326

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::intrinsic::ArmIntrinsicType;
22
use crate::common::argument::{Argument, ArgumentList};
33
use crate::common::constraint::Constraint;
44
use crate::common::intrinsic::Intrinsic;
5-
use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition};
5+
use crate::common::intrinsic_helpers::IntrinsicType;
66
use serde::Deserialize;
77
use serde_json::Value;
88
use std::collections::HashMap;
@@ -100,7 +100,7 @@ fn json_to_intrinsic(
100100
// The JSON doesn't list immediates as const
101101
let IntrinsicType {
102102
ref mut constant, ..
103-
} = arg.ty.0;
103+
} = arg.ty.data;
104104
if arg.name.starts_with("imm") {
105105
*constant = true
106106
}

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ use std::fs::{self, File};
99

1010
use rayon::prelude::*;
1111

12-
use crate::arm::config::POLY128_OSTREAM_DEF;
13-
use crate::common::SupportedArchitectureTest;
1412
use crate::common::cli::ProcessedCli;
1513
use crate::common::compare::compare_outputs;
1614
use crate::common::gen_c::{write_main_cpp, write_mod_cpp};
@@ -19,7 +17,8 @@ use crate::common::gen_rust::{
1917
};
2018
use crate::common::intrinsic::Intrinsic;
2119
use crate::common::intrinsic_helpers::TypeKind;
22-
use config::{AARCH_CONFIGURATIONS, F16_FORMATTING_DEF, build_notices};
20+
use crate::common::{SupportedArchitectureTest, chunk_info};
21+
use config::{AARCH_CONFIGURATIONS, F16_FORMATTING_DEF, POLY128_OSTREAM_DEF, build_notices};
2322
use intrinsic::ArmIntrinsicType;
2423
use json_parser::get_neon_intrinsics;
2524

@@ -28,13 +27,6 @@ pub struct ArmArchitectureTest {
2827
cli_options: ProcessedCli,
2928
}
3029

31-
fn chunk_info(intrinsic_count: usize) -> (usize, usize) {
32-
let available_parallelism = std::thread::available_parallelism().unwrap().get();
33-
let chunk_size = intrinsic_count.div_ceil(Ord::min(available_parallelism, intrinsic_count));
34-
35-
(chunk_size, intrinsic_count.div_ceil(chunk_size))
36-
}
37-
3830
impl SupportedArchitectureTest for ArmArchitectureTest {
3931
fn create(cli_options: ProcessedCli) -> Box<Self> {
4032
let a32 = cli_options.target.contains("v7");

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

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, S
55
impl IntrinsicTypeDefinition for ArmIntrinsicType {
66
/// Gets a string containing the typename for this type in C format.
77
fn c_type(&self) -> String {
8-
let prefix = self.0.kind.c_prefix();
9-
let const_prefix = if self.0.constant { "const " } else { "" };
8+
let prefix = self.kind.c_prefix();
9+
let const_prefix = if self.constant { "const " } else { "" };
1010

11-
if let (Some(bit_len), simd_len, vec_len) =
12-
(self.0.bit_len, self.0.simd_len, self.0.vec_len)
13-
{
11+
if let (Some(bit_len), simd_len, vec_len) = (self.bit_len, self.simd_len, self.vec_len) {
1412
match (simd_len, vec_len) {
1513
(None, None) => format!("{const_prefix}{prefix}{bit_len}_t"),
1614
(Some(simd), None) => format!("{prefix}{bit_len}x{simd}_t"),
@@ -23,10 +21,10 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
2321
}
2422

2523
fn c_single_vector_type(&self) -> String {
26-
if let (Some(bit_len), Some(simd_len)) = (self.0.bit_len, self.0.simd_len) {
24+
if let (Some(bit_len), Some(simd_len)) = (self.bit_len, self.simd_len) {
2725
format!(
2826
"{prefix}{bit_len}x{simd_len}_t",
29-
prefix = self.0.kind.c_prefix()
27+
prefix = self.kind.c_prefix()
3028
)
3129
} else {
3230
unreachable!("Shouldn't be called on this type")
@@ -40,17 +38,16 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
4038
bit_len: Some(bl),
4139
simd_len,
4240
vec_len,
43-
target,
4441
..
45-
} = &self.0
42+
} = &self.data
4643
{
4744
let quad = if simd_len.unwrap_or(1) * bl > 64 {
4845
"q"
4946
} else {
5047
""
5148
};
5249

53-
let choose_workaround = language == Language::C && target.contains("v7");
50+
let choose_workaround = language == Language::C && self.target.contains("v7");
5451
format!(
5552
"vld{len}{quad}_{type}{size}",
5653
type = match k {
@@ -78,7 +75,7 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
7875
bit_len: Some(bl),
7976
simd_len,
8077
..
81-
} = &self.0
78+
} = &self.data
8279
{
8380
let quad = if (simd_len.unwrap_or(1) * bl) > 64 {
8481
"q"
@@ -101,8 +98,10 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
10198
todo!("get_lane_function IntrinsicType: {:#?}", self)
10299
}
103100
}
101+
}
104102

105-
fn from_c(s: &str, target: &str) -> Result<Self, String> {
103+
impl ArmIntrinsicType {
104+
pub fn from_c(s: &str, target: &str) -> Result<Self, String> {
106105
const CONST_STR: &str = "const";
107106
if let Some(s) = s.strip_suffix('*') {
108107
let (s, constant) = match s.trim().strip_suffix(CONST_STR) {
@@ -143,32 +142,36 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
143142
),
144143
None => None,
145144
};
146-
Ok(ArmIntrinsicType(IntrinsicType {
147-
ptr: false,
148-
ptr_constant: false,
149-
constant,
150-
kind: arg_kind,
151-
bit_len: Some(bit_len),
152-
simd_len,
153-
vec_len,
145+
Ok(ArmIntrinsicType {
146+
data: IntrinsicType {
147+
ptr: false,
148+
ptr_constant: false,
149+
constant,
150+
kind: arg_kind,
151+
bit_len: Some(bit_len),
152+
simd_len,
153+
vec_len,
154+
},
154155
target: target.to_string(),
155-
}))
156+
})
156157
} else {
157158
let kind = start.parse::<TypeKind>()?;
158159
let bit_len = match kind {
159160
TypeKind::Int(_) => Some(32),
160161
_ => None,
161162
};
162-
Ok(ArmIntrinsicType(IntrinsicType {
163-
ptr: false,
164-
ptr_constant: false,
165-
constant,
166-
kind: start.parse::<TypeKind>()?,
167-
bit_len,
168-
simd_len: None,
169-
vec_len: None,
163+
Ok(ArmIntrinsicType {
164+
data: IntrinsicType {
165+
ptr: false,
166+
ptr_constant: false,
167+
constant,
168+
kind: start.parse::<TypeKind>()?,
169+
bit_len,
170+
simd_len: None,
171+
vec_len: None,
172+
},
170173
target: target.to_string(),
171-
}))
174+
})
172175
}
173176
}
174177
}

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ pub struct IntrinsicType {
120120
/// rows encoded in the type (e.g. uint8x8_t).
121121
/// A value of `None` can be assumed to be 1 though.
122122
pub vec_len: Option<u32>,
123-
124-
pub target: String,
125123
}
126124

127125
impl IntrinsicType {
@@ -321,11 +319,6 @@ pub trait IntrinsicTypeDefinition: Deref<Target = IntrinsicType> {
321319
/// can be implemented in an `impl` block
322320
fn get_lane_function(&self) -> String;
323321

324-
/// can be implemented in an `impl` block
325-
fn from_c(_s: &str, _target: &str) -> Result<Self, String>
326-
where
327-
Self: Sized;
328-
329322
/// Gets a string containing the typename for this type in C format.
330323
/// can be directly defined in `impl` blocks
331324
fn c_type(&self) -> String;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,10 @@ pub trait SupportedArchitectureTest {
2222
fn build_rust_file(&self) -> bool;
2323
fn compare_outputs(&self) -> bool;
2424
}
25+
26+
pub fn chunk_info(intrinsic_count: usize) -> (usize, usize) {
27+
let available_parallelism = std::thread::available_parallelism().unwrap().get();
28+
let chunk_size = intrinsic_count.div_ceil(Ord::min(available_parallelism, intrinsic_count));
29+
30+
(chunk_size, intrinsic_count.div_ceil(chunk_size))
31+
}

0 commit comments

Comments
 (0)