mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Add benchmark for not-quite-correct “fake SIMD” make_ascii_uppercase
This commit is contained in:
parent
ce933f77c8
commit
fbe34cc521
@ -87,6 +87,52 @@ benches! {
|
|||||||
fn bench06_libcore(bytes: &mut [u8]) {
|
fn bench06_libcore(bytes: &mut [u8]) {
|
||||||
bytes.make_ascii_uppercase()
|
bytes.make_ascii_uppercase()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn bench07_fake_simd_u32(bytes: &mut [u8]) {
|
||||||
|
let (before, aligned, after) = unsafe {
|
||||||
|
bytes.align_to_mut::<u32>()
|
||||||
|
};
|
||||||
|
for byte in before {
|
||||||
|
*byte = branchless_to_ascii_upper_case(*byte)
|
||||||
|
}
|
||||||
|
for word in aligned {
|
||||||
|
// FIXME: this is incorrect for some byte values:
|
||||||
|
// addition within a byte can carry/overflow into the next byte.
|
||||||
|
// Test case: b"\xFFz "
|
||||||
|
*word &= !(
|
||||||
|
(
|
||||||
|
word.wrapping_add(0x1f1f1f1f) &
|
||||||
|
!word.wrapping_add(0x05050505) &
|
||||||
|
0x80808080
|
||||||
|
) >> 2
|
||||||
|
)
|
||||||
|
}
|
||||||
|
for byte in after {
|
||||||
|
*byte = branchless_to_ascii_upper_case(*byte)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bench08_fake_simd_u64(bytes: &mut [u8]) {
|
||||||
|
let (before, aligned, after) = unsafe {
|
||||||
|
bytes.align_to_mut::<u64>()
|
||||||
|
};
|
||||||
|
for byte in before {
|
||||||
|
*byte = branchless_to_ascii_upper_case(*byte)
|
||||||
|
}
|
||||||
|
for word in aligned {
|
||||||
|
// FIXME: like above, this is incorrect for some byte values.
|
||||||
|
*word &= !(
|
||||||
|
(
|
||||||
|
word.wrapping_add(0x1f1f1f1f_1f1f1f1f) &
|
||||||
|
!word.wrapping_add(0x05050505_05050505) &
|
||||||
|
0x80808080_80808080
|
||||||
|
) >> 2
|
||||||
|
)
|
||||||
|
}
|
||||||
|
for byte in after {
|
||||||
|
*byte = branchless_to_ascii_upper_case(*byte)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! repeat {
|
macro_rules! repeat {
|
||||||
|
Loading…
Reference in New Issue
Block a user