Skip to content

Commit 467a699

Browse files
committed
Unrolled build for #163742 in rollup 163767
Rollup merge of #163742 - jlpetz:movdir64b-target-feature, r=folkertdev Add the `movdir64b` and `movdiri` x86 target features Adds the unstable `movdir64b` and `movdiri` x86 target features, gated behind `#![feature(movdir64b_target_feature)]` and `#![feature(movdiri_target_feature)]`, and runtime detection with `is_x86_feature_detected!("movdir64b")` / `is_x86_feature_detected!("movdiri")` (CPUID.(EAX=7,ECX=0):ECX[28] and ECX[27]). `MOVDIR64B` moves 64 bytes from memory to a 64-byte aligned destination as a single direct store; `MOVDIRI` stores a 32- or 64-bit integer as a direct store. Both are on Intel Tiger Lake / Alder Lake and later, Sapphire Rapids and later Xeons, and AMD Zen 5. They're standalone CPUID features that aren't part of any psABI microarchitecture level, so they need their own feature flags. **This is the compiler half of a two-PR feature, like `clflushopt` in #157098.** The `_movdir64b`, `_directstoreu_u32` and `_directstoreu_u64` intrinsics (rust-lang/stdarch#2239) can't compile until these target features exist, so the stdarch PR is blocked on this one merging and syncing into stdarch's pinned toolchain. - Tracking issue: #163741 - Unblocks intrinsics: rust-lang/stdarch#2239 Today the only way to emit these instructions from Rust is `asm!`, which also hides them from LLVM: a copy loop through `llvm.x86.movdir64b` gets unrolled and the source address becomes a displacement, while the `asm!` version stays one instruction per iteration with both addresses in registers. `movdir64b` and `movdiri` are LLVM's feature names, so they map 1:1 through `to_llvm_features` with no remap entry. I ran the two new feature-gate tests, `check-cfg/target_feature` and `target-feature/invalid-attribute`, the std_detect tests (which report both features as `true` on a Xeon 6975P-C), and tidy locally on x86_64-pc-windows-msvc. r? @folkertdev
2 parents f48b3e6 + 06b69b5 commit 467a699

11 files changed

Lines changed: 61 additions & 1 deletion

File tree

‎compiler/rustc_feature/src/unstable.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,10 @@ declare_features! (
641641
(unstable, mips_target_feature, "1.27.0", Some(150253)),
642642
/// Allows qualified paths in struct expressions, struct patterns and tuple struct patterns.
643643
(unstable, more_qualified_paths, "1.54.0", Some(86935)),
644+
/// The `movdir64b` target feature on x86.
645+
(unstable, movdir64b_target_feature, "CURRENT_RUSTC_VERSION", Some(163741)),
646+
/// The `movdiri` target feature on x86.
647+
(unstable, movdiri_target_feature, "CURRENT_RUSTC_VERSION", Some(163741)),
644648
/// Allows `move(expr)` in closures.
645649
(incomplete, move_expr, "1.97.0", Some(155050)),
646650
/// The `movrs` target feature on x86.

‎compiler/rustc_span/src/symbol.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,8 @@ symbols! {
14021402
more_qualified_paths,
14031403
more_struct_aliases,
14041404
movbe_target_feature,
1405+
movdir64b_target_feature,
1406+
movdiri_target_feature,
14051407
move_expr,
14061408
move_ref_pattern,
14071409
move_size_limit,

‎compiler/rustc_target/src/target_features.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,8 @@ static X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
496496
("lahfsahf", Unstable(sym::lahfsahf_target_feature), &[]),
497497
("lzcnt", Stable, &[]),
498498
("movbe", Stable, &[]),
499+
("movdir64b", Unstable(sym::movdir64b_target_feature), &[]),
500+
("movdiri", Unstable(sym::movdiri_target_feature), &[]),
499501
("movrs", Unstable(sym::movrs_target_feature), &[]),
500502
("pclmulqdq", Stable, &["sse2"]),
501503
("popcnt", Stable, &[]),

‎library/std_detect/src/detect/arch/x86.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ features! {
111111
/// * `"adx"`
112112
/// * `"rtm"`
113113
/// * `"movbe"`
114+
/// * `"movdir64b"`
115+
/// * `"movdiri"`
114116
/// * `"ermsb"`
115117
/// * `"movrs"`
116118
/// * `"xop"`
@@ -271,6 +273,10 @@ features! {
271273
/// RTM, Intel (Restricted Transactional Memory)
272274
@FEATURE: #[stable(feature = "movbe_target_feature", since = "1.67.0")] movbe: "movbe";
273275
/// MOVBE (Move Data After Swapping Bytes)
276+
@FEATURE: #[unstable(feature = "movdir64b_target_feature", issue = "163741")] movdir64b: "movdir64b";
277+
/// MOVDIR64B (Move 64 Bytes as Direct Store)
278+
@FEATURE: #[unstable(feature = "movdiri_target_feature", issue = "163741")] movdiri: "movdiri";
279+
/// MOVDIRI (Move Doubleword as Direct Store)
274280
@FEATURE: #[unstable(feature = "movrs_target_feature", issue = "137976")] movrs: "movrs";
275281
/// MOVRS (Move data with the read-shared hint)
276282
@FEATURE: #[stable(feature = "simd_x86", since = "1.27.0")] ermsb: "ermsb";

‎library/std_detect/src/detect/os/x86.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ pub(crate) fn detect_features() -> cache::Initializer {
121121
enable(extended_features_ecx, 8, Feature::gfni);
122122
enable(extended_features_ecx, 9, Feature::vaes);
123123
enable(extended_features_ecx, 10, Feature::vpclmulqdq);
124+
enable(extended_features_ecx, 27, Feature::movdiri);
125+
enable(extended_features_ecx, 28, Feature::movdir64b);
124126

125127
enable(extended_features_ebx, 3, Feature::bmi1);
126128
enable(extended_features_ebx, 8, Feature::bmi2);

‎library/std_detect/tests/x86-specific.rs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
x86_amx_intrinsics,
66
xop_target_feature,
77
movrs_target_feature,
8-
clflushopt_target_feature
8+
clflushopt_target_feature,
9+
movdir64b_target_feature,
10+
movdiri_target_feature
911
)]
1012

1113
#[macro_use]
@@ -68,6 +70,8 @@ fn dump() {
6870
println!("adx: {:?}", is_x86_feature_detected!("adx"));
6971
println!("rtm: {:?}", is_x86_feature_detected!("rtm"));
7072
println!("movbe: {:?}", is_x86_feature_detected!("movbe"));
73+
println!("movdir64b: {:?}", is_x86_feature_detected!("movdir64b"));
74+
println!("movdiri: {:?}", is_x86_feature_detected!("movdiri"));
7175
println!("avxvnni: {:?}", is_x86_feature_detected!("avxvnni"));
7276
println!("avxvnniint8: {:?}", is_x86_feature_detected!("avxvnniint8"));
7377
println!("avxneconvert: {:?}", is_x86_feature_detected!("avxneconvert"));

‎tests/ui/check-cfg/target_feature.stderr‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ LL | cfg!(target_feature = "_UNEXPECTED_VALUE");
211211
`miscsr`
212212
`mops`
213213
`movbe`
214+
`movdir64b`
215+
`movdiri`
214216
`movrs`
215217
`movw`
216218
`mp`
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//@ only-x86_64
2+
#[target_feature(enable = "movdir64b")]
3+
//~^ ERROR: currently unstable
4+
unsafe fn foo() {}
5+
6+
fn main() {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0658]: the target feature `movdir64b` is currently unstable
2+
--> $DIR/feature-gate-movdir64b_target_feature.rs:2:18
3+
|
4+
LL | #[target_feature(enable = "movdir64b")]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #163741 <https://github.com/rust-lang/rust/issues/163741> for more information
8+
= help: add `#![feature(movdir64b_target_feature)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error: aborting due to 1 previous error
12+
13+
For more information about this error, try `rustc --explain E0658`.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//@ only-x86_64
2+
#[target_feature(enable = "movdiri")]
3+
//~^ ERROR: currently unstable
4+
unsafe fn foo() {}
5+
6+
fn main() {}

0 commit comments

Comments
 (0)