Skip to content

Commit

Permalink
Merge branch 'master' into trace-issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark McCaskey committed Jun 9, 2020
2 parents 87a7f11 + 7592ff9 commit 3f45582
Show file tree
Hide file tree
Showing 19 changed files with 1,031 additions and 704 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ llvm = [
"compiler",
]

# Testing features
test-singlepass = [
"singlepass",
]
test-cranelift = [
"cranelift",
]
test-llvm = [
"llvm",
]

# [profile.release]
# lto = "fat"

Expand Down
31 changes: 23 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,16 @@ compiler_features := --features "$(compiler_features_spaced)"
# Building #
############

test:
cargo test --release $(compiler_features)
bench: $(foreach compiler,$(compilers),test-$(compiler)) test-packages

bench:
cargo bench --features "jit" $(compiler_features)
bench-singlepass:
cargo test --release $(compiler_features) --features "jit,test-singlepass"

check-bench:
cargo check --benches --features "jit" $(compiler_features)
bench-cranelift:
cargo test --release $(compiler_features) --features "jit,test-cranelift"

bench-llvm:
cargo test --release $(compiler_features) --features "jit,test-llvm"

release:
build-wasmer:
Expand Down Expand Up @@ -105,8 +107,21 @@ build-capi-llvm:
# Testing #
###########

test:
cargo test --release $(compiler_features)
test: $(foreach compiler,$(compilers),test-$(compiler)) test-packages

test-singlepass:
cargo test --release $(compiler_features) --features "test-singlepass"

test-cranelift:
cargo test --release $(compiler_features) --features "test-cranelift"

test-llvm:
cargo test --release $(compiler_features) --features "test-llvm"

test-packages:
cargo test -p wasmer --release
cargo test -p wasmer-runtime --release
cargo test -p wasm-common --release

test-capi-singlepass: build-capi-singlepass
cargo test --manifest-path lib/c-api/Cargo.toml --release \
Expand Down
198 changes: 132 additions & 66 deletions benches/static_and_dynamic_functions.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use test_utils::{get_compiler_config_from_str, wasmer_compilers};
use test_utils::get_compiler_config_from_str;

use wasmer::*;
use wasmer_engine_jit::JITEngine;

Expand Down Expand Up @@ -32,94 +33,159 @@ static BASIC_WAT: &str = r#"(module
(call $multiply (local.get 1) (i32.const 2))))
)"#;

wasmer_compilers! {
use criterion::Criterion;
use super::*;
pub fn run_basic_static_function(c: &mut Criterion) {
let store = get_store();
let module = Module::new(&store, BASIC_WAT).unwrap();
let import_object = imports! {
"env" => {
"multiply" => Function::new(&store, |a: i32, b: i32| a * b),
},
};
let instance = Instance::new(&module, &import_object).unwrap();
let dyn_f: &Function = instance.exports.get("add").unwrap();
let f: NativeFunc<(i32, i32), i32> = dyn_f.native().unwrap();

c.bench_function(&format!("basic static func {}", COMPILER_NAME), |b| {
b.iter(|| {
let result = black_box(f.call(4, 6).unwrap());
assert_eq!(result, 10);
})
});

let dyn_f_many: &Function = instance.exports.get("add20").unwrap();
let f_many: NativeFunc<(i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32,
i32, i32, i32, i32, i32), i32> = dyn_f_many.native().unwrap();
c.bench_function(&format!("basic static func with many args {}", COMPILER_NAME), |b| {
pub fn run_basic_static_function(store: &Store, compiler_name: &str, c: &mut Criterion) {
let module = Module::new(&store, BASIC_WAT).unwrap();
let import_object = imports! {
"env" => {
"multiply" => Function::new(&store, |a: i32, b: i32| a * b),
},
};
let instance = Instance::new(&module, &import_object).unwrap();
let dyn_f: &Function = instance.exports.get("add").unwrap();
let f: NativeFunc<(i32, i32), i32> = dyn_f.native().unwrap();

c.bench_function(&format!("basic static func {}", compiler_name), |b| {
b.iter(|| {
let result = black_box(f.call(4, 6).unwrap());
assert_eq!(result, 10);
})
});

let dyn_f_many: &Function = instance.exports.get("add20").unwrap();
let f_many: NativeFunc<
(
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
i32,
),
i32,
> = dyn_f_many.native().unwrap();
c.bench_function(
&format!("basic static func with many args {}", compiler_name),
|b| {
b.iter(|| {
let result = black_box(f_many.call(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20).unwrap());
let result = black_box(
f_many
.call(
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
)
.unwrap(),
);
assert_eq!(result, 210);
})
});
}

pub fn run_basic_dynamic_function(c: &mut Criterion) {
let store = get_store();
let module = Module::new(&store, BASIC_WAT).unwrap();
let import_object = imports! {
"env" => {
"multiply" => Function::new(&store, |a: i32, b: i32| a * b),
},
};
let instance = Instance::new(&module, &import_object).unwrap();

let dyn_f: &Function = instance.exports.get("add").unwrap();
c.bench_function(&format!("basic dynfunc {}", COMPILER_NAME), |b| {
b.iter(|| {
let dyn_result = black_box(dyn_f.call(&[Val::I32(4), Val::I32(6)]).unwrap());
assert_eq!(dyn_result[0], Val::I32(10));
})
});
},
);
}

let dyn_f_many: &Function = instance.exports.get("add20").unwrap();
c.bench_function(&format!("basic dynfunc with many args {}", COMPILER_NAME), |b| {
pub fn run_basic_dynamic_function(store: &Store, compiler_name: &str, c: &mut Criterion) {
let module = Module::new(&store, BASIC_WAT).unwrap();
let import_object = imports! {
"env" => {
"multiply" => Function::new(&store, |a: i32, b: i32| a * b),
},
};
let instance = Instance::new(&module, &import_object).unwrap();

let dyn_f: &Function = instance.exports.get("add").unwrap();
c.bench_function(&format!("basic dynfunc {}", compiler_name), |b| {
b.iter(|| {
let dyn_result = black_box(dyn_f.call(&[Val::I32(4), Val::I32(6)]).unwrap());
assert_eq!(dyn_result[0], Val::I32(10));
})
});

let dyn_f_many: &Function = instance.exports.get("add20").unwrap();
c.bench_function(
&format!("basic dynfunc with many args {}", compiler_name),
|b| {
b.iter(|| {
let dyn_result = black_box(dyn_f_many.call(
&[Val::I32(1), Val::I32(2), Val::I32(3), Val::I32(4), Val::I32(5),
Val::I32(6), Val::I32(7), Val::I32(8), Val::I32(9), Val::I32(10),
Val::I32(11), Val::I32(12), Val::I32(13), Val::I32(14), Val::I32(15),
Val::I32(16), Val::I32(17), Val::I32(18), Val::I32(19), Val::I32(20),
]).unwrap());
let dyn_result = black_box(
dyn_f_many
.call(&[
Val::I32(1),
Val::I32(2),
Val::I32(3),
Val::I32(4),
Val::I32(5),
Val::I32(6),
Val::I32(7),
Val::I32(8),
Val::I32(9),
Val::I32(10),
Val::I32(11),
Val::I32(12),
Val::I32(13),
Val::I32(14),
Val::I32(15),
Val::I32(16),
Val::I32(17),
Val::I32(18),
Val::I32(19),
Val::I32(20),
])
.unwrap(),
);
assert_eq!(dyn_result[0], Val::I32(210));
})
});
}
},
);
}

fn run_static_benchmarks(c: &mut Criterion) {
#[cfg(feature = "llvm")]
llvm::run_basic_static_function(c);
{
let store = test_utils::get_default_llvm_store();
run_basic_static_function(&store, "llvm", c);
}

#[cfg(feature = "cranelift")]
cranelift::run_basic_static_function(c);
{
let store = test_utils::get_default_cranelift_store();
run_basic_static_function(&store, "cranelift", c);
}

#[cfg(feature = "singlepass")]
singlepass::run_basic_static_function(c);
{
let store = test_utils::get_default_singlepass_store();
run_basic_static_function(&store, "singlepass", c);
}
}

fn run_dynamic_benchmarks(c: &mut Criterion) {
#[cfg(feature = "llvm")]
llvm::run_basic_dynamic_function(c);
{
let store = test_utils::get_default_llvm_store();
run_basic_dynamic_function(&store, "llvm", c);
}

#[cfg(feature = "cranelift")]
cranelift::run_basic_dynamic_function(c);
{
let store = test_utils::get_default_cranelift_store();
run_basic_dynamic_function(&store, "cranelift", c);
}

#[cfg(feature = "singlepass")]
singlepass::run_basic_dynamic_function(c);
{
let store = test_utils::get_default_singlepass_store();
run_basic_dynamic_function(&store, "singlepass", c);
}
}

criterion_group!(benches, run_static_benchmarks, run_dynamic_benchmarks);
Expand Down
8 changes: 2 additions & 6 deletions lib/api/src/externals/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,14 @@ impl Function {
let signature = self.ty();
if signature.params().len() != params.len() {
return Err(RuntimeError::new(format!(
"expected {} arguments, got {}: Parameters of type [{}] did not match signature {}",
signature.params().len(),
params.len(),
"Parameters of type [{}] did not match signature {}",
format_types_for_error_message(params),
&signature
)));
}
if signature.results().len() != results.len() {
return Err(RuntimeError::new(format!(
"expected {} results, got {}: Results of type [{}] did not match signature {}",
signature.results().len(),
results.len(),
"Results of type [{}] did not match signature {}",
format_types_for_error_message(results),
&signature,
)));
Expand Down
2 changes: 1 addition & 1 deletion lib/c-api/tests/test-instantiate.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int main()
int error_result = wasmer_last_error_message(error_str, error_len);
assert(error_len == error_result);
printf("Error str: `%s`\n", error_str);
assert(0 == strcmp(error_str, "RuntimeError: expected 2 arguments, got 1: Parameters of type [I32] did not match signature [I32, I32] -> [I32]"));
assert(0 == strcmp(error_str, "RuntimeError: Parameters of type [I32] did not match signature [I32, I32] -> [I32]"));
free(error_str);

printf("Destroy instance\n");
Expand Down
2 changes: 1 addition & 1 deletion lib/wasm-common/src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ mod test_features {
reference_types: false,
simd: false,
bulk_memory: false,
multi_value: false,
multi_value: true,
}
);
}
Expand Down
Loading

0 comments on commit 3f45582

Please sign in to comment.