-
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
Intrinsify typeof(T).IsPrimitive #96226
Conversation
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch Issue DetailsSeems to be straightforward unless I am missing something (if my Closes #95929 bool Test() => typeof(int).IsPrimitive; ; Method P:Test():ubyte:this (FullOpts)
- sub rsp, 40
- mov rcx, 0x17E001054B0 ; 'System.Int32'
- call System.RuntimeTypeHandle:GetCorElementType(System.RuntimeType):ubyte
- mov ecx, 1
- shlx eax, ecx, eax
- test eax, 0x3003FFC
- setne al
- movzx rax, al
- add rsp, 40
+ mov eax, 1
ret
; Total bytes of code: 45 Some other APIs are now constant-folded too, e.g.:
will add tests.
|
54763d3
to
237cc9f
Compare
I love this kind of improvements. ❤🙌 |
Any interesting diffs? Any places in this repo to switch over to this intrinsic? |
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
No diffs in BCL yet but it was requested a few times in different threads so I decided to add it since it's not a lot of efforts after all. The only place in the BCL I know is(https://github.com/dotnet/runtime/blob/main/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/Constants.cs#L46-L58) |
@jkotas does it look good to your otherwise? |
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.
LGTM
Closes #95929
Codegen diff for e.g.
Test<int>
andTest<string>
:Should allow us to avoid listing all primitives by hands for perf reasons (e.g. here)
will add tests.