As per dotnet/coreclr#20788 (comment), using BitConverter.SingleToInt32Bits, BitConverter.Int32BitsToSingle, BitConverter.DoubleToInt64Bits, and BitConverter.Int64BitsToDouble generates some "inefficient" code.
Currently BitConverter.SingleToInt32Bits is generating:
vmovss dword ptr [rsp+14H], xmm0
mov eax, dword ptr [rsp+14H]
When it could generate:
Currently BitConverter.Int32BitsToSingle is generating:
mov dword ptr [rsp+0CH], eax
vmovss xmm0, dword ptr [rsp+0CH]
When it could generate:
The same logic applies to double <-> long, but using the rax register and vmovq.
- For x86, it can use the
movq xmm, [m64] or movq [m64], xmm encoding
category:cq
theme:casts
skill-level:intermediate
cost:medium
As per dotnet/coreclr#20788 (comment), using
BitConverter.SingleToInt32Bits,BitConverter.Int32BitsToSingle,BitConverter.DoubleToInt64Bits, andBitConverter.Int64BitsToDoublegenerates some "inefficient" code.Currently
BitConverter.SingleToInt32Bitsis generating:When it could generate:
Currently
BitConverter.Int32BitsToSingleis generating:When it could generate:
The same logic applies to
double <-> long, but using theraxregister andvmovq.movq xmm, [m64]ormovq [m64], xmmencodingcategory:cq
theme:casts
skill-level:intermediate
cost:medium