-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Concerns about x86-64 _BitInt(65-128)
alignment
#60925
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
Comments
@llvm/issue-subscribers-backend-x86 |
cc @FreddyLeaf |
Indeed, Clang correctly believes Also see: |
Related: in D86310, an issue is raised that results from |
It is my understanding that currently, for the System V AMD64 ABI specification of
_BitInt(65-128)
, it has an alignment of only 8, whereas__int128
has an alignment of 16. If I remember correctly, since both are specified to be "as if a struct of 8bytes", this has no consequence for the raw by-value case for functions with a few parameters. However, in the presence of many arguments, this means that it will hit the stack, and that it will be passed differently than__int128
on the stack. It also means that if an allocation attempts to align itself to_BitInt(128)
, it is incorrectly aligned for__int128
, whereas__int128
is correctly (over)aligned for_BitInt(128)
allocations.I have a concern about cross-language, and even, to some extent, assembly-code interoperability. A lack of 16-byte alignment means the type is incorrectly aligned using as a target of CMPXCHG16B's all-important m128 operand which must be 16-byte aligned (an indicator of a 128-bit value at a memory address, not to be confused with
__m128
, which only prefers it for VEX encodings, except for VMOVAPS, but also the legacy SSE encodings still exist). It also means that any other programming language must double-up on types in order to do C FFI for such 16-byte types, whereas in some cases they may already have such types (and may want to already be able to use it for__int128
). Obviously, the C Standard doesn't guarantee other languages won't need them anyways, but it still seems preferable if more implementations choose the form which has the largest aligned integer type match_BitInt(N)
, even if merely for principle-of-least-astonishment reasons, and to help other compiler implementers down the road.Obviously, we still need a stopping point somewhere. I only suggest it here as it's already a specified large integer type. The stack is 16-byte-aligned anyways, too.
I am aware that this decision is ultimately also something that requires the attention of the people who specified the psABI, and I have raised this as an issue with them. I am mentioning it to you, here, because I wish to make sure this concern is factored in to the release of LLVM 16, and because Clang is the pioneer of this implementation.
The text was updated successfully, but these errors were encountered: