rust/library/core/src
bors 9340e5c1b9 Auto merge of #103779 - the8472:simd-str-contains, r=thomcc
x86_64 SSE2 fast-path for str.contains(&str) and short needles

Based on Wojciech Muła's [SIMD-friendly algorithms for substring searching](http://0x80.pl/articles/simd-strfind.html#sse-avx2)

The two-way algorithm is Big-O efficient but it needs to preprocess the needle
to find a "critical factorization" of it. This additional work is significant
for short needles. Additionally it mostly advances needle.len() bytes at a time.

The SIMD-based approach used here on the other hand can advance based on its
vector width, which can exceed the needle length. Except for pathological cases,
but due to being limited to small needles the worst case blowup is also small.

benchmarks taken on a Zen2, compiled with `-Ccodegen-units=1`:

```
OLD:
test str::bench_contains_16b_in_long                     ... bench:         504 ns/iter (+/- 14) = 5061 MB/s
test str::bench_contains_2b_repeated_long                ... bench:         948 ns/iter (+/- 175) = 2690 MB/s
test str::bench_contains_32b_in_long                     ... bench:         445 ns/iter (+/- 6) = 5732 MB/s
test str::bench_contains_bad_naive                       ... bench:         130 ns/iter (+/- 1) = 569 MB/s
test str::bench_contains_bad_simd                        ... bench:          84 ns/iter (+/- 8) = 880 MB/s
test str::bench_contains_equal                           ... bench:         142 ns/iter (+/- 7) = 394 MB/s
test str::bench_contains_short_long                      ... bench:         677 ns/iter (+/- 25) = 3768 MB/s
test str::bench_contains_short_short                     ... bench:          27 ns/iter (+/- 2) = 2074 MB/s

NEW:
test str::bench_contains_16b_in_long                     ... bench:          82 ns/iter (+/- 0) = 31109 MB/s
test str::bench_contains_2b_repeated_long                ... bench:          73 ns/iter (+/- 0) = 34945 MB/s
test str::bench_contains_32b_in_long                     ... bench:          71 ns/iter (+/- 1) = 35929 MB/s
test str::bench_contains_bad_naive                       ... bench:           7 ns/iter (+/- 0) = 10571 MB/s
test str::bench_contains_bad_simd                        ... bench:          97 ns/iter (+/- 41) = 762 MB/s
test str::bench_contains_equal                           ... bench:           4 ns/iter (+/- 0) = 14000 MB/s
test str::bench_contains_short_long                      ... bench:          73 ns/iter (+/- 0) = 34945 MB/s
test str::bench_contains_short_short                     ... bench:          12 ns/iter (+/- 0) = 4666 MB/s
```
2022-11-17 04:47:11 +00:00
..
alloc Remove the old ValidAlign name 2022-11-11 21:44:27 -08:00
array document and improve array Guard type 2022-11-08 00:13:26 +01:00
async_iter use consistent terminology 2022-10-29 09:23:12 +02:00
cell Move/rename lazy::{OnceCell, Lazy} to cell::{OnceCell, LazyCell} 2022-06-16 19:53:59 +04:00
char Rollup merge of #102470 - est31:stabilize_const_char_convert, r=joshtriplett 2022-11-14 19:26:15 +01:00
convert Rollup merge of #102628 - H4x5:master, r=scottmcm 2022-10-04 06:14:12 +02:00
ffi Rollup merge of #103680 - RalfJung:cstr-links, r=JohnTitor 2022-11-04 12:18:00 +01:00
fmt Remove unused diagnostic items 2022-11-13 18:49:21 +00:00
future poll_fn and Unpin: fix pinning 2022-10-06 13:51:10 +02:00
hash Test const Hash, fix nits 2022-11-08 17:39:40 +01:00
intrinsics Add support for custom MIR parsing 2022-11-08 23:13:15 -08:00
iter document and improve array Guard type 2022-11-08 00:13:26 +01:00
macros Remove unused diagnostic items 2022-11-13 18:49:21 +00:00
mem Auto merge of #104054 - RalfJung:byte-provenance, r=oli-obk 2022-11-15 17:37:15 +00:00
num Auto merge of #102935 - ajtribick:display-float-0.5-fixed-0, r=scottmcm 2022-11-16 07:20:30 +00:00
ops Rollup merge of #104383 - WaffleLapkin:rustc_undiagnostic_item, r=compiler-errors 2022-11-15 01:40:44 +01:00
panic Change tracking issue from #76156 to #102911 2022-10-11 06:40:37 +00:00
prelude Rollup merge of #102049 - fee1-dead-contrib:derive_const, r=oli-obk 2022-11-12 12:02:50 +05:30
ptr Rollup merge of #103489 - WaffleLapkin:byte_offset_from_you, r=scottmcm 2022-11-16 08:36:10 +01:00
slice Rollup merge of #104111 - yancyribbens:add-mutable-to-the-description-for-as-simd-mut, r=scottmcm 2022-11-09 19:21:24 +05:30
str - convert from core::arch to core::simd 2022-11-15 18:30:31 +01:00
sync Remove extra spaces 2022-10-19 23:54:00 +01:00
task Added tracking issue 2022-09-19 15:07:12 +02:00
unicode Bump Unicode to version 15.0.0, regenerate tables 2022-09-14 13:21:19 -07:00
any.rs Add Provider::{would_be_satisfied_by_value_of,would_be_satisfied_by_ref_of} 2022-08-23 10:48:59 -04:00
ascii.rs Inline <EscapeDefault as Iterator>::next 2022-03-10 15:35:22 +01:00
asserting.rs [RFC 2011] Library code 2022-05-22 07:18:32 -03:00
bool.rs Add missing assertion 2022-09-22 02:12:06 -04:00
borrow.rs Add const_traits 2022-09-16 11:48:42 +08:00
cell.rs Rollup merge of #104002 - RalfJung:unsafecell-new, r=JohnTitor 2022-11-06 08:35:27 +01:00
clone.rs update cfg(bootstrap)s 2022-07-01 15:48:23 +02:00
cmp.rs Use derive_const and rm manual StructuralEq impl 2022-11-12 12:57:10 +00:00
const_closure.rs Merge conflicts and rebase onto master 2022-11-05 18:05:44 +00:00
default.rs cfg-step code 2022-11-06 17:21:21 -05:00
error.md Small round of typo fixes 2022-11-04 20:06:18 -07:00
error.rs Bump version placeholders to release 2022-11-06 17:11:02 -05:00
hint.rs Bump version placeholders to release 2022-11-06 17:11:02 -05:00
internal_macros.rs ignore a doctest for the non-exported macro 2022-05-03 18:33:56 +09:00
intrinsics.rs Auto merge of #103858 - Mark-Simulacrum:bump-bootstrap, r=pietroalbini 2022-11-14 00:07:19 +00:00
lib.rs Rollup merge of #102470 - est31:stabilize_const_char_convert, r=joshtriplett 2022-11-14 19:26:15 +01:00
marker.rs Add rustc_deny_explicit_impl 2022-11-14 03:23:41 +00:00
option.rs Bump version placeholders to release 2022-11-06 17:11:02 -05:00
panic.rs Fix clippy and rustdoc 2022-11-13 22:58:20 +00:00
panicking.rs cfg-step code 2022-11-06 17:21:21 -05:00
pin.rs Update tests to match error message changes 2022-10-20 16:43:27 +01:00
primitive.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
primitive_docs.rs array docs - advertise how to get array from slice 2022-09-10 19:37:07 -07:00
result.rs Auto merge of #98354 - camsteffen:is-some-and-by-value, r=m-ou-se 2022-10-02 12:48:15 +00:00
time.rs Bump version placeholders to release 2022-11-06 17:11:02 -05:00
tuple.rs const Compare Tuples 2022-11-09 09:52:04 +01:00
unit.rs Use implicit capture syntax in format_args 2022-03-10 10:23:40 -05:00