mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-25 07:02:13 +00:00
Make the game-of-life example a bit more interesting
This moves the entire image buffer to WASM that now also applies some fading.
This commit is contained in:
parent
18ef7c1932
commit
9cd3304e13
@ -1,7 +1,7 @@
|
||||
Conway's Game of Life
|
||||
=====================
|
||||
|
||||
An [AssemblyScript](http://assemblyscript.org) example. Continuously updates the cellular automaton and visualizes its state on a canvas. Compiles to ~450 bytes of optimized WASM.
|
||||
An [AssemblyScript](http://assemblyscript.org) example. Continuously updates the cellular automaton and visualizes its state on a canvas. Compiles to ~750 bytes of optimized WASM.
|
||||
|
||||
Instructions
|
||||
------------
|
||||
|
@ -1,12 +1,41 @@
|
||||
// see: https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life
|
||||
|
||||
const RGB_ALIVE = 0xE692D3;
|
||||
const RGB_DEAD = 0x851BA6;
|
||||
|
||||
var w: i32, h: i32, s: i32;
|
||||
|
||||
/** Gets an input pixel in the range [0, s]. */
|
||||
@inline
|
||||
function get(x: u32, y: u32): u32 {
|
||||
return load<u32>((y * w + x) << 2);
|
||||
}
|
||||
|
||||
/** Sets an output pixel in the range [s, 2*s]. */
|
||||
@inline
|
||||
function set(x: u32, y: u32, v: u32): void {
|
||||
store<u32>((s + y * w + x) << 2, v);
|
||||
}
|
||||
|
||||
/** Sets an output pixel in the range [s, 2*s] while fading it out. */
|
||||
@inline
|
||||
function set_fade(x: u32, y: u32, v: u32): void {
|
||||
var a = max<i32>((v >>> 24) - 7, 0);
|
||||
set(x, y, (a << 24) | (v & 0x00ffffff));
|
||||
}
|
||||
|
||||
/** Initializes width and height. Called once from JS. */
|
||||
export function init(width: i32, height: i32): void {
|
||||
export function init(width: i32, height: i32, seed: f64): void {
|
||||
w = width;
|
||||
h = height;
|
||||
s = width * height;
|
||||
|
||||
// Start by filling output with random live cells.
|
||||
for (let y = 0; y < h; ++y) {
|
||||
for (let x = 0; x < w; ++x) {
|
||||
set(x, y, JSMath.random() > 0.15 ? RGB_DEAD & 0x00ffffff : RGB_ALIVE | 0xff000000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Performs one step. Called about 30 times a second from JS. */
|
||||
@ -18,39 +47,44 @@ export function step(): void {
|
||||
// "cells", each of which is in one of two possible states, alive or dead.
|
||||
for (let y = 0; y < h; ++y) {
|
||||
|
||||
let ym1 = y == 0 ? hm1 : y - 1, // y - 1
|
||||
yp1 = y == hm1 ? 0 : y + 1; // y + 1
|
||||
let ym1 = y == 0 ? hm1 : y - 1,
|
||||
yp1 = y == hm1 ? 0 : y + 1;
|
||||
for (let x = 0; x < w; ++x) {
|
||||
let xm1 = x == 0 ? wm1 : x - 1, // x - 1
|
||||
xp1 = x == wm1 ? 0 : x + 1; // x + 1
|
||||
let xm1 = x == 0 ? wm1 : x - 1,
|
||||
xp1 = x == wm1 ? 0 : x + 1;
|
||||
|
||||
// Every cell interacts with its eight neighbours, which are the cells that are horizontally,
|
||||
// vertically, or diagonally adjacent:
|
||||
let tl = get(xm1, ym1);
|
||||
let tm = get(x , ym1);
|
||||
let tr = get(xp1, ym1);
|
||||
let ml = get(xm1, y );
|
||||
let mm = get(x , y );
|
||||
let mr = get(xp1, y );
|
||||
let bl = get(xm1, yp1);
|
||||
let bm = get(x , yp1);
|
||||
let br = get(xp1, yp1);
|
||||
|
||||
// Least significant bit indicates alive or dead, others are ARGB.
|
||||
let aliveNeighbors = (
|
||||
load<u8>(ym1 * w + xm1) + load<u8>(ym1 * w + x) + load<u8>(ym1 * w + xp1) +
|
||||
load<u8>(y * w + xm1) + load<u8>(y * w + xp1) +
|
||||
load<u8>(yp1 * w + xm1) + load<u8>(yp1 * w + x) + load<u8>(yp1 * w + xp1)
|
||||
(tl & 1) + (tm & 1) + (tr & 1) +
|
||||
(ml & 1) + (mr & 1) +
|
||||
(bl & 1) + (bm & 1) + (br & 1)
|
||||
);
|
||||
|
||||
let alive = load<u8>(y * w + x);
|
||||
let alive = mm & 1;
|
||||
if (alive) {
|
||||
switch (aliveNeighbors) {
|
||||
// A live cell with fewer than 2 live neighbors dies, as if caused by underpopulation.
|
||||
// A live cell with more than 3 live neighbors dies, as if by overpopulation.
|
||||
default: { store<u8>(s + y * w + x, 0); break; }
|
||||
if (aliveNeighbors < 2 || aliveNeighbors > 3) set(x, y, RGB_DEAD | 0xff000000);
|
||||
// A live cell with 2 or 3 live neighbors lives on to the next generation.
|
||||
case 2: case 3:
|
||||
}
|
||||
else set_fade(x, y, mm);
|
||||
} else {
|
||||
switch (aliveNeighbors) {
|
||||
// A dead cell with exactly 3 live neighbors becomes a live cell, as if by reproduction.
|
||||
case 3: { store<u8>(s + y * w + x, 1); break; }
|
||||
default:
|
||||
if (aliveNeighbors == 3) set(x, y, RGB_ALIVE | 0xff000000);
|
||||
// Otherwise the dead cell remains dead.
|
||||
else set_fade(x, y, mm);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Performing a step uses bytes [0, s-1] as the input and writes the output to [s, 2*s-1].
|
||||
// Note that the code above wastes a lot of memory by using one byte per cell.
|
||||
|
Binary file not shown.
@ -1,6 +1,8 @@
|
||||
(module
|
||||
(type $iiv (func (param i32 i32)))
|
||||
(type $iiFv (func (param i32 i32 f64)))
|
||||
(type $F (func (result f64)))
|
||||
(type $v (func))
|
||||
(import "JSMath" "random" (func $~lib/math/JSMath.random (result f64)))
|
||||
(import "env" "memory" (memory $0 1))
|
||||
(global $assembly/index/w (mut i32) (i32.const 0))
|
||||
(global $assembly/index/h (mut i32) (i32.const 0))
|
||||
@ -8,341 +10,97 @@
|
||||
(export "init" (func $assembly/index/init))
|
||||
(export "step" (func $assembly/index/step))
|
||||
(export "memory" (memory $0))
|
||||
(func $assembly/index/init (; 0 ;) (type $iiv) (param $0 i32) (param $1 i32)
|
||||
;;@ assembly/index.ts:7:2
|
||||
(func $assembly/index/init (; 1 ;) (type $iiFv) (param $0 i32) (param $1 i32) (param $2 f64)
|
||||
(local $3 i32)
|
||||
;;@ assembly/index.ts:29:2
|
||||
(set_global $assembly/index/w
|
||||
;;@ assembly/index.ts:7:6
|
||||
;;@ assembly/index.ts:29:6
|
||||
(get_local $0)
|
||||
)
|
||||
;;@ assembly/index.ts:8:2
|
||||
;;@ assembly/index.ts:30:2
|
||||
(set_global $assembly/index/h
|
||||
;;@ assembly/index.ts:8:6
|
||||
;;@ assembly/index.ts:30:6
|
||||
(get_local $1)
|
||||
)
|
||||
;;@ assembly/index.ts:9:2
|
||||
;;@ assembly/index.ts:31:2
|
||||
(set_global $assembly/index/s
|
||||
;;@ assembly/index.ts:9:6
|
||||
;;@ assembly/index.ts:31:6
|
||||
(i32.mul
|
||||
(get_local $0)
|
||||
;;@ assembly/index.ts:9:14
|
||||
;;@ assembly/index.ts:31:14
|
||||
(get_local $1)
|
||||
)
|
||||
)
|
||||
)
|
||||
(func $assembly/index/step (; 1 ;) (type $v)
|
||||
(local $0 i32)
|
||||
(local $1 i32)
|
||||
(local $2 i32)
|
||||
(local $3 i32)
|
||||
(local $4 i32)
|
||||
(local $5 i32)
|
||||
(local $6 i32)
|
||||
(local $7 i32)
|
||||
(set_local $5
|
||||
;;@ assembly/index.ts:14:12
|
||||
(i32.sub
|
||||
(get_global $assembly/index/h)
|
||||
;;@ assembly/index.ts:14:16
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(set_local $6
|
||||
;;@ assembly/index.ts:15:12
|
||||
(i32.sub
|
||||
(get_global $assembly/index/w)
|
||||
;;@ assembly/index.ts:15:16
|
||||
(i32.const 1)
|
||||
)
|
||||
;;@ assembly/index.ts:34:7
|
||||
(set_local $0
|
||||
;;@ assembly/index.ts:34:15
|
||||
(i32.const 0)
|
||||
)
|
||||
(loop $continue|0
|
||||
(if
|
||||
;;@ assembly/index.ts:19:18
|
||||
;;@ assembly/index.ts:34:18
|
||||
(i32.lt_s
|
||||
(get_local $0)
|
||||
;;@ assembly/index.ts:19:22
|
||||
;;@ assembly/index.ts:34:22
|
||||
(get_global $assembly/index/h)
|
||||
)
|
||||
(block
|
||||
(set_local $3
|
||||
;;@ assembly/index.ts:21:14
|
||||
(if (result i32)
|
||||
(get_local $0)
|
||||
;;@ assembly/index.ts:21:29
|
||||
(i32.sub
|
||||
(get_local $0)
|
||||
;;@ assembly/index.ts:21:33
|
||||
(i32.const 1)
|
||||
)
|
||||
;;@ assembly/index.ts:21:23
|
||||
(get_local $5)
|
||||
)
|
||||
)
|
||||
(set_local $4
|
||||
;;@ assembly/index.ts:22:14
|
||||
(if (result i32)
|
||||
(i32.eq
|
||||
(get_local $0)
|
||||
;;@ assembly/index.ts:22:19
|
||||
(get_local $5)
|
||||
)
|
||||
;;@ assembly/index.ts:22:25
|
||||
(i32.const 0)
|
||||
;;@ assembly/index.ts:22:29
|
||||
(i32.add
|
||||
(get_local $0)
|
||||
;;@ assembly/index.ts:22:33
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:23:9
|
||||
;;@ assembly/index.ts:35:9
|
||||
(set_local $1
|
||||
;;@ assembly/index.ts:23:17
|
||||
;;@ assembly/index.ts:35:17
|
||||
(i32.const 0)
|
||||
)
|
||||
(loop $continue|1
|
||||
(if
|
||||
;;@ assembly/index.ts:23:20
|
||||
;;@ assembly/index.ts:35:20
|
||||
(i32.lt_s
|
||||
(get_local $1)
|
||||
;;@ assembly/index.ts:23:24
|
||||
;;@ assembly/index.ts:35:24
|
||||
(get_global $assembly/index/w)
|
||||
)
|
||||
(block
|
||||
;;@ assembly/index.ts:29:6
|
||||
(set_local $2
|
||||
;;@ assembly/index.ts:29:27
|
||||
(i32.add
|
||||
;;@ assembly/index.ts:30:8
|
||||
(i32.add
|
||||
(i32.add
|
||||
(i32.add
|
||||
(i32.add
|
||||
(i32.add
|
||||
(i32.add
|
||||
(i32.load8_u
|
||||
;;@ assembly/index.ts:30:17
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $3)
|
||||
;;@ assembly/index.ts:30:23
|
||||
(get_global $assembly/index/w)
|
||||
)
|
||||
(tee_local $2
|
||||
;;@ assembly/index.ts:24:16
|
||||
(set_local $3
|
||||
;;@ assembly/index.ts:36:16
|
||||
(if (result i32)
|
||||
(get_local $1)
|
||||
;;@ assembly/index.ts:24:31
|
||||
(i32.sub
|
||||
(get_local $1)
|
||||
;;@ assembly/index.ts:24:35
|
||||
(i32.const 1)
|
||||
(f64.gt
|
||||
;;@ assembly/index.ts:36:23
|
||||
(call $~lib/math/JSMath.random)
|
||||
;;@ assembly/index.ts:36:34
|
||||
(f64.const 0.15)
|
||||
)
|
||||
;;@ assembly/index.ts:24:25
|
||||
(get_local $6)
|
||||
;;@ assembly/index.ts:36:41
|
||||
(i32.const 8723366)
|
||||
(i32.const -1666349)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:30:34
|
||||
(i32.load8_u
|
||||
;;@ assembly/index.ts:30:43
|
||||
;;@ assembly/index.ts:17:2
|
||||
(i32.store
|
||||
;;@ assembly/index.ts:17:13
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $3)
|
||||
;;@ assembly/index.ts:30:49
|
||||
(get_global $assembly/index/w)
|
||||
)
|
||||
;;@ assembly/index.ts:30:53
|
||||
(get_local $1)
|
||||
)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:30:58
|
||||
(i32.load8_u
|
||||
;;@ assembly/index.ts:30:67
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $3)
|
||||
;;@ assembly/index.ts:30:73
|
||||
(get_global $assembly/index/w)
|
||||
)
|
||||
(tee_local $7
|
||||
;;@ assembly/index.ts:25:16
|
||||
(if (result i32)
|
||||
(i32.eq
|
||||
(get_local $1)
|
||||
;;@ assembly/index.ts:25:21
|
||||
(get_local $6)
|
||||
)
|
||||
;;@ assembly/index.ts:25:27
|
||||
(i32.const 0)
|
||||
;;@ assembly/index.ts:25:31
|
||||
(i32.add
|
||||
(get_local $1)
|
||||
;;@ assembly/index.ts:25:35
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:31:8
|
||||
(i32.load8_u
|
||||
;;@ assembly/index.ts:31:17
|
||||
;;@ assembly/index.ts:17:14
|
||||
(i32.add
|
||||
(get_global $assembly/index/s)
|
||||
;;@ assembly/index.ts:17:18
|
||||
(i32.mul
|
||||
(get_local $0)
|
||||
;;@ assembly/index.ts:31:23
|
||||
;;@ assembly/index.ts:17:22
|
||||
(get_global $assembly/index/w)
|
||||
)
|
||||
;;@ assembly/index.ts:31:27
|
||||
(get_local $2)
|
||||
)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:31:58
|
||||
(i32.load8_u
|
||||
;;@ assembly/index.ts:31:67
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $0)
|
||||
;;@ assembly/index.ts:31:73
|
||||
(get_global $assembly/index/w)
|
||||
)
|
||||
;;@ assembly/index.ts:31:77
|
||||
(get_local $7)
|
||||
)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:32:8
|
||||
(i32.load8_u
|
||||
;;@ assembly/index.ts:32:17
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $4)
|
||||
;;@ assembly/index.ts:32:23
|
||||
(get_global $assembly/index/w)
|
||||
)
|
||||
;;@ assembly/index.ts:32:27
|
||||
(get_local $2)
|
||||
)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:32:34
|
||||
(i32.load8_u
|
||||
;;@ assembly/index.ts:32:43
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $4)
|
||||
;;@ assembly/index.ts:32:49
|
||||
(get_global $assembly/index/w)
|
||||
)
|
||||
;;@ assembly/index.ts:32:53
|
||||
;;@ assembly/index.ts:17:26
|
||||
(get_local $1)
|
||||
)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:32:58
|
||||
(i32.load8_u
|
||||
;;@ assembly/index.ts:32:67
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $4)
|
||||
;;@ assembly/index.ts:32:73
|
||||
(get_global $assembly/index/w)
|
||||
)
|
||||
;;@ assembly/index.ts:32:77
|
||||
(get_local $7)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:36:6
|
||||
(if
|
||||
;;@ assembly/index.ts:35:18
|
||||
(i32.load8_u
|
||||
;;@ assembly/index.ts:35:27
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $0)
|
||||
;;@ assembly/index.ts:35:31
|
||||
(get_global $assembly/index/w)
|
||||
)
|
||||
;;@ assembly/index.ts:35:35
|
||||
(get_local $1)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:37:8
|
||||
(block $break|2
|
||||
(br_if $break|2
|
||||
(i32.eq
|
||||
;;@ assembly/index.ts:37:16
|
||||
(get_local $2)
|
||||
;;@ assembly/index.ts:42:15
|
||||
;;@ assembly/index.ts:17:32
|
||||
(i32.const 2)
|
||||
)
|
||||
;;@ assembly/index.ts:17:35
|
||||
(get_local $3)
|
||||
)
|
||||
(br_if $break|2
|
||||
(i32.eq
|
||||
(get_local $2)
|
||||
;;@ assembly/index.ts:42:23
|
||||
(i32.const 3)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:40:21
|
||||
(i32.store8
|
||||
;;@ assembly/index.ts:40:31
|
||||
(i32.add
|
||||
(i32.add
|
||||
(get_global $assembly/index/s)
|
||||
;;@ assembly/index.ts:40:35
|
||||
(i32.mul
|
||||
(get_local $0)
|
||||
;;@ assembly/index.ts:40:39
|
||||
(get_global $assembly/index/w)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:40:43
|
||||
(get_local $1)
|
||||
)
|
||||
;;@ assembly/index.ts:40:46
|
||||
(i32.const 0)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.eq
|
||||
;;@ assembly/index.ts:45:16
|
||||
(get_local $2)
|
||||
;;@ assembly/index.ts:47:15
|
||||
(i32.const 3)
|
||||
)
|
||||
;;@ assembly/index.ts:47:20
|
||||
(i32.store8
|
||||
;;@ assembly/index.ts:47:30
|
||||
(i32.add
|
||||
(i32.add
|
||||
(get_global $assembly/index/s)
|
||||
;;@ assembly/index.ts:47:34
|
||||
(i32.mul
|
||||
(get_local $0)
|
||||
;;@ assembly/index.ts:47:38
|
||||
(get_global $assembly/index/w)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:47:42
|
||||
(get_local $1)
|
||||
)
|
||||
;;@ assembly/index.ts:47:45
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:23:27
|
||||
;;@ assembly/index.ts:35:27
|
||||
(set_local $1
|
||||
(i32.add
|
||||
;;@ assembly/index.ts:23:29
|
||||
;;@ assembly/index.ts:35:29
|
||||
(get_local $1)
|
||||
(i32.const 1)
|
||||
)
|
||||
@ -351,10 +109,526 @@
|
||||
)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:19:25
|
||||
;;@ assembly/index.ts:34:25
|
||||
(set_local $0
|
||||
(i32.add
|
||||
;;@ assembly/index.ts:19:27
|
||||
;;@ assembly/index.ts:34:27
|
||||
(get_local $0)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(br $continue|0)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(func $assembly/index/step (; 2 ;) (type $v)
|
||||
(local $0 i32)
|
||||
(local $1 i32)
|
||||
(local $2 i32)
|
||||
(local $3 i32)
|
||||
(local $4 i32)
|
||||
(local $5 i32)
|
||||
(local $6 i32)
|
||||
(local $7 i32)
|
||||
(local $8 i32)
|
||||
(set_local $7
|
||||
;;@ assembly/index.ts:43:12
|
||||
(i32.sub
|
||||
(get_global $assembly/index/h)
|
||||
;;@ assembly/index.ts:43:16
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(set_local $8
|
||||
;;@ assembly/index.ts:44:12
|
||||
(i32.sub
|
||||
(get_global $assembly/index/w)
|
||||
;;@ assembly/index.ts:44:16
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(loop $continue|0
|
||||
(if
|
||||
;;@ assembly/index.ts:48:18
|
||||
(i32.lt_s
|
||||
(get_local $0)
|
||||
;;@ assembly/index.ts:48:22
|
||||
(get_global $assembly/index/h)
|
||||
)
|
||||
(block
|
||||
(set_local $5
|
||||
;;@ assembly/index.ts:50:14
|
||||
(if (result i32)
|
||||
(get_local $0)
|
||||
;;@ assembly/index.ts:50:29
|
||||
(i32.sub
|
||||
(get_local $0)
|
||||
;;@ assembly/index.ts:50:33
|
||||
(i32.const 1)
|
||||
)
|
||||
;;@ assembly/index.ts:50:23
|
||||
(get_local $7)
|
||||
)
|
||||
)
|
||||
(set_local $6
|
||||
;;@ assembly/index.ts:51:14
|
||||
(if (result i32)
|
||||
(i32.eq
|
||||
(get_local $0)
|
||||
;;@ assembly/index.ts:51:19
|
||||
(get_local $7)
|
||||
)
|
||||
;;@ assembly/index.ts:51:25
|
||||
(i32.const 0)
|
||||
;;@ assembly/index.ts:51:29
|
||||
(i32.add
|
||||
(get_local $0)
|
||||
;;@ assembly/index.ts:51:33
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:52:9
|
||||
(set_local $1
|
||||
;;@ assembly/index.ts:52:17
|
||||
(i32.const 0)
|
||||
)
|
||||
(loop $continue|1
|
||||
(if
|
||||
;;@ assembly/index.ts:52:20
|
||||
(i32.lt_s
|
||||
(get_local $1)
|
||||
;;@ assembly/index.ts:52:24
|
||||
(get_global $assembly/index/w)
|
||||
)
|
||||
(block
|
||||
;;@ assembly/index.ts:62:6
|
||||
(set_local $4
|
||||
(i32.load
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.mul
|
||||
;;@ assembly/index.ts:62:24
|
||||
(get_local $0)
|
||||
(get_global $assembly/index/w)
|
||||
)
|
||||
;;@ assembly/index.ts:62:19
|
||||
(get_local $1)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:69:6
|
||||
(set_local $2
|
||||
;;@ assembly/index.ts:69:27
|
||||
(i32.add
|
||||
;;@ assembly/index.ts:70:8
|
||||
(i32.add
|
||||
(i32.add
|
||||
(i32.add
|
||||
(i32.add
|
||||
(i32.add
|
||||
(i32.add
|
||||
(i32.and
|
||||
(i32.load
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.mul
|
||||
;;@ assembly/index.ts:58:24
|
||||
(get_local $5)
|
||||
(get_global $assembly/index/w)
|
||||
)
|
||||
(tee_local $2
|
||||
;;@ assembly/index.ts:53:16
|
||||
(if (result i32)
|
||||
(get_local $1)
|
||||
;;@ assembly/index.ts:53:31
|
||||
(i32.sub
|
||||
(get_local $1)
|
||||
;;@ assembly/index.ts:53:35
|
||||
(i32.const 1)
|
||||
)
|
||||
;;@ assembly/index.ts:53:25
|
||||
(get_local $8)
|
||||
)
|
||||
)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:70:14
|
||||
(i32.const 1)
|
||||
)
|
||||
;;@ assembly/index.ts:70:19
|
||||
(i32.and
|
||||
(i32.load
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.mul
|
||||
;;@ assembly/index.ts:59:24
|
||||
(get_local $5)
|
||||
(get_global $assembly/index/w)
|
||||
)
|
||||
;;@ assembly/index.ts:59:19
|
||||
(get_local $1)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:70:25
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:70:30
|
||||
(i32.and
|
||||
(i32.load
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.mul
|
||||
;;@ assembly/index.ts:60:24
|
||||
(get_local $5)
|
||||
(get_global $assembly/index/w)
|
||||
)
|
||||
(tee_local $3
|
||||
;;@ assembly/index.ts:54:16
|
||||
(if (result i32)
|
||||
(i32.eq
|
||||
(get_local $1)
|
||||
;;@ assembly/index.ts:54:21
|
||||
(get_local $8)
|
||||
)
|
||||
;;@ assembly/index.ts:54:27
|
||||
(i32.const 0)
|
||||
;;@ assembly/index.ts:54:31
|
||||
(i32.add
|
||||
(get_local $1)
|
||||
;;@ assembly/index.ts:54:35
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:70:36
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:71:8
|
||||
(i32.and
|
||||
(i32.load
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.mul
|
||||
;;@ assembly/index.ts:61:24
|
||||
(get_local $0)
|
||||
(get_global $assembly/index/w)
|
||||
)
|
||||
;;@ assembly/index.ts:61:19
|
||||
(get_local $2)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:71:14
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:71:30
|
||||
(i32.and
|
||||
(i32.load
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.mul
|
||||
;;@ assembly/index.ts:63:24
|
||||
(get_local $0)
|
||||
(get_global $assembly/index/w)
|
||||
)
|
||||
;;@ assembly/index.ts:63:19
|
||||
(get_local $3)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:71:36
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:72:8
|
||||
(i32.and
|
||||
(i32.load
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.mul
|
||||
;;@ assembly/index.ts:64:24
|
||||
(get_local $6)
|
||||
(get_global $assembly/index/w)
|
||||
)
|
||||
;;@ assembly/index.ts:64:19
|
||||
(get_local $2)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:72:14
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:72:19
|
||||
(i32.and
|
||||
(i32.load
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.mul
|
||||
;;@ assembly/index.ts:65:24
|
||||
(get_local $6)
|
||||
(get_global $assembly/index/w)
|
||||
)
|
||||
;;@ assembly/index.ts:65:19
|
||||
(get_local $1)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:72:25
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:72:30
|
||||
(i32.and
|
||||
;;@ assembly/index.ts:11:9
|
||||
(i32.load
|
||||
;;@ assembly/index.ts:11:19
|
||||
(i32.shl
|
||||
(i32.add
|
||||
;;@ assembly/index.ts:11:20
|
||||
(i32.mul
|
||||
;;@ assembly/index.ts:66:24
|
||||
(get_local $6)
|
||||
;;@ assembly/index.ts:11:24
|
||||
(get_global $assembly/index/w)
|
||||
)
|
||||
;;@ assembly/index.ts:66:19
|
||||
(get_local $3)
|
||||
)
|
||||
;;@ assembly/index.ts:11:34
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:72:36
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:76:6
|
||||
(if
|
||||
;;@ assembly/index.ts:75:18
|
||||
(i32.and
|
||||
(get_local $4)
|
||||
;;@ assembly/index.ts:75:23
|
||||
(i32.const 1)
|
||||
)
|
||||
;;@ assembly/index.ts:79:8
|
||||
(if
|
||||
;;@ assembly/index.ts:79:12
|
||||
(i32.and
|
||||
(if (result i32)
|
||||
(tee_local $3
|
||||
(i32.lt_u
|
||||
(get_local $2)
|
||||
;;@ assembly/index.ts:79:29
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
(get_local $3)
|
||||
;;@ assembly/index.ts:79:34
|
||||
(i32.gt_u
|
||||
(get_local $2)
|
||||
;;@ assembly/index.ts:79:51
|
||||
(i32.const 3)
|
||||
)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
(i32.store
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.add
|
||||
(get_global $assembly/index/s)
|
||||
(i32.mul
|
||||
;;@ assembly/index.ts:79:61
|
||||
(get_local $0)
|
||||
(get_global $assembly/index/w)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:79:58
|
||||
(get_local $1)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
(i32.const -8053850)
|
||||
)
|
||||
(i32.store
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.add
|
||||
(get_global $assembly/index/s)
|
||||
(i32.mul
|
||||
;;@ assembly/index.ts:81:25
|
||||
(get_local $0)
|
||||
(get_global $assembly/index/w)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:81:22
|
||||
(get_local $1)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
(i32.or
|
||||
(i32.shl
|
||||
(tee_local $4
|
||||
(select
|
||||
(tee_local $4
|
||||
(i32.sub
|
||||
(i32.shr_u
|
||||
(tee_local $3
|
||||
;;@ assembly/index.ts:81:28
|
||||
(get_local $4)
|
||||
)
|
||||
(i32.const 24)
|
||||
)
|
||||
(i32.const 7)
|
||||
)
|
||||
)
|
||||
(tee_local $2
|
||||
(i32.const 0)
|
||||
)
|
||||
(i32.gt_s
|
||||
(get_local $4)
|
||||
(i32.const 0)
|
||||
)
|
||||
)
|
||||
)
|
||||
(i32.const 24)
|
||||
)
|
||||
(i32.and
|
||||
(get_local $3)
|
||||
(i32.const 16777215)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:84:8
|
||||
(if
|
||||
;;@ assembly/index.ts:84:12
|
||||
(i32.eq
|
||||
(get_local $2)
|
||||
;;@ assembly/index.ts:84:30
|
||||
(i32.const 3)
|
||||
)
|
||||
(i32.store
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.add
|
||||
(get_global $assembly/index/s)
|
||||
(i32.mul
|
||||
;;@ assembly/index.ts:84:40
|
||||
(get_local $0)
|
||||
(get_global $assembly/index/w)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:84:37
|
||||
(get_local $1)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
(i32.const -1666349)
|
||||
)
|
||||
;;@ assembly/index.ts:17:2
|
||||
(i32.store
|
||||
;;@ assembly/index.ts:17:13
|
||||
(i32.shl
|
||||
(i32.add
|
||||
;;@ assembly/index.ts:17:14
|
||||
(i32.add
|
||||
(get_global $assembly/index/s)
|
||||
;;@ assembly/index.ts:17:18
|
||||
(i32.mul
|
||||
;;@ assembly/index.ts:86:25
|
||||
(get_local $0)
|
||||
;;@ assembly/index.ts:17:22
|
||||
(get_global $assembly/index/w)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:86:22
|
||||
(get_local $1)
|
||||
)
|
||||
;;@ assembly/index.ts:17:32
|
||||
(i32.const 2)
|
||||
)
|
||||
;;@ assembly/index.ts:24:12
|
||||
(i32.or
|
||||
(i32.shl
|
||||
;;@ assembly/index.ts:23:2
|
||||
(tee_local $2
|
||||
;;@ assembly/index.ts:23:10
|
||||
(select
|
||||
(tee_local $2
|
||||
;;@ assembly/index.ts:23:19
|
||||
(i32.sub
|
||||
(i32.shr_u
|
||||
;;@ assembly/index.ts:86:28
|
||||
(get_local $4)
|
||||
;;@ assembly/index.ts:23:26
|
||||
(i32.const 24)
|
||||
)
|
||||
;;@ assembly/index.ts:23:32
|
||||
(i32.const 7)
|
||||
)
|
||||
)
|
||||
(tee_local $3
|
||||
;;@ assembly/index.ts:23:35
|
||||
(i32.const 0)
|
||||
)
|
||||
(i32.gt_s
|
||||
(get_local $2)
|
||||
(i32.const 0)
|
||||
)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:24:18
|
||||
(i32.const 24)
|
||||
)
|
||||
;;@ assembly/index.ts:24:24
|
||||
(i32.and
|
||||
;;@ assembly/index.ts:24:25
|
||||
(get_local $4)
|
||||
;;@ assembly/index.ts:24:29
|
||||
(i32.const 16777215)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:52:27
|
||||
(set_local $1
|
||||
(i32.add
|
||||
;;@ assembly/index.ts:52:29
|
||||
(get_local $1)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(br $continue|1)
|
||||
)
|
||||
)
|
||||
)
|
||||
;;@ assembly/index.ts:48:25
|
||||
(set_local $0
|
||||
(i32.add
|
||||
;;@ assembly/index.ts:48:27
|
||||
(get_local $0)
|
||||
(i32.const 1)
|
||||
)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -6,8 +6,8 @@
|
||||
html, body { height: 100%; margin: 0; overflow: hidden; color: #111; background: #fff; font-family: sans-serif; }
|
||||
h1 { padding: 20px; font-size: 12pt; margin: 0; }
|
||||
a { color: #111; text-decoration: none; }
|
||||
a:hover { color: #851ba7; text-decoration: underline; }
|
||||
canvas { position: absolute; top: 60px; left: 20px; width: calc(100% - 40px); height: calc(100% - 80px); background: #eee; }
|
||||
a:hover { color: #bc18d4; text-decoration: underline; }
|
||||
canvas { position: absolute; top: 60px; left: 20px; width: calc(100% - 40px); height: calc(100% - 80px); background: #100707; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@ -17,7 +17,7 @@ canvas { position: absolute; top: 60px; left: 20px; width: calc(100% - 40px); he
|
||||
( <a href="https://github.com/AssemblyScript/assemblyscript/blob/master/examples/game-of-life/assembly/index.ts">source</a> )
|
||||
</h1>
|
||||
<canvas></canvas>
|
||||
<script>
|
||||
<script>"use strict";
|
||||
|
||||
// Set up the canvas with a 2D rendering context
|
||||
var cnv = document.getElementsByTagName("canvas")[0];
|
||||
@ -28,11 +28,11 @@ var bcr = cnv.getBoundingClientRect();
|
||||
var width = bcr.width >>> 1;
|
||||
var height = bcr.height >>> 1;
|
||||
var size = width * height;
|
||||
var byteSize = size + size; // input & output
|
||||
var byteSize = (size + size) << 2; // input & output (here: 4b per cell)
|
||||
|
||||
cnv.width = width;
|
||||
cnv.height = height;
|
||||
cnv.style = style = `
|
||||
cnv.style = `
|
||||
image-rendering: optimizeSpeed;
|
||||
image-rendering: -moz-crisp-edges;
|
||||
image-rendering: -webkit-optimize-contrast;
|
||||
@ -49,43 +49,36 @@ var memory = new WebAssembly.Memory({ initial: ((byteSize + 0xffff) & ~0xffff) >
|
||||
fetch("build/optimized.wasm")
|
||||
.then(response => response.arrayBuffer())
|
||||
.then(buffer => WebAssembly.instantiate(buffer, {
|
||||
env: { memory: memory }
|
||||
env: { memory: memory, abort: function() {} },
|
||||
JSMath: Math
|
||||
}))
|
||||
.then(module => {
|
||||
var exports = module.instance.exports;
|
||||
|
||||
// Tell the module about the universe's width and height
|
||||
exports.init(width, height);
|
||||
// Initialize the module with the universe's width and height
|
||||
exports.init(width, height, Math.random());
|
||||
|
||||
// Fill input at [0, s-1] with random live cells
|
||||
var mem = new Uint8Array(memory.buffer);
|
||||
for (var y = 0; y < height; ++y)
|
||||
for (var x = 0; x < width; ++x)
|
||||
mem[y * width + x] = Math.random() > 0.1 ? 0 : 1;
|
||||
var mem = new Uint32Array(memory.buffer);
|
||||
|
||||
// Update about 30 times a second
|
||||
(function update() {
|
||||
setTimeout(update, 1000 / 30);
|
||||
exports.step();
|
||||
mem.copyWithin(0, size, byteSize); // copy output to input
|
||||
mem.copyWithin(0, size, size + size); // copy output to input
|
||||
exports.step(); // perform the next step
|
||||
})();
|
||||
|
||||
// Keep rendering the output at [s, S]
|
||||
// Keep rendering the output at [size, 2*size]
|
||||
var imageData = ctx.createImageData(width, height);
|
||||
var argb = new Uint32Array(imageData.data.buffer);
|
||||
(function render() {
|
||||
requestAnimationFrame(render);
|
||||
var imageData = ctx.createImageData(width, height);
|
||||
var colors = new Uint32Array(imageData.data.buffer);
|
||||
for (let y = 0; y < height; ++y) {
|
||||
for (let x = 0; x < width; ++x) {
|
||||
if (mem[size + y * width + x]) colors[y * width + x] = 0xff851ba7;
|
||||
}
|
||||
}
|
||||
ctx.putImageData(imageData, 0, 0);
|
||||
argb.set(mem.subarray(size, size + size)); // copy output to image buffer
|
||||
ctx.putImageData(imageData, 0, 0); // apply image buffer
|
||||
})();
|
||||
|
||||
}).catch(err => {
|
||||
alert("Failed to load WASM: " + err.message + " (ad blocker, maybe?)");
|
||||
throw err;
|
||||
console.log(err.stack);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
@ -17,7 +17,7 @@ canvas { position: absolute; top: 60px; left: 20px; width: calc(100% - 40px); he
|
||||
( <a href="https://github.com/AssemblyScript/assemblyscript/blob/master/examples/mandelbrot/assembly/index.ts">source</a> )
|
||||
</h1>
|
||||
<canvas></canvas>
|
||||
<script>
|
||||
<script>"use strict";
|
||||
|
||||
// Set up a 2D rendering context
|
||||
var cnv = document.getElementsByTagName("canvas")[0];
|
||||
|
@ -1,6 +1,8 @@
|
||||
(module
|
||||
(type $iiv (func (param i32 i32)))
|
||||
(type $iiFv (func (param i32 i32 f64)))
|
||||
(type $F (func (result f64)))
|
||||
(type $v (func))
|
||||
(import "JSMath" "random" (func $~lib/math/JSMath.random (result f64)))
|
||||
(global $../../examples/game-of-life/assembly/index/w (mut i32) (i32.const 0))
|
||||
(global $../../examples/game-of-life/assembly/index/h (mut i32) (i32.const 0))
|
||||
(global $../../examples/game-of-life/assembly/index/s (mut i32) (i32.const 0))
|
||||
@ -8,7 +10,10 @@
|
||||
(export "init" (func $../../examples/game-of-life/assembly/index/init))
|
||||
(export "step" (func $../../examples/game-of-life/assembly/index/step))
|
||||
(export "memory" (memory $0))
|
||||
(func $../../examples/game-of-life/assembly/index/init (; 0 ;) (type $iiv) (param $0 i32) (param $1 i32)
|
||||
(func $../../examples/game-of-life/assembly/index/init (; 1 ;) (type $iiFv) (param $0 i32) (param $1 i32) (param $2 f64)
|
||||
(local $3 i32)
|
||||
(local $4 i32)
|
||||
(local $5 i32)
|
||||
(set_global $../../examples/game-of-life/assembly/index/w
|
||||
(get_local $0)
|
||||
)
|
||||
@ -21,8 +26,80 @@
|
||||
(get_local $1)
|
||||
)
|
||||
)
|
||||
(set_local $0
|
||||
(i32.const 0)
|
||||
)
|
||||
(func $../../examples/game-of-life/assembly/index/step (; 1 ;) (type $v)
|
||||
(loop $continue|0
|
||||
(if
|
||||
(i32.lt_s
|
||||
(get_local $0)
|
||||
(get_global $../../examples/game-of-life/assembly/index/h)
|
||||
)
|
||||
(block
|
||||
(set_local $1
|
||||
(i32.const 0)
|
||||
)
|
||||
(loop $continue|1
|
||||
(if
|
||||
(i32.lt_s
|
||||
(get_local $1)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
(block
|
||||
(set_local $3
|
||||
(get_local $1)
|
||||
)
|
||||
(set_local $4
|
||||
(get_local $0)
|
||||
)
|
||||
(set_local $5
|
||||
(if (result i32)
|
||||
(f64.gt
|
||||
(call $~lib/math/JSMath.random)
|
||||
(f64.const 0.15)
|
||||
)
|
||||
(i32.const 8723366)
|
||||
(i32.const -1666349)
|
||||
)
|
||||
)
|
||||
(i32.store
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.add
|
||||
(get_global $../../examples/game-of-life/assembly/index/s)
|
||||
(i32.mul
|
||||
(get_local $4)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
)
|
||||
(get_local $3)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
(get_local $5)
|
||||
)
|
||||
(set_local $1
|
||||
(i32.add
|
||||
(get_local $1)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(br $continue|1)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $0
|
||||
(i32.add
|
||||
(get_local $0)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(br $continue|0)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(func $../../examples/game-of-life/assembly/index/step (; 2 ;) (type $v)
|
||||
(local $0 i32)
|
||||
(local $1 i32)
|
||||
(local $2 i32)
|
||||
@ -31,13 +108,14 @@
|
||||
(local $5 i32)
|
||||
(local $6 i32)
|
||||
(local $7 i32)
|
||||
(set_local $5
|
||||
(local $8 i32)
|
||||
(set_local $7
|
||||
(i32.sub
|
||||
(get_global $../../examples/game-of-life/assembly/index/h)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(set_local $6
|
||||
(set_local $8
|
||||
(i32.sub
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
(i32.const 1)
|
||||
@ -50,17 +128,17 @@
|
||||
(get_global $../../examples/game-of-life/assembly/index/h)
|
||||
)
|
||||
(block
|
||||
(set_local $3
|
||||
(set_local $5
|
||||
(select
|
||||
(i32.sub
|
||||
(get_local $0)
|
||||
(i32.const 1)
|
||||
)
|
||||
(get_local $5)
|
||||
(get_local $7)
|
||||
(get_local $0)
|
||||
)
|
||||
)
|
||||
(set_local $4
|
||||
(set_local $6
|
||||
(select
|
||||
(i32.const 0)
|
||||
(i32.add
|
||||
@ -69,7 +147,7 @@
|
||||
)
|
||||
(i32.eq
|
||||
(get_local $0)
|
||||
(get_local $5)
|
||||
(get_local $7)
|
||||
)
|
||||
)
|
||||
)
|
||||
@ -91,10 +169,12 @@
|
||||
(i32.add
|
||||
(i32.add
|
||||
(i32.add
|
||||
(i32.load8_u
|
||||
(i32.and
|
||||
(i32.load
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $3)
|
||||
(get_local $5)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
(tee_local $2
|
||||
@ -103,29 +183,41 @@
|
||||
(get_local $1)
|
||||
(i32.const 1)
|
||||
)
|
||||
(get_local $6)
|
||||
(get_local $8)
|
||||
(get_local $1)
|
||||
)
|
||||
)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
(i32.load8_u
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
(i32.and
|
||||
(i32.load
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $3)
|
||||
(get_local $5)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
(get_local $1)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
(i32.load8_u
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(i32.and
|
||||
(i32.load
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $3)
|
||||
(get_local $5)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
(tee_local $7
|
||||
(tee_local $3
|
||||
(select
|
||||
(i32.const 0)
|
||||
(i32.add
|
||||
@ -134,66 +226,103 @@
|
||||
)
|
||||
(i32.eq
|
||||
(get_local $1)
|
||||
(get_local $8)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(i32.and
|
||||
(i32.load
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $0)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
(get_local $2)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(i32.and
|
||||
(i32.load
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $0)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
(get_local $3)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(i32.and
|
||||
(i32.load
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $6)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(i32.load8_u
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $0)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
(get_local $2)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
(i32.load8_u
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(i32.and
|
||||
(i32.load
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $0)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
(get_local $7)
|
||||
)
|
||||
)
|
||||
)
|
||||
(i32.load8_u
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $4)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
(get_local $2)
|
||||
)
|
||||
)
|
||||
)
|
||||
(i32.load8_u
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $4)
|
||||
(get_local $6)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
(get_local $1)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
(i32.load8_u
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(i32.and
|
||||
(i32.load
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $4)
|
||||
(get_local $6)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
(get_local $7)
|
||||
(get_local $3)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.load8_u
|
||||
(i32.and
|
||||
(tee_local $4
|
||||
(i32.load
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $0)
|
||||
@ -201,21 +330,31 @@
|
||||
)
|
||||
(get_local $1)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
(if
|
||||
(i32.eqz
|
||||
(i32.or
|
||||
(i32.eq
|
||||
(i32.and
|
||||
(if (result i32)
|
||||
(tee_local $3
|
||||
(i32.lt_u
|
||||
(get_local $2)
|
||||
(i32.const 2)
|
||||
)
|
||||
(i32.eq
|
||||
)
|
||||
(get_local $3)
|
||||
(i32.gt_u
|
||||
(get_local $2)
|
||||
(i32.const 3)
|
||||
)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
(i32.store8
|
||||
(i32.store
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.add
|
||||
(get_global $../../examples/game-of-life/assembly/index/s)
|
||||
@ -226,15 +365,64 @@
|
||||
)
|
||||
(get_local $1)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
(i32.const -8053850)
|
||||
)
|
||||
(i32.store
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.add
|
||||
(get_global $../../examples/game-of-life/assembly/index/s)
|
||||
(i32.mul
|
||||
(get_local $0)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
)
|
||||
(get_local $1)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
(i32.or
|
||||
(i32.shl
|
||||
(tee_local $4
|
||||
(select
|
||||
(tee_local $4
|
||||
(i32.sub
|
||||
(i32.shr_u
|
||||
(tee_local $3
|
||||
(get_local $4)
|
||||
)
|
||||
(i32.const 24)
|
||||
)
|
||||
(i32.const 7)
|
||||
)
|
||||
)
|
||||
(tee_local $2
|
||||
(i32.const 0)
|
||||
)
|
||||
(i32.gt_s
|
||||
(get_local $4)
|
||||
(get_local $2)
|
||||
)
|
||||
)
|
||||
)
|
||||
(i32.const 24)
|
||||
)
|
||||
(i32.and
|
||||
(get_local $3)
|
||||
(i32.const 16777215)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.eq
|
||||
(get_local $2)
|
||||
(i32.const 3)
|
||||
)
|
||||
(i32.store8
|
||||
(i32.store
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.add
|
||||
(get_global $../../examples/game-of-life/assembly/index/s)
|
||||
@ -245,7 +433,53 @@
|
||||
)
|
||||
(get_local $1)
|
||||
)
|
||||
(i32.const 1)
|
||||
(i32.const 2)
|
||||
)
|
||||
(i32.const -1666349)
|
||||
)
|
||||
(i32.store
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.add
|
||||
(get_global $../../examples/game-of-life/assembly/index/s)
|
||||
(i32.mul
|
||||
(get_local $0)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
)
|
||||
(get_local $1)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
(i32.or
|
||||
(i32.shl
|
||||
(tee_local $2
|
||||
(select
|
||||
(tee_local $2
|
||||
(i32.sub
|
||||
(i32.shr_u
|
||||
(get_local $4)
|
||||
(i32.const 24)
|
||||
)
|
||||
(i32.const 7)
|
||||
)
|
||||
)
|
||||
(tee_local $3
|
||||
(i32.const 0)
|
||||
)
|
||||
(i32.gt_s
|
||||
(get_local $2)
|
||||
(get_local $3)
|
||||
)
|
||||
)
|
||||
)
|
||||
(i32.const 24)
|
||||
)
|
||||
(i32.and
|
||||
(get_local $4)
|
||||
(i32.const 16777215)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -1,6 +1,10 @@
|
||||
(module
|
||||
(type $iiv (func (param i32 i32)))
|
||||
(type $iiFv (func (param i32 i32 f64)))
|
||||
(type $F (func (result f64)))
|
||||
(type $v (func))
|
||||
(import "JSMath" "random" (func $~lib/math/JSMath.random (result f64)))
|
||||
(global $../../examples/game-of-life/assembly/index/RGB_ALIVE i32 (i32.const 15110867))
|
||||
(global $../../examples/game-of-life/assembly/index/RGB_DEAD i32 (i32.const 8723366))
|
||||
(global $../../examples/game-of-life/assembly/index/w (mut i32) (i32.const 0))
|
||||
(global $../../examples/game-of-life/assembly/index/h (mut i32) (i32.const 0))
|
||||
(global $../../examples/game-of-life/assembly/index/s (mut i32) (i32.const 0))
|
||||
@ -9,7 +13,12 @@
|
||||
(export "init" (func $../../examples/game-of-life/assembly/index/init))
|
||||
(export "step" (func $../../examples/game-of-life/assembly/index/step))
|
||||
(export "memory" (memory $0))
|
||||
(func $../../examples/game-of-life/assembly/index/init (; 0 ;) (type $iiv) (param $0 i32) (param $1 i32)
|
||||
(func $../../examples/game-of-life/assembly/index/init (; 1 ;) (type $iiFv) (param $0 i32) (param $1 i32) (param $2 f64)
|
||||
(local $3 i32)
|
||||
(local $4 i32)
|
||||
(local $5 i32)
|
||||
(local $6 i32)
|
||||
(local $7 i32)
|
||||
(set_global $../../examples/game-of-life/assembly/index/w
|
||||
(get_local $0)
|
||||
)
|
||||
@ -22,8 +31,96 @@
|
||||
(get_local $1)
|
||||
)
|
||||
)
|
||||
(block $break|0
|
||||
(set_local $3
|
||||
(i32.const 0)
|
||||
)
|
||||
(func $../../examples/game-of-life/assembly/index/step (; 1 ;) (type $v)
|
||||
(loop $continue|0
|
||||
(if
|
||||
(i32.lt_s
|
||||
(get_local $3)
|
||||
(get_global $../../examples/game-of-life/assembly/index/h)
|
||||
)
|
||||
(block
|
||||
(block
|
||||
(block $break|1
|
||||
(set_local $4
|
||||
(i32.const 0)
|
||||
)
|
||||
(loop $continue|1
|
||||
(if
|
||||
(i32.lt_s
|
||||
(get_local $4)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
(block
|
||||
(block
|
||||
(block $../../examples/game-of-life/assembly/index/set|inlined.0
|
||||
(set_local $5
|
||||
(get_local $4)
|
||||
)
|
||||
(set_local $6
|
||||
(get_local $3)
|
||||
)
|
||||
(set_local $7
|
||||
(if (result i32)
|
||||
(f64.gt
|
||||
(call $~lib/math/JSMath.random)
|
||||
(f64.const 0.15)
|
||||
)
|
||||
(i32.and
|
||||
(i32.const 8723366)
|
||||
(i32.const 16777215)
|
||||
)
|
||||
(i32.or
|
||||
(i32.const 15110867)
|
||||
(i32.const -16777216)
|
||||
)
|
||||
)
|
||||
)
|
||||
(i32.store
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.add
|
||||
(get_global $../../examples/game-of-life/assembly/index/s)
|
||||
(i32.mul
|
||||
(get_local $6)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
)
|
||||
(get_local $5)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
(get_local $7)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $4
|
||||
(i32.add
|
||||
(get_local $4)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(br $continue|1)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $3
|
||||
(i32.add
|
||||
(get_local $3)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(br $continue|0)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(func $../../examples/game-of-life/assembly/index/step (; 2 ;) (type $v)
|
||||
(local $0 i32)
|
||||
(local $1 i32)
|
||||
(local $2 i32)
|
||||
@ -35,6 +132,21 @@
|
||||
(local $8 i32)
|
||||
(local $9 i32)
|
||||
(local $10 i32)
|
||||
(local $11 i32)
|
||||
(local $12 i32)
|
||||
(local $13 i32)
|
||||
(local $14 i32)
|
||||
(local $15 i32)
|
||||
(local $16 i32)
|
||||
(local $17 i32)
|
||||
(local $18 i32)
|
||||
(local $19 i32)
|
||||
(local $20 i32)
|
||||
(local $21 i32)
|
||||
(local $22 i32)
|
||||
(local $23 i32)
|
||||
(local $24 i32)
|
||||
(local $25 i32)
|
||||
(block
|
||||
(set_local $0
|
||||
(i32.sub
|
||||
@ -129,6 +241,222 @@
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $9
|
||||
(block $../../examples/game-of-life/assembly/index/get|inlined.0 (result i32)
|
||||
(set_local $8
|
||||
(get_local $6)
|
||||
)
|
||||
(set_local $9
|
||||
(get_local $3)
|
||||
)
|
||||
(br $../../examples/game-of-life/assembly/index/get|inlined.0
|
||||
(i32.load
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $9)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
(get_local $8)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $10
|
||||
(block $../../examples/game-of-life/assembly/index/get|inlined.1 (result i32)
|
||||
(set_local $8
|
||||
(get_local $5)
|
||||
)
|
||||
(set_local $10
|
||||
(get_local $3)
|
||||
)
|
||||
(br $../../examples/game-of-life/assembly/index/get|inlined.1
|
||||
(i32.load
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $10)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
(get_local $8)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $11
|
||||
(block $../../examples/game-of-life/assembly/index/get|inlined.2 (result i32)
|
||||
(set_local $8
|
||||
(get_local $7)
|
||||
)
|
||||
(set_local $11
|
||||
(get_local $3)
|
||||
)
|
||||
(br $../../examples/game-of-life/assembly/index/get|inlined.2
|
||||
(i32.load
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $11)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
(get_local $8)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $12
|
||||
(block $../../examples/game-of-life/assembly/index/get|inlined.3 (result i32)
|
||||
(set_local $8
|
||||
(get_local $6)
|
||||
)
|
||||
(set_local $12
|
||||
(get_local $2)
|
||||
)
|
||||
(br $../../examples/game-of-life/assembly/index/get|inlined.3
|
||||
(i32.load
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $12)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
(get_local $8)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $13
|
||||
(block $../../examples/game-of-life/assembly/index/get|inlined.4 (result i32)
|
||||
(set_local $8
|
||||
(get_local $5)
|
||||
)
|
||||
(set_local $13
|
||||
(get_local $2)
|
||||
)
|
||||
(br $../../examples/game-of-life/assembly/index/get|inlined.4
|
||||
(i32.load
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $13)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
(get_local $8)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $14
|
||||
(block $../../examples/game-of-life/assembly/index/get|inlined.5 (result i32)
|
||||
(set_local $8
|
||||
(get_local $7)
|
||||
)
|
||||
(set_local $14
|
||||
(get_local $2)
|
||||
)
|
||||
(br $../../examples/game-of-life/assembly/index/get|inlined.5
|
||||
(i32.load
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $14)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
(get_local $8)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $15
|
||||
(block $../../examples/game-of-life/assembly/index/get|inlined.6 (result i32)
|
||||
(set_local $8
|
||||
(get_local $6)
|
||||
)
|
||||
(set_local $15
|
||||
(get_local $4)
|
||||
)
|
||||
(br $../../examples/game-of-life/assembly/index/get|inlined.6
|
||||
(i32.load
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $15)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
(get_local $8)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $16
|
||||
(block $../../examples/game-of-life/assembly/index/get|inlined.7 (result i32)
|
||||
(set_local $8
|
||||
(get_local $5)
|
||||
)
|
||||
(set_local $16
|
||||
(get_local $4)
|
||||
)
|
||||
(br $../../examples/game-of-life/assembly/index/get|inlined.7
|
||||
(i32.load
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $16)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
(get_local $8)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $17
|
||||
(block $../../examples/game-of-life/assembly/index/get|inlined.8 (result i32)
|
||||
(set_local $8
|
||||
(get_local $7)
|
||||
)
|
||||
(set_local $17
|
||||
(get_local $4)
|
||||
)
|
||||
(br $../../examples/game-of-life/assembly/index/get|inlined.8
|
||||
(i32.load
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $17)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
(get_local $8)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $8
|
||||
(i32.add
|
||||
(i32.add
|
||||
@ -137,168 +465,269 @@
|
||||
(i32.add
|
||||
(i32.add
|
||||
(i32.add
|
||||
(i32.load8_u
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $3)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
(i32.and
|
||||
(get_local $9)
|
||||
(i32.const 1)
|
||||
)
|
||||
(get_local $6)
|
||||
(i32.and
|
||||
(get_local $10)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(i32.load8_u
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $3)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
(i32.and
|
||||
(get_local $11)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(i32.and
|
||||
(get_local $12)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(i32.and
|
||||
(get_local $14)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(i32.and
|
||||
(get_local $15)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(i32.and
|
||||
(get_local $16)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(i32.and
|
||||
(get_local $17)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $18
|
||||
(i32.and
|
||||
(get_local $13)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(get_local $18)
|
||||
(if
|
||||
(i32.and
|
||||
(if (result i32)
|
||||
(tee_local $19
|
||||
(i32.lt_u
|
||||
(get_local $8)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
(get_local $19)
|
||||
(i32.gt_u
|
||||
(get_local $8)
|
||||
(i32.const 3)
|
||||
)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
(block $../../examples/game-of-life/assembly/index/set|inlined.1
|
||||
(set_local $19
|
||||
(get_local $5)
|
||||
)
|
||||
)
|
||||
)
|
||||
(i32.load8_u
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $3)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
(get_local $7)
|
||||
)
|
||||
)
|
||||
)
|
||||
(i32.load8_u
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(set_local $20
|
||||
(get_local $2)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
(get_local $6)
|
||||
(set_local $21
|
||||
(i32.or
|
||||
(i32.const 8723366)
|
||||
(i32.const -16777216)
|
||||
)
|
||||
)
|
||||
)
|
||||
(i32.load8_u
|
||||
(i32.store
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $2)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
(get_local $7)
|
||||
)
|
||||
)
|
||||
)
|
||||
(i32.load8_u
|
||||
(i32.add
|
||||
(get_global $../../examples/game-of-life/assembly/index/s)
|
||||
(i32.mul
|
||||
(get_local $4)
|
||||
(get_local $20)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
(get_local $6)
|
||||
)
|
||||
(get_local $19)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
(get_local $21)
|
||||
)
|
||||
)
|
||||
)
|
||||
(i32.load8_u
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $4)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
(block $../../examples/game-of-life/assembly/index/set_fade|inlined.0
|
||||
(set_local $21
|
||||
(get_local $5)
|
||||
)
|
||||
)
|
||||
)
|
||||
(i32.load8_u
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(get_local $4)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
(get_local $7)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $9
|
||||
(i32.load8_u
|
||||
(i32.add
|
||||
(i32.mul
|
||||
(set_local $20
|
||||
(get_local $2)
|
||||
)
|
||||
(set_local $19
|
||||
(get_local $13)
|
||||
)
|
||||
(set_local $22
|
||||
(select
|
||||
(tee_local $22
|
||||
(i32.sub
|
||||
(i32.shr_u
|
||||
(get_local $19)
|
||||
(i32.const 24)
|
||||
)
|
||||
(i32.const 7)
|
||||
)
|
||||
)
|
||||
(tee_local $23
|
||||
(i32.const 0)
|
||||
)
|
||||
(i32.gt_s
|
||||
(get_local $22)
|
||||
(get_local $23)
|
||||
)
|
||||
)
|
||||
)
|
||||
(block $../../examples/game-of-life/assembly/index/set|inlined.2
|
||||
(set_local $23
|
||||
(get_local $21)
|
||||
)
|
||||
(set_local $24
|
||||
(get_local $20)
|
||||
)
|
||||
(set_local $25
|
||||
(i32.or
|
||||
(i32.shl
|
||||
(get_local $22)
|
||||
(i32.const 24)
|
||||
)
|
||||
(i32.and
|
||||
(get_local $19)
|
||||
(i32.const 16777215)
|
||||
)
|
||||
)
|
||||
)
|
||||
(i32.store
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.add
|
||||
(get_global $../../examples/game-of-life/assembly/index/s)
|
||||
(i32.mul
|
||||
(get_local $24)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
(get_local $5)
|
||||
)
|
||||
(get_local $23)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
(get_local $25)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(get_local $9)
|
||||
(block $break|2
|
||||
(block $case2|2
|
||||
(block $case1|2
|
||||
(block $case0|2
|
||||
(set_local $10
|
||||
(get_local $8)
|
||||
)
|
||||
(br_if $case1|2
|
||||
(i32.eq
|
||||
(get_local $10)
|
||||
(get_local $8)
|
||||
(i32.const 3)
|
||||
)
|
||||
(block $../../examples/game-of-life/assembly/index/set|inlined.3
|
||||
(set_local $22
|
||||
(get_local $5)
|
||||
)
|
||||
(set_local $19
|
||||
(get_local $2)
|
||||
)
|
||||
(set_local $20
|
||||
(i32.or
|
||||
(i32.const 15110867)
|
||||
(i32.const -16777216)
|
||||
)
|
||||
)
|
||||
(i32.store
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.add
|
||||
(get_global $../../examples/game-of-life/assembly/index/s)
|
||||
(i32.mul
|
||||
(get_local $19)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
)
|
||||
(get_local $22)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
(br_if $case2|2
|
||||
(i32.eq
|
||||
(get_local $10)
|
||||
(i32.const 3)
|
||||
)
|
||||
)
|
||||
(br $case0|2)
|
||||
)
|
||||
(block
|
||||
(i32.store8
|
||||
(i32.add
|
||||
(i32.add
|
||||
(get_global $../../examples/game-of-life/assembly/index/s)
|
||||
(i32.mul
|
||||
(get_local $2)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
(get_local $20)
|
||||
)
|
||||
)
|
||||
(block $../../examples/game-of-life/assembly/index/set_fade|inlined.1
|
||||
(set_local $20
|
||||
(get_local $5)
|
||||
)
|
||||
(set_local $19
|
||||
(get_local $2)
|
||||
)
|
||||
(set_local $22
|
||||
(get_local $13)
|
||||
)
|
||||
(set_local $21
|
||||
(select
|
||||
(tee_local $21
|
||||
(i32.sub
|
||||
(i32.shr_u
|
||||
(get_local $22)
|
||||
(i32.const 24)
|
||||
)
|
||||
(i32.const 7)
|
||||
)
|
||||
)
|
||||
(tee_local $25
|
||||
(i32.const 0)
|
||||
)
|
||||
(br $break|2)
|
||||
(i32.gt_s
|
||||
(get_local $21)
|
||||
(get_local $25)
|
||||
)
|
||||
)
|
||||
)
|
||||
(block $../../examples/game-of-life/assembly/index/set|inlined.4
|
||||
(set_local $25
|
||||
(get_local $20)
|
||||
)
|
||||
(block $break|3
|
||||
(block $case1|3
|
||||
(block $case0|3
|
||||
(set_local $10
|
||||
(get_local $8)
|
||||
(set_local $24
|
||||
(get_local $19)
|
||||
)
|
||||
(br_if $case0|3
|
||||
(i32.eq
|
||||
(get_local $10)
|
||||
(i32.const 3)
|
||||
(set_local $23
|
||||
(i32.or
|
||||
(i32.shl
|
||||
(get_local $21)
|
||||
(i32.const 24)
|
||||
)
|
||||
(i32.and
|
||||
(get_local $22)
|
||||
(i32.const 16777215)
|
||||
)
|
||||
)
|
||||
(br $case1|3)
|
||||
)
|
||||
(block
|
||||
(i32.store8
|
||||
(i32.store
|
||||
(i32.shl
|
||||
(i32.add
|
||||
(i32.add
|
||||
(get_global $../../examples/game-of-life/assembly/index/s)
|
||||
(i32.mul
|
||||
(get_local $2)
|
||||
(get_local $24)
|
||||
(get_global $../../examples/game-of-life/assembly/index/w)
|
||||
)
|
||||
)
|
||||
(get_local $5)
|
||||
(get_local $25)
|
||||
)
|
||||
(i32.const 1)
|
||||
(i32.const 2)
|
||||
)
|
||||
(get_local $23)
|
||||
)
|
||||
(br $break|3)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user