mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-15 07:51:32 +00:00
Update n-body sources and binary for rust. Add bench results (#172)
This commit is contained in:
@ -341,19 +341,6 @@ function asmFunc(global, env, buffer) {
|
||||
assembly_index_system = assembly_index_NBodySystem_constructor(0 | 0, $1 | 0) | 0;
|
||||
}
|
||||
|
||||
function assembly_index_getBody($0) {
|
||||
$0 = $0 | 0;
|
||||
var $1 = 0, $22 = 0, $20 = 0;
|
||||
$1 = HEAPU32[assembly_index_system >> 2] | 0;
|
||||
if ($0 >>> 0 < (HEAP32[($1 + 4 | 0) >> 2] | 0) >>> 0) {
|
||||
$1 = HEAPU32[$1 >> 2] | 0;
|
||||
if ($0 >>> 0 < ((HEAP32[$1 >> 2] | 0) >>> 2 | 0) >>> 0) $20 = HEAPU32[(($1 + ($0 << 2 | 0) | 0) + 8 | 0) >> 2] | 0; else abort();
|
||||
$22 = $20;
|
||||
} else $22 = 0;
|
||||
$0 = $22;
|
||||
return $0 | 0;
|
||||
}
|
||||
|
||||
function assembly_index_NBodySystem_advance($0, $1) {
|
||||
$0 = $0 | 0;
|
||||
$1 = +$1;
|
||||
@ -533,7 +520,6 @@ function asmFunc(global, env, buffer) {
|
||||
}
|
||||
}),
|
||||
init: assembly_index_init,
|
||||
getBody: assembly_index_getBody,
|
||||
step: assembly_index_step,
|
||||
bench: assembly_index_bench
|
||||
};
|
||||
|
@ -1,9 +1,7 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
require("allocator/arena");
|
||||
// From The Computer Language Benchmarks Game
|
||||
// http://benchmarksgame.alioth.debian.org
|
||||
const SOLAR_MASS = 4.0 * Math.PI * Math.PI;
|
||||
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) {
|
||||
@ -44,7 +42,7 @@ class NBodySystem {
|
||||
var py = 0.0;
|
||||
var pz = 0.0;
|
||||
var size = bodies.length;
|
||||
for (let i = 0; i < size; i++) {
|
||||
for (let i = 0; i < size; ++i) {
|
||||
let b = unchecked(bodies[i]);
|
||||
let m = b.mass;
|
||||
px += b.vx * m;
|
||||
@ -107,7 +105,7 @@ class NBodySystem {
|
||||
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 bodyj = unchecked(bodies[j]);
|
||||
let dx = ix - bodyj.x;
|
||||
let dy = iy - bodyj.y;
|
||||
let dz = iz - bodyj.z;
|
||||
@ -129,18 +127,13 @@ function init() {
|
||||
]);
|
||||
}
|
||||
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++)
|
||||
for (let i = 0; i < steps; ++i)
|
||||
system.advance(0.01);
|
||||
}
|
||||
exports.bench = bench;
|
||||
|
Binary file not shown.
@ -10,14 +10,13 @@
|
||||
(type $iF (func (param i32) (result f64)))
|
||||
(type $iv (func (param i32)))
|
||||
(import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32)))
|
||||
(import "env" "memory" (memory $0 1))
|
||||
(global $~lib/allocator/arena/startOffset (mut i32) (i32.const 0))
|
||||
(global $~lib/allocator/arena/offset (mut i32) (i32.const 0))
|
||||
(global $assembly/index/system (mut i32) (i32.const 0))
|
||||
(memory $0 1)
|
||||
(data (i32.const 8) "\0d\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s")
|
||||
(export "memory" (memory $0))
|
||||
(export "init" (func $assembly/index/init))
|
||||
(export "getBody" (func $assembly/index/getBody))
|
||||
(export "step" (func $assembly/index/step))
|
||||
(export "bench" (func $assembly/index/bench))
|
||||
(start $start)
|
||||
@ -823,50 +822,7 @@
|
||||
)
|
||||
)
|
||||
)
|
||||
(func $assembly/index/getBody (; 7 ;) (type $ii) (param $0 i32) (result i32)
|
||||
(local $1 i32)
|
||||
(tee_local $0
|
||||
(if (result i32)
|
||||
(i32.lt_u
|
||||
(get_local $0)
|
||||
(i32.load offset=4
|
||||
(tee_local $1
|
||||
(i32.load
|
||||
(get_global $assembly/index/system)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(if (result i32)
|
||||
(i32.lt_u
|
||||
(get_local $0)
|
||||
(i32.shr_u
|
||||
(i32.load
|
||||
(tee_local $1
|
||||
(i32.load
|
||||
(get_local $1)
|
||||
)
|
||||
)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
(i32.load offset=8
|
||||
(i32.add
|
||||
(get_local $1)
|
||||
(i32.shl
|
||||
(get_local $0)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
(i32.const 0)
|
||||
)
|
||||
)
|
||||
)
|
||||
(func $assembly/index/NBodySystem#advance (; 8 ;) (type $iFv) (param $0 i32) (param $1 f64)
|
||||
(func $assembly/index/NBodySystem#advance (; 7 ;) (type $iFv) (param $0 i32) (param $1 f64)
|
||||
(local $2 i32)
|
||||
(local $3 f64)
|
||||
(local $4 i32)
|
||||
@ -1170,7 +1126,7 @@
|
||||
)
|
||||
)
|
||||
)
|
||||
(func $assembly/index/NBodySystem#energy (; 9 ;) (type $iF) (param $0 i32) (result f64)
|
||||
(func $assembly/index/NBodySystem#energy (; 8 ;) (type $iF) (param $0 i32) (result f64)
|
||||
(local $1 f64)
|
||||
(local $2 i32)
|
||||
(local $3 i32)
|
||||
@ -1367,7 +1323,7 @@
|
||||
)
|
||||
(get_local $1)
|
||||
)
|
||||
(func $assembly/index/step (; 10 ;) (type $F) (result f64)
|
||||
(func $assembly/index/step (; 9 ;) (type $F) (result f64)
|
||||
(call $assembly/index/NBodySystem#advance
|
||||
(get_global $assembly/index/system)
|
||||
(f64.const 0.01)
|
||||
@ -1376,7 +1332,7 @@
|
||||
(get_global $assembly/index/system)
|
||||
)
|
||||
)
|
||||
(func $assembly/index/bench (; 11 ;) (type $iv) (param $0 i32)
|
||||
(func $assembly/index/bench (; 10 ;) (type $iv) (param $0 i32)
|
||||
(local $1 i32)
|
||||
(block $break|0
|
||||
(loop $repeat|0
|
||||
@ -1400,7 +1356,7 @@
|
||||
)
|
||||
)
|
||||
)
|
||||
(func $start (; 12 ;) (type $v)
|
||||
(func $start (; 11 ;) (type $v)
|
||||
(set_global $~lib/allocator/arena/startOffset
|
||||
(i32.const 40)
|
||||
)
|
||||
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user