Some final tweaks to the examples

I promise
This commit is contained in:
dcodeIO 2018-04-20 18:56:51 +02:00
parent 4eade0f319
commit bde13b12cf
15 changed files with 2068 additions and 1487 deletions

View File

@ -1,7 +1,8 @@
// see: https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life
const RGB_ALIVE = 0xE692D3;
const RGB_DEAD = 0x851BA6;
const RGB_ALIVE = 0xE692D3; // LSB must be set
const RGB_DEAD = 0x851BA6; // LSB must not be set
const BIT_ROT = 10; // It's everywhere
var w: i32, h: i32, s: i32;
@ -19,8 +20,8 @@ function set(x: u32, y: u32, v: u32): void {
/** 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);
function rot(x: u32, y: u32, v: u32): void {
var a = max<i32>((v >>> 24) - BIT_ROT, 0);
set(x, y, (a << 24) | (v & 0x00ffffff));
}
@ -33,7 +34,7 @@ export function init(width: i32, height: i32): void {
// 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);
set(x, y, Math.random() > 0.1 ? RGB_DEAD & 0x00ffffff : RGB_ALIVE | 0xff000000);
}
}
}
@ -53,35 +54,24 @@ export function step(): void {
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.
// vertically, or diagonally adjacent. Least significant bit indicates alive or dead.
let aliveNeighbors = (
(tl & 1) + (tm & 1) + (tr & 1) +
(ml & 1) + (mr & 1) +
(bl & 1) + (bm & 1) + (br & 1)
(get(xm1, ym1) & 1) + (get(x , ym1) & 1) + (get(xp1, ym1) & 1) +
(get(xm1, y ) & 1) + (get(xp1, y ) & 1) +
(get(xm1, yp1) & 1) + (get(x , yp1) & 1) + (get(xp1, yp1) & 1)
);
let alive = mm & 1;
if (alive) {
// A live cell with 2 or 3 live neighbors lives on to the next generation.
if ((aliveNeighbors & 0b1110) == 0b0010) set_fade(x, y, mm);
let self = get(x, y);
if (self & 1) {
// A live cell with 2 or 3 live neighbors rots on to the next generation.
if ((aliveNeighbors & 0b1110) == 0b0010) rot(x, y, self);
// A live cell with fewer than 2 or more than 3 live neighbors dies.
else set(x, y, RGB_DEAD | 0xff000000);
} else {
// A dead cell with exactly 3 live neighbors becomes a live cell.
if (aliveNeighbors == 3) set(x, y, RGB_ALIVE | 0xff000000);
// A dead cell with fewer or more than 3 live neighbors remains dead.
else set_fade(x, y, mm);
// A dead cell with fewer or more than 3 live neighbors just rots.
else rot(x, y, self);
}
}
}

View File

@ -1,5 +1,5 @@
(module
(type $iiFv (func (param i32 i32 f64)))
(type $iiv (func (param i32 i32)))
(type $F (func (result f64)))
(type $v (func))
(import "JSMath" "random" (func $~lib/math/JSMath.random (result f64)))
@ -10,97 +10,97 @@
(export "init" (func $assembly/index/init))
(export "step" (func $assembly/index/step))
(export "memory" (memory $0))
(func $assembly/index/init (; 1 ;) (type $iiFv) (param $0 i32) (param $1 i32) (param $2 f64)
(local $3 i32)
;;@ assembly/index.ts:29:2
(func $assembly/index/init (; 1 ;) (type $iiv) (param $0 i32) (param $1 i32)
(local $2 i32)
;;@ assembly/index.ts:30:2
(set_global $assembly/index/w
;;@ assembly/index.ts:29:6
;;@ assembly/index.ts:30:6
(get_local $0)
)
;;@ assembly/index.ts:30:2
;;@ assembly/index.ts:31:2
(set_global $assembly/index/h
;;@ assembly/index.ts:30:6
;;@ assembly/index.ts:31:6
(get_local $1)
)
;;@ assembly/index.ts:31:2
;;@ assembly/index.ts:32:2
(set_global $assembly/index/s
;;@ assembly/index.ts:31:6
;;@ assembly/index.ts:32:6
(i32.mul
(get_local $0)
;;@ assembly/index.ts:31:14
;;@ assembly/index.ts:32:14
(get_local $1)
)
)
;;@ assembly/index.ts:34:7
;;@ assembly/index.ts:35:7
(set_local $0
;;@ assembly/index.ts:34:15
;;@ assembly/index.ts:35:15
(i32.const 0)
)
(loop $continue|0
(if
;;@ assembly/index.ts:34:18
;;@ assembly/index.ts:35:18
(i32.lt_s
(get_local $0)
;;@ assembly/index.ts:34:22
;;@ assembly/index.ts:35:22
(get_global $assembly/index/h)
)
(block
;;@ assembly/index.ts:35:9
;;@ assembly/index.ts:36:9
(set_local $1
;;@ assembly/index.ts:35:17
;;@ assembly/index.ts:36:17
(i32.const 0)
)
(loop $continue|1
(if
;;@ assembly/index.ts:35:20
;;@ assembly/index.ts:36:20
(i32.lt_s
(get_local $1)
;;@ assembly/index.ts:35:24
;;@ assembly/index.ts:36:24
(get_global $assembly/index/w)
)
(block
(set_local $3
;;@ assembly/index.ts:36:16
(set_local $2
;;@ assembly/index.ts:37:16
(if (result i32)
(f64.gt
;;@ assembly/index.ts:36:23
;;@ assembly/index.ts:37:21
(call $~lib/math/JSMath.random)
;;@ assembly/index.ts:36:34
(f64.const 0.15)
;;@ assembly/index.ts:37:32
(f64.const 0.1)
)
;;@ assembly/index.ts:36:41
;;@ assembly/index.ts:37:38
(i32.const 8723366)
(i32.const -1666349)
)
)
;;@ assembly/index.ts:17:2
;;@ assembly/index.ts:18:2
(i32.store
;;@ assembly/index.ts:17:13
;;@ assembly/index.ts:18:13
(i32.shl
(i32.add
;;@ assembly/index.ts:17:14
;;@ assembly/index.ts:18:14
(i32.add
(get_global $assembly/index/s)
;;@ assembly/index.ts:17:18
;;@ assembly/index.ts:18:18
(i32.mul
(get_local $0)
;;@ assembly/index.ts:17:22
;;@ assembly/index.ts:18:22
(get_global $assembly/index/w)
)
)
;;@ assembly/index.ts:17:26
;;@ assembly/index.ts:18:26
(get_local $1)
)
;;@ assembly/index.ts:17:32
;;@ assembly/index.ts:18:32
(i32.const 2)
)
;;@ assembly/index.ts:17:35
(get_local $3)
;;@ assembly/index.ts:18:35
(get_local $2)
)
;;@ assembly/index.ts:35:27
;;@ assembly/index.ts:36:27
(set_local $1
(i32.add
;;@ assembly/index.ts:35:29
;;@ assembly/index.ts:36:29
(get_local $1)
(i32.const 1)
)
@ -109,10 +109,10 @@
)
)
)
;;@ assembly/index.ts:34:25
;;@ assembly/index.ts:35:25
(set_local $0
(i32.add
;;@ assembly/index.ts:34:27
;;@ assembly/index.ts:35:27
(get_local $0)
(i32.const 1)
)
@ -132,99 +132,82 @@
(local $6 i32)
(local $7 i32)
(local $8 i32)
(set_local $7
;;@ assembly/index.ts:43:12
(set_local $5
;;@ assembly/index.ts:44:12
(i32.sub
(get_global $assembly/index/h)
;;@ assembly/index.ts:43:16
;;@ assembly/index.ts:44:16
(i32.const 1)
)
)
(set_local $8
;;@ assembly/index.ts:44:12
(set_local $6
;;@ assembly/index.ts:45:12
(i32.sub
(get_global $assembly/index/w)
;;@ assembly/index.ts:44:16
;;@ assembly/index.ts:45:16
(i32.const 1)
)
)
(loop $continue|0
(if
;;@ assembly/index.ts:48:18
;;@ assembly/index.ts:49:18
(i32.lt_s
(get_local $0)
;;@ assembly/index.ts:48:22
(get_local $2)
;;@ assembly/index.ts:49:22
(get_global $assembly/index/h)
)
(block
(set_local $5
;;@ assembly/index.ts:49:14
(if (result i32)
(get_local $0)
;;@ assembly/index.ts:49:29
(i32.sub
(get_local $0)
;;@ assembly/index.ts:49:33
(i32.const 1)
)
;;@ assembly/index.ts:49:23
(get_local $7)
)
)
(set_local $6
(set_local $7
;;@ assembly/index.ts:50:14
(if (result i32)
(i32.eq
(get_local $0)
;;@ assembly/index.ts:50:19
(get_local $7)
)
;;@ assembly/index.ts:50:25
(i32.const 0)
(get_local $2)
;;@ assembly/index.ts:50:29
(i32.add
(get_local $0)
(i32.sub
(get_local $2)
;;@ assembly/index.ts:50:33
(i32.const 1)
)
;;@ assembly/index.ts:50:23
(get_local $5)
)
)
;;@ assembly/index.ts:51:9
(set_local $8
;;@ assembly/index.ts:51:14
(if (result i32)
(i32.eq
(get_local $2)
;;@ assembly/index.ts:51:19
(get_local $5)
)
;;@ assembly/index.ts:51:25
(i32.const 0)
;;@ assembly/index.ts:51:29
(i32.add
(get_local $2)
;;@ assembly/index.ts:51:33
(i32.const 1)
)
)
)
;;@ assembly/index.ts:52:9
(set_local $1
;;@ assembly/index.ts:51:17
;;@ assembly/index.ts:52:17
(i32.const 0)
)
(loop $continue|1
(if
;;@ assembly/index.ts:51:20
;;@ assembly/index.ts:52:20
(i32.lt_s
(get_local $1)
;;@ assembly/index.ts:51:24
;;@ assembly/index.ts:52:24
(get_global $assembly/index/w)
)
(block
;;@ assembly/index.ts:61:6
(set_local $3
(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 $1)
)
(i32.const 2)
)
)
)
;;@ assembly/index.ts:68:6
(set_local $2
;;@ assembly/index.ts:68:27
;;@ assembly/index.ts:58:6
(set_local $0
;;@ assembly/index.ts:58:27
(i32.add
;;@ assembly/index.ts:69:8
;;@ assembly/index.ts:59:8
(i32.add
(i32.add
(i32.add
@ -236,75 +219,77 @@
(i32.shl
(i32.add
(i32.mul
;;@ assembly/index.ts:57:24
(get_local $5)
(tee_local $0
;;@ assembly/index.ts:59:18
(get_local $7)
)
(get_global $assembly/index/w)
)
(tee_local $2
;;@ assembly/index.ts:52:16
(tee_local $3
;;@ assembly/index.ts:53:16
(if (result i32)
(get_local $1)
;;@ assembly/index.ts:52:31
;;@ assembly/index.ts:53:31
(i32.sub
(get_local $1)
;;@ assembly/index.ts:52:35
;;@ assembly/index.ts:53:35
(i32.const 1)
)
;;@ assembly/index.ts:52:25
(get_local $8)
;;@ assembly/index.ts:53:25
(get_local $6)
)
)
)
(i32.const 2)
)
)
;;@ assembly/index.ts:69:14
;;@ assembly/index.ts:59:25
(i32.const 1)
)
;;@ assembly/index.ts:69:19
;;@ assembly/index.ts:59:30
(i32.and
(i32.load
(i32.shl
(i32.add
(i32.mul
;;@ assembly/index.ts:58:24
(get_local $5)
;;@ assembly/index.ts:59:40
(get_local $0)
(get_global $assembly/index/w)
)
;;@ assembly/index.ts:58:19
;;@ assembly/index.ts:59:35
(get_local $1)
)
(i32.const 2)
)
)
;;@ assembly/index.ts:69:25
;;@ assembly/index.ts:59:47
(i32.const 1)
)
)
;;@ assembly/index.ts:69:30
;;@ assembly/index.ts:59:52
(i32.and
(i32.load
(i32.shl
(i32.add
(i32.mul
;;@ assembly/index.ts:59:24
(get_local $5)
;;@ assembly/index.ts:59:62
(get_local $0)
(get_global $assembly/index/w)
)
(tee_local $4
;;@ assembly/index.ts:53:16
;;@ assembly/index.ts:54:16
(if (result i32)
(i32.eq
(get_local $1)
;;@ assembly/index.ts:53:21
(get_local $8)
;;@ assembly/index.ts:54:21
(get_local $6)
)
;;@ assembly/index.ts:53:27
;;@ assembly/index.ts:54:27
(i32.const 0)
;;@ assembly/index.ts:53:31
;;@ assembly/index.ts:54:31
(i32.add
(get_local $1)
;;@ assembly/index.ts:53:35
;;@ assembly/index.ts:54:35
(i32.const 1)
)
)
@ -313,135 +298,155 @@
(i32.const 2)
)
)
;;@ assembly/index.ts:69:36
;;@ assembly/index.ts:59:69
(i32.const 1)
)
)
;;@ assembly/index.ts:70:8
;;@ assembly/index.ts:60:8
(i32.and
(i32.load
(i32.shl
(i32.add
(i32.mul
;;@ assembly/index.ts:60:24
(get_local $0)
(tee_local $0
;;@ assembly/index.ts:60:18
(get_local $2)
)
(get_global $assembly/index/w)
)
;;@ assembly/index.ts:60:19
(get_local $2)
;;@ assembly/index.ts:60:13
(get_local $3)
)
(i32.const 2)
)
)
;;@ assembly/index.ts:70:14
;;@ assembly/index.ts:60:25
(i32.const 1)
)
)
;;@ assembly/index.ts:70:30
;;@ assembly/index.ts:60:52
(i32.and
(i32.load
(i32.shl
(i32.add
(i32.mul
;;@ assembly/index.ts:62:24
;;@ assembly/index.ts:60:62
(get_local $0)
(get_global $assembly/index/w)
)
;;@ assembly/index.ts:62:19
;;@ assembly/index.ts:60:57
(get_local $4)
)
(i32.const 2)
)
)
;;@ assembly/index.ts:70:36
;;@ assembly/index.ts:60:69
(i32.const 1)
)
)
;;@ assembly/index.ts:71:8
;;@ assembly/index.ts:61:8
(i32.and
(i32.load
(i32.shl
(i32.add
(i32.mul
;;@ assembly/index.ts:63:24
(get_local $6)
(tee_local $0
;;@ assembly/index.ts:61:18
(get_local $8)
)
(get_global $assembly/index/w)
)
;;@ assembly/index.ts:63:19
(get_local $2)
;;@ assembly/index.ts:61:13
(get_local $3)
)
(i32.const 2)
)
)
;;@ assembly/index.ts:71:14
;;@ assembly/index.ts:61:25
(i32.const 1)
)
)
;;@ assembly/index.ts:71:19
;;@ assembly/index.ts:61:30
(i32.and
(i32.load
(i32.shl
(i32.add
(i32.mul
;;@ assembly/index.ts:64:24
(get_local $6)
;;@ assembly/index.ts:61:40
(get_local $0)
(get_global $assembly/index/w)
)
;;@ assembly/index.ts:64:19
;;@ assembly/index.ts:61:35
(get_local $1)
)
(i32.const 2)
)
)
;;@ assembly/index.ts:71:25
;;@ assembly/index.ts:61:47
(i32.const 1)
)
)
;;@ assembly/index.ts:71:30
;;@ assembly/index.ts:61:52
(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:65:24
(get_local $6)
;;@ assembly/index.ts:11:24
;;@ assembly/index.ts:61:62
(get_local $0)
(get_global $assembly/index/w)
)
;;@ assembly/index.ts:65:19
;;@ assembly/index.ts:61:57
(get_local $4)
)
;;@ assembly/index.ts:11:34
(i32.const 2)
)
)
;;@ assembly/index.ts:71:36
;;@ assembly/index.ts:61:69
(i32.const 1)
)
)
)
;;@ assembly/index.ts:75:6
;;@ assembly/index.ts:65:6
(if
;;@ assembly/index.ts:74:18
;;@ assembly/index.ts:65:10
(i32.and
(get_local $3)
;;@ assembly/index.ts:74:23
;;@ assembly/index.ts:64:6
(tee_local $3
;;@ assembly/index.ts:12:9
(i32.load
;;@ assembly/index.ts:12:19
(i32.shl
(i32.add
;;@ assembly/index.ts:12:20
(i32.mul
;;@ assembly/index.ts:64:24
(get_local $2)
;;@ assembly/index.ts:12:24
(get_global $assembly/index/w)
)
;;@ assembly/index.ts:64:21
(get_local $1)
)
;;@ assembly/index.ts:12:34
(i32.const 2)
)
)
)
;;@ assembly/index.ts:65:17
(i32.const 1)
)
;;@ assembly/index.ts:77:8
;;@ assembly/index.ts:67:8
(if
;;@ assembly/index.ts:77:12
;;@ assembly/index.ts:67:12
(i32.eq
(i32.and
;;@ assembly/index.ts:77:13
(get_local $2)
;;@ assembly/index.ts:77:30
;;@ assembly/index.ts:67:13
(get_local $0)
;;@ assembly/index.ts:67:30
(i32.const 14)
)
;;@ assembly/index.ts:77:41
;;@ assembly/index.ts:67:41
(i32.const 2)
)
(i32.store
@ -450,12 +455,12 @@
(i32.add
(get_global $assembly/index/s)
(i32.mul
;;@ assembly/index.ts:77:61
(get_local $0)
;;@ assembly/index.ts:67:56
(get_local $2)
(get_global $assembly/index/w)
)
)
;;@ assembly/index.ts:77:58
;;@ assembly/index.ts:67:53
(get_local $1)
)
(i32.const 2)
@ -467,13 +472,13 @@
(tee_local $3
(i32.sub
(i32.shr_u
(tee_local $2
;;@ assembly/index.ts:77:64
(tee_local $0
;;@ assembly/index.ts:67:59
(get_local $3)
)
(i32.const 24)
)
(i32.const 7)
(i32.const 10)
)
)
(tee_local $4
@ -488,7 +493,7 @@
(i32.const 24)
)
(i32.and
(get_local $2)
(get_local $0)
(i32.const 16777215)
)
)
@ -499,12 +504,12 @@
(i32.add
(get_global $assembly/index/s)
(i32.mul
;;@ assembly/index.ts:79:20
(get_local $0)
;;@ assembly/index.ts:69:20
(get_local $2)
(get_global $assembly/index/w)
)
)
;;@ assembly/index.ts:79:17
;;@ assembly/index.ts:69:17
(get_local $1)
)
(i32.const 2)
@ -512,12 +517,12 @@
(i32.const -8053850)
)
)
;;@ assembly/index.ts:82:8
;;@ assembly/index.ts:72:8
(if
;;@ assembly/index.ts:82:12
;;@ assembly/index.ts:72:12
(i32.eq
(get_local $2)
;;@ assembly/index.ts:82:30
(get_local $0)
;;@ assembly/index.ts:72:30
(i32.const 3)
)
(i32.store
@ -526,88 +531,88 @@
(i32.add
(get_global $assembly/index/s)
(i32.mul
;;@ assembly/index.ts:82:40
(get_local $0)
;;@ assembly/index.ts:72:40
(get_local $2)
(get_global $assembly/index/w)
)
)
;;@ assembly/index.ts:82:37
;;@ assembly/index.ts:72:37
(get_local $1)
)
(i32.const 2)
)
(i32.const -1666349)
)
;;@ assembly/index.ts:17:2
;;@ assembly/index.ts:18:2
(i32.store
;;@ assembly/index.ts:17:13
;;@ assembly/index.ts:18:13
(i32.shl
(i32.add
;;@ assembly/index.ts:17:14
;;@ assembly/index.ts:18:14
(i32.add
(get_global $assembly/index/s)
;;@ assembly/index.ts:17:18
;;@ assembly/index.ts:18:18
(i32.mul
;;@ assembly/index.ts:84:25
(get_local $0)
;;@ assembly/index.ts:17:22
;;@ assembly/index.ts:74:20
(get_local $2)
;;@ assembly/index.ts:18:22
(get_global $assembly/index/w)
)
)
;;@ assembly/index.ts:84:22
;;@ assembly/index.ts:74:17
(get_local $1)
)
;;@ assembly/index.ts:17:32
;;@ assembly/index.ts:18:32
(i32.const 2)
)
;;@ assembly/index.ts:24:12
;;@ assembly/index.ts:25:12
(i32.or
(i32.shl
;;@ assembly/index.ts:23:2
(tee_local $2
;;@ assembly/index.ts:23:10
;;@ assembly/index.ts:24:2
(tee_local $0
;;@ assembly/index.ts:24:10
(select
(tee_local $2
;;@ assembly/index.ts:23:19
(tee_local $0
;;@ assembly/index.ts:24:19
(i32.sub
(i32.shr_u
;;@ assembly/index.ts:84:28
;;@ assembly/index.ts:74:23
(get_local $3)
;;@ assembly/index.ts:23:26
;;@ assembly/index.ts:24:26
(i32.const 24)
)
;;@ assembly/index.ts:23:32
(i32.const 7)
;;@ assembly/index.ts:24:32
(i32.const 10)
)
)
(tee_local $4
;;@ assembly/index.ts:23:35
;;@ assembly/index.ts:24:41
(i32.const 0)
)
(i32.gt_s
(get_local $2)
(get_local $0)
(i32.const 0)
)
)
)
;;@ assembly/index.ts:24:18
;;@ assembly/index.ts:25:18
(i32.const 24)
)
;;@ assembly/index.ts:24:24
;;@ assembly/index.ts:25:24
(i32.and
;;@ assembly/index.ts:24:25
;;@ assembly/index.ts:25:25
(get_local $3)
;;@ assembly/index.ts:24:29
;;@ assembly/index.ts:25:29
(i32.const 16777215)
)
)
)
)
)
;;@ assembly/index.ts:51:27
;;@ assembly/index.ts:52:27
(set_local $1
(i32.add
;;@ assembly/index.ts:51:29
;;@ assembly/index.ts:52:29
(get_local $1)
(i32.const 1)
)
@ -616,11 +621,11 @@
)
)
)
;;@ assembly/index.ts:48:25
(set_local $0
;;@ assembly/index.ts:49:25
(set_local $2
(i32.add
;;@ assembly/index.ts:48:27
(get_local $0)
;;@ assembly/index.ts:49:27
(get_local $2)
(i32.const 1)
)
)

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,8 @@
<title>Conway's Game of Life - AssemblyScript</title>
<style>
html, body { height: 100%; margin: 0; overflow: hidden; color: #111; background: #fff; font-family: sans-serif; }
h1 { padding: 20px; font-size: 12pt; margin: 0; }
body { border-top: 2px solid #bc18d4; }
h1 { padding: 18px 20px 20px; font-size: 12pt; margin: 0; }
a { color: #111; text-decoration: none; }
a:hover { color: #bc18d4; text-decoration: underline; }
canvas { position: absolute; top: 60px; left: 20px; width: calc(100% - 40px); height: calc(100% - 80px); background: #100707; }

View File

@ -3,8 +3,8 @@
"version": "1.0.0",
"private": true,
"scripts": {
"asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --importMemory --sourceMap --validate --measure",
"asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat -O3 --importMemory --sourceMap --validate --noDebug --measure",
"asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --use Math=JSMath --importMemory --sourceMap --validate --measure",
"asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat --use Math=JSMath -O3 --importMemory --sourceMap --validate --noDebug --measure",
"asbuild": "npm run asbuild:untouched && npm run asbuild:optimized",
"server": "http-server . -o -c-1"
},

View File

@ -13,30 +13,31 @@ export function computeLine(y: u32, width: u32, height: u32, limit: u32): void {
let real = (x - translateX) * scale;
// Iterate until either the escape radius or iteration limit is exceeded
let ix = 0.0, iy = 0.0, ixsq: f64, iysq: f64;
let ix = 0.0, iy = 0.0, ixSq: f64, iySq: f64;
let iteration: u32 = 0;
while ((ixsq = ix * ix) + (iysq = iy * iy) <= 4.0) {
let ix_new = ixsq - iysq + real;
while ((ixSq = ix * ix) + (iySq = iy * iy) <= 4.0) {
let ixNew = ixSq - iySq + real;
iy = 2.0 * ix * iy + imaginary;
ix = ix_new;
ix = ixNew;
if (iteration >= limit) break;
++iteration;
}
// Do a few extra iterations to reduce error margin
for (let i = 0; i < 5 && iteration < limit; ++i, ++iteration) {
let ix_new = ix * ix - iy * iy + real;
// Do a few extra iterations for quick escapes to reduce error margin
for (let minIterations = min(8, limit); iteration < minIterations; ++iteration) {
let ixNew = ix * ix - iy * iy + real;
iy = 2.0 * ix * iy + imaginary;
ix = ix_new;
ix = ixNew;
}
// Renormalize, see: http://linas.org/art-gallery/escape/escape.html
let frac: f64 = JSMath.log(JSMath.log(sqrt(ix * ix + iy * iy))) / JSMath.LN2;
store<u16>((y * width + x) << 1,
isFinite(frac)
? <u32>((NUM_COLORS - 1) * clamp((iteration + 1 - frac) / limit, 0.0, 1.0))
: (NUM_COLORS - 1) * iteration / limit
);
// Iteration count is a discrete value in the range [0, limit] here, but we'd like it to be
// normalized in the range [0, 2047] so it maps to the gradient computed in JS.
// see also: http://linas.org/art-gallery/escape/escape.html
let frac = Math.log(Math.log(Math.sqrt(ix * ix + iy * iy))) / Math.LN2;
let icol = isFinite(frac)
? <u32>((NUM_COLORS - 1) * clamp((iteration + 1 - frac) / limit, 0.0, 1.0))
: NUM_COLORS - 1;
store<u16>((y * width + x) << 1, icol);
}
}

View File

@ -1,25 +1,24 @@
(module
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $FF (func (param f64) (result f64)))
(import "JSMath" "sqrt" (func $~lib/math/JSMath.sqrt (param f64) (result f64)))
(import "JSMath" "log" (func $~lib/math/JSMath.log (param f64) (result f64)))
(import "JSMath" "LN2" (global $~lib/math/JSMath.LN2 f64))
(import "env" "memory" (memory $0 1))
(export "computeLine" (func $assembly/index/computeLine))
(export "memory" (memory $0))
(func $assembly/index/computeLine (; 1 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $assembly/index/computeLine (; 2 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(local $4 f64)
(local $5 f64)
(local $6 i32)
(local $7 f64)
(local $8 i32)
(local $9 i32)
(local $8 f64)
(local $9 f64)
(local $10 f64)
(local $11 f64)
(local $12 f64)
(local $13 f64)
(local $14 f64)
;;@ assembly/index.ts:8:2
(set_local $12
(set_local $11
;;@ assembly/index.ts:8:19
(f64.div
(f64.convert_u/i32
@ -30,7 +29,7 @@
)
)
;;@ assembly/index.ts:11:2
(set_local $10
(set_local $9
;;@ assembly/index.ts:11:18
(f64.mul
(f64.sub
@ -48,7 +47,7 @@
)
)
;;@ assembly/index.ts:10:2
(tee_local $13
(tee_local $12
;;@ assembly/index.ts:10:14
(f64.div
(f64.const 10)
@ -75,29 +74,34 @@
)
)
)
;;@ assembly/index.ts:12:7
(set_local $2
;;@ assembly/index.ts:12:20
(i32.const 0)
)
(loop $continue|0
(if
;;@ assembly/index.ts:12:23
(i32.lt_u
(get_local $8)
(get_local $2)
;;@ assembly/index.ts:12:27
(get_local $1)
)
(block
;;@ assembly/index.ts:13:4
(set_local $11
(set_local $10
;;@ assembly/index.ts:13:15
(f64.mul
(f64.sub
(f64.convert_u/i32
;;@ assembly/index.ts:13:16
(get_local $8)
(get_local $2)
)
;;@ assembly/index.ts:13:20
(get_local $12)
(get_local $11)
)
;;@ assembly/index.ts:13:34
(get_local $13)
(get_local $12)
)
)
(set_local $4
@ -120,7 +124,7 @@
;;@ assembly/index.ts:18:11
(f64.le
(f64.add
(tee_local $14
(tee_local $8
;;@ assembly/index.ts:18:19
(f64.mul
(get_local $4)
@ -156,20 +160,20 @@
(get_local $5)
)
;;@ assembly/index.ts:20:27
(get_local $10)
(get_local $9)
)
)
;;@ assembly/index.ts:21:6
(set_local $4
;;@ assembly/index.ts:19:19
;;@ assembly/index.ts:19:18
(f64.add
(f64.sub
(get_local $14)
;;@ assembly/index.ts:19:26
(get_local $8)
;;@ assembly/index.ts:19:25
(get_local $7)
)
;;@ assembly/index.ts:19:33
(get_local $11)
;;@ assembly/index.ts:19:32
(get_local $10)
)
)
;;@ assembly/index.ts:22:30
@ -195,52 +199,47 @@
)
)
;;@ assembly/index.ts:27:9
(set_local $9
;;@ assembly/index.ts:27:17
(i32.const 0)
(set_local $8
;;@ assembly/index.ts:27:29
(f64.min
;;@ assembly/index.ts:27:33
(f64.const 8)
;;@ assembly/index.ts:27:36
(f64.convert_u/i32
(get_local $3)
)
)
)
(loop $continue|2
(if
;;@ assembly/index.ts:27:20
(i32.and
(if (result i32)
(tee_local $2
(i32.lt_s
(get_local $9)
;;@ assembly/index.ts:27:24
(i32.const 5)
)
)
;;@ assembly/index.ts:27:29
(i32.lt_u
(get_local $6)
;;@ assembly/index.ts:27:41
(get_local $3)
)
(get_local $2)
;;@ assembly/index.ts:27:44
(f64.lt
(f64.convert_u/i32
(get_local $6)
)
(i32.const 1)
;;@ assembly/index.ts:27:56
(get_local $8)
)
(block
;;@ assembly/index.ts:28:6
(set_local $7
;;@ assembly/index.ts:28:19
;;@ assembly/index.ts:28:18
(f64.add
(f64.sub
(f64.mul
(get_local $4)
;;@ assembly/index.ts:28:24
;;@ assembly/index.ts:28:23
(get_local $4)
)
;;@ assembly/index.ts:28:29
;;@ assembly/index.ts:28:28
(f64.mul
(get_local $5)
;;@ assembly/index.ts:28:34
;;@ assembly/index.ts:28:33
(get_local $5)
)
)
;;@ assembly/index.ts:28:39
(get_local $11)
;;@ assembly/index.ts:28:38
(get_local $10)
)
)
;;@ assembly/index.ts:29:6
@ -257,7 +256,7 @@
(get_local $5)
)
;;@ assembly/index.ts:29:27
(get_local $10)
(get_local $9)
)
)
;;@ assembly/index.ts:30:6
@ -265,18 +264,10 @@
;;@ assembly/index.ts:30:11
(get_local $7)
)
;;@ assembly/index.ts:27:48
(set_local $9
(i32.add
;;@ assembly/index.ts:27:50
(get_local $9)
(i32.const 1)
)
)
;;@ assembly/index.ts:27:53
;;@ assembly/index.ts:27:71
(set_local $6
(i32.add
;;@ assembly/index.ts:27:55
;;@ assembly/index.ts:27:73
(get_local $6)
(i32.const 1)
)
@ -285,88 +276,88 @@
)
)
)
;;@ assembly/index.ts:35:4
;;@ assembly/index.ts:40:4
(i32.store16
;;@ assembly/index.ts:35:15
;;@ assembly/index.ts:40:15
(i32.shl
(i32.add
;;@ assembly/index.ts:35:16
;;@ assembly/index.ts:40:16
(i32.mul
(get_local $0)
;;@ assembly/index.ts:35:20
;;@ assembly/index.ts:40:20
(get_local $1)
)
;;@ assembly/index.ts:35:28
(get_local $8)
;;@ assembly/index.ts:40:28
(get_local $2)
)
;;@ assembly/index.ts:35:34
;;@ assembly/index.ts:40:34
(i32.const 1)
)
;;@ assembly/index.ts:36:6
;;@ assembly/index.ts:37:15
(if (result i32)
(f64.eq
(f64.sub
(tee_local $4
;;@ assembly/index.ts:34:4
(tee_local $7
;;@ assembly/index.ts:34:20
(tee_local $7
;;@ assembly/index.ts:36:4
(tee_local $8
;;@ assembly/index.ts:36:15
(f64.div
;;@ assembly/index.ts:34:27
;;@ assembly/index.ts:36:20
(call $~lib/math/JSMath.log
;;@ assembly/index.ts:34:38
;;@ assembly/index.ts:36:29
(call $~lib/math/JSMath.log
;;@ assembly/index.ts:34:42
(f64.sqrt
;;@ assembly/index.ts:34:47
;;@ assembly/index.ts:36:38
(call $~lib/math/JSMath.sqrt
;;@ assembly/index.ts:36:43
(f64.add
(f64.mul
(get_local $4)
;;@ assembly/index.ts:34:52
;;@ assembly/index.ts:36:48
(get_local $4)
)
;;@ assembly/index.ts:34:57
;;@ assembly/index.ts:36:53
(f64.mul
(get_local $5)
;;@ assembly/index.ts:34:62
;;@ assembly/index.ts:36:58
(get_local $5)
)
)
)
)
)
;;@ assembly/index.ts:34:70
;;@ assembly/index.ts:36:66
(get_global $~lib/math/JSMath.LN2)
)
)
)
(get_local $4)
(get_local $7)
)
(f64.const 0)
)
;;@ assembly/index.ts:37:10
;;@ assembly/index.ts:38:8
(i32.trunc_u/f64
;;@ assembly/index.ts:37:16
;;@ assembly/index.ts:38:14
(f64.mul
(f64.const 2047)
(f64.min
(f64.max
(tee_local $7
;;@ assembly/index.ts:37:41
;;@ assembly/index.ts:38:39
(f64.div
(f64.sub
(f64.convert_u/i32
;;@ assembly/index.ts:37:42
;;@ assembly/index.ts:38:40
(i32.add
(get_local $6)
;;@ assembly/index.ts:37:54
;;@ assembly/index.ts:38:52
(i32.const 1)
)
)
;;@ assembly/index.ts:37:58
(get_local $7)
;;@ assembly/index.ts:38:56
(get_local $8)
)
(f64.convert_u/i32
;;@ assembly/index.ts:37:66
;;@ assembly/index.ts:38:64
(get_local $3)
)
)
@ -377,24 +368,15 @@
)
)
)
;;@ assembly/index.ts:38:10
(i32.div_s
(i32.mul
;;@ assembly/index.ts:38:29
(get_local $6)
;;@ assembly/index.ts:38:11
(i32.const 2047)
)
;;@ assembly/index.ts:38:41
(get_local $3)
)
;;@ assembly/index.ts:39:8
(i32.const 2047)
)
)
;;@ assembly/index.ts:12:34
(set_local $8
(set_local $2
(i32.add
;;@ assembly/index.ts:12:36
(get_local $8)
(get_local $2)
(i32.const 1)
)
)

View File

@ -3,6 +3,7 @@
(type $FF (func (param f64) (result f64)))
(type $Fi (func (param f64) (result i32)))
(type $FFFF (func (param f64 f64 f64) (result f64)))
(import "JSMath" "sqrt" (func $~lib/math/JSMath.sqrt (param f64) (result f64)))
(import "JSMath" "log" (func $~lib/math/JSMath.log (param f64) (result f64)))
(import "JSMath" "LN2" (global $~lib/math/JSMath.LN2 f64))
(import "env" "memory" (memory $0 1))
@ -10,7 +11,7 @@
(global $HEAP_BASE i32 (i32.const 4))
(export "computeLine" (func $assembly/index/computeLine))
(export "memory" (memory $0))
(func $isFinite<f64> (; 1 ;) (type $Fi) (param $0 f64) (result i32)
(func $isFinite<f64> (; 2 ;) (type $Fi) (param $0 f64) (result i32)
;;@ ~lib/builtins.ts:20:26
(return
;;@ ~lib/builtins.ts:20:9
@ -25,24 +26,24 @@
)
)
)
(func $assembly/index/clamp<f64> (; 2 ;) (type $FFFF) (param $0 f64) (param $1 f64) (param $2 f64) (result f64)
;;@ assembly/index.ts:46:43
(func $assembly/index/clamp<f64> (; 3 ;) (type $FFFF) (param $0 f64) (param $1 f64) (param $2 f64) (result f64)
;;@ assembly/index.ts:47:43
(return
;;@ assembly/index.ts:46:9
;;@ assembly/index.ts:47:9
(f64.min
;;@ assembly/index.ts:46:13
;;@ assembly/index.ts:47:13
(f64.max
;;@ assembly/index.ts:46:17
;;@ assembly/index.ts:47:17
(get_local $0)
;;@ assembly/index.ts:46:24
;;@ assembly/index.ts:47:24
(get_local $1)
)
;;@ assembly/index.ts:46:35
;;@ assembly/index.ts:47:35
(get_local $2)
)
)
)
(func $assembly/index/computeLine (; 3 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $assembly/index/computeLine (; 4 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(local $4 f64)
(local $5 f64)
(local $6 f64)
@ -55,7 +56,7 @@
(local $13 f64)
(local $14 i32)
(local $15 f64)
(local $16 i32)
(local $16 f64)
(local $17 i32)
;;@ assembly/index.ts:8:2
(set_local $4
@ -202,14 +203,14 @@
(block
;;@ assembly/index.ts:19:6
(set_local $15
;;@ assembly/index.ts:19:19
;;@ assembly/index.ts:19:18
(f64.add
(f64.sub
(get_local $12)
;;@ assembly/index.ts:19:26
;;@ assembly/index.ts:19:25
(get_local $13)
)
;;@ assembly/index.ts:19:33
;;@ assembly/index.ts:19:32
(get_local $9)
)
)
@ -263,52 +264,47 @@
;;@ assembly/index.ts:27:4
(block $break|2
;;@ assembly/index.ts:27:9
(set_local $16
;;@ assembly/index.ts:27:17
(i32.const 0)
(set_local $15
;;@ assembly/index.ts:27:29
(f64.min
;;@ assembly/index.ts:27:33
(f64.const 8)
;;@ assembly/index.ts:27:36
(f64.convert_u/i32
(get_local $3)
)
)
)
(loop $continue|2
(if
;;@ assembly/index.ts:27:20
(i32.and
(if (result i32)
(tee_local $17
(i32.lt_s
(get_local $16)
;;@ assembly/index.ts:27:24
(i32.const 5)
)
)
;;@ assembly/index.ts:27:29
(i32.lt_u
(get_local $14)
;;@ assembly/index.ts:27:41
(get_local $3)
)
(get_local $17)
;;@ assembly/index.ts:27:44
(f64.lt
(f64.convert_u/i32
(get_local $14)
)
(i32.const 1)
;;@ assembly/index.ts:27:56
(get_local $15)
)
(block
(block
;;@ assembly/index.ts:28:6
(set_local $15
;;@ assembly/index.ts:28:19
(set_local $16
;;@ assembly/index.ts:28:18
(f64.add
(f64.sub
(f64.mul
(get_local $10)
;;@ assembly/index.ts:28:24
;;@ assembly/index.ts:28:23
(get_local $10)
)
;;@ assembly/index.ts:28:29
;;@ assembly/index.ts:28:28
(f64.mul
(get_local $11)
;;@ assembly/index.ts:28:34
;;@ assembly/index.ts:28:33
(get_local $11)
)
)
;;@ assembly/index.ts:28:39
;;@ assembly/index.ts:28:38
(get_local $9)
)
)
@ -332,25 +328,15 @@
;;@ assembly/index.ts:30:6
(set_local $10
;;@ assembly/index.ts:30:11
(get_local $15)
(get_local $16)
)
)
;;@ assembly/index.ts:27:48
(block
(set_local $16
(i32.add
;;@ assembly/index.ts:27:50
(get_local $16)
(i32.const 1)
)
)
;;@ assembly/index.ts:27:53
(set_local $14
(i32.add
;;@ assembly/index.ts:27:55
(get_local $14)
(i32.const 1)
)
;;@ assembly/index.ts:27:71
(set_local $14
(i32.add
;;@ assembly/index.ts:27:73
(get_local $14)
(i32.const 1)
)
)
(br $continue|2)
@ -358,117 +344,113 @@
)
)
)
;;@ assembly/index.ts:34:4
;;@ assembly/index.ts:36:4
(set_local $15
;;@ assembly/index.ts:34:20
;;@ assembly/index.ts:36:15
(f64.div
;;@ assembly/index.ts:34:27
;;@ assembly/index.ts:36:20
(call $~lib/math/JSMath.log
;;@ assembly/index.ts:34:38
;;@ assembly/index.ts:36:29
(call $~lib/math/JSMath.log
;;@ assembly/index.ts:34:42
(f64.sqrt
;;@ assembly/index.ts:34:47
;;@ assembly/index.ts:36:38
(call $~lib/math/JSMath.sqrt
;;@ assembly/index.ts:36:43
(f64.add
(f64.mul
(get_local $10)
;;@ assembly/index.ts:34:52
;;@ assembly/index.ts:36:48
(get_local $10)
)
;;@ assembly/index.ts:34:57
;;@ assembly/index.ts:36:53
(f64.mul
(get_local $11)
;;@ assembly/index.ts:34:62
;;@ assembly/index.ts:36:58
(get_local $11)
)
)
)
)
)
;;@ assembly/index.ts:34:70
;;@ assembly/index.ts:36:66
(get_global $~lib/math/JSMath.LN2)
)
)
;;@ assembly/index.ts:35:4
(i32.store16
;;@ assembly/index.ts:35:15
(i32.shl
(i32.add
;;@ assembly/index.ts:35:16
(i32.mul
(get_local $0)
;;@ assembly/index.ts:35:20
(get_local $1)
)
;;@ assembly/index.ts:35:28
(get_local $8)
)
;;@ assembly/index.ts:35:34
(i32.const 1)
)
;;@ assembly/index.ts:36:6
;;@ assembly/index.ts:37:4
(set_local $17
;;@ assembly/index.ts:37:15
(if (result i32)
(call $isFinite<f64>
;;@ assembly/index.ts:36:15
;;@ assembly/index.ts:37:24
(get_local $15)
)
;;@ assembly/index.ts:37:10
;;@ assembly/index.ts:38:8
(i32.trunc_u/f64
;;@ assembly/index.ts:37:16
;;@ assembly/index.ts:38:14
(f64.mul
(f64.convert_s/i32
(i32.sub
;;@ assembly/index.ts:37:17
;;@ assembly/index.ts:38:15
(i32.const 2048)
;;@ assembly/index.ts:37:30
;;@ assembly/index.ts:38:28
(i32.const 1)
)
)
;;@ assembly/index.ts:37:35
;;@ assembly/index.ts:38:33
(call $assembly/index/clamp<f64>
;;@ assembly/index.ts:37:41
;;@ assembly/index.ts:38:39
(f64.div
(f64.sub
(f64.convert_u/i32
;;@ assembly/index.ts:37:42
;;@ assembly/index.ts:38:40
(i32.add
(get_local $14)
;;@ assembly/index.ts:37:54
;;@ assembly/index.ts:38:52
(i32.const 1)
)
)
;;@ assembly/index.ts:37:58
;;@ assembly/index.ts:38:56
(get_local $15)
)
(f64.convert_u/i32
;;@ assembly/index.ts:37:66
;;@ assembly/index.ts:38:64
(get_local $3)
)
)
;;@ assembly/index.ts:37:73
;;@ assembly/index.ts:38:71
(f64.const 0)
;;@ assembly/index.ts:37:78
;;@ assembly/index.ts:38:76
(f64.const 1)
)
)
)
;;@ assembly/index.ts:38:10
(i32.div_s
(i32.mul
(i32.sub
;;@ assembly/index.ts:38:11
(i32.const 2048)
;;@ assembly/index.ts:38:24
(i32.const 1)
)
;;@ assembly/index.ts:38:29
(get_local $14)
)
;;@ assembly/index.ts:38:41
(get_local $3)
;;@ assembly/index.ts:39:8
(i32.sub
(i32.const 2048)
;;@ assembly/index.ts:39:21
(i32.const 1)
)
)
)
;;@ assembly/index.ts:40:4
(i32.store16
;;@ assembly/index.ts:40:15
(i32.shl
(i32.add
;;@ assembly/index.ts:40:16
(i32.mul
(get_local $0)
;;@ assembly/index.ts:40:20
(get_local $1)
)
;;@ assembly/index.ts:40:28
(get_local $8)
)
;;@ assembly/index.ts:40:34
(i32.const 1)
)
;;@ assembly/index.ts:40:37
(get_local $17)
)
)
;;@ assembly/index.ts:12:34
(set_local $8

View File

@ -3,8 +3,8 @@
"version": "1.0.0",
"private": true,
"scripts": {
"asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --importMemory --sourceMap --validate --measure",
"asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat -O3 --importMemory --sourceMap --validate --noDebug --measure",
"asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --use Math=JSMath --importMemory --sourceMap --validate --measure",
"asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat --use Math=JSMath -O3 --importMemory --sourceMap --validate --noDebug --measure",
"asbuild": "npm run asbuild:untouched && npm run asbuild:optimized",
"server": "http-server . -o -c-1"
},

View File

@ -1,16 +1,90 @@
(module
(type $iiv (func (param i32 i32)))
(type $F (func (result f64)))
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $v (func))
(import "JSMath" "random" (func $~lib/math/JSMath.random (result f64)))
(import "env" "abort" (func $abort (param i32 i32 i32 i32)))
(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))
(global $~lib/math/random_seeded (mut i32) (i32.const 0))
(global $~lib/math/random_state0 (mut i64) (i64.const 0))
(global $~lib/math/random_state1 (mut i64) (i64.const 0))
(memory $0 1)
(data (i32.const 4) "\0c\00\00\00~\00l\00i\00b\00/\00m\00a\00t\00h\00.\00t\00s")
(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 (; 1 ;) (type $iiv) (param $0 i32) (param $1 i32)
(func $~lib/math/NativeMath.random (; 1 ;) (type $F) (result f64)
(local $0 i64)
(local $1 i64)
(if
(i32.eqz
(get_global $~lib/math/random_seeded)
)
(block
(call $abort
(i32.const 0)
(i32.const 4)
(i32.const 1007)
(i32.const 24)
)
(unreachable)
)
)
(set_local $0
(get_global $~lib/math/random_state0)
)
(set_global $~lib/math/random_state0
(tee_local $1
(get_global $~lib/math/random_state1)
)
)
(set_global $~lib/math/random_state1
(tee_local $0
(i64.xor
(i64.xor
(i64.xor
(tee_local $0
(i64.xor
(get_local $0)
(i64.shl
(get_local $0)
(i64.const 23)
)
)
)
(i64.shr_u
(get_local $0)
(i64.const 17)
)
)
(get_local $1)
)
(i64.shr_u
(get_local $1)
(i64.const 26)
)
)
)
)
(f64.sub
(f64.reinterpret/i64
(i64.or
(i64.and
(i64.add
(get_local $1)
(get_local $0)
)
(i64.const 4503599627370495)
)
(i64.const 4607182418800017408)
)
)
(f64.const 1)
)
)
(func $../../examples/game-of-life/assembly/index/init (; 2 ;) (type $iiv) (param $0 i32) (param $1 i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
@ -55,8 +129,8 @@
(set_local $4
(if (result i32)
(f64.gt
(call $~lib/math/JSMath.random)
(f64.const 0.15)
(call $~lib/math/NativeMath.random)
(f64.const 0.1)
)
(i32.const 8723366)
(i32.const -1666349)
@ -99,7 +173,7 @@
)
)
)
(func $../../examples/game-of-life/assembly/index/step (; 2 ;) (type $v)
(func $../../examples/game-of-life/assembly/index/step (; 3 ;) (type $v)
(local $0 i32)
(local $1 i32)
(local $2 i32)
@ -128,7 +202,7 @@
(get_global $../../examples/game-of-life/assembly/index/h)
)
(block
(set_local $5
(set_local $4
(select
(i32.sub
(get_local $0)
@ -138,7 +212,7 @@
(get_local $0)
)
)
(set_local $6
(set_local $5
(select
(i32.const 0)
(i32.add
@ -174,7 +248,7 @@
(i32.shl
(i32.add
(i32.mul
(get_local $5)
(get_local $4)
(get_global $../../examples/game-of-life/assembly/index/w)
)
(tee_local $2
@ -198,7 +272,7 @@
(i32.shl
(i32.add
(i32.mul
(get_local $5)
(get_local $4)
(get_global $../../examples/game-of-life/assembly/index/w)
)
(get_local $1)
@ -214,7 +288,7 @@
(i32.shl
(i32.add
(i32.mul
(get_local $5)
(get_local $4)
(get_global $../../examples/game-of-life/assembly/index/w)
)
(tee_local $3
@ -274,7 +348,7 @@
(i32.shl
(i32.add
(i32.mul
(get_local $6)
(get_local $5)
(get_global $../../examples/game-of-life/assembly/index/w)
)
(get_local $2)
@ -290,7 +364,7 @@
(i32.shl
(i32.add
(i32.mul
(get_local $6)
(get_local $5)
(get_global $../../examples/game-of-life/assembly/index/w)
)
(get_local $1)
@ -306,7 +380,7 @@
(i32.shl
(i32.add
(i32.mul
(get_local $6)
(get_local $5)
(get_global $../../examples/game-of-life/assembly/index/w)
)
(get_local $3)
@ -320,7 +394,7 @@
)
(if
(i32.and
(tee_local $4
(tee_local $3
(i32.load
(i32.shl
(i32.add
@ -360,25 +434,23 @@
)
(i32.or
(i32.shl
(tee_local $4
(tee_local $3
(select
(tee_local $4
(tee_local $3
(i32.sub
(i32.shr_u
(tee_local $2
(get_local $4)
(get_local $3)
)
(i32.const 24)
)
(i32.const 7)
(i32.const 10)
)
)
(tee_local $3
(i32.const 0)
)
(i32.const 0)
(i32.gt_s
(get_local $4)
(get_local $3)
(get_local $6)
)
)
)
@ -449,25 +521,23 @@
(tee_local $2
(i32.sub
(i32.shr_u
(get_local $4)
(get_local $3)
(i32.const 24)
)
(i32.const 7)
(i32.const 10)
)
)
(tee_local $3
(i32.const 0)
)
(i32.const 0)
(i32.gt_s
(get_local $2)
(get_local $3)
(get_local $6)
)
)
)
(i32.const 24)
)
(i32.and
(get_local $4)
(get_local $3)
(i32.const 16777215)
)
)

View File

@ -1,19 +1,109 @@
(module
(type $iiv (func (param i32 i32)))
(type $F (func (result f64)))
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $v (func))
(import "JSMath" "random" (func $~lib/math/JSMath.random (result f64)))
(import "env" "abort" (func $abort (param i32 i32 i32 i32)))
(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/BIT_ROT i32 (i32.const 10))
(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))
(global $HEAP_BASE i32 (i32.const 4))
(global $~lib/math/random_seeded (mut i32) (i32.const 0))
(global $~lib/math/random_state0 (mut i64) (i64.const 0))
(global $~lib/math/random_state1 (mut i64) (i64.const 0))
(global $HEAP_BASE i32 (i32.const 32))
(memory $0 1)
(data (i32.const 4) "\0c\00\00\00~\00l\00i\00b\00/\00m\00a\00t\00h\00.\00t\00s\00")
(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 (; 1 ;) (type $iiv) (param $0 i32) (param $1 i32)
(func $~lib/math/NativeMath.random (; 1 ;) (type $F) (result f64)
(local $0 i64)
(local $1 i64)
(local $2 i64)
(if
(i32.eqz
(get_global $~lib/math/random_seeded)
)
(block
(call $abort
(i32.const 0)
(i32.const 4)
(i32.const 1007)
(i32.const 24)
)
(unreachable)
)
)
(set_local $0
(get_global $~lib/math/random_state0)
)
(set_local $1
(get_global $~lib/math/random_state1)
)
(set_global $~lib/math/random_state0
(get_local $1)
)
(set_local $0
(i64.xor
(get_local $0)
(i64.shl
(get_local $0)
(i64.const 23)
)
)
)
(set_local $0
(i64.xor
(get_local $0)
(i64.shr_u
(get_local $0)
(i64.const 17)
)
)
)
(set_local $0
(i64.xor
(get_local $0)
(get_local $1)
)
)
(set_local $0
(i64.xor
(get_local $0)
(i64.shr_u
(get_local $1)
(i64.const 26)
)
)
)
(set_global $~lib/math/random_state1
(get_local $0)
)
(set_local $2
(i64.or
(i64.and
(i64.add
(get_local $1)
(get_local $0)
)
(i64.const 4503599627370495)
)
(i64.const 4607182418800017408)
)
)
(return
(f64.sub
(f64.reinterpret/i64
(get_local $2)
)
(f64.const 1)
)
)
)
(func $../../examples/game-of-life/assembly/index/init (; 2 ;) (type $iiv) (param $0 i32) (param $1 i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
@ -65,8 +155,8 @@
(set_local $6
(if (result i32)
(f64.gt
(call $~lib/math/JSMath.random)
(f64.const 0.15)
(call $~lib/math/NativeMath.random)
(f64.const 0.1)
)
(i32.and
(i32.const 8723366)
@ -120,7 +210,7 @@
)
)
)
(func $../../examples/game-of-life/assembly/index/step (; 2 ;) (type $v)
(func $../../examples/game-of-life/assembly/index/step (; 3 ;) (type $v)
(local $0 i32)
(local $1 i32)
(local $2 i32)
@ -138,15 +228,6 @@
(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
@ -241,222 +322,6 @@
)
)
)
(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
@ -466,53 +331,242 @@
(i32.add
(i32.add
(i32.and
(get_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)
)
)
)
)
(i32.const 1)
)
(i32.and
(get_local $10)
(block $../../examples/game-of-life/assembly/index/get|inlined.1 (result i32)
(set_local $9
(get_local $5)
)
(set_local $8
(get_local $3)
)
(br $../../examples/game-of-life/assembly/index/get|inlined.1
(i32.load
(i32.shl
(i32.add
(i32.mul
(get_local $8)
(get_global $../../examples/game-of-life/assembly/index/w)
)
(get_local $9)
)
(i32.const 2)
)
)
)
)
(i32.const 1)
)
)
(i32.and
(get_local $11)
(block $../../examples/game-of-life/assembly/index/get|inlined.2 (result i32)
(set_local $8
(get_local $7)
)
(set_local $9
(get_local $3)
)
(br $../../examples/game-of-life/assembly/index/get|inlined.2
(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)
)
)
)
)
(i32.const 1)
)
)
(i32.and
(get_local $12)
(block $../../examples/game-of-life/assembly/index/get|inlined.3 (result i32)
(set_local $9
(get_local $6)
)
(set_local $8
(get_local $2)
)
(br $../../examples/game-of-life/assembly/index/get|inlined.3
(i32.load
(i32.shl
(i32.add
(i32.mul
(get_local $8)
(get_global $../../examples/game-of-life/assembly/index/w)
)
(get_local $9)
)
(i32.const 2)
)
)
)
)
(i32.const 1)
)
)
(i32.and
(get_local $14)
(block $../../examples/game-of-life/assembly/index/get|inlined.4 (result i32)
(set_local $8
(get_local $7)
)
(set_local $9
(get_local $2)
)
(br $../../examples/game-of-life/assembly/index/get|inlined.4
(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)
)
)
)
)
(i32.const 1)
)
)
(i32.and
(get_local $15)
(block $../../examples/game-of-life/assembly/index/get|inlined.5 (result i32)
(set_local $9
(get_local $6)
)
(set_local $8
(get_local $4)
)
(br $../../examples/game-of-life/assembly/index/get|inlined.5
(i32.load
(i32.shl
(i32.add
(i32.mul
(get_local $8)
(get_global $../../examples/game-of-life/assembly/index/w)
)
(get_local $9)
)
(i32.const 2)
)
)
)
)
(i32.const 1)
)
)
(i32.and
(get_local $16)
(block $../../examples/game-of-life/assembly/index/get|inlined.6 (result i32)
(set_local $8
(get_local $5)
)
(set_local $9
(get_local $4)
)
(br $../../examples/game-of-life/assembly/index/get|inlined.6
(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)
)
)
)
)
(i32.const 1)
)
)
(i32.and
(get_local $17)
(block $../../examples/game-of-life/assembly/index/get|inlined.7 (result i32)
(set_local $9
(get_local $7)
)
(set_local $8
(get_local $4)
)
(br $../../examples/game-of-life/assembly/index/get|inlined.7
(i32.load
(i32.shl
(i32.add
(i32.mul
(get_local $8)
(get_global $../../examples/game-of-life/assembly/index/w)
)
(get_local $9)
)
(i32.const 2)
)
)
)
)
(i32.const 1)
)
)
)
(set_local $18
(i32.and
(get_local $13)
(i32.const 1)
(set_local $10
(block $../../examples/game-of-life/assembly/index/get|inlined.8 (result i32)
(set_local $9
(get_local $5)
)
(set_local $10
(get_local $2)
)
(br $../../examples/game-of-life/assembly/index/get|inlined.8
(i32.load
(i32.shl
(i32.add
(i32.mul
(get_local $10)
(get_global $../../examples/game-of-life/assembly/index/w)
)
(get_local $9)
)
(i32.const 2)
)
)
)
)
)
(if
(get_local $18)
(i32.and
(get_local $10)
(i32.const 1)
)
(if
(i32.eq
(i32.and
@ -521,51 +575,51 @@
)
(i32.const 2)
)
(block $../../examples/game-of-life/assembly/index/set_fade|inlined.0
(set_local $19
(block $../../examples/game-of-life/assembly/index/rot|inlined.0
(set_local $9
(get_local $5)
)
(set_local $20
(set_local $11
(get_local $2)
)
(set_local $21
(get_local $13)
(set_local $12
(get_local $10)
)
(set_local $22
(set_local $13
(select
(tee_local $22
(tee_local $13
(i32.sub
(i32.shr_u
(get_local $21)
(get_local $12)
(i32.const 24)
)
(i32.const 7)
(i32.const 10)
)
)
(tee_local $23
(tee_local $14
(i32.const 0)
)
(i32.gt_s
(get_local $22)
(get_local $23)
(get_local $13)
(get_local $14)
)
)
)
(block $../../examples/game-of-life/assembly/index/set|inlined.1
(set_local $23
(get_local $19)
(set_local $14
(get_local $9)
)
(set_local $24
(get_local $20)
(set_local $15
(get_local $11)
)
(set_local $25
(set_local $16
(i32.or
(i32.shl
(get_local $22)
(get_local $13)
(i32.const 24)
)
(i32.and
(get_local $21)
(get_local $12)
(i32.const 16777215)
)
)
@ -576,26 +630,26 @@
(i32.add
(get_global $../../examples/game-of-life/assembly/index/s)
(i32.mul
(get_local $24)
(get_local $15)
(get_global $../../examples/game-of-life/assembly/index/w)
)
)
(get_local $23)
(get_local $14)
)
(i32.const 2)
)
(get_local $25)
(get_local $16)
)
)
)
(block $../../examples/game-of-life/assembly/index/set|inlined.2
(set_local $22
(set_local $13
(get_local $5)
)
(set_local $21
(set_local $12
(get_local $2)
)
(set_local $20
(set_local $11
(i32.or
(i32.const 8723366)
(i32.const -16777216)
@ -607,15 +661,15 @@
(i32.add
(get_global $../../examples/game-of-life/assembly/index/s)
(i32.mul
(get_local $21)
(get_local $12)
(get_global $../../examples/game-of-life/assembly/index/w)
)
)
(get_local $22)
(get_local $13)
)
(i32.const 2)
)
(get_local $20)
(get_local $11)
)
)
)
@ -625,13 +679,13 @@
(i32.const 3)
)
(block $../../examples/game-of-life/assembly/index/set|inlined.3
(set_local $20
(set_local $11
(get_local $5)
)
(set_local $21
(set_local $12
(get_local $2)
)
(set_local $22
(set_local $13
(i32.or
(i32.const 15110867)
(i32.const -16777216)
@ -643,62 +697,62 @@
(i32.add
(get_global $../../examples/game-of-life/assembly/index/s)
(i32.mul
(get_local $21)
(get_local $12)
(get_global $../../examples/game-of-life/assembly/index/w)
)
)
(get_local $20)
(get_local $11)
)
(i32.const 2)
)
(get_local $22)
)
)
(block $../../examples/game-of-life/assembly/index/set_fade|inlined.1
(set_local $22
(get_local $5)
)
(set_local $21
(get_local $2)
)
(set_local $20
(get_local $13)
)
(set_local $19
)
(block $../../examples/game-of-life/assembly/index/rot|inlined.1
(set_local $13
(get_local $5)
)
(set_local $12
(get_local $2)
)
(set_local $11
(get_local $10)
)
(set_local $9
(select
(tee_local $19
(tee_local $9
(i32.sub
(i32.shr_u
(get_local $20)
(get_local $11)
(i32.const 24)
)
(i32.const 7)
(i32.const 10)
)
)
(tee_local $25
(tee_local $16
(i32.const 0)
)
(i32.gt_s
(get_local $19)
(get_local $25)
(get_local $9)
(get_local $16)
)
)
)
(block $../../examples/game-of-life/assembly/index/set|inlined.4
(set_local $25
(get_local $22)
(set_local $16
(get_local $13)
)
(set_local $24
(get_local $21)
(set_local $15
(get_local $12)
)
(set_local $23
(set_local $14
(i32.or
(i32.shl
(get_local $19)
(get_local $9)
(i32.const 24)
)
(i32.and
(get_local $20)
(get_local $11)
(i32.const 16777215)
)
)
@ -709,15 +763,15 @@
(i32.add
(get_global $../../examples/game-of-life/assembly/index/s)
(i32.mul
(get_local $24)
(get_local $15)
(get_global $../../examples/game-of-life/assembly/index/w)
)
)
(get_local $25)
(get_local $16)
)
(i32.const 2)
)
(get_local $23)
(get_local $14)
)
)
)

View File

@ -3,11 +3,274 @@
(type $FF (func (param f64) (result f64)))
(type $Fi (func (param f64) (result i32)))
(type $FFFF (func (param f64 f64 f64) (result f64)))
(import "JSMath" "log" (func $~lib/math/JSMath.log (param f64) (result f64)))
(import "JSMath" "LN2" (global $~lib/math/JSMath.LN2 f64))
(memory $0 1)
(export "computeLine" (func $../../examples/mandelbrot/assembly/index/computeLine))
(export "memory" (memory $0))
(func $~lib/math/NativeMath.log (; 0 ;) (type $FF) (param $0 f64) (result f64)
(local $1 i32)
(local $2 i32)
(local $3 i64)
(local $4 f64)
(local $5 i32)
(local $6 f64)
(local $7 f64)
(local $8 f64)
(if
(i32.and
(if (result i32)
(tee_local $5
(i32.lt_u
(tee_local $1
(i32.wrap/i64
(i64.shr_u
(tee_local $3
(i64.reinterpret/f64
(get_local $0)
)
)
(i64.const 32)
)
)
)
(i32.const 1048576)
)
)
(get_local $5)
(i32.shr_u
(get_local $1)
(i32.const 31)
)
)
(i32.const 1)
)
(block
(if
(i64.eq
(i64.shl
(get_local $3)
(i64.const 1)
)
(i64.const 0)
)
(return
(f64.div
(f64.const -1)
(f64.mul
(get_local $0)
(get_local $0)
)
)
)
)
(if
(i32.shr_u
(get_local $1)
(i32.const 31)
)
(return
(f64.div
(f64.sub
(get_local $0)
(get_local $0)
)
(f64.const 0)
)
)
)
(set_local $2
(i32.sub
(get_local $2)
(i32.const 54)
)
)
(set_local $1
(i32.wrap/i64
(i64.shr_u
(tee_local $3
(i64.reinterpret/f64
(f64.mul
(get_local $0)
(f64.const 18014398509481984)
)
)
)
(i64.const 32)
)
)
)
)
(if
(i32.ge_u
(get_local $1)
(i32.const 2146435072)
)
(return
(get_local $0)
)
(if
(i32.and
(if (result i32)
(tee_local $5
(i32.eq
(get_local $1)
(i32.const 1072693248)
)
)
(i64.eq
(i64.shl
(get_local $3)
(i64.const 32)
)
(i64.const 0)
)
(get_local $5)
)
(i32.const 1)
)
(return
(f64.const 0)
)
)
)
)
(set_local $2
(i32.add
(get_local $2)
(i32.sub
(i32.shr_s
(tee_local $1
(i32.add
(get_local $1)
(i32.const 614242)
)
)
(i32.const 20)
)
(i32.const 1023)
)
)
)
(set_local $6
(f64.mul
(f64.mul
(f64.const 0.5)
(tee_local $4
(f64.sub
(f64.reinterpret/i64
(i64.or
(i64.shl
(i64.extend_u/i32
(i32.add
(i32.and
(get_local $1)
(i32.const 1048575)
)
(i32.const 1072079006)
)
)
(i64.const 32)
)
(i64.and
(get_local $3)
(i64.const 4294967295)
)
)
)
(f64.const 1)
)
)
)
(get_local $4)
)
)
(set_local $0
(f64.mul
(tee_local $8
(f64.mul
(tee_local $7
(f64.div
(get_local $4)
(f64.add
(f64.const 2)
(get_local $4)
)
)
)
(get_local $7)
)
)
(get_local $8)
)
)
(f64.add
(f64.add
(f64.sub
(f64.add
(f64.mul
(get_local $7)
(f64.add
(get_local $6)
(f64.add
(f64.mul
(get_local $8)
(f64.add
(f64.const 0.6666666666666735)
(f64.mul
(get_local $0)
(f64.add
(f64.const 0.2857142874366239)
(f64.mul
(get_local $0)
(f64.add
(f64.const 0.1818357216161805)
(f64.mul
(get_local $0)
(f64.const 0.14798198605116586)
)
)
)
)
)
)
)
(f64.mul
(get_local $0)
(f64.add
(f64.const 0.3999999999940942)
(f64.mul
(get_local $0)
(f64.add
(f64.const 0.22222198432149784)
(f64.mul
(get_local $0)
(f64.const 0.15313837699209373)
)
)
)
)
)
)
)
)
(f64.mul
(f64.convert_s/i32
(get_local $2)
)
(f64.const 1.9082149292705877e-10)
)
)
(get_local $6)
)
(get_local $4)
)
(f64.mul
(f64.convert_s/i32
(get_local $2)
)
(f64.const 0.6931471803691238)
)
)
)
(func $isFinite<f64> (; 1 ;) (type $Fi) (param $0 f64) (result i32)
(f64.eq
(f64.sub
@ -31,14 +294,12 @@
(local $5 f64)
(local $6 i32)
(local $7 f64)
(local $8 i32)
(local $9 i32)
(local $8 f64)
(local $9 f64)
(local $10 f64)
(local $11 f64)
(local $12 f64)
(local $13 f64)
(local $14 f64)
(set_local $12
(set_local $11
(f64.div
(f64.convert_u/i32
(get_local $1)
@ -46,7 +307,7 @@
(f64.const 1.6)
)
)
(set_local $10
(set_local $9
(f64.mul
(f64.sub
(f64.convert_u/i32
@ -59,7 +320,7 @@
(f64.const 2)
)
)
(tee_local $13
(tee_local $12
(f64.div
(f64.const 10)
(f64.min
@ -80,22 +341,25 @@
)
)
)
(set_local $2
(i32.const 0)
)
(loop $continue|0
(if
(i32.lt_u
(get_local $8)
(get_local $2)
(get_local $1)
)
(block
(set_local $11
(set_local $10
(f64.mul
(f64.sub
(f64.convert_u/i32
(get_local $8)
(get_local $2)
)
(get_local $12)
(get_local $11)
)
(get_local $13)
(get_local $12)
)
)
(set_local $4
@ -112,13 +376,13 @@
(if
(f64.le
(f64.add
(tee_local $14
(tee_local $7
(f64.mul
(get_local $4)
(get_local $4)
)
)
(tee_local $7
(tee_local $8
(f64.mul
(get_local $5)
(get_local $5)
@ -137,16 +401,16 @@
)
(get_local $5)
)
(get_local $10)
(get_local $9)
)
)
(set_local $4
(f64.add
(f64.sub
(get_local $14)
(get_local $7)
(get_local $8)
)
(get_local $11)
(get_local $10)
)
)
(br_if $break|1
@ -166,29 +430,24 @@
)
)
)
(set_local $9
(i32.const 0)
(set_local $7
(f64.min
(f64.const 8)
(f64.convert_u/i32
(get_local $3)
)
)
)
(loop $continue|2
(if
(i32.and
(if (result i32)
(tee_local $2
(i32.lt_s
(get_local $9)
(i32.const 5)
)
)
(i32.lt_u
(get_local $6)
(get_local $3)
)
(get_local $2)
(f64.lt
(f64.convert_u/i32
(get_local $6)
)
(i32.const 1)
(get_local $7)
)
(block
(set_local $7
(set_local $8
(f64.add
(f64.sub
(f64.mul
@ -200,7 +459,7 @@
(get_local $5)
)
)
(get_local $11)
(get_local $10)
)
)
(set_local $5
@ -212,17 +471,11 @@
)
(get_local $5)
)
(get_local $10)
(get_local $9)
)
)
(set_local $4
(get_local $7)
)
(set_local $9
(i32.add
(get_local $9)
(i32.const 1)
)
(get_local $8)
)
(set_local $6
(i32.add
@ -234,27 +487,6 @@
)
)
)
(set_local $7
(f64.div
(call $~lib/math/JSMath.log
(call $~lib/math/JSMath.log
(f64.sqrt
(f64.add
(f64.mul
(get_local $4)
(get_local $4)
)
(f64.mul
(get_local $5)
(get_local $5)
)
)
)
)
)
(get_global $~lib/math/JSMath.LN2)
)
)
(i32.store16
(i32.shl
(i32.add
@ -262,13 +494,33 @@
(get_local $0)
(get_local $1)
)
(get_local $8)
(get_local $2)
)
(i32.const 1)
)
(if (result i32)
(call $isFinite<f64>
(get_local $7)
(tee_local $7
(f64.div
(call $~lib/math/NativeMath.log
(call $~lib/math/NativeMath.log
(f64.sqrt
(f64.add
(f64.mul
(get_local $4)
(get_local $4)
)
(f64.mul
(get_local $5)
(get_local $5)
)
)
)
)
)
(f64.const 0.6931471805599453)
)
)
)
(i32.trunc_u/f64
(f64.mul
@ -293,18 +545,12 @@
)
)
)
(i32.div_s
(i32.mul
(get_local $6)
(i32.const 2047)
)
(get_local $3)
)
(i32.const 2047)
)
)
(set_local $8
(set_local $2
(i32.add
(get_local $8)
(get_local $2)
(i32.const 1)
)
)

View File

@ -1,15 +1,327 @@
(module
(type $iiiiv (func (param i32 i32 i32 i32)))
(type $FF (func (param f64) (result f64)))
(type $F (func (result f64)))
(type $Fi (func (param f64) (result i32)))
(type $FFFF (func (param f64 f64 f64) (result f64)))
(import "JSMath" "log" (func $~lib/math/JSMath.log (param f64) (result f64)))
(import "JSMath" "LN2" (global $~lib/math/JSMath.LN2 f64))
(global $../../examples/mandelbrot/assembly/index/NUM_COLORS i32 (i32.const 2048))
(global $HEAP_BASE i32 (i32.const 4))
(memory $0 1)
(export "computeLine" (func $../../examples/mandelbrot/assembly/index/computeLine))
(export "memory" (memory $0))
(func $~lib/math/NativeMath.log (; 0 ;) (type $FF) (param $0 f64) (result f64)
(local $1 i64)
(local $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 f64)
(local $6 f64)
(local $7 f64)
(local $8 f64)
(local $9 f64)
(local $10 f64)
(local $11 f64)
(local $12 f64)
(local $13 i32)
(nop)
(set_local $1
(i64.reinterpret/f64
(get_local $0)
)
)
(set_local $2
(i32.wrap/i64
(i64.shr_u
(get_local $1)
(i64.const 32)
)
)
)
(set_local $3
(i32.const 0)
)
(if
(i32.and
(if (result i32)
(tee_local $4
(i32.lt_u
(get_local $2)
(i32.const 1048576)
)
)
(get_local $4)
(i32.and
(i32.shr_u
(get_local $2)
(i32.const 31)
)
(i32.const 1)
)
)
(i32.const 1)
)
(block
(if
(i64.eq
(i64.shl
(get_local $1)
(i64.const 1)
)
(i64.const 0)
)
(return
(f64.div
(f64.const -1)
(f64.mul
(get_local $0)
(get_local $0)
)
)
)
)
(if
(i32.shr_u
(get_local $2)
(i32.const 31)
)
(return
(f64.div
(f64.sub
(get_local $0)
(get_local $0)
)
(f64.const 0)
)
)
)
(set_local $3
(i32.sub
(get_local $3)
(i32.const 54)
)
)
(set_local $0
(f64.mul
(get_local $0)
(f64.const 18014398509481984)
)
)
(set_local $1
(i64.reinterpret/f64
(get_local $0)
)
)
(set_local $2
(i32.wrap/i64
(i64.shr_u
(get_local $1)
(i64.const 32)
)
)
)
)
(if
(i32.ge_u
(get_local $2)
(i32.const 2146435072)
)
(return
(get_local $0)
)
(if
(i32.and
(if (result i32)
(tee_local $4
(i32.eq
(get_local $2)
(i32.const 1072693248)
)
)
(i64.eq
(i64.shl
(get_local $1)
(i64.const 32)
)
(i64.const 0)
)
(get_local $4)
)
(i32.const 1)
)
(return
(f64.const 0)
)
)
)
)
(set_local $2
(i32.add
(get_local $2)
(i32.sub
(i32.const 1072693248)
(i32.const 1072079006)
)
)
)
(set_local $3
(i32.add
(get_local $3)
(i32.sub
(i32.shr_s
(get_local $2)
(i32.const 20)
)
(i32.const 1023)
)
)
)
(set_local $2
(i32.add
(i32.and
(get_local $2)
(i32.const 1048575)
)
(i32.const 1072079006)
)
)
(set_local $1
(i64.or
(i64.shl
(i64.extend_u/i32
(get_local $2)
)
(i64.const 32)
)
(i64.and
(get_local $1)
(i64.const 4294967295)
)
)
)
(set_local $0
(f64.reinterpret/i64
(get_local $1)
)
)
(set_local $5
(f64.sub
(get_local $0)
(f64.const 1)
)
)
(set_local $6
(f64.mul
(f64.mul
(f64.const 0.5)
(get_local $5)
)
(get_local $5)
)
)
(set_local $7
(f64.div
(get_local $5)
(f64.add
(f64.const 2)
(get_local $5)
)
)
)
(set_local $8
(f64.mul
(get_local $7)
(get_local $7)
)
)
(set_local $9
(f64.mul
(get_local $8)
(get_local $8)
)
)
(set_local $10
(f64.mul
(get_local $9)
(f64.add
(f64.const 0.3999999999940942)
(f64.mul
(get_local $9)
(f64.add
(f64.const 0.22222198432149784)
(f64.mul
(get_local $9)
(f64.const 0.15313837699209373)
)
)
)
)
)
)
(set_local $11
(f64.mul
(get_local $8)
(f64.add
(f64.const 0.6666666666666735)
(f64.mul
(get_local $9)
(f64.add
(f64.const 0.2857142874366239)
(f64.mul
(get_local $9)
(f64.add
(f64.const 0.1818357216161805)
(f64.mul
(get_local $9)
(f64.const 0.14798198605116586)
)
)
)
)
)
)
)
)
(set_local $12
(f64.add
(get_local $11)
(get_local $10)
)
)
(set_local $13
(get_local $3)
)
(return
(f64.add
(f64.add
(f64.sub
(f64.add
(f64.mul
(get_local $7)
(f64.add
(get_local $6)
(get_local $12)
)
)
(f64.mul
(f64.convert_s/i32
(get_local $13)
)
(f64.const 1.9082149292705877e-10)
)
)
(get_local $6)
)
(get_local $5)
)
(f64.mul
(f64.convert_s/i32
(get_local $13)
)
(f64.const 0.6931471803691238)
)
)
)
)
(func $isFinite<f64> (; 1 ;) (type $Fi) (param $0 f64) (result i32)
(return
(f64.eq
@ -45,7 +357,7 @@
(local $13 f64)
(local $14 i32)
(local $15 f64)
(local $16 i32)
(local $16 f64)
(local $17 i32)
(set_local $4
(f64.div
@ -193,30 +505,25 @@
)
)
(block $break|2
(set_local $16
(i32.const 0)
(set_local $15
(f64.min
(f64.const 8)
(f64.convert_u/i32
(get_local $3)
)
)
)
(loop $continue|2
(if
(i32.and
(if (result i32)
(tee_local $17
(i32.lt_s
(get_local $16)
(i32.const 5)
)
)
(i32.lt_u
(get_local $14)
(get_local $3)
)
(get_local $17)
(f64.lt
(f64.convert_u/i32
(get_local $14)
)
(i32.const 1)
(get_local $15)
)
(block
(block
(set_local $15
(set_local $16
(f64.add
(f64.sub
(f64.mul
@ -244,21 +551,13 @@
)
)
(set_local $10
(get_local $15)
(get_local $16)
)
)
(block
(set_local $16
(i32.add
(get_local $16)
(i32.const 1)
)
)
(set_local $14
(i32.add
(get_local $14)
(i32.const 1)
)
(set_local $14
(i32.add
(get_local $14)
(i32.const 1)
)
)
(br $continue|2)
@ -268,36 +567,33 @@
)
(set_local $15
(f64.div
(call $~lib/math/JSMath.log
(call $~lib/math/JSMath.log
(f64.sqrt
(f64.add
(f64.mul
(get_local $10)
(get_local $10)
(call $~lib/math/NativeMath.log
(call $~lib/math/NativeMath.log
(block $~lib/math/NativeMath.sqrt|inlined.0 (result f64)
(set_local $15
(f64.add
(f64.mul
(get_local $10)
(get_local $10)
)
(f64.mul
(get_local $11)
(get_local $11)
)
)
(f64.mul
(get_local $11)
(get_local $11)
)
(br $~lib/math/NativeMath.sqrt|inlined.0
(f64.sqrt
(get_local $15)
)
)
)
)
)
(get_global $~lib/math/JSMath.LN2)
(f64.const 0.6931471805599453)
)
)
(i32.store16
(i32.shl
(i32.add
(i32.mul
(get_local $0)
(get_local $1)
)
(get_local $8)
)
(i32.const 1)
)
(set_local $17
(if (result i32)
(call $isFinite<f64>
(get_local $15)
@ -330,18 +626,25 @@
)
)
)
(i32.div_s
(i32.mul
(i32.sub
(i32.const 2048)
(i32.const 1)
)
(get_local $14)
)
(get_local $3)
(i32.sub
(i32.const 2048)
(i32.const 1)
)
)
)
(i32.store16
(i32.shl
(i32.add
(i32.mul
(get_local $0)
(get_local $1)
)
(get_local $8)
)
(i32.const 1)
)
(get_local $17)
)
)
(set_local $8
(i32.add