-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Optimize Ascii.Equals when widening #87141
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
Changes from 1 commit
1467895
6b1cb00
60e0c2f
dd02aeb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -65,6 +65,10 @@ private static bool Equals<TLeft, TRight, TLoader>(ref TLeft left, ref TRight ri | |||||
{ | ||||||
ref TLeft currentLeftSearchSpace = ref left; | ||||||
ref TRight currentRightSearchSpace = ref right; | ||||||
// Add Vector256<TLeft>.Count because TLeft == TRight | ||||||
// Or we are in the Widen case where we iterate 2 * TRight.Count which is the same as TLeft.Count | ||||||
Debug.Assert(Vector256<TLeft>.Count == Vector256<TRight>.Count | ||||||
|| (typeof(TLoader) == typeof(WideningLoader) && Vector256<TLeft>.Count == Vector256<TRight>.Count * 2)); | ||||||
ref TRight oneVectorAwayFromRightEnd = ref Unsafe.Add(ref currentRightSearchSpace, length - (uint)Vector256<TLeft>.Count); | ||||||
|
||||||
// Loop until either we've finished all elements or there's less than a vector's-worth remaining. | ||||||
|
@@ -410,22 +414,22 @@ public static Vector256<ushort> Load256(ref byte ptr) | |||||
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||||||
[CompExactlyDependsOn(typeof(Avx))] | ||||||
public static bool Compare256(ref byte left, ref ushort right) | ||||||
public static bool Compare256(ref byte utf8, ref ushort utf16) | ||||||
adamsitnik marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
{ | ||||||
// We widen the utf8 param so we can compare it to utf16, this doubles how much of the utf16 vector we search | ||||||
Debug.Assert(Vector256<byte>.Count == Vector256<ushort>.Count * 2); | ||||||
|
||||||
Vector256<byte> leftNotWidened = Vector256.LoadUnsafe(ref left); | ||||||
Vector256<byte> leftNotWidened = Vector256.LoadUnsafe(ref utf8); | ||||||
if (!AllCharsInVectorAreAscii(leftNotWidened)) | ||||||
{ | ||||||
return false; | ||||||
} | ||||||
|
||||||
(Vector256<ushort> lower, Vector256<ushort> upper) = Vector256.Widen(leftNotWidened); | ||||||
|
(Vector256<ushort> lower, Vector256<ushort> upper) = Vector256.Widen(leftNotWidened); | |
var (lower, upper) = Vector256.Widen(leftNotWidened); |
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.
This is me adding value:
Please stop adding value. :-P
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.
The BCL has a rule that var
can only be used when the type is apparent.
It's a battle that I lost before ever joining the team 😅
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'm not understanding why this is valid. We're subtracting from the "right" search space the number of "left" elements in a vector?
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.
It works because
TLeft
andTRight
are either the same type, or we are in the widen case whereVector<TLeft>
is twice the size ofVector<TRight>
and the widen code will advance twiceVector<TRight>.Count
which is equal to 1Vector<TLeft>.Count
.But it is written in a confusing way. The whole
TLoader
abstraction helps with code sharing but makes this part kind of yucky. Maybe if the compare method advanced the pointers it would be better?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.
Thanks. At a minimum a comment explaining would be helpful.