Thread overview | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
October 18, 2010 struct field alignment | ||||
---|---|---|---|---|
| ||||
http://www.digitalmars.com/d/2.0/attribute.html#align Over time, it has become clear to me that there are only two useful alignments: align // set to whatever the C ABI alignment is align(1) // pack everything in, no alignment padding I think any other alignments should be deprecated. Note that with align(1), any alignment is achievable simply by adding in byte fields where desired. |
October 18, 2010 Re: struct field alignment | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Hello Walter, > http://www.digitalmars.com/d/2.0/attribute.html#align > > Over time, it has become clear to me that there are only two useful > alignments: > > align // set to whatever the C ABI alignment is > align(1) // pack everything in, no alignment padding > I think any other alignments should be deprecated. Note that with > align(1), any alignment is achievable simply by adding in byte fields > where desired. > If that's the case, then having a number in there seems silly: how about align and pack? -- ... <IXOYE>< |
October 18, 2010 Re: struct field alignment | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Mon, 18 Oct 2010 06:00:49 +0400, Walter Bright <newshound2@digitalmars.com> wrote:
> http://www.digitalmars.com/d/2.0/attribute.html#align
>
> Over time, it has become clear to me that there are only two useful alignments:
>
> align // set to whatever the C ABI alignment is
> align(1) // pack everything in, no alignment padding
>
> I think any other alignments should be deprecated. Note that with align(1), any alignment is achievable simply by adding in byte fields where desired.
On some platforms it is desired to align struct Vec { float[4] data; } on 16 bytes. I don't recall why now, but I know for sure we do that for all platforms (other than PC maybe). I guess that has something to do with vector operations.
Bikeshed note: how about align(C) to be consistent with both align(1) and extern(C)?
|
October 18, 2010 Re: struct field alignment | ||||
---|---|---|---|---|
| ||||
Posted in reply to Denis Koroskin | Hello Denis, > On some platforms it is desired to align struct Vec { float[4] data; } > on 16 bytes. At a guess, that is aligning the structure in memory, not the members in the struct. I think the 2nd is the question here. > Bikeshed note: how about align(C) to be consistent with both align(1) > and extern(C)? > vote++; -- ... <IXOYE>< |
October 18, 2010 Re: struct field alignment | ||||
---|---|---|---|---|
| ||||
Posted in reply to BCS | BCS wrote:
> If that's the case, then having a number in there seems silly: how about align and pack?
Another keyword.
|
October 18, 2010 Re: struct field alignment | ||||
---|---|---|---|---|
| ||||
Posted in reply to BCS | On Mon, 18 Oct 2010 06:22:32 +0400, BCS <none@anon.com> wrote: > Hello Denis, > >> On some platforms it is desired to align struct Vec { float[4] data; } >> on 16 bytes. > > At a guess, that is aligning the structure in memory, not the members in the struct. I think the 2nd is the question here. > Yes, I was talking about stack alignment. >> Bikeshed note: how about align(C) to be consistent with both align(1) >> and extern(C)? >> > > vote++; > > align(default) could also work. |
October 18, 2010 Re: struct field alignment | ||||
---|---|---|---|---|
| ||||
Posted in reply to Denis Koroskin | Denis Koroskin wrote: > On some platforms it is desired to align struct Vec { float[4] data; } on 16 bytes. I don't recall why now, but I know for sure we do that for all platforms (other than PC maybe). I guess that has something to do with vector operations. I was thinking of special casing such arrays to be 16 byte aligned by default. > Bikeshed note: how about align(C) to be consistent with both align(1) and extern(C)? align is shorter than align(C). |
October 18, 2010 Re: struct field alignment | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Sun, 17 Oct 2010 22:00:49 -0400, Walter Bright <newshound2@digitalmars.com> wrote:
> http://www.digitalmars.com/d/2.0/attribute.html#align
>
> Over time, it has become clear to me that there are only two useful alignments:
>
> align // set to whatever the C ABI alignment is
> align(1) // pack everything in, no alignment padding
>
> I think any other alignments should be deprecated. Note that with align(1), any alignment is achievable simply by adding in byte fields where desired.
I mainly do GP-GPU work using NVIDIA's CUDA + D. Passing data into and out of the GPU requires conforming to align(8) and align(16) structs as well as structs that contain align(8)/align(16) structs. At first, I tried using align(8)/align(16) + .alignof, only to find out that those weren't supported. Currently, I use an enum flag and a bunch of packing/unpacking routines in order to send/access data. Maintaining the correct alignment with composite structs manually is a difficult/brittle endeavor; its fine for interfacing with a stable code base, but not for development where things are constantly changing. Also, CUDA requires that the programmer maintain the proper function call alignment, adding another place where one has to remember to pad correctly.
Although I have a solution that works well for me, the one thing I lament about not having a canonical D way of expression align(8)/align(16), even at only a meta-information level, is that if phobos gets a small vector library, I can't use it and conversely I'm not motivated to improve/submit my own small vector library to phobos.
|
October 18, 2010 Re: struct field alignment | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert Jacques | Robert Jacques wrote:
> Although I have a solution that works well for me, the one thing I lament about not having a canonical D way of expression align(8)/align(16), even at only a meta-information level, is that if phobos gets a small vector library, I can't use it and conversely I'm not motivated to improve/submit my own small vector library to phobos.
I'm painfully aware that align(8)/(16) don't work on the 32 bit targets. I've been reluctant to fix that because it involves some performance degradation (keeping the stack so aligned requires the insertion of stack adjustment instructions here and there).
With the 64 bit target, however, the C ABI will force the issue. It'll support those alignments.
|
October 18, 2010 Re: struct field alignment | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Sunday 17 October 2010 20:07:26 Walter Bright wrote:
> Denis Koroskin wrote:
> > On some platforms it is desired to align struct Vec { float[4] data; } on 16 bytes. I don't recall why now, but I know for sure we do that for all platforms (other than PC maybe). I guess that has something to do with vector operations.
>
> I was thinking of special casing such arrays to be 16 byte aligned by default.
>
> > Bikeshed note: how about align(C) to be consistent with both align(1)
> > and extern(C)?
>
> align is shorter than align(C).
It would be clearer though.
- Jonathna M Davis
|
Copyright © 1999-2021 by the D Language Foundation