This adds full support for all Cranelift SIMD instructions to the s390x target. Everything is matched fully via ISLE. In addition to adding support for many new instructions, and the lower.isle code to match all SIMD IR patterns, this patch also adds ABI support for vector types. In particular, we now need to handle the fact that vector registers 8 .. 15 are partially callee-saved, i.e. the high parts of those registers (which correspond to the old floating-poing registers) are callee-saved, but the low parts are not. This is the exact same situation that we already have on AArch64, and so this patch uses the same solution (the is_included_in_clobbers callback). The bulk of the changes are platform-specific, but there are a few exceptions: - Added ISLE extractors for the Immediate and Constant types, to enable matching the vconst and swizzle instructions. - Added a missing accessor for call_conv to ABISig. - Fixed endian conversion for vector types in data_value.rs to enable their use in runtests on the big-endian platforms. - Enabled (nearly) all SIMD runtests on s390x. [ Two test cases remain disabled due to vector shift count semantics, see below. ] - Enabled all Wasmtime SIMD tests on s390x. There are three minor issues, called out via FIXMEs below, which should be addressed in the future, but should not be blockers to getting this patch merged. I've opened the following issues to track them: - Vector shift count semantics https://github.com/bytecodealliance/wasmtime/issues/4424 - is_included_in_clobbers vs. link register https://github.com/bytecodealliance/wasmtime/issues/4425 - gen_constant callback https://github.com/bytecodealliance/wasmtime/issues/4426 All tests, including all newly enabled SIMD tests, pass on both z14 and z15 architectures.
188 lines
5.6 KiB
Rust
188 lines
5.6 KiB
Rust
//! Build program to generate a program which runs all the testsuites.
|
|
//!
|
|
//! By generating a separate `#[test]` test for each file, we allow cargo test
|
|
//! to automatically run the files in parallel.
|
|
|
|
use anyhow::Context;
|
|
use std::env;
|
|
use std::fmt::Write;
|
|
use std::fs;
|
|
use std::path::{Path, PathBuf};
|
|
use std::process::Command;
|
|
|
|
fn main() -> anyhow::Result<()> {
|
|
println!("cargo:rerun-if-changed=build.rs");
|
|
let out_dir = PathBuf::from(
|
|
env::var_os("OUT_DIR").expect("The OUT_DIR environment variable must be set"),
|
|
);
|
|
let mut out = String::new();
|
|
|
|
for strategy in &["Cranelift"] {
|
|
writeln!(out, "#[cfg(test)]")?;
|
|
writeln!(out, "#[allow(non_snake_case)]")?;
|
|
writeln!(out, "mod {} {{", strategy)?;
|
|
|
|
with_test_module(&mut out, "misc", |out| {
|
|
test_directory(out, "tests/misc_testsuite", strategy)?;
|
|
test_directory_module(out, "tests/misc_testsuite/multi-memory", strategy)?;
|
|
test_directory_module(out, "tests/misc_testsuite/simd", strategy)?;
|
|
test_directory_module(out, "tests/misc_testsuite/threads", strategy)?;
|
|
test_directory_module(out, "tests/misc_testsuite/memory64", strategy)?;
|
|
if cfg!(feature = "component-model") {
|
|
test_directory_module(out, "tests/misc_testsuite/component-model", strategy)?;
|
|
}
|
|
Ok(())
|
|
})?;
|
|
|
|
with_test_module(&mut out, "spec", |out| {
|
|
let spec_tests = test_directory(out, "tests/spec_testsuite", strategy)?;
|
|
// Skip running spec_testsuite tests if the submodule isn't checked
|
|
// out.
|
|
if spec_tests > 0 {
|
|
test_directory_module(out, "tests/spec_testsuite/proposals/memory64", strategy)?;
|
|
} else {
|
|
println!(
|
|
"cargo:warning=The spec testsuite is disabled. To enable, run `git submodule \
|
|
update --remote`."
|
|
);
|
|
}
|
|
Ok(())
|
|
})?;
|
|
|
|
writeln!(out, "}}")?;
|
|
}
|
|
|
|
// Write out our auto-generated tests and opportunistically format them with
|
|
// `rustfmt` if it's installed.
|
|
let output = out_dir.join("wast_testsuite_tests.rs");
|
|
fs::write(&output, out)?;
|
|
drop(Command::new("rustfmt").arg(&output).status());
|
|
Ok(())
|
|
}
|
|
|
|
fn test_directory_module(
|
|
out: &mut String,
|
|
path: impl AsRef<Path>,
|
|
strategy: &str,
|
|
) -> anyhow::Result<usize> {
|
|
let path = path.as_ref();
|
|
let testsuite = &extract_name(path);
|
|
with_test_module(out, testsuite, |out| test_directory(out, path, strategy))
|
|
}
|
|
|
|
fn test_directory(
|
|
out: &mut String,
|
|
path: impl AsRef<Path>,
|
|
strategy: &str,
|
|
) -> anyhow::Result<usize> {
|
|
let path = path.as_ref();
|
|
let mut dir_entries: Vec<_> = path
|
|
.read_dir()
|
|
.context(format!("failed to read {:?}", path))?
|
|
.map(|r| r.expect("reading testsuite directory entry"))
|
|
.filter_map(|dir_entry| {
|
|
let p = dir_entry.path();
|
|
let ext = p.extension()?;
|
|
// Only look at wast files.
|
|
if ext != "wast" {
|
|
return None;
|
|
}
|
|
// Ignore files starting with `.`, which could be editor temporary files
|
|
if p.file_stem()?.to_str()?.starts_with(".") {
|
|
return None;
|
|
}
|
|
Some(p)
|
|
})
|
|
.collect();
|
|
|
|
dir_entries.sort();
|
|
|
|
let testsuite = &extract_name(path);
|
|
for entry in dir_entries.iter() {
|
|
write_testsuite_tests(out, entry, testsuite, strategy, false)?;
|
|
write_testsuite_tests(out, entry, testsuite, strategy, true)?;
|
|
}
|
|
|
|
Ok(dir_entries.len())
|
|
}
|
|
|
|
/// Extract a valid Rust identifier from the stem of a path.
|
|
fn extract_name(path: impl AsRef<Path>) -> String {
|
|
path.as_ref()
|
|
.file_stem()
|
|
.expect("filename should have a stem")
|
|
.to_str()
|
|
.expect("filename should be representable as a string")
|
|
.replace("-", "_")
|
|
.replace("/", "_")
|
|
}
|
|
|
|
fn with_test_module<T>(
|
|
out: &mut String,
|
|
testsuite: &str,
|
|
f: impl FnOnce(&mut String) -> anyhow::Result<T>,
|
|
) -> anyhow::Result<T> {
|
|
out.push_str("mod ");
|
|
out.push_str(testsuite);
|
|
out.push_str(" {\n");
|
|
|
|
let result = f(out)?;
|
|
|
|
out.push_str("}\n");
|
|
Ok(result)
|
|
}
|
|
|
|
fn write_testsuite_tests(
|
|
out: &mut String,
|
|
path: impl AsRef<Path>,
|
|
testsuite: &str,
|
|
strategy: &str,
|
|
pooling: bool,
|
|
) -> anyhow::Result<()> {
|
|
let path = path.as_ref();
|
|
let testname = extract_name(path);
|
|
|
|
writeln!(out, "#[test]")?;
|
|
// Ignore when using QEMU for running tests (limited memory).
|
|
if ignore(testsuite, &testname, strategy) {
|
|
writeln!(out, "#[ignore]")?;
|
|
}
|
|
|
|
writeln!(
|
|
out,
|
|
"fn r#{}{}() {{",
|
|
&testname,
|
|
if pooling { "_pooling" } else { "" }
|
|
)?;
|
|
writeln!(out, " let _ = env_logger::try_init();")?;
|
|
writeln!(
|
|
out,
|
|
" crate::wast::run_wast(r#\"{}\"#, crate::wast::Strategy::{}, {}).unwrap();",
|
|
path.display(),
|
|
strategy,
|
|
pooling
|
|
)?;
|
|
writeln!(out, "}}")?;
|
|
writeln!(out)?;
|
|
Ok(())
|
|
}
|
|
|
|
/// Ignore tests that aren't supported yet.
|
|
fn ignore(testsuite: &str, testname: &str, strategy: &str) -> bool {
|
|
match strategy {
|
|
"Cranelift" => match (testsuite, testname) {
|
|
// FIXME: These tests fail under qemu due to a qemu bug.
|
|
(_, "simd_f32x4_pmin_pmax") if platform_is_s390x() => return true,
|
|
(_, "simd_f64x2_pmin_pmax") if platform_is_s390x() => return true,
|
|
_ => {}
|
|
},
|
|
_ => panic!("unrecognized strategy"),
|
|
}
|
|
|
|
false
|
|
}
|
|
|
|
fn platform_is_s390x() -> bool {
|
|
env::var("CARGO_CFG_TARGET_ARCH").unwrap() == "s390x"
|
|
}
|