Skip to content

mark x86 intrinsics as safe #1714

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

Merged
merged 20 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/core_arch/src/x86/abm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use stdarch_test::assert_instr;
#[target_feature(enable = "lzcnt")]
#[cfg_attr(test, assert_instr(lzcnt))]
#[stable(feature = "simd_x86", since = "1.27.0")]
pub unsafe fn _lzcnt_u32(x: u32) -> u32 {
pub fn _lzcnt_u32(x: u32) -> u32 {
x.leading_zeros()
}

Expand All @@ -40,7 +40,7 @@ pub unsafe fn _lzcnt_u32(x: u32) -> u32 {
#[target_feature(enable = "popcnt")]
#[cfg_attr(test, assert_instr(popcnt))]
#[stable(feature = "simd_x86", since = "1.27.0")]
pub unsafe fn _popcnt32(x: i32) -> i32 {
pub fn _popcnt32(x: i32) -> i32 {
x.count_ones() as i32
}

Expand Down
24 changes: 12 additions & 12 deletions crates/core_arch/src/x86/aes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ unsafe extern "C" {
#[target_feature(enable = "aes")]
#[cfg_attr(test, assert_instr(aesdec))]
#[stable(feature = "simd_x86", since = "1.27.0")]
pub unsafe fn _mm_aesdec_si128(a: __m128i, round_key: __m128i) -> __m128i {
aesdec(a, round_key)
pub fn _mm_aesdec_si128(a: __m128i, round_key: __m128i) -> __m128i {
unsafe { aesdec(a, round_key) }
}

/// Performs the last round of an AES decryption flow on data (state) in `a`.
Expand All @@ -46,8 +46,8 @@ pub unsafe fn _mm_aesdec_si128(a: __m128i, round_key: __m128i) -> __m128i {
#[target_feature(enable = "aes")]
#[cfg_attr(test, assert_instr(aesdeclast))]
#[stable(feature = "simd_x86", since = "1.27.0")]
pub unsafe fn _mm_aesdeclast_si128(a: __m128i, round_key: __m128i) -> __m128i {
aesdeclast(a, round_key)
pub fn _mm_aesdeclast_si128(a: __m128i, round_key: __m128i) -> __m128i {
unsafe { aesdeclast(a, round_key) }
}

/// Performs one round of an AES encryption flow on data (state) in `a`.
Expand All @@ -57,8 +57,8 @@ pub unsafe fn _mm_aesdeclast_si128(a: __m128i, round_key: __m128i) -> __m128i {
#[target_feature(enable = "aes")]
#[cfg_attr(test, assert_instr(aesenc))]
#[stable(feature = "simd_x86", since = "1.27.0")]
pub unsafe fn _mm_aesenc_si128(a: __m128i, round_key: __m128i) -> __m128i {
aesenc(a, round_key)
pub fn _mm_aesenc_si128(a: __m128i, round_key: __m128i) -> __m128i {
unsafe { aesenc(a, round_key) }
}

/// Performs the last round of an AES encryption flow on data (state) in `a`.
Expand All @@ -68,8 +68,8 @@ pub unsafe fn _mm_aesenc_si128(a: __m128i, round_key: __m128i) -> __m128i {
#[target_feature(enable = "aes")]
#[cfg_attr(test, assert_instr(aesenclast))]
#[stable(feature = "simd_x86", since = "1.27.0")]
pub unsafe fn _mm_aesenclast_si128(a: __m128i, round_key: __m128i) -> __m128i {
aesenclast(a, round_key)
pub fn _mm_aesenclast_si128(a: __m128i, round_key: __m128i) -> __m128i {
unsafe { aesenclast(a, round_key) }
}

/// Performs the `InvMixColumns` transformation on `a`.
Expand All @@ -79,8 +79,8 @@ pub unsafe fn _mm_aesenclast_si128(a: __m128i, round_key: __m128i) -> __m128i {
#[target_feature(enable = "aes")]
#[cfg_attr(test, assert_instr(aesimc))]
#[stable(feature = "simd_x86", since = "1.27.0")]
pub unsafe fn _mm_aesimc_si128(a: __m128i) -> __m128i {
aesimc(a)
pub fn _mm_aesimc_si128(a: __m128i) -> __m128i {
unsafe { aesimc(a) }
}

/// Assist in expanding the AES cipher key.
Expand All @@ -95,9 +95,9 @@ pub unsafe fn _mm_aesimc_si128(a: __m128i) -> __m128i {
#[cfg_attr(test, assert_instr(aeskeygenassist, IMM8 = 0))]
#[rustc_legacy_const_generics(1)]
#[stable(feature = "simd_x86", since = "1.27.0")]
pub unsafe fn _mm_aeskeygenassist_si128<const IMM8: i32>(a: __m128i) -> __m128i {
pub fn _mm_aeskeygenassist_si128<const IMM8: i32>(a: __m128i) -> __m128i {
static_assert_uimm_bits!(IMM8, 8);
aeskeygenassist(a, IMM8 as u8)
unsafe { aeskeygenassist(a, IMM8 as u8) }
}

#[cfg(test)]
Expand Down
Loading