Enable SIMD instructions from the command line (#232)
This change adds an `--enable-simd` flag to the binaries in this project. This allows the ISA `enable_simd` flag to be set and to configure the validation configuration used by wasmparser to allow SIMD instructions.
This commit is contained in:
committed by
Yury Delendik
parent
fff0198fb7
commit
5873f697fc
@@ -31,6 +31,7 @@
|
||||
|
||||
use cranelift_codegen::isa;
|
||||
use cranelift_codegen::settings;
|
||||
use cranelift_codegen::settings::Configurable;
|
||||
use cranelift_native;
|
||||
use docopt::Docopt;
|
||||
use faerie::Artifact;
|
||||
@@ -62,7 +63,7 @@ The translation is dependent on the environment chosen.
|
||||
The default is a dummy environment that produces placeholder values.
|
||||
|
||||
Usage:
|
||||
wasm2obj [--target TARGET] [-cdg] <file> -o <output>
|
||||
wasm2obj [--target TARGET] [-cdg] [--enable-simd] <file> -o <output>
|
||||
wasm2obj --help | --version
|
||||
|
||||
Options:
|
||||
@@ -71,6 +72,7 @@ Options:
|
||||
--target <TARGET> build for the target triple; default is the host machine
|
||||
-g generate debug information
|
||||
-c, --cache enable caching system
|
||||
--enable-simd enable proposed SIMD instructions
|
||||
--version print the Cranelift version
|
||||
-d, --debug enable debug output on stderr/stdout
|
||||
";
|
||||
@@ -83,6 +85,7 @@ struct Args {
|
||||
flag_g: bool,
|
||||
flag_debug: bool,
|
||||
flag_cache: bool,
|
||||
flag_enable_simd: bool,
|
||||
}
|
||||
|
||||
fn read_wasm_file(path: PathBuf) -> Result<Vec<u8>, io::Error> {
|
||||
@@ -116,6 +119,7 @@ fn main() {
|
||||
&args.arg_target,
|
||||
&args.arg_output,
|
||||
args.flag_g,
|
||||
args.flag_enable_simd,
|
||||
) {
|
||||
Ok(()) => {}
|
||||
Err(message) => {
|
||||
@@ -130,6 +134,7 @@ fn handle_module(
|
||||
target: &Option<String>,
|
||||
output: &str,
|
||||
generate_debug_info: bool,
|
||||
enable_simd: bool,
|
||||
) -> Result<(), String> {
|
||||
let data = match read_wasm_file(path) {
|
||||
Ok(data) => data,
|
||||
@@ -152,7 +157,10 @@ fn handle_module(
|
||||
panic!("host machine is not a supported target");
|
||||
}),
|
||||
};
|
||||
let flag_builder = settings::builder();
|
||||
let mut flag_builder = settings::builder();
|
||||
if enable_simd {
|
||||
flag_builder.enable("enable_simd").unwrap();
|
||||
}
|
||||
let isa = isa_builder.finish(settings::Flags::new(flag_builder));
|
||||
|
||||
let mut obj = Artifact::new(isa.triple().clone(), String::from(output));
|
||||
|
||||
@@ -47,7 +47,7 @@ use std::process::exit;
|
||||
use wabt;
|
||||
use wasi_common::preopen_dir;
|
||||
use wasmtime_environ::cache_conf;
|
||||
use wasmtime_jit::{ActionOutcome, Context};
|
||||
use wasmtime_jit::{ActionOutcome, Context, Features};
|
||||
use wasmtime_wasi::instantiate_wasi;
|
||||
use wasmtime_wast::instantiate_spectest;
|
||||
|
||||
@@ -66,8 +66,8 @@ including calling the start function if one is present. Additional functions
|
||||
given with --invoke are then called.
|
||||
|
||||
Usage:
|
||||
wasmtime [-ocdg] [--wasi-c] [--preload=<wasm>...] [--env=<env>...] [--dir=<dir>...] [--mapdir=<mapping>...] <file> [<arg>...]
|
||||
wasmtime [-ocdg] [--wasi-c] [--preload=<wasm>...] [--env=<env>...] [--dir=<dir>...] [--mapdir=<mapping>...] --invoke=<fn> <file> [<arg>...]
|
||||
wasmtime [-ocdg] [--enable-simd] [--wasi-c] [--preload=<wasm>...] [--env=<env>...] [--dir=<dir>...] [--mapdir=<mapping>...] <file> [<arg>...]
|
||||
wasmtime [-ocdg] [--enable-simd] [--wasi-c] [--preload=<wasm>...] [--env=<env>...] [--dir=<dir>...] [--mapdir=<mapping>...] --invoke=<fn> <file> [<arg>...]
|
||||
wasmtime --help | --version
|
||||
|
||||
Options:
|
||||
@@ -76,6 +76,7 @@ Options:
|
||||
-c, --cache enable caching system
|
||||
-g generate debug information
|
||||
-d, --debug enable debug output on stderr/stdout
|
||||
--enable-simd enable proposed SIMD instructions
|
||||
--wasi-c enable the wasi-c implementation of WASI
|
||||
--preload=<wasm> load an additional wasm module before loading the main module
|
||||
--env=<env> pass an environment variable (\"key=value\") to the program
|
||||
@@ -94,6 +95,7 @@ struct Args {
|
||||
flag_cache: bool,
|
||||
flag_debug: bool,
|
||||
flag_g: bool,
|
||||
flag_enable_simd: bool,
|
||||
flag_invoke: Option<String>,
|
||||
flag_preload: Vec<String>,
|
||||
flag_env: Vec<String>,
|
||||
@@ -214,19 +216,26 @@ fn main() {
|
||||
panic!("host machine is not a supported target");
|
||||
});
|
||||
let mut flag_builder = settings::builder();
|
||||
let mut features: Features = Default::default();
|
||||
|
||||
// Enable verifier passes in debug mode.
|
||||
if cfg!(debug_assertions) {
|
||||
flag_builder.enable("enable_verifier").unwrap();
|
||||
}
|
||||
|
||||
// Enable SIMD if requested
|
||||
if args.flag_enable_simd {
|
||||
flag_builder.enable("enable_simd").unwrap();
|
||||
features.simd = true;
|
||||
}
|
||||
|
||||
// Enable optimization if requested.
|
||||
if args.flag_optimize {
|
||||
flag_builder.set("opt_level", "best").unwrap();
|
||||
}
|
||||
|
||||
let isa = isa_builder.finish(settings::Flags::new(flag_builder));
|
||||
let mut context = Context::with_isa(isa);
|
||||
let mut context = Context::with_isa(isa).with_features(features);
|
||||
|
||||
// Make spectest available by default.
|
||||
context.name_instance(
|
||||
|
||||
15
src/wast.rs
15
src/wast.rs
@@ -34,7 +34,7 @@ use serde::Deserialize;
|
||||
use std::path::Path;
|
||||
use std::process;
|
||||
use wasmtime_environ::cache_conf;
|
||||
use wasmtime_jit::Compiler;
|
||||
use wasmtime_jit::{Compiler, Features};
|
||||
use wasmtime_wast::WastContext;
|
||||
|
||||
mod utils;
|
||||
@@ -45,7 +45,7 @@ const USAGE: &str = "
|
||||
Wast test runner.
|
||||
|
||||
Usage:
|
||||
run_wast [-cdo] <file>...
|
||||
run_wast [-cdo] [--enable-simd] <file>...
|
||||
run_wast --help | --version
|
||||
|
||||
Options:
|
||||
@@ -54,6 +54,7 @@ Options:
|
||||
-o, --optimize runs optimization passes on the translated functions
|
||||
-c, --cache enable caching system
|
||||
-d, --debug enable debug output on stderr/stdout
|
||||
--enable-simd enable proposed SIMD instructions
|
||||
";
|
||||
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
@@ -63,6 +64,7 @@ struct Args {
|
||||
flag_function: Option<String>,
|
||||
flag_optimize: bool,
|
||||
flag_cache: bool,
|
||||
flag_enable_simd: bool,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@@ -87,6 +89,7 @@ fn main() {
|
||||
panic!("host machine is not a supported target");
|
||||
});
|
||||
let mut flag_builder = settings::builder();
|
||||
let mut features: Features = Default::default();
|
||||
|
||||
// Enable verifier passes in debug mode.
|
||||
if cfg!(debug_assertions) {
|
||||
@@ -98,9 +101,15 @@ fn main() {
|
||||
flag_builder.set("opt_level", "best").unwrap();
|
||||
}
|
||||
|
||||
// Enable SIMD if requested
|
||||
if args.flag_enable_simd {
|
||||
flag_builder.enable("enable_simd").unwrap();
|
||||
features.simd = true;
|
||||
}
|
||||
|
||||
let isa = isa_builder.finish(settings::Flags::new(flag_builder));
|
||||
let engine = Compiler::new(isa);
|
||||
let mut wast_context = WastContext::new(Box::new(engine));
|
||||
let mut wast_context = WastContext::new(Box::new(engine)).with_features(features);
|
||||
|
||||
wast_context
|
||||
.register_spectest()
|
||||
|
||||
Reference in New Issue
Block a user