Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0bc6945
give a better example why `std` modules named like primitives are needed
cyrgani Oct 5, 2025
03cdcb5
bootstrap: add `Builder::rustc_cmd` that includes the lib path
cuviper Oct 6, 2025
1e6b444
library: fs: Factor out a `file_time_to_timespec` function in prepara…
joshtriplett Oct 7, 2025
1bf555c
library: fs: Factor out the Apple file time to attrlist code for reuse
joshtriplett Oct 7, 2025
45ca537
Port the Miri implementations of SIMD intrinsics to `rustc_const_eval`
sayantn Oct 8, 2025
1654cce
prefer to use repeat_n over repeat and take
chenyukang Oct 8, 2025
affaf53
referring to repeat_n in std::iter::repeat
chenyukang Oct 8, 2025
53c79f4
bless format
chenyukang Oct 8, 2025
99ab27f
specialize slice::fill to use memset when possible
the8472 Oct 3, 2025
7225454
Implement fs api set_times and set_times_nofollow
chenyukang Oct 8, 2025
3d40fa6
Update library/std/src/fs.rs
chenyukang Oct 9, 2025
6308e76
Update library/std/src/fs.rs
chenyukang Oct 9, 2025
8f08156
compiletest: Isolate APIs used by rustdoc-gui-test
Zalathar Oct 9, 2025
b4f64fd
compiletest: Isolate APIs used by `bin/main.rs`
Zalathar Oct 9, 2025
ce4699d
compiletest: Make all other modules non-public
Zalathar Oct 9, 2025
1c5c8ca
use proper unsupported
chenyukang Oct 9, 2025
46c6f0a
rebase #147504
chenyukang Oct 9, 2025
2438df7
support fs::set_times for wasi
chenyukang Oct 9, 2025
1dd5641
add doc alias for set_times_nofollow
chenyukang Oct 9, 2025
6fd1c2b
add doc alias for set_times
chenyukang Oct 9, 2025
953dcff
Rollup merge of #146568 - sayantn:simd-shuffle, r=RalfJung
Zalathar Oct 9, 2025
c2b9031
Rollup merge of #147373 - cyrgani:cyrgani-patch-1, r=ibraheemdev
Zalathar Oct 9, 2025
84475a2
Rollup merge of #147419 - cuviper:bootstrap-rustc-libs, r=Zalathar,ji…
Zalathar Oct 9, 2025
affd573
Rollup merge of #147457 - the8472:slice_fill_memset2, r=RalfJung,joboet
Zalathar Oct 9, 2025
fd19065
Rollup merge of #147468 - chenyukang:yukang-api-set-times, r=joshtrip…
Zalathar Oct 9, 2025
1201c90
Rollup merge of #147489 - chenyukang:yukang-prefer-repeat-n, r=Kivooe…
Zalathar Oct 9, 2025
c34587e
Rollup merge of #147506 - Zalathar:isolate, r=jieyouxu
Zalathar Oct 9, 2025
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
Prev Previous commit
Next Next commit
specialize slice::fill to use memset when possible
LLVM generally can do this on its own, but it helps miri and other backends.
  • Loading branch information
the8472 committed Oct 8, 2025
commit 99ab27f90cf9e3b020e61fca65f9a8c1ec9a1695
47 changes: 46 additions & 1 deletion library/core/src/slice/specialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,54 @@ impl<T: Clone> SpecFill<T> for [T] {
}

impl<T: Copy> SpecFill<T> for [T] {
fn spec_fill(&mut self, value: T) {
default fn spec_fill(&mut self, value: T) {
for item in self.iter_mut() {
*item = value;
}
}
}

impl SpecFill<u8> for [u8] {
fn spec_fill(&mut self, value: u8) {
// SAFETY: The pointer is derived from a reference, so it's writable.
unsafe {
crate::intrinsics::write_bytes(self.as_mut_ptr(), value, self.len());
}
}
}

impl SpecFill<i8> for [i8] {
fn spec_fill(&mut self, value: i8) {
// SAFETY: The pointer is derived from a reference, so it's writable.
unsafe {
crate::intrinsics::write_bytes(self.as_mut_ptr(), value.cast_unsigned(), self.len());
}
}
}

macro spec_fill_int {
($($type:ty)*) => {$(
impl SpecFill<$type> for [$type] {
#[inline]
fn spec_fill(&mut self, value: $type) {
// We always take this fastpath in Miri for long slices as the manual `for`
// loop can be prohibitively slow.
if (cfg!(miri) && self.len() > 32) || crate::intrinsics::is_val_statically_known(value) {
let bytes = value.to_ne_bytes();
if value == <$type>::from_ne_bytes([bytes[0]; size_of::<$type>()]) {
// SAFETY: The pointer is derived from a reference, so it's writable.
unsafe {
crate::intrinsics::write_bytes(self.as_mut_ptr(), bytes[0], self.len());
}
return;
}
}
for item in self.iter_mut() {
*item = value;
}
}
}
)*}
}

spec_fill_int! { u16 i16 u32 i32 u64 i64 u128 i128 usize isize }
28 changes: 28 additions & 0 deletions tests/codegen-llvm/lib-optimizations/slice_fill.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//@ compile-flags: -Copt-level=3
#![crate_type = "lib"]

use std::mem::MaybeUninit;

// CHECK-LABEL: @slice_fill_pass_undef
#[no_mangle]
pub fn slice_fill_pass_undef(s: &mut [MaybeUninit<u8>], v: MaybeUninit<u8>) {
// CHECK: tail call void @llvm.memset.{{.*}}(ptr nonnull align 1 %s.0, i8 %v, {{.*}} %s.1, i1 false)
// CHECK: ret
s.fill(v);
}

// CHECK-LABEL: @slice_fill_uninit
#[no_mangle]
pub fn slice_fill_uninit(s: &mut [MaybeUninit<u8>]) {
// CHECK-NOT: call
// CHECK: ret void
s.fill(MaybeUninit::uninit());
}

// CHECK-LABEL: @slice_wide_memset
#[no_mangle]
pub fn slice_wide_memset(s: &mut [u16]) {
// CHECK: tail call void @llvm.memset.{{.*}}(ptr nonnull align 2 %s.0, i8 -1
// CHECK: ret
s.fill(0xFFFF);
}
Loading