Skip to content

BitOperations arm64 intrinsic for LeadingZeroCount, TrailingZeroCount and Log2 - #34486

Merged
kunalspathak merged 5 commits into
dotnet:masterfrom
kunalspathak:bitoperations-intrinsic
Apr 4, 2020
Merged

BitOperations arm64 intrinsic for LeadingZeroCount, TrailingZeroCount and Log2#34486
kunalspathak merged 5 commits into
dotnet:masterfrom
kunalspathak:bitoperations-intrinsic

Conversation

@kunalspathak

@kunalspathakkunalspathak commented Apr 3, 2020

Copy link
Copy Markdown
Contributor

Use arm64 intrinsics for BitOperations's LeadingZeroCount, TrailingZeroCount and Log2 methods.

Below are the performance improvement details of each API.

APIbefore (in us)after (in us)% diff
LeadingZeroCount_uint6.5381.54476%
LeadingZeroCount_ulong6.6141.54477%
Log2_uint5.7741.92067%
Log2_ulong6.9251.92172%
TrailingZeroCount_uint2.7221.66539%
TrailingZeroCount_ulong2.8911.66642%

I didn't include PopCount() as part of this PR because it needs special handling of CreateScalar in JIT. Once #34485 is fixed, I will send a separate PR for it PopCount().

Contributes to #33308 and #33495 .

@Dotnet-GitSync-Bot

Copy link
Copy Markdown
Collaborator

I couldn't figure out the best area label to add to this PR. Please help me learn by adding exactly one area label.

@kunalspathak

kunalspathak commented Apr 3, 2020

Copy link
Copy Markdown
ContributorAuthor

Please take a look @dotnet/jit-contrib , @tannergooding

@BruceForstall

Copy link
Copy Markdown
Contributor

The Log2_uint improvement % number looks incorrect.

For these arm64-specific libraries changes, I think you need to trigger the runtime AzDO pipeline manually, as the default PR testing does not include libraries arm64 testing.

@kunalspathak

Copy link
Copy Markdown
ContributorAuthor

@BruceForstall - Triggered one just now at https://dev.azure.com/dnceng/public/_build/results?buildId=587055&view=results
I do see jobs "Libraries Test Run release coreclr Linux arm64 Release" in it. So hopefully that is the one we wanted.

@kunalspathak
kunalspathakforce-pushed the bitoperations-intrinsic branch from b628d47 to a2effc7CompareApril 3, 2020 05:58
@kunalspathak

Copy link
Copy Markdown
ContributorAuthor

I was seeing ARM not present in System.Runtime.Intrinsics namespace errors. Not sure if this was because I didn't had #34107.

I have rebased my changes and triggered another pipeline run.
https://dev.azure.com/dnceng/public/_build/results?buildId=587081&view=results

@kunalspathak

Copy link
Copy Markdown
ContributorAuthor

Jobs are failing with following errors. Do i need to add a package reference or something inside System.Utf8String.Experimental.csproj. How is it suppose to work?

F:\workspace\_work\1\s\src\libraries\System.Private.CoreLib\src\System\Numerics\BitOperations.cs(8,33): error CS0234: The type or namespace name 'Arm' does not exist in the namespace 'System.Runtime.Intrinsics' (are you missing an assembly reference?) [F:\workspace\_work\1\s\src\libraries\System.Utf8String.Experimental\src\System.Utf8String.Experimental.csproj]
##[error]src\libraries\System.Private.CoreLib\src\System\Numerics\BitOperations.cs(8,33): error CS0234: The type or namespace name 'Arm' does not exist in the namespace 'System.Runtime.Intrinsics' (are you missing an assembly reference?)

@tannergooding , @echesakovMSFT

@EgorBo

Copy link
Copy Markdown
Member

What about BitOperations.RotateLeft does jit lower GT_ROR to arm's ror ?

@kunalspathak

Copy link
Copy Markdown
ContributorAuthor

What about BitOperations.RotateLeft does jit lower GT_ROR to arm's ror ?

Yes. It converts RotateRight to ror and RotateLeft to neg/ror because there is no rol instruction in arm.

@echesakovechesakov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good with comments regarding redundant casts to int

Comment threadsrc/libraries/System.Private.CoreLib/src/System/Numerics/BitOperations.cs Outdated
Comment threadsrc/libraries/System.Private.CoreLib/src/System/Numerics/BitOperations.cs Outdated
Comment threadsrc/libraries/System.Private.CoreLib/src/System/Numerics/BitOperations.cs Outdated
Comment threadsrc/libraries/System.Private.CoreLib/src/System/Numerics/BitOperations.cs Outdated
Comment threadsrc/libraries/System.Private.CoreLib/src/System/Numerics/BitOperations.cs Outdated
Comment threadsrc/libraries/System.Private.CoreLib/src/System/Numerics/BitOperations.cs Outdated
@echesakov

Copy link
Copy Markdown
Contributor

Jobs are failing with following errors. Do i need to add a package reference or something inside System.Utf8String.Experimental.csproj. How is it suppose to work?
F:\workspace_work\1\s\src\libraries\System.Private.CoreLib\src\System\Numerics\BitOperations.cs(8,33): error CS0234: The type or namespace name 'Arm' does not exist in the namespace 'System.Runtime.Intrinsics' (are you missing an assembly reference?) [F:\workspace_work\1\s\src\libraries\System.Utf8String.Experimental\src\System.Utf8String.Experimental.csproj]
##[error]src\libraries\System.Private.CoreLib\src\System\Numerics\BitOperations.cs(8,33): error CS0234: The type or namespace name 'Arm' does not exist in the namespace 'System.Runtime.Intrinsics' (are you missing an assembly reference?)

@kunalspathak My understanding that you need to update Intrinsics.Shims.cs simiralrly as it's been done for System.Runtime.Intrinsics.X86 in order for this to work - @tannergooding is it right?

@tannergooding

Copy link
Copy Markdown
Member

Jobs are failing with following errors. Do i need to add a package reference or something inside System.Utf8String.Experimental.csproj. How is it suppose to work?
My understanding that you need to update Intrinsics.Shims.cs simiralrly as it's been done for System.Runtime.Intrinsics.X86 in order for this to work - @tannergooding is it right?

I believe that is the case, but CC. @GrabYourPitchforks since I think he "owns" System.Utf8String.Experimental.
Just as a note, we don't want to do this more broadly as we don't want to have a reference to the experiemental package from non-experimental packages.
If there is anything non-experimental that isn't in S.P.Corelib that would require a similar change, we may need to wait for the bits to be moved in box (which should be happening once API review on everything finishes).

@kunalspathak

Copy link
Copy Markdown
ContributorAuthor

Jobs are failing with following errors. Do i need to add a package reference or something inside System.Utf8String.Experimental.csproj. How is it suppose to work?
F:\workspace_work\1\s\src\libraries\System.Private.CoreLib\src\System\Numerics\BitOperations.cs(8,33): error CS0234: The type or namespace name 'Arm' does not exist in the namespace 'System.Runtime.Intrinsics' (are you missing an assembly reference?) [F:\workspace_work\1\s\src\libraries\System.Utf8String.Experimental\src\System.Utf8String.Experimental.csproj]
##[error]src\libraries\System.Private.CoreLib\src\System\Numerics\BitOperations.cs(8,33): error CS0234: The type or namespace name 'Arm' does not exist in the namespace 'System.Runtime.Intrinsics' (are you missing an assembly reference?)

@kunalspathak My understanding that you need to update Intrinsics.Shims.cs simiralrly as it's been done for System.Runtime.Intrinsics.X86 in order for this to work - @tannergooding is it right?

That seemed to have solved the problem (atleast on my local machine). Thanks!

@kunalspathak

Copy link
Copy Markdown
ContributorAuthor

The Log2_uint improvement % number looks incorrect.

@BruceForstall - This measurements were taken on ARM64 machine manually for MicroBenchmarks. Changes are here: dotnet/performance#1264

@kunalspathak

Copy link
Copy Markdown
ContributorAuthor

Failures related to #34465
//cc @jaredpar

@kunalspathak
kunalspathak merged commit 510efdf into dotnet:masterApr 4, 2020
@kunalspathak
kunalspathak deleted the bitoperations-intrinsic branch April 4, 2020 00:27
@BruceForstall

Copy link
Copy Markdown
Contributor

@BruceForstall - This measurements were taken on ARM64 machine manually for MicroBenchmarks.

given this:

APIbefore (in us)after (in us)% diff
Log2_uint5.7741.92015%
Log2_ulong6.9251.92172%

It seems like Log2_unit should be 67% improvement, not 15%.

@kunalspathak

Copy link
Copy Markdown
ContributorAuthor

It seems like Log2_unit should be 67% improvement, not 15%.

Ah yes.

@ghostghost locked as resolved and limited conversation to collaborators Dec 9, 2020
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@kunalspathak@Dotnet-GitSync-Bot@BruceForstall@EgorBo@echesakov@tannergooding