[Issue 2278] Guarantee alignment of stack-allocated variables on x86

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Dec 17 18:12:22 PST 2010


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



--- Comment #7 from Nick Voronin <elfy.nv at gmail.com> 2010-12-17 18:10:27 PST ---
In D2 on entering main() stack may or may not be aligned to 8 bytes depending
on length of command line with which program was ran. This may cause as much as
x2 difference with no apparent reason for it. (Lack of alignment is a pity, but
this particular case is plainly confusing).

Example. Run with different command lines, for example with and without
extension.

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);
}

Also this code shows that inside a frame variables are placed as if stack
alignment was expected. (note that a & d are either both aligned on 8 or both
unaligned)

import core.stdc.stdio: printf;

void main() {
    int a;
    double d;
    printf("%X:%u %X:%u\n", &a, (cast(size_t)&a) % 8, &d, (cast(size_t)&d) %
8);
}

Also +1 for some way to have locals aligned, be it explicit align(n) before
declaration of var, or before function (I like this one), or throughout whole
program.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list