primitive vector types

Don nospam at nospam.com
Thu Feb 19 23:56:56 PST 2009


Daniel Keep wrote:
> 
> Jarrett Billingsley wrote:
>> On Thu, Feb 19, 2009 at 9:31 PM, Daniel Keep
>> <daniel.keep.lists at gmail.com> wrote:
>>>> struct float4
>>>> {
>>>>     __align(16) float[4] data; // right syntax and value?
>>>>     alias data this;
>>>> }
>>> 1. The alignment thing.  Incidentally, I just did a quick check and
>>> don't see any notes in the changelog about __align(n) syntax.  As I
>>> remember, there was no way to actually ensure the data was properly
>>> aligned.  (There's "Data items in static data segment >= 16 bytes in
>>> size are now paragraph aligned." but that doesn't help when the vectors
>>> are on, say, the stack or in the heap.)
>> It's just align(16).
>>
>> http://www.digitalmars.com/d/1.0/attribute.html#align
> 
> Yeah, except it doesn't do what you want in this case.  For example:
> 
> 
> module alignment;
> 
> import tango.io.Stdout;
> 
> struct float4
> {
>     align(16) float[4] data;
> }
> 
> void main()
> {
>     float4 a;
>     byte b;
>     float4 c;
> 
>     Stdout.format("a @ {0} & 0xF == {1}", &a, cast(size_t)&a & 0xF).newline;
>     Stdout.format("c @ {0} & 0xF == {1}", &c, cast(size_t)&c & 0xF).newline;
> }
> 
> 
> 
> Output is:
> 
> a @ 12fe68 & 0xF == 8
> c @ 12fe78 & 0xF == 8
> 
> 
> 
> The only way I found of guaranteeing alignment was to allocate all
> vectors on the heap, using a custom allocator to allocate an extra 15
> bytes and then align the result appropriately.  Obviously, for 16-byte
> vectors, this is completely unacceptable.
> 
>   -- Daniel

http://d.puremagic.com/issues/show_bug.cgi?id=2278



More information about the Digitalmars-d mailing list