Add some smoothing to mandelbrot example

This commit is contained in:
dcodeIO
2018-04-20 05:06:05 +02:00
parent 9cd3304e13
commit b53b3e08ec
16 changed files with 1441 additions and 810 deletions

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,10 +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 (; 1 ;) (type $iiFv) (param $0 i32) (param $1 i32) (param $2 f64)
(func $../../examples/game-of-life/assembly/index/init (; 1 ;) (type $iiv) (param $0 i32) (param $1 i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
(set_global $../../examples/game-of-life/assembly/index/w
(get_local $0)
)
@ -46,13 +46,13 @@
(get_global $../../examples/game-of-life/assembly/index/w)
)
(block
(set_local $3
(set_local $2
(get_local $1)
)
(set_local $4
(set_local $3
(get_local $0)
)
(set_local $5
(set_local $4
(if (result i32)
(f64.gt
(call $~lib/math/JSMath.random)
@ -68,15 +68,15 @@
(i32.add
(get_global $../../examples/game-of-life/assembly/index/s)
(i32.mul
(get_local $4)
(get_local $3)
(get_global $../../examples/game-of-life/assembly/index/w)
)
)
(get_local $3)
(get_local $2)
)
(i32.const 2)
)
(get_local $5)
(get_local $4)
)
(set_local $1
(i32.add
@ -337,37 +337,12 @@
(i32.const 1)
)
(if
(i32.and
(if (result i32)
(tee_local $3
(i32.lt_u
(get_local $2)
(i32.const 2)
)
)
(get_local $3)
(i32.gt_u
(get_local $2)
(i32.const 3)
)
(i32.eq
(i32.and
(get_local $2)
(i32.const 14)
)
(i32.const 1)
)
(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.const -8053850)
(i32.const 2)
)
(i32.store
(i32.shl
@ -390,7 +365,7 @@
(tee_local $4
(i32.sub
(i32.shr_u
(tee_local $3
(tee_local $2
(get_local $4)
)
(i32.const 24)
@ -398,23 +373,39 @@
(i32.const 7)
)
)
(tee_local $2
(tee_local $3
(i32.const 0)
)
(i32.gt_s
(get_local $4)
(get_local $2)
(get_local $3)
)
)
)
(i32.const 24)
)
(i32.and
(get_local $3)
(get_local $2)
(i32.const 16777215)
)
)
)
(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.const -8053850)
)
)
(if
(i32.eq

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)))
@ -13,12 +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 (; 1 ;) (type $iiFv) (param $0 i32) (param $1 i32) (param $2 f64)
(func $../../examples/game-of-life/assembly/index/init (; 1 ;) (type $iiv) (param $0 i32) (param $1 i32)
(local $2 i32)
(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)
)
@ -32,37 +32,37 @@
)
)
(block $break|0
(set_local $3
(set_local $2
(i32.const 0)
)
(loop $continue|0
(if
(i32.lt_s
(get_local $3)
(get_local $2)
(get_global $../../examples/game-of-life/assembly/index/h)
)
(block
(block
(block $break|1
(set_local $4
(set_local $3
(i32.const 0)
)
(loop $continue|1
(if
(i32.lt_s
(get_local $4)
(get_local $3)
(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
(set_local $4
(get_local $3)
)
(set_local $7
(set_local $5
(get_local $2)
)
(set_local $6
(if (result i32)
(f64.gt
(call $~lib/math/JSMath.random)
@ -84,21 +84,21 @@
(i32.add
(get_global $../../examples/game-of-life/assembly/index/s)
(i32.mul
(get_local $6)
(get_local $5)
(get_global $../../examples/game-of-life/assembly/index/w)
)
)
(get_local $5)
(get_local $4)
)
(i32.const 2)
)
(get_local $7)
(get_local $6)
)
)
)
(set_local $4
(set_local $3
(i32.add
(get_local $4)
(get_local $3)
(i32.const 1)
)
)
@ -108,9 +108,9 @@
)
)
)
(set_local $3
(set_local $2
(i32.add
(get_local $3)
(get_local $2)
(i32.const 1)
)
)
@ -514,60 +514,21 @@
(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)
)
(set_local $20
(get_local $2)
)
(set_local $21
(i32.or
(i32.const 8723366)
(i32.const -16777216)
)
)
(i32.store
(i32.shl
(i32.add
(i32.add
(get_global $../../examples/game-of-life/assembly/index/s)
(i32.mul
(get_local $20)
(get_global $../../examples/game-of-life/assembly/index/w)
)
)
(get_local $19)
)
(i32.const 2)
)
(get_local $21)
(i32.eq
(i32.and
(get_local $8)
(i32.const 14)
)
(i32.const 2)
)
(block $../../examples/game-of-life/assembly/index/set_fade|inlined.0
(set_local $21
(set_local $19
(get_local $5)
)
(set_local $20
(get_local $2)
)
(set_local $19
(set_local $21
(get_local $13)
)
(set_local $22
@ -575,7 +536,7 @@
(tee_local $22
(i32.sub
(i32.shr_u
(get_local $19)
(get_local $21)
(i32.const 24)
)
(i32.const 7)
@ -590,9 +551,9 @@
)
)
)
(block $../../examples/game-of-life/assembly/index/set|inlined.2
(block $../../examples/game-of-life/assembly/index/set|inlined.1
(set_local $23
(get_local $21)
(get_local $19)
)
(set_local $24
(get_local $20)
@ -604,7 +565,7 @@
(i32.const 24)
)
(i32.and
(get_local $19)
(get_local $21)
(i32.const 16777215)
)
)
@ -627,6 +588,36 @@
)
)
)
(block $../../examples/game-of-life/assembly/index/set|inlined.2
(set_local $22
(get_local $5)
)
(set_local $21
(get_local $2)
)
(set_local $20
(i32.or
(i32.const 8723366)
(i32.const -16777216)
)
)
(i32.store
(i32.shl
(i32.add
(i32.add
(get_global $../../examples/game-of-life/assembly/index/s)
(i32.mul
(get_local $21)
(get_global $../../examples/game-of-life/assembly/index/w)
)
)
(get_local $22)
)
(i32.const 2)
)
(get_local $20)
)
)
)
(if
(i32.eq
@ -634,13 +625,13 @@
(i32.const 3)
)
(block $../../examples/game-of-life/assembly/index/set|inlined.3
(set_local $22
(set_local $20
(get_local $5)
)
(set_local $19
(set_local $21
(get_local $2)
)
(set_local $20
(set_local $22
(i32.or
(i32.const 15110867)
(i32.const -16777216)
@ -652,33 +643,33 @@
(i32.add
(get_global $../../examples/game-of-life/assembly/index/s)
(i32.mul
(get_local $19)
(get_local $21)
(get_global $../../examples/game-of-life/assembly/index/w)
)
)
(get_local $22)
(get_local $20)
)
(i32.const 2)
)
(get_local $20)
(get_local $22)
)
)
(block $../../examples/game-of-life/assembly/index/set_fade|inlined.1
(set_local $20
(set_local $22
(get_local $5)
)
(set_local $19
(set_local $21
(get_local $2)
)
(set_local $22
(set_local $20
(get_local $13)
)
(set_local $21
(set_local $19
(select
(tee_local $21
(tee_local $19
(i32.sub
(i32.shr_u
(get_local $22)
(get_local $20)
(i32.const 24)
)
(i32.const 7)
@ -688,26 +679,26 @@
(i32.const 0)
)
(i32.gt_s
(get_local $21)
(get_local $19)
(get_local $25)
)
)
)
(block $../../examples/game-of-life/assembly/index/set|inlined.4
(set_local $25
(get_local $20)
(get_local $22)
)
(set_local $24
(get_local $19)
(get_local $21)
)
(set_local $23
(i32.or
(i32.shl
(get_local $21)
(get_local $19)
(i32.const 24)
)
(i32.and
(get_local $22)
(get_local $20)
(i32.const 16777215)
)
)

View File

@ -1,22 +1,26 @@
(module
(type $iiiv (func (param i32 i32 i32)))
(type $FF (func (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))
(memory $0 1)
(export "compute" (func $../../examples/mandelbrot/assembly/index/compute))
(export "memory" (memory $0))
(func $../../examples/mandelbrot/assembly/index/compute (; 0 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32)
(local $4 i32)
(func $../../examples/mandelbrot/assembly/index/compute (; 1 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 f64)
(local $4 f64)
(local $5 i32)
(local $6 f64)
(local $7 f64)
(local $6 i32)
(local $7 i32)
(local $8 f64)
(local $9 f64)
(local $9 i32)
(local $10 f64)
(local $11 f64)
(local $12 f64)
(local $13 f64)
(local $14 f64)
(set_local $9
(local $15 f64)
(set_local $13
(f64.div
(f64.convert_u/i32
(get_local $0)
@ -24,7 +28,7 @@
(f64.const 1.6)
)
)
(set_local $10
(set_local $14
(f64.div
(f64.convert_u/i32
(get_local $1)
@ -32,18 +36,29 @@
(f64.const 2)
)
)
(set_local $8
(set_local $10
(f64.div
(f64.const 4)
(f64.convert_u/i32
(get_local $0)
(f64.const 10)
(f64.min
(f64.mul
(f64.const 3)
(f64.convert_u/i32
(get_local $0)
)
)
(f64.mul
(f64.const 4)
(f64.convert_u/i32
(get_local $1)
)
)
)
)
)
(loop $continue|0
(if
(i32.lt_u
(get_local $3)
(get_local $5)
(get_local $1)
)
(block
@ -51,20 +66,20 @@
(f64.mul
(f64.sub
(f64.convert_u/i32
(get_local $3)
(get_local $5)
)
(get_local $10)
(get_local $14)
)
(get_local $8)
(get_local $10)
)
)
(set_local $4
(set_local $6
(i32.const 0)
)
(loop $continue|1
(if
(i32.lt_u
(get_local $4)
(get_local $6)
(get_local $0)
)
(block
@ -72,78 +87,73 @@
(f64.mul
(f64.sub
(f64.convert_u/i32
(get_local $4)
(get_local $6)
)
(get_local $9)
(get_local $13)
)
(get_local $8)
(get_local $10)
)
)
(set_local $5
(set_local $3
(f64.const 0)
)
(set_local $4
(f64.const 0)
)
(set_local $7
(i32.const 0)
)
(block $break|2
(set_local $6
(f64.const 0)
)
(set_local $7
(f64.const 0)
)
(loop $continue|2
(if
(f64.le
(f64.add
(tee_local $13
(tee_local $15
(f64.mul
(get_local $6)
(get_local $6)
(get_local $3)
(get_local $3)
)
)
(tee_local $14
(tee_local $8
(f64.mul
(get_local $7)
(get_local $7)
(get_local $4)
(get_local $4)
)
)
)
(f64.const 4)
)
(block
(set_local $7
(set_local $4
(f64.add
(f64.mul
(f64.mul
(f64.const 2)
(get_local $6)
(get_local $3)
)
(get_local $7)
(get_local $4)
)
(get_local $11)
)
)
(set_local $6
(set_local $3
(f64.add
(f64.sub
(get_local $13)
(get_local $14)
(get_local $15)
(get_local $8)
)
(get_local $12)
)
)
(br_if $break|2
(i32.ge_u
(tee_local $5
(i32.add
(get_local $5)
(i32.const 1)
)
)
(get_local $7)
(get_local $2)
)
)
(set_local $5
(set_local $7
(i32.add
(get_local $5)
(get_local $7)
(i32.const 1)
)
)
@ -152,25 +162,141 @@
)
)
)
(i32.store8
(i32.add
(i32.mul
(get_local $3)
(get_local $0)
(set_local $9
(i32.const 0)
)
(loop $continue|3
(if
(i32.lt_s
(get_local $9)
(i32.const 4)
)
(get_local $4)
)
(i32.div_u
(i32.mul
(get_local $5)
(i32.const 255)
(block
(set_local $8
(f64.add
(f64.sub
(f64.mul
(get_local $3)
(get_local $3)
)
(f64.mul
(get_local $4)
(get_local $4)
)
)
(get_local $12)
)
)
(set_local $4
(f64.add
(f64.mul
(f64.mul
(f64.const 2)
(get_local $3)
)
(get_local $4)
)
(get_local $11)
)
)
(set_local $3
(get_local $8)
)
(set_local $9
(i32.add
(get_local $9)
(i32.const 1)
)
)
(br $continue|3)
)
(get_local $2)
)
)
(set_local $4
(if
(f64.gt
(tee_local $8
(f64.div
(call $~lib/math/JSMath.log
(call $~lib/math/JSMath.log
(f64.sqrt
(f64.add
(f64.mul
(get_local $3)
(get_local $3)
)
(f64.mul
(get_local $4)
(get_local $4)
)
)
)
)
)
(get_global $~lib/math/JSMath.LN2)
)
)
(f64.const 0)
)
(i32.store16
(i32.shl
(i32.add
(i32.mul
(get_local $5)
(get_local $0)
)
(get_local $6)
)
(i32.const 1)
)
(i32.trunc_u/f64
(f64.mul
(f64.const 2047)
(f64.max
(f64.min
(f64.div
(f64.sub
(f64.convert_u/i32
(i32.add
(get_local $7)
(i32.const 1)
)
)
(get_local $8)
)
(f64.convert_u/i32
(get_local $2)
)
)
(f64.const 1)
)
(f64.const 0)
)
)
)
)
(i32.store16
(i32.shl
(i32.add
(i32.mul
(get_local $5)
(get_local $0)
)
(get_local $6)
)
(i32.const 1)
)
(i32.div_u
(i32.mul
(get_local $7)
(i32.const 2047)
)
(get_local $2)
)
)
)
(set_local $6
(i32.add
(get_local $4)
(get_local $6)
(i32.const 1)
)
)
@ -178,9 +304,9 @@
)
)
)
(set_local $3
(set_local $5
(i32.add
(get_local $3)
(get_local $5)
(i32.const 1)
)
)

View File

@ -1,10 +1,13 @@
(module
(type $iiiv (func (param i32 i32 i32)))
(type $FF (func (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))
(global $HEAP_BASE i32 (i32.const 4))
(memory $0 1)
(export "compute" (func $../../examples/mandelbrot/assembly/index/compute))
(export "memory" (memory $0))
(func $../../examples/mandelbrot/assembly/index/compute (; 0 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(func $../../examples/mandelbrot/assembly/index/compute (; 1 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 f64)
(local $4 f64)
(local $5 f64)
@ -12,12 +15,14 @@
(local $7 f64)
(local $8 i32)
(local $9 f64)
(local $10 i32)
(local $10 f64)
(local $11 f64)
(local $12 f64)
(local $13 f64)
(local $14 f64)
(local $14 i32)
(local $15 f64)
(local $16 i32)
(local $17 f64)
(set_local $3
(f64.div
(f64.convert_u/i32
@ -36,9 +41,20 @@
)
(set_local $5
(f64.div
(f64.const 4)
(f64.convert_u/i32
(get_local $0)
(f64.const 10)
(f64.min
(f64.mul
(f64.const 3)
(f64.convert_u/i32
(get_local $0)
)
)
(f64.mul
(f64.const 4)
(f64.convert_u/i32
(get_local $1)
)
)
)
)
)
@ -88,33 +104,32 @@
(get_local $5)
)
)
(set_local $10
(block
(set_local $10
(f64.const 0)
)
(set_local $11
(f64.const 0)
)
)
(set_local $14
(i32.const 0)
)
(nop)
(block $break|2
(block
(set_local $13
(f64.const 0)
)
(set_local $14
(f64.const 0)
)
)
(loop $continue|2
(if
(f64.le
(f64.add
(tee_local $11
(f64.mul
(get_local $13)
(get_local $13)
)
)
(tee_local $12
(f64.mul
(get_local $14)
(get_local $14)
(get_local $10)
(get_local $10)
)
)
(tee_local $13
(f64.mul
(get_local $11)
(get_local $11)
)
)
)
@ -125,44 +140,39 @@
(set_local $15
(f64.add
(f64.sub
(get_local $11)
(get_local $12)
(get_local $13)
)
(get_local $9)
)
)
(set_local $14
(set_local $11
(f64.add
(f64.mul
(f64.mul
(f64.const 2)
(get_local $13)
(get_local $10)
)
(get_local $14)
(get_local $11)
)
(get_local $7)
)
)
(set_local $13
(set_local $10
(get_local $15)
)
(if
(i32.ge_u
(tee_local $10
(i32.add
(get_local $10)
(i32.const 1)
)
)
(get_local $14)
(get_local $2)
)
(br $break|2)
)
)
(set_local $10
(i32.add
(get_local $10)
(i32.const 1)
(set_local $14
(i32.add
(get_local $14)
(i32.const 1)
)
)
)
(br $continue|2)
@ -170,20 +180,152 @@
)
)
)
(i32.store8
(i32.add
(i32.mul
(get_local $6)
(get_local $0)
)
(get_local $8)
(block $break|3
(set_local $16
(i32.const 0)
)
(i32.div_u
(i32.mul
(get_local $10)
(i32.const 255)
(loop $continue|3
(if
(i32.lt_s
(get_local $16)
(i32.const 4)
)
(block
(block
(set_local $15
(f64.add
(f64.sub
(tee_local $12
(f64.mul
(get_local $10)
(get_local $10)
)
)
(tee_local $13
(f64.mul
(get_local $11)
(get_local $11)
)
)
)
(get_local $9)
)
)
(set_local $11
(f64.add
(f64.mul
(f64.mul
(f64.const 2)
(get_local $10)
)
(get_local $11)
)
(get_local $7)
)
)
(set_local $10
(get_local $15)
)
)
(set_local $16
(i32.add
(get_local $16)
(i32.const 1)
)
)
(br $continue|3)
)
)
)
)
(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)
)
(f64.mul
(get_local $11)
(get_local $11)
)
)
)
)
)
(get_global $~lib/math/JSMath.LN2)
)
)
(if
(f64.gt
(get_local $15)
(f64.const 0)
)
(block
(set_local $17
(f64.max
(f64.min
(f64.div
(f64.sub
(f64.convert_u/i32
(i32.add
(get_local $14)
(i32.const 1)
)
)
(get_local $15)
)
(f64.convert_u/i32
(get_local $2)
)
)
(f64.const 1)
)
(f64.const 0)
)
)
(i32.store16
(i32.shl
(i32.add
(i32.mul
(get_local $6)
(get_local $0)
)
(get_local $8)
)
(i32.const 1)
)
(i32.trunc_u/f64
(f64.mul
(f64.convert_u/i32
(i32.const 2047)
)
(get_local $17)
)
)
)
)
(i32.store16
(i32.shl
(i32.add
(i32.mul
(get_local $6)
(get_local $0)
)
(get_local $8)
)
(i32.const 1)
)
(i32.div_u
(i32.mul
(get_local $14)
(i32.const 2047)
)
(get_local $2)
)
(get_local $2)
)
)
)