-
Notifications
You must be signed in to change notification settings - Fork 288
Re-organize intrinsic-test
to enable seamless addition of behaviour testing for more architectures
#1758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
madhav-madhusoodanan
wants to merge
24
commits into
rust-lang:master
Choose a base branch
from
madhav-madhusoodanan:restructure-intrinsic-test-crate
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Re-organize intrinsic-test
to enable seamless addition of behaviour testing for more architectures
#1758
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
bf7aee7
Feat: Moved majority of the code to `arm` module.
madhav-madhusoodanan 4c25aa7
Chore: Added `SupportedArchitectureTest` trait which must be implemen…
madhav-madhusoodanan 5b9f0e5
chore: Added `ProcessedCli` to extract the logic to pre-process CLI s…
madhav-madhusoodanan bf7812c
chore: separated common logic within file creations, compile_c, compi…
madhav-madhusoodanan 7118074
chore: code consolidation
madhav-madhusoodanan 0b6d424
chore: added match block in `src/main.rs`
madhav-madhusoodanan b215673
fixed `too many files open` issue
madhav-madhusoodanan 8b1a734
maintaining special list of targets which need different execution co…
madhav-madhusoodanan 18e49d6
rename struct for naming consistency
madhav-madhusoodanan 83110d3
test commit to check if `load_Values_c` can be dissociated from targe…
madhav-madhusoodanan 0d4be1c
added target field within `IntrinsicType` to perform target level che…
madhav-madhusoodanan 02a69bd
Updated `Argument::from_c` to remove `ArgPrep` specific argument
madhav-madhusoodanan a4b46a7
introduced generic types and code refactor
madhav-madhusoodanan e570aad
Added a macro to simplify <Arch>IntrinsicType definitions
madhav-madhusoodanan a668076
renamed `a64_only` data member in `Intrinsic` to `arch_tags`
madhav-madhusoodanan f1b2931
Removed aarch64-be specific execution command for rust test files
madhav-madhusoodanan fb84942
moved the C compilation commands into a struct for easier handling
madhav-madhusoodanan 757dd74
Added dynamic dispatch for easier management of `<arch>ArchitectureTe…
madhav-madhusoodanan 4935acb
code cleanup
madhav-madhusoodanan c1d2d77
chore: file renaming
madhav-madhusoodanan 90aff41
feat: made constraint common
madhav-madhusoodanan 941637c
fix: aarch64_be issues wthin compilation
madhav-madhusoodanan a4f084e
moved more code generation functionality to `common`
madhav-madhusoodanan 66a88fe
feat: merging changes related to f16 formatting
madhav-madhusoodanan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use crate::common::compile_c::CompilationCommandBuilder; | ||
use crate::common::gen_c::compile_c; | ||
|
||
pub fn compile_c_arm( | ||
intrinsics_name_list: &Vec<String>, | ||
compiler: &str, | ||
target: &str, | ||
cxx_toolchain_dir: Option<&str>, | ||
) -> bool { | ||
// -ffp-contract=off emulates Rust's approach of not fusing separate mul-add operations | ||
let mut command = CompilationCommandBuilder::new() | ||
.add_arch_flags(vec!["armv8.6-a", "crypto", "crc", "dotprod", "fp16"]) | ||
.set_compiler(compiler) | ||
.set_target(target) | ||
.set_opt_level("2") | ||
.set_cxx_toolchain_dir(cxx_toolchain_dir) | ||
.set_project_root("c_programs") | ||
.add_extra_flags(vec!["-ffp-contract=off", "-Wno-narrowing"]); | ||
|
||
if !target.contains("v7") { | ||
command = command.add_arch_flags(vec!["faminmax", "lut", "sha3"]); | ||
} | ||
|
||
/* | ||
* clang++ cannot link an aarch64_be object file, so we invoke | ||
* aarch64_be-unknown-linux-gnu's C++ linker. This ensures that we | ||
* are testing the intrinsics against LLVM. | ||
* | ||
* Note: setting `--sysroot=<...>` which is the obvious thing to do | ||
* does not work as it gets caught up with `#include_next <stdlib.h>` | ||
* not existing... | ||
*/ | ||
if target.contains("aarch64_be") { | ||
command = command | ||
.set_linker( | ||
cxx_toolchain_dir.unwrap_or("").to_string() + "/bin/aarch64_be-none-linux-gnu-g++", | ||
) | ||
.set_include_paths(vec![ | ||
"/include", | ||
"/aarch64_be-none-linux-gnu/include", | ||
"/aarch64_be-none-linux-gnu/include/c++/14.2.1", | ||
"/aarch64_be-none-linux-gnu/include/c++/14.2.1/aarch64_be-none-linux-gnu", | ||
"/aarch64_be-none-linux-gnu/include/c++/14.2.1/backward", | ||
"/aarch64_be-none-linux-gnu/libc/usr/include", | ||
]); | ||
} | ||
|
||
if !compiler.contains("clang") { | ||
command = command.add_extra_flag("-flax-vector-conversions"); | ||
} | ||
|
||
let compiler_commands = intrinsics_name_list | ||
.iter() | ||
.map(|intrinsic_name| { | ||
command | ||
.clone() | ||
.set_input_name(intrinsic_name) | ||
.set_output_name(intrinsic_name) | ||
.to_string() | ||
}) | ||
.collect::<Vec<_>>(); | ||
|
||
compile_c(&compiler_commands) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
pub fn build_notices(line_prefix: &str) -> String { | ||
format!( | ||
"\ | ||
{line_prefix}This is a transient test file, not intended for distribution. Some aspects of the | ||
{line_prefix}test are derived from a JSON specification, published under the same license as the | ||
{line_prefix}`intrinsic-test` crate.\n | ||
" | ||
) | ||
} | ||
|
||
pub const POLY128_OSTREAM_DEF: &str = r#"std::ostream& operator<<(std::ostream& os, poly128_t value) { | ||
std::stringstream temp; | ||
do { | ||
int n = value % 10; | ||
value /= 10; | ||
temp << n; | ||
} while (value != 0); | ||
std::string tempstr(temp.str()); | ||
std::string res(tempstr.rbegin(), tempstr.rend()); | ||
os << res; | ||
return os; | ||
}"#; | ||
|
||
// Format f16 values (and vectors containing them) in a way that is consistent with C. | ||
pub const F16_FORMATTING_DEF: &str = r#" | ||
/// Used to continue `Debug`ging SIMD types as `MySimd(1, 2, 3, 4)`, as they | ||
/// were before moving to array-based simd. | ||
#[inline] | ||
fn debug_simd_finish<T: core::fmt::Debug, const N: usize>( | ||
formatter: &mut core::fmt::Formatter<'_>, | ||
type_name: &str, | ||
array: &[T; N], | ||
) -> core::fmt::Result { | ||
core::fmt::Formatter::debug_tuple_fields_finish( | ||
formatter, | ||
type_name, | ||
&core::array::from_fn::<&dyn core::fmt::Debug, N, _>(|i| &array[i]), | ||
) | ||
} | ||
|
||
#[repr(transparent)] | ||
struct Hex<T>(T); | ||
|
||
impl<T: DebugHexF16> core::fmt::Debug for Hex<T> { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
<T as DebugHexF16>::fmt(&self.0, f) | ||
} | ||
} | ||
|
||
fn debug_f16<T: DebugHexF16>(x: T) -> impl core::fmt::Debug { | ||
Hex(x) | ||
} | ||
|
||
trait DebugHexF16 { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result; | ||
} | ||
|
||
impl DebugHexF16 for f16 { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
write!(f, "{:#06x?}", self.to_bits()) | ||
} | ||
} | ||
|
||
impl DebugHexF16 for float16x4_t { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
let array = unsafe { core::mem::transmute::<_, [Hex<f16>; 4]>(*self) }; | ||
debug_simd_finish(f, "float16x4_t", &array) | ||
} | ||
} | ||
|
||
impl DebugHexF16 for float16x8_t { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
let array = unsafe { core::mem::transmute::<_, [Hex<f16>; 8]>(*self) }; | ||
debug_simd_finish(f, "float16x8_t", &array) | ||
} | ||
} | ||
|
||
impl DebugHexF16 for float16x4x2_t { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
debug_simd_finish(f, "float16x4x2_t", &[Hex(self.0), Hex(self.1)]) | ||
} | ||
} | ||
impl DebugHexF16 for float16x4x3_t { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
debug_simd_finish(f, "float16x4x3_t", &[Hex(self.0), Hex(self.1), Hex(self.2)]) | ||
} | ||
} | ||
impl DebugHexF16 for float16x4x4_t { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
debug_simd_finish(f, "float16x4x4_t", &[Hex(self.0), Hex(self.1), Hex(self.2), Hex(self.3)]) | ||
} | ||
} | ||
|
||
impl DebugHexF16 for float16x8x2_t { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
debug_simd_finish(f, "float16x8x2_t", &[Hex(self.0), Hex(self.1)]) | ||
} | ||
} | ||
impl DebugHexF16 for float16x8x3_t { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
debug_simd_finish(f, "float16x8x3_t", &[Hex(self.0), Hex(self.1), Hex(self.2)]) | ||
} | ||
} | ||
impl DebugHexF16 for float16x8x4_t { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
debug_simd_finish(f, "float16x8x4_t", &[Hex(self.0), Hex(self.1), Hex(self.2), Hex(self.3)]) | ||
} | ||
} | ||
"#; | ||
|
||
pub const AARCH_CONFIGURATIONS: &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_dotprod))] | ||
#![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_sha3))] | ||
#![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))] | ||
#![feature(fmt_helpers_for_derive)] | ||
#![feature(stdarch_neon_f16)] | ||
"#; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, how important is this notice?
I'm totally in favour of documentation, but seeing as the files that are being generated are purely for testing purposes I thought it'd be best to clarify.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We would like to keep this notice for Arm intrinsics if possible. For us it's not technically mandatory to include, but it reduces risk for us.
I'm not in a position to speak for what's best for other architectures unfortunately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see