-
Notifications
You must be signed in to change notification settings - Fork 13.8k
slice/ascii: Optimize eq_ignore_ascii_case
with auto-vectorization
#147436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
okaneco
wants to merge
3
commits into
rust-lang:master
Choose a base branch
from
okaneco:eq_ignore_ascii_autovec
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+121
−0
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod eq_ignore_ascii_case; | ||
mod is_ascii; | ||
|
||
// Lower-case ASCII 'a' is the first byte that has its highest bit set | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use test::Bencher; | ||
|
||
#[bench] | ||
fn bench_str_under_8_bytes_eq(b: &mut Bencher) { | ||
let s = "foo"; | ||
let other = "FOo"; | ||
b.iter(|| { | ||
assert!(s.eq_ignore_ascii_case(other)); | ||
}) | ||
} | ||
|
||
#[bench] | ||
fn bench_str_of_8_bytes_eq(b: &mut Bencher) { | ||
let s = "foobar78"; | ||
let other = "FOObAr78"; | ||
b.iter(|| { | ||
assert!(s.eq_ignore_ascii_case(other)); | ||
}) | ||
} | ||
|
||
#[bench] | ||
fn bench_str_17_bytes_eq(b: &mut Bencher) { | ||
let s = "performance-criti"; | ||
let other = "performANce-cRIti"; | ||
b.iter(|| { | ||
assert!(s.eq_ignore_ascii_case(other)); | ||
}) | ||
} | ||
|
||
#[bench] | ||
fn bench_str_31_bytes_eq(b: &mut Bencher) { | ||
let s = "foobarbazquux02foobarbazquux025"; | ||
let other = "fooBARbazQuuX02fooBARbazQuuX025"; | ||
b.iter(|| { | ||
assert!(s.eq_ignore_ascii_case(other)); | ||
}) | ||
} | ||
|
||
#[bench] | ||
fn bench_long_str_eq(b: &mut Bencher) { | ||
let s = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor \ | ||
the8472 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud \ | ||
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute \ | ||
irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla \ | ||
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui \ | ||
officia deserunt mollit anim id est laborum."; | ||
let other = "Lorem ipsum dolor sit amet, CONSECTETUR adipisicing elit, sed do eiusmod tempor \ | ||
incididunt ut labore et dolore MAGNA aliqua. Ut enim ad MINIM veniam, quis nostrud \ | ||
exercitation ullamco LABORIS nisi ut aliquip ex ea commodo consequat. Duis aute \ | ||
irure dolor in reprehenderit in voluptate velit esse cillum DOLORE eu fugiat nulla \ | ||
pariatur. Excepteur sint occaecat CUPIDATAT non proident, sunt in culpa qui \ | ||
officia deserunt mollit anim id est laborum."; | ||
b.iter(|| { | ||
assert!(s.eq_ignore_ascii_case(other)); | ||
}) | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/codegen-llvm/lib-optimizations/eq_ignore_ascii_case.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//@ compile-flags: -Copt-level=3 | ||
//@ only-x86_64 | ||
#![crate_type = "lib"] | ||
|
||
// Ensure that the optimized variant of the function gets auto-vectorized. | ||
// CHECK-LABEL: @eq_ignore_ascii_case_autovectorized | ||
#[no_mangle] | ||
pub fn eq_ignore_ascii_case_autovectorized(s: &str, other: &str) -> bool { | ||
// CHECK: load <16 x i8> | ||
// CHECK: load <16 x i8> | ||
// CHECK: bitcast <16 x i1> | ||
// CHECK-NOT: panic | ||
s.eq_ignore_ascii_case(other) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I copied this code into compiler explorer with
-C opt_level=3
, the call toeq_ignore_ascii_inner
did not get inlined. I would suggest to mark this function#[inline(always)]
and add aCHECK-NOT: call
in the codegen test.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the annotation and filecheck adaptation in a5ba248