Skip to content
Discussion options

You must be logged in to vote

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.

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@lakecherry
Comment options

@jakobbotsch
Comment options

Answer selected by lakecherry
@lakecherry
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants