GithubHelp home page GithubHelp logo

Comments (2)

siegfriedpammer avatar siegfriedpammer commented on May 27, 2024

If you add the instruction bytes to the IL output, (The setting can be found in Settings > Display > Decompilation view options > last checkbox).

.method /* 06003173 */ public hidebysig static 
	int32 ReadInt32BigEndian (
		valuetype System.ReadOnlySpan`1<uint8> source
	) cil managed aggressiveinlining 
{
	// Method begins at RVA 0x64c5d4
	// Header size: 1
	// Code size: 19 (0x13)
	.maxstack 8

	/* 0x0064C5D5 7E78030004         */ IL_0000: ldsfld bool System.BitConverter::IsLittleEndian /* 04000378 */
	/* 0x0064C5DA 2D00               */ IL_0005: brtrue.s IL_0007

	/* 0x0064C5DC 02                 */ IL_0007: ldarg.0
	/* 0x0064C5DD 284704002B         */ IL_0008: call !!0 System.Runtime.InteropServices.MemoryMarshal::Read<int32>(valuetype System.ReadOnlySpan`1<uint8>) /* 2B000447 */
	/* 0x0064C5E2 2865310006         */ IL_000d: call int32 System.Buffers.Binary.BinaryPrimitives::ReverseEndianness(int32) /* 06003165 */
	/* 0x0064C5E7 2A                 */ IL_0012: ret
} // end of method BinaryPrimitives::ReadInt32BigEndian

You will see that the bytes of the instruction are 0x2D00, where 0x2D is the opcode for brtrue.s:

image
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.

from ilspy.

siegfriedpammer avatar siegfriedpammer commented on May 27, 2024

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?

from ilspy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.