www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Struct's alignment

reply "Temtaime" <temtaime gmail.com> writes:
Hello, guys!

I have Matrix class(that contains an array of 16 floats) and SSE 
code to mult it.
It's neccessary to have an array alignment 16.

I'm figured out simple test-code:

align(16) struct S {
	align(16) int a;
}


void main() {
	align(16) S s;
	writeln(cast(void *)&s.a);
}

And it prints 18FCC8, but must ends with "0". What i'm doing 
wrong?

Thanks.
Aug 10 2013
next sibling parent "Temtaime" <temtaime gmail.com> writes:
Sorry, not class, but struct.
Aug 10 2013
prev sibling next sibling parent Manfred Nowak <svv1999 hotmail.com> writes:
Temtaime wrote:
 What i'm doing wrong?
Maybey nothing than thinking---that the adress is printed in the number of bits, whereas it is printed in the number of bytes. -manfred
Aug 10 2013
prev sibling next sibling parent "novice2" <sorry noem.ail> writes:
i guess, because of allocated on stack:

import std.stdio;

align(16) struct S
{
   align(16) int a;
}

S sGlobal;

void main()
{
   S sLocal;
   writefln("0x%08X 0x%08X", cast(uint) &sGlobal, cast(uint) 
&sLocal);
}

0x00162110 0x0012FE14

but, IMHO, this is not good
Aug 10 2013
prev sibling next sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
Related?
http://d.puremagic.com/issues/show_bug.cgi?id=2278

Perhaps related:
http://forum.dlang.org/thread/mailman.990.1370788529.13711.digitalmars-d-ldc puremagic.com?page=3#post-pecxybsbjdsnuljtyqjm:40forum.dlang.org

Bye,
bearophile
Aug 10 2013
prev sibling parent "Kapps" <opantm2+spam gmail.com> writes:
On Saturday, 10 August 2013 at 20:36:24 UTC, Temtaime wrote:
 Hello, guys!

 I have Matrix class(that contains an array of 16 floats) and 
 SSE code to mult it.
 It's neccessary to have an array alignment 16.

 I'm figured out simple test-code:

 align(16) struct S {
 	align(16) int a;
 }


 void main() {
 	align(16) S s;
 	writeln(cast(void *)&s.a);
 }

 And it prints 18FCC8, but must ends with "0". What i'm doing 
 wrong?

 Thanks.
Perhaps core.simd (http://dlang.org/phobos/core_simd.html) could be of help. I believe that those types should be aligned.
Aug 13 2013