Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. (module
  2.  
  3. (import "js" "mem" (memory 17))
  4.  
  5. (func $mandelbrot
  6.  
  7. (local $x0 f64)
  8. (local $ox f64)
  9. (local $ox2 f64)
  10. (local $y0 f64)
  11. (local $oy f64)
  12. (local $oy2 f64)
  13. (local $oxy f64)
  14.  
  15. (local $addr i32)
  16. (local $a i32)
  17.  
  18. (local $iteration i32)
  19.  
  20. ;; addr = 0
  21. i32.const 0
  22. set_local $addr
  23.  
  24. loop
  25.  
  26. ;; mem[addr] = colour (start)
  27. get_local $addr
  28.  
  29. ;; a = addr / 4
  30. get_local $addr
  31. i32.const 4
  32. i32.div_u
  33. set_local $a
  34.  
  35. ;; x = a % W
  36. get_local $a
  37. i32.const 512
  38. i32.rem_u
  39.  
  40. ;; x = x / W * 2.0 - 1.0
  41. f64.convert_u/i32
  42. f64.const 176.0
  43. f64.div
  44. f64.const 2
  45. f64.sub
  46. set_local $x0
  47.  
  48. ;; y = a / W
  49. get_local $a
  50. i32.const 512
  51. i32.div_u
  52.  
  53. ;; y = y / W * 2.0 - 1.0
  54. f64.convert_u/i32
  55. f64.const 176.0
  56. f64.div
  57. f64.const 1.45
  58. f64.sub
  59. set_local $y0
  60.  
  61. ;; iteration = 0
  62. i32.const 0
  63. set_local $iteration
  64.  
  65. ;; ox = 0
  66. f64.const 0.0
  67. set_local $ox
  68.  
  69. ;; oy = 0
  70. f64.const 0.0
  71. set_local $oy
  72.  
  73. ;; while (x*x + y*y <= 2*2 AND iteration < max_iteration) {
  74. loop
  75.  
  76. ;; ox2 = ox*ox
  77. get_local $ox
  78. get_local $ox
  79. f64.mul
  80. set_local $ox2
  81.  
  82. ;; oy2 = oy*oy
  83. get_local $oy
  84. get_local $oy
  85. f64.mul
  86. set_local $oy2
  87.  
  88. ;; ox*ox - oy*oy + x0
  89. get_local $ox2
  90. get_local $oy2
  91. f64.sub
  92. get_local $x0
  93. f64.add
  94.  
  95. ;; y = 2*x*y + y0
  96. get_local $ox
  97. get_local $oy
  98. f64.mul
  99. f64.const 2
  100. f64.mul
  101. get_local $y0
  102. f64.add
  103. set_local $oy
  104.  
  105. ;; x = xtemp
  106. set_local $ox
  107.  
  108. ;; iteration = iteration + 1
  109. get_local $iteration
  110. i32.const 1
  111. i32.add
  112. set_local $iteration
  113.  
  114. ;; if( iteration < max_iteration
  115. get_local $iteration
  116. i32.const 1024
  117. i32.lt_u
  118.  
  119. ;; AND ox*ox + oy*oy <= 2*2)
  120. get_local $ox2
  121. get_local $oy2
  122. f64.add
  123. f64.const 4.0
  124. f64.le
  125.  
  126. i32.and
  127.  
  128. ;; continue
  129. br_if 0
  130.  
  131. end
  132.  
  133.  
  134. ;; iteration = iteration / 1000 * 15
  135. get_local $iteration
  136.  
  137. ;; mem[addr] = colour (end)
  138. i32.store
  139.  
  140. ;; addr += 4
  141. get_local $addr
  142. i32.const 4
  143. i32.add
  144. set_local $add
  145.  
  146. ;; if( addr != W*W*4 ) continue
  147. get_local $addr
  148. i32.const 0x100000
  149. i32.lt_u
  150. br_if 0
  151.  
  152. end
  153.  
  154. )
  155. (export "run" (func $mandelbrot))
  156.  
  157. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement