Skip to content
Closed
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
2 changes: 1 addition & 1 deletion library/alloc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ compiler_builtins = { path = "../compiler-builtins/compiler-builtins", features
compiler-builtins-mem = ['compiler_builtins/mem']
compiler-builtins-c = ["compiler_builtins/c"]
# Choose algorithms that are optimized for binary size instead of runtime performance
optimize_for_size = ["core/optimize_for_size"]
optimize_for_size = ["core/optimize_for_size", "compiler_builtins/optimize_for_size"]

[lints.rust.unexpected_cfgs]
level = "warn"
Expand Down
3 changes: 3 additions & 0 deletions library/compiler-builtins/builtins-shim/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,6 @@ unmangled-names = []
# This makes certain traits and function specializations public that
# are not normally public but are required by the `builtins-test`
unstable-public-internals = []

# Choose algorithms that are optimized for binary size instead of runtime performance
optimize_for_size = []
3 changes: 3 additions & 0 deletions library/compiler-builtins/compiler-builtins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ unmangled-names = []
# This makes certain traits and function specializations public that
# are not normally public but are required by the `builtins-test`
unstable-public-internals = []

# Choose algorithms that are optimized for binary size instead of runtime performance
optimize_for_size = ["core/optimize_for_size"]
34 changes: 18 additions & 16 deletions library/compiler-builtins/compiler-builtins/src/mem/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ pub unsafe fn copy_forward(mut dest: *mut u8, mut src: *const u8, mut n: usize)
}
}

if n >= WORD_COPY_THRESHOLD {
if !cfg!(feature = "optimize_for_size") && n >= WORD_COPY_THRESHOLD {
// Align dest
// Because of n >= 2 * WORD_SIZE, dst_misalignment < n
let dest_misalignment = (dest as usize).wrapping_neg() & WORD_MASK;
Expand Down Expand Up @@ -318,7 +318,7 @@ pub unsafe fn copy_backward(dest: *mut u8, src: *const u8, mut n: usize) {
let mut dest = dest.wrapping_add(n);
let mut src = src.wrapping_add(n);

if n >= WORD_COPY_THRESHOLD {
if !cfg!(feature = "optimize_for_size") && n >= WORD_COPY_THRESHOLD {
// Align dest
// Because of n >= 2 * WORD_SIZE, dst_misalignment < n
let dest_misalignment = dest as usize & WORD_MASK;
Expand Down Expand Up @@ -371,20 +371,22 @@ pub unsafe fn set_bytes(mut s: *mut u8, c: u8, mut n: usize) {
}
}

if n >= WORD_COPY_THRESHOLD {
// Align s
// Because of n >= 2 * WORD_SIZE, dst_misalignment < n
let misalignment = (s as usize).wrapping_neg() & WORD_MASK;
set_bytes_bytes(s, c, misalignment);
s = s.wrapping_add(misalignment);
n -= misalignment;

let n_words = n & !WORD_MASK;
set_bytes_words(s, c, n_words);
s = s.wrapping_add(n_words);
n -= n_words;
} else {
cold_path();
if !cfg!(feature = "optimize_for_size") {
if n >= WORD_COPY_THRESHOLD {
// Align s
// Because of n >= 2 * WORD_SIZE, dst_misalignment < n
let misalignment = (s as usize).wrapping_neg() & WORD_MASK;
set_bytes_bytes(s, c, misalignment);
s = s.wrapping_add(misalignment);
n -= misalignment;

let n_words = n & !WORD_MASK;
set_bytes_words(s, c, n_words);
s = s.wrapping_add(n_words);
n -= n_words;
} else {
cold_path();
}
}
set_bytes_bytes(s, c, n);
}
Expand Down
Loading