Inlining Code Test
Nick Voronin
elfy.nv at gmail.com
Fri Dec 17 16:24:48 PST 2010
I found this on bugzilla.
http://d.puremagic.com/issues/show_bug.cgi?id=2278
So it's not really a bug. Yet there is no simple workaround. And gap
between int and double looks strange when stack frame itself is unaligned.
btw, is there no explicit alignment for variables in D at all?
align(8) double d; compiles if d is global, but it does nothing.
import core.stdc.stdio: printf;
align(8) int a;
align(8) double d;
void main() {
printf("%u %u\n", (cast(size_t)&a) % 8, (cast(size_t)&d) % 8);
}
This _always_ prints "4 4" for me. It seems that globals are not affected
by environment, but not aligned anyway.
Honestly, I'm lost :) It all works not as expected but then again I can't
find any evidences that my expectations are valid.
On Sat, 18 Dec 2010 01:57:44 +0300, bearophile <bearophileHUGS at lycos.com>
wrote:
> Nick Voronin:
>
>> Looks like alignment of local variables is somewhat broken.
>
> This is a very nice bug. If not already present then please add it to
> Bugzilla. If you don't want to add it, then I will add it myself. I have
> modified your code like this:
>
> import core.stdc.stdio: printf;
> void main() {
> int a;
> double d;
> printf("%u %u\n", (cast(size_t)&a) % 8, (cast(size_t)&d) % 8);
> }
>
> And this shows the performance difference:
>
> import core.stdc.stdio: printf;
> import std.date: getUTCtime, ticksPerSecond;
> void main() {
> double d = 0.0;
> auto t0 = getUTCtime();
> for (size_t i = 0; i < 100_000_000; i++)
> d += 1;
> auto t1 = getUTCtime();
> printf("%lf\n", d);
> printf("%u\n", (cast(size_t)&d) % 8);
> printf("%lf\n", (cast(double)t1 - cast(double)t0) / ticksPerSecond);
> }
>
> Bye,
> bearophile
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
More information about the Digitalmars-d
mailing list