From c4cee089d574c5227f030dae72a843a91738541d Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 10 Feb 2025 10:41:19 -0800 Subject: [PATCH] Update stdarch --- .../rustc_span/src/analyze_source_file.rs | 8 +++---- library/core/Cargo.toml | 2 ++ library/core/src/lib.rs | 2 ++ library/stdarch | 2 +- .../rust-analyzer/lib/line-index/src/lib.rs | 24 ++++++++++++------- 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_span/src/analyze_source_file.rs b/compiler/rustc_span/src/analyze_source_file.rs index 141d261b5f015..6384fa06c21b0 100644 --- a/compiler/rustc_span/src/analyze_source_file.rs +++ b/compiler/rustc_span/src/analyze_source_file.rs @@ -83,17 +83,17 @@ cfg_match! { // For character in the chunk, see if its byte value is < 0, which // indicates that it's part of a UTF-8 char. - let multibyte_test = unsafe { _mm_cmplt_epi8(chunk, _mm_set1_epi8(0)) }; + let multibyte_test = _mm_cmplt_epi8(chunk, _mm_set1_epi8(0)); // Create a bit mask from the comparison results. - let multibyte_mask = unsafe { _mm_movemask_epi8(multibyte_test) }; + let multibyte_mask = _mm_movemask_epi8(multibyte_test); // If the bit mask is all zero, we only have ASCII chars here: if multibyte_mask == 0 { assert!(intra_chunk_offset == 0); // Check for newlines in the chunk - let newlines_test = unsafe { _mm_cmpeq_epi8(chunk, _mm_set1_epi8(b'\n' as i8)) }; - let mut newlines_mask = unsafe { _mm_movemask_epi8(newlines_test) }; + let newlines_test = _mm_cmpeq_epi8(chunk, _mm_set1_epi8(b'\n' as i8)); + let mut newlines_mask = _mm_movemask_epi8(newlines_test); let output_offset = RelativeBytePos::from_usize(chunk_index * CHUNK_SIZE + 1); diff --git a/library/core/Cargo.toml b/library/core/Cargo.toml index 1538ecc6b9297..edde8153aa1d2 100644 --- a/library/core/Cargo.toml +++ b/library/core/Cargo.toml @@ -32,6 +32,8 @@ check-cfg = [ 'cfg(bootstrap)', 'cfg(no_fp_fmt_parse)', 'cfg(stdarch_intel_sde)', + # #[cfg(bootstrap)] + 'cfg(target_feature, values("vector-enhancements-1"))', # core use #[path] imports to portable-simd `core_simd` crate # and to stdarch `core_arch` crate which messes-up with Cargo list # of declared features, we therefor expect any feature cfg diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index db68f472c42f6..db3697c7e6b5a 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -205,11 +205,13 @@ #![feature(arm_target_feature)] #![feature(avx512_target_feature)] #![feature(hexagon_target_feature)] +#![feature(keylocker_x86)] #![feature(loongarch_target_feature)] #![feature(mips_target_feature)] #![feature(powerpc_target_feature)] #![feature(riscv_target_feature)] #![feature(rtm_target_feature)] +#![feature(s390x_target_feature)] #![feature(sha512_sm_x86)] #![feature(sse4a_target_feature)] #![feature(tbm_target_feature)] diff --git a/library/stdarch b/library/stdarch index 684de0d6fef70..3f38a72876d9d 160000 --- a/library/stdarch +++ b/library/stdarch @@ -1 +1 @@ -Subproject commit 684de0d6fef708cae08214fef9643dd9ec7296e1 +Subproject commit 3f38a72876d9d6c87cf4903d01b78b9e43e1a831 diff --git a/src/tools/rust-analyzer/lib/line-index/src/lib.rs b/src/tools/rust-analyzer/lib/line-index/src/lib.rs index bc87ada3eb55c..905da330e64b0 100644 --- a/src/tools/rust-analyzer/lib/line-index/src/lib.rs +++ b/src/tools/rust-analyzer/lib/line-index/src/lib.rs @@ -257,6 +257,8 @@ fn analyze_source_file_dispatch( /// SSE2 intrinsics to quickly find all newlines. #[target_feature(enable = "sse2")] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +// This can be removed once 1.87 is stable due to some intrinsics switching to safe. +#[allow(unsafe_op_in_unsafe_fn)] unsafe fn analyze_source_file_sse2( src: &str, lines: &mut Vec, @@ -287,17 +289,17 @@ unsafe fn analyze_source_file_sse2( // For character in the chunk, see if its byte value is < 0, which // indicates that it's part of a UTF-8 char. - let multibyte_test = unsafe { _mm_cmplt_epi8(chunk, _mm_set1_epi8(0)) }; + let multibyte_test = _mm_cmplt_epi8(chunk, _mm_set1_epi8(0)); // Create a bit mask from the comparison results. - let multibyte_mask = unsafe { _mm_movemask_epi8(multibyte_test) }; + let multibyte_mask = _mm_movemask_epi8(multibyte_test); // If the bit mask is all zero, we only have ASCII chars here: if multibyte_mask == 0 { assert!(intra_chunk_offset == 0); // Check for newlines in the chunk - let newlines_test = unsafe { _mm_cmpeq_epi8(chunk, _mm_set1_epi8(b'\n' as i8)) }; - let newlines_mask = unsafe { _mm_movemask_epi8(newlines_test) }; + let newlines_test = _mm_cmpeq_epi8(chunk, _mm_set1_epi8(b'\n' as i8)); + let newlines_mask = _mm_movemask_epi8(newlines_test); if newlines_mask != 0 { // All control characters are newlines, record them @@ -354,15 +356,19 @@ unsafe fn analyze_source_file_sse2( // The mask is a 64-bit integer, where each 4-bit corresponds to a u8 in the // input vector. The least significant 4 bits correspond to the first byte in // the vector. +// This can be removed once 1.87 is stable due to some intrinsics switching to safe. +#[allow(unsafe_op_in_unsafe_fn)] unsafe fn move_mask(v: std::arch::aarch64::uint8x16_t) -> u64 { use std::arch::aarch64::*; - let nibble_mask = unsafe { vshrn_n_u16(vreinterpretq_u16_u8(v), 4) }; - unsafe { vget_lane_u64(vreinterpret_u64_u8(nibble_mask), 0) } + let nibble_mask = vshrn_n_u16(vreinterpretq_u16_u8(v), 4); + vget_lane_u64(vreinterpret_u64_u8(nibble_mask), 0) } #[target_feature(enable = "neon")] #[cfg(all(target_arch = "aarch64", target_endian = "little"))] +// This can be removed once 1.87 is stable due to some intrinsics switching to safe. +#[allow(unsafe_op_in_unsafe_fn)] unsafe fn analyze_source_file_neon( src: &str, lines: &mut Vec, @@ -376,7 +382,7 @@ unsafe fn analyze_source_file_neon( let chunk_count = src.len() / CHUNK_SIZE; - let newline = unsafe { vdupq_n_s8(b'\n' as i8) }; + let newline = vdupq_n_s8(b'\n' as i8); // This variable keeps track of where we should start decoding a // chunk. If a multi-byte character spans across chunk boundaries, @@ -390,7 +396,7 @@ unsafe fn analyze_source_file_neon( // For character in the chunk, see if its byte value is < 0, which // indicates that it's part of a UTF-8 char. - let multibyte_test = unsafe { vcltzq_s8(chunk) }; + let multibyte_test = vcltzq_s8(chunk); // Create a bit mask from the comparison results. let multibyte_mask = unsafe { move_mask(multibyte_test) }; @@ -399,7 +405,7 @@ unsafe fn analyze_source_file_neon( assert!(intra_chunk_offset == 0); // Check for newlines in the chunk - let newlines_test = unsafe { vceqq_s8(chunk, newline) }; + let newlines_test = vceqq_s8(chunk, newline); let mut newlines_mask = unsafe { move_mask(newlines_test) }; // If the bit mask is not all zero, there are newlines in this chunk.