diff --git a/examples/n-body/assembly/index.js b/examples/n-body/assembly/index.js index 3f84716427..72239ed1ff 100644 --- a/examples/n-body/assembly/index.js +++ b/examples/n-body/assembly/index.js @@ -2,13 +2,13 @@ const fs = require("fs"); const path = require("path"); const compiled = new WebAssembly.Module( - fs.readFileSync(path.resolve(__dirname, "..", "build", "optimized.wasm")) + fs.readFileSync(path.resolve(__dirname, "..", "build", "as_nbody.wasm")) ); const imports = { env: { memory: new WebAssembly.Memory({ initial: 10 }), - abort: (filename, line, column) => { + abort: (_, line, column) => { throw Error("abort called at " + line + ":" + column); } } diff --git a/examples/n-body/build/.gitignore b/examples/n-body/build/.gitignore index 22b2ed20a7..7e3009b620 100644 --- a/examples/n-body/build/.gitignore +++ b/examples/n-body/build/.gitignore @@ -1,3 +1,7 @@ *.wasm *.wasm.map -*.asm.js +.rustc_info.* +/release +wasm32-unknown-unknown/release/**/* +!rust_nbody.wasm +!as_nbody.wasm \ No newline at end of file diff --git a/examples/n-body/build/index.asm.js b/examples/n-body/build/as_nbody.asm.js similarity index 100% rename from examples/n-body/build/index.asm.js rename to examples/n-body/build/as_nbody.asm.js diff --git a/examples/n-body/build/optimized.wasm b/examples/n-body/build/as_nbody.wasm similarity index 100% rename from examples/n-body/build/optimized.wasm rename to examples/n-body/build/as_nbody.wasm diff --git a/examples/n-body/build/optimized.wat b/examples/n-body/build/as_nbody.wat similarity index 100% rename from examples/n-body/build/optimized.wat rename to examples/n-body/build/as_nbody.wat diff --git a/examples/n-body/build/asmjs_nbody.asm.js b/examples/n-body/build/asmjs_nbody.asm.js new file mode 100644 index 0000000000..6580d08541 --- /dev/null +++ b/examples/n-body/build/asmjs_nbody.asm.js @@ -0,0 +1,287 @@ + +function asmFunc(global, env, buffer) { + 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 Math_floor = global.Math.floor; + var Math_ceil = global.Math.ceil; + var Math_sqrt = global.Math.sqrt; + var abort = env.abort; + var nan = global.NaN; + var infinity = global.Infinity; + var assembly_index_system = 0; + var $lib_rt_stub_startOffset = 0; + var $lib_rt_stub_offset = 0; + function $lib_rt_stub_maybeGrowMemory($0) { + var $1 = 0, $2 = 0; + $2 = __wasm_memory_size(); + $1 = $2 << 16 | 0; + if ($0 >>> 0 > $1 >>> 0) { + $1 = ((($0 - $1 | 0) + 65535 | 0) & -65536 | 0) >>> 16 | 0; + if ((__wasm_memory_grow((($2 | 0) > ($1 | 0) ? $2 : $1) | 0) | 0) < (0 | 0)) { + if ((__wasm_memory_grow($1 | 0) | 0) < (0 | 0)) { + abort() + } + } + } + $lib_rt_stub_offset = $0; + } + + function $lib_rt_stub___alloc($0, $1) { + var $2 = 0, $3 = 0, $4 = 0; + if ($0 >>> 0 > 1073741808 >>> 0) { + abort() + } + $2 = ($0 + 15 | 0) & -16 | 0; + $3 = $2 >>> 0 > 16 >>> 0; + $4 = $lib_rt_stub_offset + 16 | 0; + $3 = $3 ? $2 : 16; + $lib_rt_stub_maybeGrowMemory($4 + $3 | 0); + $2 = $4 - 16 | 0; + HEAP32[$2 >> 2] = $3; + HEAP32[($2 + 4 | 0) >> 2] = 1; + HEAP32[($2 + 8 | 0) >> 2] = $1; + HEAP32[($2 + 12 | 0) >> 2] = $0; + return $4; + } + + function assembly_index_NBodySystem_constructor($0) { + var $1 = 0, $2 = 0, $3 = 0.0, $4 = 0.0, $5 = 0.0, $6 = 0.0, $7 = 0; + $7 = HEAP32[(($0 - 16 | 0) + 12 | 0) >> 2] >>> 2 | 0; + for_loop_0 : while (1) { + if (($1 | 0) < ($7 | 0)) { + $2 = HEAP32[(($1 << 2 | 0) + $0 | 0) >> 2]; + $3 = HEAPF64[($2 + 48 | 0) >> 3]; + $4 = $4 + HEAPF64[($2 + 24 | 0) >> 3] * $3; + $5 = $5 + HEAPF64[($2 + 32 | 0) >> 3] * $3; + $6 = $6 + HEAPF64[($2 + 40 | 0) >> 3] * $3; + $1 = $1 + 1 | 0; + continue for_loop_0; + } + break for_loop_0; + }; + $1 = HEAP32[$0 >> 2]; + HEAPF64[($1 + 24 | 0) >> 3] = -$4 / 39.47841760435743; + HEAPF64[($1 + 32 | 0) >> 3] = -$5 / 39.47841760435743; + HEAPF64[($1 + 40 | 0) >> 3] = -$6 / 39.47841760435743; + $1 = $lib_rt_stub___alloc(4, 3); + HEAP32[$1 >> 2] = $0; + return $1; + } + + function assembly_index_Body_constructor($0, $1, $2, $3, $4, $5, $6) { + var $7 = 0; + $7 = $lib_rt_stub___alloc(56, 4); + HEAPF64[$7 >> 3] = $0; + HEAPF64[($7 + 8 | 0) >> 3] = $1; + HEAPF64[($7 + 16 | 0) >> 3] = $2; + HEAPF64[($7 + 24 | 0) >> 3] = $3; + HEAPF64[($7 + 32 | 0) >> 3] = $4; + HEAPF64[($7 + 40 | 0) >> 3] = $5; + HEAPF64[($7 + 48 | 0) >> 3] = $6; + return $7; + } + + function assembly_index_init() { + var $0 = 0, wasm2js_i32$0 = 0, wasm2js_i32$1 = 0; + $0 = $lib_rt_stub___alloc(20, 5); + (wasm2js_i32$0 = $0, wasm2js_i32$1 = assembly_index_Body_constructor(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 39.47841760435743)), HEAP32[wasm2js_i32$0 >> 2] = wasm2js_i32$1; + (wasm2js_i32$0 = $0, wasm2js_i32$1 = assembly_index_Body_constructor(4.841431442464721, -1.1603200440274284, -.10362204447112311, .606326392995832, 2.81198684491626, -.02521836165988763, .03769367487038949)), HEAP32[(wasm2js_i32$0 + 4 | 0) >> 2] = wasm2js_i32$1; + (wasm2js_i32$0 = $0, wasm2js_i32$1 = assembly_index_Body_constructor(8.34336671824458, 4.124798564124305, -.4035234171143214, -1.0107743461787924, 1.8256623712304119, .008415761376584154, .011286326131968767)), HEAP32[(wasm2js_i32$0 + 8 | 0) >> 2] = wasm2js_i32$1; + (wasm2js_i32$0 = $0, wasm2js_i32$1 = assembly_index_Body_constructor(12.894369562139131, -15.111151401698631, -.22330757889265573, 1.0827910064415354, .8687130181696082, -.010832637401363636, 1.7237240570597112e-03)), HEAP32[(wasm2js_i32$0 + 12 | 0) >> 2] = wasm2js_i32$1; + (wasm2js_i32$0 = $0, wasm2js_i32$1 = assembly_index_Body_constructor(15.379697114850917, -25.919314609987964, .17925877295037118, .979090732243898, .5946989986476762, -.034755955504078104, 2.0336868699246304e-03)), HEAP32[(wasm2js_i32$0 + 16 | 0) >> 2] = wasm2js_i32$1; + assembly_index_system = assembly_index_NBodySystem_constructor($0); + } + + function assembly_index_NBodySystem_advance($0) { + var $1 = 0, $2 = 0.0, $3 = 0.0, $4 = 0, $5 = 0.0, $6 = 0.0, $7 = 0.0, $8 = 0, $9 = 0.0, $10 = 0.0, $11 = 0.0, $12 = 0, $13 = 0, $14 = 0.0, $15 = 0.0, $16 = 0.0, $17 = 0.0; + $12 = HEAP32[$0 >> 2]; + $13 = HEAP32[(($12 - 16 | 0) + 12 | 0) >> 2] >>> 2 | 0; + for_loop_0 : while (1) { + if ($4 >>> 0 < $13 >>> 0) { + $0 = HEAP32[(($4 << 2 | 0) + $12 | 0) >> 2]; + $14 = HEAPF64[$0 >> 3]; + $15 = HEAPF64[($0 + 8 | 0) >> 3]; + $16 = HEAPF64[($0 + 16 | 0) >> 3]; + $5 = HEAPF64[($0 + 24 | 0) >> 3]; + $6 = HEAPF64[($0 + 32 | 0) >> 3]; + $7 = HEAPF64[($0 + 40 | 0) >> 3]; + $17 = HEAPF64[($0 + 48 | 0) >> 3]; + $8 = $4 + 1 | 0; + for_loop_1 : while (1) { + if ($8 >>> 0 < $13 >>> 0) { + $1 = HEAP32[(($8 << 2 | 0) + $12 | 0) >> 2]; + $2 = $14 - HEAPF64[$1 >> 3]; + $9 = $15 - HEAPF64[($1 + 8 | 0) >> 3]; + $10 = $16 - HEAPF64[($1 + 16 | 0) >> 3]; + $3 = $2 * $2 + $9 * $9 + $10 * $10; + $11 = Math_sqrt($3); + $11 = .01 / ($3 * $11); + $3 = HEAPF64[($1 + 48 | 0) >> 3] * $11; + $5 = $5 - $2 * $3; + $6 = $6 - $9 * $3; + $7 = $7 - $10 * $3; + $3 = $2; + $2 = $17 * $11; + HEAPF64[($1 + 24 | 0) >> 3] = HEAPF64[($1 + 24 | 0) >> 3] + $3 * $2; + HEAPF64[($1 + 32 | 0) >> 3] = HEAPF64[($1 + 32 | 0) >> 3] + $9 * $2; + HEAPF64[($1 + 40 | 0) >> 3] = HEAPF64[($1 + 40 | 0) >> 3] + $10 * $2; + $8 = $8 + 1 | 0; + continue for_loop_1; + } + break for_loop_1; + }; + HEAPF64[($0 + 24 | 0) >> 3] = $5; + HEAPF64[($0 + 32 | 0) >> 3] = $6; + HEAPF64[($0 + 40 | 0) >> 3] = $7; + HEAPF64[$0 >> 3] = HEAPF64[$0 >> 3] + .01 * $5; + HEAPF64[($0 + 8 | 0) >> 3] = HEAPF64[($0 + 8 | 0) >> 3] + .01 * $6; + HEAPF64[($0 + 16 | 0) >> 3] = HEAPF64[($0 + 16 | 0) >> 3] + .01 * $7; + $4 = $4 + 1 | 0; + continue for_loop_0; + } + break for_loop_0; + }; + } + + function assembly_index_NBodySystem_energy($0) { + var $1 = 0.0, $2 = 0.0, $3 = 0, $4 = 0, $5 = 0, $6 = 0.0, $7 = 0, $8 = 0.0, $9 = 0.0, $10 = 0.0, $11 = 0.0; + $5 = HEAP32[$0 >> 2]; + $7 = HEAP32[(($5 - 16 | 0) + 12 | 0) >> 2] >>> 2 | 0; + for_loop_0 : while (1) { + if ($3 >>> 0 < $7 >>> 0) { + $0 = HEAP32[(($3 << 2 | 0) + $5 | 0) >> 2]; + $9 = HEAPF64[$0 >> 3]; + $10 = HEAPF64[($0 + 8 | 0) >> 3]; + $11 = HEAPF64[($0 + 16 | 0) >> 3]; + $6 = $1; + $8 = HEAPF64[($0 + 48 | 0) >> 3]; + $1 = HEAPF64[($0 + 24 | 0) >> 3]; + $2 = $1 * $1; + $1 = HEAPF64[($0 + 32 | 0) >> 3]; + $2 = $2 + $1 * $1; + $1 = HEAPF64[($0 + 40 | 0) >> 3]; + $1 = $6 + .5 * $8 * ($2 + $1 * $1); + $0 = $3 + 1 | 0; + for_loop_1 : while (1) { + if ($0 >>> 0 < $7 >>> 0) { + $4 = HEAP32[(($0 << 2 | 0) + $5 | 0) >> 2]; + $6 = $1; + $1 = $9 - HEAPF64[$4 >> 3]; + $2 = $1 * $1; + $1 = $10 - HEAPF64[($4 + 8 | 0) >> 3]; + $2 = $2 + $1 * $1; + $1 = $11 - HEAPF64[($4 + 16 | 0) >> 3]; + $1 = $6 - $8 * HEAPF64[($4 + 48 | 0) >> 3] / Math_sqrt($2 + $1 * $1); + $0 = $0 + 1 | 0; + continue for_loop_1; + } + break for_loop_1; + }; + $3 = $3 + 1 | 0; + continue for_loop_0; + } + break for_loop_0; + }; + return $1; + } + + function assembly_index_step() { + assembly_index_NBodySystem_advance(assembly_index_system); + return +assembly_index_NBodySystem_energy(assembly_index_system); + } + + function assembly_index_bench($0) { + $0 = $0 | 0; + var $1 = 0; + for_loop_0 : while (1) { + if ($1 >>> 0 < $0 >>> 0) { + assembly_index_NBodySystem_advance(assembly_index_system); + $1 = $1 + 1 | 0; + continue for_loop_0; + } + break for_loop_0; + }; + } + + function assembly_index_getBody($0) { + $0 = $0 | 0; + var $1 = 0; + $1 = HEAP32[assembly_index_system >> 2]; + if ($0 >>> 0 < (HEAP32[(($1 - 16 | 0) + 12 | 0) >> 2] >>> 2 | 0) >>> 0) { + $0 = HEAP32[(($0 << 2 | 0) + $1 | 0) >> 2] + } else { + $0 = 0 + } + return $0 | 0; + } + + function $start() { + $lib_rt_stub_startOffset = 16; + $lib_rt_stub_offset = 16; + } + + var FUNCTION_TABLE = []; + function __wasm_memory_size() { + return buffer.byteLength / 65536 | 0; + } + + function __wasm_memory_grow(pagesToAdd) { + pagesToAdd = pagesToAdd | 0; + var oldPages = __wasm_memory_size() | 0; + var newPages = oldPages + pagesToAdd | 0; + if ((oldPages < newPages) && (newPages < 65536)) { + var newBuffer = new ArrayBuffer(Math_imul(newPages, 65536)); + var newHEAP8 = new global.Int8Array(newBuffer); + newHEAP8.set(HEAP8); + HEAP8 = newHEAP8; + HEAP8 = new global.Int8Array(newBuffer); + 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; + } + + return { + "memory": Object.create(Object.prototype, { + "grow": { + "value": __wasm_memory_grow + }, + "buffer": { + "get": function () { + return buffer; + } + + } + }), + "init": assembly_index_init, + "step": assembly_index_step, + "bench": assembly_index_bench, + "getBody": assembly_index_getBody + }; +} + +var memasmFunc = new ArrayBuffer(65536); +var retasmFunc = asmFunc({Math,Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,NaN,Infinity}, {abort:function() { throw new Error('abort'); }},memasmFunc); +export var memory = retasmFunc.memory; +export var init = retasmFunc.init; +export var step = retasmFunc.step; +export var bench = retasmFunc.bench; +export var getBody = retasmFunc.getBody; diff --git a/examples/n-body/build/untouched.wat b/examples/n-body/build/untouched.wat deleted file mode 100644 index 4ecd32c47b..0000000000 --- a/examples/n-body/build/untouched.wat +++ /dev/null @@ -1,2167 +0,0 @@ -(module - (type $none_=>_i32 (func (result i32))) - (type $i32_=>_none (func (param i32))) - (type $i32_=>_i32 (func (param i32) (result i32))) - (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) - (type $none_=>_none (func)) - (type $i32_i32_i32_=>_none (func (param i32 i32 i32))) - (type $i32_f64_=>_none (func (param i32 f64))) - (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) - (type $i32_f64_f64_f64_=>_i32 (func (param i32 f64 f64 f64) (result i32))) - (type $i32_f64_f64_f64_f64_f64_f64_f64_=>_i32 (func (param i32 f64 f64 f64 f64 f64 f64 f64) (result i32))) - (type $none_=>_f64 (func (result f64))) - (type $i32_=>_f64 (func (param i32) (result f64))) - (import "env" "memory" (memory $0 0)) - (table $0 1 funcref) - (global $~lib/math/NativeMath.PI f64 (f64.const 3.141592653589793)) - (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/rt/stub/startOffset (mut i32) (i32.const 0)) - (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) - (global $~lib/ASC_SHRINK_LEVEL i32 (i32.const 0)) - (global $~lib/heap/__heap_base i32 (i32.const 8)) - (export "memory" (memory $0)) - (export "init" (func $assembly/index/init)) - (export "step" (func $assembly/index/step)) - (export "bench" (func $assembly/index/bench)) - (export "getBody" (func $assembly/index/getBody)) - (start $~start) - (func $~lib/rt/stub/__retain (; 0 ;) (param $0 i32) (result i32) - local.get $0 - ) - (func $~lib/staticarray/StaticArray#get:length (; 1 ;) (param $0 i32) (result i32) - local.get $0 - i32.const 16 - i32.sub - i32.load offset=12 - i32.const 2 - i32.shr_u - ) - (func $~lib/staticarray/StaticArray#__unchecked_get (; 2 ;) (param $0 i32) (param $1 i32) (result i32) - local.get $0 - local.get $1 - i32.const 2 - i32.shl - i32.add - i32.load - call $~lib/rt/stub/__retain - ) - (func $~lib/rt/stub/__release (; 3 ;) (param $0 i32) - nop - ) - (func $assembly/index/Body#offsetMomentum (; 4 ;) (param $0 i32) (param $1 f64) (param $2 f64) (param $3 f64) (result i32) - local.get $0 - local.get $1 - f64.neg - global.get $assembly/index/SOLAR_MASS - f64.div - f64.store offset=24 - local.get $0 - local.get $2 - f64.neg - global.get $assembly/index/SOLAR_MASS - f64.div - f64.store offset=32 - local.get $0 - local.get $3 - f64.neg - global.get $assembly/index/SOLAR_MASS - f64.div - f64.store offset=40 - local.get $0 - call $~lib/rt/stub/__retain - ) - (func $~lib/rt/stub/maybeGrowMemory (; 5 ;) (param $0 i32) - (local $1 i32) - (local $2 i32) - (local $3 i32) - (local $4 i32) - (local $5 i32) - memory.size - local.set $1 - local.get $1 - i32.const 16 - i32.shl - local.set $2 - local.get $0 - local.get $2 - i32.gt_u - if - local.get $0 - local.get $2 - i32.sub - i32.const 65535 - i32.add - i32.const 65535 - i32.const -1 - i32.xor - i32.and - i32.const 16 - i32.shr_u - local.set $3 - local.get $1 - local.tee $4 - local.get $3 - local.tee $5 - local.get $4 - local.get $5 - i32.gt_s - select - local.set $4 - local.get $4 - memory.grow - i32.const 0 - i32.lt_s - if - local.get $3 - memory.grow - i32.const 0 - i32.lt_s - if - unreachable - end - end - end - local.get $0 - global.set $~lib/rt/stub/offset - ) - (func $~lib/rt/stub/__alloc (; 6 ;) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - (local $3 i32) - (local $4 i32) - (local $5 i32) - (local $6 i32) - local.get $0 - i32.const 1073741808 - i32.gt_u - if - unreachable - end - global.get $~lib/rt/stub/offset - i32.const 16 - i32.add - local.set $2 - local.get $0 - i32.const 15 - i32.add - i32.const 15 - i32.const -1 - i32.xor - i32.and - local.tee $3 - i32.const 16 - local.tee $4 - local.get $3 - local.get $4 - i32.gt_u - select - local.set $5 - local.get $2 - local.get $5 - i32.add - call $~lib/rt/stub/maybeGrowMemory - local.get $2 - i32.const 16 - i32.sub - local.set $6 - local.get $6 - local.get $5 - i32.store - local.get $6 - i32.const 1 - i32.store offset=4 - local.get $6 - local.get $1 - i32.store offset=8 - local.get $6 - local.get $0 - i32.store offset=12 - local.get $2 - ) - (func $assembly/index/NBodySystem#constructor (; 7 ;) (param $0 i32) (param $1 i32) (result i32) - (local $2 f64) - (local $3 f64) - (local $4 f64) - (local $5 i32) - (local $6 i32) - (local $7 i32) - (local $8 i32) - (local $9 i32) - (local $10 f64) - local.get $1 - call $~lib/rt/stub/__retain - local.set $1 - f64.const 0 - local.set $2 - f64.const 0 - local.set $3 - f64.const 0 - local.set $4 - local.get $1 - call $~lib/staticarray/StaticArray#get:length - local.set $5 - i32.const 0 - local.set $6 - loop $for-loop|0 - local.get $6 - local.get $5 - i32.lt_s - local.set $7 - local.get $7 - if - local.get $1 - local.get $6 - call $~lib/staticarray/StaticArray#__unchecked_get - local.tee $8 - call $~lib/rt/stub/__retain - local.set $9 - local.get $9 - f64.load offset=48 - local.set $10 - local.get $2 - local.get $9 - f64.load offset=24 - local.get $10 - f64.mul - f64.add - local.set $2 - local.get $3 - local.get $9 - f64.load offset=32 - local.get $10 - f64.mul - f64.add - local.set $3 - local.get $4 - local.get $9 - f64.load offset=40 - local.get $10 - f64.mul - f64.add - local.set $4 - local.get $8 - call $~lib/rt/stub/__release - local.get $9 - call $~lib/rt/stub/__release - local.get $6 - i32.const 1 - i32.add - local.set $6 - br $for-loop|0 - end - end - local.get $1 - i32.const 0 - call $~lib/staticarray/StaticArray#__unchecked_get - local.tee $6 - local.get $2 - local.get $3 - local.get $4 - call $assembly/index/Body#offsetMomentum - call $~lib/rt/stub/__release - local.get $0 - i32.eqz - if - i32.const 4 - i32.const 3 - call $~lib/rt/stub/__alloc - call $~lib/rt/stub/__retain - local.set $0 - end - local.get $0 - local.get $1 - call $~lib/rt/stub/__retain - i32.store - local.get $6 - call $~lib/rt/stub/__release - local.get $1 - call $~lib/rt/stub/__release - local.get $0 - ) - (func $assembly/index/Body#constructor (; 8 ;) (param $0 i32) (param $1 f64) (param $2 f64) (param $3 f64) (param $4 f64) (param $5 f64) (param $6 f64) (param $7 f64) (result i32) - local.get $0 - i32.eqz - if - i32.const 56 - i32.const 4 - call $~lib/rt/stub/__alloc - call $~lib/rt/stub/__retain - local.set $0 - end - local.get $0 - local.get $1 - f64.store - local.get $0 - local.get $2 - f64.store offset=8 - local.get $0 - local.get $3 - f64.store offset=16 - local.get $0 - local.get $4 - f64.store offset=24 - local.get $0 - local.get $5 - f64.store offset=32 - local.get $0 - local.get $6 - f64.store offset=40 - local.get $0 - local.get $7 - f64.store offset=48 - local.get $0 - ) - (func $assembly/index/Sun (; 9 ;) (result i32) - i32.const 0 - f64.const 0 - f64.const 0 - f64.const 0 - f64.const 0 - f64.const 0 - f64.const 0 - global.get $assembly/index/SOLAR_MASS - call $assembly/index/Body#constructor - ) - (func $assembly/index/Jupiter (; 10 ;) (result i32) - i32.const 0 - f64.const 4.841431442464721 - f64.const -1.1603200440274284 - f64.const -0.10362204447112311 - f64.const 0.001660076642744037 - global.get $assembly/index/DAYS_PER_YEAR - f64.mul - f64.const 0.007699011184197404 - global.get $assembly/index/DAYS_PER_YEAR - f64.mul - f64.const -6.90460016972063e-05 - global.get $assembly/index/DAYS_PER_YEAR - f64.mul - f64.const 9.547919384243266e-04 - global.get $assembly/index/SOLAR_MASS - f64.mul - call $assembly/index/Body#constructor - ) - (func $assembly/index/Saturn (; 11 ;) (result i32) - i32.const 0 - f64.const 8.34336671824458 - f64.const 4.124798564124305 - f64.const -0.4035234171143214 - f64.const -0.002767425107268624 - global.get $assembly/index/DAYS_PER_YEAR - f64.mul - f64.const 0.004998528012349172 - global.get $assembly/index/DAYS_PER_YEAR - f64.mul - f64.const 2.3041729757376393e-05 - global.get $assembly/index/DAYS_PER_YEAR - f64.mul - f64.const 2.858859806661308e-04 - global.get $assembly/index/SOLAR_MASS - f64.mul - call $assembly/index/Body#constructor - ) - (func $assembly/index/Uranus (; 12 ;) (result i32) - i32.const 0 - f64.const 12.894369562139131 - f64.const -15.111151401698631 - f64.const -0.22330757889265573 - f64.const 0.002964601375647616 - global.get $assembly/index/DAYS_PER_YEAR - f64.mul - f64.const 2.3784717395948095e-03 - global.get $assembly/index/DAYS_PER_YEAR - f64.mul - f64.const -2.9658956854023756e-05 - global.get $assembly/index/DAYS_PER_YEAR - f64.mul - f64.const 4.366244043351563e-05 - global.get $assembly/index/SOLAR_MASS - f64.mul - call $assembly/index/Body#constructor - ) - (func $assembly/index/Neptune (; 13 ;) (result i32) - i32.const 0 - f64.const 15.379697114850917 - f64.const -25.919314609987964 - f64.const 0.17925877295037118 - f64.const 2.6806777249038932e-03 - global.get $assembly/index/DAYS_PER_YEAR - f64.mul - f64.const 0.001628241700382423 - global.get $assembly/index/DAYS_PER_YEAR - f64.mul - f64.const -9.515922545197159e-05 - global.get $assembly/index/DAYS_PER_YEAR - f64.mul - f64.const 5.1513890204661145e-05 - global.get $assembly/index/SOLAR_MASS - f64.mul - call $assembly/index/Body#constructor - ) - (func $~lib/util/memory/memcpy (; 14 ;) (param $0 i32) (param $1 i32) (param $2 i32) - (local $3 i32) - (local $4 i32) - (local $5 i32) - (local $6 i32) - loop $while-continue|0 - local.get $2 - if (result i32) - local.get $1 - i32.const 3 - i32.and - else - i32.const 0 - end - local.set $5 - local.get $5 - if - local.get $0 - local.tee $6 - i32.const 1 - i32.add - local.set $0 - local.get $6 - local.get $1 - local.tee $6 - i32.const 1 - i32.add - local.set $1 - local.get $6 - i32.load8_u - i32.store8 - local.get $2 - i32.const 1 - i32.sub - local.set $2 - br $while-continue|0 - end - end - local.get $0 - i32.const 3 - i32.and - i32.const 0 - i32.eq - if - loop $while-continue|1 - local.get $2 - i32.const 16 - i32.ge_u - local.set $5 - local.get $5 - if - local.get $0 - local.get $1 - i32.load - i32.store - local.get $0 - i32.const 4 - i32.add - local.get $1 - i32.const 4 - i32.add - i32.load - i32.store - local.get $0 - i32.const 8 - i32.add - local.get $1 - i32.const 8 - i32.add - i32.load - i32.store - local.get $0 - i32.const 12 - i32.add - local.get $1 - i32.const 12 - i32.add - i32.load - i32.store - local.get $1 - i32.const 16 - i32.add - local.set $1 - local.get $0 - i32.const 16 - i32.add - local.set $0 - local.get $2 - i32.const 16 - i32.sub - local.set $2 - br $while-continue|1 - end - end - local.get $2 - i32.const 8 - i32.and - if - local.get $0 - local.get $1 - i32.load - i32.store - local.get $0 - i32.const 4 - i32.add - local.get $1 - i32.const 4 - i32.add - i32.load - i32.store - local.get $0 - i32.const 8 - i32.add - local.set $0 - local.get $1 - i32.const 8 - i32.add - local.set $1 - end - local.get $2 - i32.const 4 - i32.and - if - local.get $0 - local.get $1 - i32.load - i32.store - local.get $0 - i32.const 4 - i32.add - local.set $0 - local.get $1 - i32.const 4 - i32.add - local.set $1 - end - local.get $2 - i32.const 2 - i32.and - if - local.get $0 - local.get $1 - i32.load16_u - i32.store16 - local.get $0 - i32.const 2 - i32.add - local.set $0 - local.get $1 - i32.const 2 - i32.add - local.set $1 - end - local.get $2 - i32.const 1 - i32.and - if - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - end - return - end - local.get $2 - i32.const 32 - i32.ge_u - if - block $break|2 - block $case2|2 - block $case1|2 - block $case0|2 - local.get $0 - i32.const 3 - i32.and - local.set $5 - local.get $5 - i32.const 1 - i32.eq - br_if $case0|2 - local.get $5 - i32.const 2 - i32.eq - br_if $case1|2 - local.get $5 - i32.const 3 - i32.eq - br_if $case2|2 - br $break|2 - end - local.get $1 - i32.load - local.set $3 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $2 - i32.const 3 - i32.sub - local.set $2 - loop $while-continue|3 - local.get $2 - i32.const 17 - i32.ge_u - local.set $5 - local.get $5 - if - local.get $1 - i32.const 1 - i32.add - i32.load - local.set $4 - local.get $0 - local.get $3 - i32.const 24 - i32.shr_u - local.get $4 - i32.const 8 - i32.shl - i32.or - i32.store - local.get $1 - i32.const 5 - i32.add - i32.load - local.set $3 - local.get $0 - i32.const 4 - i32.add - local.get $4 - i32.const 24 - i32.shr_u - local.get $3 - i32.const 8 - i32.shl - i32.or - i32.store - local.get $1 - i32.const 9 - i32.add - i32.load - local.set $4 - local.get $0 - i32.const 8 - i32.add - local.get $3 - i32.const 24 - i32.shr_u - local.get $4 - i32.const 8 - i32.shl - i32.or - i32.store - local.get $1 - i32.const 13 - i32.add - i32.load - local.set $3 - local.get $0 - i32.const 12 - i32.add - local.get $4 - i32.const 24 - i32.shr_u - local.get $3 - i32.const 8 - i32.shl - i32.or - i32.store - local.get $1 - i32.const 16 - i32.add - local.set $1 - local.get $0 - i32.const 16 - i32.add - local.set $0 - local.get $2 - i32.const 16 - i32.sub - local.set $2 - br $while-continue|3 - end - end - br $break|2 - end - local.get $1 - i32.load - local.set $3 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $2 - i32.const 2 - i32.sub - local.set $2 - loop $while-continue|4 - local.get $2 - i32.const 18 - i32.ge_u - local.set $5 - local.get $5 - if - local.get $1 - i32.const 2 - i32.add - i32.load - local.set $4 - local.get $0 - local.get $3 - i32.const 16 - i32.shr_u - local.get $4 - i32.const 16 - i32.shl - i32.or - i32.store - local.get $1 - i32.const 6 - i32.add - i32.load - local.set $3 - local.get $0 - i32.const 4 - i32.add - local.get $4 - i32.const 16 - i32.shr_u - local.get $3 - i32.const 16 - i32.shl - i32.or - i32.store - local.get $1 - i32.const 10 - i32.add - i32.load - local.set $4 - local.get $0 - i32.const 8 - i32.add - local.get $3 - i32.const 16 - i32.shr_u - local.get $4 - i32.const 16 - i32.shl - i32.or - i32.store - local.get $1 - i32.const 14 - i32.add - i32.load - local.set $3 - local.get $0 - i32.const 12 - i32.add - local.get $4 - i32.const 16 - i32.shr_u - local.get $3 - i32.const 16 - i32.shl - i32.or - i32.store - local.get $1 - i32.const 16 - i32.add - local.set $1 - local.get $0 - i32.const 16 - i32.add - local.set $0 - local.get $2 - i32.const 16 - i32.sub - local.set $2 - br $while-continue|4 - end - end - br $break|2 - end - local.get $1 - i32.load - local.set $3 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $2 - i32.const 1 - i32.sub - local.set $2 - loop $while-continue|5 - local.get $2 - i32.const 19 - i32.ge_u - local.set $5 - local.get $5 - if - local.get $1 - i32.const 3 - i32.add - i32.load - local.set $4 - local.get $0 - local.get $3 - i32.const 8 - i32.shr_u - local.get $4 - i32.const 24 - i32.shl - i32.or - i32.store - local.get $1 - i32.const 7 - i32.add - i32.load - local.set $3 - local.get $0 - i32.const 4 - i32.add - local.get $4 - i32.const 8 - i32.shr_u - local.get $3 - i32.const 24 - i32.shl - i32.or - i32.store - local.get $1 - i32.const 11 - i32.add - i32.load - local.set $4 - local.get $0 - i32.const 8 - i32.add - local.get $3 - i32.const 8 - i32.shr_u - local.get $4 - i32.const 24 - i32.shl - i32.or - i32.store - local.get $1 - i32.const 15 - i32.add - i32.load - local.set $3 - local.get $0 - i32.const 12 - i32.add - local.get $4 - i32.const 8 - i32.shr_u - local.get $3 - i32.const 24 - i32.shl - i32.or - i32.store - local.get $1 - i32.const 16 - i32.add - local.set $1 - local.get $0 - i32.const 16 - i32.add - local.set $0 - local.get $2 - i32.const 16 - i32.sub - local.set $2 - br $while-continue|5 - end - end - br $break|2 - end - end - local.get $2 - i32.const 16 - i32.and - if - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - end - local.get $2 - i32.const 8 - i32.and - if - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - end - local.get $2 - i32.const 4 - i32.and - if - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - end - local.get $2 - i32.const 2 - i32.and - if - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - end - local.get $2 - i32.const 1 - i32.and - if - local.get $0 - local.tee $5 - i32.const 1 - i32.add - local.set $0 - local.get $5 - local.get $1 - local.tee $5 - i32.const 1 - i32.add - local.set $1 - local.get $5 - i32.load8_u - i32.store8 - end - ) - (func $~lib/memory/memory.copy (; 15 ;) (param $0 i32) (param $1 i32) (param $2 i32) - (local $3 i32) - (local $4 i32) - (local $5 i32) - (local $6 i32) - (local $7 i32) - block $~lib/util/memory/memmove|inlined.0 - local.get $0 - local.set $5 - local.get $1 - local.set $4 - local.get $2 - local.set $3 - local.get $5 - local.get $4 - i32.eq - if - br $~lib/util/memory/memmove|inlined.0 - end - local.get $4 - local.get $3 - i32.add - local.get $5 - i32.le_u - if (result i32) - i32.const 1 - else - local.get $5 - local.get $3 - i32.add - local.get $4 - i32.le_u - end - if - local.get $5 - local.get $4 - local.get $3 - call $~lib/util/memory/memcpy - br $~lib/util/memory/memmove|inlined.0 - end - local.get $5 - local.get $4 - i32.lt_u - if - local.get $4 - i32.const 7 - i32.and - local.get $5 - i32.const 7 - i32.and - i32.eq - if - loop $while-continue|0 - local.get $5 - i32.const 7 - i32.and - local.set $6 - local.get $6 - if - local.get $3 - i32.eqz - if - br $~lib/util/memory/memmove|inlined.0 - end - local.get $3 - i32.const 1 - i32.sub - local.set $3 - local.get $5 - local.tee $7 - i32.const 1 - i32.add - local.set $5 - local.get $7 - local.get $4 - local.tee $7 - i32.const 1 - i32.add - local.set $4 - local.get $7 - i32.load8_u - i32.store8 - br $while-continue|0 - end - end - loop $while-continue|1 - local.get $3 - i32.const 8 - i32.ge_u - local.set $6 - local.get $6 - if - local.get $5 - local.get $4 - i64.load - i64.store - local.get $3 - i32.const 8 - i32.sub - local.set $3 - local.get $5 - i32.const 8 - i32.add - local.set $5 - local.get $4 - i32.const 8 - i32.add - local.set $4 - br $while-continue|1 - end - end - end - loop $while-continue|2 - local.get $3 - local.set $6 - local.get $6 - if - local.get $5 - local.tee $7 - i32.const 1 - i32.add - local.set $5 - local.get $7 - local.get $4 - local.tee $7 - i32.const 1 - i32.add - local.set $4 - local.get $7 - i32.load8_u - i32.store8 - local.get $3 - i32.const 1 - i32.sub - local.set $3 - br $while-continue|2 - end - end - else - local.get $4 - i32.const 7 - i32.and - local.get $5 - i32.const 7 - i32.and - i32.eq - if - loop $while-continue|3 - local.get $5 - local.get $3 - i32.add - i32.const 7 - i32.and - local.set $6 - local.get $6 - if - local.get $3 - i32.eqz - if - br $~lib/util/memory/memmove|inlined.0 - end - local.get $5 - local.get $3 - i32.const 1 - i32.sub - local.tee $3 - i32.add - local.get $4 - local.get $3 - i32.add - i32.load8_u - i32.store8 - br $while-continue|3 - end - end - loop $while-continue|4 - local.get $3 - i32.const 8 - i32.ge_u - local.set $6 - local.get $6 - if - local.get $3 - i32.const 8 - i32.sub - local.set $3 - local.get $5 - local.get $3 - i32.add - local.get $4 - local.get $3 - i32.add - i64.load - i64.store - br $while-continue|4 - end - end - end - loop $while-continue|5 - local.get $3 - local.set $6 - local.get $6 - if - local.get $5 - local.get $3 - i32.const 1 - i32.sub - local.tee $3 - i32.add - local.get $4 - local.get $3 - i32.add - i32.load8_u - i32.store8 - br $while-continue|5 - end - end - end - end - ) - (func $~lib/rt/__allocBuffer (; 16 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - (local $3 i32) - local.get $0 - local.get $1 - call $~lib/rt/stub/__alloc - local.set $3 - local.get $2 - if - local.get $3 - local.get $2 - local.get $0 - call $~lib/memory/memory.copy - end - local.get $3 - ) - (func $assembly/index/init (; 17 ;) - (local $0 i32) - (local $1 i32) - i32.const 0 - i32.const 20 - i32.const 5 - i32.const 0 - call $~lib/rt/__allocBuffer - call $~lib/rt/stub/__retain - local.set $0 - local.get $0 - call $assembly/index/Sun - i32.store - local.get $0 - call $assembly/index/Jupiter - i32.store offset=4 - local.get $0 - call $assembly/index/Saturn - i32.store offset=8 - local.get $0 - call $assembly/index/Uranus - i32.store offset=12 - local.get $0 - call $assembly/index/Neptune - i32.store offset=16 - local.get $0 - local.tee $0 - call $assembly/index/NBodySystem#constructor - local.set $1 - global.get $assembly/index/system - call $~lib/rt/stub/__release - local.get $1 - global.set $assembly/index/system - local.get $0 - call $~lib/rt/stub/__release - ) - (func $assembly/index/NBodySystem#advance (; 18 ;) (param $0 i32) (param $1 f64) - (local $2 i32) - (local $3 i32) - (local $4 i32) - (local $5 i32) - (local $6 i32) - (local $7 i32) - (local $8 f64) - (local $9 f64) - (local $10 f64) - (local $11 f64) - (local $12 f64) - (local $13 f64) - (local $14 f64) - (local $15 i32) - (local $16 i32) - (local $17 i32) - (local $18 i32) - (local $19 f64) - (local $20 f64) - (local $21 f64) - (local $22 f64) - (local $23 f64) - (local $24 f64) - (local $25 f64) - (local $26 f64) - local.get $0 - i32.load - call $~lib/rt/stub/__retain - local.set $2 - local.get $2 - call $~lib/staticarray/StaticArray#get:length - local.set $3 - i32.const 0 - local.set $4 - loop $for-loop|0 - local.get $4 - local.get $3 - i32.lt_u - local.set $5 - local.get $5 - if - local.get $2 - local.get $4 - call $~lib/staticarray/StaticArray#__unchecked_get - local.tee $6 - call $~lib/rt/stub/__retain - local.set $7 - local.get $7 - f64.load - local.set $8 - local.get $7 - f64.load offset=8 - local.set $9 - local.get $7 - f64.load offset=16 - local.set $10 - local.get $7 - f64.load offset=24 - local.set $11 - local.get $7 - f64.load offset=32 - local.set $12 - local.get $7 - f64.load offset=40 - local.set $13 - local.get $7 - f64.load offset=48 - local.set $14 - local.get $4 - i32.const 1 - i32.add - local.set $15 - loop $for-loop|1 - local.get $15 - local.get $3 - i32.lt_u - local.set $16 - local.get $16 - if - local.get $2 - local.get $15 - call $~lib/staticarray/StaticArray#__unchecked_get - local.tee $17 - call $~lib/rt/stub/__retain - local.set $18 - local.get $8 - local.get $18 - f64.load - f64.sub - local.set $19 - local.get $9 - local.get $18 - f64.load offset=8 - f64.sub - local.set $20 - local.get $10 - local.get $18 - f64.load offset=16 - f64.sub - local.set $21 - local.get $19 - local.get $19 - f64.mul - local.get $20 - local.get $20 - f64.mul - f64.add - local.get $21 - local.get $21 - f64.mul - f64.add - local.set $22 - local.get $22 - local.set $23 - local.get $23 - f64.sqrt - local.set $23 - local.get $1 - local.get $22 - local.get $23 - f64.mul - f64.div - local.set $24 - local.get $14 - local.get $24 - f64.mul - local.set $25 - local.get $18 - f64.load offset=48 - local.get $24 - f64.mul - local.set $26 - local.get $11 - local.get $19 - local.get $26 - f64.mul - f64.sub - local.set $11 - local.get $12 - local.get $20 - local.get $26 - f64.mul - f64.sub - local.set $12 - local.get $13 - local.get $21 - local.get $26 - f64.mul - f64.sub - local.set $13 - local.get $18 - local.get $18 - f64.load offset=24 - local.get $19 - local.get $25 - f64.mul - f64.add - f64.store offset=24 - local.get $18 - local.get $18 - f64.load offset=32 - local.get $20 - local.get $25 - f64.mul - f64.add - f64.store offset=32 - local.get $18 - local.get $18 - f64.load offset=40 - local.get $21 - local.get $25 - f64.mul - f64.add - f64.store offset=40 - local.get $17 - call $~lib/rt/stub/__release - local.get $18 - call $~lib/rt/stub/__release - local.get $15 - i32.const 1 - i32.add - local.set $15 - br $for-loop|1 - end - end - local.get $7 - local.get $11 - f64.store offset=24 - local.get $7 - local.get $12 - f64.store offset=32 - local.get $7 - local.get $13 - f64.store offset=40 - local.get $7 - local.get $7 - f64.load - local.get $1 - local.get $11 - f64.mul - f64.add - f64.store - local.get $7 - local.get $7 - f64.load offset=8 - local.get $1 - local.get $12 - f64.mul - f64.add - f64.store offset=8 - local.get $7 - local.get $7 - f64.load offset=16 - local.get $1 - local.get $13 - f64.mul - f64.add - f64.store offset=16 - local.get $6 - call $~lib/rt/stub/__release - local.get $7 - call $~lib/rt/stub/__release - local.get $4 - i32.const 1 - i32.add - local.set $4 - br $for-loop|0 - end - end - local.get $2 - call $~lib/rt/stub/__release - ) - (func $assembly/index/NBodySystem#energy (; 19 ;) (param $0 i32) (result f64) - (local $1 f64) - (local $2 i32) - (local $3 i32) - (local $4 i32) - (local $5 i32) - (local $6 i32) - (local $7 i32) - (local $8 f64) - (local $9 f64) - (local $10 f64) - (local $11 f64) - (local $12 f64) - (local $13 f64) - (local $14 f64) - (local $15 i32) - (local $16 i32) - (local $17 i32) - (local $18 i32) - (local $19 f64) - (local $20 f64) - (local $21 f64) - (local $22 f64) - f64.const 0 - local.set $1 - local.get $0 - i32.load - call $~lib/rt/stub/__retain - local.set $2 - i32.const 0 - local.set $3 - local.get $2 - call $~lib/staticarray/StaticArray#get:length - local.set $4 - loop $for-loop|0 - local.get $3 - local.get $4 - i32.lt_u - local.set $5 - local.get $5 - if - local.get $2 - local.get $3 - call $~lib/staticarray/StaticArray#__unchecked_get - local.tee $6 - call $~lib/rt/stub/__retain - local.set $7 - local.get $7 - f64.load - local.set $8 - local.get $7 - f64.load offset=8 - local.set $9 - local.get $7 - f64.load offset=16 - local.set $10 - local.get $7 - f64.load offset=24 - local.set $11 - local.get $7 - f64.load offset=32 - local.set $12 - local.get $7 - f64.load offset=40 - local.set $13 - local.get $7 - f64.load offset=48 - local.set $14 - local.get $1 - f64.const 0.5 - local.get $14 - f64.mul - local.get $11 - local.get $11 - f64.mul - local.get $12 - local.get $12 - f64.mul - f64.add - local.get $13 - local.get $13 - f64.mul - f64.add - f64.mul - f64.add - local.set $1 - local.get $3 - i32.const 1 - i32.add - local.set $15 - loop $for-loop|1 - local.get $15 - local.get $4 - i32.lt_u - local.set $16 - local.get $16 - if - local.get $2 - local.get $15 - call $~lib/staticarray/StaticArray#__unchecked_get - local.tee $17 - call $~lib/rt/stub/__retain - local.set $18 - local.get $8 - local.get $18 - f64.load - f64.sub - local.set $19 - local.get $9 - local.get $18 - f64.load offset=8 - f64.sub - local.set $20 - local.get $10 - local.get $18 - f64.load offset=16 - f64.sub - local.set $21 - local.get $19 - local.get $19 - f64.mul - local.get $20 - local.get $20 - f64.mul - f64.add - local.get $21 - local.get $21 - f64.mul - f64.add - local.set $22 - local.get $22 - f64.sqrt - local.set $22 - local.get $1 - local.get $14 - local.get $18 - f64.load offset=48 - f64.mul - local.get $22 - f64.div - f64.sub - local.set $1 - local.get $17 - call $~lib/rt/stub/__release - local.get $18 - call $~lib/rt/stub/__release - local.get $15 - i32.const 1 - i32.add - local.set $15 - br $for-loop|1 - end - end - local.get $6 - call $~lib/rt/stub/__release - local.get $7 - call $~lib/rt/stub/__release - local.get $3 - i32.const 1 - i32.add - local.set $3 - br $for-loop|0 - end - end - local.get $1 - local.set $14 - local.get $2 - call $~lib/rt/stub/__release - local.get $14 - ) - (func $assembly/index/step (; 20 ;) (result f64) - global.get $assembly/index/system - f64.const 0.01 - call $assembly/index/NBodySystem#advance - global.get $assembly/index/system - call $assembly/index/NBodySystem#energy - ) - (func $assembly/index/bench (; 21 ;) (param $0 i32) - (local $1 i32) - (local $2 i32) - i32.const 0 - local.set $1 - loop $for-loop|0 - local.get $1 - local.get $0 - i32.lt_u - local.set $2 - local.get $2 - if - global.get $assembly/index/system - f64.const 0.01 - call $assembly/index/NBodySystem#advance - local.get $1 - i32.const 1 - i32.add - local.set $1 - br $for-loop|0 - end - end - ) - (func $assembly/index/getBody (; 22 ;) (param $0 i32) (result i32) - (local $1 i32) - (local $2 i32) - global.get $assembly/index/system - i32.load - call $~lib/rt/stub/__retain - local.set $1 - local.get $0 - local.get $1 - call $~lib/staticarray/StaticArray#get:length - i32.lt_u - if (result i32) - local.get $1 - local.get $0 - call $~lib/staticarray/StaticArray#__unchecked_get - local.tee $2 - else - i32.const 0 - call $~lib/rt/stub/__retain - end - local.set $2 - local.get $1 - call $~lib/rt/stub/__release - local.get $2 - ) - (func $~start (; 23 ;) - global.get $~lib/heap/__heap_base - i32.const 15 - i32.add - i32.const 15 - i32.const -1 - i32.xor - i32.and - global.set $~lib/rt/stub/startOffset - global.get $~lib/rt/stub/startOffset - global.set $~lib/rt/stub/offset - ) -) diff --git a/examples/n-body/build/rust.optimized.wasm b/examples/n-body/build/wasm32-unknown-unknown/release/rust_nbody.wasm similarity index 96% rename from examples/n-body/build/rust.optimized.wasm rename to examples/n-body/build/wasm32-unknown-unknown/release/rust_nbody.wasm index 308aa95969..f9025b1e09 100755 Binary files a/examples/n-body/build/rust.optimized.wasm and b/examples/n-body/build/wasm32-unknown-unknown/release/rust_nbody.wasm differ diff --git a/examples/n-body/package.json b/examples/n-body/package.json index 5d0e1bf527..b25b7174ba 100644 --- a/examples/n-body/package.json +++ b/examples/n-body/package.json @@ -3,12 +3,12 @@ "version": "1.0.0", "private": true, "scripts": { - "asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --sourceMap --debug --validate --runtime none --importMemory", - "asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat -O3 --validate --runtime none --noAssert --importMemory", - "asbuild:asmjs": "asc assembly/index.ts -a build/index.asm.js -O3 --validate --runtime none --noAssert && node scripts/postprocess-asmjs", - "asbuild": "npm run asbuild:untouched && npm run asbuild:optimized && npm run asbuild:asmjs", + "asbuild:optimized": "asc assembly/index.ts -b build/as_nbody.wasm -t build/as_nbody.wat -O3 --validate --runtime none --noAssert --importMemory", + "asbuild:asmjs": "asc assembly/index.ts -a build/as_nbody.asm.js -O3 --validate --runtime none --noAssert && node scripts/postprocess-asmjs", + "asbuild": "npm run asbuild:optimized && npm run asbuild:asmjs", "tsbuild": "tsc -p assembly -t ES2017 -m commonjs --outDir build", - "build": "npm run asbuild && npm run tsbuild", + "rsbuild": "cd rust && RUSTFLAGS='-C link-arg=-s' cargo +nightly build --release", + "build": "npm run asbuild && npm run tsbuild && npm run rsbuild", "server": "http-server . -o -c-1", "test": "node --wasm-no-bounds-checks --wasm-no-stack-checks --expose-gc tests" }, diff --git a/examples/n-body/rust/.cargo/config b/examples/n-body/rust/.cargo/config new file mode 100644 index 0000000000..92035adb0a --- /dev/null +++ b/examples/n-body/rust/.cargo/config @@ -0,0 +1,4 @@ +[build] +jobs = 1 +target = "wasm32-unknown-unknown" +target-dir = "../build" diff --git a/examples/n-body/rust/README.md b/examples/n-body/rust/README.md index 2c53c3f4f4..c6bae4ce59 100644 --- a/examples/n-body/rust/README.md +++ b/examples/n-body/rust/README.md @@ -1,7 +1,10 @@ ### Build - ```bash -RUSTFLAGS='-C link-arg=-s' cargo +nightly build --release --target wasm32-unknown-unknown +npm run rsbuild +``` +or +```bash +RUSTFLAGS='-C link-arg=-s' cargo +nightly build --release ``` ***wasm-gc is deprecated. But the same strip effect we could get with RUSTFLAGS='-C link-arg=-s'*** diff --git a/examples/n-body/rust/index.js b/examples/n-body/rust/index.js index febcbb2f21..f2a4c2f37f 100644 --- a/examples/n-body/rust/index.js +++ b/examples/n-body/rust/index.js @@ -2,8 +2,15 @@ const fs = require("fs"); const path = require("path"); const compiled = new WebAssembly.Module( - fs.readFileSync(path.resolve(__dirname, "..", "build", "rust.optimized.wasm")) -); + fs.readFileSync(path.resolve( + __dirname, + "..", + "build", + "wasm32-unknown-unknown", + "release", + "rust_nbody.wasm" + ) +)); const imports = { env: { diff --git a/examples/n-body/rust/src/lib.rs b/examples/n-body/rust/src/lib.rs index ce295d07d0..ccc58df295 100644 --- a/examples/n-body/rust/src/lib.rs +++ b/examples/n-body/rust/src/lib.rs @@ -7,9 +7,8 @@ use core::intrinsics; use core::panic::PanicInfo; #[panic_handler] -#[no_mangle] pub fn panic(_info: &PanicInfo) -> ! { - unsafe { intrinsics::abort() } + loop {} } #[inline(always)] diff --git a/examples/n-body/scripts/postprocess-asmjs.js b/examples/n-body/scripts/postprocess-asmjs.js index d331a75a75..313cd279c4 100644 --- a/examples/n-body/scripts/postprocess-asmjs.js +++ b/examples/n-body/scripts/postprocess-asmjs.js @@ -1,7 +1,7 @@ const fs = require("fs"); const path = require("path"); -const filename = path.join(__dirname, "..", "build" , "index.asm.js"); +const filename = path.join(__dirname, "..", "build" , "as_nbody.asm.js"); var source = fs.readFileSync(filename, { encoding: "utf8" }); source = source.replace(/^export var ([^ ]+) =/mg, ($0, $1) => "exports." + $1 + " = "); fs.writeFileSync(filename, source); diff --git a/examples/n-body/tests/index.js b/examples/n-body/tests/index.js index 8d6c4705f0..d62aa18506 100644 --- a/examples/n-body/tests/index.js +++ b/examples/n-body/tests/index.js @@ -5,7 +5,7 @@ const nbodyAS = require("../assembly/index.js"); const nbodyRS = require("../rust/index.js"); // Load ASMJS version -var src = fs.readFileSync(__dirname + "/../build/index.asm.js", "utf8") +var src = fs.readFileSync(__dirname + "/../build/as_nbody.asm.js", "utf8") .replace(/const retasmFunc[^$]*$/g, ""); const nbodyAsmJS = eval(src + ";asmFunc")({