Skip to content
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

remove redundant OR #88993

Merged
merged 1 commit into from
Jul 17, 2023
Merged

remove redundant OR #88993

merged 1 commit into from
Jul 17, 2023

Conversation

adamsitnik
Copy link
Member

@adamsitnik adamsitnik commented Jul 17, 2023

both inputs are equal here so if one of them is non ASCII, then the other one is too (idea taken from @BrennanConroy)

ASM diff: https://www.diffchecker.com/hdGIxueW

#87141 have not introduced the regression reported in #88670, but it has changed... the code alignment.

This PR improves the perf for the mentioned benchmark by 5%.

The other benchmark is back to it's previous state:

image

So it should be safe to assume that this PR is going to fix #88670

dotnet run -c Release -f net8.0 -- --filter "*Perf_Ascii.Equals_*Chars*" --envVars DOTNET_EnableAVX2:0 --memoryRandomization --launchCount 6 --corerun $removedForBrevity
BenchmarkDotNet=v0.13.2.2052-nightly, OS=Windows 11 (10.0.22621.1848)
AMD Ryzen Threadripper PRO 3945WX 12-Cores, 1 CPU, 24 logical and 12 physical cores
.NET SDK=8.0.100-preview.4.23259.14
  [Host]     : .NET 8.0.0 (8.0.23.25905), X64 RyuJIT AVX2
  Job-VOGWHW : .NET 8.0.0 (42.42.42.42424), X64 RyuJIT AVX
  Job-AYOMRP : .NET 8.0.0 (42.42.42.42424), X64 RyuJIT AVX
Method Job Size Mean Ratio
Equals_Chars PR 6 5.121 ns 0.93
Equals_Chars main 6 5.502 ns 1.00
Equals_Bytes_Chars PR 6 4.533 ns 0.95
Equals_Bytes_Chars main 6 4.778 ns 1.00
Equals_Chars PR 128 15.179 ns 1.00
Equals_Chars main 128 15.176 ns 1.00
Equals_Bytes_Chars PR 128 11.559 ns 1.01
Equals_Bytes_Chars main 128 11.413 ns 1.00

both inputs are equal here so if one of them is non ASCII, then the other one is too
@ghost
Copy link

ghost commented Jul 17, 2023

Tagging subscribers to this area: @dotnet/area-system-text-encoding
See info in area-owners.md if you want to be subscribed.

Issue Details

both inputs are equal here so if one of them is non ASCII, then the other one is too (idea taken from @BrennanConroy)

ASM diff: https://www.diffchecker.com/hdGIxueW

#87141 have not introduced the regression reported in #88670, but it has changed... the code alignment.

This PR improves the perf for the mentioned benchmark by 5%.

The other benchmark is back to it's previous state:

image

So it should be safe to assume that this PR is going to fix #88670

dotnet run -c Release -f net8.0 -- --filter "*Perf_Ascii.Equals_*Chars*6*" --envVars DOTNET_EnableAVX2:0 --memoryRandomization --launchCount 6 --corerun $removedForBrevity
BenchmarkDotNet=v0.13.2.2052-nightly, OS=Windows 11 (10.0.22621.1848)
AMD Ryzen Threadripper PRO 3945WX 12-Cores, 1 CPU, 24 logical and 12 physical cores
.NET SDK=8.0.100-preview.4.23259.14
  [Host]     : .NET 8.0.0 (8.0.23.25905), X64 RyuJIT AVX2
  Job-VOGWHW : .NET 8.0.0 (42.42.42.42424), X64 RyuJIT AVX
  Job-AYOMRP : .NET 8.0.0 (42.42.42.42424), X64 RyuJIT AVX
Method Job Size Mean Ratio
Equals_Chars PR 6 5.121 ns 0.93
Equals_Chars main 6 5.502 ns 1.00
Equals_Bytes_Chars PR 6 4.533 ns 0.95
Equals_Bytes_Chars main 6 4.778 ns 1.00
Equals_Chars PR 128 15.179 ns 1.00
Equals_Chars main 128 15.176 ns 1.00
Equals_Bytes_Chars PR 128 11.559 ns 1.01
Equals_Bytes_Chars main 128 11.413 ns 1.00
Author: adamsitnik
Assignees: -
Labels:

area-System.Text.Encoding, tenet-performance

Milestone: -

@adamsitnik adamsitnik added this to the 8.0.0 milestone Jul 17, 2023
@EgorBo
Copy link
Member

EgorBo commented Jul 17, 2023

Presumably, you can use the same trick in the main loop of these functions that currently looks like this:

-if (!AllCharsInVectorAreAscii(leftValues | rightValues))
-{
-    return false;
-}

Vector128<TRight> notEquals = ~Vector128.Equals(leftValues, rightValues);

if (notEquals != Vector128<TRight>.Zero)
{
+   if (!AllCharsInVectorAreAscii(leftValues | rightValues))
+       return false;
    // not exact match

    leftValues |= loweringMask;
    rightValues |= loweringMask;

    if (Vector128.GreaterThanAny((leftValues - vecA) & notEquals, vecZMinusA) || leftValues != rightValues)
    {
        return false; // first input isn't in [A-Za-z], and not exact match of lowered
    }
}
+else if (!AllCharsInVectorAreAscii(leftValues))
+   return false;

but I'm not sure if it's profitable - or is fast and this increases loop body's size 🙂

@adamsitnik
Copy link
Member Author

The failures are unrelated (#88996), merging.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regressions in System.Text.Perf_Ascii
3 participants