Skip to content

Commit 5033f99

Browse files
authored
cranelift-native flags detection: fix flags on SSE2-only systems. (#4231)
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.
1 parent 2b52f47 commit 5033f99

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

cranelift/native/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ pub fn builder_with_options(infer_native_flags: bool) -> Result<isa::Builder, &'
5858
return Ok(isa_builder);
5959
}
6060

61+
// These are temporarily enabled by default (see #3810 for
62+
// more) so that a default-constructed `Flags` can work with
63+
// default Wasmtime features. Otherwise, the user must
64+
// explicitly use native flags or turn these on when on x86-64
65+
// platforms to avoid a configuration panic. In order for the
66+
// "enable if detected" logic below to work, we must turn them
67+
// *off* (differing from the default) and then re-enable below
68+
// if present.
69+
isa_builder.set("has_sse3", "false").unwrap();
70+
isa_builder.set("has_ssse3", "false").unwrap();
71+
isa_builder.set("has_sse41", "false").unwrap();
72+
isa_builder.set("has_sse42", "false").unwrap();
73+
6174
if std::is_x86_feature_detected!("sse3") {
6275
isa_builder.enable("has_sse3").unwrap();
6376
}

0 commit comments

Comments
 (0)