Thread overview
Struct's alignment
Aug 10, 2013
Temtaime
Aug 10, 2013
Temtaime
Aug 10, 2013
Manfred Nowak
Aug 10, 2013
novice2
Aug 10, 2013
bearophile
Aug 13, 2013
Kapps
August 10, 2013
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.
August 10, 2013
Sorry, not class, but struct.
August 10, 2013
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

August 10, 2013
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
August 10, 2013
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
August 13, 2013
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.