]> git.lizzy.rs Git - rust.git/commit
Make [u8]::reverse() 5x faster
authorScott McMurray <scottmcm@users.noreply.github.com>
Fri, 5 May 2017 03:28:34 +0000 (20:28 -0700)
committerScott McMurray <scottmcm@users.noreply.github.com>
Fri, 5 May 2017 03:28:34 +0000 (20:28 -0700)
commite8fad325fe8630c0a6561d3e0c9c5fc51423aac0
tree802ce2c90817ccfbe44a3a680a685f83902e3643
parent06fb4d25642a3f223db1441972dd5962085cfba1
Make [u8]::reverse() 5x faster

Since LLVM doesn't vectorize the loop for us, do unaligned reads
of a larger type and use LLVM's bswap intrinsic to do the
reversing of the actual bytes.  cfg!-restricted to x86 and
x86_64, as I assume it wouldn't help on things like ARMv5.

Also makes [u16]::reverse() a more modest 1.5x faster by
loading/storing u32 and swapping the u16s with ROT16.

Thank you ptr::*_unaligned for making this easy :)
src/libcollections/benches/slice.rs
src/libcollections/tests/slice.rs
src/libcore/slice/mod.rs