From fbe34cc521a5d0f04dd6afadb5b200f0338f41d9 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Mon, 18 Mar 2019 20:40:32 +0100 Subject: [PATCH] =?utf8?q?Add=20benchmark=20for=20not-quite-correct=20?= =?utf8?q?=E2=80=9Cfake=20SIMD=E2=80=9D=20make=5Fascii=5Fuppercase?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/libcore/benches/ascii_case.rs | 46 +++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/libcore/benches/ascii_case.rs b/src/libcore/benches/ascii_case.rs index 1c9691d1ee1..df82a8cb1d5 100644 --- a/src/libcore/benches/ascii_case.rs +++ b/src/libcore/benches/ascii_case.rs @@ -87,6 +87,52 @@ fn bench05_branchless(bytes: &mut [u8]) { fn bench06_libcore(bytes: &mut [u8]) { bytes.make_ascii_uppercase() } + + fn bench07_fake_simd_u32(bytes: &mut [u8]) { + let (before, aligned, after) = unsafe { + bytes.align_to_mut::() + }; + 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::() + }; + 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 { -- 2.44.0