[Issue 859] Improve compiler inlining
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jul 8 05:10:35 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=859
bearophile_hugs at eml.cc changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bearophile_hugs at eml.cc
--- Comment #6 from bearophile_hugs at eml.cc 2010-07-08 05:10:27 PDT ---
An improved version of the test program, that allows to compare dmd and ldc on
this inlining problem:
version (Tango) {
import tango.stdc.stdio: printf;
import tango.stdc.stdlib: atof;
} else {
import std.c.stdio: printf;
import std.c.stdlib: atof;
}
struct Vec3 {
float x, y, z;
}
float dot(Vec3 A, Vec3 B) {
return A.x * B.x + A.y * B.y + A.z * B.z;
}
struct Timer {
long starttime;
static long getTime() {
asm {
naked;
rdtsc;
ret;
}
}
void start() {
starttime = getTime();
}
void stop() {
long endTime = getTime();
printf("time: %lld\n", endTime - starttime);
}
}
void main() {
int n = 30_000;
Vec3 a = Vec3(atof("1.0"), atof("2.0"), atof("3.0"));
Vec3 b = Vec3(atof("4.0"), atof("5.0"), atof("6.0"));
Timer t;
float sum;
printf(" Auto inlined ");
sum = 0.0;
t.start();
for (int i; i < n; i++) {
a.x++;
a.y++;
a.z++;
sum += dot(a, b);
}
t.stop();
printf("sum: %f\n", sum);
printf("Manually inlined ");
sum = 0.0;
t.start();;
for (int i; i < n; i++) {
a.x++;
a.y++;
a.z++;
sum += a.x * b.x + a.y * b.y + a.z * b.z;
}
t.stop();
printf("sum: %f\n", sum);
}
--
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