Closed
Description
Here two functions do the same thing but their codegen is different:
public static void WriteBigEndian128_1(ulong hi, ulong lo, Span<byte> destination)
{
if (destination.Length < 16)
return;
Span<byte> destHi = destination.Slice(0, 8);
Span<byte> destLo = destination.Slice(8, 8);
BinaryPrimitives.WriteUInt64BigEndian(destLo, lo);
BinaryPrimitives.WriteUInt64BigEndian(destHi, hi);
}
public static void WriteBigEndian128_2(ulong hi, ulong lo, Span<byte> destination)
{
if (destination.Length >= 16)
{
Span<byte> destHi = destination.Slice(0, 8);
Span<byte> destLo = destination.Slice(8, 8);
BinaryPrimitives.WriteUInt64BigEndian(destLo, lo);
BinaryPrimitives.WriteUInt64BigEndian(destHi, hi);
}
}
; Method Benchmarks:WriteBigEndian128_1(ulong,ulong,System.Span`1[ubyte]) (FullOpts)
G_M15399_IG01:
sub rsp, 40
G_M15399_IG02:
mov rax, bword ptr [r8]
mov r8d, dword ptr [r8+0x08]
cmp r8d, 16
jl SHORT G_M15399_IG04
G_M15399_IG03:
cmp r8d, 8
jl SHORT G_M15399_IG05
lea r8, bword ptr [rax+0x08]
bswap rdx
mov qword ptr [r8], rdx
bswap rcx
mov qword ptr [rax], rcx
G_M15399_IG04:
add rsp, 40
ret
G_M15399_IG05:
call [System.ThrowHelper:ThrowArgumentOutOfRangeException()]
int3
; Total bytes of code: 51
; Method Benchmarks:WriteBigEndian128_2(ulong,ulong,System.Span`1[ubyte]) (FullOpts)
G_M24932_IG01:
G_M24932_IG02:
mov rax, bword ptr [r8]
mov r8d, dword ptr [r8+0x08]
cmp r8d, 16
jl SHORT G_M24932_IG04
G_M24932_IG03:
lea r8, bword ptr [rax+0x08]
bswap rdx
mov qword ptr [r8], rdx
bswap rcx
mov qword ptr [rax], rcx
G_M24932_IG04:
ret
; Total bytes of code: 30
cc @AndyAyersMS @dotnet/jit-contrib