aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorPatrick Walton <[email protected]>2011-03-26 23:06:06 -0700
committerPatrick Walton <[email protected]>2011-03-26 23:10:28 -0700
commit9c5affda1a17532109f919df954ee743b850544e (patch)
tree82192e769852e81b943992b592e4428c92c965b5 /src/test
parentTwiddle visibility, start exposing only type-mangled names (64 bit truncated ... (diff)
downloadrust-9c5affda1a17532109f919df954ee743b850544e.tar.xz
rust-9c5affda1a17532109f919df954ee743b850544e.zip
shootout: Hoist out the vector indexing on nbody; don't rely on LICM, which isn't working for some reason (insufficient alias info?) Speeds up nbody a bit.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/bench/shootout/nbody.rs40
1 files changed, 21 insertions, 19 deletions
diff --git a/src/test/bench/shootout/nbody.rs b/src/test/bench/shootout/nbody.rs
index 9df439f2..06f8998a 100644
--- a/src/test/bench/shootout/nbody.rs
+++ b/src/test/bench/shootout/nbody.rs
@@ -70,26 +70,8 @@ mod NBodySystem {
while (i < 5) {
let int j = i+1;
while (j < 5) {
- let float dx = bodies.(i).x - bodies.(j).x;
- let float dy = bodies.(i).y - bodies.(j).y;
- let float dz = bodies.(i).z - bodies.(j).z;
-
- let float dSquared = dx * dx + dy * dy + dz * dz;
-
- let float distance;
- rustrt.squareroot(dSquared, distance);
- let float mag = dt / (dSquared * distance);
-
- bodies.(i).vx -= dx * bodies.(j).mass * mag;
- bodies.(i).vy -= dy * bodies.(j).mass * mag;
- bodies.(i).vz -= dz * bodies.(j).mass * mag;
-
- bodies.(j).vx += dx * bodies.(i).mass * mag;
- bodies.(j).vy += dy * bodies.(i).mass * mag;
- bodies.(j).vz += dz * bodies.(i).mass * mag;
-
+ advance_one(bodies.(i), bodies.(j), dt);
j += 1;
-
}
i += 1;
@@ -106,6 +88,26 @@ mod NBodySystem {
}
}
+ fn advance_one(&Body.props bi, &Body.props bj, float dt) {
+ let float dx = bi.x - bj.x;
+ let float dy = bi.y - bj.y;
+ let float dz = bi.z - bj.z;
+
+ let float dSquared = dx * dx + dy * dy + dz * dz;
+
+ let float distance;
+ rustrt.squareroot(dSquared, distance);
+ let float mag = dt / (dSquared * distance);
+
+ bi.vx -= dx * bj.mass * mag;
+ bi.vy -= dy * bj.mass * mag;
+ bi.vz -= dz * bj.mass * mag;
+
+ bj.vx += dx * bi.mass * mag;
+ bj.vy += dy * bi.mass * mag;
+ bj.vz += dz * bi.mass * mag;
+ }
+
fn energy(vec[Body.props] bodies) -> float {
let float dx;
let float dy;