Compare n-body to asmjs and js

This commit is contained in:
dcodeIO 2018-04-23 15:04:04 +02:00
parent 80d104201c
commit 78a3dcfaf0
10 changed files with 4285 additions and 3390 deletions

View File

@ -120,7 +120,7 @@ class NBodySystem {
let dz = iz - bodyj.z;
let distanceSq = dx * dx + dy * dy + dz * dz;
let distance = sqrt(distanceSq);
let distance = Math.sqrt(distanceSq);
let mag = dt / (distanceSq * distance);
let bim = bodyim * mag;
@ -170,7 +170,7 @@ class NBodySystem {
let dx = ix - bodyj.x;
let dy = iy - bodyj.y;
let dz = iz - bodyj.z;
let distance = sqrt(dx * dx + dy * dy + dz * dz);
let distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
e -= bim * bodyj.mass / distance;
}
}
@ -178,17 +178,21 @@ class NBodySystem {
}
}
var bodies = new Array<Body>();
bodies.push(Sun());
bodies.push(Jupiter());
bodies.push(Saturn());
bodies.push(Uranus());
bodies.push(Neptune());
var system: NBodySystem;
var system = new NBodySystem(bodies);
export function init(): void {
var bodies = new Array<Body>();
bodies.push(Sun());
bodies.push(Jupiter());
bodies.push(Saturn());
bodies.push(Uranus());
bodies.push(Neptune());
system = new NBodySystem(bodies);
}
export function getBody(index: i32): Body | null {
return index < bodies.length ? bodies[index] : null;
var bodies = system.bodies;
return <u32>index < <u32>bodies.length ? bodies[index] : null;
}
export function step(): f64 {
@ -196,7 +200,6 @@ export function step(): f64 {
return system.energy();
}
export function bench(steps: i32): f64 {
for (let i = 0; i < steps; i++) system.advance(0.01);
return system.energy();
export function bench(steps: u32): void {
for (let i: u32 = 0; i < steps; i++) system.advance(0.01);
}

View File

@ -1,5 +1,5 @@
{
"extends": "../../../std/assembly.d.ts",
"extends": "../../../std/assembly.json",
"include": [
"./**/*.ts"
]

View File

@ -0,0 +1,142 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("allocator/arena");
const SOLAR_MASS = 4.0 * Math.PI * Math.PI;
const DAYS_PER_YEAR = 365.24;
class Body {
constructor(x, y, z, vx, vy, vz, mass) {
this.x = x;
this.y = y;
this.z = z;
this.vx = vx;
this.vy = vy;
this.vz = vz;
this.mass = mass;
}
offsetMomentum(px, py, pz) {
this.vx = -px / SOLAR_MASS;
this.vy = -py / SOLAR_MASS;
this.vz = -pz / SOLAR_MASS;
return this;
}
}
function Sun() {
return new Body(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, SOLAR_MASS);
}
function Jupiter() {
return new Body(4.84143144246472090e+00, -1.16032004402742839e+00, -1.03622044471123109e-01, 1.66007664274403694e-03 * DAYS_PER_YEAR, 7.69901118419740425e-03 * DAYS_PER_YEAR, -6.90460016972063023e-05 * DAYS_PER_YEAR, 9.54791938424326609e-04 * SOLAR_MASS);
}
function Saturn() {
return new Body(8.34336671824457987e+00, 4.12479856412430479e+00, -4.03523417114321381e-01, -2.76742510726862411e-03 * DAYS_PER_YEAR, 4.99852801234917238e-03 * DAYS_PER_YEAR, 2.30417297573763929e-05 * DAYS_PER_YEAR, 2.85885980666130812e-04 * SOLAR_MASS);
}
function Uranus() {
return new Body(1.28943695621391310e+01, -1.51111514016986312e+01, -2.23307578892655734e-01, 2.96460137564761618e-03 * DAYS_PER_YEAR, 2.37847173959480950e-03 * DAYS_PER_YEAR, -2.96589568540237556e-05 * DAYS_PER_YEAR, 4.36624404335156298e-05 * SOLAR_MASS);
}
function Neptune() {
return new Body(1.53796971148509165e+01, -2.59193146099879641e+01, 1.79258772950371181e-01, 2.68067772490389322e-03 * DAYS_PER_YEAR, 1.62824170038242295e-03 * DAYS_PER_YEAR, -9.51592254519715870e-05 * DAYS_PER_YEAR, 5.15138902046611451e-05 * SOLAR_MASS);
}
class NBodySystem {
constructor(bodies) {
var px = 0.0;
var py = 0.0;
var pz = 0.0;
var size = bodies.length;
for (let i = 0; i < size; i++) {
let b = bodies[i];
let m = b.mass;
px += b.vx * m;
py += b.vy * m;
pz += b.vz * m;
}
this.bodies = bodies;
this.bodies[0].offsetMomentum(px, py, pz);
}
advance(dt) {
var bodies = this.bodies;
var size = bodies.length;
for (let i = 0; i < size; ++i) {
let bodyi = bodies[i];
let ix = bodyi.x;
let iy = bodyi.y;
let iz = bodyi.z;
let bivx = bodyi.vx;
let bivy = bodyi.vy;
let bivz = bodyi.vz;
let bodyim = bodyi.mass;
for (let j = i + 1; j < size; ++j) {
let bodyj = bodies[j];
let dx = ix - bodyj.x;
let dy = iy - bodyj.y;
let dz = iz - bodyj.z;
let distanceSq = dx * dx + dy * dy + dz * dz;
let distance = Math.sqrt(distanceSq);
let mag = dt / (distanceSq * distance);
let bim = bodyim * mag;
let bjm = bodyj.mass * mag;
bivx -= dx * bjm;
bivy -= dy * bjm;
bivz -= dz * bjm;
bodyj.vx += dx * bim;
bodyj.vy += dy * bim;
bodyj.vz += dz * bim;
}
bodyi.vx = bivx;
bodyi.vy = bivy;
bodyi.vz = bivz;
bodyi.x += dt * bivx;
bodyi.y += dt * bivy;
bodyi.z += dt * bivz;
}
}
energy() {
var e = 0.0;
var bodies = this.bodies;
var size = bodies.length;
for (let i = 0; i < size; ++i) {
let bodyi = bodies[i];
let ix = bodyi.x;
let iy = bodyi.y;
let iz = bodyi.z;
let vx = bodyi.vx;
let vy = bodyi.vy;
let vz = bodyi.vz;
let bim = bodyi.mass;
e += 0.5 * bim * (vx * vx + vy * vy + vz * vz);
for (let j = i + 1; j < size; ++j) {
let bodyj = bodies[j];
let dx = ix - bodyj.x;
let dy = iy - bodyj.y;
let dz = iz - bodyj.z;
let distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
e -= bim * bodyj.mass / distance;
}
}
return e;
}
}
var system;
function init() {
var bodies = new Array();
bodies.push(Sun());
bodies.push(Jupiter());
bodies.push(Saturn());
bodies.push(Uranus());
bodies.push(Neptune());
system = new NBodySystem(bodies);
}
exports.init = init;
function getBody(index) {
var bodies = system.bodies;
return index < bodies.length ? bodies[index] : null;
}
exports.getBody = getBody;
function step() {
system.advance(0.01);
return system.energy();
}
exports.step = step;
function bench(steps) {
for (let i = 0; i < steps; i++)
system.advance(0.01);
}
exports.bench = bench;

View File

@ -0,0 +1,958 @@
function asmFunc(global, env, buffer) {
"almost asm";
var HEAP8 = new global.Int8Array(buffer);
var HEAP16 = new global.Int16Array(buffer);
var HEAP32 = new global.Int32Array(buffer);
var HEAPU8 = new global.Uint8Array(buffer);
var HEAPU16 = new global.Uint16Array(buffer);
var HEAPU32 = new global.Uint32Array(buffer);
var HEAPF32 = new global.Float32Array(buffer);
var HEAPF64 = new global.Float64Array(buffer);
var Math_imul = global.Math.imul;
var Math_fround = global.Math.fround;
var Math_abs = global.Math.abs;
var Math_clz32 = global.Math.clz32;
var Math_min = global.Math.min;
var Math_max = global.Math.max;
var abort = env.abort;
var $lib_allocator_arena_startOffset = 0;
var $lib_allocator_arena_offset = 0;
var assembly_index_system = 0;
var $argc = 0;
var HEAP_BASE = 36;
var i64toi32_i32$HIGH_BITS = 0;
function $lib_allocator_arena_allocate_memory($0) {
$0 = $0 | 0;
var $1 = 0, $2 = 0, $3 = 0, $4 = 0, wasm2asm_i32$0 = 0, wasm2asm_i32$1 = 0, wasm2asm_i32$2 = 0;
if ($0) {
if ($0 >>> 0 > 1073741824 >>> 0) abort();
$1 = $lib_allocator_arena_offset;
$2 = (($1 + $0 | 0) + 7 | 0) & 4294967288 | 0;
$0 = __wasm_current_memory();
if ($2 >>> 0 > ($0 << 16 | 0) >>> 0) {
$3 = ((($2 - $1 | 0) + 65535 | 0) & 4294901760 | 0) >>> 16 | 0;
$4 = $3;
if ((__wasm_grow_memory((wasm2asm_i32$2 = ($0 | 0) > ($4 | 0), wasm2asm_i32$0 = $0, wasm2asm_i32$1 = $4, wasm2asm_i32$2 ? wasm2asm_i32$0 : wasm2asm_i32$1) | 0) | 0) < (0 | 0)) if ((__wasm_grow_memory($3 | 0) | 0) < (0 | 0)) abort();;
}
$lib_allocator_arena_offset = $2;
return $1 | 0;
}
return 0 | 0;
}
function $lib_internal_arraybuffer_allocUnsafe($0) {
$0 = $0 | 0;
var $1 = 0;
$1 = $0;
$1 = $lib_allocator_arena_allocate_memory(1 << (32 - Math_clz32($1 + 7 | 0) | 0) | 0 | 0) | 0;
HEAP32[$1 >> 2] = $0;
return $1 | 0;
}
function $lib_array_Array_Body__constructor($0, $1) {
$0 = $0 | 0;
$1 = $1 | 0;
var $2 = 0, $3 = 0;
if ($1 >>> 0 > 268435454 >>> 0) {
abort(0 | 0, 4 | 0, 23 | 0, 39 | 0);
abort();
}
if ($0) $3 = $0; else {
$2 = $lib_allocator_arena_allocate_memory(8 | 0) | 0;
HEAP32[$2 >> 2] = 0;
HEAP32[($2 + 4 | 0) >> 2] = 0;
$0 = $2;
$3 = $0;
}
HEAP32[$3 >> 2] = $lib_internal_arraybuffer_allocUnsafe($1 << 2 | 0 | 0) | 0;
HEAP32[($0 + 4 | 0) >> 2] = $1;
return $0 | 0;
}
function assembly_index_Body_constructor($0, $1, $2, $3, $4, $5, $6, $7) {
$0 = $0 | 0;
$1 = +$1;
$2 = +$2;
$3 = +$3;
$4 = +$4;
$5 = +$5;
$6 = +$6;
$7 = +$7;
var $8 = 0, $9 = 0;
if ($0) $9 = $0; else {
$8 = $lib_allocator_arena_allocate_memory(56 | 0) | 0;
HEAPF64[$8 >> 3] = $1;
HEAPF64[($8 + 8 | 0) >> 3] = $2;
HEAPF64[($8 + 16 | 0) >> 3] = $3;
HEAPF64[($8 + 24 | 0) >> 3] = $4;
HEAPF64[($8 + 32 | 0) >> 3] = $5;
HEAPF64[($8 + 40 | 0) >> 3] = $6;
HEAPF64[($8 + 48 | 0) >> 3] = $7;
$9 = $8;
}
return $9 | 0;
}
function $lib_memory_set_memory($0, $1, $2) {
$0 = $0 | 0;
$1 = $1 | 0;
$2 = $2 | 0;
var i64toi32_i32$3 = 0, i64toi32_i32$2 = 0, $4 = 0, i64toi32_i32$5 = 0, $3 = 0, $3$hi = 0, i64toi32_i32$1 = 0, i64toi32_i32$4 = 0, $11 = 0, i64toi32_i32$0 = 0, wasm2asm_i32$0 = 0, wasm2asm_i32$1 = 0;
if (($2 | 0) == (0 | 0)) return;
HEAP8[$0 >> 0] = $1;
HEAP8[(($0 + $2 | 0) - 1 | 0) >> 0] = $1;
if ($2 >>> 0 <= 2 >>> 0) return;
HEAP8[($0 + 1 | 0) >> 0] = $1;
HEAP8[($0 + 2 | 0) >> 0] = $1;
HEAP8[(($0 + $2 | 0) - 2 | 0) >> 0] = $1;
HEAP8[(($0 + $2 | 0) - 3 | 0) >> 0] = $1;
if ($2 >>> 0 <= 6 >>> 0) return;
HEAP8[($0 + 3 | 0) >> 0] = $1;
HEAP8[(($0 + $2 | 0) - 4 | 0) >> 0] = $1;
if ($2 >>> 0 <= 8 >>> 0) return;
$4 = (0 - $0 | 0) & 3 | 0;
$0 = $0 + $4 | 0;
$1 = Math_imul($1, 16843009);
HEAP32[$0 >> 2] = $1;
$2 = ($2 - $4 | 0) & 4294967292 | 0;
HEAP32[(($0 + $2 | 0) - 4 | 0) >> 2] = $1;
if ($2 >>> 0 <= 8 >>> 0) return;
HEAP32[($0 + 4 | 0) >> 2] = $1;
HEAP32[($0 + 8 | 0) >> 2] = $1;
HEAP32[(($0 + $2 | 0) - 12 | 0) >> 2] = $1;
HEAP32[(($0 + $2 | 0) - 8 | 0) >> 2] = $1;
if ($2 >>> 0 <= 24 >>> 0) return;
HEAP32[($0 + 12 | 0) >> 2] = $1;
HEAP32[($0 + 16 | 0) >> 2] = $1;
HEAP32[($0 + 20 | 0) >> 2] = $1;
HEAP32[($0 + 24 | 0) >> 2] = $1;
HEAP32[(($0 + $2 | 0) - 28 | 0) >> 2] = $1;
HEAP32[(($0 + $2 | 0) - 24 | 0) >> 2] = $1;
HEAP32[(($0 + $2 | 0) - 20 | 0) >> 2] = $1;
HEAP32[(($0 + $2 | 0) - 16 | 0) >> 2] = $1;
$4 = ($0 & 4 | 0) + 24 | 0;
$0 = $0 + $4 | 0;
$2 = $2 - $4 | 0;
i64toi32_i32$0 = 0;
i64toi32_i32$3 = $1;
i64toi32_i32$1 = 0;
i64toi32_i32$3 = $1;
i64toi32_i32$2 = 0;
i64toi32_i32$4 = 32;
i64toi32_i32$5 = i64toi32_i32$4 & 31 | 0;
if (32 >>> 0 <= (i64toi32_i32$4 & 63 | 0) >>> 0) {
i64toi32_i32$2 = i64toi32_i32$3 << i64toi32_i32$5 | 0;
$11 = 0;
} else {
i64toi32_i32$2 = ((1 << i64toi32_i32$5 | 0) - 1 | 0) & (i64toi32_i32$3 >>> (32 - i64toi32_i32$5 | 0) | 0) | 0 | (i64toi32_i32$1 << i64toi32_i32$5 | 0) | 0;
$11 = i64toi32_i32$3 << i64toi32_i32$5 | 0;
}
i64toi32_i32$1 = $11;
i64toi32_i32$2 = i64toi32_i32$0 | i64toi32_i32$2 | 0;
$3 = i64toi32_i32$3 | i64toi32_i32$1 | 0;
$3$hi = i64toi32_i32$2;
continue_0 : do {
if ($2 >>> 0 >= 32 >>> 0) {
i64toi32_i32$3 = $0;
i64toi32_i32$2 = $3$hi;
HEAP32[i64toi32_i32$3 >> 2] = $3;
(wasm2asm_i32$0 = i64toi32_i32$3, wasm2asm_i32$1 = i64toi32_i32$2), ((HEAP8[(wasm2asm_i32$0 + 4 | 0) >> 0] = wasm2asm_i32$1 & 255 | 0, HEAP8[(wasm2asm_i32$0 + 5 | 0) >> 0] = (wasm2asm_i32$1 >>> 8 | 0) & 255 | 0), HEAP8[(wasm2asm_i32$0 + 6 | 0) >> 0] = (wasm2asm_i32$1 >>> 16 | 0) & 255 | 0), HEAP8[(wasm2asm_i32$0 + 7 | 0) >> 0] = (wasm2asm_i32$1 >>> 24 | 0) & 255 | 0;
i64toi32_i32$3 = $0 + 8 | 0;
i64toi32_i32$2 = $3$hi;
HEAP32[i64toi32_i32$3 >> 2] = $3;
(wasm2asm_i32$0 = i64toi32_i32$3, wasm2asm_i32$1 = i64toi32_i32$2), ((HEAP8[(wasm2asm_i32$0 + 4 | 0) >> 0] = wasm2asm_i32$1 & 255 | 0, HEAP8[(wasm2asm_i32$0 + 5 | 0) >> 0] = (wasm2asm_i32$1 >>> 8 | 0) & 255 | 0), HEAP8[(wasm2asm_i32$0 + 6 | 0) >> 0] = (wasm2asm_i32$1 >>> 16 | 0) & 255 | 0), HEAP8[(wasm2asm_i32$0 + 7 | 0) >> 0] = (wasm2asm_i32$1 >>> 24 | 0) & 255 | 0;
i64toi32_i32$3 = $0 + 16 | 0;
i64toi32_i32$2 = $3$hi;
HEAP32[i64toi32_i32$3 >> 2] = $3;
(wasm2asm_i32$0 = i64toi32_i32$3, wasm2asm_i32$1 = i64toi32_i32$2), ((HEAP8[(wasm2asm_i32$0 + 4 | 0) >> 0] = wasm2asm_i32$1 & 255 | 0, HEAP8[(wasm2asm_i32$0 + 5 | 0) >> 0] = (wasm2asm_i32$1 >>> 8 | 0) & 255 | 0), HEAP8[(wasm2asm_i32$0 + 6 | 0) >> 0] = (wasm2asm_i32$1 >>> 16 | 0) & 255 | 0), HEAP8[(wasm2asm_i32$0 + 7 | 0) >> 0] = (wasm2asm_i32$1 >>> 24 | 0) & 255 | 0;
i64toi32_i32$3 = $0 + 24 | 0;
i64toi32_i32$2 = $3$hi;
HEAP32[i64toi32_i32$3 >> 2] = $3;
(wasm2asm_i32$0 = i64toi32_i32$3, wasm2asm_i32$1 = i64toi32_i32$2), ((HEAP8[(wasm2asm_i32$0 + 4 | 0) >> 0] = wasm2asm_i32$1 & 255 | 0, HEAP8[(wasm2asm_i32$0 + 5 | 0) >> 0] = (wasm2asm_i32$1 >>> 8 | 0) & 255 | 0), HEAP8[(wasm2asm_i32$0 + 6 | 0) >> 0] = (wasm2asm_i32$1 >>> 16 | 0) & 255 | 0), HEAP8[(wasm2asm_i32$0 + 7 | 0) >> 0] = (wasm2asm_i32$1 >>> 24 | 0) & 255 | 0;
$2 = $2 - 32 | 0;
$0 = $0 + 32 | 0;
continue continue_0;
}
break continue_0;
} while (1);
}
function $lib_memory_copy_memory($0, $1, $2) {
$0 = $0 | 0;
$1 = $1 | 0;
$2 = $2 | 0;
var $3 = 0, $4 = 0, $5 = 0, $6 = 0, $7 = 0, $8 = 0, $9 = 0, $10 = 0, $11 = 0, $12 = 0, $13 = 0, $14 = 0, $15 = 0, $16 = 0, $17 = 0, $18 = 0, $19 = 0, $20 = 0, $21 = 0, $22 = 0, $23 = 0, $24 = 0, $25 = 0, $26 = 0, $27 = 0, $28 = 0, $29 = 0, $30 = 0, $31 = 0, $32 = 0, $33 = 0, $34 = 0, $35 = 0, $36 = 0, $37 = 0, $38 = 0, $39 = 0, $40 = 0, $41 = 0, $42 = 0, $43 = 0, $44 = 0;
continue_0 : do {
if ($2) $5 = $1 & 3 | 0; else $5 = $2;
if ($5) {
$3 = $0;
$0 = $3 + 1 | 0;
$6 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$6 >> 0] = HEAPU8[$3 >> 0] | 0;
$2 = $2 - 1 | 0;
continue continue_0;
}
break continue_0;
} while (1);
if (($0 & 3 | 0 | 0) == (0 | 0)) {
continue_1 : do {
if ($2 >>> 0 >= 16 >>> 0) {
HEAP32[$0 >> 2] = HEAPU32[$1 >> 2] | 0;
HEAP32[($0 + 4 | 0) >> 2] = HEAPU32[($1 + 4 | 0) >> 2] | 0;
HEAP32[($0 + 8 | 0) >> 2] = HEAPU32[($1 + 8 | 0) >> 2] | 0;
HEAP32[($0 + 12 | 0) >> 2] = HEAPU32[($1 + 12 | 0) >> 2] | 0;
$1 = $1 + 16 | 0;
$0 = $0 + 16 | 0;
$2 = $2 - 16 | 0;
continue continue_1;
}
break continue_1;
} while (1);
if ($2 & 8 | 0) {
HEAP32[$0 >> 2] = HEAPU32[$1 >> 2] | 0;
HEAP32[($0 + 4 | 0) >> 2] = HEAPU32[($1 + 4 | 0) >> 2] | 0;
$0 = $0 + 8 | 0;
$1 = $1 + 8 | 0;
}
if ($2 & 4 | 0) {
HEAP32[$0 >> 2] = HEAPU32[$1 >> 2] | 0;
$0 = $0 + 4 | 0;
$1 = $1 + 4 | 0;
}
if ($2 & 2 | 0) {
HEAP16[$0 >> 1] = HEAPU16[$1 >> 1] | 0;
$0 = $0 + 2 | 0;
$1 = $1 + 2 | 0;
}
if ($2 & 1 | 0) {
$3 = $0;
$7 = $3;
$3 = $1;
HEAP8[$7 >> 0] = HEAPU8[$3 >> 0] | 0;
}
return;
}
if ($2 >>> 0 >= 32 >>> 0) break_2 : {
case2_2 : {
case1_2 : {
case0_2 : {
tablify_0 : {
switch (($0 & 3 | 0) - 1 | 0 | 0) {
case 0:
break case0_2;
case 1:
break case1_2;
case 2:
break case2_2;
default:
break tablify_0;
};
};
break break_2;
};
$4 = HEAPU32[$1 >> 2] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$8 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$8 >> 0] = HEAPU8[$3 >> 0] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$9 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$9 >> 0] = HEAPU8[$3 >> 0] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$10 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$10 >> 0] = HEAPU8[$3 >> 0] | 0;
$2 = $2 - 3 | 0;
continue_3 : do {
if ($2 >>> 0 >= 17 >>> 0) {
$3 = HEAPU32[($1 + 1 | 0) >> 2] | 0;
HEAP32[$0 >> 2] = $4 >>> 24 | 0 | ($3 << 8 | 0) | 0;
$4 = HEAPU32[($1 + 5 | 0) >> 2] | 0;
HEAP32[($0 + 4 | 0) >> 2] = $3 >>> 24 | 0 | ($4 << 8 | 0) | 0;
$3 = HEAPU32[($1 + 9 | 0) >> 2] | 0;
HEAP32[($0 + 8 | 0) >> 2] = $4 >>> 24 | 0 | ($3 << 8 | 0) | 0;
$4 = HEAPU32[($1 + 13 | 0) >> 2] | 0;
HEAP32[($0 + 12 | 0) >> 2] = $3 >>> 24 | 0 | ($4 << 8 | 0) | 0;
$1 = $1 + 16 | 0;
$0 = $0 + 16 | 0;
$2 = $2 - 16 | 0;
continue continue_3;
}
break continue_3;
} while (1);
break break_2;
};
$4 = HEAPU32[$1 >> 2] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$11 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$11 >> 0] = HEAPU8[$3 >> 0] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$12 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$12 >> 0] = HEAPU8[$3 >> 0] | 0;
$2 = $2 - 2 | 0;
continue_4 : do {
if ($2 >>> 0 >= 18 >>> 0) {
$3 = HEAPU32[($1 + 2 | 0) >> 2] | 0;
HEAP32[$0 >> 2] = $4 >>> 16 | 0 | ($3 << 16 | 0) | 0;
$4 = HEAPU32[($1 + 6 | 0) >> 2] | 0;
HEAP32[($0 + 4 | 0) >> 2] = $3 >>> 16 | 0 | ($4 << 16 | 0) | 0;
$3 = HEAPU32[($1 + 10 | 0) >> 2] | 0;
HEAP32[($0 + 8 | 0) >> 2] = $4 >>> 16 | 0 | ($3 << 16 | 0) | 0;
$4 = HEAPU32[($1 + 14 | 0) >> 2] | 0;
HEAP32[($0 + 12 | 0) >> 2] = $3 >>> 16 | 0 | ($4 << 16 | 0) | 0;
$1 = $1 + 16 | 0;
$0 = $0 + 16 | 0;
$2 = $2 - 16 | 0;
continue continue_4;
}
break continue_4;
} while (1);
break break_2;
};
$4 = HEAPU32[$1 >> 2] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$13 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$13 >> 0] = HEAPU8[$3 >> 0] | 0;
$2 = $2 - 1 | 0;
continue_5 : do {
if ($2 >>> 0 >= 19 >>> 0) {
$3 = HEAPU32[($1 + 3 | 0) >> 2] | 0;
HEAP32[$0 >> 2] = $4 >>> 8 | 0 | ($3 << 24 | 0) | 0;
$4 = HEAPU32[($1 + 7 | 0) >> 2] | 0;
HEAP32[($0 + 4 | 0) >> 2] = $3 >>> 8 | 0 | ($4 << 24 | 0) | 0;
$3 = HEAPU32[($1 + 11 | 0) >> 2] | 0;
HEAP32[($0 + 8 | 0) >> 2] = $4 >>> 8 | 0 | ($3 << 24 | 0) | 0;
$4 = HEAPU32[($1 + 15 | 0) >> 2] | 0;
HEAP32[($0 + 12 | 0) >> 2] = $3 >>> 8 | 0 | ($4 << 24 | 0) | 0;
$1 = $1 + 16 | 0;
$0 = $0 + 16 | 0;
$2 = $2 - 16 | 0;
continue continue_5;
}
break continue_5;
} while (1);
};
if ($2 & 16 | 0) {
$3 = $0;
$0 = $3 + 1 | 0;
$14 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$14 >> 0] = HEAPU8[$3 >> 0] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$15 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$15 >> 0] = HEAPU8[$3 >> 0] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$16 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$16 >> 0] = HEAPU8[$3 >> 0] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$17 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$17 >> 0] = HEAPU8[$3 >> 0] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$18 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$18 >> 0] = HEAPU8[$3 >> 0] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$19 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$19 >> 0] = HEAPU8[$3 >> 0] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$20 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$20 >> 0] = HEAPU8[$3 >> 0] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$21 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$21 >> 0] = HEAPU8[$3 >> 0] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$22 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$22 >> 0] = HEAPU8[$3 >> 0] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$23 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$23 >> 0] = HEAPU8[$3 >> 0] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$24 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$24 >> 0] = HEAPU8[$3 >> 0] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$25 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$25 >> 0] = HEAPU8[$3 >> 0] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$26 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$26 >> 0] = HEAPU8[$3 >> 0] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$27 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$27 >> 0] = HEAPU8[$3 >> 0] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$28 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$28 >> 0] = HEAPU8[$3 >> 0] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$29 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$29 >> 0] = HEAPU8[$3 >> 0] | 0;
}
if ($2 & 8 | 0) {
$3 = $0;
$0 = $3 + 1 | 0;
$30 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$30 >> 0] = HEAPU8[$3 >> 0] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$31 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$31 >> 0] = HEAPU8[$3 >> 0] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$32 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$32 >> 0] = HEAPU8[$3 >> 0] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$33 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$33 >> 0] = HEAPU8[$3 >> 0] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$34 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$34 >> 0] = HEAPU8[$3 >> 0] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$35 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$35 >> 0] = HEAPU8[$3 >> 0] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$36 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$36 >> 0] = HEAPU8[$3 >> 0] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$37 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$37 >> 0] = HEAPU8[$3 >> 0] | 0;
}
if ($2 & 4 | 0) {
$3 = $0;
$0 = $3 + 1 | 0;
$38 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$38 >> 0] = HEAPU8[$3 >> 0] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$39 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$39 >> 0] = HEAPU8[$3 >> 0] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$40 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$40 >> 0] = HEAPU8[$3 >> 0] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$41 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$41 >> 0] = HEAPU8[$3 >> 0] | 0;
}
if ($2 & 2 | 0) {
$3 = $0;
$0 = $3 + 1 | 0;
$42 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$42 >> 0] = HEAPU8[$3 >> 0] | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$43 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$43 >> 0] = HEAPU8[$3 >> 0] | 0;
}
if ($2 & 1 | 0) {
$3 = $0;
$44 = $3;
$3 = $1;
HEAP8[$44 >> 0] = HEAPU8[$3 >> 0] | 0;
}
}
function $lib_memory_move_memory($0, $1, $2) {
$0 = $0 | 0;
$1 = $1 | 0;
$2 = $2 | 0;
var $3 = 0, i64toi32_i32$1 = 0, i64toi32_i32$0 = 0, $6 = 0, $7 = 0, $8 = 0, $9 = 0, $10 = 0, wasm2asm_i32$0 = 0, wasm2asm_i32$1 = 0;
if (($0 | 0) == ($1 | 0)) return;
$3 = ($1 + $2 | 0) >>> 0 <= $0 >>> 0;
if ($3) $6 = $3; else $6 = ($0 + $2 | 0) >>> 0 <= $1 >>> 0;
if ($6 & 1 | 0) {
$lib_memory_copy_memory($0 | 0, $1 | 0, $2 | 0);
return;
}
if ($0 >>> 0 < $1 >>> 0) {
if (($1 & 7 | 0 | 0) == ($0 & 7 | 0 | 0)) {
continue_0 : do {
if ($0 & 7 | 0) {
if (($2 | 0) == (0 | 0)) return;
$2 = $2 - 1 | 0;
$3 = $0;
$0 = $3 + 1 | 0;
$7 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$7 >> 0] = HEAPU8[$3 >> 0] | 0;
continue continue_0;
}
break continue_0;
} while (1);
continue_1 : do {
if ($2 >>> 0 >= 8 >>> 0) {
i64toi32_i32$1 = $0;
$8 = i64toi32_i32$1;
i64toi32_i32$1 = $1;
i64toi32_i32$0 = (wasm2asm_i32$0 = i64toi32_i32$1, HEAPU8[(wasm2asm_i32$0 + 4 | 0) >> 0] | 0 | 0 | (HEAPU8[(wasm2asm_i32$0 + 5 | 0) >> 0] | 0 | 0) << 8 | (HEAPU8[(wasm2asm_i32$0 + 6 | 0) >> 0] | 0 | 0) << 16 | (HEAPU8[(wasm2asm_i32$0 + 7 | 0) >> 0] | 0 | 0) << 24);
HEAP32[$8 >> 2] = HEAPU32[i64toi32_i32$1 >> 2] | 0;
(wasm2asm_i32$0 = i64toi32_i32$1, wasm2asm_i32$1 = i64toi32_i32$0), ((HEAP8[(wasm2asm_i32$0 + 4 | 0) >> 0] = wasm2asm_i32$1 & 255 | 0, HEAP8[(wasm2asm_i32$0 + 5 | 0) >> 0] = (wasm2asm_i32$1 >>> 8 | 0) & 255 | 0), HEAP8[(wasm2asm_i32$0 + 6 | 0) >> 0] = (wasm2asm_i32$1 >>> 16 | 0) & 255 | 0), HEAP8[(wasm2asm_i32$0 + 7 | 0) >> 0] = (wasm2asm_i32$1 >>> 24 | 0) & 255 | 0;
$2 = $2 - 8 | 0;
$0 = $0 + 8 | 0;
$1 = $1 + 8 | 0;
continue continue_1;
}
break continue_1;
} while (1);
}
continue_2 : do {
if ($2) {
$3 = $0;
$0 = $3 + 1 | 0;
$9 = $3;
$3 = $1;
$1 = $3 + 1 | 0;
HEAP8[$9 >> 0] = HEAPU8[$3 >> 0] | 0;
$2 = $2 - 1 | 0;
continue continue_2;
}
break continue_2;
} while (1);
} else {
if (($1 & 7 | 0 | 0) == ($0 & 7 | 0 | 0)) {
continue_3 : do {
if (($0 + $2 | 0) & 7 | 0) {
if (($2 | 0) == (0 | 0)) return;
$2 = $2 - 1 | 0;
HEAP8[($0 + $2 | 0) >> 0] = HEAPU8[($1 + $2 | 0) >> 0] | 0;
continue continue_3;
}
break continue_3;
} while (1);
continue_4 : do {
if ($2 >>> 0 >= 8 >>> 0) {
$2 = $2 - 8 | 0;
i64toi32_i32$1 = $0 + $2 | 0;
$10 = i64toi32_i32$1;
i64toi32_i32$1 = $1 + $2 | 0;
i64toi32_i32$0 = (wasm2asm_i32$0 = i64toi32_i32$1, HEAPU8[(wasm2asm_i32$0 + 4 | 0) >> 0] | 0 | 0 | (HEAPU8[(wasm2asm_i32$0 + 5 | 0) >> 0] | 0 | 0) << 8 | (HEAPU8[(wasm2asm_i32$0 + 6 | 0) >> 0] | 0 | 0) << 16 | (HEAPU8[(wasm2asm_i32$0 + 7 | 0) >> 0] | 0 | 0) << 24);
HEAP32[$10 >> 2] = HEAPU32[i64toi32_i32$1 >> 2] | 0;
(wasm2asm_i32$0 = i64toi32_i32$1, wasm2asm_i32$1 = i64toi32_i32$0), ((HEAP8[(wasm2asm_i32$0 + 4 | 0) >> 0] = wasm2asm_i32$1 & 255 | 0, HEAP8[(wasm2asm_i32$0 + 5 | 0) >> 0] = (wasm2asm_i32$1 >>> 8 | 0) & 255 | 0), HEAP8[(wasm2asm_i32$0 + 6 | 0) >> 0] = (wasm2asm_i32$1 >>> 16 | 0) & 255 | 0), HEAP8[(wasm2asm_i32$0 + 7 | 0) >> 0] = (wasm2asm_i32$1 >>> 24 | 0) & 255 | 0;
continue continue_4;
}
break continue_4;
} while (1);
}
continue_5 : do {
if ($2) {
$2 = $2 - 1 | 0;
HEAP8[($0 + $2 | 0) >> 0] = HEAPU8[($1 + $2 | 0) >> 0] | 0;
continue continue_5;
}
break continue_5;
} while (1);
}
}
function $lib_internal_arraybuffer_reallocUnsafe($0, $1) {
$0 = $0 | 0;
$1 = $1 | 0;
var $2 = 0, $3 = 0;
$2 = HEAP32[$0 >> 2] | 0;
if (($1 | 0) > ($2 | 0)) {
$3 = $2;
if (($1 | 0) <= ((1 << (32 - Math_clz32($3 + 7 | 0) | 0) | 0) - 8 | 0 | 0)) {
HEAP32[$0 >> 2] = $1;
$lib_memory_set_memory(($0 + 8 | 0) + $2 | 0 | 0, 0 | 0, $1 - $2 | 0 | 0);
} else {
$3 = $lib_internal_arraybuffer_allocUnsafe($1 | 0) | 0;
$lib_memory_move_memory($3 + 8 | 0 | 0, $0 + 8 | 0 | 0, $2 | 0);
$lib_memory_set_memory(($3 + 8 | 0) + $2 | 0 | 0, 0 | 0, $1 - $2 | 0 | 0);
return $3 | 0;
}
} else if (($1 | 0) < ($2 | 0)) HEAP32[$0 >> 2] = $1;;
return $0 | 0;
}
function $lib_array_Array_Body__push($0, $1) {
$0 = $0 | 0;
$1 = $1 | 0;
var $4 = 0, $2 = 0, $3 = 0;
$2 = HEAP32[($0 + 4 | 0) >> 2] | 0;
$3 = $2 + 1 | 0;
$4 = HEAPU32[$0 >> 2] | 0;
if ($2 >>> 0 >= ((HEAP32[$4 >> 2] | 0) >>> 2 | 0) >>> 0) {
if ($2 >>> 0 >= 268435454 >>> 0) {
abort(0 | 0, 4 | 0, 128 | 0, 42 | 0);
abort();
}
$4 = $lib_internal_arraybuffer_reallocUnsafe($4 | 0, $3 << 2 | 0 | 0) | 0;
HEAP32[$0 >> 2] = $4;
}
HEAP32[($0 + 4 | 0) >> 2] = $3;
HEAP32[(($4 + ($2 << 2 | 0) | 0) + 8 | 0) >> 2] = $1;
return $3 | 0;
}
function $lib_array_Array_Body____get($0, $1) {
$0 = $0 | 0;
$1 = $1 | 0;
var $2 = 0;
$2 = HEAPU32[$0 >> 2] | 0;
if ($1 >>> 0 >= ((HEAP32[$2 >> 2] | 0) >>> 2 | 0) >>> 0) {
abort(0 | 0, 4 | 0, 64 | 0, 37 | 0);
abort();
}
return HEAPU32[(($2 + ($1 << 2 | 0) | 0) + 8 | 0) >> 2] | 0 | 0;
}
function assembly_index_NBodySystem_constructor($0, $1) {
$0 = $0 | 0;
$1 = $1 | 0;
var $3 = 0, $2 = 0, $4 = 0.0, $5 = 0.0, $6 = 0.0, $7 = 0.0, $8 = 0, $8 = 0;
$3 = $1;
$8 = HEAP32[($3 + 4 | 0) >> 2] | 0;
continue_0 : do {
if (($2 | 0) < ($8 | 0)) {
$3 = $lib_array_Array_Body____get($1 | 0, $2 | 0) | 0;
$4 = +HEAPF64[($3 + 48 | 0) >> 3];
$5 = $5 + +HEAPF64[($3 + 24 | 0) >> 3] * $4;
$6 = $6 + +HEAPF64[($3 + 32 | 0) >> 3] * $4;
$7 = $7 + +HEAPF64[($3 + 40 | 0) >> 3] * $4;
$2 = $2 + 1 | 0;
continue continue_0;
}
break continue_0;
} while (1);
if ($0) $8 = $0; else {
$2 = $lib_allocator_arena_allocate_memory(4 | 0) | 0;
HEAP32[$2 >> 2] = 0;
$0 = $2;
$8 = $0;
}
HEAP32[$8 >> 2] = $1;
$1 = $lib_array_Array_Body____get(HEAPU32[$0 >> 2] | 0 | 0, 0 | 0) | 0;
HEAPF64[($1 + 24 | 0) >> 3] = -$5 / 39.47841760435743;
HEAPF64[($1 + 32 | 0) >> 3] = -$6 / 39.47841760435743;
HEAPF64[($1 + 40 | 0) >> 3] = -$7 / 39.47841760435743;
return $0 | 0;
}
function assembly_index_init() {
var $0 = 0;
$argc = 0;
$1of1 : {
$0of1 : {
oob : {
switch ($argc | 0) {
case 0:
break $0of1;
case 1:
break $1of1;
default:
break oob;
};
};
abort();
};
};
$0 = $lib_array_Array_Body__constructor(0 | 0, 0 | 0) | 0;
$lib_array_Array_Body__push($0 | 0, assembly_index_Body_constructor(0 | 0, +(0.0), +(0.0), +(0.0), +(0.0), +(0.0), +(0.0), +(39.47841760435743)) | 0 | 0) | 0;
$lib_array_Array_Body__push($0 | 0, assembly_index_Body_constructor(0 | 0, +(4.841431442464721), +(-1.1603200440274284), +(-.10362204447112311), +(.606326392995832), +(2.81198684491626), +(-.02521836165988763), +(.03769367487038949)) | 0 | 0) | 0;
$lib_array_Array_Body__push($0 | 0, assembly_index_Body_constructor(0 | 0, +(8.34336671824458), +(4.124798564124305), +(-.4035234171143214), +(-1.0107743461787924), +(1.8256623712304119), +(.008415761376584154), +(.011286326131968767)) | 0 | 0) | 0;
$lib_array_Array_Body__push($0 | 0, assembly_index_Body_constructor(0 | 0, +(12.894369562139131), +(-15.111151401698631), +(-.22330757889265573), +(1.0827910064415354), +(.8687130181696082), +(-.010832637401363636), +(1.7237240570597112e-03)) | 0 | 0) | 0;
$lib_array_Array_Body__push($0 | 0, assembly_index_Body_constructor(0 | 0, +(15.379697114850917), +(-25.919314609987964), +(.17925877295037118), +(.979090732243898), +(.5946989986476762), +(-.034755955504078104), +(2.0336868699246304e-03)) | 0 | 0) | 0;
assembly_index_system = assembly_index_NBodySystem_constructor(0 | 0, $0 | 0) | 0;
}
function assembly_index_getBody($0) {
$0 = $0 | 0;
var $1 = 0, $2 = 0;
$1 = HEAPU32[assembly_index_system >> 2] | 0;
if ($0 >>> 0 < (HEAP32[($1 + 4 | 0) >> 2] | 0) >>> 0) $2 = $lib_array_Array_Body____get($1 | 0, $0 | 0) | 0; else $2 = 0;
return $2 | 0;
}
function assembly_index_NBodySystem_advance($0, $1) {
$0 = $0 | 0;
$1 = +$1;
var $2 = 0, $3 = 0.0, $4 = 0.0, $5 = 0, $6 = 0.0, $7 = 0.0, $8 = 0.0, $9 = 0, $10 = 0.0, $11 = 0.0, $12 = 0.0, $13 = 0, $14 = 0, $15 = 0.0, $16 = 0.0, $17 = 0.0, $18 = 0.0;
$13 = HEAPU32[$0 >> 2] | 0;
$0 = $13;
$14 = HEAP32[($0 + 4 | 0) >> 2] | 0;
continue_0 : do {
if (($5 | 0) < ($14 | 0)) {
$0 = $lib_array_Array_Body____get($13 | 0, $5 | 0) | 0;
$15 = +HEAPF64[$0 >> 3];
$16 = +HEAPF64[($0 + 8 | 0) >> 3];
$17 = +HEAPF64[($0 + 16 | 0) >> 3];
$6 = +HEAPF64[($0 + 24 | 0) >> 3];
$7 = +HEAPF64[($0 + 32 | 0) >> 3];
$8 = +HEAPF64[($0 + 40 | 0) >> 3];
$18 = +HEAPF64[($0 + 48 | 0) >> 3];
$9 = $5 + 1 | 0;
continue_1 : do {
if (($9 | 0) < ($14 | 0)) {
$2 = $lib_array_Array_Body____get($13 | 0, $9 | 0) | 0;
$10 = $15 - +HEAPF64[$2 >> 3];
$11 = $16 - +HEAPF64[($2 + 8 | 0) >> 3];
$12 = $17 - +HEAPF64[($2 + 16 | 0) >> 3];
$3 = $10 * $10 + $11 * $11 + $12 * $12;
$4 = Math_sqrt($3);
$3 = $1 / ($3 * $4);
$4 = $18 * $3;
$3 = +HEAPF64[($2 + 48 | 0) >> 3] * $3;
$6 = $6 - $10 * $3;
$7 = $7 - $11 * $3;
$8 = $8 - $12 * $3;
HEAPF64[($2 + 24 | 0) >> 3] = +HEAPF64[($2 + 24 | 0) >> 3] + $10 * $4;
HEAPF64[($2 + 32 | 0) >> 3] = +HEAPF64[($2 + 32 | 0) >> 3] + $11 * $4;
HEAPF64[($2 + 40 | 0) >> 3] = +HEAPF64[($2 + 40 | 0) >> 3] + $12 * $4;
$9 = $9 + 1 | 0;
continue continue_1;
}
break continue_1;
} while (1);
HEAPF64[($0 + 24 | 0) >> 3] = $6;
HEAPF64[($0 + 32 | 0) >> 3] = $7;
HEAPF64[($0 + 40 | 0) >> 3] = $8;
HEAPF64[$0 >> 3] = +HEAPF64[$0 >> 3] + $1 * $6;
HEAPF64[($0 + 8 | 0) >> 3] = +HEAPF64[($0 + 8 | 0) >> 3] + $1 * $7;
HEAPF64[($0 + 16 | 0) >> 3] = +HEAPF64[($0 + 16 | 0) >> 3] + $1 * $8;
$5 = $5 + 1 | 0;
continue continue_0;
}
break continue_0;
} while (1);
}
function assembly_index_NBodySystem_energy($0) {
$0 = $0 | 0;
var $1 = 0.0, $2 = 0, $3 = 0, $4 = 0, $5 = 0, $10 = 0.0, $6 = 0.0, $7 = 0.0, $8 = 0.0, $9 = 0.0, $11 = 0.0, $12 = 0.0, $13 = 0.0, $14 = 0.0, $15 = 0.0;
$4 = HEAPU32[$0 >> 2] | 0;
$0 = $4;
$5 = HEAP32[($0 + 4 | 0) >> 2] | 0;
continue_0 : do {
if (($2 | 0) < ($5 | 0)) {
$0 = $lib_array_Array_Body____get($4 | 0, $2 | 0) | 0;
$7 = +HEAPF64[$0 >> 3];
$8 = +HEAPF64[($0 + 8 | 0) >> 3];
$9 = +HEAPF64[($0 + 16 | 0) >> 3];
$11 = $1;
$10 = +HEAPF64[($0 + 48 | 0) >> 3];
$1 = +HEAPF64[($0 + 24 | 0) >> 3];
$12 = $1 * $1;
$1 = +HEAPF64[($0 + 32 | 0) >> 3];
$13 = $12 + $1 * $1;
$1 = +HEAPF64[($0 + 40 | 0) >> 3];
$1 = $11 + .5 * $10 * ($13 + $1 * $1);
$0 = $2 + 1 | 0;
continue_1 : do {
if (($0 | 0) < ($5 | 0)) {
$3 = $lib_array_Array_Body____get($4 | 0, $0 | 0) | 0;
$6 = $7 - +HEAPF64[$3 >> 3];
$14 = $1;
$1 = $8 - +HEAPF64[($3 + 8 | 0) >> 3];
$15 = $6 * $6 + $1 * $1;
$1 = $9 - +HEAPF64[($3 + 16 | 0) >> 3];
$1 = $14 - $10 * +HEAPF64[($3 + 48 | 0) >> 3] / Math_sqrt($15 + $1 * $1);
$0 = $0 + 1 | 0;
continue continue_1;
}
break continue_1;
} while (1);
$2 = $2 + 1 | 0;
continue continue_0;
}
break continue_0;
} while (1);
return +$1;
}
function assembly_index_step() {
assembly_index_NBodySystem_advance(assembly_index_system | 0, +(.01));
return +(+assembly_index_NBodySystem_energy(assembly_index_system | 0));
}
function assembly_index_bench($0) {
$0 = $0 | 0;
var $1 = 0;
continue_0 : do {
if ($1 >>> 0 < $0 >>> 0) {
assembly_index_NBodySystem_advance(assembly_index_system | 0, +(.01));
$1 = $1 + 1 | 0;
continue continue_0;
}
break continue_0;
} while (1);
}
function start() {
$lib_allocator_arena_startOffset = (HEAP_BASE + 7 | 0) & 4294967288 | 0;
$lib_allocator_arena_offset = $lib_allocator_arena_startOffset;
}
function __wasm_ctz_i32(x) {
x = x | 0;
var $1 = 0;
if ((x | 0) == (0 | 0)) $1 = 32; else $1 = 31 - Math_clz32(x ^ (x - 1 | 0) | 0) | 0;
return $1 | 0;
}
function __wasm_popcnt_i32(x) {
x = x | 0;
var count = 0, $2 = 0;
count = 0;
b : {
l : do {
$2 = count;
if ((x | 0) == (0 | 0)) break b;
x = x & (x - 1 | 0) | 0;
count = count + 1 | 0;
continue l;
break l;
} while (1);
};
return $2 | 0;
}
function __wasm_rotl_i32(x, k) {
x = x | 0;
k = k | 0;
return ((4294967295 >>> (k & 31 | 0) | 0) & x | 0) << (k & 31 | 0) | 0 | (((4294967295 << (32 - (k & 31 | 0) | 0) | 0) & x | 0) >>> (32 - (k & 31 | 0) | 0) | 0) | 0 | 0;
}
function __wasm_rotr_i32(x, k) {
x = x | 0;
k = k | 0;
return ((4294967295 << (k & 31 | 0) | 0) & x | 0) >>> (k & 31 | 0) | 0 | (((4294967295 >>> (32 - (k & 31 | 0) | 0) | 0) & x | 0) << (32 - (k & 31 | 0) | 0) | 0) | 0 | 0;
}
function __wasm_grow_memory(pagesToAdd) {
pagesToAdd = pagesToAdd | 0;
var oldPages = __wasm_current_memory() | 0;
var newPages = oldPages + pagesToAdd | 0;
if ((oldPages < newPages) && (newPages < 65535)) {
var newBuffer = new ArrayBuffer(Math_imul(newPages, 65536));
var newHEAP8 = new global.Int8Array(newBuffer);
newHEAP8.set(HEAP8);
HEAP8 = newHEAP8;
HEAP16 = new global.Int16Array(newBuffer);
HEAP32 = new global.Int32Array(newBuffer);
HEAPU8 = new global.Uint8Array(newBuffer);
HEAPU16 = new global.Uint16Array(newBuffer);
HEAPU32 = new global.Uint32Array(newBuffer);
HEAPF32 = new global.Float32Array(newBuffer);
HEAPF64 = new global.Float64Array(newBuffer);
buffer = newBuffer;
}
return oldPages;
}
function __wasm_current_memory() {
return buffer.byteLength / 65536 | 0;
}
return {
init: assembly_index_init,
getBody: assembly_index_getBody,
step: assembly_index_step,
bench: assembly_index_bench,
memory: Object.create(Object.prototype, {
grow: {
value: __wasm_grow_memory
},
buffer: {
get: function () {
return buffer;
}
}
})
};
}

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,7 @@
(module
(type $i (func (result i32)))
(type $F (func (result f64)))
(type $v (func))
(type $iii (func (param i32 i32) (result i32)))
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $ii (func (param i32) (result i32)))
@ -9,7 +10,7 @@
(type $iFFFi (func (param i32 f64 f64 f64) (result i32)))
(type $iFv (func (param i32 f64)))
(type $iF (func (param i32) (result f64)))
(type $v (func))
(type $iv (func (param i32)))
(import "env" "abort" (func $abort (param i32 i32 i32 i32)))
(global $~lib/internal/allocator/AL_BITS i32 (i32.const 3))
(global $~lib/internal/allocator/AL_SIZE i32 (i32.const 8))
@ -19,15 +20,15 @@
(global $~lib/allocator/arena/offset (mut i32) (i32.const 0))
(global $assembly/index/SOLAR_MASS f64 (f64.const 39.47841760435743))
(global $assembly/index/DAYS_PER_YEAR f64 (f64.const 365.24))
(global $assembly/index/system (mut i32) (i32.const 0))
(global $~lib/internal/arraybuffer/HEADER_SIZE i32 (i32.const 8))
(global $~lib/internal/arraybuffer/MAX_BLENGTH i32 (i32.const 1073741816))
(global $~argc (mut i32) (i32.const 0))
(global $assembly/index/bodies (mut i32) (i32.const 0))
(global $assembly/index/system (mut i32) (i32.const 0))
(global $HEAP_BASE i32 (i32.const 96))
(memory $0 1)
(data (i32.const 4) "\0d\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s\00")
(data (i32.const 36) "\1c\00\00\00~\00l\00i\00b\00/\00i\00n\00t\00e\00r\00n\00a\00l\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s\00")
(export "init" (func $assembly/index/init))
(export "getBody" (func $assembly/index/getBody))
(export "step" (func $assembly/index/step))
(export "bench" (func $assembly/index/bench))
@ -4407,30 +4408,109 @@
)
(get_local $0)
)
(func $assembly/index/getBody (; 21 ;) (type $ii) (param $0 i32) (result i32)
;;@ assembly/index.ts:191:49
(func $assembly/index/init (; 21 ;) (type $v)
(local $0 i32)
;;@ assembly/index.ts:184:2
(set_local $0
;;@ assembly/index.ts:184:15
(block (result i32)
(set_global $~argc
(i32.const 0)
)
(call $~lib/array/Array<Body>#constructor|trampoline
(i32.const 0)
(i32.const 0)
)
)
)
;;@ assembly/index.ts:185:9
(drop
(call $~lib/array/Array<Body>#push
;;@ assembly/index.ts:185:2
(get_local $0)
;;@ assembly/index.ts:185:14
(call $assembly/index/Sun)
)
)
;;@ assembly/index.ts:186:9
(drop
(call $~lib/array/Array<Body>#push
;;@ assembly/index.ts:186:2
(get_local $0)
;;@ assembly/index.ts:186:14
(call $assembly/index/Jupiter)
)
)
;;@ assembly/index.ts:187:9
(drop
(call $~lib/array/Array<Body>#push
;;@ assembly/index.ts:187:2
(get_local $0)
;;@ assembly/index.ts:187:14
(call $assembly/index/Saturn)
)
)
;;@ assembly/index.ts:188:9
(drop
(call $~lib/array/Array<Body>#push
;;@ assembly/index.ts:188:2
(get_local $0)
;;@ assembly/index.ts:188:14
(call $assembly/index/Uranus)
)
)
;;@ assembly/index.ts:189:9
(drop
(call $~lib/array/Array<Body>#push
;;@ assembly/index.ts:189:2
(get_local $0)
;;@ assembly/index.ts:189:14
(call $assembly/index/Neptune)
)
)
;;@ assembly/index.ts:190:2
(set_global $assembly/index/system
;;@ assembly/index.ts:190:11
(call $assembly/index/NBodySystem#constructor
(i32.const 0)
;;@ assembly/index.ts:190:27
(get_local $0)
)
)
)
(func $assembly/index/getBody (; 22 ;) (type $ii) (param $0 i32) (result i32)
(local $1 i32)
;;@ assembly/index.ts:194:2
(set_local $1
;;@ assembly/index.ts:194:15
(i32.load
(get_global $assembly/index/system)
)
)
;;@ assembly/index.ts:195:59
(return
;;@ assembly/index.ts:191:9
;;@ assembly/index.ts:195:9
(if (result i32)
(i32.lt_s
(i32.lt_u
(get_local $0)
;;@ assembly/index.ts:191:17
;;@ assembly/index.ts:195:22
(call $~lib/array/Array<Body>#get:length
(get_global $assembly/index/bodies)
;;@ assembly/index.ts:195:27
(get_local $1)
)
)
;;@ assembly/index.ts:191:33
;;@ assembly/index.ts:195:43
(call $~lib/array/Array<Body>#__get
(get_global $assembly/index/bodies)
;;@ assembly/index.ts:191:40
(get_local $1)
;;@ assembly/index.ts:195:50
(get_local $0)
)
;;@ assembly/index.ts:191:49
;;@ assembly/index.ts:195:59
(i32.const 0)
)
)
)
(func $assembly/index/NBodySystem#advance (; 22 ;) (type $iFv) (param $0 i32) (param $1 f64)
(func $assembly/index/NBodySystem#advance (; 23 ;) (type $iFv) (param $0 i32) (param $1 f64)
(local $2 i32)
(local $3 i32)
(local $4 i32)
@ -4631,10 +4711,20 @@
)
;;@ assembly/index.ts:123:8
(set_local $19
;;@ assembly/index.ts:123:23
(f64.sqrt
;;@ assembly/index.ts:123:28
(get_local $18)
;;@ assembly/index.ts:123:28
(block $~lib/math/NativeMath.sqrt|inlined.0 (result f64)
(set_local $19
;;@ assembly/index.ts:123:33
(get_local $18)
)
;;@ ~lib/math.ts:1076:30
(br $~lib/math/NativeMath.sqrt|inlined.0
;;@ ~lib/math.ts:1076:11
(f64.sqrt
;;@ ~lib/math.ts:1076:29
(get_local $19)
)
)
)
)
;;@ assembly/index.ts:124:8
@ -4844,7 +4934,7 @@
)
)
)
(func $assembly/index/NBodySystem#energy (; 23 ;) (type $iF) (param $0 i32) (result f64)
(func $assembly/index/NBodySystem#energy (; 24 ;) (type $iF) (param $0 i32) (result f64)
(local $1 f64)
(local $2 i32)
(local $3 i32)
@ -5059,28 +5149,38 @@
)
;;@ assembly/index.ts:173:8
(set_local $18
;;@ assembly/index.ts:173:23
(f64.sqrt
;;@ assembly/index.ts:173:28
(f64.add
;;@ assembly/index.ts:173:28
(block $~lib/math/NativeMath.sqrt|inlined.1 (result f64)
(set_local $18
;;@ assembly/index.ts:173:33
(f64.add
(f64.mul
(get_local $15)
;;@ assembly/index.ts:173:33
(get_local $15)
)
;;@ assembly/index.ts:173:38
(f64.mul
(get_local $16)
(f64.add
(f64.mul
(get_local $15)
;;@ assembly/index.ts:173:38
(get_local $15)
)
;;@ assembly/index.ts:173:43
(get_local $16)
(f64.mul
(get_local $16)
;;@ assembly/index.ts:173:48
(get_local $16)
)
)
;;@ assembly/index.ts:173:53
(f64.mul
(get_local $17)
;;@ assembly/index.ts:173:58
(get_local $17)
)
)
;;@ assembly/index.ts:173:48
(f64.mul
(get_local $17)
;;@ assembly/index.ts:173:53
(get_local $17)
)
;;@ ~lib/math.ts:1076:30
(br $~lib/math/NativeMath.sqrt|inlined.1
;;@ ~lib/math.ts:1076:11
(f64.sqrt
;;@ ~lib/math.ts:1076:29
(get_local $18)
)
)
)
@ -5136,49 +5236,49 @@
(get_local $1)
)
)
(func $assembly/index/step (; 24 ;) (type $F) (result f64)
;;@ assembly/index.ts:195:9
(func $assembly/index/step (; 25 ;) (type $F) (result f64)
;;@ assembly/index.ts:199:9
(call $assembly/index/NBodySystem#advance
;;@ assembly/index.ts:195:2
;;@ assembly/index.ts:199:2
(get_global $assembly/index/system)
;;@ assembly/index.ts:195:17
;;@ assembly/index.ts:199:17
(f64.const 0.01)
)
;;@ assembly/index.ts:196:23
;;@ assembly/index.ts:200:23
(return
;;@ assembly/index.ts:196:16
;;@ assembly/index.ts:200:16
(call $assembly/index/NBodySystem#energy
;;@ assembly/index.ts:196:9
;;@ assembly/index.ts:200:9
(get_global $assembly/index/system)
)
)
)
(func $assembly/index/bench (; 25 ;) (type $iF) (param $0 i32) (result f64)
(func $assembly/index/bench (; 26 ;) (type $iv) (param $0 i32)
(local $1 i32)
;;@ assembly/index.ts:200:2
;;@ assembly/index.ts:204:2
(block $break|0
;;@ assembly/index.ts:200:7
;;@ assembly/index.ts:204:7
(set_local $1
;;@ assembly/index.ts:200:15
;;@ assembly/index.ts:204:20
(i32.const 0)
)
(loop $continue|0
(if
;;@ assembly/index.ts:200:18
(i32.lt_s
;;@ assembly/index.ts:204:23
(i32.lt_u
(get_local $1)
;;@ assembly/index.ts:200:22
;;@ assembly/index.ts:204:27
(get_local $0)
)
(block
;;@ assembly/index.ts:200:41
;;@ assembly/index.ts:204:46
(call $assembly/index/NBodySystem#advance
;;@ assembly/index.ts:200:34
;;@ assembly/index.ts:204:39
(get_global $assembly/index/system)
;;@ assembly/index.ts:200:49
;;@ assembly/index.ts:204:54
(f64.const 0.01)
)
;;@ assembly/index.ts:200:29
;;@ assembly/index.ts:204:34
(set_local $1
(i32.add
(get_local $1)
@ -5190,16 +5290,8 @@
)
)
)
;;@ assembly/index.ts:201:23
(return
;;@ assembly/index.ts:201:16
(call $assembly/index/NBodySystem#energy
;;@ assembly/index.ts:201:9
(get_global $assembly/index/system)
)
)
)
(func $start (; 26 ;) (type $v)
(func $start (; 27 ;) (type $v)
(set_global $~lib/allocator/arena/startOffset
;;@ ~lib/allocator/arena.ts:12:25
(i32.and
@ -5221,70 +5313,5 @@
;;@ ~lib/allocator/arena.ts:13:20
(get_global $~lib/allocator/arena/startOffset)
)
(set_global $assembly/index/bodies
;;@ assembly/index.ts:181:13
(block (result i32)
(set_global $~argc
(i32.const 0)
)
(call $~lib/array/Array<Body>#constructor|trampoline
(i32.const 0)
(i32.const 0)
)
)
)
;;@ assembly/index.ts:182:7
(drop
(call $~lib/array/Array<Body>#push
;;@ assembly/index.ts:182:0
(get_global $assembly/index/bodies)
;;@ assembly/index.ts:182:12
(call $assembly/index/Sun)
)
)
;;@ assembly/index.ts:183:7
(drop
(call $~lib/array/Array<Body>#push
;;@ assembly/index.ts:183:0
(get_global $assembly/index/bodies)
;;@ assembly/index.ts:183:12
(call $assembly/index/Jupiter)
)
)
;;@ assembly/index.ts:184:7
(drop
(call $~lib/array/Array<Body>#push
;;@ assembly/index.ts:184:0
(get_global $assembly/index/bodies)
;;@ assembly/index.ts:184:12
(call $assembly/index/Saturn)
)
)
;;@ assembly/index.ts:185:7
(drop
(call $~lib/array/Array<Body>#push
;;@ assembly/index.ts:185:0
(get_global $assembly/index/bodies)
;;@ assembly/index.ts:185:12
(call $assembly/index/Uranus)
)
)
;;@ assembly/index.ts:186:7
(drop
(call $~lib/array/Array<Body>#push
;;@ assembly/index.ts:186:0
(get_global $assembly/index/bodies)
;;@ assembly/index.ts:186:12
(call $assembly/index/Neptune)
)
)
(set_global $assembly/index/system
;;@ assembly/index.ts:188:13
(call $assembly/index/NBodySystem#constructor
(i32.const 0)
;;@ assembly/index.ts:188:29
(get_global $assembly/index/bodies)
)
)
)
)

View File

@ -45,6 +45,8 @@ fetch("build/optimized.wasm")
var exports = module.instance.exports;
var mem = new Float64Array(exports.memory.buffer);
exports.init();
// Update about 30 times a second
(function update() {
setTimeout(update, 1000 / 30);

View File

@ -4,8 +4,9 @@
"private": true,
"scripts": {
"asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --sourceMap --validate",
"asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat -O3 --sourceMap --validate --noDebug --noAssert",
"asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat -a build/optimized.asm.js -O3 --validate --noDebug --noAssert",
"asbuild": "npm run asbuild:untouched && npm run asbuild:optimized",
"tsbuild": "tsc -p assembly -t ES2017 -m commonjs --outDir build",
"server": "http-server . -o -c-1",
"test": "node tests"
},

View File

@ -1,10 +1,59 @@
var nbody = require("..");
const fs = require("fs");
var steps = process.argv.length > 2 ? parseInt(process.argv[2], 10) : 1000000;
console.log("Performing " + steps + " steps ...");
// Load WASM version
const nbodyWASM = require("../index.js");
var start = process.hrtime();
var energy = nbody.bench(steps);
var time = process.hrtime(start);
// Load ASMJS version
src = fs.readFileSync(__dirname + "/../build/optimized.asm.js", "utf8");
if (src.indexOf("var Math_sqrt =") < 0) { // currently missing in asm.js output
let p = src.indexOf(" var abort = env.abort;");
src = src.substring(0, p) + " var Math_sqrt = global.Math.sqrt;\n " + src.substring(p);
}
var nbodyASMJS = eval("0," + src)({
Int8Array,
Int16Array,
Int32Array,
Uint8Array,
Uint16Array,
Uint32Array,
Float32Array,
Float64Array,
Math
}, {
abort: function() { throw Error(); }
}, new ArrayBuffer(0x10000));
console.log("Took " + (time[0] * 1e3 + time[1] / 1e6) + "ms (energy=" + energy + ")");
// Load JS version
var src = fs.readFileSync(__dirname + "/../build/index.js", "utf8");
var nbodyJS = (new Function("require", "exports", src + " return exports;"))(function() {}, {});
function test(nbody, steps) {
nbody.init();
var start = process.hrtime();
nbody.bench(steps);
return process.hrtime(start);
}
var steps = process.argv.length > 2 ? parseInt(process.argv[2], 10) : 10000000;
console.log("Warming up ...");
test(nbodyWASM, 100000);
test(nbodyASMJS, 100000);
test(nbodyJS, 100000);
setTimeout(() => {
var time;
console.log("Performing " + steps + " steps (WASM) ...");
time = test(nbodyWASM, steps);
console.log("Took " + (time[0] * 1e3 + time[1] / 1e6) + "ms");
console.log("Performing " + steps + " steps (ASMJS) ...");
time = test(nbodyASMJS, steps);
console.log("Took " + (time[0] * 1e3 + time[1] / 1e6) + "ms");
console.log("Performing " + steps + " steps (JS) ...");
time = test(nbodyJS, steps);
console.log("Took " + (time[0] * 1e3 + time[1] / 1e6) + "ms");
}, 1000);