-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.wat
More file actions
69 lines (52 loc) · 1.45 KB
/
main.wat
File metadata and controls
69 lines (52 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
(module
(import "js" "mem" (memory 32))
(import "js" "log" (func $log (param i32)))
(global $rand (import "js" "seed") (mut i32))
(global $increment (import "js" "increment") i32)
(global $multiplier (import "js" "multiplier") i32)
(func $lgc (result i32)
;; linear congruential generator using "Numerical Recipes" parameters
global.get $rand
;; i32.const 1664525
global.get $multiplier
i32.mul
;; i32.const 1013904223
global.get $increment
i32.add
i32.const 0x400000
i32.rem_u
)
(func $chaosGame
(local $cx i32)
(local $cy i32)
;; first edge
(local $iteration i32)
i32.const 0
local.set $iteration
loop
local.get $iteration
i32.const 1024
i32.rem_u
local.set $cx
local.get $iteration
i32.const 1024
i32.div_u
local.set $cy
call $lgc
global.set $rand
global.get $rand
i32.const 0xff880088
i32.store
;; global.get $rand
;; call $log
local.get $iteration
i32.const 4
i32.add
local.set $iteration
local.get $iteration
i32.const 50000000
i32.lt_u
br_if 0
end
)
(export "run" (func $chaosGame)))