-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
type alignment declaration #2555
Comments
cc @pao (I'll just borrow whatever you come up with in StrPack.jl.) |
I believe the syntax type X
a :: Int32 @0 # field .a is 32 bits and starts at offset 0
b :: Int32 @128 # field .b is 32 bits and starts at offset 128
c1 :: Uint16 @128 # field .c1 is 16 bits and starts at offset 128
c2 :: Uint16 @144 # field .c2 is 16 bits and starts at offset 144
_ :: None @192 # total struct size is at least 192 bits
end |
Would @ not interfere with the macro pass - or can the parser do this? As an alternative, |
The @ sign syntax looks good to me, if it doesn't interfere with macro parsing. Also type X
a :: Int32 :: -64 # field .a is 32 bits and starts at first non-overlapping byte index, required alignment of 64 bits
b :: Int32 :: 128 # field .b is 32 bits and starts at offset 128
c1 :: Uint16 :: 128 # field .c1 is 16 bits and starts at offset 128
c2 :: Uint16 :: 144 # field .c2 is 16 bits and starts at offset 144
_ :: None :: 192 # total struct size is at least 192 bits
end |
|
+1 for Stefan's |
I imagine one would want to define integer constants for the alignment, and then refer to these constants when specifying the alignment. This would e.g. allow defining several types with identical alignment, or using This would not work well with the |
I was just checking to see if Julia already had something like this, not just to control alignment in a structure, but of the structure itself... this is very important if you need to lay things out so that they are on cache-line boundaries (usually 32 for ARM, 64 for Intel/AMD..., 128 for POWER). |
@ScottPJones I don't think Julia can control the alignment of objects, but wouldn't that be needed as well as internal organisation to ensure cache alignment? |
Julia allocates all of the memory for objects, so it can align allocations. As far as global objects (which I am also interested in aligning, C can do this with the |
Yes, what I meant is that Julia code doesn't have any way of specifying a required object alignment to its allocators, as you said "that information must be passed on to LLVM somehow". |
It's perhaps worth pointing out that the gcc alignment attribute tells the compiler to assume the address is aligned, but does not guarantee alignment. For example the gcc docs suggest it may only provide int alignment. Also: http://stackoverflow.com/questions/1468513/attribute-aligned-not-working-with-static-variables |
@vtjnash that SO points the finger at the system linker as the actual problem, but being JITed, does Julia actually use the system linker? |
closing in favor of #15244 |
I am soliciting syntax ideas for alignment contraints on types (if Jeff approves). Below is one proposal:
Additionally, we may want to be able to specify absolute offsets:
The text was updated successfully, but these errors were encountered: