struct with StructLayout(LayoutKind.Explicit) and EqualityComparer<TKey>.Default.Equals #93630
-
Given following simple struct union:
X64 Expected: 00007FF7E88683E9 mov eax,eax X64 Reality: 00007FF7E88683F1 mov eax,eax Removing Index1 and Index2 will deliver the expected result, but shouldn't "Key.Equals" depend on "value" only?
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
|
Beta Was this translation helpful? Give feedback.
-
Works fine in .NET8 :) |
Beta Was this translation helpful? Give feedback.
This isn't good advice. Bitcasting or reinterpreting a 2x ushort struct to an
int
(or vice versa) will generally not result in good codegen.@lakecherry is the code examples from .NET 7 or .NET 8? In .NET 8 we made improvements in this area, so the codegen might already be improved for you. In particular the JIT is able to reason about structs with overlapping fields if you aren't mixing accesses within the same function.