-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[mono][interp] Intrinsify BitOperations.Log2 #40069
Conversation
Tagging subscribers to this area: @BrzVlad |
@@ -5358,6 +5358,16 @@ interp_exec_method (InterpFrame *frame, ThreadContext *context, FrameClauseArgs | |||
ip++; | |||
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); |
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.
__builtin_clz
uses bsr
since we don't set -march=native
or -mattr+
https://godbolt.org/z/bMqcM5
lzcnt
makes it even faster.
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 might need an ifdef gcc or something.
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.
@vargaz works fine on clang and should be correctly expanded for Arm
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.
ah, forgot about MSVC
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.
With MSVC, we can use _BitScan{Forward,Reverse} with this conversion. (can be wrapped in a macro?)
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.
@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
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