-
Notifications
You must be signed in to change notification settings - Fork 336
intrinsic-test: Support testing LoongArch64 SIMD intrinsics #2226
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
Empty file.
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,31 @@ | ||
| # Missing in old c compiler | ||
| lasx_concat_128 | ||
| lasx_concat_128_d | ||
| lasx_concat_128_s | ||
| lasx_extract_128_hi | ||
| lasx_extract_128_lo | ||
| lasx_extract_128_hi_d | ||
| lasx_extract_128_lo_d | ||
| lasx_extract_128_hi_s | ||
| lasx_extract_128_lo_s | ||
| lasx_insert_128_hi | ||
| lasx_insert_128_lo | ||
| lasx_insert_128_hi_d | ||
| lasx_insert_128_lo_d | ||
| lasx_insert_128_hi_s | ||
| lasx_insert_128_lo_s | ||
|
|
||
| # Missing in old qemu | ||
| lasx_xvfrecipe_d | ||
| lasx_xvfrecipe_s | ||
| lasx_xvfrsqrte_d | ||
| lasx_xvfrsqrte_s | ||
| lsx_vfrecipe_d | ||
| lsx_vfrecipe_s | ||
| lsx_vfrsqrte_d | ||
| lsx_vfrsqrte_s | ||
|
|
||
| # Top bits are undefined, unclear how to test these | ||
| lasx_cast_128 | ||
| lasx_cast_128_d | ||
| lasx_cast_128_s |
Empty file.
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
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,19 @@ | ||
| use crate::common::intrinsic_helpers::IntrinsicType; | ||
| use std::ops::{Deref, DerefMut}; | ||
|
|
||
| #[derive(Debug, Clone, PartialEq)] | ||
| pub struct LoongArchType(pub IntrinsicType); | ||
|
|
||
| impl Deref for LoongArchType { | ||
| type Target = IntrinsicType; | ||
|
|
||
| fn deref(&self) -> &Self::Target { | ||
| &self.0 | ||
| } | ||
| } | ||
|
|
||
| impl DerefMut for LoongArchType { | ||
| fn deref_mut(&mut self) -> &mut Self::Target { | ||
| &mut self.0 | ||
| } | ||
| } |
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,139 @@ | ||
| mod intrinsic; | ||
| mod parser; | ||
| mod types; | ||
|
|
||
| use std::path::Path; | ||
|
|
||
| use crate::common::SupportedArchitecture; | ||
| use crate::common::cli::ProcessedCli; | ||
| use crate::common::intrinsic::Intrinsic; | ||
| use crate::common::intrinsic_helpers::TypeKind; | ||
| use intrinsic::LoongArchType; | ||
| use parser::get_intrinsics; | ||
|
|
||
| #[derive(PartialEq)] | ||
| pub struct LoongArch { | ||
| intrinsics: Vec<Intrinsic<LoongArch>>, | ||
| } | ||
|
|
||
| impl SupportedArchitecture for LoongArch { | ||
| type Type = LoongArchType; | ||
|
|
||
| fn intrinsics(&self) -> &[Intrinsic<Self>] { | ||
| &self.intrinsics | ||
| } | ||
|
|
||
| const NOTICE: &str = r#" | ||
| // This is a transient test file, not intended for distribution. Some aspects of the | ||
| // test are derived from LoongArch specification files, published under the same license as the | ||
| // `intrinsic-test` crate. | ||
| "#; | ||
|
|
||
| const C_PRELUDE: &str = r#" | ||
| #include <lsxintrin.h> | ||
| #include <lasxintrin.h> | ||
| "#; | ||
| const RUST_PRELUDE: &str = RUST_PRELUDE; | ||
|
|
||
| const C_NAME_PREFIX: &str = "__"; | ||
|
|
||
| fn c_compiler_flags(&self, _cli_options: &ProcessedCli) -> Vec<&str> { | ||
| let mut flags = vec!["-mlsx"]; | ||
| if self | ||
| .intrinsics | ||
| .iter() | ||
| .any(|intrinsic| intrinsic.extension == "LASX") | ||
| { | ||
| flags.push("-mlasx"); | ||
| } | ||
| if self.intrinsics.iter().any(|intrinsic| { | ||
| intrinsic.name.contains("frecipe") || intrinsic.name.contains("frsqrte") | ||
| }) { | ||
| flags.push("-mfrecipe"); | ||
| } | ||
| flags | ||
| } | ||
|
|
||
| fn create(cli_options: &ProcessedCli) -> Self { | ||
| let mut intrinsics = | ||
| load_intrinsics(&cli_options.filename).expect("Error parsing input file"); | ||
|
|
||
| intrinsics.sort_by(|a, b| a.name.cmp(&b.name)); | ||
| intrinsics.dedup_by(|a, b| { | ||
| a.name == b.name && a.results == b.results && a.arguments == b.arguments | ||
| }); | ||
|
|
||
| let intrinsics = intrinsics | ||
| .into_iter() | ||
| // Skip intrinsics that don't return a value. | ||
| .filter(|intrinsic| intrinsic.results.kind() != TypeKind::Void) | ||
| .filter(|intrinsic| !intrinsic.arguments.args.is_empty()) | ||
| // Skip pointers for now, we would probably need to look at the return | ||
| // type to work out how many elements we need to point to. | ||
| .filter(|intrinsic| !intrinsic.arguments.iter().any(|arg| arg.is_ptr())) | ||
| // Skip intrinsics from `--skip` | ||
| .filter(|intrinsic| !cli_options.skip.contains(&intrinsic.name)) | ||
| .collect::<Vec<_>>(); | ||
|
|
||
| let sample_percentage: usize = cli_options.sample_percentage as usize; | ||
| let sample_size = (intrinsics.len() * sample_percentage) / 100; | ||
| let intrinsics = intrinsics.into_iter().take(sample_size).collect(); | ||
|
|
||
| Self { intrinsics } | ||
| } | ||
|
|
||
| fn predicate_function(_: u32) -> String { | ||
| unimplemented!("no scalable vectors on LoongArch") | ||
| } | ||
| } | ||
|
|
||
| fn load_intrinsics(path: &Path) -> Result<Vec<Intrinsic<LoongArch>>, Box<dyn std::error::Error>> { | ||
| if path.is_dir() { | ||
| let mut intrinsics = Vec::new(); | ||
| for spec in ["lsx.spec", "lasx.spec"] { | ||
| let spec_path = path.join(spec); | ||
| if spec_path.exists() { | ||
| intrinsics.extend(get_intrinsics(&spec_path)?); | ||
| } | ||
| } | ||
| return Ok(intrinsics); | ||
| } | ||
|
|
||
| get_intrinsics(path) | ||
| } | ||
|
|
||
| const RUST_PRELUDE: &str = r#" | ||
| #![feature(stdarch_loongarch)] | ||
|
|
||
| use core_arch::arch::loongarch64::*; | ||
|
|
||
| #[inline] | ||
| unsafe fn lsx_vld_to_m128i(mem_addr: *const i8) -> m128i { | ||
| lsx_vld::<0>(mem_addr) | ||
| } | ||
|
|
||
| #[inline] | ||
| unsafe fn lsx_vld_to_m128(mem_addr: *const i8) -> m128 { | ||
| core::mem::transmute(lsx_vld::<0>(mem_addr)) | ||
| } | ||
|
|
||
| #[inline] | ||
| unsafe fn lsx_vld_to_m128d(mem_addr: *const i8) -> m128d { | ||
| core::mem::transmute(lsx_vld::<0>(mem_addr)) | ||
| } | ||
|
|
||
| #[inline] | ||
| unsafe fn lasx_xvld_to_m256i(mem_addr: *const i8) -> m256i { | ||
| lasx_xvld::<0>(mem_addr) | ||
| } | ||
|
|
||
| #[inline] | ||
| unsafe fn lasx_xvld_to_m256(mem_addr: *const i8) -> m256 { | ||
| core::mem::transmute(lasx_xvld::<0>(mem_addr)) | ||
| } | ||
|
|
||
| #[inline] | ||
| unsafe fn lasx_xvld_to_m256d(mem_addr: *const i8) -> m256d { | ||
| core::mem::transmute(lasx_xvld::<0>(mem_addr)) | ||
| } | ||
| "#; |
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.
Uh oh!
There was an error while loading. Please reload this page.