-
Notifications
You must be signed in to change notification settings - Fork 329
Port stdarch-gen-loongarch to stdarch-gen-common harness #2178
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
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.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| // This code is automatically generated. DO NOT MODIFY. | ||
| // See crates/stdarch-gen-loongarch/README.md | ||
| // This code is automatically generated. DO NOT MODIFY. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the By the way, if you regenerate the Loongarch
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a different header . As for regenerating the tests.rs i haven't actually run it. Thank you! |
||
|
|
||
| use crate::{ | ||
| core_arch::{loongarch64::*, simd::*}, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,3 +8,4 @@ edition = "2024" | |
|
|
||
| [dependencies] | ||
| rand = "0.9.3" | ||
| stdarch-gen-common = { path = "../stdarch-gen-common" } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,7 +4,9 @@ use std::fmt; | |||||||||||||||||||||||||
| use std::fs::File; | ||||||||||||||||||||||||||
| use std::io::prelude::*; | ||||||||||||||||||||||||||
| use std::io::{self, BufReader}; | ||||||||||||||||||||||||||
| use std::path::Path; | ||||||||||||||||||||||||||
| use std::path::PathBuf; | ||||||||||||||||||||||||||
| use stdarch_gen_common::{Mode, run_generator}; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /// Complete lines of generated source. | ||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||
|
|
@@ -148,8 +150,8 @@ fn gen_spec(in_file: String, ext_name: &str) -> io::Result<()> { | |||||||||||||||||||||||||
| Ok(()) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| fn gen_bind(in_file: String, ext_name: &str) -> io::Result<()> { | ||||||||||||||||||||||||||
| let f = File::open(in_file.clone()).unwrap_or_else(|_| panic!("Failed to open {in_file}")); | ||||||||||||||||||||||||||
| fn gen_bind(in_file: &str, ext_name: &str, out_path: &Path) -> io::Result<()> { | ||||||||||||||||||||||||||
| let f = File::open(in_file).unwrap_or_else(|_| panic!("Failed to open {in_file}")); | ||||||||||||||||||||||||||
| let f = BufReader::new(f); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| let target: TargetFeature = TargetFeature::new(ext_name); | ||||||||||||||||||||||||||
|
|
@@ -241,13 +243,7 @@ unsafe extern "unadjusted" { | |||||||||||||||||||||||||
| out.push_str("}\n"); | ||||||||||||||||||||||||||
| out.push_str(&function_str); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| let out_path: PathBuf = | ||||||||||||||||||||||||||
| PathBuf::from(env::var("OUT_DIR").unwrap_or("crates/core_arch".to_string())) | ||||||||||||||||||||||||||
| .join("src") | ||||||||||||||||||||||||||
| .join("loongarch64") | ||||||||||||||||||||||||||
| .join(ext_name); | ||||||||||||||||||||||||||
| std::fs::create_dir_all(&out_path)?; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| std::fs::create_dir_all(out_path)?; | ||||||||||||||||||||||||||
| let mut file = File::create(out_path.join("generated.rs"))?; | ||||||||||||||||||||||||||
| file.write_all(out.as_bytes())?; | ||||||||||||||||||||||||||
| Ok(()) | ||||||||||||||||||||||||||
|
|
@@ -862,8 +858,10 @@ union v4df | |||||||||||||||||||||||||
| out.push('\n'); | ||||||||||||||||||||||||||
| out.push_str("int main(int argc, char *argv[])\n"); | ||||||||||||||||||||||||||
| out.push_str("{\n"); | ||||||||||||||||||||||||||
| out.push_str(" printf(\"// This code is automatically generated. DO NOT MODIFY.\\n\");\n"); | ||||||||||||||||||||||||||
| out.push_str(" printf(\"// See crates/stdarch-gen-loongarch/README.md\\n\\n\");\n"); | ||||||||||||||||||||||||||
| out.push_str(" printf(\"// See crates/stdarch-gen-loongarch/README.md\\n\");\n"); | ||||||||||||||||||||||||||
| out.push_str( | ||||||||||||||||||||||||||
| " printf(\"// This code is automatically generated. DO NOT MODIFY.\\n\\n\");\n", | ||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||
| out.push_str(" printf(\"use crate::{\\n\");\n"); | ||||||||||||||||||||||||||
| out.push_str(" printf(\" core_arch::{loongarch64::*, simd::*},\\n\");\n"); | ||||||||||||||||||||||||||
| out.push_str(" printf(\" mem::transmute,\\n\");\n"); | ||||||||||||||||||||||||||
|
|
@@ -1604,28 +1602,52 @@ static void {current_name}(void) | |||||||||||||||||||||||||
| (impl_function, call_function) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| pub fn main() -> io::Result<()> { | ||||||||||||||||||||||||||
| /// Runs the check/bless harness for `lsx`/`lasx` when invoked with | ||||||||||||||||||||||||||
| /// no args or a bare ext name. | ||||||||||||||||||||||||||
| pub fn main() -> Result<(), String> { | ||||||||||||||||||||||||||
| let args: Vec<String> = env::args().collect(); | ||||||||||||||||||||||||||
| let in_file = args.get(1).cloned().expect("Input file missing!"); | ||||||||||||||||||||||||||
| let in_file_path = PathBuf::from(&in_file); | ||||||||||||||||||||||||||
| let in_file_name = in_file_path | ||||||||||||||||||||||||||
| let harness_exts: Option<&[&str]> = match args.len() { | ||||||||||||||||||||||||||
| 1 => Some(&["lsx", "lasx"]), | ||||||||||||||||||||||||||
| 2 if args[1] == "lsx" => Some(&["lsx"]), | ||||||||||||||||||||||||||
| 2 if args[1] == "lasx" => Some(&["lasx"]), | ||||||||||||||||||||||||||
| _ => None, | ||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpicky but I think this should work
Suggested change
|
||||||||||||||||||||||||||
| if let Some(exts) = harness_exts { | ||||||||||||||||||||||||||
| let crate_dir = | ||||||||||||||||||||||||||
| PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set")); | ||||||||||||||||||||||||||
| let core_arch_src = crate_dir.join("../core_arch/src"); | ||||||||||||||||||||||||||
| let mode = Mode::from_env(); | ||||||||||||||||||||||||||
| for ext in exts { | ||||||||||||||||||||||||||
| let spec_rel = format!("crates/stdarch-gen-loongarch/{ext}.spec"); | ||||||||||||||||||||||||||
| let committed = core_arch_src.join("loongarch64").join(ext); | ||||||||||||||||||||||||||
| run_generator(&committed, mode, |out_dir| { | ||||||||||||||||||||||||||
| gen_bind(&spec_rel, ext, out_dir) | ||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||
| .map_err(|e| e.to_string())?; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| return Ok(()); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| let in_file = args[1].clone(); | ||||||||||||||||||||||||||
| let in_file_name = PathBuf::from(&in_file) | ||||||||||||||||||||||||||
| .file_name() | ||||||||||||||||||||||||||
| .unwrap() | ||||||||||||||||||||||||||
| .to_os_string() | ||||||||||||||||||||||||||
| .into_string() | ||||||||||||||||||||||||||
| .unwrap(); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| .to_string_lossy() | ||||||||||||||||||||||||||
| .into_owned(); | ||||||||||||||||||||||||||
| let ext_name = if in_file_name.starts_with("lasx") { | ||||||||||||||||||||||||||
| "lasx" | ||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||
| "lsx" | ||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if in_file_name.ends_with(".h") { | ||||||||||||||||||||||||||
| gen_spec(in_file, ext_name) | ||||||||||||||||||||||||||
| } else if args.get(2).is_some() { | ||||||||||||||||||||||||||
| gen_test(in_file, ext_name) | ||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||
| gen_bind(in_file, ext_name) | ||||||||||||||||||||||||||
| return gen_spec(in_file, ext_name).map_err(|e| e.to_string()); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| if args.get(2).is_some() { | ||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I kind of lost what is in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
is much clearer then.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. YES . |
||||||||||||||||||||||||||
| return gen_test(in_file, ext_name).map_err(|e| e.to_string()); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| let out_path = PathBuf::from(env::var("OUT_DIR").unwrap_or("crates/core_arch".to_string())) | ||||||||||||||||||||||||||
| .join("src") | ||||||||||||||||||||||||||
| .join("loongarch64") | ||||||||||||||||||||||||||
| .join(ext_name); | ||||||||||||||||||||||||||
| gen_bind(&in_file, ext_name, &out_path).map_err(|e| e.to_string()) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
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.
Ultimately, this will still be a bit annoying to replicate in bootstrap, as we have to ensure that we invoke both the right crates, and with the right arguments.
That is not for this PR, but I'd think about merging everything into a single binary that will generate everything, I think that would be easier to work with.
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.
Agreed.