Skip to content

Commit a5ba248

Browse files
committed
Relocate bench and use str corpora for data
Add #[inline(always)] to inner function and check not for filecheck test
1 parent 7b88f48 commit a5ba248

File tree

6 files changed

+50
-58
lines changed

6 files changed

+50
-58
lines changed

library/core/src/slice/ascii.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ impl [u8] {
103103
let (other_chunks, _) = other.as_chunks::<N>();
104104

105105
// Branchless check to encourage auto-vectorization
106+
#[inline(always)]
106107
const fn eq_ignore_ascii_inner(lhs: &[u8; N], rhs: &[u8; N]) -> bool {
107108
let mut equal_ascii = true;
108109
let mut j = 0;

library/coretests/benches/ascii.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
mod eq_ignore_ascii_case;
21
mod is_ascii;
32

43
// Lower-case ASCII 'a' is the first byte that has its highest bit set

library/coretests/benches/ascii/eq_ignore_ascii_case.rs

Lines changed: 0 additions & 56 deletions
This file was deleted.

library/coretests/benches/str.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use test::{Bencher, black_box};
55
mod char_count;
66
mod corpora;
77
mod debug;
8+
mod eq_ignore_ascii_case;
89
mod iter;
910

1011
#[bench]
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
use test::{Bencher, black_box};
2+
3+
use super::corpora::*;
4+
5+
#[bench]
6+
fn bench_str_under_8_bytes_eq(b: &mut Bencher) {
7+
let s = black_box("foo");
8+
let other = black_box("foo");
9+
b.iter(|| assert!(s.eq_ignore_ascii_case(other)))
10+
}
11+
12+
#[bench]
13+
fn bench_str_of_8_bytes_eq(b: &mut Bencher) {
14+
let s = black_box(en::TINY);
15+
let other = black_box(en::TINY);
16+
b.iter(|| assert!(s.eq_ignore_ascii_case(other)))
17+
}
18+
19+
#[bench]
20+
fn bench_str_17_bytes_eq(b: &mut Bencher) {
21+
let s = black_box(&en::SMALL[..17]);
22+
let other = black_box(&en::SMALL[..17]);
23+
b.iter(|| assert!(s.eq_ignore_ascii_case(other)))
24+
}
25+
26+
#[bench]
27+
fn bench_str_31_bytes_eq(b: &mut Bencher) {
28+
let s = black_box(&en::SMALL[..31]);
29+
let other = black_box(&en::SMALL[..31]);
30+
b.iter(|| assert!(s.eq_ignore_ascii_case(other)))
31+
}
32+
33+
#[bench]
34+
fn bench_medium_str_eq(b: &mut Bencher) {
35+
let s = black_box(en::MEDIUM);
36+
let other = black_box(en::MEDIUM);
37+
b.iter(|| assert!(s.eq_ignore_ascii_case(other)))
38+
}
39+
40+
#[bench]
41+
fn bench_large_str_eq(b: &mut Bencher) {
42+
let s = black_box(en::LARGE);
43+
let other = black_box(en::LARGE);
44+
b.iter(|| assert!(s.eq_ignore_ascii_case(other)))
45+
}

tests/codegen-llvm/lib-optimizations/eq_ignore_ascii_case.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
//@ only-x86_64
33
#![crate_type = "lib"]
44

5-
// Ensure that the optimized variant of the function gets auto-vectorized.
5+
// Ensure that the optimized variant of the function gets auto-vectorized and
6+
// that the inner helper function is inlined.
67
// CHECK-LABEL: @eq_ignore_ascii_case_autovectorized
78
#[no_mangle]
89
pub fn eq_ignore_ascii_case_autovectorized(s: &str, other: &str) -> bool {
910
// CHECK: load <16 x i8>
1011
// CHECK: load <16 x i8>
1112
// CHECK: bitcast <16 x i1>
13+
// CHECK-NOT: call {{.*}}eq_ignore_ascii_inner
1214
// CHECK-NOT: panic
1315
s.eq_ignore_ascii_case(other)
1416
}

0 commit comments

Comments
 (0)