Skip to content

Conversation

JeffBezanson
Copy link
Member

@JeffBezanson JeffBezanson commented Apr 14, 2023

I believe our use of MAX_ALIGN in jl_new_primitivetype already computes the right alignment. This is intended to implement the C23 ABI for _BitInt.

fixes #49318

@test sizeof(Tuple{UInt24}) == 4
@test Base.datatype_haspadding(Tuple{UInt24})
@test sizeof(UInt136) == 17
@test sizeof(Tuple{UInt136}) == 24
Copy link
Contributor

@Seelengrab Seelengrab Apr 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On 32 bit, I'd expect this to only be 20, since the base register size is only 32 bits there. Aligning 136 to the next largest multiple of 32 is 160, or 20 bytes.

EDIT: This is also the cause for the test failure here on CI:

https://buildkite.com/julialang/julia-master/builds/22859#01878096-0a77-40eb-a2f7-3dfe35aacae4/753-827

This is the core issue with #49318 (and other padding related issues) - they are architecture specific. Conversely, on AVR sizeof(Tuple{UInt136}) ought to return 17 again (so no padding), due to the base register size there being single bytes (the code in this PR should do this, as far as I can tell - it's just the test that should be architecture specific as well).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should likely reflect the vector register alignment requirements from the ABI, which is likely supposed to be double-word size here (aside from clang bugs).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At what size does the double-word alignment kick in?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clang compiler gets the ABI wrong, relative to other compilers and the standard in this. But i128 is supposed to be 128-bit aligned on most 64-bit platforms as an example (such as x86_64)

Copy link
Contributor

@Seelengrab Seelengrab Apr 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should likely reflect the vector register alignment requirements from the ABI, which is likely supposed to be double-word size here (aside from clang bugs).

Are you saying an i136 should end up effectively 256 bit aligned on x86_64..? And presumably that too on x86?

The clang compiler gets the ABI wrong, relative to other compilers and the standard in this.

How does it get it wrong? On 64 bit, i128 is supposed to be aligned to 2*64 = 128 already. On 32 bit, it's aligned to 4*32 = 128 as well, if I'm reading the standard right. Is that not what clang is already doing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By not having it set at all, clang kinda gets it right because they hard coded a fix somewhere, but LLVM in general gets it wrong. Fixing it is very easy, but it's an ABI break which is really annoying to handle.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have

#  elif defined(_CPU_AARCH64_)
// int128 is 16 bytes aligned on aarch64
#    define MAX_ALIGN 16

and 8 on other 64-bit systems. Should we change that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in this PR, but we are tracking that in another issue already

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's #42326 specifically

@vtjnash
Copy link
Member

vtjnash commented Jun 21, 2023

Error in testset compiler/codegen:
Test Failed at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-macmini-aarch64-5.0/build/default-macmini-aarch64-5-0/julialang/julia-master/julia-4100322b07/share/julia/test/compiler/codegen.jl:554
  Expression: sizeof(Tuple{UInt136}) == 24
   Evaluated: 32 == 24

@gbaraldi gbaraldi closed this in 1b0b028 May 19, 2025
@giordano giordano deleted the jb/fix49318 branch May 19, 2025 15:17
KristofferC pushed a commit that referenced this pull request May 20, 2025
#58435)

This is caused because for LLVMs sake we have to say that the oddly
typed field is smaller than it actually is. (I wonder if we could
represent it as an iN field in a struct and have it work but the result
would be the same for now)

Fix #58434, fix #49318, close #49362.

---------

Co-authored-by: Mosè Giordano <[email protected]>
Co-authored-by: Sukera <[email protected]>
(cherry picked from commit 1b0b028)
KristofferC pushed a commit that referenced this pull request Jun 25, 2025
#58435)

This is caused because for LLVMs sake we have to say that the oddly
typed field is smaller than it actually is. (I wonder if we could
represent it as an iN field in a struct and have it work but the result
would be the same for now)

Fix #58434, fix #49318, close #49362.

---------

Co-authored-by: Mosè Giordano <[email protected]>
Co-authored-by: Sukera <[email protected]>
(cherry picked from commit 1b0b028)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent claims about padding in structs
4 participants