Skip to content

Commit 4b549a7

Browse files
committed
move target-specific definitions into constants
1 parent ccec202 commit 4b549a7

File tree

5 files changed

+36
-38
lines changed

5 files changed

+36
-38
lines changed

library/stdarch/crates/intrinsic-test/src/arm/config.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@ pub const NOTICE: &str = "\
33
// test are derived from a JSON specification, published under the same license as the
44
// `intrinsic-test` crate.\n";
55

6-
pub const POLY128_OSTREAM_DEF: &str = r#"std::ostream& operator<<(std::ostream& os, poly128_t value) {
6+
pub const POLY128_OSTREAM_DECL: &str = r#"
7+
#ifdef __aarch64__
8+
std::ostream& operator<<(std::ostream& os, poly128_t value);
9+
#endif
10+
"#;
11+
12+
pub const POLY128_OSTREAM_DEF: &str = r#"
13+
#ifdef __aarch64__
14+
std::ostream& operator<<(std::ostream& os, poly128_t value) {
715
std::stringstream temp;
816
do {
917
int n = value % 10;
@@ -14,7 +22,9 @@ pub const POLY128_OSTREAM_DEF: &str = r#"std::ostream& operator<<(std::ostream&
1422
std::string res(tempstr.rbegin(), tempstr.rend());
1523
os << res;
1624
return os;
17-
}"#;
25+
}
26+
#endif
27+
"#;
1828

1929
// Format f16 values (and vectors containing them) in a way that is consistent with C.
2030
pub const F16_FORMATTING_DEF: &str = r#"
@@ -113,4 +123,10 @@ pub const AARCH_CONFIGURATIONS: &str = r#"
113123
#![cfg_attr(any(target_arch = "aarch64", target_arch = "arm64ec"), feature(stdarch_neon_ftts))]
114124
#![feature(fmt_helpers_for_derive)]
115125
#![feature(stdarch_neon_f16)]
126+
127+
#[cfg(any(target_arch = "aarch64", target_arch = "arm64ec"))]
128+
use core::arch::aarch64::*;
129+
130+
#[cfg(target_arch = "arm")]
131+
use core::arch::arm::*;
116132
"#;

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
2929
&self.intrinsics
3030
}
3131

32+
const NOTICE: &str = config::NOTICE;
33+
34+
const PLATFORM_C_HEADERS: &[&str] = &["arm_neon.h", "arm_acle.h", "arm_fp16.h"];
35+
const PLATFORM_C_DEFINITIONS: &str = config::POLY128_OSTREAM_DEF;
36+
const PLATFORM_C_FORWARD_DECLARATIONS: &str = config::POLY128_OSTREAM_DECL;
37+
38+
const PLATFORM_RUST_DEFINITIONS: &str = config::F16_FORMATTING_DEF;
39+
const PLATFORM_RUST_CFGS: &str = config::AARCH_CONFIGURATIONS;
40+
41+
fn cpp_compilation(&self) -> Option<CppCompilation> {
42+
compile::build_cpp_compilation(&self.cli_options)
43+
}
44+
3245
fn create(cli_options: ProcessedCli) -> Self {
3346
let a32 = cli_options.target.contains("v7");
3447
let mut intrinsics = get_neon_intrinsics(&cli_options.filename, &cli_options.target)
@@ -56,16 +69,4 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
5669
cli_options,
5770
}
5871
}
59-
60-
const NOTICE: &str = config::NOTICE;
61-
62-
const PLATFORM_C_HEADERS: &[&str] = &["arm_neon.h", "arm_acle.h", "arm_fp16.h"];
63-
const PLATFORM_C_DEFINITIONS: &str = config::POLY128_OSTREAM_DEF;
64-
65-
const PLATFORM_RUST_DEFINITIONS: &str = config::F16_FORMATTING_DEF;
66-
const PLATFORM_RUST_CFGS: &str = config::AARCH_CONFIGURATIONS;
67-
68-
fn cpp_compilation(&self) -> Option<CppCompilation> {
69-
compile::build_cpp_compilation(&self.cli_options)
70-
}
7172
}

library/stdarch/crates/intrinsic-test/src/common/gen_c.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ pub fn create_c_test_function<T: IntrinsicTypeDefinition>(
9393
pub fn write_mod_cpp<T: IntrinsicTypeDefinition>(
9494
w: &mut impl std::io::Write,
9595
notice: &str,
96-
architecture: &str,
9796
platform_headers: &[&str],
97+
forward_declarations: &str,
9898
intrinsics: &[Intrinsic<T>],
9999
) -> std::io::Result<()> {
100100
write!(w, "{notice}")?;
@@ -125,12 +125,7 @@ std::ostream& operator<<(std::ostream& os, float16_t value);
125125
"#
126126
)?;
127127

128-
writeln!(w, "#ifdef __{architecture}__")?;
129-
writeln!(
130-
w,
131-
"std::ostream& operator<<(std::ostream& os, poly128_t value);"
132-
)?;
133-
writeln!(w, "#endif")?;
128+
writeln!(w, "{}", forward_declarations)?;
134129

135130
for intrinsic in intrinsics {
136131
create_c_test_function(w, intrinsic)?;
@@ -141,7 +136,6 @@ std::ostream& operator<<(std::ostream& os, float16_t value);
141136

142137
pub fn write_main_cpp<'a>(
143138
w: &mut impl std::io::Write,
144-
architecture: &str,
145139
arch_specific_definitions: &str,
146140
intrinsics: impl Iterator<Item = &'a str> + Clone,
147141
) -> std::io::Result<()> {
@@ -170,9 +164,8 @@ std::ostream& operator<<(std::ostream& os, float16_t value) {{
170164
"#
171165
)?;
172166

173-
writeln!(w, "#ifdef __{architecture}__")?;
167+
// NOTE: It's assumed that this value contains the required `ifdef`s.
174168
writeln!(w, "{arch_specific_definitions }")?;
175-
writeln!(w, "#endif")?;
176169

177170
for intrinsic in intrinsics.clone() {
178171
writeln!(w, "extern int run_{intrinsic}(void);")?;

library/stdarch/crates/intrinsic-test/src/common/gen_rust.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ pub fn write_main_rs<'a>(
9898

9999
pub fn write_lib_rs<T: IntrinsicTypeDefinition>(
100100
w: &mut impl std::io::Write,
101-
architecture: &str,
102101
notice: &str,
103102
cfg: &str,
104103
definitions: &str,
@@ -117,8 +116,6 @@ pub fn write_lib_rs<T: IntrinsicTypeDefinition>(
117116

118117
writeln!(w, "{cfg}")?;
119118

120-
writeln!(w, "use core_arch::arch::{architecture}::*;")?;
121-
122119
writeln!(w, "{definitions}")?;
123120

124121
for intrinsic in intrinsics {

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,14 @@ pub trait SupportedArchitectureTest {
4141

4242
const PLATFORM_C_HEADERS: &[&str];
4343
const PLATFORM_C_DEFINITIONS: &str;
44+
const PLATFORM_C_FORWARD_DECLARATIONS: &str;
4445

4546
const PLATFORM_RUST_CFGS: &str;
4647
const PLATFORM_RUST_DEFINITIONS: &str;
4748

4849
fn cpp_compilation(&self) -> Option<CppCompilation>;
4950

5051
fn build_c_file(&self) -> bool {
51-
let c_target = "aarch64";
52-
5352
let (chunk_size, chunk_count) = chunk_info(self.intrinsics().len());
5453

5554
let cpp_compiler_wrapped = self.cpp_compilation();
@@ -64,8 +63,8 @@ pub trait SupportedArchitectureTest {
6463
write_mod_cpp(
6564
&mut file,
6665
Self::NOTICE,
67-
c_target,
6866
Self::PLATFORM_C_HEADERS,
67+
Self::PLATFORM_C_FORWARD_DECLARATIONS,
6968
chunk,
7069
)
7170
.unwrap();
@@ -88,7 +87,6 @@ pub trait SupportedArchitectureTest {
8887
let mut file = File::create("c_programs/main.cpp").unwrap();
8988
write_main_cpp(
9089
&mut file,
91-
c_target,
9290
Self::PLATFORM_C_DEFINITIONS,
9391
self.intrinsics().iter().map(|i| i.name.as_str()),
9492
)
@@ -120,12 +118,6 @@ pub trait SupportedArchitectureTest {
120118
fn build_rust_file(&self) -> bool {
121119
std::fs::create_dir_all("rust_programs/src").unwrap();
122120

123-
let architecture = if self.cli_options().target.contains("v7") {
124-
"arm"
125-
} else {
126-
"aarch64"
127-
};
128-
129121
let (chunk_size, chunk_count) = chunk_info(self.intrinsics().len());
130122

131123
let mut cargo = File::create("rust_programs/Cargo.toml").unwrap();
@@ -157,7 +149,6 @@ pub trait SupportedArchitectureTest {
157149

158150
write_lib_rs(
159151
&mut file,
160-
architecture,
161152
Self::NOTICE,
162153
Self::PLATFORM_RUST_CFGS,
163154
Self::PLATFORM_RUST_DEFINITIONS,

0 commit comments

Comments
 (0)