Loader: SSE4a replacement off by default (VICTORY_PATCH_SSE4A=1 turns it on)

A second thread reaching an insertq/extrq while the first replaces it can still end the run with 0xc000001d on Intel (#2393, #3775). #2585 makes that much rarer, not impossible; emulating each time never crashes this way.
This commit is contained in:
trustno1-coder
2026-11-30 15:24:32 -08:00
parent 8592c14286
commit bc8eb69794

View File

@ -117,11 +117,15 @@ fn clzero_stub(at: usize, stub: usize, cmp: [u8; 3]) -> Option<Vec<u8>> {
/// Whether SSE4a `extrq` / `insertq` with immediate length and index are replaced the first
/// time they fault by a jump to the same operation in SSE2 ([`sse4a_stub`]). Run 19:19 of
/// 2026-11-28: one `insertq xmm0, xmm1, 16, 16` faulted about 3,700 times a second. On by
/// default; `VICTORY_PATCH_SSE4A=0` emulates each time, as before.
/// 2026-11-28: one `insertq xmm0, xmm1, 16, 16` faulted about 3,700 times a second.
///
/// Off by default (`VICTORY_PATCH_SSE4A=1` turns it on): on Intel, a second thread that
/// reaches the instruction while the first is replacing it can still end the run with
/// `0xc000001d` (#2393, #3775). The late-fault fix (#2585) makes that much rarer but not
/// impossible; emulating each time never crashes this way.
fn patches_sse4a() -> bool {
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
*ON.get_or_init(|| std::env::var_os("VICTORY_PATCH_SSE4A").is_none_or(|v| v != "0"))
*ON.get_or_init(|| std::env::var_os("VICTORY_PATCH_SSE4A").is_some_and(|v| v == "1"))
}
/// `op xmm(reg), xmm(rm)` with `prefix`.