-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adjust the usage of ReverseEndianness in BinaryPrimitives #69063
Conversation
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
Diffs
Detail diffs
Regressions are due to different register allocation and decisions to inline more methods. Some methods show up as regression due to #66965 (comment) |
Tagging subscribers to this area: @dotnet/area-system-buffers Issue DetailsFollow up on #66965 Adjusts the usage of ReverseEndianness in BinaryPrimitives to allow the JIT to recognize the pattern and optimize them to
|
} | ||
return result; | ||
return BitConverter.IsLittleEndian ? | ||
ReverseEndianness(MemoryMarshal.Read<short>(source)) : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The JIT is reordering the IR so that the ReverseEndianness
occurs directly over the Unsafe.ReadUnaligned
and emitting just movbe reg, [addr]
? The throw helpers/checks and inlining boundaries aren't getting in the way here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thats the case. We end up generating:
mov rax, bword ptr [rcx]
mov ecx, dword ptr [rcx+8]
cmp ecx, 4
jl SHORT G_M53413_IG04
movbe eax, dword ptr [rax]
Follow up on #66965
Adjusts the usage of ReverseEndianness in BinaryPrimitives to allow the JIT to recognize the pattern and optimize them to
movbe