diff options
5 files changed, 49 insertions, 152 deletions
diff --git a/library/stdarch/crates/intrinsic-test/src/arm/intrinsic.rs b/library/stdarch/crates/intrinsic-test/src/arm/intrinsic.rs index e408432bfae..0c3a832bac8 100644 --- a/library/stdarch/crates/intrinsic-test/src/arm/intrinsic.rs +++ b/library/stdarch/crates/intrinsic-test/src/arm/intrinsic.rs @@ -1,13 +1,19 @@ -use crate::base_intrinsictype_trait_def_macro; use crate::common::argument::ArgumentList; -use crate::common::cli::Language; use crate::common::indentation::Indentation; use crate::common::intrinsic::{Intrinsic, IntrinsicDefinition}; -use crate::common::intrinsic_helpers::{ - BaseIntrinsicTypeDefinition, IntrinsicTypeDefinition, TypeKind, -}; +use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, TypeKind}; +use std::ops::Deref; -base_intrinsictype_trait_def_macro! {ArmIntrinsicType} +#[derive(Debug, Clone, PartialEq)] +pub struct ArmIntrinsicType(pub IntrinsicType); + +impl Deref for ArmIntrinsicType { + type Target = IntrinsicType; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} impl IntrinsicDefinition<ArmIntrinsicType> for Intrinsic<ArmIntrinsicType> { fn arguments(&self) -> ArgumentList<ArmIntrinsicType> { diff --git a/library/stdarch/crates/intrinsic-test/src/arm/mod.rs b/library/stdarch/crates/intrinsic-test/src/arm/mod.rs index 9e089863b62..97e23093283 100644 --- a/library/stdarch/crates/intrinsic-test/src/arm/mod.rs +++ b/library/stdarch/crates/intrinsic-test/src/arm/mod.rs @@ -11,7 +11,7 @@ use crate::common::cli::ProcessedCli; use crate::common::compare::compare_outputs; use crate::common::gen_rust::compile_rust; use crate::common::intrinsic::{Intrinsic, IntrinsicDefinition}; -use crate::common::intrinsic_helpers::{BaseIntrinsicTypeDefinition, TypeKind}; +use crate::common::intrinsic_helpers::TypeKind; use crate::common::write_file::{write_c_testfiles, write_rust_testfiles}; use config::{AARCH_CONFIGURATIONS, F16_FORMATTING_DEF, POLY128_OSTREAM_DEF, build_notices}; use json_parser::get_neon_intrinsics; @@ -54,6 +54,7 @@ impl SupportedArchitectureTest for ArmArchitectureTest { let compiler = self.cli_options.cpp_compiler.as_deref(); let target = &self.cli_options.target; let cxx_toolchain_dir = self.cli_options.cxx_toolchain_dir.as_deref(); + let c_target = "aarch64"; let intrinsics_name_list = write_c_testfiles( &self @@ -62,6 +63,7 @@ impl SupportedArchitectureTest for ArmArchitectureTest { .map(|i| i as &dyn IntrinsicDefinition<_>) .collect::<Vec<_>>(), target, + c_target, &["arm_neon.h", "arm_acle.h", "arm_fp16.h"], &build_notices("// "), &[POLY128_OSTREAM_DEF], @@ -76,7 +78,7 @@ impl SupportedArchitectureTest for ArmArchitectureTest { } fn build_rust_file(&self) -> bool { - let final_target = if self.cli_options.target.contains("v7") { + let rust_target = if self.cli_options.target.contains("v7") { "arm" } else { "aarch64" @@ -89,7 +91,7 @@ impl SupportedArchitectureTest for ArmArchitectureTest { .iter() .map(|i| i as &dyn IntrinsicDefinition<_>) .collect::<Vec<_>>(), - final_target, + rust_target, &build_notices("// "), F16_FORMATTING_DEF, AARCH_CONFIGURATIONS, diff --git a/library/stdarch/crates/intrinsic-test/src/common/intrinsic.rs b/library/stdarch/crates/intrinsic-test/src/common/intrinsic.rs index 05f4328d3ee..fcc2d4941b3 100644 --- a/library/stdarch/crates/intrinsic-test/src/common/intrinsic.rs +++ b/library/stdarch/crates/intrinsic-test/src/common/intrinsic.rs @@ -39,9 +39,7 @@ where /// Generates a std::cout for the intrinsics results that will match the /// rust debug output format for the return type. The generated line assumes /// there is an int i in scope which is the current pass number. - fn print_result_c(&self, _indentation: Indentation, _additional: &str) -> String { - unimplemented!("Architectures need to implement print_result_c!") - } + fn print_result_c(&self, _indentation: Indentation, _additional: &str) -> String; fn generate_loop_c( &self, @@ -137,6 +135,7 @@ where &self, header_files: &[&str], target: &str, + c_target: &str, notices: &str, arch_specific_definitions: &[&str], ) -> String { @@ -150,7 +149,7 @@ where generate_c_program( notices, header_files, - "aarch64", + c_target, arch_specific_definitions, self.arguments() .gen_arglists_c(indentation, PASSES) diff --git a/library/stdarch/crates/intrinsic-test/src/common/intrinsic_helpers.rs b/library/stdarch/crates/intrinsic-test/src/common/intrinsic_helpers.rs index 5cb190e6bf6..2f2593a6602 100644 --- a/library/stdarch/crates/intrinsic-test/src/common/intrinsic_helpers.rs +++ b/library/stdarch/crates/intrinsic-test/src/common/intrinsic_helpers.rs @@ -1,4 +1,5 @@ use std::fmt; +use std::ops::Deref; use std::str::FromStr; use itertools::Itertools as _; @@ -102,62 +103,12 @@ pub struct IntrinsicType { pub target: String, } -pub trait BaseIntrinsicTypeDefinition { - /// Get the TypeKind for this type, recursing into pointers. - fn kind(&self) -> TypeKind; - - /// Get the size of a single element inside this type, recursing into - /// pointers, i.e. a pointer to a u16 would be 16 rather than the size - /// of a pointer. - fn inner_size(&self) -> u32; - - fn num_lanes(&self) -> u32; - - fn num_vectors(&self) -> u32; - - /// Determine if the type is a simd type, this will treat a type such as - /// `uint64x1` as simd. - fn is_simd(&self) -> bool; - - fn is_ptr(&self) -> bool; - - fn c_scalar_type(&self) -> String; - - fn rust_scalar_type(&self) -> String; - - /// Gets a cast for this type if needs promotion. - /// This is required for 8 bit types due to printing as the 8 bit types use - /// a char and when using that in `std::cout` it will print as a character, - /// which means value of 0 will be printed as a null byte. - /// - /// This is also needed for polynomial types because we want them to be - /// printed as unsigned integers to match Rust's `Debug` impl. - fn c_promotion(&self) -> &str; - - /// Generates an initialiser for an array, which can be used to initialise an argument for the - /// intrinsic call. - /// - /// This is determistic based on the pass number. - /// - /// * `loads`: The number of values that need to be loaded from the argument array - /// * e.g for argument type uint32x2, loads=2 results in a string representing 4 32-bit values - /// - /// Returns a string such as - /// * `{0x1, 0x7F, 0xFF}` if `language` is `Language::C` - /// * `[0x1 as _, 0x7F as _, 0xFF as _]` if `language` is `Language::Rust` - fn populate_random(&self, indentation: Indentation, loads: u32, language: &Language) -> String; - - fn is_rust_vals_array_const(&self) -> bool; - - fn as_call_param_c(&self, name: &String) -> String; -} - -impl BaseIntrinsicTypeDefinition for IntrinsicType { - fn kind(&self) -> TypeKind { +impl IntrinsicType { + pub fn kind(&self) -> TypeKind { self.kind } - fn inner_size(&self) -> u32 { + pub fn inner_size(&self) -> u32 { if let Some(bl) = self.bit_len { bl } else { @@ -165,23 +116,23 @@ impl BaseIntrinsicTypeDefinition for IntrinsicType { } } - fn num_lanes(&self) -> u32 { + pub fn num_lanes(&self) -> u32 { if let Some(sl) = self.simd_len { sl } else { 1 } } - fn num_vectors(&self) -> u32 { + pub fn num_vectors(&self) -> u32 { if let Some(vl) = self.vec_len { vl } else { 1 } } - fn is_simd(&self) -> bool { + pub fn is_simd(&self) -> bool { self.simd_len.is_some() || self.vec_len.is_some() } - fn is_ptr(&self) -> bool { + pub fn is_ptr(&self) -> bool { self.ptr } - fn c_scalar_type(&self) -> String { + pub fn c_scalar_type(&self) -> String { format!( "{prefix}{bits}_t", prefix = self.kind().c_prefix(), @@ -189,7 +140,7 @@ impl BaseIntrinsicTypeDefinition for IntrinsicType { ) } - fn rust_scalar_type(&self) -> String { + pub fn rust_scalar_type(&self) -> String { format!( "{prefix}{bits}", prefix = self.kind().rust_prefix(), @@ -197,7 +148,7 @@ impl BaseIntrinsicTypeDefinition for IntrinsicType { ) } - fn c_promotion(&self) -> &str { + pub fn c_promotion(&self) -> &str { match *self { IntrinsicType { kind, @@ -225,7 +176,12 @@ impl BaseIntrinsicTypeDefinition for IntrinsicType { } } - fn populate_random(&self, indentation: Indentation, loads: u32, language: &Language) -> String { + pub fn populate_random( + &self, + indentation: Indentation, + loads: u32, + language: &Language, + ) -> String { match self { IntrinsicType { bit_len: Some(bit_len @ (8 | 16 | 32 | 64)), @@ -293,7 +249,7 @@ impl BaseIntrinsicTypeDefinition for IntrinsicType { } } - fn is_rust_vals_array_const(&self) -> bool { + pub fn is_rust_vals_array_const(&self) -> bool { match self { // Floats have to be loaded at runtime for stable NaN conversion. IntrinsicType { @@ -308,7 +264,7 @@ impl BaseIntrinsicTypeDefinition for IntrinsicType { } } - fn as_call_param_c(&self, name: &String) -> String { + pub fn as_call_param_c(&self, name: &String) -> String { if self.ptr { format!("&{}", name) } else { @@ -317,92 +273,24 @@ impl BaseIntrinsicTypeDefinition for IntrinsicType { } } -pub trait IntrinsicTypeDefinition: BaseIntrinsicTypeDefinition { +pub trait IntrinsicTypeDefinition: Deref<Target = IntrinsicType> { /// Determines the load function for this type. /// can be implemented in an `impl` block - fn get_load_function(&self, _language: Language) -> String { - unimplemented!("Different architectures must implement get_load_function!") - } + fn get_load_function(&self, _language: Language) -> String; /// can be implemented in an `impl` block - fn get_lane_function(&self) -> String { - unimplemented!("Different architectures must implement get_lane_function!") - } + fn get_lane_function(&self) -> String; /// can be implemented in an `impl` block - fn from_c(_s: &str, _target: &String) -> Result<Box<Self>, String> { - unimplemented!("Different architectures must implement from_c!") - } + fn from_c(_s: &str, _target: &String) -> Result<Box<Self>, String>; /// Gets a string containing the typename for this type in C format. /// can be directly defined in `impl` blocks - fn c_type(&self) -> String { - unimplemented!("Different architectures must implement c_type!") - } + fn c_type(&self) -> String; /// can be directly defined in `impl` blocks - fn c_single_vector_type(&self) -> String { - unimplemented!("Different architectures must implement c_single_vector_type!") - } + fn c_single_vector_type(&self) -> String; /// can be defined in `impl` blocks - fn rust_type(&self) -> String { - unimplemented!("Different architectures must implement rust_type!") - } -} - -/// Defines the basic structure of achitecture-specific derivatives -/// of IntrinsicType. -#[macro_export] -macro_rules! base_intrinsictype_trait_def_macro { - ($T:ident) => { - use crate::common::intrinsic_helpers::IntrinsicType; - - #[derive(Debug, Clone, PartialEq)] - pub struct $T(pub IntrinsicType); - - impl BaseIntrinsicTypeDefinition for $T { - fn kind(&self) -> TypeKind { - self.0.kind() - } - fn inner_size(&self) -> u32 { - self.0.inner_size() - } - fn num_lanes(&self) -> u32 { - self.0.num_lanes() - } - fn num_vectors(&self) -> u32 { - self.0.num_vectors() - } - fn is_simd(&self) -> bool { - self.0.is_simd() - } - fn is_ptr(&self) -> bool { - self.0.is_ptr() - } - fn c_scalar_type(&self) -> String { - self.0.c_scalar_type() - } - fn rust_scalar_type(&self) -> String { - self.0.rust_scalar_type() - } - fn c_promotion(&self) -> &str { - self.0.c_promotion() - } - fn populate_random( - &self, - indentation: Indentation, - loads: u32, - language: &Language, - ) -> String { - self.0.populate_random(indentation, loads, language) - } - fn is_rust_vals_array_const(&self) -> bool { - self.0.is_rust_vals_array_const() - } - fn as_call_param_c(&self, name: &String) -> String { - self.0.as_call_param_c(name) - } - } - }; + fn rust_type(&self) -> String; } diff --git a/library/stdarch/crates/intrinsic-test/src/common/write_file.rs b/library/stdarch/crates/intrinsic-test/src/common/write_file.rs index a8b62c7b659..88644fa7de1 100644 --- a/library/stdarch/crates/intrinsic-test/src/common/write_file.rs +++ b/library/stdarch/crates/intrinsic-test/src/common/write_file.rs @@ -7,6 +7,7 @@ use crate::common::write_file; pub fn write_c_testfiles<T: IntrinsicTypeDefinition + Sized>( intrinsics: &Vec<&dyn IntrinsicDefinition<T>>, target: &str, + c_target: &str, headers: &[&str], notice: &str, arch_specific_definitions: &[&str], @@ -18,7 +19,8 @@ pub fn write_c_testfiles<T: IntrinsicTypeDefinition + Sized>( let filename_mapping = create_c_filenames(&intrinsics_name_list); intrinsics.iter().for_each(|i| { - let c_code = i.generate_c_program(headers, target, notice, arch_specific_definitions); + let c_code = + i.generate_c_program(headers, target, c_target, notice, arch_specific_definitions); match filename_mapping.get(&i.name()) { Some(filename) => write_file(filename, c_code), None => {} |
