From d51e703534c49b5b658a954fe6d387c33ba0c5e3 Mon Sep 17 00:00:00 2001 From: CKingX Date: Thu, 8 Feb 2024 17:15:11 -0800 Subject: [PATCH 1/7] As Windows 10 requires certain features like CMPXCHG16B and a few others and Rust plans to set Windows 10 as the minimum supported OS for target x86_64-pc-windows-msvc, I have added the cmpxchg16b and sse3 feature (as CPUs that meet the Windows 10 64-bit requirement also support SSE3. See https://walbourn.github.io/directxmath-sse3-and-ssse3/ ) --- compiler/rustc_target/src/spec/targets/x86_64_pc_windows_msvc.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_msvc.rs b/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_msvc.rs index 357261073a8f7..e3db187e7eb5b 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_msvc.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_msvc.rs @@ -3,6 +3,7 @@ use crate::spec::{base, SanitizerSet, Target}; pub fn target() -> Target { let mut base = base::windows_msvc::opts(); base.cpu = "x86-64".into(); + base.features = "+cmpxchg16b,+sse3".into(); base.plt_by_default = false; base.max_atomic_width = Some(64); base.supported_sanitizers = SanitizerSet::ADDRESS; From d6766e2bc8eb6cfd695f2c9e931c7a712da474ff Mon Sep 17 00:00:00 2001 From: CKingX Date: Fri, 9 Feb 2024 07:59:38 -0800 Subject: [PATCH 2/7] Update x86_64_pc_windows_msvc.rs Fixed a bug where adding CMPXCHG16B would fail due to different names in Rustc and LLVM --- .../rustc_target/src/spec/targets/x86_64_pc_windows_msvc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_msvc.rs b/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_msvc.rs index e3db187e7eb5b..f7dc60df0f475 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_msvc.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_msvc.rs @@ -3,7 +3,7 @@ use crate::spec::{base, SanitizerSet, Target}; pub fn target() -> Target { let mut base = base::windows_msvc::opts(); base.cpu = "x86-64".into(); - base.features = "+cmpxchg16b,+sse3".into(); + base.features = "+cx16,+sse3".into(); base.plt_by_default = false; base.max_atomic_width = Some(64); base.supported_sanitizers = SanitizerSet::ADDRESS; From fcb06f7ca2a20d030fdd5f9c53b684557f17c00c Mon Sep 17 00:00:00 2001 From: CKingX Date: Fri, 9 Feb 2024 09:19:59 -0800 Subject: [PATCH 3/7] Update x86_64_pc_windows_msvc.rs As CMPXCHG16B is supported, I updated the max atomic width to 128-bits from 64-bits --- .../rustc_target/src/spec/targets/x86_64_pc_windows_msvc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_msvc.rs b/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_msvc.rs index f7dc60df0f475..e72e97db7756a 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_msvc.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_msvc.rs @@ -5,7 +5,7 @@ pub fn target() -> Target { base.cpu = "x86-64".into(); base.features = "+cx16,+sse3".into(); base.plt_by_default = false; - base.max_atomic_width = Some(64); + base.max_atomic_width = Some(128); base.supported_sanitizers = SanitizerSet::ADDRESS; Target { From abeac8fbc1cac4bad60094c64179366a802ec949 Mon Sep 17 00:00:00 2001 From: CKingX Date: Fri, 9 Feb 2024 12:25:17 -0800 Subject: [PATCH 4/7] Update x86_64_uwp_windows_gnu.rs Updated x86_64-uwp-windows-gnu to use CMPXCHG16B and SSE3 --- .../rustc_target/src/spec/targets/x86_64_uwp_windows_gnu.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_target/src/spec/targets/x86_64_uwp_windows_gnu.rs b/compiler/rustc_target/src/spec/targets/x86_64_uwp_windows_gnu.rs index c2981ddbad69b..ee95c67496d66 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_uwp_windows_gnu.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_uwp_windows_gnu.rs @@ -3,6 +3,7 @@ use crate::spec::{base, Cc, LinkerFlavor, Lld, Target}; pub fn target() -> Target { let mut base = base::windows_uwp_gnu::opts(); base.cpu = "x86-64".into(); + base.features = "+cx16,+sse3".into(); base.plt_by_default = false; // Use high-entropy 64 bit address space for ASLR base.add_pre_link_args( @@ -10,7 +11,7 @@ pub fn target() -> Target { &["-m", "i386pep", "--high-entropy-va"], ); base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64", "-Wl,--high-entropy-va"]); - base.max_atomic_width = Some(64); + base.max_atomic_width = Some(128); Target { llvm_target: "x86_64-pc-windows-gnu".into(), From 1c6dda72774d19e79d14b7a51c047414b3126b7b Mon Sep 17 00:00:00 2001 From: Chiragroop Date: Fri, 9 Feb 2024 12:54:38 -0800 Subject: [PATCH 5/7] Possibly removed merge policy --- .../rustc_target/src/spec/targets/x86_64_pc_windows_gnu.rs | 3 ++- .../rustc_target/src/spec/targets/x86_64_pc_windows_gnullvm.rs | 3 ++- .../rustc_target/src/spec/targets/x86_64_uwp_windows_msvc.rs | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_gnu.rs b/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_gnu.rs index 9e964d248bf8f..d16e5905eac62 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_gnu.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_gnu.rs @@ -3,6 +3,7 @@ use crate::spec::{base, Cc, LinkerFlavor, Lld, Target}; pub fn target() -> Target { let mut base = base::windows_gnu::opts(); base.cpu = "x86-64".into(); + base.features = "+cx16,+sse3".into(); base.plt_by_default = false; // Use high-entropy 64 bit address space for ASLR base.add_pre_link_args( @@ -10,7 +11,7 @@ pub fn target() -> Target { &["-m", "i386pep", "--high-entropy-va"], ); base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64", "-Wl,--high-entropy-va"]); - base.max_atomic_width = Some(64); + base.max_atomic_width = Some(128); base.linker = Some("x86_64-w64-mingw32-gcc".into()); Target { diff --git a/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_gnullvm.rs b/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_gnullvm.rs index 1facf9450cd2a..ea7f7df8120f9 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_gnullvm.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_gnullvm.rs @@ -3,9 +3,10 @@ use crate::spec::{base, Cc, LinkerFlavor, Lld, Target}; pub fn target() -> Target { let mut base = base::windows_gnullvm::opts(); base.cpu = "x86-64".into(); + base.features = "+cx16,+sse3".into(); base.plt_by_default = false; base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]); - base.max_atomic_width = Some(64); + base.max_atomic_width = Some(128); base.linker = Some("x86_64-w64-mingw32-clang".into()); Target { diff --git a/compiler/rustc_target/src/spec/targets/x86_64_uwp_windows_msvc.rs b/compiler/rustc_target/src/spec/targets/x86_64_uwp_windows_msvc.rs index 3f0702c7ad60e..acdf969375ec5 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_uwp_windows_msvc.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_uwp_windows_msvc.rs @@ -3,8 +3,9 @@ use crate::spec::{base, Target}; pub fn target() -> Target { let mut base = base::windows_uwp_msvc::opts(); base.cpu = "x86-64".into(); + base.features = "+cx16,+sse3".into(); base.plt_by_default = false; - base.max_atomic_width = Some(64); + base.max_atomic_width = Some(128); Target { llvm_target: "x86_64-pc-windows-msvc".into(), From 376c7b98921b427699b99fc36496cb81ed40c946 Mon Sep 17 00:00:00 2001 From: CKingX Date: Tue, 13 Feb 2024 12:08:30 -0800 Subject: [PATCH 6/7] Added sahf feature to windows targets --- compiler/rustc_target/src/spec/targets/x86_64_pc_windows_gnu.rs | 2 +- .../rustc_target/src/spec/targets/x86_64_pc_windows_gnullvm.rs | 2 +- .../rustc_target/src/spec/targets/x86_64_pc_windows_msvc.rs | 2 +- .../rustc_target/src/spec/targets/x86_64_uwp_windows_gnu.rs | 2 +- .../rustc_target/src/spec/targets/x86_64_uwp_windows_msvc.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_gnu.rs b/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_gnu.rs index d16e5905eac62..d6b44e7cfd4cb 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_gnu.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_gnu.rs @@ -3,7 +3,7 @@ use crate::spec::{base, Cc, LinkerFlavor, Lld, Target}; pub fn target() -> Target { let mut base = base::windows_gnu::opts(); base.cpu = "x86-64".into(); - base.features = "+cx16,+sse3".into(); + base.features = "+cx16,+sse3,+sahf".into(); base.plt_by_default = false; // Use high-entropy 64 bit address space for ASLR base.add_pre_link_args( diff --git a/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_gnullvm.rs b/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_gnullvm.rs index ea7f7df8120f9..b84a9a5a8a120 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_gnullvm.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_gnullvm.rs @@ -3,7 +3,7 @@ use crate::spec::{base, Cc, LinkerFlavor, Lld, Target}; pub fn target() -> Target { let mut base = base::windows_gnullvm::opts(); base.cpu = "x86-64".into(); - base.features = "+cx16,+sse3".into(); + base.features = "+cx16,+sse3,+sahf".into(); base.plt_by_default = false; base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]); base.max_atomic_width = Some(128); diff --git a/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_msvc.rs b/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_msvc.rs index e72e97db7756a..51807bdba5d7a 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_msvc.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_pc_windows_msvc.rs @@ -3,7 +3,7 @@ use crate::spec::{base, SanitizerSet, Target}; pub fn target() -> Target { let mut base = base::windows_msvc::opts(); base.cpu = "x86-64".into(); - base.features = "+cx16,+sse3".into(); + base.features = "+cx16,+sse3,+sahf".into(); base.plt_by_default = false; base.max_atomic_width = Some(128); base.supported_sanitizers = SanitizerSet::ADDRESS; diff --git a/compiler/rustc_target/src/spec/targets/x86_64_uwp_windows_gnu.rs b/compiler/rustc_target/src/spec/targets/x86_64_uwp_windows_gnu.rs index ee95c67496d66..b37d33601e66b 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_uwp_windows_gnu.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_uwp_windows_gnu.rs @@ -3,7 +3,7 @@ use crate::spec::{base, Cc, LinkerFlavor, Lld, Target}; pub fn target() -> Target { let mut base = base::windows_uwp_gnu::opts(); base.cpu = "x86-64".into(); - base.features = "+cx16,+sse3".into(); + base.features = "+cx16,+sse3,+sahf".into(); base.plt_by_default = false; // Use high-entropy 64 bit address space for ASLR base.add_pre_link_args( diff --git a/compiler/rustc_target/src/spec/targets/x86_64_uwp_windows_msvc.rs b/compiler/rustc_target/src/spec/targets/x86_64_uwp_windows_msvc.rs index acdf969375ec5..fe2b4c8e92dcd 100644 --- a/compiler/rustc_target/src/spec/targets/x86_64_uwp_windows_msvc.rs +++ b/compiler/rustc_target/src/spec/targets/x86_64_uwp_windows_msvc.rs @@ -3,7 +3,7 @@ use crate::spec::{base, Target}; pub fn target() -> Target { let mut base = base::windows_uwp_msvc::opts(); base.cpu = "x86-64".into(); - base.features = "+cx16,+sse3".into(); + base.features = "+cx16,+sse3,+sahf".into(); base.plt_by_default = false; base.max_atomic_width = Some(128); From 2d25c3b3697728ea42eb26f79e6f80907470ca22 Mon Sep 17 00:00:00 2001 From: CKingX Date: Mon, 19 Feb 2024 21:59:13 -0800 Subject: [PATCH 7/7] Updated test to account for added previous features (thanks erikdesjardins!) --- tests/codegen/sse42-implies-crc32.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/codegen/sse42-implies-crc32.rs b/tests/codegen/sse42-implies-crc32.rs index 56079d32a8d81..f84d390b4e40b 100644 --- a/tests/codegen/sse42-implies-crc32.rs +++ b/tests/codegen/sse42-implies-crc32.rs @@ -12,4 +12,4 @@ pub unsafe fn crc32sse(v: u8) -> u32 { _mm_crc32_u8(out, v) } -// CHECK: attributes #0 {{.*"target-features"="\+sse4.2,\+crc32"}} +// CHECK: attributes #0 {{.*"target-features"=".*\+sse4.2,\+crc32"}}