Update nbody example for Rust (#528)

This commit is contained in:
Max Graey
2019-03-06 22:27:54 +02:00
committed by Daniel Wirtz
parent f841f0fe1f
commit 5f547131ab
6 changed files with 18 additions and 14 deletions

View File

@ -1,3 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "rust_nbody"
version = "0.1.0"

View File

@ -1,7 +1,7 @@
### Build
```bash
cargo build --release --target=wasm32-unknown-unknown
cargo +nightly build --release --target wasm32-unknown-unknown
```
***Next step optimize target wasm via wasm-opt.***
***Next step optimize target wasm via wasm-gc***

View File

@ -8,8 +8,8 @@ const compiled = new WebAssembly.Module(
const imports = {
env: {
memory: new WebAssembly.Memory({ initial: 17 }),
abort: (filename, line, column) => {
throw Error("abort called at " + line + ":" + colum);
abort: (_filename, line, column) => {
throw Error("abort called at " + line + ":" + column);
}
}
};

View File

@ -1,6 +1,6 @@
// Code adopted from https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/nbody-rust-1.html
#![feature(core_intrinsics, panic_implementation)]
#![feature(core_intrinsics)]
#![no_std]
use core::intrinsics;
@ -156,18 +156,18 @@ fn offset_momentum(bodies: &mut [Planet; N_BODIES]) {
}
#[no_mangle]
pub unsafe extern "C" fn init() {
pub unsafe extern fn init() {
offset_momentum(&mut BODIES);
}
#[no_mangle]
pub unsafe extern "C" fn step() -> f64 {
pub unsafe extern fn step() -> f64 {
advance(&mut BODIES, 0.01);
energy(&BODIES)
}
#[no_mangle]
pub unsafe extern "C" fn bench(steps: i32) {
pub unsafe extern fn bench(steps: i32) {
for _ in 0..steps {
advance(&mut BODIES, 0.01);
}