-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Inefficient codegen for casts between same size types. #11413
Comments
Related PR: #6864, which makes use of this API |
#33476 introduced a fix which works around the issue, but we are leaving this issue open to track the JIT getting a more general codegen improvement that isn't specific to |
BitConverter.SingleToInt32Bits
and BitConverter.DoubleToInt64Bits
I guess this is partially related to aforementioned issue - is there any reason float.isFinite() is safe while the rest of similar extensions using similar tools are |
@Kein Looks like we just forgot to remove the unsafe modifier from the |
This seems like one of the simpler analyzers we could write, is there an issue suggesting it yet? |
There's some limited discussion around it as part of #31354. Basically: if we have an analyzer that says "you're not using pointers, remove unsafe" alongside a language feature that enforces "this API doesn't use pointers but you need to wrap call sites within an unsafe block", we need to figure out how these two things interact together. |
In .NET 7 it generates L0000: vzeroupper
L0003: vmovd eax, xmm1 |
With .NET 9 Preview 7, vmovd eax, xmm0
vmovd xmm0, ecx
vmovd rax, xmm0
vmovd xmm0, rcx |
@tannergooding, please check the generated encoding with .NET 9 above (#11413 (comment)).
cc @dotnet/jit-contrib |
This got resolved some time back (#71567, as well as other commits by other JIT team members) The |
Very good.
Also checked mov eax, dword ptr [ebp+0x08] |
on x86, vmovd xmm0, ecx
vmovss dword ptr [ebp-0x04], xmm0
fld dword ptr [ebp-0x04]
vmovsd xmm0, qword ptr [ebp+0x08]
sub esp, 8
vmovsd qword ptr [esp], xmm0
call [System.BitConverter:DoubleToInt64Bits(double):long]
push dword ptr [ebp+0x0C]
push dword ptr [ebp+0x08]
call [System.BitConverter:Int64BitsToDouble(long):double]
fstp qword ptr [ebp-0x08]
vmovsd xmm0, qword ptr [ebp-0x08]
vmovsd qword ptr [ebp-0x08], xmm0
fld qword ptr [ebp-0x08] |
👍 x86 is expected to be less efficient for There is notably a way to load a double directly to/from memory using a specialized memory only version of |
As per dotnet/coreclr#20788 (comment), using
BitConverter.SingleToInt32Bits
,BitConverter.Int32BitsToSingle
,BitConverter.DoubleToInt64Bits
, andBitConverter.Int64BitsToDouble
generates some "inefficient" code.Currently
BitConverter.SingleToInt32Bits
is generating:When it could generate:
Currently
BitConverter.Int32BitsToSingle
is generating:When it could generate:
The same logic applies to
double <-> long
, but using therax
register andvmovq
.movq xmm, [m64]
ormovq [m64], xmm
encodingcategory:cq
theme:casts
skill-level:intermediate
cost:medium
The text was updated successfully, but these errors were encountered: