Skip to content

Commit

Permalink
Fill out the rest of the SIMD proposal (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Mar 31, 2021
1 parent 990fa4c commit 75d4728
Show file tree
Hide file tree
Showing 6 changed files with 265 additions and 163 deletions.
55 changes: 28 additions & 27 deletions crates/fuzz-utils/src/lib.rs
Expand Up @@ -151,6 +151,11 @@ where
let timeout = time::Duration::from_secs(self.timeout);
let mut failing = Ok(());
loop {
// Used all of our time, and didn't find any failing test cases.
if start.elapsed() > timeout {
return Ok(());
}

match self.run_one() {
Ok(()) => {
// We reduced fuel as far as we could, so return the last
Expand All @@ -159,12 +164,6 @@ where
return failing;
}

// Used all of our time, and didn't find any failing test cases.
if time::Instant::now().duration_since(start) > timeout {
assert!(failing.is_ok());
return Ok(());
}

// This did not produce a failing test case, so generate a
// new one.
continue;
Expand Down Expand Up @@ -393,27 +392,29 @@ impl TestCaseGenerator for WasmOptTtf {
let input_tmp = tempfile::NamedTempFile::new().expect("should create temp file OK");
fs::write(input_tmp.path(), input).expect("should write to temp file OK");

let wat =
match walrus_tests_utils::wasm_opt(input_tmp.path(), vec!["-ttf", "--emit-text"]) {
Ok(ref w) if Some(w) == last_wat.as_ref() => {
// We're stuck in a loop generating the same wat that
// `wat2wasm` can't handle over and over. This is
// typically because we're using an RNG that is derived
// from some fuzzer's output, and it is yielding all
// zeros or something. Just return the most basic wat
// module.
return "(module)".to_string();
}
Ok(w) => w,
Err(e) => {
// Sometimes `wasm-opt -ttf` fails to generate wasm
// modules, so we just try again with the next output
// from the RNG.
eprintln!("Warning: `wasm-opt -ttf` failed:");
print_err(&e);
continue;
}
};
let wat = match walrus_tests_utils::wasm_opt(
input_tmp.path(),
vec!["-ttf", "--emit-text", "--disable-simd", "--disable-threads"],
) {
Ok(ref w) if Some(w) == last_wat.as_ref() => {
// We're stuck in a loop generating the same wat that
// `wat2wasm` can't handle over and over. This is
// typically because we're using an RNG that is derived
// from some fuzzer's output, and it is yielding all
// zeros or something. Just return the most basic wat
// module.
return "(module)".to_string();
}
Ok(w) => w,
Err(e) => {
// Sometimes `wasm-opt -ttf` fails to generate wasm
// modules, so we just try again with the next output
// from the RNG.
eprintln!("Warning: `wasm-opt -ttf` failed:");
print_err(&e);
continue;
}
};

// Only generate programs that wat2wasm can handle.
if let Ok(bytes) = wat::parse_bytes(&wat) {
Expand Down
4 changes: 2 additions & 2 deletions crates/tests/Cargo.toml
Expand Up @@ -16,8 +16,8 @@ serde_json = { version = "1.0.40", features = ['preserve_order'] }
tempfile = "3.1.0"
walrus = { path = "../.." }
walrus-tests-utils = { path = "../tests-utils" }
wasmprinter = "0.2"
wat = "1.0"
wasmprinter = "0.2.25"
wat = "1.0.36"

[features]
parallel = ['walrus/parallel']
Expand Down
29 changes: 2 additions & 27 deletions crates/tests/build.rs
Expand Up @@ -6,36 +6,11 @@ use walkdir::WalkDir;

fn is_known_failing(name: &str) -> bool {
match name {
// TODO issues to investigate: wasm parsed when it shouldn't
// enabling multi-memory means that these tests fail, but the failure is
// benign.
"tests_spec_tests_proposals_bulk_memory_operations_binary_wast"
| "tests_spec_tests_proposals_reference_types_binary_wast" => true,

// SIMD isn't fully implemented yet.
"tests_spec_tests_proposals_simd_simd_boolean_wast"
| "tests_spec_tests_proposals_simd_simd_conversions_wast"
| "tests_spec_tests_proposals_simd_simd_f32x4_rounding_wast"
| "tests_spec_tests_proposals_simd_simd_f64x2_rounding_wast"
| "tests_spec_tests_proposals_simd_simd_i16x8_extadd_pairwise_i8x16_wast"
| "tests_spec_tests_proposals_simd_simd_i16x8_extmul_i8x16_wast"
| "tests_spec_tests_proposals_simd_simd_i16x8_q15mulr_sat_s_wast"
| "tests_spec_tests_proposals_simd_simd_i32x4_extadd_pairwise_i16x8_wast"
| "tests_spec_tests_proposals_simd_simd_i32x4_extmul_i16x8_wast"
| "tests_spec_tests_proposals_simd_simd_i32x4_trunc_sat_f64x2_wast"
| "tests_spec_tests_proposals_simd_simd_i64x2_arith2_wast"
| "tests_spec_tests_proposals_simd_simd_i64x2_cmp_wast"
| "tests_spec_tests_proposals_simd_simd_i64x2_extmul_i32x4_wast"
| "tests_spec_tests_proposals_simd_simd_i8x16_arith2_wast"
| "tests_spec_tests_proposals_simd_simd_int_to_int_extend_wast"
| "tests_spec_tests_proposals_simd_simd_load16_lane_wast"
| "tests_spec_tests_proposals_simd_simd_load32_lane_wast"
| "tests_spec_tests_proposals_simd_simd_load64_lane_wast"
| "tests_spec_tests_proposals_simd_simd_load8_lane_wast"
| "tests_spec_tests_proposals_simd_simd_load_zero_wast"
| "tests_spec_tests_proposals_simd_simd_store16_lane_wast"
| "tests_spec_tests_proposals_simd_simd_store32_lane_wast"
| "tests_spec_tests_proposals_simd_simd_store64_lane_wast"
| "tests_spec_tests_proposals_simd_simd_store8_lane_wast" => true,

_ => false,
}
}
Expand Down
49 changes: 49 additions & 0 deletions src/ir/mod.rs
Expand Up @@ -772,6 +772,13 @@ pub enum BinaryOp {
I32x4GeS,
I32x4GeU,

I64x2Eq,
I64x2Ne,
I64x2LtS,
I64x2GtS,
I64x2LeS,
I64x2GeS,

F32x4Eq,
F32x4Ne,
F32x4Lt,
Expand Down Expand Up @@ -861,6 +868,20 @@ pub enum BinaryOp {
I32x4MaxU,

I32x4DotI16x8S,

I16x8Q15MulrSatS,
I16x8ExtMulLowI8x16S,
I16x8ExtMulHighI8x16S,
I16x8ExtMulLowI8x16U,
I16x8ExtMulHighI8x16U,
I32x4ExtMulLowI16x8S,
I32x4ExtMulHighI16x8S,
I32x4ExtMulLowI16x8U,
I32x4ExtMulHighI16x8U,
I64x2ExtMulLowI32x4S,
I64x2ExtMulHighI32x4S,
I64x2ExtMulLowI32x4U,
I64x2ExtMulHighI32x4U,
}

/// Possible unary operations in wasm
Expand Down Expand Up @@ -946,6 +967,7 @@ pub enum UnaryOp {
V128AnyTrue,

I8x16Abs,
I8x16Popcnt,
I8x16Neg,
I8x16AllTrue,
I8x16Bitmask,
Expand All @@ -957,7 +979,10 @@ pub enum UnaryOp {
I32x4Neg,
I32x4AllTrue,
I32x4Bitmask,
I64x2Abs,
I64x2Neg,
I64x2AllTrue,
I64x2Bitmask,

F32x4Abs,
F32x4Neg,
Expand All @@ -974,6 +999,21 @@ pub enum UnaryOp {
F64x2Trunc,
F64x2Nearest,

I16x8ExtAddPairwiseI8x16S,
I16x8ExtAddPairwiseI8x16U,
I32x4ExtAddPairwiseI16x8S,
I32x4ExtAddPairwiseI16x8U,
I64x2ExtendLowI32x4S,
I64x2ExtendHighI32x4S,
I64x2ExtendLowI32x4U,
I64x2ExtendHighI32x4U,
I32x4TruncSatF64x2SZero,
I32x4TruncSatF64x2UZero,
F64x2ConvertLowI32x4S,
F64x2ConvertLowI32x4U,
F32x4DemoteF64x2Zero,
F64x2PromoteLowF32x4,

I32x4TruncSatF32x4S,
I32x4TruncSatF32x4U,
F32x4ConvertI32x4S,
Expand Down Expand Up @@ -1035,6 +1075,15 @@ pub enum LoadSimdKind {
V128Load32x2U,
V128Load32Zero,
V128Load64Zero,

V128Load8Lane(u8),
V128Load16Lane(u8),
V128Load32Lane(u8),
V128Load64Lane(u8),
V128Store8Lane(u8),
V128Store16Lane(u8),
V128Store32Lane(u8),
V128Store64Lane(u8),
}

/// The kinds of extended loads which can happen
Expand Down

0 comments on commit 75d4728

Please sign in to comment.