Skip to content

BinaryPrimitives endianness-specific methods contain confusing branches #74892

Answered by huoyaoyuan
siegfriedpammer asked this question in Q&A
Discussion options

You must be logged in to vote
  • Is MethodImplOptions.AggressiveInlining honored by Roslyn?

No, it's for JIT.

BitConverter.IsLittleEndian is marked with the IntrinsicAttribute but that doesn't seem to change Roslyn's behavior...

[Intrinsic] is for JIT and roslyn know nothing about it.
In fact, roslyn can't even see the [Intrinsic] or [MethodImplOptions.AggressiveInlining] attributes since they are only present in implementation, not the reference assembly.

IL is expected to contain calls and branches around intrinsic functions. They will be constant folded by JIT.

You should view JIT asm in sharplab. There's only one branch for range checking in this case.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@siegfriedpammer
Comment options

Answer selected by siegfriedpammer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants