-
Notifications
You must be signed in to change notification settings - Fork 299
intrinsic-test
: Adding x86 behavioural testing.
#1894
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
Draft
madhav-madhusoodanan
wants to merge
14
commits into
rust-lang:master
Choose a base branch
from
madhav-madhusoodanan:intrinsic-test-x86-addition
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.
Draft
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
88b2641
feat: added the skeleton structure of the x86 module
madhav-madhusoodanan 14ffd14
feat: added the XML intrinsic parser for x86
madhav-madhusoodanan 75af0cb
feat: updated intrinsics creation
madhav-madhusoodanan 178b4c8
feat: update building C code for x86 architecture.
madhav-madhusoodanan 5883d17
fix: code cleanup
madhav-madhusoodanan 989a8ff
chore: added Regex crate, updated the structure of X86IntrinsicType
madhav-madhusoodanan accc019
feat: implemented build_rust_file of `x86` module
madhav-madhusoodanan 6d2e865
feat: implemented compare_outputs of `x86` module
madhav-madhusoodanan 746f7f3
feat: implement `print_result_c` for `Intrinsic<X86IntrinsicType>`
madhav-madhusoodanan 111cd5d
feat: Added x86 to CI pipeline
madhav-madhusoodanan 301b3e0
Merge branch 'master' into intrinsic-test-x86-addition
madhav-madhusoodanan 82f60b8
fix: update arch flags being sent to the x86 compilation command
madhav-madhusoodanan ebc3e53
fix: set default value for varname and type fields of the
madhav-madhusoodanan 8fc09ee
fix: correcting semantical logic for setting vec_len
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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,38 @@ | ||
use crate::common::cli::ProcessedCli; | ||
use crate::common::compile_c::{CompilationCommandBuilder, CppCompilation}; | ||
|
||
pub fn build_cpp_compilation(config: &ProcessedCli) -> Option<CppCompilation> { | ||
let cpp_compiler = config.cpp_compiler.as_ref()?; | ||
|
||
// -ffp-contract=off emulates Rust's approach of not fusing separate mul-add operations | ||
let mut command = CompilationCommandBuilder::new() | ||
.add_arch_flags([ | ||
"avx", | ||
"avx2", | ||
"avx512f", | ||
"avx512cd", | ||
"avx512dq", | ||
"avx512vl", | ||
"avx512bw", | ||
"avx512bf16", | ||
"avx512bitalg", | ||
"lzcnt", | ||
"popcnt", | ||
"adx", | ||
"aes", | ||
]) | ||
.set_compiler(cpp_compiler) | ||
.set_target(&config.target) | ||
.set_opt_level("2") | ||
.set_cxx_toolchain_dir(config.cxx_toolchain_dir.as_deref()) | ||
.set_project_root("c_programs") | ||
.add_extra_flags(vec!["-ffp-contract=off", "-Wno-narrowing"]); | ||
|
||
if !cpp_compiler.contains("clang") { | ||
command = command.add_extra_flag("-flax-vector-conversions"); | ||
} | ||
|
||
let cpp_compiler = command.into_cpp_compilation(); | ||
|
||
Some(cpp_compiler) | ||
} |
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,25 @@ | ||
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 an XML specification, published under the same license as the | ||
{line_prefix}`intrinsic-test` crate.\n | ||
" | ||
) | ||
} | ||
|
||
// Format f16 values (and vectors containing them) in a way that is consistent with C. | ||
pub const F16_FORMATTING_DEF: &str = r#" | ||
#[repr(transparent)] | ||
struct Hex<T>(T); | ||
"#; | ||
|
||
pub const X86_CONFIGURATIONS: &str = r#" | ||
#![cfg_attr(target_arch = "x86", feature(stdarch_x86_avx512_bf16))] | ||
#![cfg_attr(target_arch = "x86", feature(stdarch_x86_avx512_f16))] | ||
#![cfg_attr(target_arch = "x86", feature(stdarch_x86_rtm))] | ||
#![cfg_attr(target_arch = "x86", feature(stdarch_x86_rtm))] | ||
#![cfg_attr(target_arch = "x86_64", feature(x86_amx_intrinsics))] | ||
#![cfg_attr(target_arch = "x86_64", feature(stdarch_x86_avx512_f16))] | ||
#![feature(fmt_helpers_for_derive)] | ||
"#; |
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,20 @@ | ||
use crate::common::constraint::Constraint; | ||
|
||
pub fn map_constraints(imm_type: &String) -> Option<Constraint> { | ||
match imm_type.as_str() { | ||
"_MM_FROUND" => Some(Constraint::Range(0..4)), | ||
"_MM_INDEX_SCALE" => Some(Constraint::Set(vec![1, 2, 4, 8])), | ||
"_MM_CMPINT" => Some(Constraint::Range(0..8)), | ||
"_MM_REDUCE" => Some(Constraint::Range(0..8)), | ||
"_MM_FROUND_SAE" => Some(Constraint::Range(0..8)), | ||
"_MM_MANTISSA_NORM" => Some(Constraint::Range(0..4)), | ||
"_MM_MANTISSA_NORM_ENUM" => Some(Constraint::Range(0..4)), | ||
"_MM_MANTISSA_SIGN" => Some(Constraint::Range(0..3)), | ||
"_MM_PERM" => Some(Constraint::Range(0..256)), | ||
"_MM_PERM_ENUM" => Some(Constraint::Range(0..256)), | ||
"_MM_CMPINT_ENUM" => Some(Constraint::Range(0..8)), | ||
"_MM_ROUND_MODE" => Some(Constraint::Set(vec![0, 0x2000, 0x4000, 0x6000])), | ||
"_CMP_" => Some(Constraint::Range(0..32)), | ||
_ => None, | ||
} | ||
} |
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,109 @@ | ||
use crate::common::argument::ArgumentList; | ||
use crate::common::indentation::Indentation; | ||
use crate::common::intrinsic::{Intrinsic, IntrinsicDefinition}; | ||
use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, TypeKind}; | ||
use crate::x86::xml_parser::Parameter; | ||
use std::ops::{Deref, DerefMut}; | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct X86IntrinsicType { | ||
pub data: IntrinsicType, | ||
pub param: Parameter, | ||
} | ||
|
||
impl Deref for X86IntrinsicType { | ||
type Target = IntrinsicType; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.data | ||
} | ||
} | ||
|
||
impl DerefMut for X86IntrinsicType { | ||
fn deref_mut(&mut self) -> &mut Self::Target { | ||
&mut self.data | ||
} | ||
} | ||
|
||
impl IntrinsicDefinition<X86IntrinsicType> for Intrinsic<X86IntrinsicType> { | ||
fn arguments(&self) -> ArgumentList<X86IntrinsicType> { | ||
self.arguments.clone() | ||
} | ||
|
||
fn results(&self) -> X86IntrinsicType { | ||
self.results.clone() | ||
} | ||
|
||
fn name(&self) -> String { | ||
self.name.clone() | ||
} | ||
|
||
/// 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 { | ||
let lanes = if self.results().num_vectors() > 1 { | ||
(0..self.results().num_vectors()) | ||
.map(|vector| { | ||
format!( | ||
r#""{ty}(" << {lanes} << ")""#, | ||
ty = self.results().c_single_vector_type(), | ||
lanes = (0..self.results().num_lanes()) | ||
.map(move |idx| -> std::string::String { | ||
format!( | ||
"{cast}{lane_fn}(__return_value.val[{vector}], {lane})", | ||
cast = self.results().c_promotion(), | ||
lane_fn = self.results().get_lane_function(), | ||
lane = idx, | ||
vector = vector, | ||
) | ||
}) | ||
.collect::<Vec<_>>() | ||
.join(r#" << ", " << "#) | ||
) | ||
}) | ||
.collect::<Vec<_>>() | ||
.join(r#" << ", " << "#) | ||
} else if self.results().num_lanes() > 1 { | ||
(0..self.results().num_lanes()) | ||
.map(|idx| -> std::string::String { | ||
format!( | ||
"{cast}{lane_fn}(__return_value, {lane})", | ||
cast = self.results().c_promotion(), | ||
lane_fn = self.results().get_lane_function(), | ||
lane = idx | ||
) | ||
}) | ||
.collect::<Vec<_>>() | ||
.join(r#" << ", " << "#) | ||
} else { | ||
format!( | ||
"{promote}cast<{cast}>(__return_value)", | ||
cast = match self.results.kind() { | ||
TypeKind::Void => "void".to_string(), | ||
TypeKind::Float if self.results().inner_size() == 64 => "double".to_string(), | ||
TypeKind::Float if self.results().inner_size() == 32 => "float".to_string(), | ||
// TypeKind::Float if self.results().inner_size() == 16 => "float16_t".to_string(), | ||
// TypeKind::Int(true) if self.results().inner_size() == 64 => "long".to_string(), | ||
// TypeKind::Int(false) if self.results().inner_size() == 64 => "unsigned long".to_string(), | ||
// TypeKind::Int(true) if self.results().inner_size() == 32 => "int".to_string(), | ||
// TypeKind::Int(false) if self.results().inner_size() == 32 => "unsigned int".to_string(), | ||
// TypeKind::Int(true) if self.results().inner_size() == 16 => "short".to_string(), | ||
// TypeKind::Int(false) if self.results().inner_size() == 16 => "unsigned short".to_string(), | ||
_ => self.results.c_scalar_type(), | ||
}, | ||
promote = self.results().c_promotion(), | ||
) | ||
}; | ||
|
||
format!( | ||
r#"{indentation}std::cout << "Result {additional}-" << i+1 << ": {ty}" << std::fixed << std::setprecision(150) << {lanes} << "{close}" << std::endl;"#, | ||
ty = if self.results().is_simd() { | ||
format!("{}(", self.results().c_type()) | ||
} else { | ||
String::from("") | ||
}, | ||
close = if self.results.is_simd() { ")" } else { "" }, | ||
) | ||
} | ||
} |
Oops, something went wrong.
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.
we'll have to see how to do this exactly, but we want to split these out of the main CI job to speed it up