Skip to content

intrinsic-test: Cleaning the IntrinsicType struct and related functionalities #1895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions crates/intrinsic-test/src/arm/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@ use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, S
use std::ops::{Deref, DerefMut};

#[derive(Debug, Clone, PartialEq)]
pub struct ArmIntrinsicType(pub IntrinsicType);
pub struct ArmIntrinsicType {
pub data: IntrinsicType,
pub target: String,
}

impl Deref for ArmIntrinsicType {
type Target = IntrinsicType;

fn deref(&self) -> &Self::Target {
&self.0
&self.data
}
}

impl DerefMut for ArmIntrinsicType {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
&mut self.data
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/intrinsic-test/src/arm/json_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::intrinsic::ArmIntrinsicType;
use crate::common::argument::{Argument, ArgumentList};
use crate::common::constraint::Constraint;
use crate::common::intrinsic::Intrinsic;
use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition};
use crate::common::intrinsic_helpers::IntrinsicType;
use serde::Deserialize;
use serde_json::Value;
use std::collections::HashMap;
Expand Down Expand Up @@ -100,7 +100,7 @@ fn json_to_intrinsic(
// The JSON doesn't list immediates as const
let IntrinsicType {
ref mut constant, ..
} = arg.ty.0;
} = arg.ty.data;
if arg.name.starts_with("imm") {
*constant = true
}
Expand Down
12 changes: 2 additions & 10 deletions crates/intrinsic-test/src/arm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use std::fs::{self, File};

use rayon::prelude::*;

use crate::arm::config::POLY128_OSTREAM_DEF;
use crate::common::SupportedArchitectureTest;
use crate::common::cli::ProcessedCli;
use crate::common::compare::compare_outputs;
use crate::common::gen_c::{write_main_cpp, write_mod_cpp};
Expand All @@ -19,7 +17,8 @@ use crate::common::gen_rust::{
};
use crate::common::intrinsic::Intrinsic;
use crate::common::intrinsic_helpers::TypeKind;
use config::{AARCH_CONFIGURATIONS, F16_FORMATTING_DEF, build_notices};
use crate::common::{SupportedArchitectureTest, chunk_info};
use config::{AARCH_CONFIGURATIONS, F16_FORMATTING_DEF, POLY128_OSTREAM_DEF, build_notices};
use intrinsic::ArmIntrinsicType;
use json_parser::get_neon_intrinsics;

Expand All @@ -28,13 +27,6 @@ pub struct ArmArchitectureTest {
cli_options: ProcessedCli,
}

fn chunk_info(intrinsic_count: usize) -> (usize, usize) {
let available_parallelism = std::thread::available_parallelism().unwrap().get();
let chunk_size = intrinsic_count.div_ceil(Ord::min(available_parallelism, intrinsic_count));

(chunk_size, intrinsic_count.div_ceil(chunk_size))
}

impl SupportedArchitectureTest for ArmArchitectureTest {
fn create(cli_options: ProcessedCli) -> Box<Self> {
let a32 = cli_options.target.contains("v7");
Expand Down
63 changes: 33 additions & 30 deletions crates/intrinsic-test/src/arm/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, S
impl IntrinsicTypeDefinition for ArmIntrinsicType {
/// Gets a string containing the typename for this type in C format.
fn c_type(&self) -> String {
let prefix = self.0.kind.c_prefix();
let const_prefix = if self.0.constant { "const " } else { "" };
let prefix = self.kind.c_prefix();
let const_prefix = if self.constant { "const " } else { "" };

if let (Some(bit_len), simd_len, vec_len) =
(self.0.bit_len, self.0.simd_len, self.0.vec_len)
{
if let (Some(bit_len), simd_len, vec_len) = (self.bit_len, self.simd_len, self.vec_len) {
match (simd_len, vec_len) {
(None, None) => format!("{const_prefix}{prefix}{bit_len}_t"),
(Some(simd), None) => format!("{prefix}{bit_len}x{simd}_t"),
Expand All @@ -23,10 +21,10 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
}

fn c_single_vector_type(&self) -> String {
if let (Some(bit_len), Some(simd_len)) = (self.0.bit_len, self.0.simd_len) {
if let (Some(bit_len), Some(simd_len)) = (self.bit_len, self.simd_len) {
format!(
"{prefix}{bit_len}x{simd_len}_t",
prefix = self.0.kind.c_prefix()
prefix = self.kind.c_prefix()
)
} else {
unreachable!("Shouldn't be called on this type")
Expand All @@ -40,17 +38,16 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
bit_len: Some(bl),
simd_len,
vec_len,
target,
..
} = &self.0
} = &self.data
{
let quad = if simd_len.unwrap_or(1) * bl > 64 {
"q"
} else {
""
};

let choose_workaround = language == Language::C && target.contains("v7");
let choose_workaround = language == Language::C && self.target.contains("v7");
format!(
"vld{len}{quad}_{type}{size}",
type = match k {
Expand Down Expand Up @@ -78,7 +75,7 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
bit_len: Some(bl),
simd_len,
..
} = &self.0
} = &self.data
{
let quad = if (simd_len.unwrap_or(1) * bl) > 64 {
"q"
Expand All @@ -101,8 +98,10 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
todo!("get_lane_function IntrinsicType: {:#?}", self)
}
}
}

fn from_c(s: &str, target: &str) -> Result<Self, String> {
impl ArmIntrinsicType {
pub fn from_c(s: &str, target: &str) -> Result<Self, String> {
const CONST_STR: &str = "const";
if let Some(s) = s.strip_suffix('*') {
let (s, constant) = match s.trim().strip_suffix(CONST_STR) {
Expand Down Expand Up @@ -143,32 +142,36 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
),
None => None,
};
Ok(ArmIntrinsicType(IntrinsicType {
ptr: false,
ptr_constant: false,
constant,
kind: arg_kind,
bit_len: Some(bit_len),
simd_len,
vec_len,
Ok(ArmIntrinsicType {
data: IntrinsicType {
ptr: false,
ptr_constant: false,
constant,
kind: arg_kind,
bit_len: Some(bit_len),
simd_len,
vec_len,
},
target: target.to_string(),
}))
})
} else {
let kind = start.parse::<TypeKind>()?;
let bit_len = match kind {
TypeKind::Int(_) => Some(32),
_ => None,
};
Ok(ArmIntrinsicType(IntrinsicType {
ptr: false,
ptr_constant: false,
constant,
kind: start.parse::<TypeKind>()?,
bit_len,
simd_len: None,
vec_len: None,
Ok(ArmIntrinsicType {
data: IntrinsicType {
ptr: false,
ptr_constant: false,
constant,
kind: start.parse::<TypeKind>()?,
bit_len,
simd_len: None,
vec_len: None,
},
target: target.to_string(),
}))
})
}
}
}
Expand Down
7 changes: 0 additions & 7 deletions crates/intrinsic-test/src/common/intrinsic_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ pub struct IntrinsicType {
/// rows encoded in the type (e.g. uint8x8_t).
/// A value of `None` can be assumed to be 1 though.
pub vec_len: Option<u32>,

pub target: String,
}

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

/// can be implemented in an `impl` block
fn from_c(_s: &str, _target: &str) -> Result<Self, String>
where
Self: Sized;

/// Gets a string containing the typename for this type in C format.
/// can be directly defined in `impl` blocks
fn c_type(&self) -> String;
Expand Down
7 changes: 7 additions & 0 deletions crates/intrinsic-test/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ pub trait SupportedArchitectureTest {
fn build_rust_file(&self) -> bool;
fn compare_outputs(&self) -> bool;
}

pub fn chunk_info(intrinsic_count: usize) -> (usize, usize) {
let available_parallelism = std::thread::available_parallelism().unwrap().get();
let chunk_size = intrinsic_count.div_ceil(Ord::min(available_parallelism, intrinsic_count));

(chunk_size, intrinsic_count.div_ceil(chunk_size))
}