Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore: Move from IntrinsicType::target to intrinsicType::metadata to
support architecture-specific use cases
  • Loading branch information
madhav-madhusoodanan committed Jul 26, 2025
commit 17f35f4898fda7a9377c3753eacb93624f00e3d7
12 changes: 12 additions & 0 deletions crates/intrinsic-test/src/arm/argument.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::arm::intrinsic::ArmIntrinsicType;
use crate::common::argument::Argument;

impl Argument<ArmIntrinsicType> {
pub fn type_and_name_from_c(arg: &str) -> (&str, &str) {
let split_index = arg
.rfind([' ', '*'])
.expect("Couldn't split type and argname");

(arg[..split_index + 1].trim_end(), &arg[split_index + 1..])
}
}
17 changes: 11 additions & 6 deletions crates/intrinsic-test/src/arm/json_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,25 @@ fn json_to_intrinsic(
) -> Result<Intrinsic<ArmIntrinsicType>, Box<dyn std::error::Error>> {
let name = intr.name.replace(['[', ']'], "");

let results = ArmIntrinsicType::from_c(&intr.return_type.value, target)?;
let mut results = ArmIntrinsicType::from_c(&intr.return_type.value)?;
results.set_metadata("target".to_string(), target.to_string());

let args = intr
.arguments
.into_iter()
.enumerate()
.map(|(i, arg)| {
let arg_name = Argument::<ArmIntrinsicType>::type_and_name_from_c(&arg).1;
let metadata = intr.args_prep.as_mut();
let metadata = metadata.and_then(|a| a.remove(arg_name));
let arg_prep: Option<ArgPrep> = metadata.and_then(|a| a.try_into().ok());
let (type_name, arg_name) = Argument::<ArmIntrinsicType>::type_and_name_from_c(&arg);
let ty = ArmIntrinsicType::from_c(type_name)
.unwrap_or_else(|_| panic!("Failed to parse argument '{arg}'"));

let arg_prep = intr.args_prep.as_mut();
let arg_prep = arg_prep.and_then(|a| a.remove(arg_name));
let arg_prep: Option<ArgPrep> = arg_prep.and_then(|a| a.try_into().ok());
let constraint: Option<Constraint> = arg_prep.and_then(|a| a.try_into().ok());

let mut arg = Argument::<ArmIntrinsicType>::from_c(i, &arg, target, constraint);
let mut arg =
Argument::<ArmIntrinsicType>::new(i, arg_name.to_string(), ty, constraint);

// The JSON doesn't list immediates as const
let IntrinsicType {
Expand Down
1 change: 1 addition & 0 deletions crates/intrinsic-test/src/arm/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod argument;
mod compile;
mod config;
mod intrinsic;
Expand Down
20 changes: 14 additions & 6 deletions crates/intrinsic-test/src/arm/types.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::HashMap;

use super::intrinsic::ArmIntrinsicType;
use crate::common::cli::Language;
use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, Sign, TypeKind};
Expand Down Expand Up @@ -40,7 +42,7 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
bit_len: Some(bl),
simd_len,
vec_len,
target,
metadata,
..
} = &self.0
{
Expand All @@ -50,7 +52,11 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
""
};

let choose_workaround = language == Language::C && target.contains("v7");
let choose_workaround = language == Language::C
&& metadata
.get("target")
.filter(|value| value.contains("v7"))
.is_some();
format!(
"vld{len}{quad}_{type}{size}",
type = match k {
Expand Down Expand Up @@ -102,15 +108,17 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
}
}

fn from_c(s: &str, target: &str) -> Result<Self, String> {
fn from_c(s: &str) -> Result<Self, String> {
const CONST_STR: &str = "const";
let mut metadata: HashMap<String, String> = HashMap::new();
metadata.insert("type".to_string(), s.to_string());
if let Some(s) = s.strip_suffix('*') {
let (s, constant) = match s.trim().strip_suffix(CONST_STR) {
Some(stripped) => (stripped, true),
None => (s, false),
};
let s = s.trim_end();
let temp_return = ArmIntrinsicType::from_c(s, target);
let temp_return = ArmIntrinsicType::from_c(s);
temp_return.map(|mut op| {
op.ptr = true;
op.ptr_constant = constant;
Expand Down Expand Up @@ -151,7 +159,7 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
bit_len: Some(bit_len),
simd_len,
vec_len,
target: target.to_string(),
metadata,
}))
} else {
let kind = start.parse::<TypeKind>()?;
Expand All @@ -167,7 +175,7 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
bit_len,
simd_len: None,
vec_len: None,
target: target.to_string(),
metadata,
}))
}
}
Expand Down
36 changes: 9 additions & 27 deletions crates/intrinsic-test/src/common/argument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ impl<T> Argument<T>
where
T: IntrinsicTypeDefinition,
{
pub fn new(pos: usize, name: String, ty: T, constraint: Option<Constraint>) -> Self {
Argument {
pos,
name,
ty,
constraint,
}
}

pub fn to_c_type(&self) -> String {
self.ty.c_type()
}
Expand All @@ -36,14 +45,6 @@ where
self.constraint.is_some()
}

pub fn type_and_name_from_c(arg: &str) -> (&str, &str) {
let split_index = arg
.rfind([' ', '*'])
.expect("Couldn't split type and argname");

(arg[..split_index + 1].trim_end(), &arg[split_index + 1..])
}

/// The binding keyword (e.g. "const" or "let") for the array of possible test inputs.
fn rust_vals_array_binding(&self) -> impl std::fmt::Display {
if self.ty.is_rust_vals_array_const() {
Expand All @@ -62,25 +63,6 @@ where
}
}

pub fn from_c(
pos: usize,
arg: &str,
target: &str,
constraint: Option<Constraint>,
) -> Argument<T> {
let (ty, var_name) = Self::type_and_name_from_c(arg);

let ty =
T::from_c(ty, target).unwrap_or_else(|_| panic!("Failed to parse argument '{arg}'"));

Argument {
pos,
name: String::from(var_name),
ty: ty,
constraint,
}
}

fn as_call_param_c(&self) -> String {
self.ty.as_call_param_c(&self.name)
}
Expand Down
9 changes: 7 additions & 2 deletions crates/intrinsic-test/src/common/intrinsic_helpers.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::collections::HashMap;
use std::fmt;
use std::ops::Deref;
use std::str::FromStr;
Expand Down Expand Up @@ -121,7 +122,7 @@ pub struct IntrinsicType {
/// A value of `None` can be assumed to be 1 though.
pub vec_len: Option<u32>,

pub target: String,
pub metadata: HashMap<String, String>,
}

impl IntrinsicType {
Expand Down Expand Up @@ -153,6 +154,10 @@ impl IntrinsicType {
self.ptr
}

pub fn set_metadata(&mut self, key: String, value: String) {
self.metadata.insert(key, value);
}

pub fn c_scalar_type(&self) -> String {
match self.kind() {
TypeKind::Char(_) => String::from("char"),
Expand Down Expand Up @@ -322,7 +327,7 @@ pub trait IntrinsicTypeDefinition: Deref<Target = IntrinsicType> {
fn get_lane_function(&self) -> String;

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

Expand Down
Loading