Implement reference counting (#592)

This commit is contained in:
Daniel Wirtz
2019-06-05 23:15:39 +02:00
committed by GitHub
parent 3ed76a97f0
commit 0484a6b740
601 changed files with 261645 additions and 146131 deletions

View File

@ -43,7 +43,7 @@ export function computeLine(y: u32, width: u32, height: u32, limit: u32): void {
let sqd = ix * ix + iy * iy;
if (sqd > 1.0) {
let frac = Math.log2(0.5 * Math.log(sqd));
col = <u32>((NUM_COLORS - 1) * clamp((iteration + 1 - frac) * invLimit, 0.0, 1.0));
col = <u32>((NUM_COLORS - 1) * clamp<f64>((iteration + 1 - frac) * invLimit, 0.0, 1.0));
}
store<u16>(stride + (x << 1), col);
}

View File

@ -8,12 +8,6 @@ declare module ASModule {
type f32 = number;
type f64 = number;
type bool = any;
namespace JSMath {
function log(x: f64): f64;
function log2(x: f64): f64;
}
var NUM_COLORS: i32;
function computeLine(y: u32, width: u32, height: u32, limit: u32): void;
function clamp<f64>(value: f64, minValue: f64, maxValue: f64): f64;
}
export default ASModule;

View File

@ -5,52 +5,51 @@
(import "env" "memory" (memory $0 0))
(import "Math" "log" (func $~lib/bindings/Math/log (param f64) (result f64)))
(import "Math" "log2" (func $~lib/bindings/Math/log2 (param f64) (result f64)))
(table $0 1 funcref)
(elem (i32.const 0) $null)
(export "memory" (memory $0))
(export "table" (table $0))
(export "computeLine" (func $assembly/index/computeLine))
(func $assembly/index/computeLine (; 2 ;) (type $FUNCSIG$viiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(local $4 f64)
(local $5 f64)
(local $6 f64)
(local $7 i32)
(local $8 f64)
(local $8 i32)
(local $9 f64)
(local $10 f64)
(local $11 f64)
(local $12 f64)
(local $13 f64)
(local $14 f64)
f64.const 10
f64.const 3
(local $15 f64)
local.get $1
f64.convert_i32_u
local.tee $8
local.tee $9
f64.const 0.625
f64.mul
f64.const 4
local.get $2
f64.convert_i32_u
local.tee $4
f64.mul
f64.min
f64.div
local.set $9
local.set $4
local.get $0
f64.convert_i32_u
local.get $4
local.get $2
f64.convert_i32_u
local.tee $6
f64.const 0.5
f64.mul
f64.sub
f64.const 10
f64.const 3
local.get $9
f64.mul
local.set $10
local.get $8
f64.const 0.625
f64.const 4
local.get $6
f64.mul
local.get $9
f64.min
f64.div
local.tee $10
f64.mul
local.set $12
local.set $11
local.get $4
local.get $10
f64.mul
local.set $13
local.get $0
local.get $1
i32.mul
@ -62,34 +61,35 @@
f64.convert_i32_u
local.tee $6
f64.div
local.set $13
local.set $14
f64.const 8
local.get $6
f64.min
local.set $8
local.set $15
loop $repeat|0
local.get $7
local.get $1
i32.lt_u
if
local.get $7
block $break|0
local.get $8
local.get $1
i32.ge_u
br_if $break|0
local.get $8
f64.convert_i32_u
local.get $9
local.get $10
f64.mul
local.get $12
local.get $13
f64.sub
local.set $11
local.set $12
f64.const 0
local.set $4
f64.const 0
local.set $5
i32.const 0
local.set $2
local.set $7
loop $continue|1
local.get $4
local.get $4
f64.mul
local.tee $14
local.tee $9
local.get $5
local.get $5
f64.mul
@ -104,31 +104,31 @@
f64.mul
local.get $5
f64.mul
local.get $10
f64.add
local.set $5
local.get $14
local.get $6
f64.sub
local.get $11
f64.add
local.set $5
local.get $9
local.get $6
f64.sub
local.get $12
f64.add
local.set $4
local.get $2
local.get $7
local.get $3
i32.ge_u
br_if $break|1
local.get $2
local.get $7
i32.const 1
i32.add
local.set $2
local.set $7
br $continue|1
end
end
end
loop $continue|2
local.get $2
local.get $7
f64.convert_i32_u
local.get $8
local.get $15
f64.lt
if
local.get $4
@ -138,7 +138,7 @@
local.get $5
f64.mul
f64.sub
local.get $11
local.get $12
f64.add
local.set $6
f64.const 2
@ -146,19 +146,21 @@
f64.mul
local.get $5
f64.mul
local.get $10
local.get $11
f64.add
local.set $5
local.get $6
local.set $4
local.get $2
local.get $7
i32.const 1
i32.add
local.set $2
local.set $7
br $continue|2
end
end
local.get $7
i32.const 2047
local.set $2
local.get $8
i32.const 1
i32.shl
local.get $0
@ -175,7 +177,7 @@
f64.gt
if (result i32)
f64.const 2047
local.get $2
local.get $7
i32.const 1
i32.add
f64.convert_i32_u
@ -185,7 +187,7 @@
f64.mul
call $~lib/bindings/Math/log2
f64.sub
local.get $13
local.get $14
f64.mul
f64.const 0
f64.max
@ -197,10 +199,10 @@
i32.const 2047
end
i32.store16
local.get $7
local.get $8
i32.const 1
i32.add
local.set $7
local.set $8
br $repeat|0
end
end

View File

@ -1,7 +1,6 @@
(module
(type $FUNCSIG$viiii (func (param i32 i32 i32 i32)))
(type $FUNCSIG$dd (func (param f64) (result f64)))
(type $FUNCSIG$dddd (func (param f64 f64 f64) (result f64)))
(type $FUNCSIG$v (func))
(import "env" "memory" (memory $0 0))
(import "Math" "log" (func $~lib/bindings/Math/log (param f64) (result f64)))
@ -9,18 +8,9 @@
(table $0 1 funcref)
(elem (i32.const 0) $null)
(global $assembly/index/NUM_COLORS i32 (i32.const 2048))
(global $~lib/memory/HEAP_BASE i32 (i32.const 8))
(export "memory" (memory $0))
(export "table" (table $0))
(export "computeLine" (func $assembly/index/computeLine))
(func $assembly/index/clamp<f64> (; 2 ;) (type $FUNCSIG$dddd) (param $0 f64) (param $1 f64) (param $2 f64) (result f64)
local.get $0
local.get $1
f64.max
local.get $2
f64.min
)
(func $assembly/index/computeLine (; 3 ;) (type $FUNCSIG$viiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(func $assembly/index/computeLine (; 2 ;) (type $FUNCSIG$viiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32)
(local $4 f64)
(local $5 f64)
(local $6 f64)
@ -39,6 +29,9 @@
(local $19 f64)
(local $20 i32)
(local $21 f64)
(local $22 f64)
(local $23 f64)
(local $24 f64)
local.get $1
f64.convert_i32_u
f64.const 1
@ -101,127 +94,123 @@
i32.lt_u
i32.eqz
br_if $break|0
block
local.get $12
f64.convert_i32_u
local.get $6
f64.mul
local.get $8
f64.sub
local.set $13
f64.const 0
local.set $14
f64.const 0
local.set $15
i32.const 0
local.set $18
block $break|1
loop $continue|1
local.get $14
local.get $12
f64.convert_i32_u
local.get $6
f64.mul
local.get $8
f64.sub
local.set $13
f64.const 0
local.set $14
f64.const 0
local.set $15
i32.const 0
local.set $18
block $break|1
loop $continue|1
local.get $14
local.get $14
f64.mul
local.tee $16
local.get $15
local.get $15
f64.mul
local.tee $17
f64.add
f64.const 4
f64.le
if
f64.const 2
local.get $14
f64.mul
local.tee $16
local.get $15
local.get $15
f64.mul
local.tee $17
local.get $7
f64.add
f64.const 4
f64.le
if
block
f64.const 2
local.get $14
f64.mul
local.get $15
f64.mul
local.get $7
f64.add
local.set $15
local.get $16
local.get $17
f64.sub
local.get $13
f64.add
local.set $14
local.get $18
local.get $3
i32.ge_u
if
br $break|1
end
local.get $18
i32.const 1
i32.add
local.set $18
end
br $continue|1
end
end
end
block $break|2
loop $continue|2
local.set $15
local.get $16
local.get $17
f64.sub
local.get $13
f64.add
local.set $14
local.get $18
f64.convert_i32_u
local.get $11
f64.lt
local.get $3
i32.ge_u
if
block
local.get $14
local.get $14
f64.mul
local.get $15
local.get $15
f64.mul
f64.sub
local.get $13
f64.add
local.set $19
f64.const 2
local.get $14
f64.mul
local.get $15
f64.mul
local.get $7
f64.add
local.set $15
local.get $19
local.set $14
local.get $18
i32.const 1
i32.add
local.set $18
end
br $continue|2
br $break|1
end
local.get $18
i32.const 1
i32.add
local.set $18
br $continue|1
end
end
end
block $break|2
loop $continue|2
local.get $18
f64.convert_i32_u
local.get $11
f64.lt
if
local.get $14
local.get $14
f64.mul
local.get $15
local.get $15
f64.mul
f64.sub
local.get $13
f64.add
local.set $19
f64.const 2
local.get $14
f64.mul
local.get $15
f64.mul
local.get $7
f64.add
local.set $15
local.get $19
local.set $14
local.get $18
i32.const 1
i32.add
local.set $18
br $continue|2
end
end
end
global.get $assembly/index/NUM_COLORS
i32.const 1
i32.sub
local.set $20
local.get $14
local.get $14
f64.mul
local.get $15
local.get $15
f64.mul
f64.add
local.set $19
local.get $19
f64.const 1
f64.gt
if
f64.const 0.5
local.get $19
call $~lib/bindings/Math/log
f64.mul
call $~lib/bindings/Math/log2
local.set $21
global.get $assembly/index/NUM_COLORS
i32.const 1
i32.sub
local.set $20
local.get $14
local.get $14
f64.mul
local.get $15
local.get $15
f64.mul
f64.add
local.set $19
local.get $19
f64.const 1
f64.gt
if
f64.const 0.5
local.get $19
call $~lib/bindings/Math/log
f64.mul
call $~lib/bindings/Math/log2
local.set $21
global.get $assembly/index/NUM_COLORS
i32.const 1
i32.sub
f64.convert_i32_s
f64.convert_i32_s
block $assembly/index/clamp<f64>|inlined.0 (result f64)
local.get $18
i32.const 1
i32.add
@ -230,21 +219,28 @@
f64.sub
local.get $10
f64.mul
local.set $24
f64.const 0
local.set $23
f64.const 1
call $assembly/index/clamp<f64>
f64.mul
i32.trunc_f64_u
local.set $20
local.set $22
local.get $24
local.get $23
f64.max
local.get $22
f64.min
end
local.get $9
local.get $12
i32.const 1
i32.shl
i32.add
local.get $20
i32.store16
f64.mul
i32.trunc_f64_u
local.set $20
end
local.get $9
local.get $12
i32.const 1
i32.shl
i32.add
local.get $20
i32.store16
local.get $12
i32.const 1
i32.add
@ -255,6 +251,6 @@
unreachable
end
)
(func $null (; 4 ;) (type $FUNCSIG$v)
(func $null (; 3 ;) (type $FUNCSIG$v)
)
)

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 --use Math=JSMath --importMemory --sourceMap --debug --validate --measure",
"asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat -d build/optimized.d.ts --use Math=JSMath -O3 --importMemory --sourceMap --validate --measure",
"asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --use Math=JSMath --runtime none --importMemory --sourceMap --debug --validate --measure",
"asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat -d build/optimized.d.ts --use Math=JSMath --runtime none -O3 --importMemory --sourceMap --validate --measure",
"asbuild": "npm run asbuild:untouched && npm run asbuild:optimized",
"server": "http-server . -o -c-1"
},