Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (module
- (import "js" "mem" (memory 17))
- (func $mandelbrot
- (local $x0 f64)
- (local $ox f64)
- (local $ox2 f64)
- (local $y0 f64)
- (local $oy f64)
- (local $oy2 f64)
- (local $oxy f64)
- (local $addr i32)
- (local $a i32)
- (local $iteration i32)
- ;; addr = 0
- i32.const 0
- set_local $addr
- loop
- ;; mem[addr] = colour (start)
- get_local $addr
- ;; a = addr / 4
- get_local $addr
- i32.const 4
- i32.div_u
- set_local $a
- ;; x = a % W
- get_local $a
- i32.const 512
- i32.rem_u
- ;; x = x / W * 2.0 - 1.0
- f64.convert_u/i32
- f64.const 176.0
- f64.div
- f64.const 2
- f64.sub
- set_local $x0
- ;; y = a / W
- get_local $a
- i32.const 512
- i32.div_u
- ;; y = y / W * 2.0 - 1.0
- f64.convert_u/i32
- f64.const 176.0
- f64.div
- f64.const 1.45
- f64.sub
- set_local $y0
- ;; iteration = 0
- i32.const 0
- set_local $iteration
- ;; ox = 0
- f64.const 0.0
- set_local $ox
- ;; oy = 0
- f64.const 0.0
- set_local $oy
- ;; while (x*x + y*y <= 2*2 AND iteration < max_iteration) {
- loop
- ;; ox2 = ox*ox
- get_local $ox
- get_local $ox
- f64.mul
- set_local $ox2
- ;; oy2 = oy*oy
- get_local $oy
- get_local $oy
- f64.mul
- set_local $oy2
- ;; ox*ox - oy*oy + x0
- get_local $ox2
- get_local $oy2
- f64.sub
- get_local $x0
- f64.add
- ;; y = 2*x*y + y0
- get_local $ox
- get_local $oy
- f64.mul
- f64.const 2
- f64.mul
- get_local $y0
- f64.add
- set_local $oy
- ;; x = xtemp
- set_local $ox
- ;; iteration = iteration + 1
- get_local $iteration
- i32.const 1
- i32.add
- set_local $iteration
- ;; if( iteration < max_iteration
- get_local $iteration
- i32.const 1024
- i32.lt_u
- ;; AND ox*ox + oy*oy <= 2*2)
- get_local $ox2
- get_local $oy2
- f64.add
- f64.const 4.0
- f64.le
- i32.and
- ;; continue
- br_if 0
- end
- ;; iteration = iteration / 1000 * 15
- get_local $iteration
- ;; mem[addr] = colour (end)
- i32.store
- ;; addr += 4
- get_local $addr
- i32.const 4
- i32.add
- set_local $add
- ;; if( addr != W*W*4 ) continue
- get_local $addr
- i32.const 0x100000
- i32.lt_u
- br_if 0
- end
- )
- (export "run" (func $mandelbrot))
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement