summary refs log tree commit diff
path: root/test/mandel.ssa
blob: efefeb3650aab318ea9f1e76ab525bb53d8a9a4a (plain) (blame)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# Print the Mandelbrot set on the
# terminal line output.

function w $mandel(d %x, d %y) {
@mandel
	%cr =d sub %y, d_0.5
	%ci =d copy %x
@loop
	%i =w phi @mandel 0, @loop1 %i1
	%zr =d phi @mandel d_0, @loop1 %zr1
	%zi =d phi @mandel d_0, @loop1 %zi1
	%i1 =w add 1, %i
	%tmp =d mul %zr, %zi
	%zr2 =d mul %zr, %zr
	%zi2 =d mul %zi, %zi
	%zrx =d sub %zr2, %zi2
	%zr1 =d add %zrx, %cr
	%zix =d add %tmp, %tmp
	%zi1 =d add %zix, %ci
	%sum =d add %zi2, %zr2
	%cmp1 =w cgtd %sum, d_16
	jnz %cmp1, @reti, @loop1
@loop1
	%cmp2 =w csgtw %i1, 1000
	jnz %cmp2, @ret0, @loop
@reti
	ret %i1
@ret0
	ret 0
}

function w $main() {
@main
@loopy
	%y =d phi @main d_-1, @loopy1 %y1
@loopx
	%x =d phi @loopy d_-1, @loopx1 %x1
	%i =w call $mandel(d %x, d %y)
	jnz %i, @out, @in
@in
	%r0 =w call $putchar(w 42)   # '*'
	jmp @loopx1
@out
	%r1 =w call $putchar(w 32)   # ' '
	jmp @loopx1
@loopx1
	%x1 =d add %x, d_0.032
	%cmp1 =w cgtd %x1, d_1
	jnz %cmp1, @loopy1, @loopx
@loopy1
	%r2 =w call $putchar(w 10)   # '\n'
	%y1 =d add %y, d_0.032
	%cmp2 =w cgtd %y1, d_1
	jnz %cmp2, @ret, @loopy
@ret
	ret 0
}

# >>> output
#                                                                #
#                                                                #
#                                                                #
#                                                                #
#                                *                               #
#                               ****                             #
#                               ****                             #
#                               ***                              #
#                              *****                             #
#                             *********                          #
#                           ************                         #
#                        *****************                       #
#                         ****************                       #
#                         ***************                        #
#                         ****************                       #
#                         ****************                       #
#                        *****************                       #
#                         ****************                       #
#                         ****************                       #
#                          **************                        #
#                          *************                         #
#                           ************                         #
#                            *********                           #
#                              *****                             #
#                            ***********                         #
#                         *****************                      #
#                      **********************                    #
#                   * *********************** **                 #
#                   ***************************                  #
#                  *****************************                 #
#               * *******************************  **            #
#              ** ***********************************            #
#              *********************************** *             #
#               ***********************************              #
#              *************************************             #
#              *************************************             #
#             ***************************************            #
#             ***************************************            #
#             ***************************************            #
#             ****************************************           #
#       *     ****************************************           #
#       ********************************************** ****      #
#       ****************************************************     #
#     * *****************************************************    #
#     * *****************************************************    #
#       ***** **************************************** ****      #
#         *   ****************************************    *      #
#             ****************************************           #
#             ***************************************            #
#            ****************************************            #
#              ***************************************           #
#             ****************************************           #
#               ************************************             #
#               ***********************************              #
#                *********************************               #
#               ************************************             #
#               *** ************* ************** ***             #
#                    ***********   ************   **             #
#                      ********      ********                    #
#                     **                *   *                    #
#                                                                #
#                                                                #
#                                                                #
# <<<