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: 45Some 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? |
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.