Repository navigation
Support fuzz testing RISC-V intrinsics against C API #2263
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
TechnoPorg
wants to merge
2
commits into
rust-lang:main
Choose a base branch
from
TechnoPorg:push-pxsnmmxmvwtv
base: main
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.
+1,556
−18
Open
Changes from all commits
Commits
Show all changes
2 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
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,15 @@ | ||
| # Not implemented in stdarch | ||
| clz_32 | ||
| clz_64 | ||
| ctz_32 | ||
| ctz_64 | ||
| cpop_32 | ||
| cpop_64 | ||
| ror_32 | ||
| ror_64 | ||
| rol_32 | ||
| rol_64 | ||
| rev8_32 | ||
| rev8_64 | ||
| brev8_32 | ||
| brev8_64 | ||
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
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 RiscvIntrinsicType(pub IntrinsicType); | ||
|
|
||
| impl Deref for RiscvIntrinsicType { | ||
| type Target = IntrinsicType; | ||
|
|
||
| fn deref(&self) -> &Self::Target { | ||
| &self.0 | ||
| } | ||
| } | ||
|
|
||
| impl DerefMut for RiscvIntrinsicType { | ||
| 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,104 @@ | ||
| 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 crate::riscv::parser::get_intrinsics; | ||
| use intrinsic::RiscvIntrinsicType; | ||
|
|
||
| #[derive(PartialEq)] | ||
| pub struct Riscv { | ||
| intrinsics: Vec<Intrinsic<Riscv>>, | ||
| } | ||
|
|
||
| impl SupportedArchitecture for Riscv { | ||
| type Type = RiscvIntrinsicType; | ||
|
|
||
| fn intrinsics(&self) -> &[Intrinsic<Self>] { | ||
| &self.intrinsics | ||
| } | ||
|
|
||
| fn create(cli_options: &ProcessedCli) -> Self { | ||
| let rv32 = cli_options.target.starts_with("riscv32"); | ||
|
|
||
| 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 sample_percentage: usize = cli_options.sample_percentage as usize; | ||
| let sample_size = (intrinsics.len() * sample_percentage) / 100; | ||
|
|
||
| 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()) | ||
| .filter(|intrinsic| !cli_options.skip.contains(&intrinsic.name)) | ||
| .filter(|intrinsic| { | ||
| intrinsic.arch_tags.is_empty() || ((intrinsic.arch_tags[0] == "rv64") ^ rv32) | ||
| }) | ||
| .take(sample_size) | ||
| .collect::<Vec<_>>(); | ||
|
|
||
| Self { intrinsics } | ||
| } | ||
|
|
||
| const NOTICE: &str = r#" | ||
| // This is a transient test file, not intended for distribution. Some aspects of the | ||
| // test are derived from RISC-V specification files, published under the same license as the | ||
| // `intrinsic-test` crate. | ||
| "#; | ||
|
|
||
| const C_PRELUDE: &str = r#" | ||
| #include <riscv_bitmanip.h> | ||
| #include <riscv_crypto.h> | ||
| "#; | ||
|
|
||
| const RUST_PRELUDE: &str = RUST_PRELUDE; | ||
|
|
||
| const C_NAME_PREFIX: &str = "__riscv_"; | ||
|
|
||
| fn c_compiler_flags(&self, cli_options: &ProcessedCli) -> Vec<&str> { | ||
| let arch_str = if cli_options.target.starts_with("riscv32") { | ||
| "-march=rv32gc_zbb_zbc_zk_zks" | ||
| } else { | ||
| "-march=rv64gc_zbb_zbc_zk_zks" | ||
| }; | ||
| vec![arch_str] | ||
| } | ||
|
|
||
| fn predicate_function(_: u32) -> String { | ||
| unimplemented!("scalable vector intrinsics are currently unimplemented for RISC-V") | ||
| } | ||
| } | ||
|
|
||
| const RUST_PRELUDE: &str = r#" | ||
| #![feature(riscv_ext_intrinsics)] | ||
|
|
||
| #[cfg(target_arch = "riscv64")] | ||
| use core_arch::arch::riscv64::*; | ||
| #[cfg(target_arch = "riscv32")] | ||
| use core_arch::arch::riscv32::*; | ||
| "#; | ||
|
|
||
| fn load_intrinsics(path: &Path) -> Result<Vec<Intrinsic<Riscv>>, Box<dyn std::error::Error>> { | ||
| if path.is_dir() { | ||
| let mut intrinsics = Vec::new(); | ||
| for spec in ["crypto.spec", "bitmanip.spec"] { | ||
| let spec_path = path.join(spec); | ||
| intrinsics.extend(get_intrinsics(&spec_path)?); | ||
| } | ||
| return Ok(intrinsics); | ||
| } | ||
|
|
||
| get_intrinsics(path) | ||
| } |
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.