Skip to content

[mono][interp] Intrinsify BitOperations.Log2 - #40069

Closed
EgorBo wants to merge 3 commits into
dotnet:masterfrom
EgorBo:interp-intrin-log2
Closed

EgorBo wants to merge 3 commits into
dotnet:masterfrom
EgorBo:interp-intrin-log2

Conversation

@EgorBo

@EgorBo EgorBo commented Jul 29, 2020 •

Copy link
Copy Markdown
Member

It's used in NumberFormatter, Array.Sort and SpanHelpers.

e.g. the following code uses it under the hood:
235235235325.ToString("X")

^ For Mono-Wasm:
before: 18.4 ms (in a loop)
after: 15.2 ms

@ghost

ghost commented Jul 29, 2020

Copy link
Copy Markdown

Tagging subscribers to this area: @BrzVlad
See info in area-owners.md if you want to be subscribed.

@EgorBo
EgorBo requested a review from vargaz July 29, 2020 08:44
MINT_IN_BREAK;
}
MINT_IN_CASE(MINT_INTRINS_BITOPS_LOG2_32) {
sp [-1].data.i = 31 ^ (gint32)__builtin_clz ((guint32)sp [-1].data.i | 1);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

__builtin_clz uses bsr since we don't set -march=native or -mattr+ https://godbolt.org/z/bMqcM5
lzcnt makes it even faster.

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.

This might need an ifdef gcc or something.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@vargaz works fine on clang and should be correctly expanded for Arm

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ah, forgot about MSVC

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

With MSVC, we can use _BitScan{Forward,Reverse} with this conversion. (can be wrapped in a macro?)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@EgorBo you could extract sgen_clz out of sgen into utils and reuse it here. We have the logic there to use _BitScan on msvc

@EgorBo EgorBo closed this Sep 8, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
Sign up for free to 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.

5 participants