You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The instruction at IL_0005: brtrue.s IL_0007 doesn't seem right to me... but I'm a bit rusty on my IL right now.
ILSpy disassembles this to:
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int ReadInt32BigEndian(ReadOnlySpan<byte> source)
{
if (!BitConverter.IsLittleEndian)
{
}
return BinaryPrimitives.ReverseEndianness(MemoryMarshal.Read<int>(source));
}
You will see that the bytes of the instruction are 0x2D00, where 0x2D is the opcode for brtrue.s:
Taken from ECMA-335, 6th edition, June 2012, page 297
and 0x00 is the relative offset to jump to, which basically is "don't jump at all".
Not sure what the C# compiler is trying to do, but it seems pointless. I don't think ILSpy is at fault here. Probably some branch optimization gone wrong in the compiler.
Converter.IsLittleEndian is marked with an IntrinsicAttribute, so it seems there is something special going on. May I ask you to open a discussion on the dotnet/runtime repo?
Input code
System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
(.NET 7 SDK 7.0.13)C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.13\System.Private.CoreLib.dll
System.Buffers.Binary.BinaryPrimitives
ReadInt32BigEndian
The instruction at
IL_0005: brtrue.s IL_0007
doesn't seem right to me... but I'm a bit rusty on my IL right now.ILSpy disassembles this to:
The actual C# source is:
Details
The text was updated successfully, but these errors were encountered: