diff options
| author | okaneco <47607823+okaneco@users.noreply.github.com> | 2023-10-26 20:23:56 -0400 |
|---|---|---|
| committer | okaneco <47607823+okaneco@users.noreply.github.com> | 2023-10-26 21:48:36 -0400 |
| commit | 465ffc9ca781af9ac0a89643c9971ac807da5766 (patch) | |
| tree | 4de6c72d8584d65aa4d27c02c900f3251bca64e5 /tests/codegen/char-ascii-branchless.rs | |
| parent | 8396efecf7d30ca9f7edcf76aba2ea388300f6ab (diff) | |
| download | rust-465ffc9ca781af9ac0a89643c9971ac807da5766.tar.gz rust-465ffc9ca781af9ac0a89643c9971ac807da5766.zip | |
Refactor some `char`, `u8` ascii functions to be branchless
Decompose singular `matches!` with or-patterns to individual `matches!` statements to enable branchless code output. The following functions were changed: - `is_ascii_alphanumeric` - `is_ascii_hexdigit` - `is_ascii_punctuation` Add codegen tests Co-authored-by: George Bateman <george.bateman16@gmail.com> Co-authored-by: scottmcm <scottmcm@users.noreply.github.com>
Diffstat (limited to 'tests/codegen/char-ascii-branchless.rs')
| -rw-r--r-- | tests/codegen/char-ascii-branchless.rs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/codegen/char-ascii-branchless.rs b/tests/codegen/char-ascii-branchless.rs new file mode 100644 index 00000000000..b612b24c7c7 --- /dev/null +++ b/tests/codegen/char-ascii-branchless.rs @@ -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() +} |
