Repository navigation
gh-120196: Faster ascii_decode and find_max_char implementations #120212
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
a54bf86
Write an unrolled version of find_max_char
rhpvorderman 71ff457
Unroll 8 characters rather than 4 to improve vectorization in find_ma…
rhpvorderman 98a6449
Bigger chunk ascii decoding
rhpvorderman 10527c6
Fix whitespace issues
rhpvorderman f0f4139
Fix compiler warnings
rhpvorderman 849a068
Prevent re-read of same value
rhpvorderman fad19a0
Simplify find_max_char initialization
rhpvorderman f04bb2c
Add missing increments
rhpvorderman cd0fc5e
Add blurb
rhpvorderman 8f0fd56
Replace unroll_end with unrolled_end
rhpvorderman 37aee7a
Reword burb
rhpvorderman a6fc417
Update Objects/stringlib/find_max_char.h
rhpvorderman 104ca62
Merge branch 'main' into MICROOPTIMIZATIONS
rhpvorderman d465517
Merge branch 'main' into MICROOPTIMIZATIONS
rhpvorderman 1ce308e
Reuse find_max_char for bytes objects
rhpvorderman 48f1e84
Simplify the find_max_char function by loading unaligned
rhpvorderman 21de804
Allow optimized unaligned loads and simplify ascii_decode
rhpvorderman 1ec2113
Add loop for more optimal assembly
rhpvorderman 0258ae0
Also perform an unalgined load at the end
rhpvorderman ec76b74
Fix compiler warning
rhpvorderman 845eb4e
Revert "Reuse find_max_char for bytes objects"
rhpvorderman f8cc68d
Merge branch 'main' into MICROOPTIMIZATIONS
rhpvorderman 89ab2c9
Improve comments
rhpvorderman 002b7ec
Merge branch 'main' into MICROOPTIMIZATIONS
rhpvorderman 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
Also perform an unalgined load at the end
- Loading branch information
commit 0258ae0b47b5b0efa9d44f435bd3475e09a9763a
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,7 @@ STRINGLIB(find_max_char)(const STRINGLIB_CHAR *begin, const STRINGLIB_CHAR *end) | |
| const unsigned char *restrict p = (const unsigned char *) begin; | ||
| const unsigned char *_end = (const unsigned char *)end; | ||
| const unsigned char *size_t_end = _end - SIZEOF_SIZE_T; | ||
| const unsigned char *unrolled_end = _end - 4 * SIZEOF_SIZE_T; | ||
| const unsigned char *unrolled_end = _end - (4 * SIZEOF_SIZE_T - 1); | ||
| while (p < unrolled_end) { | ||
| /* Test chunks of 32 as more granularity limits compiler optimization */ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 32 what? the number of bytes depend on size_t size in bytes.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoops, will write a better comment. This is a "programmer talking to self" one. |
||
| const size_t *restrict _p = (const size_t *)p; | ||
|
|
@@ -50,9 +50,17 @@ STRINGLIB(find_max_char)(const STRINGLIB_CHAR *begin, const STRINGLIB_CHAR *end) | |
| accumulator |= value; | ||
| p += SIZEOF_SIZE_T; | ||
| } | ||
| while (p < end) { | ||
| accumulator |= *p; | ||
| p += 1; | ||
| if (size_t_end >= begin) { | ||
| /* Do unaligned size_t load rather than loading bytes individually. */ | ||
| size_t value; | ||
| memcpy(&value, size_t_end, SIZEOF_SIZE_T); | ||
| accumulator |= value; | ||
| } else { | ||
| /* Fallback for smaller than size_t strings. */ | ||
| while (p < end) { | ||
| accumulator |= *p; | ||
| p += 1; | ||
| } | ||
| } | ||
| if (accumulator & UCS1_ASCII_CHAR_MASK) { | ||
| return 255; | ||
|
|
||
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.
I would prefer to start processing bytes until we reach an address aligned of SIZEOF_SIZE_T, and then use
size_t*pointers instead ofmemcpy().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.
Ok, good to know thanks. I will close another PR that simplifies the code by using this technique to allow unaligned loads:
#123895