Skip to content

Commit e86b274

Browse files
feat: added a skeletal structure for loongarch in intrinsic-test
1 parent 071373d commit e86b274

File tree

5 files changed

+191
-0
lines changed

5 files changed

+191
-0
lines changed

crates/intrinsic-test/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ pretty_env_logger = "0.5.0"
1919
rayon = "1.5.0"
2020
diff = "0.1.12"
2121
itertools = "0.14.0"
22+
regex = "1.11.1"
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use crate::common::argument::ArgumentList;
2+
use crate::common::indentation::Indentation;
3+
use crate::common::intrinsic::{Intrinsic, IntrinsicDefinition};
4+
use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, Sign, TypeKind};
5+
use std::ops::{Deref, DerefMut};
6+
7+
#[derive(Debug, Clone, PartialEq)]
8+
pub struct LoongArchIntrinsicType(pub IntrinsicType);
9+
10+
impl Deref for LoongArchIntrinsicType {
11+
type Target = IntrinsicType;
12+
13+
fn deref(&self) -> &Self::Target {
14+
&self.0
15+
}
16+
}
17+
18+
impl DerefMut for LoongArchIntrinsicType {
19+
fn deref_mut(&mut self) -> &mut Self::Target {
20+
&mut self.0
21+
}
22+
}
23+
24+
impl IntrinsicDefinition<LoongArchIntrinsicType> for Intrinsic<LoongArchIntrinsicType> {
25+
fn arguments(&self) -> ArgumentList<LoongArchIntrinsicType> {
26+
self.arguments.clone()
27+
}
28+
29+
fn results(&self) -> LoongArchIntrinsicType {
30+
self.results.clone()
31+
}
32+
33+
fn name(&self) -> String {
34+
self.name.clone()
35+
}
36+
37+
/// Generates a std::cout for the intrinsics results that will match the
38+
/// rust debug output format for the return type. The generated line assumes
39+
/// there is an int i in scope which is the current pass number.
40+
fn print_result_c(&self, indentation: Indentation, additional: &str) -> String {
41+
unimplemented!("print_result_c of IntrinsicDefinition<LoongArchIntrinsicType> is not defined!")
42+
}
43+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
mod intrinsic;
2+
mod types;
3+
4+
use std::fs::{self, File};
5+
6+
use rayon::prelude::*;
7+
8+
use crate::common::SupportedArchitectureTest;
9+
use crate::common::cli::ProcessedCli;
10+
use crate::common::compare::compare_outputs;
11+
12+
use crate::common::intrinsic::Intrinsic;
13+
use intrinsic::LoongArchIntrinsicType;
14+
15+
pub struct LoongArchArchitectureTest {
16+
intrinsics: Vec<Intrinsic<LoongArchIntrinsicType>>,
17+
cli_options: ProcessedCli,
18+
}
19+
20+
impl SupportedArchitectureTest for LoongArchArchitectureTest {
21+
fn create(cli_options: ProcessedCli) -> Box<Self> {
22+
unimplemented!("create of LoongArchIntrinsicType is not defined!")
23+
}
24+
25+
fn build_c_file(&self) -> bool {
26+
unimplemented!("build_c_file of LoongArchIntrinsicType is not defined!")
27+
}
28+
29+
fn build_rust_file(&self) -> bool {
30+
unimplemented!("build_rust_file of LoongArchIntrinsicType is not defined!")
31+
}
32+
33+
fn compare_outputs(&self) -> bool {
34+
if self.cli_options.toolchain.is_some() {
35+
let intrinsics_name_list = self
36+
.intrinsics
37+
.iter()
38+
.map(|i| i.name.clone())
39+
.collect::<Vec<_>>();
40+
41+
compare_outputs(
42+
&intrinsics_name_list,
43+
&self.cli_options.runner,
44+
&self.cli_options.target,
45+
)
46+
} else {
47+
true
48+
}
49+
}
50+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
use super::intrinsic::LoongArchIntrinsicType;
2+
use crate::common::cli::Language;
3+
use crate::common::intrinsic_helpers::IntrinsicTypeDefinition;
4+
5+
impl IntrinsicTypeDefinition for LoongArchIntrinsicType {
6+
/// Gets a string containing the type in C format.
7+
/// This function assumes that this value is present in the metadata hashmap.
8+
fn c_type(&self) -> String {
9+
unimplemented!("c_type for LoongArchIntrinsicType is not implemented!")
10+
}
11+
12+
fn c_single_vector_type(&self) -> String {
13+
unimplemented!("c_single_vector_type for LoongArchIntrinsicType is not implemented!")
14+
}
15+
16+
// fn rust_type(&self) -> String {
17+
// // handling edge cases first
18+
// // the general handling is implemented below
19+
// if let Some(val) = self.metadata.get("type") {
20+
// match val.as_str() {
21+
// "__m128 const *" => {
22+
// return "&__m128".to_string();
23+
// }
24+
// "__m128d const *" => {
25+
// return "&__m128d".to_string();
26+
// }
27+
// "const void*" => {
28+
// return "&__m128d".to_string();
29+
// }
30+
// _ => {}
31+
// }
32+
// }
33+
34+
// if self.kind() == TypeKind::Void && self.ptr {
35+
// // this has been handled by default settings in
36+
// // the from_param function of X86IntrinsicType
37+
// unreachable!()
38+
// }
39+
40+
// // general handling cases
41+
// let core_part = if self.kind() == TypeKind::Mask {
42+
// // all types of __mmask<int> are handled here
43+
// format!("__mask{}", self.bit_len.unwrap())
44+
// } else if self.simd_len.is_some() {
45+
// // all types of __m<int> vector types are handled here
46+
// let re = Regex::new(r"\__m\d+[a-z]*").unwrap();
47+
// let rust_type = self
48+
// .metadata
49+
// .get("type")
50+
// .map(|val| re.find(val).unwrap().as_str());
51+
// rust_type.unwrap().to_string()
52+
// } else {
53+
// format!(
54+
// "{}{}",
55+
// self.kind.rust_prefix().to_string(),
56+
// self.bit_len.unwrap()
57+
// )
58+
// };
59+
60+
// // extracting "memsize" so that even vector types can be involved
61+
// let memwidth = self
62+
// .metadata
63+
// .get("memwidth")
64+
// .map(|n| str::parse::<u32>(n).unwrap());
65+
// let prefix_part = if self.ptr && self.constant && self.bit_len.eq(&memwidth) {
66+
// "&"
67+
// } else if self.ptr && self.bit_len.eq(&memwidth) {
68+
// "&mut "
69+
// } else if self.ptr && self.constant {
70+
// "*const "
71+
// } else if self.ptr {
72+
// "*mut "
73+
// } else {
74+
// ""
75+
// };
76+
77+
// return prefix_part.to_string() + core_part.as_str();
78+
// }
79+
80+
/// Determines the load function for this type.
81+
fn get_load_function(&self, _language: Language) -> String {
82+
unimplemented!("get_load_function for LoongArchIntrinsicType is not implemented!")
83+
}
84+
85+
/// Determines the get lane function for this type.
86+
fn get_lane_function(&self) -> String {
87+
todo!("get_lane_function for LoongArchIntrinsicType needs to be implemented!");
88+
}
89+
90+
fn from_c(s: &str, target: &str) -> Result<Self, String> {
91+
todo!("from_c for LoongArchIntrinsicType needs to be implemented!");
92+
}
93+
}

crates/intrinsic-test/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ extern crate log;
33

44
mod arm;
55
mod common;
6+
mod loongarch;
67

78
use arm::ArmArchitectureTest;
9+
use loongarch::LoongArchArchitectureTest;
10+
811
use common::SupportedArchitectureTest;
912
use common::cli::{Cli, ProcessedCli};
1013

@@ -21,6 +24,7 @@ fn main() {
2124
Some(ArmArchitectureTest::create(processed_cli_options))
2225
}
2326

27+
"loongarch64-unknown-linux-gnu" => Some(LoongArchArchitectureTest::create(processed_cli_options)),
2428
_ => None,
2529
};
2630

0 commit comments

Comments
 (0)