rust/library/core/src
The 8472 3d4a8482b9 x86_64 SSE2 fast-path for str.contains(&str) and short needles
Based on Wojciech Muła's "SIMD-friendly algorithms for substring searching"[0]

The two-way algorithm is Big-O efficient but it needs to preprocess the needle
to find a "criticla 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:

```
16CGU, OLD:
test str::bench_contains_short_short                     ... bench:          27 ns/iter (+/- 1)
test str::bench_contains_short_long                      ... bench:         667 ns/iter (+/- 29)
test str::bench_contains_bad_naive                       ... bench:         131 ns/iter (+/- 2)
test str::bench_contains_bad_simd                        ... bench:         130 ns/iter (+/- 2)
test str::bench_contains_equal                           ... bench:         148 ns/iter (+/- 4)


16CGU, NEW:
test str::bench_contains_short_short                     ... bench:           8 ns/iter (+/- 0)
test str::bench_contains_short_long                      ... bench:         135 ns/iter (+/- 4)
test str::bench_contains_bad_naive                       ... bench:         130 ns/iter (+/- 2)
test str::bench_contains_bad_simd                        ... bench:         292 ns/iter (+/- 1)
test str::bench_contains_equal                           ... bench:           3 ns/iter (+/- 0)


1CGU, OLD:
test str::bench_contains_short_short                     ... bench:          30 ns/iter (+/- 0)
test str::bench_contains_short_long                      ... bench:         713 ns/iter (+/- 17)
test str::bench_contains_bad_naive                       ... bench:         131 ns/iter (+/- 3)
test str::bench_contains_bad_simd                        ... bench:         130 ns/iter (+/- 3)
test str::bench_contains_equal                           ... bench:         148 ns/iter (+/- 6)

1CGU, NEW:
test str::bench_contains_short_short                     ... bench:          10 ns/iter (+/- 0)
test str::bench_contains_short_long                      ... bench:         111 ns/iter (+/- 0)
test str::bench_contains_bad_naive                       ... bench:         135 ns/iter (+/- 3)
test str::bench_contains_bad_simd                        ... bench:         274 ns/iter (+/- 2)
test str::bench_contains_equal                           ... bench:           4 ns/iter (+/- 0)
```


[0] http://0x80.pl/articles/simd-strfind.html#sse-avx2
2022-11-14 23:03:16 +01: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 Clarify the possible return values of len_utf16 2022-10-16 11:06:19 -04: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 Auto merge of #99099 - Stargateur:phantomdata_debug, r=joshtriplett 2022-10-04 00:56:14 +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 Rollup merge of #102049 - fee1-dead-contrib:derive_const, r=oli-obk 2022-11-12 12:02:50 +05:30
mem Rollup merge of #104308 - scottmcm:no-more-validalign, r=thomcc 2022-11-12 17:25:03 +01:00
num Auto merge of #103858 - Mark-Simulacrum:bump-bootstrap, r=pietroalbini 2022-11-14 00:07:19 +00:00
ops Auto merge of #103858 - Mark-Simulacrum:bump-bootstrap, r=pietroalbini 2022-11-14 00:07:19 +00: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 Auto merge of #103858 - Mark-Simulacrum:bump-bootstrap, r=pietroalbini 2022-11-14 00:07:19 +00: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 x86_64 SSE2 fast-path for str.contains(&str) and short needles 2022-11-14 23:03:16 +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 Use derive_const and rm manual StructuralEq impl 2022-11-12 12:57:10 +00:00
marker.rs Rollup merge of #103110 - RalfJung:manual-send, r=thomcc 2022-10-27 15:03:55 +02:00
option.rs Bump version placeholders to release 2022-11-06 17:11:02 -05:00
panic.rs resolve the conflict in compiler/rustc_session/src/parse.rs 2022-03-16 20:12:30 +08: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