Skip to content

Commit

Permalink
Merge pull request wasmerio#3363 from wasmerio/feat_store-used-cpufea…
Browse files Browse the repository at this point in the history
…ture-artifact

Store Used CpuFeature in Artifact instead of Present CpuFeatures for Singlepass
  • Loading branch information
syrusakbary authored Nov 30, 2022
2 parents 46328d5 + 253fd4f commit df8307e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 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.

1 change: 1 addition & 0 deletions lib/compiler-singlepass/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ wasmer-compiler = { path = "../compiler", version = "=3.0.2", features = ["trans
wasmer-types = { path = "../types", version = "=3.0.2", default-features = false, features = ["std"] }
hashbrown = { version = "0.11", optional = true }
gimli = { version = "0.26", optional = true }
enumset = "1.0.2"
more-asserts = "0.2"
dynasm = "1.2.3"
dynasmrt = "1.2.3"
Expand Down
26 changes: 26 additions & 0 deletions lib/compiler-singlepass/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::machine_arm64::MachineARM64;
use crate::machine_x64::MachineX86_64;
#[cfg(feature = "unwind")]
use crate::unwind::{create_systemv_cie, UnwindFrame};
use enumset::EnumSet;
#[cfg(feature = "unwind")]
use gimli::write::{EhFrame, FrameTable};
#[cfg(feature = "rayon")]
Expand Down Expand Up @@ -256,6 +257,11 @@ impl Compiler for SinglepassCompiler {
debug: dwarf,
})
}

fn get_cpu_features_used(&self, cpu_features: &EnumSet<CpuFeature>) -> EnumSet<CpuFeature> {
let used = CpuFeature::AVX | CpuFeature::SSE42 | CpuFeature::LZCNT | CpuFeature::BMI1;
cpu_features.intersection(used)
}
}

trait IntoParIterIfRayon {
Expand Down Expand Up @@ -323,4 +329,24 @@ mod tests {
error => panic!("Unexpected error: {:?}", error),
};
}

#[test]
fn errors_for_unsuported_cpufeatures() {
let compiler = SinglepassCompiler::new(Singlepass::default());
let mut features =
CpuFeature::AVX | CpuFeature::SSE42 | CpuFeature::LZCNT | CpuFeature::BMI1;
// simple test
assert!(compiler
.get_cpu_features_used(&features)
.is_subset(CpuFeature::AVX | CpuFeature::SSE42 | CpuFeature::LZCNT | CpuFeature::BMI1));
// check that an AVX build don't work on SSE4.2 only host
assert!(!compiler
.get_cpu_features_used(&features)
.is_subset(CpuFeature::SSE42 | CpuFeature::LZCNT | CpuFeature::BMI1));
// check that having a host with AVX512 doesn't change anything
features.insert_all(CpuFeature::AVX512DQ | CpuFeature::AVX512F);
assert!(compiler
.get_cpu_features_used(&features)
.is_subset(CpuFeature::AVX | CpuFeature::SSE42 | CpuFeature::LZCNT | CpuFeature::BMI1));
}
}
3 changes: 2 additions & 1 deletion lib/compiler/src/artifact_builders/artifact_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ impl ArtifactBuild {
custom_section_relocations.push(libcall_trampolines_section.relocations.clone());
let libcall_trampolines = custom_sections.push(libcall_trampolines_section);
let libcall_trampoline_len = libcall_trampoline_len(target) as u32;
let cpu_features = compiler.get_cpu_features_used(target.cpu_features());

let serializable_compilation = SerializableCompilation {
function_bodies,
Expand All @@ -119,7 +120,7 @@ impl ArtifactBuild {
compilation: serializable_compilation,
compile_info,
data_initializers,
cpu_features: target.cpu_features().as_u64(),
cpu_features: cpu_features.as_u64(),
};
Ok(Self { serializable })
}
Expand Down
8 changes: 7 additions & 1 deletion lib/compiler/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ use crate::lib::std::sync::Arc;
use crate::translator::ModuleMiddleware;
use crate::FunctionBodyData;
use crate::ModuleTranslationState;
use enumset::EnumSet;
use wasmer_types::compilation::function::Compilation;
use wasmer_types::compilation::module::CompileModuleInfo;
use wasmer_types::compilation::symbols::SymbolRegistry;
use wasmer_types::compilation::target::Target;
use wasmer_types::entity::PrimaryMap;
use wasmer_types::error::CompileError;
use wasmer_types::{Features, LocalFunctionIndex};
use wasmer_types::{CpuFeature, Features, LocalFunctionIndex};
use wasmparser::{Validator, WasmFeatures};

/// The compiler configuration options.
Expand Down Expand Up @@ -143,4 +144,9 @@ pub trait Compiler: Send {

/// Get the middlewares for this compiler
fn get_middlewares(&self) -> &[Arc<dyn ModuleMiddleware>];

/// Get the CpuFeatues used by the compiler
fn get_cpu_features_used(&self, cpu_features: &EnumSet<CpuFeature>) -> EnumSet<CpuFeature> {
*cpu_features
}
}

0 comments on commit df8307e

Please sign in to comment.