Skip to content

Commit

Permalink
cranelift-native flags detection: fix flags on SSE2-only systems.
Browse files Browse the repository at this point in the history
In #4224 we saw that an SSE2-only x86-64 system somehow was still
detecting SSE3/SSSE3/SSE4.1/SSE4.2. It turns out that we enabled these
in the baseline `Flags` in #3816, because without that, a ton of other
things break: default flags no longer produce a compiler backend that
works with default Wasmtime settings. However the logic to set them when
detected (via `CPUID`-using feature-test macros) only does an "if
detected then set bit" step per feature; the bits are never *cleared*.
This PR fixes that.
  • Loading branch information
cfallin committed Jun 6, 2022
1 parent 3f15227 commit fee8ed4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cranelift/codegen/src/isa/x64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ fn isa_constructor(

// Check for compatibility between flags and ISA level
// requested. In particular, SIMD support requires SSE4.2.
println!(
"simd = {} sse3 = {} sse42 = {}",
shared_flags.enable_simd(),
isa_flags.has_sse3(),
isa_flags.has_sse42()
);
if shared_flags.enable_simd() {
if !isa_flags.has_sse3()
|| !isa_flags.has_ssse3()
Expand Down
13 changes: 13 additions & 0 deletions cranelift/native/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ pub fn builder_with_options(infer_native_flags: bool) -> Result<isa::Builder, &'
return Ok(isa_builder);
}

// These are temporarily enabled by default (see #3810 for
// more) so that a default-constructed `Flags` can work with
// default Wasmtime features. Otherwise, the user must
// explicitly use native flags or turn these on when on x86-64
// platforms to avoid a configuration panic. In order for the
// "enable if detected" logic below to work, we must turn them
// *off* (differing from the default) and then re-enable below
// if present.
isa_builder.set("has_sse3", "false").unwrap();
isa_builder.set("has_ssse3", "false").unwrap();
isa_builder.set("has_sse41", "false").unwrap();
isa_builder.set("has_sse42", "false").unwrap();

if std::is_x86_feature_detected!("sse3") {
isa_builder.enable("has_sse3").unwrap();
}
Expand Down

0 comments on commit fee8ed4

Please sign in to comment.