forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#117260 - okaneco:ascii_branchless, r=thomcc
Refactor some `char`, `u8` ASCII functions to be branchless Extract conditions in singular `matches!` with or-patterns to individual `matches!` statements which enables branchless code output. The following functions were changed: - `is_ascii_alphanumeric` - `is_ascii_hexdigit` - `is_ascii_punctuation` Added codegen tests --- Continued from rust-lang#103024. Based on the comment from `@scottmcm` rust-lang#103024 (review). The unmodified `is_ascii_*` functions didn't seem to benefit from extracting the conditions. I've never written a codegen test before, but I tried to check that no branches were emitted.
- Loading branch information
Showing
3 changed files
with
59 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 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,47 @@ | ||
// Checks that these functions are branchless. | ||
// | ||
// compile-flags: -O | ||
|
||
#![crate_type = "lib"] | ||
|
||
// CHECK-LABEL: @is_ascii_alphanumeric_char | ||
#[no_mangle] | ||
pub fn is_ascii_alphanumeric_char(x: char) -> bool { | ||
// CHECK-NOT: br | ||
x.is_ascii_alphanumeric() | ||
} | ||
|
||
// CHECK-LABEL: @is_ascii_alphanumeric_u8 | ||
#[no_mangle] | ||
pub fn is_ascii_alphanumeric_u8(x: u8) -> bool { | ||
// CHECK-NOT: br | ||
x.is_ascii_alphanumeric() | ||
} | ||
|
||
// CHECK-LABEL: @is_ascii_hexdigit_char | ||
#[no_mangle] | ||
pub fn is_ascii_hexdigit_char(x: char) -> bool { | ||
// CHECK-NOT: br | ||
x.is_ascii_hexdigit() | ||
} | ||
|
||
// CHECK-LABEL: @is_ascii_hexdigit_u8 | ||
#[no_mangle] | ||
pub fn is_ascii_hexdigit_u8(x: u8) -> bool { | ||
// CHECK-NOT: br | ||
x.is_ascii_hexdigit() | ||
} | ||
|
||
// CHECK-LABEL: @is_ascii_punctuation_char | ||
#[no_mangle] | ||
pub fn is_ascii_punctuation_char(x: char) -> bool { | ||
// CHECK-NOT: br | ||
x.is_ascii_punctuation() | ||
} | ||
|
||
// CHECK-LABEL: @is_ascii_punctuation_u8 | ||
#[no_mangle] | ||
pub fn is_ascii_punctuation_u8(x: u8) -> bool { | ||
// CHECK-NOT: br | ||
x.is_ascii_punctuation() | ||
} |