Skip to content
Open
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
25 changes: 0 additions & 25 deletions crates/intrinsic-test/src/arm/config.rs

This file was deleted.

38 changes: 31 additions & 7 deletions crates/intrinsic-test/src/arm/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mod config;
mod intrinsic;
mod json_parser;
mod types;
Expand All @@ -21,14 +20,20 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
&self.intrinsics
}

const NOTICE: &str = config::NOTICE;
const NOTICE: &str = r#"
// This is a transient test file, not intended for distribution. Some aspects of the
// test are derived from a JSON specification, published under the same license as the
// `intrinsic-test` crate.
"#;

const PLATFORM_C_HEADERS: &[&str] = &["arm_neon.h", "arm_acle.h", "arm_fp16.h"];
const C_PRELUDE: &str = r#"
#include <arm_acle.h>
#include <arm_fp16.h>
#include <arm_neon.h>
"#;
const RUST_PRELUDE: &str = RUST_PRELUDE;

const PLATFORM_RUST_DEFINITIONS: &str = config::PLATFORM_RUST_DEFINITIONS;
const PLATFORM_RUST_CFGS: &str = config::PLATFORM_RUST_CFGS;

fn arch_flags(&self, cli_options: &ProcessedCli) -> Vec<&str> {
fn c_compiler_flags(&self, cli_options: &ProcessedCli) -> Vec<&str> {
// GCC uses an extra `-` in the arch name
match cli_options.cc_arg_style {
CcArgStyle::Clang => vec!["-march=armv8.6a+crypto+crc+dotprod+fp16"],
Expand Down Expand Up @@ -69,3 +74,22 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
Self { intrinsics }
}
}

const RUST_PRELUDE: &str = r#"
#![cfg_attr(target_arch = "arm", feature(stdarch_arm_neon_intrinsics))]
#![cfg_attr(target_arch = "arm", feature(stdarch_aarch32_crc32))]
#![cfg_attr(any(target_arch = "aarch64", target_arch = "arm64ec"), feature(stdarch_neon_fcma))]
#![cfg_attr(any(target_arch = "aarch64", target_arch = "arm64ec"), feature(stdarch_neon_i8mm))]
#![cfg_attr(any(target_arch = "aarch64", target_arch = "arm64ec"), feature(stdarch_neon_sm4))]
#![cfg_attr(any(target_arch = "aarch64", target_arch = "arm64ec"), feature(stdarch_neon_ftts))]
#![cfg_attr(any(target_arch = "aarch64", target_arch = "arm64ec"), feature(stdarch_neon_feat_lut))]
#![cfg_attr(any(target_arch = "aarch64", target_arch = "arm64ec"), feature(stdarch_neon_fp8))]
#![cfg_attr(any(target_arch = "aarch64", target_arch = "arm64ec"), feature(faminmax))]
#![feature(stdarch_neon_f16)]

#[cfg(any(target_arch = "aarch64", target_arch = "arm64ec"))]
use core_arch::arch::aarch64::*;

#[cfg(target_arch = "arm")]
use core_arch::arch::arm::*;
"#;
7 changes: 2 additions & 5 deletions crates/intrinsic-test/src/common/gen_c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@ use super::intrinsic_helpers::IntrinsicTypeDefinition;
pub fn write_wrapper_c<T: IntrinsicTypeDefinition>(
w: &mut impl std::io::Write,
notice: &str,
platform_headers: &[&str],
prelude: &str,
intrinsics: &[Intrinsic<T>],
) -> std::io::Result<()> {
write!(w, "{notice}")?;

writeln!(w, "#include <stdint.h>")?;
writeln!(w, "#include <stddef.h>")?;

for header in platform_headers {
writeln!(w, "#include <{header}>")?;
}
writeln!(w, "{prelude}")?;

for intrinsic in intrinsics {
intrinsic.iter_specializations(|imm_values| {
Expand Down
5 changes: 1 addition & 4 deletions crates/intrinsic-test/src/common/gen_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ pub fn write_lib_cargo_toml(w: &mut impl std::io::Write, name: &str) -> std::io:
pub fn write_lib_rs<T: IntrinsicTypeDefinition>(
w: &mut impl std::io::Write,
notice: &str,
cfg: &str,
definitions: &str,
i: usize,
intrinsics: &[Intrinsic<T>],
Expand All @@ -121,12 +120,10 @@ pub fn write_lib_rs<T: IntrinsicTypeDefinition>(
writeln!(w, "#![allow(non_camel_case_types)]")?;
writeln!(w, "#![allow(non_snake_case)]")?;

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

writeln!(w, "{}", COMMON_RUST_DEFINITIONS)?;

writeln!(w, "{definitions}")?;

let mut seen = std::collections::HashSet::new();

for intrinsic in intrinsics {
Expand Down
21 changes: 6 additions & 15 deletions crates/intrinsic-test/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ pub trait SupportedArchitectureTest {

const NOTICE: &str;

const PLATFORM_C_HEADERS: &[&str];
const C_PRELUDE: &str;
const RUST_PRELUDE: &str;

const PLATFORM_RUST_CFGS: &str;
const PLATFORM_RUST_DEFINITIONS: &str;

fn arch_flags(&self, cli_options: &ProcessedCli) -> Vec<&str>;
fn c_compiler_flags(&self, cli_options: &ProcessedCli) -> Vec<&str>;

fn generate_c_file(&self) {
let (max_chunk_size, _chunk_count) = manual_chunk(self.intrinsics().len());
Expand All @@ -55,14 +53,14 @@ pub trait SupportedArchitectureTest {
.map(|(i, chunk)| {
let c_filename = format!("c_programs/wrapper_{i}.c");
let mut file = File::create(&c_filename).unwrap();
write_wrapper_c(&mut file, Self::NOTICE, Self::PLATFORM_C_HEADERS, chunk)
write_wrapper_c(&mut file, Self::NOTICE, Self::C_PRELUDE, chunk)
})
.collect::<io::Result<()>>()
.unwrap();
}

fn generate_rust_file(&self, cli_options: &ProcessedCli) {
let arch_flags = self.arch_flags(cli_options);
let arch_flags = self.c_compiler_flags(cli_options);

std::fs::create_dir_all("rust_programs").unwrap();

Expand All @@ -81,14 +79,7 @@ pub trait SupportedArchitectureTest {
trace!("generating `{rust_filename}`");
let mut file = File::create(&rust_filename)?;

write_lib_rs(
&mut file,
Self::NOTICE,
Self::PLATFORM_RUST_CFGS,
Self::PLATFORM_RUST_DEFINITIONS,
i,
chunk,
)?;
write_lib_rs(&mut file, Self::NOTICE, Self::RUST_PRELUDE, i, chunk)?;
run_rustfmt(&rust_filename);

let toml_filename = format!("rust_programs/mod_{i}/Cargo.toml");
Expand Down
138 changes: 0 additions & 138 deletions crates/intrinsic-test/src/x86/config.rs

This file was deleted.

Loading