Align a variable on the stack.
TheFlyingFiddle via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Nov 5 13:22:16 PST 2015
On Thursday, 5 November 2015 at 11:14:50 UTC, Marc Schütz wrote:
> On Thursday, 5 November 2015 at 03:52:47 UTC, TheFlyingFiddle
> wrote:
> Can you publish two compilable and runnable versions of the
> code that exhibit the difference? Then we can have a look at
> the generated assembly. If there's really different code being
> generated depending on whether the .init value is explicitly
> set to float.nan or not, then this suggests there is a bug in
> DMD.
I created a simple example here:
struct A { float x, y, z ,w; }
struct B
{
float x=float.nan;
float y=float.nan;
float z=float.nan;
float w=float.nan;
}
void initVal(T)(ref T t, ref float k)
{
pragma(inline, false);
t.x = k;
t.y = k * 2;
t.z = k / 2;
t.w = k^^3;
}
__gshared A[] a;
void benchA()
{
A val;
foreach(float f; 0 .. 1000_000)
{
val = A.init;
initVal(val, f);
a ~= val;
}
}
__gshared B[] b;
void benchB()
{
B val;
foreach(float f; 0 .. 1000_000)
{
val = B.init;
initVal(val, f);
b ~= val;
}
}
int main(string[] argv)
{
import std.datetime;
import std.stdio;
auto res = benchmark!(benchA, benchB)(1);
writeln("Default: ", res[0]);
writeln("Explicit: ", res[1]);
return 0;
}
output:
Default: TickDuration(1637842)
Explicit: TickDuration(167088)
~10x slowdown...
More information about the Digitalmars-d-learn
mailing list