Skip to content

Commit 7c686ef

Browse files
added target field within IntrinsicType to perform target level checking cleanly
1 parent 7b1b684 commit 7c686ef

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

Diff for: crates/intrinsic-test/src/arm/argument.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ impl Argument {
7979
}
8080

8181
// ARM-specific
82-
pub fn from_c(pos: usize, arg: &str, arg_prep: Option<ArgPrep>) -> Argument {
82+
pub fn from_c(pos: usize, arg: &str, arg_prep: Option<ArgPrep>, target: &String) -> Argument {
8383
let (ty, var_name) = Self::type_and_name_from_c(arg);
8484

85-
let ty = IntrinsicType::from_c(ty)
85+
let ty = IntrinsicType::from_c(ty, target)
8686
.unwrap_or_else(|_| panic!("Failed to parse argument '{arg}'"));
8787

8888
let constraint = arg_prep.and_then(|a| a.try_into().ok());

Diff for: crates/intrinsic-test/src/arm/json_parser.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct JsonIntrinsic {
4141
architectures: Vec<String>,
4242
}
4343

44-
pub fn get_neon_intrinsics(filename: &Path) -> Result<Vec<Intrinsic>, Box<dyn std::error::Error>> {
44+
pub fn get_neon_intrinsics(filename: &Path, target: &String) -> Result<Vec<Intrinsic>, Box<dyn std::error::Error>> {
4545
let file = std::fs::File::open(filename)?;
4646
let reader = std::io::BufReader::new(file);
4747
let json: Vec<JsonIntrinsic> = serde_json::from_reader(reader).expect("Couldn't parse JSON");
@@ -50,7 +50,7 @@ pub fn get_neon_intrinsics(filename: &Path) -> Result<Vec<Intrinsic>, Box<dyn st
5050
.into_iter()
5151
.filter_map(|intr| {
5252
if intr.simd_isa == "Neon" {
53-
Some(json_to_intrinsic(intr).expect("Couldn't parse JSON"))
53+
Some(json_to_intrinsic(intr, target).expect("Couldn't parse JSON"))
5454
} else {
5555
None
5656
}
@@ -59,10 +59,10 @@ pub fn get_neon_intrinsics(filename: &Path) -> Result<Vec<Intrinsic>, Box<dyn st
5959
Ok(parsed)
6060
}
6161

62-
fn json_to_intrinsic(mut intr: JsonIntrinsic) -> Result<Intrinsic, Box<dyn std::error::Error>> {
62+
fn json_to_intrinsic(mut intr: JsonIntrinsic, target: &String) -> Result<Intrinsic, Box<dyn std::error::Error>> {
6363
let name = intr.name.replace(['[', ']'], "");
6464

65-
let results = IntrinsicType::from_c(&intr.return_type.value)?;
65+
let results = IntrinsicType::from_c(&intr.return_type.value, target)?;
6666

6767
let mut args_prep = intr.args_prep.as_mut();
6868
let args = intr
@@ -72,7 +72,7 @@ fn json_to_intrinsic(mut intr: JsonIntrinsic) -> Result<Intrinsic, Box<dyn std::
7272
.map(|(i, arg)| {
7373
let arg_name = Argument::type_and_name_from_c(&arg).1;
7474
let arg_prep = args_prep.as_mut().and_then(|a| a.remove(arg_name));
75-
let mut arg = Argument::from_c(i, &arg, arg_prep);
75+
let mut arg = Argument::from_c(i, &arg, arg_prep, target);
7676
// The JSON doesn't list immediates as const
7777
if let IntrinsicType::Type {
7878
ref mut constant, ..

Diff for: crates/intrinsic-test/src/arm/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
2323
fn create(cli_options: ProcessedCli) -> Self {
2424
let a32 = cli_options.target.contains("v7");
2525
let mut intrinsics =
26-
get_neon_intrinsics(&cli_options.filename).expect("Error parsing input file");
26+
get_neon_intrinsics(&cli_options.filename, &cli_options.target).expect("Error parsing input file");
2727

2828
intrinsics.sort_by(|a, b| a.name.cmp(&b.name));
2929

Diff for: crates/intrinsic-test/src/arm/types.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ pub enum IntrinsicType {
9797
/// rows encoded in the type (e.g. uint8x8_t).
9898
/// A value of `None` can be assumed to be 1 though.
9999
vec_len: Option<u32>,
100+
101+
target: String,
100102
},
101103
}
102104

@@ -393,21 +395,25 @@ impl IntrinsicType {
393395
bit_len: Some(bl),
394396
simd_len,
395397
vec_len,
398+
target,
396399
..
397400
} => {
398401
let quad = if simd_len.unwrap_or(1) * bl > 64 {
399402
"q"
400403
} else {
401404
""
402405
};
406+
407+
let choose_workaround = language == Language::C && target.contains("v7");
403408
format!(
404409
"vld{len}{quad}_{type}{size}",
405410
type = match k {
406411
TypeKind::UInt => "u",
407412
TypeKind::Int => "s",
408413
TypeKind::Float => "f",
409414
// The ACLE doesn't support 64-bit polynomial loads on Armv7
410-
TypeKind::Poly => if language == Language::C && *bl == 64 {"s"} else {"p"},
415+
// if armv7 and bl == 64, use "s", else "p"
416+
TypeKind::Poly => if choose_workaround && *bl == 64 {"s"} else {"p"},
411417
x => todo!("get_load_function TypeKind: {:#?}", x),
412418
},
413419
size = bl,
@@ -462,7 +468,7 @@ impl IntrinsicType {
462468
}
463469

464470
/// ARM-specific
465-
pub fn from_c(s: &str) -> Result<IntrinsicType, String> {
471+
pub fn from_c(s: &str, target: &String) -> Result<IntrinsicType, String> {
466472
const CONST_STR: &str = "const";
467473
if let Some(s) = s.strip_suffix('*') {
468474
let (s, constant) = match s.trim().strip_suffix(CONST_STR) {
@@ -472,7 +478,7 @@ impl IntrinsicType {
472478
let s = s.trim_end();
473479
Ok(IntrinsicType::Ptr {
474480
constant,
475-
child: Box::new(IntrinsicType::from_c(s)?),
481+
child: Box::new(IntrinsicType::from_c(s, target)?),
476482
})
477483
} else {
478484
// [const ]TYPE[{bitlen}[x{simdlen}[x{vec_len}]]][_t]
@@ -507,6 +513,7 @@ impl IntrinsicType {
507513
bit_len: Some(bit_len),
508514
simd_len,
509515
vec_len,
516+
target: target.to_string(),
510517
})
511518
} else {
512519
let kind = start.parse::<TypeKind>()?;
@@ -520,6 +527,7 @@ impl IntrinsicType {
520527
bit_len,
521528
simd_len: None,
522529
vec_len: None,
530+
target: target.to_string(),
523531
})
524532
}
525533
}

0 commit comments

Comments
 (0)