Skip to content

Commit

Permalink
Merge #2775
Browse files Browse the repository at this point in the history
2775: Support SSE 4.2 for the Singlepass compiler r=ptitSeb a=batconjurer

Closes #2767 

# Description
This PR adds support for the SSE 4.2 instruction set in the singlepass compiler. Previously, only AVX was supported. This implementation may also work for SSE 4.1, but this should be double checked. It does use the `blendvps` instruction indroduced in SSE 4.1, so it cannot support any earlier SSE versions at present for sure. 

The following are the main changes:
 - The assembler has changed from a Vec<X64Relocation> to a struct containing this as well as the corresponding CPU feature (indicating AVX/SSE4.2/...)
 - A set of SSE function macros have been added. To handle non-destructive operations, additional moves may be made before executing the corresponding SSE instruction if `src1 != dst`
 - A minor change to the `EmitterX64` trait. It now has a function for returning a possible CPU feature.
 - The implementation of `EmitterX64` for the assembler has obviously changed. It chooses the emitted assembly based on the CPU feature.


Co-authored-by: R2D2 <jacob.turner870@gmail.com>
Co-authored-by: Jacob Turner <jacob.turner870@gmail.com>
  • Loading branch information
bors[bot] and batconjurer committed Feb 17, 2022
2 parents 1df8720 + 3f2fa63 commit fba8465
Show file tree
Hide file tree
Showing 5 changed files with 836 additions and 321 deletions.
4 changes: 3 additions & 1 deletion lib/compiler-singlepass/Cargo.toml
Expand Up @@ -32,6 +32,8 @@ target-lexicon = { version = "0.12.2", default-features = false }
maintenance = { status = "actively-developed" }

[features]
default = ["std", "rayon"]
default = ["std", "rayon", "avx"]
std = ["wasmer-compiler/std", "wasmer-types/std"]
core = ["hashbrown", "wasmer-types/core"]
sse = []
avx = []
15 changes: 9 additions & 6 deletions lib/compiler-singlepass/src/compiler.rs
Expand Up @@ -69,13 +69,16 @@ impl Compiler for SinglepassCompiler {
))
}
}
if target.triple().architecture == Architecture::X86_64
&& !target.cpu_features().contains(CpuFeature::AVX)
{

let simd_arch = if target.cpu_features().contains(CpuFeature::AVX) {
CpuFeature::AVX
} else if target.cpu_features().contains(CpuFeature::SSE42) {
CpuFeature::SSE42
} else {
return Err(CompileError::UnsupportedTarget(
"x86_64 without AVX".to_string(),
"x86_64 without AVX or SSE 4.2".to_string(),
));
}
};
if compile_info.features.multi_value {
return Err(CompileError::UnsupportedFeature("multivalue".to_string()));
}
Expand Down Expand Up @@ -131,7 +134,7 @@ impl Compiler for SinglepassCompiler {

match target.triple().architecture {
Architecture::X86_64 => {
let machine = MachineX86_64::new();
let machine = MachineX86_64::new(Some(simd_arch));
let mut generator = FuncGen::new(
module,
&self.config,
Expand Down

0 comments on commit fba8465

Please sign in to comment.