Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x86/x86_64 intrinsics seem to be marked stable, but require feature flags #98253

Closed
afetisov opened this issue Jun 19, 2022 · 5 comments
Closed
Labels
A-target-feature Area: Enabling/disabling target features like AVX, Neon, etc. C-bug Category: This is a bug. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@afetisov
Copy link

I tried this code:

use std::arch::x86_64::*;

fn main() {
    unsafe { ud2(); }
}

I expected this code to successfully compile on stable, since all of std::arch, core::arch, core_arch::arch and core_arch::arch::x86/x86_64 are explicitly marked stable since 1.27:

#[doc = include_str!("core_arch_docs.md")]
#[stable(feature = "simd_arch", since = "1.27.0")]
pub mod arch {
    /// Platform-specific intrinsics for the `x86` platform.
    ///
    /// See the [module documentation](../index.html) for more details.
    #[cfg(any(target_arch = "x86", doc))]
    #[doc(cfg(target_arch = "x86"))]
    #[stable(feature = "simd_x86", since = "1.27.0")]
    pub mod x86 {
        #[stable(feature = "simd_x86", since = "1.27.0")]
        pub use crate::core_arch::x86::*;
    }

    /// Platform-specific intrinsics for the `x86_64` platform.
    ///
    /// See the [module documentation](../index.html) for more details.
    #[cfg(any(target_arch = "x86_64", doc))]
    #[doc(cfg(target_arch = "x86_64"))]
    #[stable(feature = "simd_x86", since = "1.27.0")]
    pub mod x86_64 {
        #[stable(feature = "simd_x86", since = "1.27.0")]
        pub use crate::core_arch::x86::*;
        #[stable(feature = "simd_x86", since = "1.27.0")]
        pub use crate::core_arch::x86_64::*;
    }

    /* snip */
}

Instead, I got the error

error[E0658]: use of unstable library feature 'stdsimd'
 --> src\main.rs:4:14
  |
4 |     unsafe { ud2(); }
  |              ^^^
  |
  = note: see issue #48556 <https://github.com/rust-lang/rust/issues/48556> for more information
  = help: add `#![feature(stdsimd)]` to the crate attributes to enable

However, this issue is closed, since x86/x86_64/aarch64 intrinsics were shipped long ago:

We discussed this in today's @rust-lang/lang meeting.

This seems to be the tracking issue for target-specific SIMD (not portable SIMD, which is being tracked and developed elsewhere). And we've shipped target-specific SIMD on x86-64 and aarch64. There will always be more CPUs to support, but that doesn't mean this issue needs to remain open indefinitely.

We've shipped this; closing.

The stdsimd feature flag was also removed from all x86/x86_64 intrinsics a long time ago. However, I can see that the core_arch crate is included as an unstable submodule guarded by #[feature(stdsimd)] inside of libcore:

// Pull in the `core_arch` crate directly into libcore. The contents of
// `core_arch` are in a different repository: rust-lang/stdarch.
//
// `core_arch` depends on libcore, but the contents of this module are
// set up in such a way that directly pulling it here works such that the
// crate uses the this crate as its libcore.
#[path = "../../stdarch/crates/core_arch/src/mod.rs"]
#[allow(
    missing_docs,
    missing_debug_implementations,
    dead_code,
    unused_imports,
    unsafe_op_in_unsafe_fn
)]
#[allow(rustdoc::bare_urls)]
// FIXME: This annotation should be moved into rust-lang/stdarch after clashing_extern_declarations is
// merged. It currently cannot because bootstrap fails as the lint hasn't been defined yet.
#[allow(clashing_extern_declarations)]
#[unstable(feature = "stdsimd", issue = "48556")]
mod core_arch;

Rust version

This issue reproduces on the current stable and nightly toolchains.

rustc 1.61.0 (fe5b13d68 2022-05-18)
binary: rustc
commit-hash: fe5b13d681f25ee6474be29d748c65adcd91f69e
commit-date: 2022-05-18
host: x86_64-pc-windows-msvc
release: 1.61.0
LLVM version: 14.0.0
rustc 1.63.0-nightly (4e725bad7 2022-06-04)
binary: rustc
commit-hash: 4e725bad73747a4c93a3ac53106e4b4006edc665
commit-date: 2022-06-04
host: x86_64-pc-windows-msvc
release: 1.63.0-nightly
LLVM version: 14.0.5
@afetisov afetisov added the C-bug Category: This is a bug. label Jun 19, 2022
@C0D3-M4513R
Copy link

For core::arch::x86_64::{__cpuid, has_cpuid}; it is especially bad.
__cpuid is explicitly stable, and thus works.
has_cpuid doesn't work, since it is not explicitly stable.

That is worrysome for this code (checking for Long Mode).
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=11f2501972a1bc4f58cb93f86c4bf93e

@zertyz
Copy link

zertyz commented Aug 19, 2022

Still a thing in Rust 1.63
plus both core::arch::x86_64::cmpxchg16b & std::arch::x86_64::cmpxchg16b don't work either

@tomaka
Copy link
Contributor

tomaka commented May 1, 2023

This happens as well for some std::arch::wasm functions, especially memory_atomic_notify

@ChrisDenton ChrisDenton added the needs-triage-legacy Old issue that were never triaged. Remove this label once the issue has been sufficiently triaged. label Jul 16, 2023
@C0D3-M4513R
Copy link

C0D3-M4513R commented Feb 19, 2024

I think this is solved by: ea37e80 / #117372

So this issue can be closed, right?

@afetisov
Copy link
Author

Seems so. The ud2 intrinsic was removed, so the original example is no longer valid, but I couldn't create any new counterexample, after a few attempts. Since nothing in x86_64 or x86 is marked as unstable now, and other arches don't seem to have the original inconsistent stable-unstable marking, I guess the issue should really be fixed. Closing.

@jieyouxu jieyouxu added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. A-target-feature Area: Enabling/disabling target features like AVX, Neon, etc. and removed needs-triage-legacy Old issue that were never triaged. Remove this label once the issue has been sufficiently triaged. labels Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-target-feature Area: Enabling/disabling target features like AVX, Neon, etc. C-bug Category: This is a bug. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants